-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Luke Sikina
committed
Oct 8, 2023
1 parent
b3e5448
commit 7c02fd6
Showing
6 changed files
with
117 additions
and
7 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
pic-sure-api-data/src/main/java/edu/harvard/dbmi/avillach/data/entity/Site.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package edu.harvard.dbmi.avillach.data.entity; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.Table; | ||
import javax.persistence.UniqueConstraint; | ||
|
||
@Schema(description = "A site that contains a PIC-SURE installation that we can send data to") | ||
@Table(uniqueConstraints = { | ||
@UniqueConstraint(name = "unique_code", columnNames = { "code" }), | ||
@UniqueConstraint(name = "unique_email", columnNames = { "domain" }) | ||
}) | ||
@Entity(name = "site") | ||
public class Site extends BaseEntity { | ||
|
||
@Schema(description = "The site code. Ex: BCH") | ||
@Column(length = 15) | ||
private String code; | ||
|
||
@Schema(description = "The site name. Ex: Boston Children's") | ||
@Column(length = 255) | ||
private String name; | ||
|
||
@Schema(description = "The email domain of users for this site. Ex: childrens.harvard.edu") | ||
@Column(length = 255) | ||
private String domain; | ||
|
||
public String getCode() { | ||
return code; | ||
} | ||
|
||
public void setCode(String code) { | ||
this.code = code; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getDomain() { | ||
return domain; | ||
} | ||
|
||
public void setDomain(String domain) { | ||
this.domain = domain; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...sure-api-data/src/main/java/edu/harvard/dbmi/avillach/data/repository/SiteRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package edu.harvard.dbmi.avillach.data.repository; | ||
|
||
import edu.harvard.dbmi.avillach.data.entity.NamedDataset; | ||
import edu.harvard.dbmi.avillach.data.entity.Site; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.transaction.Transactional; | ||
import java.util.UUID; | ||
|
||
@Transactional | ||
@ApplicationScoped | ||
public class SiteRepository extends BaseRepository<Site, UUID>{ | ||
protected SiteRepository() {super(Site.class);} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
pic-sure-api-war/src/main/java/edu/harvard/dbmi/avillach/service/SiteParsingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package edu.harvard.dbmi.avillach.service; | ||
|
||
import edu.harvard.dbmi.avillach.data.entity.Site; | ||
import edu.harvard.dbmi.avillach.data.repository.SiteRepository; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.inject.Inject; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class SiteParsingService { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(SiteParsingService.class); | ||
|
||
private static final Pattern emailRegex = Pattern.compile("^([^@]+)(@)(.*)$"); | ||
|
||
@Inject | ||
SiteRepository repository; | ||
|
||
public Optional<String> parseSiteOfOrigin(String email) { | ||
Matcher matcher = emailRegex.matcher(email); | ||
if (!matcher.find()) { | ||
LOG.warn("Unable to parse domain for email: {}", email); | ||
return Optional.empty(); | ||
} | ||
|
||
List<Site> matchingDomains = repository.getByColumn("domain", matcher.group(3)); | ||
if (matchingDomains.isEmpty()) { | ||
LOG.warn("Unable to match domain for email: {}, looked for domain: {}", email, matcher.group(3)); | ||
return Optional.empty(); | ||
} | ||
if (matchingDomains.size() > 1) { | ||
LOG.warn("Multiple domains match email. This should never happen! Email: {}", email); | ||
return Optional.empty(); | ||
} | ||
return Optional.of(matchingDomains.get(0).getCode()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters