-
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.
* Add table and API for naming a dataset id (#132) * Adds named_dataset sql table for saving named dataset ids. * Adds a SecurityContext class to persist authenticated user information for the entire request. * Updates JWTFilter class to add the new SecurityContext to the context object. * Adds classes for new service, entity, and endpoints needed. * Add metadata column to named_dataset table to extend in the future. (#135) * Update migration file name. (#143)
- Loading branch information
Showing
19 changed files
with
1,356 additions
and
371 deletions.
There are no files selected for viewing
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
69 changes: 69 additions & 0 deletions
69
pic-sure-api-data/src/main/java/edu/harvard/dbmi/avillach/data/entity/AuthUser.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,69 @@ | ||
package edu.harvard.dbmi.avillach.data.entity; | ||
|
||
import java.security.Principal; | ||
|
||
import javax.json.Json; | ||
|
||
/* | ||
* This class is used to mirror the User object from the auth DB to maintain schema separation. - nc | ||
*/ | ||
public class AuthUser extends BaseEntity implements Principal { | ||
private String userId; | ||
|
||
private String subject; | ||
|
||
private String roles; | ||
|
||
private String email; | ||
|
||
public String getUserId() { | ||
return userId; | ||
} | ||
|
||
public AuthUser setUserId(String userId) { | ||
this.userId = userId; | ||
return this; | ||
} | ||
|
||
public String getSubject() { | ||
return subject; | ||
} | ||
|
||
public AuthUser setSubject(String subject) { | ||
this.subject = subject; | ||
return this; | ||
} | ||
|
||
public String getRoles() { | ||
return roles; | ||
} | ||
|
||
public AuthUser setRoles(String roles) { | ||
this.roles = roles; | ||
return this; | ||
} | ||
|
||
public String getEmail(){ | ||
return email; | ||
} | ||
|
||
public AuthUser setEmail(String email){ | ||
this.email = email; | ||
return this; | ||
} | ||
|
||
@Override // Principal method | ||
public String getName() { | ||
return getEmail(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return Json.createObjectBuilder() | ||
.add("userId", userId) | ||
.add("subject", subject) | ||
.add("email", email) | ||
.add("roles", roles) | ||
.build().toString(); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
pic-sure-api-data/src/main/java/edu/harvard/dbmi/avillach/data/entity/NamedDataset.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,101 @@ | ||
package edu.harvard.dbmi.avillach.data.entity; | ||
|
||
import java.util.Map; | ||
|
||
import javax.json.Json; | ||
import javax.persistence.Column; | ||
import javax.persistence.Convert; | ||
import javax.persistence.Entity; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.OneToOne; | ||
import javax.persistence.Table; | ||
import javax.persistence.UniqueConstraint; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
import edu.harvard.dbmi.avillach.data.entity.convert.JsonConverter; | ||
|
||
@Schema(description = "A NamedDataset object containing query, name, user, and archived status.") | ||
@Entity(name = "named_dataset") | ||
@Table(uniqueConstraints = { | ||
@UniqueConstraint(name = "unique_queryId_user", columnNames = { "queryId", "user" }) | ||
}) | ||
public class NamedDataset extends BaseEntity { | ||
@Schema(description = "The associated Query") | ||
@OneToOne | ||
@JoinColumn(name = "queryId") | ||
private Query query; | ||
|
||
@Schema(description = "The user identifier") | ||
@Column(length = 255) | ||
private String user; | ||
|
||
@Schema(description = "The name user has assigned to this dataset") | ||
@Column(length = 255) | ||
private String name; | ||
|
||
@Schema(description = "The archived state") | ||
private Boolean archived = false; | ||
|
||
@Schema(description = "A json string object containing override specific values") | ||
@Column(length = 8192) | ||
@Convert(converter = JsonConverter.class) | ||
private Map<String, Object> metadata; | ||
|
||
public NamedDataset setName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public NamedDataset setArchived(Boolean archived) { | ||
this.archived = archived; | ||
return this; | ||
} | ||
|
||
public Boolean getArchived() { | ||
return archived; | ||
} | ||
|
||
public NamedDataset setQuery(Query query) { | ||
this.query = query; | ||
return this; | ||
} | ||
|
||
public Query getQuery(){ | ||
return query; | ||
} | ||
|
||
public NamedDataset setUser(String user) { | ||
this.user = user; | ||
return this; | ||
} | ||
|
||
public String getUser(){ | ||
return user; | ||
} | ||
|
||
public Map<String, Object> getMetadata(){ | ||
return metadata; | ||
} | ||
|
||
public NamedDataset setMetadata(Map<String, Object> metadata){ | ||
this.metadata = metadata; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return Json.createObjectBuilder() | ||
.add("uuid", uuid.toString()) | ||
.add("name", name) | ||
.add("archived", archived) | ||
.add("queryId", query.getUuid().toString()) | ||
.add("user", user) | ||
.add("metadata", metadata.toString()) | ||
.build().toString(); | ||
} | ||
} |
43 changes: 0 additions & 43 deletions
43
pic-sure-api-data/src/main/java/edu/harvard/dbmi/avillach/data/entity/User.java
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
...e-api-data/src/main/java/edu/harvard/dbmi/avillach/data/entity/convert/JsonConverter.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,50 @@ | ||
package edu.harvard.dbmi.avillach.data.entity.convert; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.persistence.AttributeConverter; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public class JsonConverter implements AttributeConverter<Map<String, Object>, String> { | ||
private final Logger logger = LoggerFactory.getLogger(JsonConverter.class); | ||
|
||
@Override | ||
public String convertToDatabaseColumn(Map<String, Object> objectData) { | ||
if (objectData == null) { | ||
return "{}"; | ||
} | ||
|
||
String jsonData = null; | ||
try { | ||
jsonData = new ObjectMapper().writeValueAsString(objectData); | ||
} catch (final JsonProcessingException e) { | ||
logger.error("JSON writing error", e); | ||
} | ||
|
||
return jsonData; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> convertToEntityAttribute(String jsonData) { | ||
if (jsonData == null) { | ||
return new HashMap<String, Object>(); | ||
} | ||
|
||
Map<String, Object> objectData = null; | ||
try { | ||
objectData = new ObjectMapper().readValue(jsonData, new TypeReference<HashMap<String, Object>>() {}); | ||
} catch (final IOException e) { | ||
logger.error("JSON reading error", e); | ||
} | ||
|
||
return objectData; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...-data/src/main/java/edu/harvard/dbmi/avillach/data/repository/NamedDatasetRepository.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,13 @@ | ||
package edu.harvard.dbmi.avillach.data.repository; | ||
|
||
import edu.harvard.dbmi.avillach.data.entity.NamedDataset; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.transaction.Transactional; | ||
import java.util.UUID; | ||
|
||
@Transactional | ||
@ApplicationScoped | ||
public class NamedDatasetRepository extends BaseRepository<NamedDataset, UUID>{ | ||
protected NamedDatasetRepository() {super(NamedDataset.class);} | ||
} |
64 changes: 64 additions & 0 deletions
64
...re-api-data/src/main/java/edu/harvard/dbmi/avillach/data/request/NamedDatasetRequest.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,64 @@ | ||
package edu.harvard.dbmi.avillach.data.request; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Pattern; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
@Schema( | ||
description = "Request to add or update a named dataset.", | ||
example = "{\n" + // | ||
" \"queryId\": \"ec780aeb-d981-432a-b72b-51d4ecb3fd53\",\n" + // | ||
" \"name\": \"My first Query\",\n" + // | ||
" \"archived\": false\n" + // | ||
" \"metadata\": {}\n" + // | ||
"}" | ||
) | ||
public class NamedDatasetRequest { | ||
@NotNull | ||
private UUID queryId; | ||
|
||
@NotNull | ||
@Pattern(regexp = "^[\\w\\d \\-\\\\/?+=\\[\\].():\"']+$") | ||
private String name; | ||
|
||
private Boolean archived = false; | ||
|
||
private Map<String, Object> metadata = new HashMap<String, Object>(); | ||
|
||
public UUID getQueryId() { | ||
return queryId; | ||
} | ||
|
||
public void setQueryId(UUID query) { | ||
this.queryId = query; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Boolean getArchived(){ | ||
return archived; | ||
} | ||
|
||
public void setArchived(Boolean archived) { | ||
this.archived = archived; | ||
} | ||
|
||
public Map<String, Object> getMetadata(){ | ||
return metadata; | ||
} | ||
|
||
public void setMetadata(Map<String, Object> metadata){ | ||
this.metadata = metadata; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
pic-sure-api-data/src/main/resources/db/sql/V5__ADD_NAMED_DATASET_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,13 @@ | ||
USE `picsure`; | ||
|
||
CREATE TABLE `named_dataset` ( | ||
`uuid` binary(16) NOT NULL, | ||
`queryId` binary(16) NOT NULL, | ||
`user` varchar(255) COLLATE utf8_bin DEFAULT NULL, | ||
`name` varchar(255) COLLATE utf8_bin DEFAULT NULL, | ||
`archived` bit(1) NOT NULL DEFAULT FALSE, | ||
`metadata` TEXT, | ||
PRIMARY KEY (`uuid`), | ||
CONSTRAINT `foreign_queryId` FOREIGN KEY (`queryId`) REFERENCES `query` (`uuid`), | ||
CONSTRAINT `unique_queryId_user` UNIQUE (`queryId`, `user`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; |
Oops, something went wrong.