Skip to content

Commit

Permalink
catalog: create cohort does not increment sample version, #TASK-6754
Browse files Browse the repository at this point in the history
  • Loading branch information
pfurio committed Sep 23, 2024
1 parent 87cc4a6 commit d435ec3
Show file tree
Hide file tree
Showing 8 changed files with 356 additions and 228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,23 @@ public abstract class AnnotationMongoDBAdaptor<T> extends CatalogMongoDBAdaptor

protected abstract MongoDBCollection getCollection();

abstract OpenCGAResult<T> transactionalUpdate(ClientSession clientSession, T entry, ObjectMap parameters,
OpenCGAResult<T> transactionalUpdate(ClientSession clientSession, T entry, ObjectMap parameters,
List<VariableSet> variableSetList, QueryOptions queryOptions)
throws CatalogParameterException, CatalogDBException, CatalogAuthorizationException {
return transactionalUpdate(clientSession, entry, parameters, variableSetList, queryOptions, true);
}

abstract OpenCGAResult<T> transactionalUpdate(ClientSession clientSession, T entry, ObjectMap parameters,
List<VariableSet> variableSetList, QueryOptions queryOptions, boolean incrementVersion)
throws CatalogParameterException, CatalogDBException, CatalogAuthorizationException;

abstract OpenCGAResult<T> transactionalUpdate(ClientSession clientSession, long studyUid, Bson query, UpdateDocument updateDocument)
OpenCGAResult<T> transactionalUpdate(ClientSession clientSession, long studyUid, Bson query, UpdateDocument updateDocument)
throws CatalogParameterException, CatalogDBException, CatalogAuthorizationException {
return transactionalUpdate(clientSession, studyUid, query, updateDocument, true);
}

abstract OpenCGAResult<T> transactionalUpdate(ClientSession clientSession, long studyUid, Bson query, UpdateDocument updateDocument,
boolean incrementVersion)
throws CatalogParameterException, CatalogDBException, CatalogAuthorizationException;

public enum AnnotationSetParams implements QueryParam {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,20 +355,21 @@ OpenCGAResult transactionalUpdate(ClientSession clientSession, ClinicalAnalysis

@Override
OpenCGAResult<ClinicalAnalysis> transactionalUpdate(ClientSession clientSession, ClinicalAnalysis entry, ObjectMap parameters,
List<VariableSet> variableSetList, QueryOptions queryOptions)
List<VariableSet> variableSetList, QueryOptions queryOptions,
boolean incrementVersion)
throws CatalogParameterException, CatalogDBException, CatalogAuthorizationException {
throw new NotImplementedException("Please call to the other transactionalUpdate method passing the ClinicalAudit list");
}

@Override
OpenCGAResult<ClinicalAnalysis> transactionalUpdate(ClientSession clientSession, long studyUid, Bson query,
UpdateDocument updateDocument)
UpdateDocument updateDocument, boolean incrementVersion)
throws CatalogParameterException, CatalogDBException, CatalogAuthorizationException {
long tmpStartTime = startQuery();

Document updateOperation = updateDocument.toFinalUpdateDocument();
if (!updateOperation.isEmpty()) {
return versionedMongoDBAdaptor.update(clientSession, query, entryList -> {
SnapshotVersionedMongoDBAdaptor.FunctionWithException<ClinicalAnalysis> updateClinicalReferences = (clinicalList) -> {
logger.debug("Update clinical analysis. Query: {}, Update: {}", query.toBsonDocument(), updateDocument);
DataResult<?> update = clinicalCollection.update(clientSession, query, updateOperation, null);

Expand All @@ -385,7 +386,12 @@ OpenCGAResult<ClinicalAnalysis> transactionalUpdate(ClientSession clientSession,

logger.debug("{} clinical analyses successfully updated", update.getNumUpdated());
return endWrite(tmpStartTime, update.getNumMatches(), update.getNumUpdated(), Collections.emptyList());
}, null, null);
};
if (incrementVersion) {
return versionedMongoDBAdaptor.update(clientSession, query, null, updateClinicalReferences, null, null);
} else {
return versionedMongoDBAdaptor.updateWithoutVersionIncrement(clientSession, query, null, updateClinicalReferences);
}
} else {
throw new CatalogDBException("Nothing to update");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public OpenCGAResult update(Query query, ObjectMap parameters, List<VariableSet>

@Override
OpenCGAResult<Cohort> transactionalUpdate(ClientSession clientSession, Cohort cohort, ObjectMap parameters,
List<VariableSet> variableSetList, QueryOptions queryOptions)
List<VariableSet> variableSetList, QueryOptions queryOptions, boolean incrementVersion)
throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
long tmpStartTime = startQuery();
Query tmpQuery = new Query()
Expand Down Expand Up @@ -341,7 +341,8 @@ OpenCGAResult<Cohort> transactionalUpdate(ClientSession clientSession, Cohort co
}

@Override
OpenCGAResult<Cohort> transactionalUpdate(ClientSession clientSession, long studyUid, Bson query, UpdateDocument updateDocument)
OpenCGAResult<Cohort> transactionalUpdate(ClientSession clientSession, long studyUid, Bson query, UpdateDocument updateDocument,
boolean incrementVersion)
throws CatalogParameterException, CatalogDBException, CatalogAuthorizationException {
long tmpStartTime = startQuery();

Expand Down
Loading

0 comments on commit d435ec3

Please sign in to comment.