-
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.
- Requirement: in order to know where to send data, we need to associate each query with the requester's site - Create table of site code, site name, site email domain - When an institutional query request is made: - Parse the site code from the email of the requesting user - Add that site code to the query request - When persisting a query object after starting a query request - Check for a site code in the query request - Add it to the query meta if it exists - Add some extra niceness for later data transfer work - S3 status code
- Loading branch information
Luke Sikina
committed
Oct 10, 2023
1 parent
3babb26
commit 51912b0
Showing
10 changed files
with
163 additions
and
9 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
pic-sure-api-data/src/main/java/edu/harvard/dbmi/avillach/data/entity/DataSharingStatus.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,5 @@ | ||
package edu.harvard.dbmi.avillach.data.entity; | ||
|
||
public enum DataSharingStatus { | ||
Unknown, Pending, Error, Complete, NotShared | ||
} |
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);} | ||
} |
11 changes: 11 additions & 0 deletions
11
pic-sure-api-data/src/main/resources/db/sql/V6__ADD_SITE_TABLE.sql
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,11 @@ | ||
USE `picsure`; | ||
|
||
CREATE TABLE `site` ( | ||
`uuid` binary(16) NOT NULL, | ||
`code` varchar(15) COLLATE utf8_bin DEFAULT NULL, | ||
`name` varchar(255) COLLATE utf8_bin DEFAULT NULL, | ||
`domain` varchar(255) COLLATE utf8_bin DEFAULT NULL, | ||
PRIMARY KEY (`uuid`), | ||
CONSTRAINT `unique_code` UNIQUE (`code`), | ||
CONSTRAINT `unique_domain` UNIQUE (`domain`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; |
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
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