Skip to content

Commit

Permalink
Merge branch 'TASK-5663' of github.com:opencb/opencga into TASK-5663
Browse files Browse the repository at this point in the history
  • Loading branch information
j-coll committed Feb 22, 2024
2 parents 565693f + f4e9aa5 commit 328a8bb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,17 @@ public void test2Member2GenerationFamilyTest() throws CatalogException {
public void updateTest() throws CatalogException {
FamilyUpdateParams updateParams = new FamilyUpdateParams();

Family prevFamily = catalogManager.getFamilyManager().get(studyId, family.getId(), null, sessionIdUser).first();
assertEquals(prevFamily.getPedigreeGraph().getBase64(), family.getPedigreeGraph().getBase64());

QueryOptions queryOptions = new QueryOptions()
.append(ParamConstants.FAMILY_UPDATE_ROLES_PARAM, true)
.append(ParamConstants.INCLUDE_RESULT_PARAM, true);
Family updatedFamily = catalogManager.getFamilyManager().update(studyId, family.getId(), updateParams, queryOptions, sessionIdUser)
.first();

PedigreeGraph pedigreeGraph = updatedFamily.getPedigreeGraph();
MatcherAssert.assertThat(pedigreeGraph.getBase64(), CoreMatchers.startsWith("iVBORw0KGgoAAAANSUhEUgAAAeAAAAHg="));
MatcherAssert.assertThat(pedigreeGraph.getBase64(), CoreMatchers.endsWith("5UIf81hI8AAAAASUVORK5CYII="));
assertEquals(prevFamily.getPedigreeGraph().getBase64(), updatedFamily.getPedigreeGraph().getBase64());
assertEquals(prevFamily.getVersion() + 1, updatedFamily.getVersion());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@

package org.opencb.opencga.catalog.db.mongodb.converters;

import org.apache.commons.collections4.CollectionUtils;
import org.bson.Document;
import org.opencb.biodata.models.clinical.Phenotype;
import org.opencb.commons.utils.ListUtils;
import org.opencb.opencga.catalog.db.api.FamilyDBAdaptor;
import org.opencb.opencga.core.models.family.Family;
import org.opencb.opencga.core.models.individual.Individual;
import org.opencb.opencga.core.models.study.VariableSet;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -55,40 +54,41 @@ public Document convertToStorageType(Family object, List<VariableSet> variableSe
}

public void validateDocumentToUpdate(Document document) {
List<Document> memberList = (List) document.get("members");
List<Document> memberList = document.getList("members", Document.class);
if (memberList != null) {
// We make sure we don't store duplicates
Map<Long, Individual> individualMap = new HashMap<>();
Set<Long> individualSet = new HashSet<>();
for (Document individual : memberList) {
long id = individual.getInteger("uid").longValue();
int version = individual.getInteger("version");
if (id > 0) {
Individual tmpIndividual = new Individual()
.setVersion(version);
tmpIndividual.setUid(id);
individualMap.put(id, tmpIndividual);
long uid = individual.get("uid", Number.class).longValue();
if (uid <= 0) {
throw new IllegalArgumentException("Missing uid value for member '" + individual.getString("id") + "'.");
}
if (individualSet.contains(uid)) {
throw new IllegalArgumentException("Duplicated member '" + individual.getString("id") + " (" + uid + ")' found.");
}
individualSet.add(uid);
}

document.put("members",
individualMap.entrySet().stream()
memberList.stream()
.map(entry -> new Document()
.append("uid", entry.getValue().getUid())
.append("version", entry.getValue().getVersion()))
.append("uid", entry.get("uid", Number.class).longValue())
.append("version", entry.get("version", Number.class).intValue())
)
.collect(Collectors.toList()));
}

List<Document> disorderList = (List) document.get("disorders");
List<Document> disorderList = document.getList("disorders", Document.class);
if (disorderList != null) {
for (Document disorder : disorderList) {
fixPhenotypeFields((List) disorder.get("evidences"));
fixPhenotypeFields(disorder.getList("evidences", Document.class));
}
}
fixPhenotypeFields((List) document.get("phenotypes"));
fixPhenotypeFields(document.getList("phenotypes", Document.class));
}

private void fixPhenotypeFields(List<Document> phenotypeList) {
if (ListUtils.isNotEmpty(phenotypeList)) {
if (CollectionUtils.isNotEmpty(phenotypeList)) {
for (Document phenotype : phenotypeList) {
phenotype.put("status", Phenotype.Status.UNKNOWN.name());
phenotype.put("ageOfOnset", "-1");
Expand Down

0 comments on commit 328a8bb

Please sign in to comment.