void checkCanDeleteSamples(MyResourceIds resources) throws CatalogException {
for (Long sampleId : resources.getResourceIds()) {
authorizationManager.checkSamplePermission(resources.getStudyId(), sampleId, resources.getUser(),
SampleAclEntry.SamplePermissions.DELETE);
}
Query query = new Query()
.append(CohortDBAdaptor.QueryParams.STUDY_UID.key(), resources.getStudyId())
.append(CohortDBAdaptor.QueryParams.SAMPLE_UIDS.key(), resources.getResourceIds())
.append(CohortDBAdaptor.QueryParams.STATUS_NAME.key(), "!=" + Status.DELETED);
long count = cohortDBAdaptor.count(query).first();
if (count > 0) {
if (resources.getResourceIds().size() == 1) {
throw new CatalogException("The sample " + resources.getResourceIds().get(0) + " is part of " + count + " cohorts. Please, "
+ "first update or delete the cohorts");
} else {
throw new CatalogException("Some samples are part of " + count + " cohorts. Please, first update or delete the cohorts");
}
}
}