Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK-1415 - Fix OpenCGA audit handling #2162

Open
wants to merge 22 commits into
base: release-2.4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bde5c3d
catalog: improve auditing system, #TASK-1415
pfurio Aug 11, 2022
9ebc869
Merge branch 'release-2.4.x' into TASK-1415
pfurio Aug 18, 2022
df3078e
Merge branch 'release-2.4.x' into TASK-1415
pfurio Aug 18, 2022
2ed5f83
Merge branch 'release-2.4.x' into TASK-1415
pfurio Sep 12, 2022
445b8d2
pom: upgrade java-common-libs version dependency, #TASK-1415
pfurio Sep 12, 2022
6cb959b
catalog: fix count calls, #TASK-1415
pfurio Sep 12, 2022
f82e602
catalog: audit all ClinicalAnalysis and Family methods, #TASK-1415
pfurio Sep 14, 2022
b28e403
catalog: add audit in ResourceManager, #TASK-1415
pfurio Sep 20, 2022
f894648
Merge branch 'release-2.4.x' into TASK-1415
pfurio Sep 28, 2022
989341a
catalog: audit all methods from CohortManager, #TASK-1415
pfurio Sep 28, 2022
72b580b
catalog: audit all methods from StudyManager, #TASK-1415
pfurio Oct 3, 2022
de91f3f
catalog: audit all methods from UserManager, #TASK-1415
pfurio Oct 6, 2022
8863a9e
catalog: audit all methods from ProjectManager, #TASK-1415
pfurio Oct 6, 2022
74e3f17
catalog: audit methods from FileManager (wip), #TASK-1415
pfurio Oct 7, 2022
bafb915
catalog: audit all methods from FileManager, #TASK-1415
pfurio Oct 10, 2022
10ff104
catalog: audit all methods from IndividualManager, #TASK-1415
pfurio Oct 10, 2022
9696d30
catalog: audit all methods from IndividualManager, #TASK-1415
pfurio Oct 10, 2022
46ea504
catalog: audit all methods from SampleManager, #TASK-1415
pfurio Oct 11, 2022
c6a481d
catalog: audit all methods from InterpretationManager, #TASK-1415
pfurio Oct 11, 2022
ee23c60
catalog: audit all methods from PanelManager, #TASK-1415
pfurio Oct 14, 2022
89c0f1f
catalog: audit all methods from JobManager, #TASK-1415
pfurio Oct 19, 2022
419d437
catalog: audit only sample id, #TASK-1415
pfurio Nov 2, 2022
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
Expand Up @@ -158,7 +158,7 @@ public static File create(String resourceName, boolean indexed) throws IOExcepti
catalogManager.getFileManager().updateFileInternalVariantIndex(file,
FileInternalVariantIndex.init().setStatus(new VariantIndexStatus(InternalStatus.READY)), sessionId);
indexedFiles.add(file.getName());
List<String> samples = catalogManager.getCohortManager().getSamples(studyId, cohortId, sessionId).getResults().stream().map(Sample::getId).collect(Collectors.toList());
List<String> samples = catalogManager.getCohortManager().get(studyId, cohortId, QueryOptions.empty(), sessionId).first().getSamples().stream().map(Sample::getId).collect(Collectors.toList());
samples.addAll(file.getSampleIds());
List<SampleReferenceParam> sampleReferenceParams = samples.stream().map(s -> new SampleReferenceParam().setId(s)).collect(Collectors.toList());
catalogManager.getCohortManager().update(studyId, cohortId,
Expand All @@ -172,8 +172,9 @@ public void updateCatalogFromStorageTest() throws Exception {

StudyMetadata sm = studyConfigurationFactory.getStudyMetadata(studyId);

List<String> samples = catalogManager.getCohortManager().getSamples(studyId, cohortId, sessionId)
.getResults()
List<String> samples = catalogManager.getCohortManager().get(studyId, cohortId, QueryOptions.empty(), sessionId)
.first()
.getSamples()
.stream()
.map(Sample::getId)
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ DBIterator<T> iterator(long studyUid, Query query, QueryOptions options, String
DBIterator nativeIterator(long studyUid, Query query, QueryOptions options, String user)
throws CatalogDBException, CatalogAuthorizationException, CatalogParameterException;

OpenCGAResult<Long> count(Query query, String user) throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException;
OpenCGAResult<T> count(Query query, String user) throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException;

OpenCGAResult<T> groupBy(Query query, List<String> fields, QueryOptions options, String user)
throws CatalogDBException, CatalogAuthorizationException, CatalogParameterException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public interface DBAdaptor<T> extends Iterable<T> {
@Deprecated
String FORCE = "force";

default OpenCGAResult<Long> count() throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
default OpenCGAResult<T> count() throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
return count(new Query());
}

OpenCGAResult<Long> count(Query query) throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException;
OpenCGAResult<T> count(Query query) throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException;

default OpenCGAResult<T> stats() {
return stats(new Query());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,24 @@ public MongoDBCollection getClinicalCollection() {
}

@Override
public OpenCGAResult<Long> count(Query query) throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
public OpenCGAResult<ClinicalAnalysis> count(Query query)
throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
return count(null, query);
}

OpenCGAResult<Long> count(ClientSession clientSession, Query query)
OpenCGAResult<ClinicalAnalysis> count(ClientSession clientSession, Query query)
throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
Bson bson = parseQuery(query);
return new OpenCGAResult<>(clinicalCollection.count(clientSession, bson));
}

@Override
public OpenCGAResult<Long> count(final Query query, final String user)
public OpenCGAResult<ClinicalAnalysis> count(final Query query, final String user)
throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
return count(null, query, user);
}

OpenCGAResult<Long> count(ClientSession clientSession, final Query query, final String user)
OpenCGAResult<ClinicalAnalysis> count(ClientSession clientSession, final Query query, final String user)
throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
Bson bson = parseQuery(query, user);
logger.debug("Clinical count: query : {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry()));
Expand Down Expand Up @@ -300,7 +301,7 @@ UpdateDocument parseAndValidateUpdateParams(ObjectMap parameters, List<ClinicalA
tmpQuery = new Query()
.append(QueryParams.ID.key(), parameters.get(QueryParams.ID.key()))
.append(QueryParams.STUDY_UID.key(), studyId);
OpenCGAResult<Long> count = count(tmpQuery);
OpenCGAResult<ClinicalAnalysis> count = count(tmpQuery);
if (count.getNumMatches() > 0) {
throw new CatalogDBException("Cannot set id for clinical analysis. A clinical analysis with { id: '"
+ parameters.get(QueryParams.ID.key()) + "'} already exists.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,23 @@ public OpenCGAResult unmarkPermissionRule(long studyId, String permissionRuleId)
}

@Override
public OpenCGAResult<Long> count(Query query) throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
public OpenCGAResult<Cohort> count(Query query) throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
return count(null, query);
}

private OpenCGAResult<Long> count(ClientSession clientSession, Query query)
private OpenCGAResult<Cohort> count(ClientSession clientSession, Query query)
throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
long startTime = startQuery();
return endQuery(startTime, cohortCollection.count(clientSession, parseQuery(query)));
}

@Override
public OpenCGAResult<Long> count(final Query query, final String user)
public OpenCGAResult<Cohort> count(final Query query, final String user)
throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
return count(null, query, user);
}

private OpenCGAResult<Long> count(ClientSession clientSession, final Query query, final String user)
private OpenCGAResult<Cohort> count(ClientSession clientSession, final Query query, final String user)
throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
Bson bson = parseQuery(query, user);
logger.debug("Cohort count: query : {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry()));
Expand Down Expand Up @@ -441,8 +441,8 @@ private UpdateDocument parseAndValidateUpdateParams(ClientSession clientSession,

tmpQuery = new Query()
.append(QueryParams.ID.key(), parameters.get(QueryParams.ID.key()))
.append(STUDY_UID.key(), studyId);
OpenCGAResult<Long> count = count(clientSession, tmpQuery);
.append(QueryParams.STUDY_UID.key(), studyId);
OpenCGAResult<Cohort> count = count(clientSession, tmpQuery);
if (count.getNumMatches() > 0) {
throw new CatalogDBException("Cannot update the " + QueryParams.ID.key() + ". Cohort "
+ parameters.get(QueryParams.ID.key()) + " already exists.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.opencb.opencga.core.api.ParamConstants;
import org.opencb.opencga.core.common.TimeUtils;
import org.opencb.opencga.core.config.Configuration;
import org.opencb.opencga.core.models.clinical.ClinicalAnalysis;
import org.opencb.opencga.core.models.cohort.Cohort;
import org.opencb.opencga.core.models.common.AnnotationSet;
import org.opencb.opencga.core.models.common.Enums;
Expand Down Expand Up @@ -230,23 +231,23 @@ private void createMissingIndividual(ClientSession clientSession, long studyUid,
}

@Override
public OpenCGAResult<Long> count(Query query) throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
public OpenCGAResult<Family> count(Query query) throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
return count(null, query);
}

OpenCGAResult<Long> count(ClientSession clientSession, Query query)
OpenCGAResult<Family> count(ClientSession clientSession, Query query)
throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
Bson bson = parseQuery(query);
return new OpenCGAResult<>(familyCollection.count(clientSession, bson));
}

@Override
public OpenCGAResult<Long> count(final Query query, final String user)
public OpenCGAResult<Family> count(final Query query, final String user)
throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
return count(null, query, user);
}

public OpenCGAResult<Long> count(ClientSession clientSession, final Query query, final String user)
public OpenCGAResult<Family> count(ClientSession clientSession, final Query query, final String user)
throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
Bson bson = parseQuery(query, user);
logger.debug("Family count: query : {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry()));
Expand Down Expand Up @@ -654,7 +655,7 @@ UpdateDocument parseAndValidateUpdateParams(ClientSession clientSession, ObjectM
tmpQuery = new Query()
.append(QueryParams.ID.key(), parameters.get(QueryParams.ID.key()))
.append(QueryParams.STUDY_UID.key(), familyDataResult.first().getStudyUid());
OpenCGAResult<Long> count = count(clientSession, tmpQuery);
OpenCGAResult<Family> count = count(clientSession, tmpQuery);
if (count.getNumMatches() > 0) {
throw new CatalogDBException("Cannot set '" + QueryParams.ID.key() + "' for family. A family with { '"
+ QueryParams.ID.key() + "': '" + parameters.get(QueryParams.ID.key()) + "'} already exists.");
Expand Down Expand Up @@ -731,7 +732,7 @@ OpenCGAResult<Object> privateDelete(ClientSession clientSession, Document family
Query queryCheck = new Query()
.append(ClinicalAnalysisDBAdaptor.QueryParams.FAMILY_UID.key(), familyUid)
.append(ClinicalAnalysisDBAdaptor.QueryParams.STUDY_UID.key(), studyUid);
OpenCGAResult<Long> count = dbAdaptorFactory.getClinicalAnalysisDBAdaptor().count(clientSession, queryCheck);
OpenCGAResult<ClinicalAnalysis> count = dbAdaptorFactory.getClinicalAnalysisDBAdaptor().count(clientSession, queryCheck);
if (count.getNumMatches() > 0) {
throw new CatalogDBException("Could not delete family. Family is in use in " + count.getNumMatches() + " cases");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -965,18 +965,18 @@ public OpenCGAResult restore(long id, QueryOptions queryOptions) throws CatalogD
}

@Override
public OpenCGAResult<Long> count(Query query) throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
public OpenCGAResult<File> count(Query query) throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
return count(null, query);
}

OpenCGAResult<Long> count(ClientSession clientSession, Query query)
OpenCGAResult<File> count(ClientSession clientSession, Query query)
throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
Bson bson = parseQuery(query);
return new OpenCGAResult<>(fileCollection.count(clientSession, bson));
}

@Override
public OpenCGAResult<Long> count(final Query query, final String user)
public OpenCGAResult<File> count(final Query query, final String user)
throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
Bson bson = parseQuery(query, user);
logger.debug("File count: query : {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,23 +275,24 @@ public OpenCGAResult unmarkPermissionRule(long studyId, String permissionRuleId)
}

@Override
public OpenCGAResult<Long> count(Query query) throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
public OpenCGAResult<Individual> count(Query query)
throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
return count(null, query);
}

public OpenCGAResult<Long> count(ClientSession clientSession, Query query)
public OpenCGAResult<Individual> count(ClientSession clientSession, Query query)
throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
Bson bson = parseQuery(query);
return new OpenCGAResult<>(individualCollection.count(clientSession, bson));
}

@Override
public OpenCGAResult<Long> count(Query query, String user)
public OpenCGAResult<Individual> count(Query query, String user)
throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
return count(null, query, user);
}

OpenCGAResult<Long> count(ClientSession clientSession, Query query, String user)
OpenCGAResult<Individual> count(ClientSession clientSession, Query query, String user)
throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
Bson bson = parseQuery(query, user);
logger.debug("Individual count: query : {}, dbTime: {}", bson.toBsonDocument(Document.class,
Expand Down Expand Up @@ -653,7 +654,7 @@ private void checkInUseInClinicalAnalysis(ClientSession clientSession, Document
Query query = new Query()
.append(ClinicalAnalysisDBAdaptor.QueryParams.STUDY_UID.key(), studyUid)
.append(ClinicalAnalysisDBAdaptor.QueryParams.INDIVIDUAL.key(), individualUid);
OpenCGAResult<Long> count = dbAdaptorFactory.getClinicalAnalysisDBAdaptor().count(clientSession, query);
OpenCGAResult<ClinicalAnalysis> count = dbAdaptorFactory.getClinicalAnalysisDBAdaptor().count(clientSession, query);
if (count.getNumMatches() > 0) {
throw new CatalogDBException("Could not delete individual '" + individualId + "'. Individual is in use in "
+ count.getNumMatches() + " cases");
Expand All @@ -675,7 +676,7 @@ UpdateDocument parseAndValidateUpdateParams(ClientSession clientSession, ObjectM
Query tmpQuery = new Query()
.append(QueryParams.ID.key(), parameters.get(QueryParams.ID.key()))
.append(QueryParams.STUDY_UID.key(), studyId);
OpenCGAResult<Long> count = count(clientSession, tmpQuery);
OpenCGAResult<Individual> count = count(clientSession, tmpQuery);
if (count.getNumMatches() > 0) {
throw new CatalogDBException("Cannot set id for individual. An individual with { id: '"
+ parameters.get(QueryParams.ID.key()) + "'} already exists.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,18 @@ public OpenCGAResult updateProjectRelease(long studyId, int release)
}

@Override
public OpenCGAResult<Long> count(Query query) throws CatalogDBException {
public OpenCGAResult<Interpretation> count(Query query) throws CatalogDBException {
return count(null, query);
}

public OpenCGAResult<Long> count(ClientSession clientSession, Query query) throws CatalogDBException {
public OpenCGAResult<Interpretation> count(ClientSession clientSession, Query query) throws CatalogDBException {
Bson bson = parseQuery(query);
logger.debug("Interpretation count: query : {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry()));
return new OpenCGAResult<>(interpretationCollection.count(clientSession, bson));
}

@Override
public OpenCGAResult<Long> count(Query query, String user)
public OpenCGAResult<Interpretation> count(Query query, String user)
throws CatalogDBException {
return count(query);
}
Expand Down Expand Up @@ -415,7 +415,7 @@ private UpdateDocument parseAndValidateUpdateParams(ClientSession clientSession,
tmpQuery = new Query()
.append(QueryParams.ID.key(), parameters.get(QueryParams.ID.key()))
.append(QueryParams.STUDY_UID.key(), studyId);
OpenCGAResult<Long> count = count(clientSession, tmpQuery);
OpenCGAResult<Interpretation> count = count(clientSession, tmpQuery);
if (count.getNumMatches() > 0) {
throw new CatalogDBException("Cannot set id for interpretation. A interpretation with { id: '"
+ parameters.get(QueryParams.ID.key()) + "'} already exists.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,22 +190,22 @@ public OpenCGAResult unmarkPermissionRule(long studyId, String permissionRuleId)
}

@Override
public OpenCGAResult<Long> count(Query query) throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
public OpenCGAResult<Job> count(Query query) throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
return count(null, query);
}

OpenCGAResult<Long> count(ClientSession clientSession, Query query)
OpenCGAResult<Job> count(ClientSession clientSession, Query query)
throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
Bson bsonDocument = parseQuery(query, QueryOptions.empty());
return new OpenCGAResult<>(jobCollection.count(clientSession, bsonDocument));
}


@Override
public OpenCGAResult<Long> count(Query query, String user)
public OpenCGAResult<Job> count(Query query, String user)
throws CatalogDBException, CatalogParameterException, CatalogAuthorizationException {
Bson bson = parseQuery(query, QueryOptions.empty(), user);
logger.debug("Job count: query : {}, dbTime: {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry()));
logger.debug("Job count: query : {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry()));
return new OpenCGAResult<>(jobCollection.count(bson));
}

Expand Down
Loading