Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.broadinstitute.consent.http.models.elastic_search;

import java.util.List;
import java.util.Map;

public class StudyTerm {

Expand All @@ -16,6 +17,7 @@ public class StudyTerm {
private List<String> dataCustodianEmail;
private Boolean publicVisibility;
private List<String> dataTypes;
private Map<String, Object> assets;


public String getDescription() {
Expand Down Expand Up @@ -110,4 +112,12 @@ public List<String> getDataTypes() {
public void setDataTypes(List<String> dataTypes) {
this.dataTypes = dataTypes;
}

public Map<String, Object> getAssets() {
return assets;
}

public void setAssets(Map<String, Object> assets) {
this.assets = assets;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,32 @@ public StudyTerm toStudyTerm(Study study) {
term.setDataSubmitterEmail(study.getCreateUserEmail());
}

findStudyProperty(
study.getProperties(), "assets"
).ifPresent(
prop -> {
Object value = prop.getValue();
Map<String, Object> assetsMap;
// When property is loaded from db it is deserialized as JsonObject
if (value instanceof com.google.gson.JsonElement) {
assetsMap = GsonUtil.getInstance().fromJson(
(com.google.gson.JsonElement) value,
new com.google.gson.reflect.TypeToken<Map<String, Object>>(){}.getType()
);
// Otherwise Gson deserializes JSON and creates a LinkedTreeMap
} else if (value instanceof Map) {
assetsMap = (Map<String, Object>) value;
// Fallback: try to parse as JSON string
} else {
assetsMap = GsonUtil.getInstance().fromJson(
value.toString(),
new com.google.gson.reflect.TypeToken<Map<String, Object>>(){}.getType()
);
}
term.setAssets(assetsMap);
}
);

return term;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,15 +864,15 @@ private DatasetRegistrationSchemaV1 createRandomCompleteDatasetRegistration(User
consentGroup.setAccessManagement(AccessManagement.CONTROLLED);
consentGroup.setDataLocation(ConsentGroup.DataLocation.TDR_LOCATION);
consentGroup.setDataAccessCommitteeId(new Random().nextInt());
schemaV1.setAssets(Map.of(
schemaV1.setAssets(Map.of("workspaces", List.of(Map.of(
"workspace_id", "c7b96ac5-5568-441c-a3f4-2e82e45e3e6d",
"name", "Cardiometabolic GWAS Analysis Workspace",
"platform", "Terra",
"authors", List.of(
Map.of("user", "john", "email", "[email protected]"),
Map.of("user", "emma", "email", "[email protected]")
),
"tags", List.of("GWAS", "Terra", "featured")));
"tags", List.of("GWAS", "Terra", "featured")))));
schemaV1.setConsentGroups(List.of(consentGroup));
return schemaV1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.HttpVersion;
import org.apache.http.StatusLine;
Expand Down Expand Up @@ -342,6 +343,38 @@ void testToDatasetTerm_StudyInfo() {
assertEquals(datasetRecord.study.getDataTypes(), term.getStudy().getDataTypes());
}

@Test
void testToDatasetTerm_StudyAssets() {
DatasetRecord datasetRecord = createDatasetRecord();
Map<String, Object> assetsMap = Map.of("workspaces", List.of(Map.of(
"workspace_id", "c7b96ac5-5568-441c-a3f4-2e82e45e3e6d",
"name", "Cardiometabolic GWAS Analysis Workspace",
"platform", "Terra",
"authors", List.of(
Map.of("user", "john", "email", "[email protected]"),
Map.of("user", "emma", "email", "[email protected]")
),
"tags", List.of("GWAS", "Terra", "featured")))
);
String assetsJson = GsonUtil.getInstance().toJson(assetsMap);
StudyProperty assetsProp = new StudyProperty();
assetsProp.setStudyId(datasetRecord.study.getStudyId());
assetsProp.setKey("assets");
assetsProp.setType(PropertyType.Json);
assetsProp.setValue(GsonUtil.getInstance().fromJson(assetsJson, Object.class));
datasetRecord.study.addProperty(assetsProp);

when(userDao.findUserById(datasetRecord.createUser.getUserId())).thenReturn(
datasetRecord.createUser);
when(userDao.findUserById(datasetRecord.updateUser.getUserId())).thenReturn(
datasetRecord.updateUser);
when(dacDAO.findById(any())).thenReturn(datasetRecord.dac);

DatasetTerm term = service.toDatasetTerm(datasetRecord.dataset);

assertEquals(assetsMap, term.getStudy().getAssets());
}

@Test
void testToDatasetTerm_DatasetInfo() {
DataAccessRequest dar1 = new DataAccessRequest();
Expand Down
Loading