Skip to content

Commit

Permalink
Merge branch 'release-3.x.x' into TASK-6219
Browse files Browse the repository at this point in the history
  • Loading branch information
j-coll committed Nov 8, 2024
2 parents ced9545 + feedb60 commit 026635a
Show file tree
Hide file tree
Showing 9 changed files with 358 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ public void checkCanAssignOrSeePermissions(String organizationId, long studyId,

@Override
public void checkCanCreateUpdateDeleteVariableSets(String organizationId, long studyId, String userId) throws CatalogException {
if (!isAtLeastOrganizationOwnerOrAdmin(organizationId, userId)) {
throw CatalogAuthorizationException.notOrganizationOwnerOrAdmin("create, update or delete variable sets.");
if (!isAtLeastStudyAdministrator(organizationId, studyId, userId)) {
throw CatalogAuthorizationException.notStudyAdmin("create, update or delete variable sets.");
}
}

Expand Down
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 026635a

Please sign in to comment.