diff --git a/src/main/java/org/broadinstitute/consent/http/ConsentApplication.java b/src/main/java/org/broadinstitute/consent/http/ConsentApplication.java index 2b5c723172..ffe5d1c387 100644 --- a/src/main/java/org/broadinstitute/consent/http/ConsentApplication.java +++ b/src/main/java/org/broadinstitute/consent/http/ConsentApplication.java @@ -76,8 +76,6 @@ import org.broadinstitute.consent.http.resources.VersionResource; import org.broadinstitute.consent.http.resources.VoteResource; import org.broadinstitute.consent.http.service.AcknowledgementService; -import org.broadinstitute.consent.http.service.AuditService; -import org.broadinstitute.consent.http.service.ConsentService; import org.broadinstitute.consent.http.service.DacService; import org.broadinstitute.consent.http.service.DarCollectionService; import org.broadinstitute.consent.http.service.DataAccessRequestService; @@ -92,7 +90,6 @@ import org.broadinstitute.consent.http.service.MatchService; import org.broadinstitute.consent.http.service.MetricsService; import org.broadinstitute.consent.http.service.NihService; -import org.broadinstitute.consent.http.service.SummaryService; import org.broadinstitute.consent.http.service.SupportRequestService; import org.broadinstitute.consent.http.service.TDRService; import org.broadinstitute.consent.http.service.UserService; @@ -160,7 +157,6 @@ public void run(ConsentConfiguration config, Environment env) { final HttpClientUtil clientUtil = new HttpClientUtil(config.getServicesConfiguration()); // Services - final ConsentService consentService = injector.getProvider(ConsentService.class).get(); final DarCollectionService darCollectionService = injector.getProvider( DarCollectionService.class).get(); final DacService dacService = injector.getProvider(DacService.class).get(); @@ -177,8 +173,6 @@ public void run(ConsentConfiguration config, Environment env) { final MetricsService metricsService = injector.getProvider(MetricsService.class).get(); final UserService userService = injector.getProvider(UserService.class).get(); final VoteService voteService = injector.getProvider(VoteService.class).get(); - final AuditService auditService = injector.getProvider(AuditService.class).get(); - final SummaryService summaryService = injector.getProvider(SummaryService.class).get(); final MatchService matchService = injector.getProvider(MatchService.class).get(); final OAuthAuthenticator authenticator = injector.getProvider(OAuthAuthenticator.class).get(); final LibraryCardService libraryCardService = injector.getProvider(LibraryCardService.class) @@ -224,14 +218,13 @@ public void run(ConsentConfiguration config, Environment env) { env.jersey().register(new DatasetResource(datasetService, userService, dataAccessRequestService, datasetRegistrationService, elasticSearchService)); env.jersey().register(new DatasetAssociationsResource(datasetAssociationService)); - env.jersey() - .register(new ConsentResource(auditService, userService, consentService, matchService)); - env.jersey().register(new ConsentCasesResource(summaryService)); + env.jersey().register(injector.getInstance(ConsentResource.class)); + env.jersey().register(injector.getInstance(ConsentCasesResource.class)); env.jersey().register(new DacResource(dacService, userService, datasetService)); env.jersey().register(new DACUserResource(userService)); env.jersey().register( new DarCollectionResource(darCollectionService, userService)); - env.jersey().register(new DataRequestCasesResource(summaryService)); + env.jersey().register(injector.getInstance(DataRequestCasesResource.class)); env.jersey().register(new DataRequestReportsResource(dataAccessRequestService)); env.jersey().register(new EmailNotifierResource(emailService)); env.jersey().register(new InstitutionResource(userService, institutionService)); diff --git a/src/main/java/org/broadinstitute/consent/http/ConsentModule.java b/src/main/java/org/broadinstitute/consent/http/ConsentModule.java index 07e80fb01e..62a54dadd6 100644 --- a/src/main/java/org/broadinstitute/consent/http/ConsentModule.java +++ b/src/main/java/org/broadinstitute/consent/http/ConsentModule.java @@ -12,8 +12,6 @@ import org.broadinstitute.consent.http.cloudstore.GCSService; import org.broadinstitute.consent.http.configurations.ConsentConfiguration; import org.broadinstitute.consent.http.db.AcknowledgementDAO; -import org.broadinstitute.consent.http.db.ConsentAuditDAO; -import org.broadinstitute.consent.http.db.ConsentDAO; import org.broadinstitute.consent.http.db.CounterDAO; import org.broadinstitute.consent.http.db.DAOContainer; import org.broadinstitute.consent.http.db.DacDAO; @@ -37,8 +35,6 @@ import org.broadinstitute.consent.http.mail.SendGridAPI; import org.broadinstitute.consent.http.mail.freemarker.FreeMarkerTemplateHelper; import org.broadinstitute.consent.http.service.AcknowledgementService; -import org.broadinstitute.consent.http.service.AuditService; -import org.broadinstitute.consent.http.service.ConsentService; import org.broadinstitute.consent.http.service.CounterService; import org.broadinstitute.consent.http.service.DacService; import org.broadinstitute.consent.http.service.DarCollectionService; @@ -57,7 +53,6 @@ import org.broadinstitute.consent.http.service.NihService; import org.broadinstitute.consent.http.service.OntologyService; import org.broadinstitute.consent.http.service.ResearcherService; -import org.broadinstitute.consent.http.service.SummaryService; import org.broadinstitute.consent.http.service.SupportRequestService; import org.broadinstitute.consent.http.service.UseRestrictionConverter; import org.broadinstitute.consent.http.service.UserService; @@ -87,7 +82,6 @@ public class ConsentModule extends AbstractModule { private final Client client; private final Jdbi jdbi; - private final ConsentDAO consentDAO; private final CounterDAO counterDAO; private final ElectionDAO electionDAO; private final VoteDAO voteDAO; @@ -100,7 +94,6 @@ public class ConsentModule extends AbstractModule { private final MatchDAO matchDAO; private final MailMessageDAO mailMessageDAO; private final UserPropertyDAO userPropertyDAO; - private final ConsentAuditDAO consentAuditDAO; private final DataAccessRequestDAO dataAccessRequestDAO; private final DarCollectionDAO darCollectionDAO; private final DarCollectionSummaryDAO darCollectionSummaryDAO; @@ -124,7 +117,6 @@ public class ConsentModule extends AbstractModule { jdbi.installPlugin(new GuavaPlugin()); jdbi.getConfig().get(Gson2Config.class).setGson(GsonUtil.buildGson()); - this.consentDAO = this.jdbi.onDemand(ConsentDAO.class); this.counterDAO = this.jdbi.onDemand(CounterDAO.class); this.electionDAO = this.jdbi.onDemand(ElectionDAO.class); this.voteDAO = this.jdbi.onDemand(VoteDAO.class); @@ -137,7 +129,6 @@ public class ConsentModule extends AbstractModule { this.matchDAO = this.jdbi.onDemand(MatchDAO.class); this.mailMessageDAO = this.jdbi.onDemand(MailMessageDAO.class); this.userPropertyDAO = this.jdbi.onDemand(UserPropertyDAO.class); - this.consentAuditDAO = this.jdbi.onDemand(ConsentAuditDAO.class); this.dataAccessRequestDAO = this.jdbi.onDemand(DataAccessRequestDAO.class); this.darCollectionDAO = this.jdbi.onDemand(DarCollectionDAO.class); this.darCollectionSummaryDAO = this.jdbi.onDemand(DarCollectionSummaryDAO.class); @@ -156,8 +147,6 @@ protected void configure() { @Provides public DAOContainer providesDAOContainer() { DAOContainer container = new DAOContainer(); - container.setConsentAuditDAO(providesConsentAuditDAO()); - container.setConsentDAO(providesConsentDAO()); container.setCounterDAO(providesCounterDAO()); container.setDacDAO(providesDacDAO()); container.setDataAccessRequestDAO(providesDataAccessRequestDAO()); @@ -209,13 +198,6 @@ OAuthAuthenticator providesOAuthAuthenticator() { return new OAuthAuthenticator(providesClient(), providesSamService()); } - @Provides - AuditService providesAuditService() { - return new AuditService( - providesUserDAO(), - providesConsentAuditDAO()); - } - @Provides DarCollectionService providesDarCollectionService() { return new DarCollectionService( @@ -244,18 +226,6 @@ GCSService providesGCSService() { return new GCSService(config.getCloudStoreConfiguration()); } - @Provides - ConsentService providesConsentService() { - return new ConsentService( - providesConsentDAO(), - providesElectionDAO()); - } - - @Provides - ConsentDAO providesConsentDAO() { - return consentDAO; - } - @Provides CounterDAO providesCounterDAO() { return counterDAO; @@ -322,7 +292,6 @@ FreeMarkerTemplateHelper providesFreeMarkerTemplateHelper() { EmailService providesEmailService() { return new EmailService( providesDARCollectionDAO(), - providesConsentDAO(), providesVoteDAO(), providesElectionDAO(), providesUserDAO(), @@ -465,7 +434,6 @@ MatchService providesMatchService() { return new MatchService( providesClient(), config.getServicesConfiguration(), - providesConsentDAO(), providesMatchDAO(), providesDataAccessRequestDAO(), providesDatasetDAO(), @@ -499,11 +467,6 @@ UserPropertyDAO providesUserPropertyDAO() { return userPropertyDAO; } - @Provides - ConsentAuditDAO providesConsentAuditDAO() { - return consentAuditDAO; - } - @Provides InstitutionDAO providesInstitutionDAO() { return institutionDAO; @@ -603,20 +566,6 @@ NihServiceDAO providesNIHServiceDAO() { return new NihServiceDAO(jdbi); } - @Provides - SummaryService providesSummaryService() { - return new SummaryService( - providesDataAccessRequestService(), - providesVoteDAO(), - providesElectionDAO(), - providesUserDAO(), - providesConsentDAO(), - providesDatasetDAO(), - providesMatchDAO(), - providesDARCollectionDAO() - ); - } - @Provides SamService providesSamService() { return new SamService(providesSamDAO()); diff --git a/src/main/java/org/broadinstitute/consent/http/db/ConsentAuditDAO.java b/src/main/java/org/broadinstitute/consent/http/db/ConsentAuditDAO.java deleted file mode 100644 index 204adaa4c0..0000000000 --- a/src/main/java/org/broadinstitute/consent/http/db/ConsentAuditDAO.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.broadinstitute.consent.http.db; - -import java.util.List; -import org.broadinstitute.consent.http.models.ConsentAudit; -import org.jdbi.v3.sqlobject.customizer.BindBean; -import org.jdbi.v3.sqlobject.customizer.BindList; -import org.jdbi.v3.sqlobject.statement.SqlBatch; -import org.jdbi.v3.sqlobject.statement.SqlQuery; -import org.jdbi.v3.sqlobject.statement.SqlUpdate; - -public interface ConsentAuditDAO { - - @SqlUpdate( - " INSERT INTO consent_audit (modified_object_id, modified_table, change_action, modified_by_user_id, modification_date) " - + " VALUES (:modifiedObjectId, :modifiedTable, :changeAction, :modifiedByUserId, :modificationDate)") - void insertWorkspaceAudit(@BindBean ConsentAudit consentAudit); - - @SqlBatch( - " INSERT INTO consent_audit (modified_object_id, modified_table, change_action, modified_by_user_id, modification_date) " - + " VALUES (:modifiedObjectId, :modifiedTable, :changeAction, :modifiedByUserId, :modificationDate)") - void batchInsertWorkspaceAudit(@BindBean List consentAudits); - - @SqlUpdate(" DELETE FROM consent_audit where modified_object_id in () ") - void deleteByObjectIds(@BindList("objectIds") List objectIds); - - @SqlQuery(" SELECT distinct modified_object_id FROM consent_audit ") - List findAllObjectIds(); -} diff --git a/src/main/java/org/broadinstitute/consent/http/db/ConsentDAO.java b/src/main/java/org/broadinstitute/consent/http/db/ConsentDAO.java deleted file mode 100644 index b67b89bcbd..0000000000 --- a/src/main/java/org/broadinstitute/consent/http/db/ConsentDAO.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.broadinstitute.consent.http.db; - -import java.util.Collection; -import java.util.Date; -import java.util.List; -import org.broadinstitute.consent.http.db.mapper.ConsentMapper; -import org.broadinstitute.consent.http.models.Consent; -import org.jdbi.v3.sqlobject.config.RegisterRowMapper; -import org.jdbi.v3.sqlobject.customizer.Bind; -import org.jdbi.v3.sqlobject.customizer.BindList; -import org.jdbi.v3.sqlobject.statement.SqlQuery; -import org.jdbi.v3.sqlobject.statement.SqlUpdate; -import org.jdbi.v3.sqlobject.transaction.Transactional; - -@RegisterRowMapper(ConsentMapper.class) -public interface ConsentDAO extends Transactional { - - /** - * Find consent by id - * - * @return Consent - */ - @SqlQuery("SELECT * FROM consents WHERE consent_id = :consentId AND active=true") - Consent findConsentById(@Bind("consentId") String consentId); - - @SqlQuery("SELECT * FROM consents WHERE consent_id IN ()") - Collection findConsentsFromConsentsIDs(@BindList("consentIds") List consentIds); - - @SqlQuery("SELECT consent_id FROM consents WHERE consent_id = :consentId AND active=true") - String checkConsentById(@Bind("consentId") String consentId); - - @SqlQuery("SELECT consent_id FROM consents WHERE name = :name") - String getIdByName(@Bind("name") String name); - - @SqlQuery("SELECT * FROM consents WHERE name = :name AND active=true") - Consent findConsentByName(@Bind("name") String name); - - - @SqlUpdate(""" - INSERT INTO consents - (consent_id, requires_manual_review, data_use, data_use_letter, active, name, dul_name, - create_date, sort_date, group_name) - VALUES (:consentId, :requiresManualReview, :dataUse, :dataUseLetter, true, :name, - :dulName, :createDate, :sortDate, :groupName) - """) - void insertConsent(@Bind("consentId") String consentId, - @Bind("requiresManualReview") Boolean requiresManualReview, - @Bind("dataUse") String dataUse, - @Bind("dataUseLetter") String dataUseLetter, - @Bind("name") String name, - @Bind("dulName") String dulName, - @Bind("createDate") Date createDate, - @Bind("sortDate") Date sortDate, - @Bind("groupName") String groupName); - - @SqlUpdate("DELETE FROM consents WHERE consent_id = :consentId") - void deleteConsent(@Bind("consentId") String consentId); - - @SqlUpdate(""" - UPDATE consents - SET requires_manual_review = :requiresManualReview, - data_use = :dataUse, - data_use_letter = :dataUseLetter, - name = :name, - dul_name = :dulName, - last_update = :lastUpdate, - sort_date = :sortDate, - group_name = :groupName, - updated = :updated - WHERE consent_id = :consentId - AND active = true - """) - void updateConsent(@Bind("consentId") String consentId, - @Bind("requiresManualReview") Boolean requiresManualReview, - @Bind("dataUse") String dataUse, - @Bind("dataUseLetter") String dataUseLetter, - @Bind("name") String name, - @Bind("dulName") String dulName, - @Bind("lastUpdate") Date createDate, - @Bind("sortDate") Date sortDate, - @Bind("groupName") String groupName, - @Bind("updated") Boolean updateStatus); - - // Consent Association Access Methods - - @SqlUpdate("INSERT INTO consent_associations (consent_id, association_type, dataset_id) VALUES (:consentId, :associationType, :dataSetId)") - void insertConsentAssociation(@Bind("consentId") String consentId, - @Bind("associationType") String associationType, - @Bind("dataSetId") Integer dataSetId); - - @SqlQuery("SELECT association_id FROM consent_associations WHERE dataset_id = :datasetId") - Integer findAssociationsByDataSetId(@Bind("datasetId") Integer datasetId); - - @SqlUpdate("DELETE FROM consent_associations WHERE consent_id = :consentId") - void deleteAllAssociationsForConsent(@Bind("consentId") String consentId); - - @SqlQuery("SELECT requires_manual_review FROM consents WHERE consent_id = :consentId") - Boolean checkManualReview(@Bind("consentId") String consentId); - -} diff --git a/src/main/java/org/broadinstitute/consent/http/db/DAOContainer.java b/src/main/java/org/broadinstitute/consent/http/db/DAOContainer.java index 16c71f5a86..67dc00ad59 100644 --- a/src/main/java/org/broadinstitute/consent/http/db/DAOContainer.java +++ b/src/main/java/org/broadinstitute/consent/http/db/DAOContainer.java @@ -7,7 +7,6 @@ @SuppressWarnings("unused") public class DAOContainer { - private ConsentDAO consentDAO; private CounterDAO counterDAO; private DacDAO dacDAO; private DataAccessRequestDAO dataAccessRequestDAO; @@ -23,19 +22,10 @@ public class DAOContainer { private UserRoleDAO userRoleDAO; private VoteDAO voteDAO; private StudyDAO studyDAO; - private ConsentAuditDAO consentAuditDAO; private InstitutionDAO institutionDAO; private FileStorageObjectDAO fileStorageObjectDAO; private AcknowledgementDAO acknowledgementDAO; - public ConsentDAO getConsentDAO() { - return consentDAO; - } - - public void setConsentDAO(ConsentDAO consentDAO) { - this.consentDAO = consentDAO; - } - public CounterDAO getCounterDAO() { return counterDAO; } @@ -162,14 +152,6 @@ public void setStudyDAO(StudyDAO studyDAO) { this.studyDAO = studyDAO; } - public ConsentAuditDAO getConsentAuditDAO() { - return consentAuditDAO; - } - - public void setConsentAuditDAO(ConsentAuditDAO consentAuditDAO) { - this.consentAuditDAO = consentAuditDAO; - } - public InstitutionDAO getInstitutionDAO() { return institutionDAO; } diff --git a/src/main/java/org/broadinstitute/consent/http/db/DatasetDAO.java b/src/main/java/org/broadinstitute/consent/http/db/DatasetDAO.java index 8af75e94e9..34b3bfc87b 100644 --- a/src/main/java/org/broadinstitute/consent/http/db/DatasetDAO.java +++ b/src/main/java/org/broadinstitute/consent/http/db/DatasetDAO.java @@ -7,7 +7,6 @@ import java.util.Set; import org.broadinstitute.consent.http.db.mapper.ApprovedDatasetMapper; import org.broadinstitute.consent.http.db.mapper.ApprovedDatasetReducer; -import org.broadinstitute.consent.http.db.mapper.AssociationMapper; import org.broadinstitute.consent.http.db.mapper.DatasetDTOWithPropertiesMapper; import org.broadinstitute.consent.http.db.mapper.DatasetMapper; import org.broadinstitute.consent.http.db.mapper.DatasetPropertyMapper; @@ -15,7 +14,6 @@ import org.broadinstitute.consent.http.db.mapper.DictionaryMapper; import org.broadinstitute.consent.http.db.mapper.FileStorageObjectMapperWithFSOPrefix; import org.broadinstitute.consent.http.models.ApprovedDataset; -import org.broadinstitute.consent.http.models.Association; import org.broadinstitute.consent.http.models.Dataset; import org.broadinstitute.consent.http.models.DatasetAudit; import org.broadinstitute.consent.http.models.DatasetProperty; @@ -693,31 +691,11 @@ Set findDatasetsByReceiveOrder( @SqlQuery("SELECT * FROM dictionary ORDER BY key_id") List getDictionaryTerms(); - @SqlQuery( - "SELECT ds.* FROM consent_associations ca " - + "INNER JOIN dataset ds ON ds.dataset_id = ca.dataset_id " - + "WHERE ca.consent_id = :consentId") - List getDatasetsForConsent(@Bind("consentId") String consentId); - - @SqlQuery( - "SELECT ca.consent_id FROM consent_associations ca " - + "INNER JOIN dataset ds on ds.dataset_id = ca.dataset_id " - + "WHERE ds.dataset_id = :dataSetId") - String getAssociatedConsentIdByDatasetId(@Bind("dataSetId") Integer dataSetId); - @SqlQuery("SELECT * FROM dataset WHERE LOWER(name) = LOWER(:name)") Dataset getDatasetByName(@Bind("name") String name); - @RegisterRowMapper(AssociationMapper.class) - @SqlQuery( - "SELECT * FROM consent_associations ca " - + "INNER JOIN dataset ds ON ds.dataset_id = ca.dataset_id " - + "WHERE ds.dataset_id IN ()") - List getAssociationsForDatasetIdList( - @BindList("dataSetIdList") List dataSetIdList); - /** - * DACs -> Consents -> Consent Associations -> Datasets Datasets -> DatasetProperties -> + * DACs -> Datasets Datasets -> DatasetProperties -> * Dictionary * * @return Set of datasets, with properties, that are associated with the provided DAC IDs @@ -744,7 +722,7 @@ WHERE d.dac_id IN () List findDatasetListByDacIds(@BindList("dacIds") List dacIds); /** - * DACs -> Consents -> Consent Associations -> Datasets Datasets -> DatasetProperties -> + * DACs -> Datasets Datasets -> DatasetProperties -> * Dictionary * * @return Set of datasets, with properties, that are associated to any Dac. diff --git a/src/main/java/org/broadinstitute/consent/http/db/mapper/AssociationMapper.java b/src/main/java/org/broadinstitute/consent/http/db/mapper/AssociationMapper.java deleted file mode 100644 index 7f024db94a..0000000000 --- a/src/main/java/org/broadinstitute/consent/http/db/mapper/AssociationMapper.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.broadinstitute.consent.http.db.mapper; - -import java.sql.ResultSet; -import java.sql.SQLException; -import org.broadinstitute.consent.http.models.Association; -import org.jdbi.v3.core.mapper.RowMapper; -import org.jdbi.v3.core.statement.StatementContext; - -public class AssociationMapper implements RowMapper { - - @Override - public Association map(ResultSet r, StatementContext statementContext) throws SQLException { - Association association = new Association(); - association.setAssociationId(r.getInt("association_id")); - association.setConsentId(r.getString("consent_id")); - association.setAssociationType(r.getString("association_type")); - association.setObjectId(r.getString("object_id")); - association.setDataSetId(r.getInt("dataset_id")); - return association; - } -} diff --git a/src/main/java/org/broadinstitute/consent/http/db/mapper/ConsentMapper.java b/src/main/java/org/broadinstitute/consent/http/db/mapper/ConsentMapper.java deleted file mode 100644 index 90a3f02067..0000000000 --- a/src/main/java/org/broadinstitute/consent/http/db/mapper/ConsentMapper.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.broadinstitute.consent.http.db.mapper; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; -import org.broadinstitute.consent.http.models.Consent; -import org.broadinstitute.consent.http.models.DataUse; -import org.jdbi.v3.core.mapper.RowMapper; -import org.jdbi.v3.core.statement.StatementContext; - -public class ConsentMapper implements RowMapper { - - private Map consentMap = new HashMap<>(); - - public Consent map(ResultSet r, StatementContext ctx) throws SQLException { - Consent consent; - if (!consentMap.containsKey(r.getString("consent_id"))) { - consent = new Consent(); - consent.setConsentId(r.getString("consent_id")); - } else { - consent = consentMap.get(r.getString("consent_id")); - } - consent.setRequiresManualReview(r.getBoolean("requires_manual_review")); - consent.setDataUseLetter(r.getString("data_use_letter")); - consent.setDulName(r.getString("dul_name")); - consent.setDataUse(DataUse.parseDataUse(r.getString("data_use")).orElse(null)); - consent.setName(r.getString("name")); - consent.setCreateDate(r.getTimestamp("create_date")); - consent.setSortDate(r.getTimestamp("sort_date")); - consent.setLastUpdate(r.getTimestamp("last_update")); - consent.setGroupName(r.getString("group_name")); - consent.setUpdated(r.getBoolean("updated")); - consentMap.put(consent.getConsentId(), consent); - return consent; - } -} diff --git a/src/main/java/org/broadinstitute/consent/http/db/mapper/DatasetDTOWithPropertiesMapper.java b/src/main/java/org/broadinstitute/consent/http/db/mapper/DatasetDTOWithPropertiesMapper.java index bc43f5578a..f96ad88507 100644 --- a/src/main/java/org/broadinstitute/consent/http/db/mapper/DatasetDTOWithPropertiesMapper.java +++ b/src/main/java/org/broadinstitute/consent/http/db/mapper/DatasetDTOWithPropertiesMapper.java @@ -32,7 +32,6 @@ public DatasetDTO map(ResultSet r, StatementContext ctx) throws SQLException { } datasetDTO.setAlias(alias); datasetDTO.setDataSetId(dataSetId); - // Both Consents and Datasets store DataUse in `data_use`. if (hasColumn(r, "data_use")) { datasetDTO.setDataUse(DataUse.parseDataUse(r.getString("data_use")).orElse(null)); } diff --git a/src/main/java/org/broadinstitute/consent/http/db/mapper/DatasetReducer.java b/src/main/java/org/broadinstitute/consent/http/db/mapper/DatasetReducer.java index cb304b4a01..6b76f46b8d 100644 --- a/src/main/java/org/broadinstitute/consent/http/db/mapper/DatasetReducer.java +++ b/src/main/java/org/broadinstitute/consent/http/db/mapper/DatasetReducer.java @@ -22,9 +22,6 @@ public void accumulate(Map map, RowView rowView) { if (hasColumn(rowView, "dac_id", Integer.class)) { dataset.setDacId(rowView.getColumn("dac_id", Integer.class)); } - if (hasColumn(rowView, "consent_id", String.class)) { - dataset.setConsentId(rowView.getColumn("consent_id", String.class)); - } if (hasColumn(rowView, "data_use", String.class)) { dataset.setDataUse( DataUse.parseDataUse(rowView.getColumn("data_use", String.class)).orElse(null)); diff --git a/src/main/java/org/broadinstitute/consent/http/enumeration/AuditTable.java b/src/main/java/org/broadinstitute/consent/http/enumeration/AuditTable.java deleted file mode 100644 index 7b998e5285..0000000000 --- a/src/main/java/org/broadinstitute/consent/http/enumeration/AuditTable.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.broadinstitute.consent.http.enumeration; - -public enum AuditTable { - - CONSENT_ASSOCIATIONS("consentassociations"), CONSENT("consents"); - - private final String value; - - AuditTable(String value) { - this.value = value; - } - - public String getValue() { - return value; - } -} diff --git a/src/main/java/org/broadinstitute/consent/http/models/Association.java b/src/main/java/org/broadinstitute/consent/http/models/Association.java deleted file mode 100644 index db01ac7136..0000000000 --- a/src/main/java/org/broadinstitute/consent/http/models/Association.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.broadinstitute.consent.http.models; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Association Representation object. This class represents a single row of consentassociation data. - * There can be many `associations` to a single consent which would indicate multiple datasets using - * the same consent. See also: ConsentAssociation - */ -public class Association { - - @JsonProperty - public Integer associationId; - - @JsonProperty - public String consentId; - - @JsonProperty - public String associationType; - - @JsonProperty - public String objectId; - - @JsonProperty - public Integer dataSetId; - - public Integer getAssociationId() { - return associationId; - } - - public void setAssociationId(Integer associationId) { - this.associationId = associationId; - } - - public String getConsentId() { - return consentId; - } - - public void setConsentId(String consentId) { - this.consentId = consentId; - } - - public String getAssociationType() { - return associationType; - } - - public void setAssociationType(String associationType) { - this.associationType = associationType; - } - - public String getObjectId() { - return objectId; - } - - public Integer getDataSetId() { - return dataSetId; - } - - public void setDataSetId(Integer dataSetId) { - this.dataSetId = dataSetId; - } - - public void setObjectId(String objectId) { - this.objectId = objectId; - } -} diff --git a/src/main/java/org/broadinstitute/consent/http/models/Consent.java b/src/main/java/org/broadinstitute/consent/http/models/Consent.java deleted file mode 100644 index c9ad158cc0..0000000000 --- a/src/main/java/org/broadinstitute/consent/http/models/Consent.java +++ /dev/null @@ -1,194 +0,0 @@ -package org.broadinstitute.consent.http.models; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.sql.Timestamp; - -/** - * Consent Representation object. - *

- * Created by grushton on 6/3/15. - */ - -public class Consent { - - @JsonProperty - public String consentId; - - @JsonProperty - public String lastElectionStatus; - - @JsonProperty - public Boolean lastElectionArchived; - - @JsonProperty - public Boolean requiresManualReview; - - @JsonProperty - public String dataUseLetter; - - @JsonProperty - public String name; - - @JsonProperty - public String dulName; - - @JsonProperty - public Timestamp createDate; - - @JsonProperty - public Timestamp lastUpdate; - - @JsonProperty - public Timestamp sortDate; - - @JsonProperty - public DataUse dataUse; - - @JsonProperty - public String groupName; - - @JsonProperty - public boolean updateStatus; - - public Consent() { - } - - public Consent(Boolean requiresManualReview, String dataUseLetter, - String name, Timestamp createDate, Timestamp sortDate, Timestamp lastUpdate, - String groupName) { - this.requiresManualReview = requiresManualReview; - this.dataUseLetter = dataUseLetter; - this.name = name; - this.createDate = createDate; - this.sortDate = sortDate; - this.lastUpdate = lastUpdate; - this.groupName = groupName; - } - - @JsonProperty - public Timestamp getCreateDate() { - return createDate; - } - - @JsonProperty - public void setCreateDate(Timestamp createDate) { - this.createDate = createDate; - } - - @JsonProperty - public Timestamp getLastUpdate() { - return lastUpdate; - } - - @JsonProperty - public void setLastUpdate(Timestamp lastUpdate) { - this.lastUpdate = lastUpdate; - } - - @JsonProperty - public Timestamp getSortDate() { - return sortDate; - } - - @JsonProperty - public void setSortDate(Timestamp sortDate) { - this.sortDate = sortDate; - } - - @JsonProperty - public String getDataUseLetter() { - return dataUseLetter; - } - - @JsonProperty - public void setDataUseLetter(String dataUseLetter) { - this.dataUseLetter = dataUseLetter; - } - - @JsonProperty - public Boolean getRequiresManualReview() { - return requiresManualReview; - } - - @JsonProperty - public void setRequiresManualReview(Boolean requiresManualReview) { - this.requiresManualReview = requiresManualReview; - } - - @JsonProperty - public String getName() { - return name; - } - - @JsonProperty - public void setName(String name) { - this.name = name; - } - - @JsonProperty - public String getConsentId() { - return consentId; - } - - @JsonProperty - public void setConsentId(String consentId) { - this.consentId = consentId; - } - - @JsonProperty - public String getDulName() { - return dulName; - } - - @JsonProperty - public void setDulName(String dulName) { - this.dulName = dulName; - } - - @JsonProperty - public DataUse getDataUse() { - return dataUse; - } - - @JsonProperty - public void setDataUse(DataUse dataUse) { - this.dataUse = dataUse; - } - - @JsonProperty - public String getGroupName() { - return groupName; - } - - @JsonProperty - public void setGroupName(String groupName) { - this.groupName = groupName; - } - - public String getLastElectionStatus() { - return lastElectionStatus; - } - - @JsonProperty - public void setLastElectionStatus(String lastElectionStatus) { - this.lastElectionStatus = lastElectionStatus; - } - - public Boolean getLastElectionArchived() { - return lastElectionArchived; - } - - public void setLastElectionArchived(Boolean lastElectionArchived) { - this.lastElectionArchived = lastElectionArchived; - } - - public boolean getUpdated() { - return updateStatus; - } - - @JsonProperty - public void setUpdated(boolean updateStatus) { - this.updateStatus = updateStatus; - } -} - diff --git a/src/main/java/org/broadinstitute/consent/http/models/ConsentAssociation.java b/src/main/java/org/broadinstitute/consent/http/models/ConsentAssociation.java deleted file mode 100644 index d7f149257e..0000000000 --- a/src/main/java/org/broadinstitute/consent/http/models/ConsentAssociation.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.broadinstitute.consent.http.models; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.Objects; -import com.google.gson.Gson; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; - -/** - * ConsentAssociation Representation object. Represents a set of consentassociations to a single - * "type" of object. For example, the "sampleSet"s associated with an individual consent via the - * dataset id on consentassociations. See also: Association - */ -public class ConsentAssociation { - - @JsonProperty - private String associationType; - - private HashSet elementSet; - - public ConsentAssociation() { - } - - public ConsentAssociation(String atype, List ids) { - this.associationType = atype; - this.elementSet = new HashSet<>(ids); - } - - - public String getAssociationType() { - return associationType; - } - - public void setAssociationType(String atype) { - this.associationType = atype; - } - - @JsonProperty - public ArrayList getElements() { - return new ArrayList<>(elementSet); - } - - @JsonProperty - public void setElements(List ids) { - elementSet = new HashSet<>(ids); - } - - public boolean isAssociationType(String atype) { - return (associationType != null) && associationType.equals(atype); - } - - @Override - public boolean equals(Object o) { - return o instanceof ConsentAssociation && - Objects.equal(this.associationType, ((ConsentAssociation) o).associationType) && - Objects.equal(this.elementSet, ((ConsentAssociation) o).elementSet); - } - - @Override - public int hashCode() { - return Objects.hashCode(associationType, elementSet); - } - - @Override - public String toString() { - return new Gson().toJson(this); - } - -} diff --git a/src/main/java/org/broadinstitute/consent/http/models/ConsentAudit.java b/src/main/java/org/broadinstitute/consent/http/models/ConsentAudit.java deleted file mode 100644 index cf038b8026..0000000000 --- a/src/main/java/org/broadinstitute/consent/http/models/ConsentAudit.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.broadinstitute.consent.http.models; - -import java.util.Date; - -public class ConsentAudit { - - private String modifiedObjectId; - - private String modifiedTable; - - private String changeAction; - - private long modifiedByUserId; - - private Date modificationDate; - - public ConsentAudit(String modifiedObjectId, String modifiedTable, String changeAction, - int modifiedByUserId, Date modificationDate) { - this.modifiedObjectId = modifiedObjectId; - this.modifiedTable = modifiedTable; - this.changeAction = changeAction; - this.modifiedByUserId = modifiedByUserId; - this.modificationDate = modificationDate; - } - - public String getModifiedObjectId() { - return modifiedObjectId; - } - - public String getModifiedTable() { - return modifiedTable; - } - - public String getChangeAction() { - return changeAction; - } - - public long getModifiedByUserId() { - return modifiedByUserId; - } - - public Date getModificationDate() { - return modificationDate; - } -} diff --git a/src/main/java/org/broadinstitute/consent/http/models/ConsentBuilder.java b/src/main/java/org/broadinstitute/consent/http/models/ConsentBuilder.java deleted file mode 100644 index a716534c01..0000000000 --- a/src/main/java/org/broadinstitute/consent/http/models/ConsentBuilder.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.broadinstitute.consent.http.models; - -import java.sql.Timestamp; - -/** - * Syntactic sugar for creating a Consent object. - */ -public class ConsentBuilder { - - private Consent consent; - - public ConsentBuilder() { - consent = new Consent(); - } - - public Consent build() { - return this.consent; - } - - public ConsentBuilder setCreateDate(Timestamp createDate) { - this.consent.setCreateDate(createDate); - return this; - } - - public ConsentBuilder setLastUpdate(Timestamp lastUpdate) { - this.consent.setLastUpdate(lastUpdate); - return this; - } - - public ConsentBuilder setSortDate(Timestamp sortDate) { - this.consent.setSortDate(sortDate); - return this; - } - - public ConsentBuilder setDataUseLetter(String dataUseLetter) { - this.consent.setDataUseLetter(dataUseLetter); - return this; - } - - public ConsentBuilder setRequiresManualReview(Boolean requiresManualReview) { - this.consent.setRequiresManualReview(requiresManualReview); - return this; - } - - public ConsentBuilder setName(String name) { - this.consent.setName(name); - return this; - } - - public ConsentBuilder setConsentId(String consentId) { - this.consent.setConsentId(consentId); - return this; - } - - public ConsentBuilder setDulName(String dulName) { - this.consent.setDulName(dulName); - return this; - } - - public ConsentBuilder setDataUse(DataUse dataUse) { - this.consent.setDataUse(dataUse); - return this; - } - - public ConsentBuilder setGroupName(String groupName) { - this.consent.setGroupName(groupName); - return this; - } - -} diff --git a/src/main/java/org/broadinstitute/consent/http/models/ConsentSummaryDetail.java b/src/main/java/org/broadinstitute/consent/http/models/ConsentSummaryDetail.java deleted file mode 100644 index ab67e2e78e..0000000000 --- a/src/main/java/org/broadinstitute/consent/http/models/ConsentSummaryDetail.java +++ /dev/null @@ -1,188 +0,0 @@ -package org.broadinstitute.consent.http.models; - -import java.util.Collection; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.IntStream; -import org.broadinstitute.consent.http.enumeration.HeaderSummary; -import org.broadinstitute.consent.http.enumeration.VoteType; - -public class ConsentSummaryDetail implements SummaryDetail { - - private Election election; - private Consent consent; - private List electionVotes; - private Collection electionUsers; - private Vote chairPersonVote; - private User chairPerson; - private Integer maxNumberOfElectionUsers; - - public ConsentSummaryDetail( - Election election, - Consent consent, - List electionVotes, - Collection electionUsers, - Vote chairPersonVote, - User chairPerson, - Integer maxNumberOfElectionUsers) { - setElection(election); - setConsent(consent); - setElectionVotes(electionVotes); - setElectionUsers(electionUsers); - setChairPersonVote(chairPersonVote); - setChairPerson(chairPerson); - setMaxNumberOfElectionUsers(maxNumberOfElectionUsers); - } - - private static final String TAB = "\t"; - - public String headers() { - StringBuilder builder = new StringBuilder(); - builder - .append(HeaderSummary.CONSENT.getValue()) - .append(TAB) - .append(HeaderSummary.VERSION.getValue()) - .append(TAB) - .append(HeaderSummary.STATUS.getValue()) - .append(TAB) - .append(HeaderSummary.ARCHIVED.getValue()) - .append(TAB) - .append(HeaderSummary.STRUCT_LIMITATIONS.getValue()) - .append(TAB) - .append(HeaderSummary.DATE.getValue()) - .append(TAB) - .append(HeaderSummary.CHAIRPERSON.getValue()) - .append(TAB) - .append(HeaderSummary.FINAL_DECISION.getValue()) - .append(TAB) - .append(HeaderSummary.FINAL_DECISION_RATIONALE.getValue()) - .append(TAB); - IntStream.rangeClosed(1, getMaxNumberOfElectionUsers()) - .forEach( - i -> - builder - .append(HeaderSummary.USER.getValue()) - .append(TAB) - .append(HeaderSummary.VOTE.getValue()) - .append(TAB) - .append(HeaderSummary.RATIONALE.getValue()) - .append(TAB)); - builder - .append(HeaderSummary.USER.getValue()) - .append(TAB) - .append(HeaderSummary.VOTE.getValue()) - .append(TAB) - .append(HeaderSummary.RATIONALE.getValue()) - .append(System.lineSeparator()); - return builder.toString(); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - if (Objects.nonNull(getConsent())) { - builder.append(delimiterCheck(getConsent().getName())); - } - builder.append(TAB); - builder.append(getElection().getVersion()); - builder.append(TAB); - builder.append(getElection().getStatus()); - builder.append(TAB); - builder.append(booleanToString(getElection().getArchived())); - builder.append(TAB); - builder.append(""); - builder.append(TAB); - builder.append(formatLongToDate(getConsent().getCreateDate().getTime())); - builder.append(TAB); - if (Objects.nonNull(getChairPerson())) { - builder.append(nullToString(getChairPerson().getDisplayName())); - } - builder.append(TAB); - if (Objects.nonNull(getChairPersonVote())) { - builder.append(booleanToString(getChairPersonVote().getVote())); - } - builder.append(TAB); - if (Objects.nonNull(getChairPersonVote())) { - builder.append(unwrapLines(nullToString(getChairPersonVote().getRationale()))); - } - builder.append(TAB); - getElectionVotes().stream() - .filter(ev -> ev.getType().equals(VoteType.DAC.getValue())) - .forEach( - v -> { - Optional user = - getElectionUsers().stream() - .filter(u -> v.getUserId().equals(u.getUserId())) - .findFirst(); - user.ifPresent(value -> builder.append(value.getDisplayName())); - builder.append(TAB); - builder.append(booleanToString(v.getVote())); - builder.append(TAB); - builder.append(unwrapLines(nullToString(v.getRationale()))); - builder.append(TAB); - // Append extra tabs for the case where there are more election users in other rows - // than there are election users for this row. - builder.append( - TAB.repeat( - Math.max(0, (getMaxNumberOfElectionUsers() - getElectionUsers().size())))); - }); - return builder.toString(); - } - - private Election getElection() { - return election; - } - - private void setElection(Election election) { - this.election = election; - } - - private Consent getConsent() { - return consent; - } - - private void setConsent(Consent consent) { - this.consent = consent; - } - - private List getElectionVotes() { - return electionVotes; - } - - private void setElectionVotes(List electionVotes) { - this.electionVotes = electionVotes; - } - - private Collection getElectionUsers() { - return electionUsers; - } - - private void setElectionUsers(Collection electionUsers) { - this.electionUsers = electionUsers; - } - - private Vote getChairPersonVote() { - return chairPersonVote; - } - - private void setChairPersonVote(Vote chairPersonVote) { - this.chairPersonVote = chairPersonVote; - } - - private User getChairPerson() { - return chairPerson; - } - - private void setChairPerson(User chairPerson) { - this.chairPerson = chairPerson; - } - - private Integer getMaxNumberOfElectionUsers() { - return maxNumberOfElectionUsers; - } - - private void setMaxNumberOfElectionUsers(Integer maxNumberOfElectionUsers) { - this.maxNumberOfElectionUsers = maxNumberOfElectionUsers; - } -} diff --git a/src/main/java/org/broadinstitute/consent/http/models/Dataset.java b/src/main/java/org/broadinstitute/consent/http/models/Dataset.java index f915dc37e2..1bb7e52bc0 100644 --- a/src/main/java/org/broadinstitute/consent/http/models/Dataset.java +++ b/src/main/java/org/broadinstitute/consent/http/models/Dataset.java @@ -1,6 +1,7 @@ package org.broadinstitute.consent.http.models; import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Date; @@ -10,10 +11,7 @@ import java.util.Optional; import java.util.Set; import org.apache.commons.lang3.StringUtils; -import com.google.gson.reflect.TypeToken; -import org.bouncycastle.crypto.CryptoServicesRegistrar.Property; import org.broadinstitute.consent.http.enumeration.PropertyType; -import org.broadinstitute.consent.http.models.dataset_registration_v1.ConsentGroup; import org.broadinstitute.consent.http.models.dataset_registration_v1.ConsentGroup.AccessManagement; import org.broadinstitute.consent.http.util.gson.GsonUtil; import org.checkerframework.checker.nullness.qual.NonNull; @@ -28,7 +26,6 @@ public class Dataset { u.create_date AS u_create_date, u.email_preference AS u_email_preference, u.institution_id AS u_institution_id, u.era_commons_id AS u_era_commons_id, k.key, dp.property_value, dp.property_key, dp.property_type, dp.schema_property, dp.property_id, - ca.consent_id, c.translated_use_restriction, s.study_id AS s_study_id, s.name AS s_name, s.description AS s_description, @@ -62,12 +59,10 @@ public class Dataset { LEFT JOIN (SELECT DISTINCT dataset_id AS id FROM dar_dataset) dar_ds_ids ON dar_ds_ids.id = d.dataset_id LEFT JOIN dataset_property dp ON dp.dataset_id = d.dataset_id LEFT JOIN dictionary k ON k.key_id = dp.property_key - LEFT JOIN consent_associations ca ON ca.dataset_id = d.dataset_id LEFT JOIN study s ON s.study_id = d.study_id LEFT JOIN study_property sp ON sp.study_id = s.study_id LEFT JOIN dataset s_dataset ON s_dataset.study_id = s.study_id LEFT JOIN file_storage_object fso ON (fso.entity_id = d.dataset_id::text OR fso.entity_id = s.uuid::text) AND fso.deleted = false - LEFT JOIN consents c ON c.consent_id = ca.consent_id """; private Integer dataSetId; @@ -94,8 +89,6 @@ LEFT JOIN file_storage_object fso ON (fso.entity_id = d.dataset_id::text OR fso. @Deprecated(forRemoval = true) private Boolean active; - private String consentName; - /** * Needs Approval is a deprecated property. The visibility of a dataset is calculated from DAC * approval and the public visibility dataset property @@ -112,8 +105,6 @@ LEFT JOIN file_storage_object fso ON (fso.entity_id = d.dataset_id::text OR fso. private String translatedDataUse; private Integer dacId; - private String consentId; - private Boolean deletable; private FileStorageObject nihInstitutionalCertificationFile; @@ -126,8 +117,6 @@ LEFT JOIN file_storage_object fso ON (fso.entity_id = d.dataset_id::text OR fso. private User createUser; private Study study; - private ConsentGroup consentGroup; - public Dataset() { } @@ -275,14 +264,6 @@ public void setDacApproval(Boolean dacApproval) { this.dacApproval = dacApproval; } - public String getConsentName() { - return consentName; - } - - public void setConsentName(String consentName) { - this.consentName = consentName; - } - public Integer getAlias() { return alias; } @@ -338,14 +319,6 @@ public void setDacId(Integer dacId) { this.dacId = dacId; } - public String getConsentId() { - return consentId; - } - - public void setConsentId(String consentId) { - this.consentId = consentId; - } - public String getTranslatedDataUse() { return translatedDataUse; } diff --git a/src/main/java/org/broadinstitute/consent/http/resources/ConsentCasesResource.java b/src/main/java/org/broadinstitute/consent/http/resources/ConsentCasesResource.java index 66dfa8cb87..e82e68f4c7 100644 --- a/src/main/java/org/broadinstitute/consent/http/resources/ConsentCasesResource.java +++ b/src/main/java/org/broadinstitute/consent/http/resources/ConsentCasesResource.java @@ -1,5 +1,6 @@ package org.broadinstitute.consent.http.resources; +import com.google.api.client.http.HttpStatusCodes; import com.google.inject.Inject; import io.dropwizard.auth.Auth; import jakarta.annotation.security.PermitAll; @@ -8,59 +9,31 @@ import jakarta.ws.rs.Produces; import jakarta.ws.rs.QueryParam; import jakarta.ws.rs.core.Response; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import org.broadinstitute.consent.http.enumeration.ElectionType; import org.broadinstitute.consent.http.models.AuthUser; -import org.broadinstitute.consent.http.models.Summary; -import org.broadinstitute.consent.http.models.SummaryDetail; -import org.broadinstitute.consent.http.service.SummaryService; @Path("api/consent/cases") public class ConsentCasesResource extends Resource { - private final SummaryService summaryService; - @Inject - public ConsentCasesResource(SummaryService summaryService) { - this.summaryService = summaryService; + public ConsentCasesResource() { } + @Deprecated @GET @Path("/summary") @PermitAll public Response getConsentSummaryCases(@Auth AuthUser authUser) { - Summary summary = summaryService.describeConsentSummaryCases(); - return Response.ok().entity(summary).build(); + return Response.status(HttpStatusCodes.STATUS_CODE_NOT_FOUND).build(); } + @Deprecated @GET @Path("/summary/file") @Produces("text/plain") @PermitAll public Response getConsentSummaryDetailFile(@QueryParam("type") String type, @Auth AuthUser authUser) { - try { - if (Objects.isNull(type)) { - type = ElectionType.DATA_ACCESS.getValue(); - } - List details = new ArrayList<>(); - if (type.equals(ElectionType.TRANSLATE_DUL.getValue())) { - details = summaryService.describeConsentSummaryDetail(); - } else if (type.equals(ElectionType.DATA_ACCESS.getValue())) { - details = summaryService.listDataAccessRequestSummaryDetails(); - } - if (!details.isEmpty()) { - StringBuilder detailsBuilder = new StringBuilder(); - detailsBuilder.append(details.get(0).headers()).append(System.lineSeparator()); - details.forEach(d -> detailsBuilder.append(d.toString()).append(System.lineSeparator())); - return Response.ok(detailsBuilder.toString()).build(); - } - return Response.ok().build(); - } catch (Exception e) { - return createExceptionResponse(e); - } + return Response.status(HttpStatusCodes.STATUS_CODE_NOT_FOUND).build(); } diff --git a/src/main/java/org/broadinstitute/consent/http/resources/ConsentResource.java b/src/main/java/org/broadinstitute/consent/http/resources/ConsentResource.java index 0ef7a8f21f..70f029a641 100644 --- a/src/main/java/org/broadinstitute/consent/http/resources/ConsentResource.java +++ b/src/main/java/org/broadinstitute/consent/http/resources/ConsentResource.java @@ -1,6 +1,6 @@ package org.broadinstitute.consent.http.resources; -import com.google.api.client.http.GenericUrl; +import com.google.api.client.http.HttpStatusCodes; import com.google.inject.Inject; import io.dropwizard.auth.Auth; import jakarta.annotation.security.PermitAll; @@ -18,35 +18,13 @@ import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.UriInfo; -import java.net.URI; -import org.broadinstitute.consent.http.enumeration.AuditActions; -import org.broadinstitute.consent.http.enumeration.AuditTable; -import org.broadinstitute.consent.http.exceptions.UnknownIdentifierException; -import org.broadinstitute.consent.http.exceptions.UpdateConsentException; import org.broadinstitute.consent.http.models.AuthUser; -import org.broadinstitute.consent.http.models.Consent; -import org.broadinstitute.consent.http.models.Error; -import org.broadinstitute.consent.http.models.User; -import org.broadinstitute.consent.http.service.AuditService; -import org.broadinstitute.consent.http.service.ConsentService; -import org.broadinstitute.consent.http.service.MatchService; -import org.broadinstitute.consent.http.service.UserService; @Path("api/consent") public class ConsentResource extends Resource { - private final ConsentService consentService; - private final AuditService auditService; - private final MatchService matchService; - private final UserService userService; - @Inject - public ConsentResource(AuditService auditService, UserService userService, - ConsentService consentService, MatchService matchService) { - this.auditService = auditService; - this.consentService = consentService; - this.userService = userService; - this.matchService = matchService; + public ConsentResource() { } @Deprecated @@ -55,62 +33,25 @@ public ConsentResource(AuditService auditService, UserService userService, @Produces("application/json") @PermitAll public Response describe(@PathParam("id") String id) { - try { - return Response.ok(populateFromApi(id)) - .build(); - } catch (UnknownIdentifierException e) { - return Response.status(Response.Status.NOT_FOUND).entity( - new Error(String.format("Could not find consent with id %s", id), - Response.Status.NOT_FOUND.getStatusCode())).build(); - } + return Response.status(HttpStatusCodes.STATUS_CODE_NOT_FOUND).build(); } + @Deprecated @POST @Consumes("application/json") @RolesAllowed({ADMIN, RESEARCHER, DATAOWNER}) - public Response createConsent(@Context UriInfo info, Consent rec, @Auth AuthUser user) { - try { - User dacUser = userService.findUserByEmail(user.getEmail()); - if (rec.getDataUse() == null) { - throw new IllegalArgumentException("Data Use Object is required."); - } - if (rec.getDataUseLetter() != null) { - checkValidDUL(rec); - } - Consent consent = consentService.create(rec); - auditService.saveConsentAudit(consent.getConsentId(), AuditTable.CONSENT.getValue(), - AuditActions.CREATE.getValue(), dacUser.getEmail()); - URI uri = info.getRequestUriBuilder().path("{id}").build(consent.consentId); - matchService.reprocessMatchesForConsent(consent.consentId); - return Response.created(uri).build(); - } catch (Exception e) { - return createExceptionResponse(e); - } + public Response createConsent(@Context UriInfo info, String rec, @Auth AuthUser user) { + return Response.status(HttpStatusCodes.STATUS_CODE_NOT_FOUND).build(); } + @Deprecated @Path("{id}") @PUT @Consumes("application/json") @Produces("application/json") @RolesAllowed({ADMIN, RESEARCHER, DATAOWNER}) - public Response update(@PathParam("id") String id, Consent updated, @Auth AuthUser user) { - try { - checkConsentElection(id); - if (updated.getDataUse() == null) { - throw new IllegalArgumentException("Data Use Object is required."); - } - if (updated.getDataUseLetter() != null) { - checkValidDUL(updated); - } - User dacUser = userService.findUserByEmail(user.getEmail()); - updated = consentService.update(id, updated); - auditService.saveConsentAudit(updated.getConsentId(), AuditTable.CONSENT.getValue(), - AuditActions.REPLACE.getValue(), dacUser.getEmail()); - matchService.reprocessMatchesForConsent(id); - return Response.ok(updated).build(); - } catch (Exception e) { - return createExceptionResponse(e); - } + public Response update(@PathParam("id") String id, String updated, @Auth AuthUser user) { + return Response.status(HttpStatusCodes.STATUS_CODE_NOT_FOUND).build(); } @@ -120,66 +61,26 @@ public Response update(@PathParam("id") String id, Consent updated, @Auth AuthUs @Path("{id}") @RolesAllowed(ADMIN) public Response delete(@PathParam("id") String consentId) { - try { - consentService.delete(consentId); - return Response.ok().build(); - } catch (Exception e) { - return createExceptionResponse(e); - } + return Response.status(HttpStatusCodes.STATUS_CODE_NOT_FOUND).build(); } + @Deprecated @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/matches") @PermitAll public Response getMatches(@PathParam("id") String purposeId, @Context UriInfo info) { - try { - return Response.status(Response.Status.OK) - .entity(matchService.findMatchByConsentId(purposeId)).build(); - } catch (Exception e) { - return Response.status(Response.Status.NOT_FOUND) - .entity(new Error(e.getMessage(), Response.Status.NOT_FOUND.getStatusCode())).build(); - } + return Response.status(HttpStatusCodes.STATUS_CODE_NOT_FOUND).build(); } + @Deprecated @GET @Produces(MediaType.APPLICATION_JSON) @PermitAll public Response getByName(@QueryParam("name") String name, @Context UriInfo info) { - try { - Consent consent = consentService.getByName(name); - return Response.ok(consent).build(); - } catch (UnknownIdentifierException ex) { - return Response.status(Response.Status.NOT_FOUND).entity( - new Error(String.format("Consent with a name of '%s' was not found.", name), - Response.Status.NOT_FOUND.getStatusCode())).build(); - } - } - - - private Consent populateFromApi(String id) throws UnknownIdentifierException { - return consentService.retrieve(id); - } - - private void checkValidDUL(Consent rec) { - // ensure that the URL is a valid one - try { - new GenericUrl(rec.getDataUseLetter()); - } catch (Exception e) { - throw new IllegalArgumentException("Invalid Data Use Letter URL: " + rec.getDataUseLetter()); - } + return Response.status(HttpStatusCodes.STATUS_CODE_NOT_FOUND).build(); } - private void checkConsentElection(String consentId) throws Exception { - Consent consent = populateFromApi(consentId); - Boolean consentElectionArchived = consent.getLastElectionArchived(); - - if (consentElectionArchived != null && !consentElectionArchived) { - // NOTE: we still need to define a proper error message that clarifies the cause of the error. - throw new UpdateConsentException( - String.format("Consent '%s' cannot be updated with an active election.", consentId)); - } - } } diff --git a/src/main/java/org/broadinstitute/consent/http/resources/DataRequestCasesResource.java b/src/main/java/org/broadinstitute/consent/http/resources/DataRequestCasesResource.java index 222e258baf..b35dc9caf6 100644 --- a/src/main/java/org/broadinstitute/consent/http/resources/DataRequestCasesResource.java +++ b/src/main/java/org/broadinstitute/consent/http/resources/DataRequestCasesResource.java @@ -1,5 +1,6 @@ package org.broadinstitute.consent.http.resources; +import com.google.api.client.http.HttpStatusCodes; import com.google.inject.Inject; import io.dropwizard.auth.Auth; import jakarta.annotation.security.PermitAll; @@ -7,37 +8,31 @@ import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; import jakarta.ws.rs.core.Response; -import java.util.List; import org.broadinstitute.consent.http.models.AuthUser; -import org.broadinstitute.consent.http.models.Summary; -import org.broadinstitute.consent.http.service.SummaryService; @Path("api/dataRequest/cases") public class DataRequestCasesResource extends Resource { - private final SummaryService summaryService; - @Inject - public DataRequestCasesResource(SummaryService summaryService) { - this.summaryService = summaryService; + public DataRequestCasesResource() { } + @Deprecated @GET @Path("/summary/{type}") @PermitAll public Response getDataRequestSummaryCases(@PathParam("type") String type, @Auth AuthUser authUser) { - Summary summary = summaryService.describeDataRequestSummaryCases(type); - return Response.ok().entity(summary).build(); + return Response.status(HttpStatusCodes.STATUS_CODE_NOT_FOUND).build(); } + @Deprecated @GET @Path("/matchsummary") @PermitAll public Response getMatchSummaryCases(@Auth AuthUser authUser) { - List

summaries = summaryService.describeMatchSummaryCases(); - return Response.ok().entity(summaries).build(); + return Response.status(HttpStatusCodes.STATUS_CODE_NOT_FOUND).build(); } diff --git a/src/main/java/org/broadinstitute/consent/http/service/AuditService.java b/src/main/java/org/broadinstitute/consent/http/service/AuditService.java deleted file mode 100644 index b664b711b4..0000000000 --- a/src/main/java/org/broadinstitute/consent/http/service/AuditService.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.broadinstitute.consent.http.service; - -import com.google.inject.Inject; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import org.broadinstitute.consent.http.db.ConsentAuditDAO; -import org.broadinstitute.consent.http.db.UserDAO; -import org.broadinstitute.consent.http.models.ConsentAudit; - -public class AuditService { - - private final UserDAO userDAO; - private final ConsentAuditDAO consentAuditDAO; - - @Inject - public AuditService(UserDAO userDAO, ConsentAuditDAO dao) { - this.userDAO = userDAO; - this.consentAuditDAO = dao; - } - - public void saveAssociationAuditList(List ids, String modifiedTable, String changeAction, - String modifiedByUserEmail) { - int modifiedByUserId = userDAO.findUserByEmail(modifiedByUserEmail).getUserId(); - List auditList = createAuditList(ids, modifiedTable, changeAction, - modifiedByUserId); - consentAuditDAO.batchInsertWorkspaceAudit(auditList); - } - - private List createAuditList(List ids, String modifiedTable, - String changeAction, int modifiedByUserId) { - List audits = new ArrayList<>(); - Date date = new Date(); - for (String id : ids) { - audits.add(new ConsentAudit(id, modifiedTable, changeAction, modifiedByUserId, date)); - } - return audits; - } - - public void saveConsentAudit(String consentId, String modifiedTable, String changeAction, - String modifiedByUserEmail) { - int modifiedByUserId = userDAO.findUserByEmail(modifiedByUserEmail).getUserId(); - saveAuditInfo( - new ConsentAudit(consentId, modifiedTable, changeAction, modifiedByUserId, new Date())); - } - - private void saveAuditInfo(ConsentAudit auditInfo) { - consentAuditDAO.insertWorkspaceAudit(auditInfo); - } - -} diff --git a/src/main/java/org/broadinstitute/consent/http/service/ConsentService.java b/src/main/java/org/broadinstitute/consent/http/service/ConsentService.java deleted file mode 100644 index 081b079612..0000000000 --- a/src/main/java/org/broadinstitute/consent/http/service/ConsentService.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.broadinstitute.consent.http.service; - -import com.google.inject.Inject; -import jakarta.ws.rs.NotFoundException; -import java.sql.Timestamp; -import java.util.Date; -import java.util.List; -import java.util.Objects; -import java.util.UUID; -import org.apache.commons.lang3.StringUtils; -import org.broadinstitute.consent.http.db.ConsentDAO; -import org.broadinstitute.consent.http.db.ElectionDAO; -import org.broadinstitute.consent.http.enumeration.DataUseTranslationType; -import org.broadinstitute.consent.http.enumeration.ElectionType; -import org.broadinstitute.consent.http.exceptions.UnknownIdentifierException; -import org.broadinstitute.consent.http.models.Consent; -import org.broadinstitute.consent.http.models.Election; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ConsentService { - - private final Logger logger; - private final ConsentDAO consentDAO; - private final ElectionDAO electionDAO; - - @Inject - public ConsentService(ConsentDAO consentDAO, ElectionDAO electionDAO) { - this.consentDAO = consentDAO; - this.electionDAO = electionDAO; - this.logger = LoggerFactory.getLogger(this.getClass()); - } - - public Consent create(Consent rec) { - String id; - if (StringUtils.isNotEmpty(rec.consentId)) { - id = rec.consentId; - } else { - id = UUID.randomUUID().toString(); - } - if (consentDAO.getIdByName(rec.getName()) != null) { - throw new IllegalArgumentException("Consent for the specified name already exist"); - } - if (StringUtils.isNotEmpty(rec.consentId) - && consentDAO.checkConsentById(rec.consentId) != null) { - throw new IllegalArgumentException("Consent for the specified id already exist"); - } - Date createDate = new Date(); - consentDAO.insertConsent(id, rec.getRequiresManualReview(), - rec.getDataUse().toString(), - rec.getDataUseLetter(), rec.getName(), rec.getDulName(), createDate, createDate, - rec.getGroupName()); - return consentDAO.findConsentById(id); - } - - public Consent update(String id, Consent rec) throws NotFoundException { - rec = updateConsentDates(rec); - if (StringUtils.isEmpty(consentDAO.checkConsentById(id))) { - throw new NotFoundException(); - } - consentDAO.updateConsent(id, rec.getRequiresManualReview(), - rec.getDataUse().toString(), - rec.getDataUseLetter(), rec.getName(), rec.getDulName(), rec.getLastUpdate(), - rec.getSortDate(), rec.getGroupName(), true); - return consentDAO.findConsentById(id); - } - - public Consent retrieve(String id) throws UnknownIdentifierException { - Consent consent = consentDAO.findConsentById(id); - if (consent == null) { - throw new UnknownIdentifierException(String.format("Could not find consent with id %s", id)); - } - - Election election = electionDAO.findLastElectionByReferenceIdAndType(id, - ElectionType.TRANSLATE_DUL.getValue()); - if (election != null) { - consent.setLastElectionStatus(election.getStatus()); - consent.setLastElectionArchived(election.getArchived()); - } - return consent; - } - - public void delete(String id) throws IllegalArgumentException { - checkConsentExists(id); - List elections = electionDAO.findElectionsWithFinalVoteByReferenceId(id); - if (elections.isEmpty()) { - consentDAO.deleteConsent(id); - consentDAO.deleteAllAssociationsForConsent(id); - } else { - throw new IllegalArgumentException( - "Consent cannot be deleted because already exist elections associated with it"); - } - } - - // Check that the specified Consent resource exists, or throw NotFoundException. - private void checkConsentExists(String consentId) { - String ck_id = consentDAO.checkConsentById(consentId); - logger.debug(String.format("CreateAssocition, checkConsentbyId returned '%s'", - (ck_id == null ? "" : ck_id))); - if (ck_id == null) { - throw new NotFoundException(String.format("Consent with id '%s' not found", consentId)); - } - } - - private Consent updateConsentDates(Consent c) { - Timestamp updateDate = new Timestamp(new Date().getTime()); - c.setLastUpdate(updateDate); - c.setSortDate(updateDate); - return c; - } - - public Consent getByName(String name) throws UnknownIdentifierException { - Consent consent = consentDAO.findConsentByName(name); - if (consent == null) { - throw new UnknownIdentifierException("Consent does not exist"); - } - return consent; - } -} diff --git a/src/main/java/org/broadinstitute/consent/http/service/DataAccessRequestService.java b/src/main/java/org/broadinstitute/consent/http/service/DataAccessRequestService.java index ae2e9e6701..fdbb8cd022 100644 --- a/src/main/java/org/broadinstitute/consent/http/service/DataAccessRequestService.java +++ b/src/main/java/org/broadinstitute/consent/http/service/DataAccessRequestService.java @@ -15,7 +15,6 @@ import java.util.Objects; import java.util.UUID; import org.apache.commons.collections4.CollectionUtils; -import org.broadinstitute.consent.http.db.ConsentDAO; import org.broadinstitute.consent.http.db.DAOContainer; import org.broadinstitute.consent.http.db.DarCollectionDAO; import org.broadinstitute.consent.http.db.DataAccessRequestDAO; @@ -28,7 +27,6 @@ import org.broadinstitute.consent.http.enumeration.DarStatus; import org.broadinstitute.consent.http.enumeration.UserRoles; import org.broadinstitute.consent.http.models.AuthUser; -import org.broadinstitute.consent.http.models.Consent; import org.broadinstitute.consent.http.models.DarCollection; import org.broadinstitute.consent.http.models.DarDataset; import org.broadinstitute.consent.http.models.DataAccessRequest; @@ -42,7 +40,6 @@ public class DataAccessRequestService implements ConsentLogger { - private final ConsentDAO consentDAO; private final CounterService counterService; private final DatasetDAO datasetDAO; private final DataAccessRequestDAO dataAccessRequestDAO; @@ -61,7 +58,6 @@ public class DataAccessRequestService implements ConsentLogger { public DataAccessRequestService(CounterService counterService, DAOContainer container, DacService dacService, DataAccessRequestServiceDAO dataAccessRequestServiceDAO, UseRestrictionConverter useRestrictionConverter) { - this.consentDAO = container.getConsentDAO(); this.counterService = counterService; this.dataAccessRequestDAO = container.getDataAccessRequestDAO(); this.darCollectionDAO = container.getDarCollectionDAO(); @@ -342,11 +338,8 @@ public File createApprovedDARDocument() throws IOException { User user = userDAO.findUserById(dataAccessRequest.getUserId()); Dataset dataset = Objects.nonNull(election.getDataSetId()) ? datasetDAO.findDatasetById( election.getDataSetId()) : null; + String datasetName = Objects.nonNull(dataset) ? dataset.getName() : ""; if (Objects.nonNull(collection) && Objects.nonNull(user) && Objects.nonNull(dataset)) { - String consentId = datasetDAO.getAssociatedConsentIdByDatasetId(dataset.getDataSetId()); - Consent consent = - Objects.nonNull(consentId) ? consentDAO.findConsentById(consentId) : null; - String consentName = Objects.nonNull(consent) ? consent.getName() : ""; String profileName = user.getDisplayName(); if (Objects.isNull(user.getInstitutionId())) { logWarn( @@ -357,7 +350,7 @@ public File createApprovedDARDocument() throws IOException { : institutionDAO.findInstitutionById(user.getInstitutionId()).getName(); String translatedDatasetDataUse = dataset.getTranslatedDataUse(); dataAccessReportsParser.addApprovedDARLine(darWriter, election, dataAccessRequest, - collection.getDarCode(), profileName, institution, consentName, + collection.getDarCode(), profileName, institution, datasetName, translatedDatasetDataUse); } } catch (Exception e) { @@ -391,16 +384,11 @@ public File createReviewedDARDocument() throws IOException { if (Objects.nonNull(dar) && Objects.nonNull(collection)) { Integer datasetId = !CollectionUtils.isEmpty(dar.getDatasetIds()) ? dar.getDatasetIds().get(0) : null; - String consentId = - Objects.nonNull(datasetId) ? datasetDAO.getAssociatedConsentIdByDatasetId(datasetId) - : null; - Consent consent = - Objects.nonNull(consentId) ? consentDAO.findConsentById(consentId) : null; - String consentName = - (Objects.nonNull(consent) && Objects.nonNull(consent.getName())) ? consent.getName() + String datasetName = + (Objects.nonNull(dataset) && Objects.nonNull(dataset.getName())) ? dataset.getName() : ""; dataAccessReportsParser.addReviewedDARLine(darWriter, election, dar, - collection.getDarCode(), consentName, translatedDataUse); + collection.getDarCode(), datasetName, translatedDataUse); } } } diff --git a/src/main/java/org/broadinstitute/consent/http/service/EmailService.java b/src/main/java/org/broadinstitute/consent/http/service/EmailService.java index f7d3d8a73a..0fe71eb64e 100644 --- a/src/main/java/org/broadinstitute/consent/http/service/EmailService.java +++ b/src/main/java/org/broadinstitute/consent/http/service/EmailService.java @@ -18,7 +18,6 @@ import java.util.Set; import java.util.stream.Collectors; import javax.annotation.Nullable; -import org.broadinstitute.consent.http.db.ConsentDAO; import org.broadinstitute.consent.http.db.DarCollectionDAO; import org.broadinstitute.consent.http.db.ElectionDAO; import org.broadinstitute.consent.http.db.MailMessageDAO; @@ -29,7 +28,6 @@ import org.broadinstitute.consent.http.enumeration.UserRoles; import org.broadinstitute.consent.http.mail.SendGridAPI; import org.broadinstitute.consent.http.mail.freemarker.FreeMarkerTemplateHelper; -import org.broadinstitute.consent.http.models.Consent; import org.broadinstitute.consent.http.models.DarCollection; import org.broadinstitute.consent.http.models.DataAccessRequest; import org.broadinstitute.consent.http.models.Election; @@ -41,7 +39,6 @@ public class EmailService { private final DarCollectionDAO collectionDAO; - private final ConsentDAO consentDAO; private final UserDAO userDAO; private final ElectionDAO electionDAO; private final MailMessageDAO emailDAO; @@ -79,12 +76,11 @@ public static String getValue(String value) { } @Inject - public EmailService(DarCollectionDAO collectionDAO, ConsentDAO consentDAO, + public EmailService(DarCollectionDAO collectionDAO, VoteDAO voteDAO, ElectionDAO electionDAO, UserDAO userDAO, MailMessageDAO emailDAO, SendGridAPI sendGridAPI, FreeMarkerTemplateHelper helper, String serverUrl) { this.collectionDAO = collectionDAO; - this.consentDAO = consentDAO; this.userDAO = userDAO; this.electionDAO = electionDAO; this.voteDAO = voteDAO; @@ -331,8 +327,7 @@ private Map retrieveForVote(Integer voteId) { dataMap.put("userName", user.getDisplayName()); dataMap.put("electionType", retrieveElectionTypeString(election.getElectionType())); dataMap.put("entityId", election.getReferenceId()); - dataMap.put("entityName", - retrieveReferenceId(election.getElectionType(), election.getReferenceId())); + dataMap.put("entityName", retrieveReferenceId(election.getReferenceId())); dataMap.put("electionId", election.getElectionId().toString()); dataMap.put("dacUserId", user.getUserId().toString()); dataMap.put("email", user.getEmail()); @@ -369,14 +364,9 @@ private Map retrieveForNewDAR(String dataAccessRequestId, User u return dataMap; } - private String retrieveReferenceId(String electionType, String referenceId) { - if (electionType.equals(ElectionType.TRANSLATE_DUL.getValue())) { - Consent consent = consentDAO.findConsentById(referenceId); - return Objects.nonNull(consent) ? consent.getName() : " "; - } else { - DarCollection collection = collectionDAO.findDARCollectionByReferenceId(referenceId); - return Objects.nonNull(collection) ? collection.getDarCode() : " "; - } + private String retrieveReferenceId(String referenceId) { + DarCollection collection = collectionDAO.findDARCollectionByReferenceId(referenceId); + return Objects.nonNull(collection) ? collection.getDarCode() : " "; } private String retrieveElectionTypeString(String electionType) { diff --git a/src/main/java/org/broadinstitute/consent/http/service/MatchService.java b/src/main/java/org/broadinstitute/consent/http/service/MatchService.java index 2f2df7f4d1..6ba55954ce 100644 --- a/src/main/java/org/broadinstitute/consent/http/service/MatchService.java +++ b/src/main/java/org/broadinstitute/consent/http/service/MatchService.java @@ -12,13 +12,10 @@ import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; import java.util.ArrayList; -import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; import org.broadinstitute.consent.http.configurations.ServicesConfiguration; -import org.broadinstitute.consent.http.db.ConsentDAO; import org.broadinstitute.consent.http.db.DataAccessRequestDAO; import org.broadinstitute.consent.http.db.DatasetDAO; import org.broadinstitute.consent.http.db.MatchDAO; @@ -34,19 +31,16 @@ public class MatchService implements ConsentLogger { private final MatchDAO matchDAO; - private final ConsentDAO consentDAO; private final UseRestrictionConverter useRestrictionConverter; private final DataAccessRequestDAO dataAccessRequestDAO; private final DatasetDAO datasetDAO; private final WebTarget matchServiceTargetV3; @Inject - public MatchService(Client client, ServicesConfiguration config, ConsentDAO consentDAO, - MatchDAO matchDAO, + public MatchService(Client client, ServicesConfiguration config, MatchDAO matchDAO, DataAccessRequestDAO dataAccessRequestDAO, DatasetDAO datasetDAO, UseRestrictionConverter useRestrictionConverter) { this.matchDAO = matchDAO; - this.consentDAO = consentDAO; this.dataAccessRequestDAO = dataAccessRequestDAO; this.useRestrictionConverter = useRestrictionConverter; this.datasetDAO = datasetDAO; @@ -92,14 +86,6 @@ public List findMatchesForLatestDataAccessElectionsByPurposeIds(List matches = createMatchesForConsent(consentId); - insertMatches(matches); - } - } - public void reprocessMatchesForPurpose(String purposeId) { removeMatchesForPurpose(purposeId); DataAccessRequest dar = dataAccessRequestDAO.findByReferenceId(purposeId); @@ -114,11 +100,6 @@ public void removeMatchesForPurpose(String purposeId) { matchDAO.deleteMatchesByPurposeId(purposeId); } - public void removeMatchesForConsent(String consentId) { - matchDAO.deleteRationalesByConsentIds(List.of(consentId)); - matchDAO.deleteMatchesByConsentId(consentId); - } - protected List createMatchesForDataAccessRequest(DataAccessRequest dar) { List matches = new ArrayList<>(); dar.getDatasetIds().forEach(id -> { @@ -137,27 +118,6 @@ protected List createMatchesForDataAccessRequest(DataAccessRequest dar) { return matches; } - public List createMatchesForConsent(String consentId) { - List matches = new ArrayList<>(); - List datasets = datasetDAO.getDatasetsForConsent(consentId); - if (datasets.isEmpty()) { - logWarn("Error finding datasets for consent: " + consentId); - return matches; - } - datasets.forEach(d -> { - List dars = findRelatedDars(List.of(d.getDataSetId())); - dars.forEach(dar -> { - try { - matches.add(singleEntitiesMatchV3(d, dar)); - } catch (Exception e) { - logWarn("Error finding matches for consent: " + consentId); - matches.add(matchFailure(consentId, dar.getReferenceId(), List.of())); - } - }); - }); - return matches; - } - public Match singleEntitiesMatchV3(Dataset dataset, DataAccessRequest dar) { if (Objects.isNull(dataset)) { logWarn("Dataset is null"); @@ -185,12 +145,6 @@ public Match singleEntitiesMatchV3(Dataset dataset, DataAccessRequest dar) { return match; } - private List findRelatedDars(List dataSetIds) { - return dataAccessRequestDAO.findAllDataAccessRequests().stream() - .filter(d -> !Collections.disjoint(dataSetIds, d.getDatasetIds())) - .collect(Collectors.toList()); - } - private DataUseRequestMatchingObject createRequestObject(Dataset dataset, DataAccessRequest dar) { DataUse dataUse = useRestrictionConverter.parseDataUsePurpose(dar); return new DataUseRequestMatchingObject(dataset.getDataUse(), dataUse); diff --git a/src/main/java/org/broadinstitute/consent/http/service/SummaryService.java b/src/main/java/org/broadinstitute/consent/http/service/SummaryService.java deleted file mode 100644 index dd8e2e2173..0000000000 --- a/src/main/java/org/broadinstitute/consent/http/service/SummaryService.java +++ /dev/null @@ -1,353 +0,0 @@ -package org.broadinstitute.consent.http.service; - -import static org.broadinstitute.consent.http.resources.Resource.CHAIRPERSON; - -import com.google.inject.Inject; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.commons.collections4.CollectionUtils; -import org.broadinstitute.consent.http.db.ConsentDAO; -import org.broadinstitute.consent.http.db.DarCollectionDAO; -import org.broadinstitute.consent.http.db.DatasetDAO; -import org.broadinstitute.consent.http.db.ElectionDAO; -import org.broadinstitute.consent.http.db.MatchDAO; -import org.broadinstitute.consent.http.db.UserDAO; -import org.broadinstitute.consent.http.db.VoteDAO; -import org.broadinstitute.consent.http.enumeration.ElectionStatus; -import org.broadinstitute.consent.http.enumeration.ElectionType; -import org.broadinstitute.consent.http.enumeration.VoteType; -import org.broadinstitute.consent.http.models.Association; -import org.broadinstitute.consent.http.models.Consent; -import org.broadinstitute.consent.http.models.ConsentSummaryDetail; -import org.broadinstitute.consent.http.models.DarCollection; -import org.broadinstitute.consent.http.models.DataAccessRequest; -import org.broadinstitute.consent.http.models.DataAccessRequestSummaryDetail; -import org.broadinstitute.consent.http.models.Election; -import org.broadinstitute.consent.http.models.Match; -import org.broadinstitute.consent.http.models.Summary; -import org.broadinstitute.consent.http.models.User; -import org.broadinstitute.consent.http.models.Vote; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SummaryService { - - private final VoteDAO voteDAO; - private final ElectionDAO electionDAO; - private final UserDAO userDAO; - private final ConsentDAO consentDAO; - private final DatasetDAO datasetDAO; - private final MatchDAO matchDAO; - private final DarCollectionDAO darCollectionDAO; - private final DataAccessRequestService dataAccessRequestService; - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - @Inject - public SummaryService(DataAccessRequestService dataAccessRequestService, VoteDAO dao, - ElectionDAO electionDAO, UserDAO userDAO, ConsentDAO consentDAO, DatasetDAO datasetDAO, - MatchDAO matchDAO, DarCollectionDAO darCollectionDAO) { - this.dataAccessRequestService = dataAccessRequestService; - this.voteDAO = dao; - this.electionDAO = electionDAO; - this.userDAO = userDAO; - this.consentDAO = consentDAO; - this.datasetDAO = datasetDAO; - this.matchDAO = matchDAO; - this.darCollectionDAO = darCollectionDAO; - } - - public Summary describeConsentSummaryCases() { - return getSummaryCases(ElectionType.TRANSLATE_DUL.getValue()); - } - - public Summary describeDataRequestSummaryCases(String electionType) { - Summary summary; - if (electionType.equals(ElectionType.DATA_ACCESS.getValue())) { - summary = getAccessSummaryCases(electionType); - } else { - summary = getSummaryCases(electionType); - } - return summary; - } - - public List describeMatchSummaryCases() { - return getMatchSummaryCases(); - } - - private List getMatchSummaryCases() { - List summaryList = new ArrayList<>(); - summaryList.add(createSummary(0, matchDAO.countMatchesByResult(Boolean.TRUE), - matchDAO.countMatchesByResult(Boolean.FALSE))); - - List latestElections = electionDAO.findLastElectionsWithFinalVoteByType( - ElectionType.DATA_ACCESS.getValue()); - List reviewedElections = null; - if (!CollectionUtils.isEmpty(latestElections)) { - reviewedElections = latestElections.stream() - .filter(le -> le.getStatus().equals(ElectionStatus.CLOSED.getValue())) - .collect(Collectors.toList()); - } - if (!CollectionUtils.isEmpty(reviewedElections)) { - List electionIds = reviewedElections.stream().map(Election::getElectionId) - .collect(Collectors.toList()); - List votes = voteDAO.findVotesByElectionIds(electionIds); - - List agreementYesVotes = filterAgreementVotes(votes, Boolean.TRUE); - List agreementNoVotes = filterAgreementVotes(votes, Boolean.FALSE); - - if (CollectionUtils.isNotEmpty(agreementYesVotes) || CollectionUtils.isNotEmpty( - agreementNoVotes)) { - summaryList.add(createSummary(0, agreementYesVotes.size(), agreementNoVotes.size())); - } - } else { - summaryList.add(createSummary(0, 0, 0)); - } - return summaryList; - } - - private List filterAgreementVotes(List votes, Boolean desiredValue) { - return votes.stream().filter( - v -> v.getType().equals(VoteType.AGREEMENT.getValue()) && v.getVote() != null && v.getVote() - .equals(desiredValue) - ).collect(Collectors.toList()); - } - - - protected Summary getSummaryCases(String type) { - List statuses = Stream.of(ElectionStatus.FINAL.getValue(), - ElectionStatus.OPEN.getValue()). - map(String::toLowerCase). - collect(Collectors.toList()); - List openElections = electionDAO.findElectionsWithFinalVoteByTypeAndStatus(type, - statuses); - Integer totalPendingCases = openElections == null ? 0 : openElections.size(); - Integer totalPositiveCases = electionDAO.findTotalElectionsByTypeStatusAndVote(type, - ElectionStatus.CLOSED.getValue(), true); - Integer totalNegativeCases = electionDAO.findTotalElectionsByTypeStatusAndVote(type, - ElectionStatus.CLOSED.getValue(), false); - return createSummary(totalPendingCases, totalPositiveCases, totalNegativeCases); - } - - protected Summary getAccessSummaryCases(String type) { - List statuses = Stream.of(ElectionStatus.FINAL.getValue(), - ElectionStatus.OPEN.getValue()). - map(String::toLowerCase). - collect(Collectors.toList()); - List openElections = electionDAO.findElectionsWithFinalVoteByTypeAndStatus(type, - statuses); - Integer totalPendingCases = openElections == null ? 0 : openElections.size(); - Integer totalPositiveCases = voteDAO.findTotalFinalVoteByElectionTypeAndVote(type, true); - Integer totalNegativeCases = voteDAO.findTotalFinalVoteByElectionTypeAndVote(type, false); - return createSummary(totalPendingCases, totalPositiveCases, totalNegativeCases); - } - - private Summary createSummary(Integer totalPendingCases, - Integer totalPositiveCases, Integer totalNegativeCases) { - Summary summary = new Summary(); - summary.setPendingCases(totalPendingCases); - summary.setReviewedNegativeCases(totalNegativeCases); - summary.setReviewedPositiveCases(totalPositiveCases); - return summary; - } - - /** - * Generate a list of Summary Details for all reviewed Consent elections. - * - * @return List - */ - public List describeConsentSummaryDetail() { - List details = new ArrayList<>(); - try { - List statuses = - Stream.of(ElectionStatus.CLOSED.getValue(), ElectionStatus.CANCELED.getValue()) - .map(String::toLowerCase) - .collect(Collectors.toList()); - List reviewedElections = electionDAO.findElectionsWithFinalVoteByTypeAndStatus( - ElectionType.TRANSLATE_DUL.getValue(), statuses).stream() - .filter(e -> Objects.nonNull(e.getFinalVote())).distinct() - .collect(Collectors.toUnmodifiableList()); - if (!CollectionUtils.isEmpty(reviewedElections)) { - List consentIds = - reviewedElections.stream().map(Election::getReferenceId).collect(Collectors.toList()); - List electionIds = - reviewedElections.stream().map(Election::getElectionId).collect(Collectors.toList()); - Integer maxNumberOfDACMembers = voteDAO.findMaxNumberOfDACMembers(electionIds); - Collection consents = consentDAO.findConsentsFromConsentsIDs(consentIds); - List votes = voteDAO.findVotesByElectionIds(electionIds); - Collection userIds = - votes.stream().map(Vote::getUserId).collect(Collectors.toSet()); - Collection users = userDAO.findUsers(userIds); - for (Election election : reviewedElections) { - Optional electionConsent = - consents.stream() - .filter(c -> c.getConsentId().equals(election.getReferenceId())) - .findFirst(); - List electionVotes = - votes.stream() - .filter(ev -> ev.getElectionId().equals(election.getElectionId())) - .collect(Collectors.toList()); - List electionVotesUserIds = - electionVotes.stream().map(Vote::getUserId).collect(Collectors.toList()); - Collection electionUsers = - users.stream() - .filter(du -> electionVotesUserIds.contains(du.getUserId())) - .collect(Collectors.toSet()); - Optional chairPersonVote = - electionVotes.stream() - .filter(ev -> ev.getType().equals(CHAIRPERSON)) - .findFirst(); - Optional chairPerson = chairPersonVote - .flatMap(vote -> users.stream() - .filter(du -> du.getUserId().equals(vote.getUserId())) - .findFirst()); - ConsentSummaryDetail detail = new ConsentSummaryDetail( - election, - electionConsent.orElse(null), - electionVotes, - electionUsers, - chairPersonVote.orElse(null), - chairPerson.orElse(null), - maxNumberOfDACMembers); - details.add(detail); - } - } - } catch (Exception e) { - logger.error("There is an error trying to create statistics file, error: " + e.getMessage()); - } - return details; - } - - /** - * Generate a list of Summary Details for all reviewed Data Access Requests Requires a significant - * amount of database interaction as we need to find all completed elections for DARs, datasets, - * votes, matches, and users for those elections. Batch what we can as efficiently as possible and - * calculate the rest. - * - * @return List - */ - public List listDataAccessRequestSummaryDetails() { - List details = new ArrayList<>(); - List accessElections = electionDAO.findElectionsWithFinalVoteByTypeAndStatus( - ElectionType.DATA_ACCESS.getValue(), ElectionStatus.CLOSED.getValue()).stream() - .filter(e -> Objects.nonNull(e.getFinalVote())).distinct().collect(Collectors.toList()); - List rpElections = electionDAO.findElectionsWithFinalVoteByTypeAndStatus( - ElectionType.RP.getValue(), ElectionStatus.CLOSED.getValue()).stream() - .filter(e -> Objects.nonNull(e.getFinalVote())).distinct().collect(Collectors.toList()); - if (!accessElections.isEmpty()) { - List referenceIds = accessElections.stream().map(Election::getReferenceId) - .collect(Collectors.toList()); - List dataAccessRequests = referenceIds.isEmpty() ? Collections.emptyList() - : dataAccessRequestService.getDataAccessRequestsByReferenceIds(referenceIds); - List datasetIds = - dataAccessRequests.stream() - .filter(Objects::nonNull) - .map(DataAccessRequest::getDatasetIds) - .flatMap(List::stream) - .filter(Objects::nonNull) - .collect(Collectors.toList()); - List associations = datasetIds.isEmpty() ? Collections.emptyList() - : datasetDAO.getAssociationsForDatasetIdList(datasetIds); - List associatedConsentIds = associations.stream().map(Association::getConsentId) - .collect(Collectors.toList()); - List consentElections = associatedConsentIds.isEmpty() ? Collections.emptyList() - : electionDAO.findLastElectionsWithFinalVoteByReferenceIdsTypeAndStatus( - associatedConsentIds, ElectionStatus.CLOSED.getValue()); - List accessElectionIds = accessElections.stream().map(Election::getElectionId) - .collect(Collectors.toList()); - List rpElectionIds = rpElections.stream().map(Election::getElectionId) - .collect(Collectors.toList()); - List consentElectionIds = consentElections.stream().map(Election::getElectionId) - .collect(Collectors.toList()); - List accessVotes = accessElectionIds.isEmpty() ? Collections.emptyList() - : voteDAO.findVotesByElectionIds(accessElectionIds); - List rpVotes = rpElectionIds.isEmpty() ? Collections.emptyList() - : voteDAO.findVotesByElectionIds(rpElectionIds); - List consentVotes = consentElectionIds.isEmpty() ? Collections.emptyList() - : voteDAO.findVotesByElectionIds(consentElectionIds); - List matchList = referenceIds.isEmpty() ? Collections.emptyList() - : matchDAO.findMatchesForPurposeIds(referenceIds); - List voteUserIds = accessVotes.stream().map(Vote::getUserId).distinct() - .collect(Collectors.toList()); - List voteUsers = voteUserIds.isEmpty() ? Collections.emptyList() - : new ArrayList<>(userDAO.findUsers(voteUserIds)); - List darUserIds = dataAccessRequests.stream().map(DataAccessRequest::getUserId) - .collect(Collectors.toList()); - List darUsers = darUserIds.isEmpty() ? Collections.emptyList() - : new ArrayList<>(userDAO.findUsers(darUserIds)); - - // This represents the maximum possible number of DAC members across all elections. We need to - // pre-calculate this so each row can know the correct max # of DAC members for header - // construction. - int maxNumberOfDACMembers = 0; - for (Election accessElection : accessElections) { - List accessElectionVotes = Objects.nonNull(accessElection) ? accessVotes - .stream() - .filter(ev -> ev.getElectionId().equals(accessElection.getElectionId())) - .collect(Collectors.toList()) : - Collections.emptyList(); - List userIds = accessElectionVotes.stream().map(Vote::getUserId).distinct() - .collect(Collectors.toList()); - maxNumberOfDACMembers = Math.max(maxNumberOfDACMembers, userIds.size()); - } - - for (Election accessElection : accessElections) { - List accessElectionVotes = Objects.nonNull(accessElection) ? accessVotes - .stream() - .filter(ev -> ev.getElectionId().equals(accessElection.getElectionId())) - .collect(Collectors.toList()) : - Collections.emptyList(); - Optional rpElection = rpElections - .stream() - .filter(e -> e.getReferenceId().equalsIgnoreCase(accessElection.getReferenceId())) - .findFirst(); - List rpElectionVotes = rpElection - .map(election -> rpVotes - .stream() - .filter(ev -> ev.getElectionId().equals(election.getElectionId())) - .collect(Collectors.toList())).orElse(Collections.emptyList()); - Optional matchOption = matchList.stream() - .filter(m -> m.getPurpose().equals(accessElection.getReferenceId())).findFirst(); - Optional darOption = dataAccessRequests.stream() - .filter(Objects::nonNull) - .filter(d -> d.getReferenceId().equalsIgnoreCase(accessElection.getReferenceId())) - .findFirst(); - DataAccessRequest dar = darOption.orElse(null); - List userIds = accessElectionVotes.stream().map(Vote::getUserId).distinct() - .collect(Collectors.toList()); - List dacMembers = voteUsers.stream().filter(v -> userIds.contains(v.getUserId())) - .collect(Collectors.toList()); - - if (Objects.nonNull(dar) && Objects.nonNull(dar.getData())) { - List datasetId = dar.getDatasetIds(); - if (CollectionUtils.isNotEmpty(datasetId)) { - DarCollection collection = darCollectionDAO.findDARCollectionByCollectionId( - dar.getCollectionId()); - String darCode = Objects.nonNull(collection) ? collection.getDarCode() : null; - Optional darUser = darUsers.stream() - .filter(u -> u.getUserId().equals(dar.getUserId())).findFirst(); - details.add(new DataAccessRequestSummaryDetail( - dar, - darCode, - accessElection, - accessElectionVotes, - rpElectionVotes, - consentVotes, - matchOption.orElse(null), - dacMembers, - darUser.orElse(null), - maxNumberOfDACMembers - )); - } - } - } - } - return details; - } - -} diff --git a/src/main/resources/assets/api-docs.yaml b/src/main/resources/assets/api-docs.yaml index 16122104ec..e87bcf46dc 100644 --- a/src/main/resources/assets/api-docs.yaml +++ b/src/main/resources/assets/api-docs.yaml @@ -64,8 +64,8 @@ paths: /api/consent/{id}: get: deprecated: true - summary: Get Consent by ID - description: Returns the consent identified by the ID. + summary: Deprecated endpoint. + description: Deprecated endpoint. Use `GET /api/tdr/{identifier}` instead. parameters: - name: id in: path @@ -76,18 +76,12 @@ paths: tags: - Consent responses: - 200: - description: Returns the requested consent. - content: - application/json: - schema: - $ref: './schemas/Consent.yaml' 404: - description: The consent associated with the ID couldn't be found. + description: Deprecated endpoint. Use `GET /api/tdr/{identifier}` instead. put: deprecated: true - summary: Update Consent by ID - description: Updates the consent identified by the ID. + summary: Deprecated endpoint. + description: Deprecated endpoint. Use `GET /api/tdr/{identifier}` instead. parameters: - name: id in: path @@ -104,26 +98,13 @@ paths: tags: - Consent responses: - 200: - description: Returns the requested consent. - content: - application/json: - schema: - $ref: './schemas/Consent.yaml' - 400: - description: - Consent updates are only allowed when - 1-There have been no previous elections created for this consent - 2-The most recent election has been closed/cancelled AND archived 404: - description: The consent associated with the ID couldn't be found. - 500: - description: Internal server error + description: Deprecated endpoint. Use `GET /api/tdr/{identifier}` instead. /api/consent/{id}/matches: get: deprecated: true - summary: getMatches - description: Returns the matches that are related to this consent. + summary: Deprecated endpoint. + description: Deprecated endpoint. Use `GET /api/tdr/{identifier}` instead. parameters: - name: id in: path @@ -135,16 +116,8 @@ paths: - Match - Consent responses: - 200: - description: Returns a list of matches. - content: - application/json: - schema: - type: array - items: - $ref: './schemas/MatchResult.yaml' 404: - description: The consent for the id couldn't be found. + description: Deprecated endpoint. Use `GET /api/tdr/{identifier}` instead. /api/dac: $ref: 'paths/dac.yaml' /api/dac/{dacId}: diff --git a/src/main/resources/assets/paths/consent.yaml b/src/main/resources/assets/paths/consent.yaml index 7cd358c4a0..a3f752ffa1 100644 --- a/src/main/resources/assets/paths/consent.yaml +++ b/src/main/resources/assets/paths/consent.yaml @@ -1,7 +1,7 @@ get: deprecated: true - summary: Find Consent by name - description: Returns the Consent identified by the name. + summary: Deprecated endpoint. + description: Deprecated endpoint. Use `GET /api/tdr/{identifier}` instead. parameters: - name: name in: query @@ -12,20 +12,12 @@ get: tags: - Consent responses: - 200: - description: Returns the requested consent. - content: - application/json: - schema: - $ref: '../schemas/Consent.yaml' - 400: - description: The consent associated with the provided name has not been approved. 404: - description: The consent associated with the provided name could not be found. + description: Deprecated endpoint. Use `GET /api/tdr/{identifier}` instead. post: deprecated: true - summary: Create new Consent - description: Creates the consent sent with the request. + summary: Deprecated endpoint. + description: Deprecated endpoint. requestBody: description: Object that represents a Consent required: true @@ -36,7 +28,5 @@ post: tags: - Consent responses: - 201: - description: Returns the URL to find the created consent. - 500: - description: Internal Server Error. + 404: + description: Deprecated endpoint. diff --git a/src/main/resources/assets/paths/consentCasesSummaryFile.yaml b/src/main/resources/assets/paths/consentCasesSummaryFile.yaml index bde6f74b26..a9a2cd3b48 100644 --- a/src/main/resources/assets/paths/consentCasesSummaryFile.yaml +++ b/src/main/resources/assets/paths/consentCasesSummaryFile.yaml @@ -1,10 +1,7 @@ get: deprecated: true - summary: Get Data Access Request or Consent Election Summary Details - description: | - Returns the details of the reviewed cases by type - * `DataAccess` (default option when none specified) returns Data Access Request Election details - * `TranslateDUL` returns Consent Election details + summary: Deprecated endpoint. + description: Deprecated endpoint. Use `/api/tdr/{identifier}` instead. tags: - Summary parameters: @@ -16,9 +13,5 @@ get: type: string enum: [DataAccess, TranslateDUL] responses: - 200: - description: Summary data as plain text - content: - text/plain: - schema: - type: string + 404: + description: Deprecated endpoint. Use `/api/tdr/{identifier}` instead. diff --git a/src/test/java/org/broadinstitute/consent/http/ConsentAssociationTest.java b/src/test/java/org/broadinstitute/consent/http/ConsentAssociationTest.java deleted file mode 100644 index a5927f45ca..0000000000 --- a/src/test/java/org/broadinstitute/consent/http/ConsentAssociationTest.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.broadinstitute.consent.http; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.dropwizard.jackson.Jackson; -import java.util.ArrayList; -import java.util.Collections; -import org.broadinstitute.consent.http.models.ConsentAssociation; -import org.junit.jupiter.api.Test; - -/** - * Unit Tests for ConsentAssociation object. - *

- * Created by egolin on 9/16/14. - */ -public class ConsentAssociationTest { - - private static final ObjectMapper MAPPER = Jackson.newObjectMapper(); - - private static final String CONSENT_ASSOCIATION = """ - {"associationType":"sample","elements":["SM-5678","SM-1234"]}"""; - - private static ConsentAssociation buildConsentAssociation(String atype, String... elements) { - final ArrayList elem_list = new ArrayList<>(); - Collections.addAll(elem_list, elements); - return new ConsentAssociation(atype, elem_list); - } - - @Test - public void serializesToJSON() throws Exception { - final ConsentAssociation consent_association = buildConsentAssociation("sample", "SM-1234", - "SM-5678"); - assertEquals(MAPPER.writeValueAsString(consent_association), CONSENT_ASSOCIATION); - } - - @Test - public void deserializesFromJSON() throws JsonProcessingException { - final ConsentAssociation consent_association = buildConsentAssociation("sample", "SM-1234", - "SM-5678"); - assertEquals( - MAPPER.readValue(CONSENT_ASSOCIATION, ConsentAssociation.class), - consent_association); - } - - @Test - public void testEqualsTrue() { - final ConsentAssociation consent_assoc1 = buildConsentAssociation("sample", "SM-1234", - "SM-5678"); - final ConsentAssociation consent_assoc2 = buildConsentAssociation("sample", "SM-1234", - "SM-5678"); - assertEquals(consent_assoc1, consent_assoc2); - } - - @Test - public void testEqualsNotMatchingElements() { - final ConsentAssociation consent_assoc1 = buildConsentAssociation("sample", "SM-1234", - "SM-5678"); - final ConsentAssociation consent_assoc2 = buildConsentAssociation("sample", "SM-4321", - "SM-8765"); - assertNotEquals(consent_assoc1, consent_assoc2); - } - - @Test - public void testEqualsNotMatchingAssociationType() { - final ConsentAssociation consent_assoc1 = buildConsentAssociation("sample", "SM-1234", - "SM-5678"); - final ConsentAssociation consent_assoc2 = buildConsentAssociation("sampleSet", "SM-1234", - "SM-5678"); - assertNotEquals(consent_assoc1, consent_assoc2); - } - - @Test - public void testToString() { - final ConsentAssociation consent_association = buildConsentAssociation("sample", "SM-1234", - "SM-5678"); - assertNotNull(consent_association.toString()); - } - - @Test - public void testIsAssociationType() { - final ConsentAssociation consent_association = buildConsentAssociation("sample", "SM-1234", - "SM-5678"); - assertTrue(consent_association.isAssociationType("sample")); - assertFalse(consent_association.isAssociationType("sampleSet")); - } -} diff --git a/src/test/java/org/broadinstitute/consent/http/db/ConsentAuditDAOTest.java b/src/test/java/org/broadinstitute/consent/http/db/ConsentAuditDAOTest.java deleted file mode 100644 index 11827230f5..0000000000 --- a/src/test/java/org/broadinstitute/consent/http/db/ConsentAuditDAOTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.broadinstitute.consent.http.db; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.Date; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; -import org.broadinstitute.consent.http.enumeration.AuditActions; -import org.broadinstitute.consent.http.enumeration.AuditTable; -import org.broadinstitute.consent.http.models.Consent; -import org.broadinstitute.consent.http.models.ConsentAudit; -import org.broadinstitute.consent.http.models.User; -import org.junit.jupiter.api.Test; - -public class ConsentAuditDAOTest extends DAOTestHelper { - - @Test - public void testInsertWorkspaceAudit() { - ConsentAudit audit = createConsentAudit(); - - consentAuditDAO.insertWorkspaceAudit(audit); - - List consentIds = consentAuditDAO.findAllObjectIds(); - assertFalse(consentIds.isEmpty()); - assertEquals(audit.getModifiedObjectId(), consentIds.get(0)); - } - - @Test - public void testBatchInsertWorkspaceAudit() { - List audits = - List.of(createConsentAudit(), createConsentAudit(), createConsentAudit()); - List auditObjectIds = - audits.stream().map(ConsentAudit::getModifiedObjectId).collect(Collectors.toList()); - - consentAuditDAO.batchInsertWorkspaceAudit(audits); - - List consentIds = consentAuditDAO.findAllObjectIds(); - assertFalse(consentIds.isEmpty()); - auditObjectIds.forEach(id -> assertTrue(consentIds.contains(id))); - } - - private ConsentAudit createConsentAudit() { - User user = createUser(); - Consent consent = createConsent(); - return new ConsentAudit( - consent.getConsentId(), - AuditTable.CONSENT.getValue(), - AuditActions.CREATE.getValue(), - user.getUserId(), - new Date()); - } - - private Consent createConsent() { - String consentId = UUID.randomUUID().toString(); - consentDAO.insertConsent(consentId, - false, - "{\"generalUse\": true }", - "dul", - consentId, - "dulName", - new Date(), - new Date(), - "Group"); - return consentDAO.findConsentById(consentId); - } - -} diff --git a/src/test/java/org/broadinstitute/consent/http/db/ConsentDAOTest.java b/src/test/java/org/broadinstitute/consent/http/db/ConsentDAOTest.java deleted file mode 100644 index 2b6ee04f67..0000000000 --- a/src/test/java/org/broadinstitute/consent/http/db/ConsentDAOTest.java +++ /dev/null @@ -1,225 +0,0 @@ -package org.broadinstitute.consent.http.db; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.UUID; -import org.apache.commons.lang3.RandomStringUtils; -import org.broadinstitute.consent.http.models.Consent; -import org.broadinstitute.consent.http.models.DataUse; -import org.broadinstitute.consent.http.models.DataUseBuilder; -import org.broadinstitute.consent.http.models.Dataset; -import org.broadinstitute.consent.http.models.DatasetProperty; -import org.broadinstitute.consent.http.models.User; -import org.junit.jupiter.api.Test; - -public class ConsentDAOTest extends DAOTestHelper { - - @Test - void testFindConsentsFromConsentsIDs() { - Consent consent1 = createConsent(); - Consent consent2 = createConsent(); - - Collection consents = consentDAO.findConsentsFromConsentsIDs(Arrays.asList( - consent1.getConsentId(), - consent2.getConsentId())); - Collection ids = consents.stream().map(Consent::getConsentId).toList(); - assertNotNull(consents); - assertFalse(consents.isEmpty()); - assertEquals(2, consents.size()); - assertTrue(ids.contains(consent1.getConsentId())); - assertTrue(ids.contains(consent2.getConsentId())); - } - - @Test - void testCheckConsentById_case1() { - Consent consent = createConsent(); - - String consentId = consentDAO.checkConsentById(consent.getConsentId()); - assertEquals(consent.getConsentId(), consentId); - } - - @Test - void testGetIdByName() { - Consent consent = createConsent(); - - String consentId = consentDAO.getIdByName(consent.getName()); - assertEquals(consent.getConsentId(), consentId); - } - - @Test - void testFindConsentByName() { - Consent consent = createConsent(); - - Consent foundConsent = consentDAO.findConsentByName(consent.getName()); - assertEquals(consent.getConsentId(), foundConsent.getConsentId()); - } - - - @Test - void testDeleteConsent() { - Consent consent = createConsent(); - String consentId = consent.getConsentId(); - Consent foundConsent = consentDAO.findConsentById(consentId); - assertNotNull(foundConsent); - consentDAO.deleteConsent(consentId); - Consent deletedConsent = consentDAO.findConsentById(consentId); - assertNull(deletedConsent); - } - - @Test - void testUpdateConsent() { - Consent consent = createConsent(); - - consentDAO.updateConsent( - consent.getConsentId(), - false, - consent.getDataUse().toString(), - consent.getDataUseLetter(), - "something else", - consent.getDulName(), - new Date(), - new Date(), - consent.getGroupName(), - consent.getUpdated() - ); - - Consent foundConsent = consentDAO.findConsentById(consent.getConsentId()); - assertNotNull(foundConsent.getName()); - assertEquals("something else", foundConsent.getName()); - } - - @Test - void testDeleteAllAssociationsForConsent() { - Dataset dataset = createDataset(); - Dataset dataset2 = createDataset(); - Consent consent = createConsent(); - String consentId = consent.getConsentId(); - consentDAO.insertConsentAssociation(consentId, ASSOCIATION_TYPE_TEST, dataset.getDataSetId()); - consentDAO.insertConsentAssociation(consentId, ASSOCIATION_TYPE_TEST, dataset2.getDataSetId()); - - consentDAO.deleteAllAssociationsForConsent(consentId); - Integer deletedAssociationId1 = consentDAO.findAssociationsByDataSetId(dataset.getDataSetId()); - assertNull(deletedAssociationId1); - Integer deletedAssociationId2 = consentDAO.findAssociationsByDataSetId(dataset2.getDataSetId()); - assertNull(deletedAssociationId2); - } - - @Test - void testDeleteAssociationsByDataSetId() { - Dataset dataset = createDataset(); - Dataset dataset2 = createDataset(); - Consent consent = createConsent(); - consentDAO.insertConsentAssociation(consent.getConsentId(), ASSOCIATION_TYPE_TEST, - dataset.getDataSetId()); - consentDAO.insertConsentAssociation(consent.getConsentId(), ASSOCIATION_TYPE_TEST, - dataset2.getDataSetId()); - - datasetDAO.deleteConsentAssociationsByDatasetId(dataset.getDataSetId()); - Integer deletedAssociationId = consentDAO.findAssociationsByDataSetId(dataset.getDataSetId()); - assertNull(deletedAssociationId); - Integer remainingAssociationId = consentDAO.findAssociationsByDataSetId( - dataset2.getDataSetId()); - assertNotNull(remainingAssociationId); - } - - @Test - void testCheckManualReview() { - Consent consent = createConsent(); - Consent consent2 = createConsent(); - consentDAO.updateConsent( - consent2.getConsentId(), - true, - consent2.getDataUse().toString(), - consent2.getDataUseLetter(), - consent2.getName(), - consent2.getDulName(), - new Date(), - consent2.getSortDate(), - consent2.getGroupName(), - consent2.getUpdated()); - - assertFalse(consentDAO.checkManualReview(consent.getConsentId())); - assertTrue(consentDAO.checkManualReview(consent2.getConsentId())); - } - - @Test - void testConsentUpdateStatus() { - Consent consent1 = createConsent(); - consentDAO.updateConsent( - consent1.getConsentId(), - consent1.getRequiresManualReview(), - consent1.getDataUse().toString(), - consent1.getDataUseLetter(), - consent1.getName(), - consent1.getDulName(), - new Date(), - consent1.getSortDate(), - consent1.getGroupName(), - true); - Consent consent2 = createConsent(); - consentDAO.updateConsent( - consent2.getConsentId(), - consent2.getRequiresManualReview(), - consent2.getDataUse().toString(), - consent2.getDataUseLetter(), - consent2.getName(), - consent2.getDulName(), - new Date(), - consent2.getSortDate(), - consent2.getGroupName(), - false); - - Consent consent1Found = consentDAO.findConsentById(consent1.getConsentId()); - assertTrue(consent1Found.getUpdated()); - Consent consent2Found = consentDAO.findConsentById(consent2.getConsentId()); - assertFalse(consent2Found.getUpdated()); - } - - private Dataset createDataset() { - User user = createUser(); - String name = "Name_" + RandomStringUtils.random(20, true, true); - Timestamp now = new Timestamp(new Date().getTime()); - String objectId = "Object ID_" + RandomStringUtils.random(20, true, true); - DataUse dataUse = new DataUseBuilder().setGeneralUse(true).build(); - Integer id = datasetDAO.insertDataset(name, now, user.getUserId(), objectId, - dataUse.toString(), null); - createDatasetProperties(id); - return datasetDAO.findDatasetById(id); - } - - private void createDatasetProperties(Integer datasetId) { - List list = new ArrayList<>(); - DatasetProperty dsp = new DatasetProperty(); - dsp.setDataSetId(datasetId); - dsp.setPropertyKey(1); - dsp.setPropertyValue("Test_PropertyValue"); - dsp.setCreateDate(new Date()); - list.add(dsp); - datasetDAO.insertDatasetProperties(list); - } - - private Consent createConsent() { - String consentId = UUID.randomUUID().toString(); - consentDAO.insertConsent(consentId, - false, - "{\"generalUse\": true }", - "dul", - consentId, - "dulName", - new Date(), - new Date(), - "Group"); - return consentDAO.findConsentById(consentId); - } - -} diff --git a/src/test/java/org/broadinstitute/consent/http/db/DAOTestHelper.java b/src/test/java/org/broadinstitute/consent/http/db/DAOTestHelper.java index f46ef1bd14..403db78a39 100644 --- a/src/test/java/org/broadinstitute/consent/http/db/DAOTestHelper.java +++ b/src/test/java/org/broadinstitute/consent/http/db/DAOTestHelper.java @@ -45,9 +45,6 @@ public class DAOTestHelper { protected static Jdbi jdbi; - protected static ConsentAuditDAO consentAuditDAO; - - protected static ConsentDAO consentDAO; protected static CounterDAO counterDAO; protected static DacDAO dacDAO; protected static UserDAO userDAO; @@ -117,8 +114,6 @@ public static void startUp() throws Exception { GsonUtil.buildGson() ); - consentAuditDAO = jdbi.onDemand(ConsentAuditDAO.class); - consentDAO = jdbi.onDemand(ConsentDAO.class); counterDAO = jdbi.onDemand(CounterDAO.class); dacDAO = jdbi.onDemand(DacDAO.class); userDAO = jdbi.onDemand(UserDAO.class); diff --git a/src/test/java/org/broadinstitute/consent/http/db/DacDAOTest.java b/src/test/java/org/broadinstitute/consent/http/db/DacDAOTest.java index 514ebc6389..f349a60838 100644 --- a/src/test/java/org/broadinstitute/consent/http/db/DacDAOTest.java +++ b/src/test/java/org/broadinstitute/consent/http/db/DacDAOTest.java @@ -13,11 +13,9 @@ import java.util.Date; import java.util.List; import java.util.Set; -import java.util.UUID; import org.apache.commons.lang3.RandomStringUtils; import org.broadinstitute.consent.http.enumeration.PropertyType; import org.broadinstitute.consent.http.enumeration.UserRoles; -import org.broadinstitute.consent.http.models.Consent; import org.broadinstitute.consent.http.models.Dac; import org.broadinstitute.consent.http.models.DataUse; import org.broadinstitute.consent.http.models.DataUseBuilder; @@ -28,36 +26,22 @@ import org.broadinstitute.consent.http.models.UserRole; import org.junit.jupiter.api.Test; -public class DacDAOTest extends DAOTestHelper { +class DacDAOTest extends DAOTestHelper { @Test - public void testInsertWithoutEmail() { + void testInsertWithoutEmail() { Dac dac = insertDac(); assertNotNull(dac); } @Test - public void testInsertWithEmail() { + void testInsertWithEmail() { Dac dac = insertDacWithEmail(); assertNotNull(dac); } @Test - public void testFindAll() { - int count = 4; - for (int i = 1; i <= count; i++) { - Dac d = insertDacWithEmail(); - Dataset ds = createDatasetWithDac(d.getDacId()); - Consent c = createConsent(); - consentDAO.insertConsentAssociation(c.getConsentId(), ASSOCIATION_TYPE_TEST, - ds.getDataSetId()); - } - List dacList = dacDAO.findAll(); - assertEquals(count, dacList.size()); - } - - @Test - public void testFindDacsForEmail() { + void testFindDacsForEmail() { Dac dac = insertDacWithEmail(); User chair = createUser(); dacDAO.addDacMember(UserRoles.CHAIRPERSON.getRoleId(), chair.getUserId(), dac.getDacId()); @@ -67,7 +51,7 @@ public void testFindDacsForEmail() { } @Test - public void testFindAllDacMemberships() { + void testFindAllDacMemberships() { List dacs = new ArrayList<>(); dacs.add(createDac()); dacs.add(createDac()); @@ -84,7 +68,7 @@ public void testFindAllDacMemberships() { } @Test - public void testFindAllDACUsersBySearchString_case1() { + void testFindAllDACUsersBySearchString_case1() { Dac dac = insertDacWithEmail(); User chair = createUser(); // Creates a user with researcher role dacDAO.addDacMember(UserRoles.CHAIRPERSON.getRoleId(), chair.getUserId(), dac.getDacId()); @@ -95,13 +79,13 @@ public void testFindAllDACUsersBySearchString_case1() { } @Test - public void testFindAllDACUsersBySearchString_case2() { + void testFindAllDACUsersBySearchString_case2() { Set users = dacDAO.findAllDACUsersBySearchString("random"); assertTrue(users.isEmpty()); } @Test - public void testFindById() { + void testFindById() { Integer id = dacDAO.createDac( "Test_" + RandomStringUtils.random(20, true, true), "Test_" + RandomStringUtils.random(20, true, true), @@ -111,7 +95,7 @@ public void testFindById() { } @Test - public void testCreateDac() { + void testCreateDac() { Integer id = dacDAO.createDac( "Test_" + RandomStringUtils.random(20, true, true), "Test_" + RandomStringUtils.random(20, true, true), @@ -121,7 +105,7 @@ public void testCreateDac() { } @Test - public void testUpdateDacWithoutEmail() { + void testUpdateDacWithoutEmail() { String newValue = "New Value"; Dac dac = insertDac(); dacDAO.updateDac(newValue, newValue, new Date(), dac.getDacId()); @@ -132,7 +116,7 @@ public void testUpdateDacWithoutEmail() { } @Test - public void testUpdateDacWithEmail() { + void testUpdateDacWithEmail() { String newValue = "New Value"; String newEmail = "new_email@test.com"; Dac dac = insertDacWithEmail(); @@ -145,7 +129,7 @@ public void testUpdateDacWithEmail() { } @Test - public void testDeleteDacMembers() { + void testDeleteDacMembers() { Dac dac = insertDacWithEmail(); Integer memberRoleId = UserRoles.MEMBER.getRoleId(); User user1 = createUser(); @@ -159,7 +143,7 @@ public void testDeleteDacMembers() { } @Test - public void testDeleteDac() { + void testDeleteDac() { Dac dac = insertDacWithEmail(); assertNotNull(dac.getDacId()); @@ -169,7 +153,7 @@ public void testDeleteDac() { } @Test - public void testFindMembersByDacId() { + void testFindMembersByDacId() { Dac dac = insertDacWithEmail(); Integer chairRoleId = UserRoles.CHAIRPERSON.getRoleId(); Integer memberRoleId = UserRoles.MEMBER.getRoleId(); @@ -189,7 +173,7 @@ public void testFindMembersByDacId() { } @Test - public void testFindMembersByDacIdAndRoleId() { + void testFindMembersByDacIdAndRoleId() { Dac dac = insertDacWithEmail(); Integer chairRoleId = UserRoles.CHAIRPERSON.getRoleId(); Integer memberRoleId = UserRoles.MEMBER.getRoleId(); @@ -214,7 +198,7 @@ public void testFindMembersByDacIdAndRoleId() { } @Test - public void testAddDacMember() { + void testAddDacMember() { Dac dac = insertDacWithEmail(); Integer roleId = UserRoles.MEMBER.getRoleId(); User user = createUser(); @@ -227,7 +211,7 @@ public void testAddDacMember() { } @Test - public void testAddDacChair() { + void testAddDacChair() { Dac dac = insertDacWithEmail(); Integer roleId = UserRoles.CHAIRPERSON.getRoleId(); User user = createUser(); @@ -240,7 +224,7 @@ public void testAddDacChair() { } @Test - public void testRemoveDacMember() { + void testRemoveDacMember() { Dac dac = insertDacWithEmail(); Integer chairRoleId = UserRoles.CHAIRPERSON.getRoleId(); Integer memberRoleId = UserRoles.MEMBER.getRoleId(); @@ -255,7 +239,7 @@ public void testRemoveDacMember() { } @Test - public void testGetRoleById() { + void testGetRoleById() { Role chair = dacDAO.getRoleById(UserRoles.CHAIRPERSON.getRoleId()); assertEquals(chair.getName().toLowerCase(), UserRoles.CHAIRPERSON.getRoleName().toLowerCase()); @@ -265,7 +249,7 @@ public void testGetRoleById() { } @Test - public void testFindUserRolesForUser() { + void testFindUserRolesForUser() { Dac dac = insertDacWithEmail(); User chair = createUser(); // Creates a user with researcher role; UserRole #1 dacDAO.addDacMember(UserRoles.CHAIRPERSON.getRoleId(), chair.getUserId(), @@ -276,7 +260,7 @@ public void testFindUserRolesForUser() { } @Test - public void testFindUserRolesForUsers() { + void testFindUserRolesForUsers() { Dac dac = insertDacWithEmail(); User chair = createUser(); // Creates a user with researcher role; UserRole #1 User member = createUser(); // Creates a user with researcher role; UserRole #2 @@ -290,25 +274,7 @@ public void testFindUserRolesForUsers() { } @Test - public void testFindDacsForDatasetIds() { - Dac dac = insertDacWithEmail(); - Consent consent1 = createConsent(); - Dataset dataset1 = createDatasetWithDac(dac.getDacId()); - consentDAO.insertConsentAssociation(consent1.getConsentId(), ASSOCIATION_TYPE_TEST, - dataset1.getDataSetId()); - - Consent consent2 = createConsent(); - Dataset dataset2 = createDatasetWithDac(dac.getDacId()); - consentDAO.insertConsentAssociation(consent2.getConsentId(), ASSOCIATION_TYPE_TEST, - dataset2.getDataSetId()); - Set dacs = dacDAO.findDacsForDatasetIds( - Arrays.asList(dataset1.getDataSetId(), dataset2.getDataSetId())); - assertFalse(dacs.isEmpty()); - assertEquals(1, dacs.size()); - } - - @Test - public void testFindDatasetsAssociatedWithDac_NoAssociated() { + void testFindDatasetsAssociatedWithDac_NoAssociated() { Dac dac = insertDacWithEmail(); List results = datasetDAO.findDatasetsAssociatedWithDac(dac.getDacId()); @@ -316,7 +282,7 @@ public void testFindDatasetsAssociatedWithDac_NoAssociated() { } @Test - public void testFindDatasetsAssociatedWithDac_AssignedDacId() { + void testFindDatasetsAssociatedWithDac_AssignedDacId() { Dac dac = insertDacWithEmail(); Dataset datasetAssignedDac = createDatasetWithDac(dac.getDacId()); @@ -326,7 +292,7 @@ public void testFindDatasetsAssociatedWithDac_AssignedDacId() { } @Test - public void testFindDatasetsAssociatedWithDac_SuggestedDacId() { + void testFindDatasetsAssociatedWithDac_SuggestedDacId() { Dac dac = insertDacWithEmail(); Dataset datasetSuggestedDac = createDataset(); @@ -392,20 +358,6 @@ private void createDatasetProperties(Integer datasetId) { datasetDAO.insertDatasetProperties(list); } - private Consent createConsent() { - String consentId = UUID.randomUUID().toString(); - consentDAO.insertConsent(consentId, - false, - "{\"generalUse\": true }", - "dul", - consentId, - "dulName", - new Date(), - new Date(), - "Group"); - return consentDAO.findConsentById(consentId); - } - private Dataset createDatasetWithDac(Integer dacId) { User user = createUser(); String name = "Name_" + RandomStringUtils.random(20, true, true); diff --git a/src/test/java/org/broadinstitute/consent/http/db/DarCollectionDAOTest.java b/src/test/java/org/broadinstitute/consent/http/db/DarCollectionDAOTest.java index 4340e6ccc0..7f712f3428 100644 --- a/src/test/java/org/broadinstitute/consent/http/db/DarCollectionDAOTest.java +++ b/src/test/java/org/broadinstitute/consent/http/db/DarCollectionDAOTest.java @@ -21,7 +21,6 @@ import org.broadinstitute.consent.http.enumeration.OrganizationType; import org.broadinstitute.consent.http.enumeration.UserFields; import org.broadinstitute.consent.http.enumeration.VoteType; -import org.broadinstitute.consent.http.models.Consent; import org.broadinstitute.consent.http.models.Dac; import org.broadinstitute.consent.http.models.DarCollection; import org.broadinstitute.consent.http.models.DataAccessRequest; @@ -42,7 +41,7 @@ import org.postgresql.util.PSQLState; -public class DarCollectionDAOTest extends DAOTestHelper { +class DarCollectionDAOTest extends DAOTestHelper { private void generateDatasetElectionForCollection(DarCollection collection) { DataAccessRequest dar = collection.getDars().values().stream() @@ -68,7 +67,7 @@ private List getDatasetElectionsFromElection(List elections) } @Test - public void testFindAllDARCollections() { + void testFindAllDARCollections() { DarCollection collection = createDarCollectionMultipleUserProperties(); List allAfter = darCollectionDAO.findAllDARCollections(); assertTrue(allAfter.contains(collection)); @@ -88,7 +87,7 @@ public void testFindAllDARCollections() { } @Test - public void testFindAllDarCollectionsMultipleUserProperties() { + void testFindAllDarCollectionsMultipleUserProperties() { DarCollection collection = createDarCollectionMultipleUserProperties(); List allAfter = darCollectionDAO.findAllDARCollections(); assertTrue(allAfter.contains(collection)); @@ -100,7 +99,7 @@ public void testFindAllDarCollectionsMultipleUserProperties() { } @Test - public void testFindDARCollectionByReferenceId() { + void testFindDARCollectionByReferenceId() { DataAccessRequest dar = createDataAccessRequestV3(); DarCollection collection = darCollectionDAO.findDARCollectionByReferenceId( dar.getReferenceId()); @@ -112,7 +111,7 @@ public void testFindDARCollectionByReferenceId() { } @Test - public void testFindDARCollectionByReferenceIdNegative() { + void testFindDARCollectionByReferenceIdNegative() { //dar without a collection ID DataAccessRequest dar = createDraftDataAccessRequest(); DarCollection collection = darCollectionDAO.findDARCollectionByReferenceId( @@ -121,7 +120,7 @@ public void testFindDARCollectionByReferenceIdNegative() { } @Test - public void testFindDARCollectionByCollectionId() { + void testFindDARCollectionByCollectionId() { DarCollection collection = createDarCollectionMultipleUserProperties(); DarCollection returned = darCollectionDAO.findDARCollectionByCollectionId( collection.getDarCollectionId()); @@ -150,7 +149,7 @@ public void testFindDARCollectionByCollectionId() { } @Test - public void testFindDARCollectionByCollectionIdMultipleUserProperties() { + void testFindDARCollectionByCollectionIdMultipleUserProperties() { DarCollection collection = createDarCollectionMultipleUserProperties(); DarCollection returned = darCollectionDAO.findDARCollectionByCollectionId( collection.getDarCollectionId()); @@ -163,7 +162,7 @@ public void testFindDARCollectionByCollectionIdMultipleUserProperties() { } @Test - public void testFindDARCollectionByCollectionIdLibraryCard() { + void testFindDARCollectionByCollectionIdLibraryCard() { User user = createUser(); LibraryCard libraryCard = createLibraryCard(user); String darCode = "DAR-" + RandomUtils.nextInt(100, 1000); @@ -182,14 +181,14 @@ public void testFindDARCollectionByCollectionIdLibraryCard() { } @Test - public void testFindDARCollectionByCollectionIdNegative() { + void testFindDARCollectionByCollectionIdNegative() { DarCollection returned = darCollectionDAO.findDARCollectionByCollectionId( RandomUtils.nextInt(1000, 2000)); assertNull(returned); } @Test - public void testInsertDARCollection() { + void testInsertDARCollection() { List allBefore = darCollectionDAO.findAllDARCollections(); assertTrue(allBefore.isEmpty()); DarCollection collection = createDarCollection(); @@ -199,7 +198,7 @@ public void testInsertDARCollection() { } @Test - public void testInsertDarCollectionNegative() { + void testInsertDarCollectionNegative() { Integer userId = createUser().getUserId(); try { darCollectionDAO.insertDarCollection("darCode", 0, new Date()); @@ -217,7 +216,7 @@ public void testInsertDarCollectionNegative() { } @Test - public void testUpdateDARCollection() { + void testUpdateDARCollection() { DarCollection collection = createDarCollection(); assertNotNull(collection); assertNull(collection.getUpdateDate()); @@ -232,7 +231,7 @@ public void testUpdateDARCollection() { } @Test - public void testUpdateDarCollectionNegative() { + void testUpdateDarCollectionNegative() { Integer userId = createUser().getUserId(); try { darCollectionDAO.updateDarCollection(0, userId, new Date()); @@ -250,7 +249,7 @@ public void testUpdateDarCollectionNegative() { } @Test - public void testDeleteByCollectionId() { + void testDeleteByCollectionId() { DarCollection collection = createDarCollection(); collection.getDars().keySet() .forEach(k -> dataAccessRequestDAO.deleteDARDatasetRelationByReferenceId(k)); @@ -261,7 +260,7 @@ public void testDeleteByCollectionId() { } @Test - public void testDeleteByCollectionIdNegative() { + void testDeleteByCollectionIdNegative() { try { darCollectionDAO.deleteByCollectionId(RandomUtils.nextInt(100, 1000)); } catch (Exception e) { @@ -271,7 +270,7 @@ public void testDeleteByCollectionIdNegative() { } // local method to create a test DAR - public DataAccessRequest createDAR(User user, Dataset dataset, Integer collectionId) { + DataAccessRequest createDAR(User user, Dataset dataset, Integer collectionId) { Timestamp now = new Timestamp(new Date().getTime()); DataAccessRequest testDar = new DataAccessRequest(); testDar.setCollectionId(collectionId); @@ -299,7 +298,7 @@ public DataAccessRequest createDAR(User user, Dataset dataset, Integer collectio } // local method to create a test DAC - public Dac createDAC() { + Dac createDAC() { Integer id = dacDAO.createDac( "Test_" + RandomStringUtils.random(20, true, true), "Test_" + RandomStringUtils.random(20, true, true), @@ -310,7 +309,7 @@ public Dac createDAC() { // local method to create a test DAR Collection and dataset // takes in user as a parameter so we can test multiple collections with the same user // this method returns a list that includes: user, now, dataset, collectionId, testDar, dac, testDarCollection - public List createDarCollectionWithDataset(User user) { + List createDarCollectionWithDataset(User user) { Timestamp now = new Timestamp(new Date().getTime()); String darCode = "DAR-" + RandomStringUtils.randomAlphanumeric(25); Dataset dataset = createDataset(); @@ -321,7 +320,6 @@ public List createDarCollectionWithDataset(User user) { // create a DAC Dac dac = createDAC(); - Consent consent = createConsent(); datasetDAO.updateDatasetDacId(dataset.getDataSetId(), dac.getDacId()); DarCollection testDarCollection = darCollectionDAO.findDARCollectionByCollectionId( collectionId); @@ -331,7 +329,7 @@ public List createDarCollectionWithDataset(User user) { // findDARCollectionByCollectionIds should exclude archived collections @Test - public void testFindDARCollectionIdsByCollectionIdsArchived() { + void testFindDARCollectionIdsByCollectionIdsArchived() { User user = createUserWithInstitution(); List newDarCollection1 = createDarCollectionWithDataset(user); List newDarCollection2 = createDarCollectionWithDataset(user); @@ -357,7 +355,7 @@ public void testFindDARCollectionIdsByCollectionIdsArchived() { // findAllDARCollections should exclude archived collections @Test - public void testFindAllDARCollectionsArchived() { + void testFindAllDARCollectionsArchived() { User user = createUserWithInstitution(); List newDarCollection1 = createDarCollectionWithDataset(user); @@ -378,7 +376,7 @@ public void testFindAllDARCollectionsArchived() { // findDARCollectionByReferenceId should exclude archived collections @Test - public void testFindDARCollectionByReferenceIdArchived() { + void testFindDARCollectionByReferenceIdArchived() { User user = createUserWithInstitution(); List newDarCollection1 = createDarCollectionWithDataset(user); List newDarCollection2 = createDarCollectionWithDataset(user); @@ -400,7 +398,7 @@ public void testFindDARCollectionByReferenceIdArchived() { // findDARCollectionByCollectionId should exclude archived collections @Test - public void testFindDARCollectionByCollectionIdArchived() { + void testFindDARCollectionByCollectionIdArchived() { User user = createUserWithInstitution(); List newDarCollection = createDarCollectionWithDataset(user); @@ -584,20 +582,6 @@ private DataAccessRequest createDraftDataAccessRequest() { return dataAccessRequestDAO.findByReferenceId(referenceId); } - private Consent createConsent() { - String consentId = UUID.randomUUID().toString(); - consentDAO.insertConsent(consentId, - false, - "{\"generalUse\": true }", - "dul", - consentId, - "dulName", - new Date(), - new Date(), - "Group"); - return consentDAO.findConsentById(consentId); - } - private Vote createFinalVote(Integer userId, Integer electionId) { Integer voteId = voteDAO.insertVote(userId, electionId, VoteType.FINAL.getValue()); return voteDAO.findVoteById(voteId); diff --git a/src/test/java/org/broadinstitute/consent/http/db/DatasetDAOTest.java b/src/test/java/org/broadinstitute/consent/http/db/DatasetDAOTest.java index 1f17db5e18..8874094415 100644 --- a/src/test/java/org/broadinstitute/consent/http/db/DatasetDAOTest.java +++ b/src/test/java/org/broadinstitute/consent/http/db/DatasetDAOTest.java @@ -29,7 +29,6 @@ import org.broadinstitute.consent.http.enumeration.UserRoles; import org.broadinstitute.consent.http.enumeration.VoteType; import org.broadinstitute.consent.http.models.ApprovedDataset; -import org.broadinstitute.consent.http.models.Consent; import org.broadinstitute.consent.http.models.Dac; import org.broadinstitute.consent.http.models.DarCollection; import org.broadinstitute.consent.http.models.DataAccessRequest; @@ -945,27 +944,6 @@ void testFindDatasetWithDataUseByIdList() { assertTrue(datasetIds.contains(dataset.getDataSetId())); } - @Test - void testGetDatasetsForConsent() { - Integer datasetId = datasetDAO.insertDataset(RandomStringUtils.randomAlphabetic(10), null, - null, RandomStringUtils.randomAlphabetic(10), null, null); - //negative record, make sure this isn't pulled in - datasetDAO.insertDataset(RandomStringUtils.randomAlphabetic(10), null, null, - RandomStringUtils.randomAlphabetic(10), null, null); - String consentId = RandomStringUtils.randomAlphabetic(10); - consentDAO.insertConsent(consentId, false, "", null, - RandomStringUtils.randomAlphabetic(10), RandomStringUtils.randomAlphabetic(10), new Date(), - new Date(), RandomStringUtils.randomAlphabetic(10)); - consentDAO.insertConsentAssociation(consentId, RandomStringUtils.randomAlphabetic(10), - datasetId); - - List datasets = datasetDAO.getDatasetsForConsent(consentId); - assertEquals(1, datasets.size()); - Dataset targetDataset = datasets.get(0); - assertEquals(datasetId, targetDataset.getDataSetId()); - assertNull(targetDataset.getDacApproval()); - } - @Test void testUpdateDatasetApproval() { User updateUser = createUser(); @@ -1231,21 +1209,6 @@ private Dac insertDac() { return dacDAO.findById(id); } - protected Consent insertConsent() { - String consentId = UUID.randomUUID().toString(); - consentDAO.insertConsent(consentId, - false, - """ - {"generalUse":true}""", - "dul", - consentId, - "dulName", - new Date(), - new Date(), - "Group"); - return consentDAO.findConsentById(consentId); - } - private Study insertStudyWithProperties() { User u = createUser(); diff --git a/src/test/java/org/broadinstitute/consent/http/db/ElectionDAOTest.java b/src/test/java/org/broadinstitute/consent/http/db/ElectionDAOTest.java index 26867a1f65..f02f8a0b26 100644 --- a/src/test/java/org/broadinstitute/consent/http/db/ElectionDAOTest.java +++ b/src/test/java/org/broadinstitute/consent/http/db/ElectionDAOTest.java @@ -21,7 +21,6 @@ import org.broadinstitute.consent.http.enumeration.OrganizationType; import org.broadinstitute.consent.http.enumeration.UserRoles; import org.broadinstitute.consent.http.enumeration.VoteType; -import org.broadinstitute.consent.http.models.Consent; import org.broadinstitute.consent.http.models.Dac; import org.broadinstitute.consent.http.models.DataAccessRequest; import org.broadinstitute.consent.http.models.DataAccessRequestData; @@ -37,10 +36,10 @@ import org.broadinstitute.consent.http.models.Vote; import org.junit.jupiter.api.Test; -public class ElectionDAOTest extends DAOTestHelper { +class ElectionDAOTest extends DAOTestHelper { @Test - public void testGetOpenElectionIdByReferenceId() { + void testGetOpenElectionIdByReferenceId() { String accessReferenceId = UUID.randomUUID().toString(); Dataset dataset = createDataset(); Election accessElection = createDataAccessElection(accessReferenceId, dataset.getDataSetId()); @@ -52,7 +51,7 @@ public void testGetOpenElectionIdByReferenceId() { } @Test - public void testGetElectionIdsByReferenceIds() { + void testGetElectionIdsByReferenceIds() { String accessReferenceId1 = UUID.randomUUID().toString(); String accessReferenceId2 = UUID.randomUUID().toString(); Dataset dataset1 = createDataset(); @@ -73,54 +72,16 @@ public void testGetElectionIdsByReferenceIds() { } @Test - public void testFindDacForConsentElection() { + void testFindElectionByDacId() { Dac dac = createDac(); - Consent consent = createConsent(); - Dataset dataset = createDataset(); - datasetDAO.updateDatasetDacId(dataset.getDataSetId(), dac.getDacId()); - consentDAO.insertConsentAssociation(consent.getConsentId(), ASSOCIATION_TYPE_TEST, - dataset.getDataSetId()); - Election election = createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); - - Dac foundDac = electionDAO.findDacForElection(election.getElectionId()); - assertNotNull(foundDac); - assertEquals(dac.getDacId(), foundDac.getDacId()); - } - - @Test - public void testFindDacForConsentElectionWithNoAssociation() { - Dac dac = createDac(); - Consent consent = createConsent(); - Dataset dataset = createDataset(); - datasetDAO.updateDatasetDacId(dataset.getDataSetId(), dac.getDacId()); - - Election election = createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); - - Dac foundDac = electionDAO.findDacForElection(election.getElectionId()); - assertNotNull(foundDac); - assertEquals(dac.getDacId(), foundDac.getDacId()); - } - - @Test - public void testFindDacForConsentElectionNotFound() { - Consent consent = createConsent(); - Dataset dataset = createDataset(); - Election election = createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); - - Dac foundDac = electionDAO.findDacForElection(election.getElectionId()); - assertNull(foundDac); - } - - @Test - public void testFindElectionByDacId() { - Dac dac = createDac(); - Consent consent = createConsent(); + User user = createUser(); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequest(user.getUserId(), collection_id, darCode); Dataset dataset = createDataset(); datasetDAO.updateDatasetDacId(dataset.getDataSetId(), dac.getDacId()); - - consentDAO.insertConsentAssociation(consent.getConsentId(), ASSOCIATION_TYPE_TEST, - dataset.getDataSetId()); - Election election = createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); + Election election = createDataAccessElection(dar.getReferenceId(), dataset.getDataSetId()); List foundElections = electionDAO.findOpenElectionsByDacId(dac.getDacId()); assertNotNull(foundElections); @@ -128,7 +89,7 @@ public void testFindElectionByDacId() { } @Test - public void testFindElectionsByReferenceId() { + void testFindElectionsByReferenceId() { Dataset dataset = createDataset(); DataAccessRequest dar = createDataAccessRequestV3(); String referenceId = dar.getReferenceId(); @@ -144,7 +105,7 @@ public void testFindElectionsByReferenceId() { } @Test - public void testFindElectionsByReferenceIds() { + void testFindElectionsByReferenceIds() { Dataset dataset = createDataset(); DataAccessRequest dar1 = createDataAccessRequestV3(); DataAccessRequest dar2 = createDataAccessRequestV3(); @@ -176,7 +137,7 @@ public void testFindElectionsByReferenceIds() { } @Test - public void testFindLastElectionByReferenceIdDatasetIdAndType() { + void testFindLastElectionByReferenceIdDatasetIdAndType() { // Goal is to create elections for a single dar across two datasets // One set of elections will be canceled // A new set will then be created @@ -244,7 +205,7 @@ private List createElectionsForDarDataset(DataAccessRequest dar, Datase } @Test - public void testFindElectionsByReferenceIdAndDatasetId() { + void testFindElectionsByReferenceIdAndDatasetId() { User user = createUser(); String darCode = "DAR-1234567890"; Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), @@ -262,17 +223,19 @@ public void testFindElectionsByReferenceIdAndDatasetId() { } @Test - public void testDeleteElectionFromAccessRP() { + void testDeleteElectionFromAccessRP() { Dac dac = createDac(); - Consent consent = createConsent(); + User user = createUser(); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequest(user.getUserId(), collection_id, darCode); Dataset dataset = createDataset(); datasetDAO.updateDatasetDacId(dataset.getDataSetId(), dac.getDacId()); - consentDAO.insertConsentAssociation(consent.getConsentId(), ASSOCIATION_TYPE_TEST, + Election accessElection = createDataAccessElection(dar.getReferenceId(), dataset.getDataSetId()); - Election accessElection = createDataAccessElection(consent.getConsentId(), - dataset.getDataSetId()); - Election rpElection = createRPElection(consent.getConsentId(), dataset.getDataSetId()); + Election rpElection = createRPElection(dar.getReferenceId(), dataset.getDataSetId()); electionDAO.insertAccessRP(accessElection.getElectionId(), rpElection.getElectionId()); @@ -306,13 +269,17 @@ public void testDeleteElectionFromAccessRP() { } @Test - public void testFindElectionByDacIdWithNoAssociation() { + void testFindElectionByDacIdWithNoAssociation() { Dac dac = createDac(); - Consent consent = createConsent(); + User user = createUser(); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequest(user.getUserId(), collection_id, darCode); Dataset dataset = createDataset(); datasetDAO.updateDatasetDacId(dataset.getDataSetId(), dac.getDacId()); - Election election = createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); + Election election = createDataAccessElection(dar.getReferenceId(), dataset.getDataSetId()); List foundElections = electionDAO.findOpenElectionsByDacId(dac.getDacId()); assertNotNull(foundElections); @@ -320,28 +287,33 @@ public void testFindElectionByDacIdWithNoAssociation() { } @Test - public void testFindElectionByDacIdNotFound() { + void testFindElectionByDacIdNotFound() { Dac dac = createDac(); - Consent consent = createConsent(); Dataset dataset = createDataset(); - consentDAO.insertConsentAssociation(consent.getConsentId(), ASSOCIATION_TYPE_TEST, - dataset.getDataSetId()); - createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); + User user = createUser(); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequest(user.getUserId(), collection_id, darCode); + createDataAccessElection(dar.getReferenceId(), dataset.getDataSetId()); List foundElections = electionDAO.findOpenElectionsByDacId(dac.getDacId()); assertTrue(foundElections.isEmpty()); } @Test - public void testFindAccessElectionWithFinalVoteById() { + void testFindAccessElectionWithFinalVoteById() { User u = createUserWithRole(UserRoles.CHAIRPERSON.getRoleId()); Dac dac = createDac(); - Consent c = createConsent(); + User user = createUser(); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequest(user.getUserId(), collection_id, darCode); Dataset d = createDataset(); datasetDAO.updateDatasetDacId(d.getDataSetId(), dac.getDacId()); - consentDAO.insertConsentAssociation(c.getConsentId(), ASSOCIATION_TYPE_TEST, d.getDataSetId()); - Election e = createDataAccessElection(c.getConsentId(), d.getDataSetId()); + Election e = createDataAccessElection(dar.getReferenceId(), d.getDataSetId()); Integer voteId = voteDAO.insertVote(u.getUserId(), e.getElectionId(), VoteType.FINAL.getValue()); voteDAO.updateVote(true, "rationale", new Date(), voteId, false, e.getElectionId(), new Date(), @@ -355,15 +327,18 @@ public void testFindAccessElectionWithFinalVoteById() { } @Test - public void testRPFindElectionWithFinalVoteById() { + void testRPFindElectionWithFinalVoteById() { User u = createUserWithRole(UserRoles.CHAIRPERSON.getRoleId()); Dac dac = createDac(); - Consent c = createConsent(); + User user = createUser(); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequest(user.getUserId(), collection_id, darCode); Dataset d = createDataset(); datasetDAO.updateDatasetDacId(d.getDataSetId(), dac.getDacId()); - consentDAO.insertConsentAssociation(c.getConsentId(), ASSOCIATION_TYPE_TEST, d.getDataSetId()); - Election e = createRPElection(c.getConsentId(), d.getDataSetId()); + Election e = createRPElection(dar.getReferenceId(), d.getDataSetId()); Vote v = createPopulatedChairpersonVote(u.getUserId(), e.getElectionId()); Election election = electionDAO.findElectionWithFinalVoteById(e.getElectionId()); @@ -373,19 +348,22 @@ public void testRPFindElectionWithFinalVoteById() { } @Test - public void testDatasetFindElectionWithFinalVoteById() { + void testDatasetFindElectionWithFinalVoteById() { User u = createUserWithRole(UserRoles.DATAOWNER.getRoleId()); Dac dac = createDac(); - Consent c = createConsent(); + User user = createUser(); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequest(user.getUserId(), collection_id, darCode); Dataset d = createDataset(); datasetDAO.updateDatasetDacId(d.getDataSetId(), dac.getDacId()); - consentDAO.insertConsentAssociation(c.getConsentId(), ASSOCIATION_TYPE_TEST, d.getDataSetId()); Integer electionId = electionDAO.insertElection( ElectionType.DATA_SET.getValue(), ElectionStatus.OPEN.getValue(), new Date(), - c.getConsentId(), + dar.getReferenceId(), d.getDataSetId()); Election e = electionDAO.findElectionById(electionId); @@ -402,19 +380,22 @@ public void testDatasetFindElectionWithFinalVoteById() { } @Test - public void testDULFindElectionWithFinalVoteById() { + void testDULFindElectionWithFinalVoteById() { User u = createUserWithRole(UserRoles.CHAIRPERSON.getRoleId()); Dac dac = createDac(); - Consent c = createConsent(); + User user = createUser(); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequest(user.getUserId(), collection_id, darCode); Dataset d = createDataset(); datasetDAO.updateDatasetDacId(d.getDataSetId(), dac.getDacId()); - consentDAO.insertConsentAssociation(c.getConsentId(), ASSOCIATION_TYPE_TEST, d.getDataSetId()); Integer electionId = electionDAO.insertElection( ElectionType.TRANSLATE_DUL.getValue(), ElectionStatus.OPEN.getValue(), new Date(), - c.getConsentId(), + dar.getReferenceId(), d.getDataSetId()); Election e = electionDAO.findElectionById(electionId); Vote v = createPopulatedChairpersonVote(u.getUserId(), e.getElectionId()); @@ -426,7 +407,7 @@ public void testDULFindElectionWithFinalVoteById() { } @Test - public void testFindElectionsByReferenceIdCase1() { + void testFindElectionsByReferenceIdCase1() { DataAccessRequest dar = createDataAccessRequestV3(); Dataset d = createDataset(); createDataAccessElection(dar.getReferenceId(), d.getDataSetId()); @@ -438,19 +419,22 @@ public void testFindElectionsByReferenceIdCase1() { } @Test - public void testInsertExtendedElection() { + void testInsertExtendedElection() { Dac dac = createDac(); - Consent c = createConsent(); + User user = createUser(); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequest(user.getUserId(), collection_id, darCode); Dataset d = createDataset(); User u = createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); datasetDAO.updateDatasetDacId(d.getDataSetId(), dac.getDacId()); - consentDAO.insertConsentAssociation(c.getConsentId(), ASSOCIATION_TYPE_TEST, d.getDataSetId()); Integer electionId = electionDAO.insertElection( ElectionType.DATA_ACCESS.getValue(), ElectionStatus.OPEN.getValue(), new Date(), - c.getConsentId(), + dar.getReferenceId(), d.getDataSetId()); Election e = electionDAO.findElectionById(electionId); createFinalVote(u.getUserId(), e.getElectionId()); @@ -460,7 +444,7 @@ public void testInsertExtendedElection() { } @Test - public void testFindLastElectionsByReferenceIdsAndType() { + void testFindLastElectionsByReferenceIdsAndType() { DataAccessRequest dar = createDataAccessRequestV3(); Dataset d = createDataset(); electionDAO.insertElection( @@ -478,18 +462,22 @@ public void testFindLastElectionsByReferenceIdsAndType() { } @Test - public void testFindAllDacsForElectionIds() { + void testFindAllDacsForElectionIds() { Dac dac = createDac(); String accessReferenceId = UUID.randomUUID().toString(); Dataset dataset = createDataset(); Integer datasetId = dataset.getDataSetId(); - Consent consent = createConsent(); + User user = createUser(); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequest(user.getUserId(), collection_id, darCode); datasetDAO.updateDatasetDacId(dataset.getDataSetId(), dac.getDacId()); Integer electionId = electionDAO.insertElection( - ElectionType.TRANSLATE_DUL.getValue(), + ElectionType.DATA_ACCESS.getValue(), ElectionStatus.OPEN.getValue(), new Date(), - consent.getConsentId(), + dar.getReferenceId(), datasetId); Election dulElection = electionDAO.findElectionById(electionId); Election accessElection = createDataAccessElection(accessReferenceId, datasetId); @@ -505,16 +493,15 @@ public void testFindAllDacsForElectionIds() { } @Test - public void testFindAllDacsForElectionIds_EmptyList() { + void testFindAllDacsForElectionIds_EmptyList() { List electionIds = Collections.singletonList(10000); List dacList = electionDAO.findAllDacsForElectionIds(electionIds); assertTrue(dacList.isEmpty()); } @Test - public void testFindLastElectionsByReferenceIds() { + void testFindLastElectionsByReferenceIds() { Dac dac = createDac(); - Consent consent = createConsent(); Dataset dataset = createDataset(); datasetDAO.updateDatasetDacId(dataset.getDataSetId(), dac.getDacId()); @@ -523,8 +510,6 @@ public void testFindLastElectionsByReferenceIds() { String darReferenceId = dar.getReferenceId(); Integer datasetId = dataset.getDataSetId(); dataAccessRequestDAO.insertDARDatasetRelation(dar.getReferenceId(), datasetId); - consentDAO.insertConsentAssociation(consent.getConsentId(), ASSOCIATION_TYPE_TEST, - dataset.getDataSetId()); Election recentClosedAccessElection = createDataAccessElection(darReferenceId, dataset.getDataSetId()); @@ -539,7 +524,7 @@ public void testFindLastElectionsByReferenceIds() { } @Test - public void testFindLastElectionsByReferenceIds_EmptyList() { + void testFindLastElectionsByReferenceIds_EmptyList() { List elections = electionDAO.findLastElectionsByReferenceIds( Collections.singletonList(UUID.randomUUID().toString())); @@ -547,7 +532,7 @@ public void testFindLastElectionsByReferenceIds_EmptyList() { } @Test - public void testFindElectionsByVoteIdsAndType_DataAccess() { + void testFindElectionsByVoteIdsAndType_DataAccess() { DataAccessRequest dar = createDataAccessRequestV3(); Dataset dataset = createDataset(); String referenceId = dar.getReferenceId(); @@ -566,7 +551,7 @@ public void testFindElectionsByVoteIdsAndType_DataAccess() { } @Test - public void testFindElectionsByVoteIdsAndType_RP() { + void testFindElectionsByVoteIdsAndType_RP() { DataAccessRequest dar = createDataAccessRequestV3(); Dataset dataset = createDataset(); String referenceId = dar.getReferenceId(); @@ -585,7 +570,7 @@ public void testFindElectionsByVoteIdsAndType_RP() { } @Test - public void testFindElectionsWithCardHoldingUsersByElectionIds() { + void testFindElectionsWithCardHoldingUsersByElectionIds() { User lcUser = createUser(); User nonLCUser = createUser(); Dataset dataset = createDataset(); @@ -604,7 +589,7 @@ public void testFindElectionsWithCardHoldingUsersByElectionIds() { } @Test - public void testDeleteByReferenceId() { + void testDeleteByReferenceId() { Dataset dataset = createDataset(); DataAccessRequest dar = createDataAccessRequestV3(); String referenceId = dar.getReferenceId(); @@ -623,7 +608,7 @@ public void testDeleteByReferenceId() { } @Test - public void testDeleteByReferenceIds() { + void testDeleteByReferenceIds() { Dataset dataset = createDataset(); DataAccessRequest dar = createDataAccessRequestV3(); String referenceId = dar.getReferenceId(); @@ -644,7 +629,7 @@ public void testDeleteByReferenceIds() { @Test - public void testFindElectionsWithFinalVoteByReferenceId() { + void testFindElectionsWithFinalVoteByReferenceId() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); User user = createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); @@ -673,7 +658,7 @@ public void testFindElectionsWithFinalVoteByReferenceId() { } @Test - public void testInsertAndFindElection() { + void testInsertAndFindElection() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); @@ -701,7 +686,7 @@ public void testInsertAndFindElection() { } @Test - public void testUpdateElectionById() { + void testUpdateElectionById() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); DataAccessRequest dar = createDataAccessRequestV3(); @@ -725,7 +710,7 @@ public void testUpdateElectionById() { } @Test - public void testUpdateElectionById_FinalAccessVote() { + void testUpdateElectionById_FinalAccessVote() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); DataAccessRequest dar = createDataAccessRequestV3(); @@ -752,7 +737,7 @@ public void testUpdateElectionById_FinalAccessVote() { } @Test - public void testFindElectionWithFinalVoteById_NotFinal() { + void testFindElectionWithFinalVoteById_NotFinal() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); DataAccessRequest dar = createDataAccessRequestV3(); @@ -769,7 +754,7 @@ public void testFindElectionWithFinalVoteById_NotFinal() { } @Test - public void testFindElectionWithFinalVoteById_Success() { + void testFindElectionWithFinalVoteById_Success() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); User user = createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); @@ -788,7 +773,7 @@ public void testFindElectionWithFinalVoteById_Success() { } @Test - public void testFindElectionsWithFinalVoteByTypeAndStatus_SelectsOnType() { + void testFindElectionsWithFinalVoteByTypeAndStatus_SelectsOnType() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); User user = createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); @@ -811,7 +796,7 @@ public void testFindElectionsWithFinalVoteByTypeAndStatus_SelectsOnType() { } @Test - public void testFindElectionsWithFinalVoteByTypeAndStatus_SelectsOnStatus() { + void testFindElectionsWithFinalVoteByTypeAndStatus_SelectsOnStatus() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); User user = createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); @@ -837,7 +822,7 @@ public void testFindElectionsWithFinalVoteByTypeAndStatus_SelectsOnStatus() { } @Test - public void testFindLastElectionsWithFinalVoteByType_Ordered() { + void testFindLastElectionsWithFinalVoteByType_Ordered() { Dac dac = createDac(); User user = createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); @@ -883,7 +868,7 @@ public void testFindLastElectionsWithFinalVoteByType_Ordered() { } @Test - public void testFindLastElectionsWithFinalVoteByType_SelectsOnType() { + void testFindLastElectionsWithFinalVoteByType_SelectsOnType() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); User user = createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); @@ -907,7 +892,7 @@ public void testFindLastElectionsWithFinalVoteByType_SelectsOnType() { } @Test - public void testFindLastDataAccessElectionsWithFinalVoteByStatus_FiltersByStatus() { + void testFindLastDataAccessElectionsWithFinalVoteByStatus_FiltersByStatus() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); User user = createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); @@ -932,7 +917,7 @@ public void testFindLastDataAccessElectionsWithFinalVoteByStatus_FiltersByStatus } @Test - public void testFindLastDataAccessElectionsWithFinalVoteByStatus_WrongType() { + void testFindLastDataAccessElectionsWithFinalVoteByStatus_WrongType() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); User user = createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); @@ -951,7 +936,7 @@ public void testFindLastDataAccessElectionsWithFinalVoteByStatus_WrongType() { } @Test - public void testFindTotalElectionsByTypeStatusAndVote() { + void testFindTotalElectionsByTypeStatusAndVote() { Dac dac = createDac(); User user = createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); @@ -989,7 +974,7 @@ public void testFindTotalElectionsByTypeStatusAndVote() { } @Test - public void testFindLastElectionByReferenceIdAndStatus() { + void testFindLastElectionByReferenceIdAndStatus() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); DataAccessRequest dar = createDataAccessRequestV3(); @@ -1007,7 +992,7 @@ public void testFindLastElectionByReferenceIdAndStatus() { } @Test - public void testFindLastElectionByReferenceIdAndStatus_WrongType() { + void testFindLastElectionByReferenceIdAndStatus_WrongType() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); DataAccessRequest dar = createDataAccessRequestV3(); @@ -1025,7 +1010,7 @@ public void testFindLastElectionByReferenceIdAndStatus_WrongType() { } @Test - public void testFindLastElectionsWithFinalVoteByReferenceIdsTypeAndStatus() { + void testFindLastElectionsWithFinalVoteByReferenceIdsTypeAndStatus() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); User user = createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); @@ -1053,7 +1038,7 @@ public void testFindLastElectionsWithFinalVoteByReferenceIdsTypeAndStatus() { } @Test - public void testFindLastElectionsWithFinalVoteByReferenceIdsTypeAndStatus_WrongType() { + void testFindLastElectionsWithFinalVoteByReferenceIdsTypeAndStatus_WrongType() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); User user = createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); @@ -1079,7 +1064,7 @@ public void testFindLastElectionsWithFinalVoteByReferenceIdsTypeAndStatus_WrongT } @Test - public void testFindLastElectionByReferenceIdAndType() { + void testFindLastElectionByReferenceIdAndType() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); DataAccessRequest dar = createDataAccessRequestV3(); @@ -1097,7 +1082,7 @@ public void testFindLastElectionByReferenceIdAndType() { } @Test - public void testFindLastElectionByReferenceIdAndType_WrongType() { + void testFindLastElectionByReferenceIdAndType_WrongType() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); DataAccessRequest dar = createDataAccessRequestV3(); @@ -1115,7 +1100,7 @@ public void testFindLastElectionByReferenceIdAndType_WrongType() { } @Test - public void testFindElectionByAccessRPAssociation() { + void testFindElectionByAccessRPAssociation() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); @@ -1139,7 +1124,7 @@ public void testFindElectionByAccessRPAssociation() { } @Test - public void testDeleteAccessRP() { + void testDeleteAccessRP() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); @@ -1166,7 +1151,7 @@ public void testDeleteAccessRP() { } @Test - public void testDeleteElectionsFromAccessRPs_Access() { + void testDeleteElectionsFromAccessRPs_Access() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); @@ -1192,7 +1177,7 @@ public void testDeleteElectionsFromAccessRPs_Access() { } @Test - public void testDeleteElectionsFromAccessRPs_RP() { + void testDeleteElectionsFromAccessRPs_RP() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); @@ -1218,7 +1203,7 @@ public void testDeleteElectionsFromAccessRPs_RP() { } @Test - public void testFindElectionsByIds() { + void testFindElectionsByIds() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); @@ -1239,7 +1224,7 @@ public void testFindElectionsByIds() { } @Test - public void testFindElectionById() { + void testFindElectionById() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); @@ -1255,7 +1240,7 @@ public void testFindElectionById() { } @Test - public void testGetOpenElectionByReferenceId_NoElection() { + void testGetOpenElectionByReferenceId_NoElection() { Dac dac = createDac(); createDatasetWithDac(dac.getDacId()); @@ -1269,7 +1254,7 @@ public void testGetOpenElectionByReferenceId_NoElection() { } @Test - public void testGetOpenElectionByReferenceId() { + void testGetOpenElectionByReferenceId() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); @@ -1286,7 +1271,7 @@ public void testGetOpenElectionByReferenceId() { } @Test - public void testArchiveElectionByIds() { + void testArchiveElectionByIds() { User user = createUser(); String darCode = "DAR-1234567890"; Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), @@ -1307,7 +1292,7 @@ public void testArchiveElectionByIds() { } @Test - public void testFindDataAccessClosedElectionsByFinalResult_Success() { + void testFindDataAccessClosedElectionsByFinalResult_Success() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); User user = createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); @@ -1333,7 +1318,7 @@ public void testFindDataAccessClosedElectionsByFinalResult_Success() { } @Test - public void testFindDataAccessClosedElectionsByFinalResult_None() { + void testFindDataAccessClosedElectionsByFinalResult_None() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); User user = createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); @@ -1358,7 +1343,7 @@ public void testFindDataAccessClosedElectionsByFinalResult_None() { } @Test - public void testFindDataAccessClosedElectionsByFinalResult_NotDataAccess() { + void testFindDataAccessClosedElectionsByFinalResult_NotDataAccess() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); User user = createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); @@ -1383,7 +1368,7 @@ public void testFindDataAccessClosedElectionsByFinalResult_NotDataAccess() { } @Test - public void testFindApprovalAccessElectionDate() { + void testFindApprovalAccessElectionDate() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); User user = createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); @@ -1413,7 +1398,7 @@ public void testFindApprovalAccessElectionDate() { } @Test - public void testFindApprovalAccessElectionDate_NotApproced() { + void testFindApprovalAccessElectionDate_NotApproced() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); User user = createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); @@ -1429,7 +1414,7 @@ public void testFindApprovalAccessElectionDate_NotApproced() { } @Test - public void testFindDacForElection() { + void testFindDacForElection() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); @@ -1444,7 +1429,7 @@ public void testFindDacForElection() { } @Test - public void testFindOpenElectionsByDacId() { + void testFindOpenElectionsByDacId() { Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); @@ -1589,20 +1574,6 @@ private Institution createInstitution() { return institutionDAO.findInstitutionById(id); } - private Consent createConsent() { - String consentId = UUID.randomUUID().toString(); - consentDAO.insertConsent(consentId, - false, - "{\"generalUse\": true }", - "dul", - consentId, - "dulName", - new Date(), - new Date(), - "Group"); - return consentDAO.findConsentById(consentId); - } - private Vote createFinalVote(Integer userId, Integer electionId) { Integer voteId = voteDAO.insertVote(userId, electionId, VoteType.FINAL.getValue()); return voteDAO.findVoteById(voteId); diff --git a/src/test/java/org/broadinstitute/consent/http/db/MatchDAOTest.java b/src/test/java/org/broadinstitute/consent/http/db/MatchDAOTest.java index 725b4ede03..82e2925598 100644 --- a/src/test/java/org/broadinstitute/consent/http/db/MatchDAOTest.java +++ b/src/test/java/org/broadinstitute/consent/http/db/MatchDAOTest.java @@ -15,7 +15,6 @@ import org.broadinstitute.consent.http.enumeration.ElectionStatus; import org.broadinstitute.consent.http.enumeration.ElectionType; import org.broadinstitute.consent.http.enumeration.MatchAlgorithm; -import org.broadinstitute.consent.http.models.Consent; import org.broadinstitute.consent.http.models.Dac; import org.broadinstitute.consent.http.models.DataAccessRequest; import org.broadinstitute.consent.http.models.DataUse; @@ -27,10 +26,10 @@ import org.broadinstitute.consent.http.models.User; import org.junit.jupiter.api.Test; -public class MatchDAOTest extends DAOTestHelper { +class MatchDAOTest extends DAOTestHelper { @Test - public void testFindMatchesByConsentId() { + void testFindMatchesByConsentId() { Match m = createMatch(); List matches = matchDAO.findMatchesByConsentId(m.getConsent()); @@ -44,7 +43,7 @@ public void testFindMatchesByConsentId() { } @Test - public void testFindMatchesByPurposeId() { + void testFindMatchesByPurposeId() { Match m = createMatch(); List matches = matchDAO.findMatchesByPurposeId(m.getPurpose()); @@ -70,7 +69,7 @@ private Match makeMockMatch(String consentId) { } @Test - public void testDeleteMatchesByConsentId() { + void testDeleteMatchesByConsentId() { Match m = createMatch(); matchDAO.deleteMatchesByConsentId(m.getConsent()); @@ -79,7 +78,7 @@ public void testDeleteMatchesByConsentId() { } @Test - public void testDeleteMatchesByPurposeId() { + void testDeleteMatchesByPurposeId() { Match m = createMatch(); matchDAO.deleteMatchesByPurposeId(m.getPurpose()); @@ -88,7 +87,7 @@ public void testDeleteMatchesByPurposeId() { } @Test - public void testCountMatchesByResult() { + void testCountMatchesByResult() { Match m1 = createMatch(); Match m2 = createMatch(); @@ -99,7 +98,7 @@ public void testCountMatchesByResult() { } @Test - public void testFindMatchesForLatestDataAccessElectionsByPurposeIds() { + void testFindMatchesForLatestDataAccessElectionsByPurposeIds() { Dataset dataset = createDataset(); //query should pull the latest election for a given reference id //creating two access elections with the same reference id and datasetid to test that condition @@ -113,18 +112,18 @@ public void testFindMatchesForLatestDataAccessElectionsByPurposeIds() { //Generate RP election to test that the query only references DataAccess elections Election rpElection = createRPElection(UUID.randomUUID().toString(), dataset.getDataSetId()); - String consentId = createConsent().getConsentId(); + String datasetIdentifier = dataset.getDatasetIdentifier(); //This match represents the match record generated for the target election - matchDAO.insertMatch(consentId, darReferenceId, true, false, new Date(), MatchAlgorithm.V3.getVersion(), false); + matchDAO.insertMatch(datasetIdentifier, darReferenceId, true, false, new Date(), MatchAlgorithm.V3.getVersion(), false); // This match represents the match record generated for the ignored access election - matchDAO.insertMatch(consentId, ignoredAccessElection.getReferenceId(), false, false, + matchDAO.insertMatch(datasetIdentifier, ignoredAccessElection.getReferenceId(), false, false, new Date(), MatchAlgorithm.V3.getVersion(), false); // This match is never created under consent's workflow (unless the cause is a bug) // This is included simply to test the DataAccess conditional on the INNER JOIN statement - matchDAO.insertMatch(consentId, rpElection.getReferenceId(), false, false, new Date(), MatchAlgorithm.V3.getVersion(), true); + matchDAO.insertMatch(datasetIdentifier, rpElection.getReferenceId(), false, false, new Date(), MatchAlgorithm.V3.getVersion(), true); List matchResults = matchDAO.findMatchesForLatestDataAccessElectionsByPurposeIds( List.of(darReferenceId)); @@ -134,7 +133,7 @@ public void testFindMatchesForLatestDataAccessElectionsByPurposeIds() { } @Test - public void testFindMatchesForLatestDataAccessElectionsByPurposeIds_NegativeTest() { + void testFindMatchesForLatestDataAccessElectionsByPurposeIds_NegativeTest() { Dataset dataset = createDataset(); String darReferenceId = UUID.randomUUID().toString(); @@ -144,14 +143,14 @@ public void testFindMatchesForLatestDataAccessElectionsByPurposeIds_NegativeTest //Generate RP election for test Election rpElection = createRPElection(darReferenceId, dataset.getDataSetId()); - String consentId = createConsent().getConsentId(); + String datasetIdentifier = dataset.getDatasetIdentifier(); // This match represents the match record generated for the access election - matchDAO.insertMatch(consentId, accessElection.getReferenceId(), true, false, new Date(), MatchAlgorithm.V3.getVersion(), false); + matchDAO.insertMatch(datasetIdentifier, accessElection.getReferenceId(), true, false, new Date(), MatchAlgorithm.V3.getVersion(), false); // This match is never created under consent's workflow (unless the cause is a bug) // This is included simply to test the DataAccess conditional on the INNER JOIN statement - matchDAO.insertMatch(consentId, rpElection.getReferenceId(), false, false, new Date(), MatchAlgorithm.V3.getVersion(), false); + matchDAO.insertMatch(datasetIdentifier, rpElection.getReferenceId(), false, false, new Date(), MatchAlgorithm.V3.getVersion(), false); //Negative testing means we'll feed the query a reference id that isn't tied to a DataAccess election //Again, a match like this usually isn't generated in a normal workflow unless bug occurs, but having the 'DataAccess' condition is a nice safety net @@ -161,7 +160,7 @@ public void testFindMatchesForLatestDataAccessElectionsByPurposeIds_NegativeTest } @Test - public void testFindMatchByPurposeIdAndConsentId() { + void testFindMatchByPurposeIdAndConsentId() { Match match = makeMockMatch(UUID.randomUUID().toString()); matchDAO.insertMatch( match.getConsent(), @@ -177,7 +176,7 @@ public void testFindMatchByPurposeIdAndConsentId() { } @Test - public void testFindMatchById() { + void testFindMatchById() { Match match = makeMockMatch(UUID.randomUUID().toString()); Integer matchId = matchDAO.insertMatch( match.getConsent(), @@ -192,7 +191,7 @@ public void testFindMatchById() { } @Test - public void testInsertFailureReason() { + void testInsertFailureReason() { Match match = makeMockMatch(UUID.randomUUID().toString()); match.setMatch(false); match.setAlgorithmVersion(MatchAlgorithm.V3.getVersion()); @@ -214,7 +213,7 @@ public void testInsertFailureReason() { } @Test - public void testDeleteFailureReasonsByConsentIds() { + void testDeleteFailureReasonsByConsentIds() { Match match = makeMockMatch(UUID.randomUUID().toString()); match.setMatch(false); match.setAlgorithmVersion(MatchAlgorithm.V3.getVersion()); @@ -236,7 +235,7 @@ public void testDeleteFailureReasonsByConsentIds() { } @Test - public void testDeleteFailureReasonsByPurposeIds() { + void testDeleteFailureReasonsByPurposeIds() { Match match = makeMockMatch(UUID.randomUUID().toString()); match.setMatch(false); match.setAlgorithmVersion(MatchAlgorithm.V3.getVersion()); @@ -304,20 +303,6 @@ private void createDatasetProperties(Integer datasetId) { datasetDAO.insertDatasetProperties(list); } - private Consent createConsent() { - String consentId = UUID.randomUUID().toString(); - consentDAO.insertConsent(consentId, - false, - "{\"generalUse\": true }", - "dul", - consentId, - "dulName", - new Date(), - new Date(), - "Group"); - return consentDAO.findConsentById(consentId); - } - private Election createRPElection(String referenceId, Integer datasetId) { Integer electionId = electionDAO.insertElection( ElectionType.RP.getValue(), diff --git a/src/test/java/org/broadinstitute/consent/http/db/UserDAOTest.java b/src/test/java/org/broadinstitute/consent/http/db/UserDAOTest.java index 2d91d2fa7f..f82e7cbfba 100644 --- a/src/test/java/org/broadinstitute/consent/http/db/UserDAOTest.java +++ b/src/test/java/org/broadinstitute/consent/http/db/UserDAOTest.java @@ -16,32 +16,25 @@ import java.util.Optional; import java.util.Random; import java.util.Set; -import java.util.UUID; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomUtils; -import org.broadinstitute.consent.http.enumeration.ElectionStatus; -import org.broadinstitute.consent.http.enumeration.ElectionType; import org.broadinstitute.consent.http.enumeration.OrganizationType; import org.broadinstitute.consent.http.enumeration.UserRoles; -import org.broadinstitute.consent.http.enumeration.VoteType; -import org.broadinstitute.consent.http.models.Consent; import org.broadinstitute.consent.http.models.Dac; import org.broadinstitute.consent.http.models.DataUse; import org.broadinstitute.consent.http.models.DataUseBuilder; import org.broadinstitute.consent.http.models.Dataset; import org.broadinstitute.consent.http.models.DatasetProperty; -import org.broadinstitute.consent.http.models.Election; import org.broadinstitute.consent.http.models.Institution; import org.broadinstitute.consent.http.models.LibraryCard; import org.broadinstitute.consent.http.models.User; import org.broadinstitute.consent.http.models.UserRole; -import org.broadinstitute.consent.http.models.Vote; import org.junit.jupiter.api.Test; -public class UserDAOTest extends DAOTestHelper { +class UserDAOTest extends DAOTestHelper { @Test - public void testFindDACUserById() { + void testFindDACUserById() { User user = createUserWithRole(UserRoles.ALUMNI.getRoleId()); assertNotNull(user); assertFalse(user.getRoles().isEmpty()); @@ -73,7 +66,7 @@ public void testFindDACUserById() { } @Test - public void testFindUsers_withIdCollection() { + void testFindUsers_withIdCollection() { User user = createUser(); Collection users = userDAO.findUsers(Collections.singletonList(user.getUserId())); assertNotNull(users); @@ -82,7 +75,7 @@ public void testFindUsers_withIdCollection() { } @Test - public void testDescribeUsersByRole() { + void testDescribeUsersByRole() { createUserWithRole(UserRoles.CHAIRPERSON.getRoleId()); createUserWithRole(UserRoles.MEMBER.getRoleId()); @@ -107,7 +100,7 @@ public void testDescribeUsersByRole() { } @Test - public void testCheckChairpersonUser() { + void testCheckChairpersonUser() { User chair = createUserWithRole(UserRoles.CHAIRPERSON.getRoleId()); User member = createUserWithRole(UserRoles.MEMBER.getRoleId()); assertNotNull(userDAO.checkChairpersonUser(chair.getUserId())); @@ -115,14 +108,14 @@ public void testCheckChairpersonUser() { } @Test - public void testFindDACUsersEnabledToVoteByDacEmpty() { + void testFindDACUsersEnabledToVoteByDacEmpty() { Dac dac = createDac(); Collection users = userDAO.findUsersEnabledToVoteByDAC(dac.getDacId()); assertTrue(users.isEmpty()); } @Test - public void testFindDACUsersEnabledToVoteByDacNotEmpty() { + void testFindDACUsersEnabledToVoteByDacNotEmpty() { Dac dac = createDac(); User chair = createUserWithRole(UserRoles.CHAIRPERSON.getRoleId()); dacDAO.addDacMember(UserRoles.CHAIRPERSON.getRoleId(), chair.getUserId(), dac.getDacId()); @@ -131,7 +124,7 @@ public void testFindDACUsersEnabledToVoteByDacNotEmpty() { } @Test - public void testFindNonDACUsersEnabledToVote() { + void testFindNonDACUsersEnabledToVote() { createUserWithRole(UserRoles.CHAIRPERSON.getRoleId()); createUserWithRole(UserRoles.MEMBER.getRoleId()); Collection users = userDAO.findNonDacUsersEnabledToVote(); @@ -139,7 +132,7 @@ public void testFindNonDACUsersEnabledToVote() { } @Test - public void testFindUsersWithRoles() { + void testFindUsersWithRoles() { User chair = createUserWithRole(UserRoles.ADMIN.getRoleId()); userRoleDAO.insertSingleUserRole(UserRoles.DATAOWNER.getRoleId(), chair.getUserId()); Collection userIds = Collections.singletonList(chair.getUserId()); @@ -153,7 +146,7 @@ public void testFindUsersWithRoles() { } @Test - public void testFindUserByEmail() { + void testFindUserByEmail() { User user = createUser(); userRoleDAO.insertSingleUserRole(UserRoles.ALUMNI.getRoleId(), user.getUserId()); userRoleDAO.insertSingleUserRole(UserRoles.ADMIN.getRoleId(), user.getUserId()); @@ -177,7 +170,7 @@ public void testFindUserByEmail() { } @Test - public void testFindUserByEmails() { + void testFindUserByEmails() { User user1 = createUser(); userRoleDAO.insertSingleUserRole(UserRoles.ADMIN.getRoleId(), user1.getUserId()); User user2 = createUser(); @@ -196,12 +189,12 @@ public void testFindUserByEmails() { } @Test - public void testInsertUser() { + void testInsertUser() { // No-op ... tested in `createUser()` } @Test - public void testUpdateUser_case1() { + void testUpdateUser_case1() { User user = createUser(); Institution firstInstitute = createInstitution(); userDAO.updateUser( @@ -214,12 +207,12 @@ public void testUpdateUser_case1() { } @Test - public void testDeleteUserById() { + void testDeleteUserById() { // No-op ... tested in `tearDown()` } @Test - public void testFindUsersWithLCsAndInstitution() { + void testFindUsersWithLCsAndInstitution() { User user = createUserWithInstitution(); libraryCardDAO.insertLibraryCard(user.getUserId(), user.getInstitutionId(), "asdf", user.getDisplayName(), user.getEmail(), user.getUserId(), new Date()); @@ -242,7 +235,7 @@ public void testFindUsersWithLCsAndInstitution() { } @Test - public void testDescribeUsersByRoleAndEmailPreference() { + void testDescribeUsersByRoleAndEmailPreference() { User researcher = createUserWithRole(UserRoles.RESEARCHER.getRoleId()); userDAO.updateEmailPreference(researcher.getUserId(), true); Collection researchers = userDAO.describeUsersByRoleAndEmailPreference("Researcher", @@ -256,7 +249,7 @@ public void testDescribeUsersByRoleAndEmailPreference() { } @Test - public void testUpdateEmailPreference() { + void testUpdateEmailPreference() { User researcher = createUserWithRole(UserRoles.RESEARCHER.getRoleId()); userDAO.updateEmailPreference(researcher.getUserId(), true); User u1 = userDAO.findUserById(researcher.getUserId()); @@ -267,7 +260,7 @@ public void testUpdateEmailPreference() { } @Test - public void testUpdateInstitutionId() { + void testUpdateInstitutionId() { User researcher = createUserWithRole(UserRoles.RESEARCHER.getRoleId()); Integer institutionId = institutionDAO.insertInstitution("Institution", "it director", "it director email", null, null, null, null, null, null, researcher.getUserId(), @@ -278,7 +271,7 @@ public void testUpdateInstitutionId() { } @Test - public void testUpdateDisplayName() { + void testUpdateDisplayName() { User researcher = createUserWithRole(UserRoles.RESEARCHER.getRoleId()); String newName = RandomStringUtils.random(10, true, false); userDAO.updateDisplayName(researcher.getUserId(), newName); @@ -287,7 +280,7 @@ public void testUpdateDisplayName() { } @Test - public void testFindUserByEmailAndRoleId() { + void testFindUserByEmailAndRoleId() { User chair = createUserWithRole(UserRoles.CHAIRPERSON.getRoleId()); User user = userDAO.findUserByEmailAndRoleId(chair.getEmail(), UserRoles.CHAIRPERSON.getRoleId()); @@ -297,14 +290,11 @@ public void testFindUserByEmailAndRoleId() { } @Test - public void testFindUsersForDatasetsByRole() { + void testFindUsersForDatasetsByRole() { Dataset dataset = createDataset(); Dac dac = createDac(); User user = createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); - Consent consent = createConsent(); datasetDAO.updateDatasetDacId(dataset.getDataSetId(), dac.getDacId()); - consentDAO.insertConsentAssociation(consent.getConsentId(), ASSOCIATION_TYPE_TEST, - dataset.getDataSetId()); Set users = userDAO.findUsersForDatasetsByRole( Collections.singletonList(dataset.getDataSetId()), @@ -317,14 +307,11 @@ public void testFindUsersForDatasetsByRole() { } @Test - public void testFindUsersForDatasetsByRoleNotFound() { + void testFindUsersForDatasetsByRoleNotFound() { Dataset dataset = createDataset(); Dac dac = createDac(); createUserWithRoleInDac(UserRoles.MEMBER.getRoleId(), dac.getDacId()); - Consent consent = createConsent(); datasetDAO.updateDatasetDacId(dataset.getDataSetId(), dac.getDacId()); - consentDAO.insertConsentAssociation(consent.getConsentId(), ASSOCIATION_TYPE_TEST, - dataset.getDataSetId()); Set users = userDAO.findUsersForDatasetsByRole( Collections.singletonList(dataset.getDataSetId()), @@ -334,7 +321,7 @@ public void testFindUsersForDatasetsByRoleNotFound() { } @Test - public void testFindUsersByInstitution() { + void testFindUsersByInstitution() { Integer institutionId = createUserWithInstitution().getInstitutionId(); List beforeList = userDAO.findUsersByInstitution(institutionId); //should not change results since they are not in the institution @@ -346,7 +333,7 @@ public void testFindUsersByInstitution() { } @Test - public void testGetSOsByInstitution() { + void testGetSOsByInstitution() { //user with institutionId and SO role User user = createUserWithInstitution(); Integer institutionId = user.getInstitutionId(); @@ -362,7 +349,7 @@ public void testGetSOsByInstitution() { } @Test - public void testGetUsersFromInstitutionWithCards() { + void testGetUsersFromInstitutionWithCards() { LibraryCard card = createLibraryCard(); Integer institutionId = card.getInstitutionId(); Integer userId = card.getUserId(); @@ -377,7 +364,7 @@ public void testGetUsersFromInstitutionWithCards() { } @Test - public void testGetUsersWithNoInstitution() { + void testGetUsersWithNoInstitution() { createUserWithInstitution(); User user = createUser(); List users = userDAO.getUsersWithNoInstitution(); @@ -386,7 +373,7 @@ public void testGetUsersWithNoInstitution() { } @Test - public void testUpdateEraCommonsId() { + void testUpdateEraCommonsId() { User u = createUser(); String era = u.getEraCommonsId(); assertNull(era); @@ -396,7 +383,7 @@ public void testUpdateEraCommonsId() { } @Test - public void testCanAddAllRoles() { + void testCanAddAllRoles() { User u = createUser(); UserRoles[] roles = UserRoles.values(); @@ -419,7 +406,7 @@ public void testCanAddAllRoles() { } @Test - public void testCanBeChairOfTwoDACs() { + void testCanBeChairOfTwoDACs() { User u = createUser(); Dac dac1 = createDac(); Dac dac2 = createDac(); @@ -524,36 +511,6 @@ private LibraryCard createLibraryCard() { return libraryCardDAO.findLibraryCardById(id); } - private Vote createDacVote(Integer userId, Integer electionId) { - Integer voteId = voteDAO.insertVote(userId, electionId, VoteType.DAC.getValue()); - return voteDAO.findVoteById(voteId); - } - - private Consent createConsent() { - String consentId = UUID.randomUUID().toString(); - consentDAO.insertConsent(consentId, - false, - "{\"generalUse\": true }", - "dul", - consentId, - "dulName", - new Date(), - new Date(), - "Group"); - return consentDAO.findConsentById(consentId); - } - - private Election createDataAccessElection(String referenceId, Integer datasetId) { - Integer electionId = electionDAO.insertElection( - ElectionType.DATA_ACCESS.getValue(), - ElectionStatus.OPEN.getValue(), - new Date(), - referenceId, - datasetId - ); - return electionDAO.findElectionById(electionId); - } - private User createUserWithRoleInDac(Integer roleId, Integer dacId) { User user = createUserWithRole(roleId); dacDAO.addDacMember(roleId, user.getUserId(), dacId); diff --git a/src/test/java/org/broadinstitute/consent/http/db/VoteDAOTest.java b/src/test/java/org/broadinstitute/consent/http/db/VoteDAOTest.java index 3b7306a074..54f185130b 100644 --- a/src/test/java/org/broadinstitute/consent/http/db/VoteDAOTest.java +++ b/src/test/java/org/broadinstitute/consent/http/db/VoteDAOTest.java @@ -14,14 +14,12 @@ import java.util.Date; import java.util.List; import java.util.Optional; -import java.util.UUID; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomUtils; import org.broadinstitute.consent.http.enumeration.ElectionStatus; import org.broadinstitute.consent.http.enumeration.ElectionType; import org.broadinstitute.consent.http.enumeration.UserRoles; import org.broadinstitute.consent.http.enumeration.VoteType; -import org.broadinstitute.consent.http.models.Consent; import org.broadinstitute.consent.http.models.Dac; import org.broadinstitute.consent.http.models.DarCollection; import org.broadinstitute.consent.http.models.DataAccessRequest; @@ -35,14 +33,18 @@ import org.broadinstitute.consent.http.models.Vote; import org.junit.jupiter.api.Test; -public class VoteDAOTest extends DAOTestHelper { +class VoteDAOTest extends DAOTestHelper { @Test - public void testFindVoteById() { + void testFindVoteById() { User user = createUserWithRole(UserRoles.CHAIRPERSON.getRoleId()); - Consent consent = createConsent(); Dataset dataset = createDataset(); - Election election = createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequestWithDatasetAndCollectionInfo(collection_id, + dataset.getDataSetId(), user.getUserId()); + Election election = createDataAccessElection(dar.getReferenceId(), dataset.getDataSetId()); Vote vote = createDacVote(user.getUserId(), election.getElectionId()); Vote foundVote = voteDAO.findVoteById(vote.getVoteId()); @@ -50,14 +52,18 @@ public void testFindVoteById() { } @Test - public void testFindVotesByIds() { + void testFindVotesByIds() { User user = createUserWithRole(UserRoles.CHAIRPERSON.getRoleId()); User user2 = createUserWithRole(UserRoles.MEMBER.getRoleId()); User user3 = createUserWithRole(UserRoles.MEMBER.getRoleId()); User user4 = createUserWithRole(UserRoles.MEMBER.getRoleId()); - Consent consent = createConsent(); Dataset dataset = createDataset(); - Election election = createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequestWithDatasetAndCollectionInfo(collection_id, + dataset.getDataSetId(), user.getUserId()); + Election election = createDataAccessElection(dar.getReferenceId(), dataset.getDataSetId()); Vote vote = createDacVote(user.getUserId(), election.getElectionId()); Vote vote2 = createDacVote(user2.getUserId(), election.getElectionId()); Vote vote3 = createDacVote(user3.getUserId(), election.getElectionId()); @@ -73,16 +79,24 @@ public void testFindVotesByIds() { } @Test - public void testFindVotesByElectionIds() { + void testFindVotesByElectionIds() { User user = createUserWithRole(UserRoles.CHAIRPERSON.getRoleId()); - Consent consent = createConsent(); Dataset dataset = createDataset(); - Election election = createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); + String darCode = "DAR-12345"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequestWithDatasetAndCollectionInfo(collection_id, + dataset.getDataSetId(), user.getUserId()); + Election election = createDataAccessElection(dar.getReferenceId(), dataset.getDataSetId()); createDacVote(user.getUserId(), election.getElectionId()); - Consent consent2 = createConsent(); Dataset dataset2 = createDataset(); - Election election2 = createDataAccessElection(consent2.getConsentId(), dataset2.getDataSetId()); + String darCode2 = "DAR-67890"; + Integer collection_id2 = darCollectionDAO.insertDarCollection(darCode2, user.getUserId(), + new Date()); + DataAccessRequest dar2 = createDataAccessRequestWithDatasetAndCollectionInfo(collection_id2, + dataset.getDataSetId(), user.getUserId()); + Election election2 = createDataAccessElection(dar2.getReferenceId(), dataset2.getDataSetId()); createDacVote(user.getUserId(), election2.getElectionId()); List electionIds = Arrays.asList(election.getElectionId(), election2.getElectionId()); @@ -93,11 +107,15 @@ public void testFindVotesByElectionIds() { } @Test - public void testFindVotesByElectionIdAndType() { + void testFindVotesByElectionIdAndType() { User user = createUserWithRole(UserRoles.CHAIRPERSON.getRoleId()); - Consent consent = createConsent(); Dataset dataset = createDataset(); - Election election = createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequestWithDatasetAndCollectionInfo(collection_id, + dataset.getDataSetId(), user.getUserId()); + Election election = createDataAccessElection(dar.getReferenceId(), dataset.getDataSetId()); Vote vote = createDacVote(user.getUserId(), election.getElectionId()); List foundVotes = voteDAO.findVotesByElectionIdAndType(election.getElectionId(), @@ -120,11 +138,15 @@ public void testFindVotesByElectionIdAndType() { } @Test - public void testFindVoteByElectionIdAndDACUserId() { + void testFindVoteByElectionIdAndDACUserId() { User user = createUserWithRole(UserRoles.CHAIRPERSON.getRoleId()); - Consent consent = createConsent(); Dataset dataset = createDataset(); - Election election = createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequestWithDatasetAndCollectionInfo(collection_id, + dataset.getDataSetId(), user.getUserId()); + Election election = createDataAccessElection(dar.getReferenceId(), dataset.getDataSetId()); Vote vote = createDacVote(user.getUserId(), election.getElectionId()); Vote foundVote = voteDAO.findVoteByElectionIdAndUserId(election.getElectionId(), @@ -134,11 +156,15 @@ public void testFindVoteByElectionIdAndDACUserId() { } @Test - public void testCheckVoteById() { + void testCheckVoteById() { User user = createUserWithRole(UserRoles.CHAIRPERSON.getRoleId()); - Consent consent = createConsent(); Dataset dataset = createDataset(); - Election election = createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequestWithDatasetAndCollectionInfo(collection_id, + dataset.getDataSetId(), user.getUserId()); + Election election = createDataAccessElection(dar.getReferenceId(), dataset.getDataSetId()); Vote vote = createDacVote(user.getUserId(), election.getElectionId()); Integer voteId = voteDAO.checkVoteById(election.getReferenceId(), vote.getVoteId()); @@ -147,18 +173,22 @@ public void testCheckVoteById() { } @Test - public void testInsertVote() { + void testInsertVote() { // no-op ... tested by `createDacVote` and `createFinalVote` } @Test - public void testCreateVote() { + void testCreateVote() { User user = createUser(); Dataset dataset = createDataset(); Dac dac = createDac(); - Consent consent = createConsent(); datasetDAO.updateDatasetDacId(dataset.getDataSetId(), dac.getDacId()); - Election election = createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequestWithDatasetAndCollectionInfo(collection_id, + dataset.getDataSetId(), user.getUserId()); + Election election = createDataAccessElection(dar.getReferenceId(), dataset.getDataSetId()); Vote v = createDacVote(user.getUserId(), election.getElectionId()); Vote vote = voteDAO.findVoteById(v.getVoteId()); @@ -167,13 +197,17 @@ public void testCreateVote() { } @Test - public void testUpdateVote() { + void testUpdateVote() { User user = createUser(); Dataset dataset = createDataset(); Dac dac = createDac(); - Consent consent = createConsent(); datasetDAO.updateDatasetDacId(dataset.getDataSetId(), dac.getDacId()); - Election election = createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequestWithDatasetAndCollectionInfo(collection_id, + dataset.getDataSetId(), user.getUserId()); + Election election = createDataAccessElection(dar.getReferenceId(), dataset.getDataSetId()); Vote v = createDacVote(user.getUserId(), election.getElectionId()); String rationale = "rationale"; @@ -191,18 +225,22 @@ public void testUpdateVote() { } @Test - public void testDeleteVotes() { + void testDeleteVotes() { // No-op ... tested by `tearDown()` } @Test - public void testUpdateVoteReminderFlag() { + void testUpdateVoteReminderFlag() { User user = createUser(); Dataset dataset = createDataset(); Dac dac = createDac(); - Consent consent = createConsent(); datasetDAO.updateDatasetDacId(dataset.getDataSetId(), dac.getDacId()); - Election election = createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequestWithDatasetAndCollectionInfo(collection_id, + dataset.getDataSetId(), user.getUserId()); + Election election = createDataAccessElection(dar.getReferenceId(), dataset.getDataSetId()); Vote v = createDacVote(user.getUserId(), election.getElectionId()); voteDAO.updateVoteReminderFlag(v.getVoteId(), true); @@ -215,12 +253,16 @@ public void testUpdateVoteReminderFlag() { } @Test - public void testFindTotalFinalVoteByElectionTypeAndVote() { + void testFindTotalFinalVoteByElectionTypeAndVote() { User user = createUser(); Dac dac = createDac(); Dataset dataset = createDatasetWithDac(dac.getDacId()); - Consent consent = createConsent(); - Election election = createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequestWithDatasetAndCollectionInfo(collection_id, + dataset.getDataSetId(), user.getUserId()); + Election election = createDataAccessElection(dar.getReferenceId(), dataset.getDataSetId()); electionDAO.updateElectionById( election.getElectionId(), ElectionStatus.CLOSED.getValue(), @@ -252,13 +294,17 @@ public void testFindTotalFinalVoteByElectionTypeAndVote() { } @Test - public void testFindMaxNumberOfDACMembers() { + void testFindMaxNumberOfDACMembers() { User user = createUser(); Dataset dataset = createDataset(); Dac dac = createDac(); - Consent consent = createConsent(); datasetDAO.updateDatasetDacId(dataset.getDataSetId(), dac.getDacId()); - Election election = createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequestWithDatasetAndCollectionInfo(collection_id, + dataset.getDataSetId(), user.getUserId()); + Election election = createDataAccessElection(dar.getReferenceId(), dataset.getDataSetId()); electionDAO.updateElectionById( election.getElectionId(), ElectionStatus.CLOSED.getValue(), @@ -282,15 +328,20 @@ public void testFindMaxNumberOfDACMembers() { } @Test - public void testInsertVotes() { + void testInsertVotes() { User user1 = createUserWithRole(UserRoles.CHAIRPERSON.getRoleId()); User user2 = createUserWithRole(UserRoles.MEMBER.getRoleId()); User user3 = createUserWithRole(UserRoles.MEMBER.getRoleId()); Dataset dataset = createDataset(); Dac dac = createDac(); - Consent consent = createConsent(); datasetDAO.updateDatasetDacId(dataset.getDataSetId(), dac.getDacId()); - Election election = createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); + User user4 = createUserWithRole(UserRoles.RESEARCHER.getRoleId()); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user4.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequestWithDatasetAndCollectionInfo(collection_id, + dataset.getDataSetId(), user4.getUserId()); + Election election = createDataAccessElection(dar.getReferenceId(), dataset.getDataSetId()); List userIds = Arrays.asList(user1.getUserId(), user2.getUserId(), user3.getUserId()); voteDAO.insertVotes(userIds, election.getElectionId(), VoteType.DAC.getValue()); @@ -302,13 +353,17 @@ public void testInsertVotes() { } @Test - public void testRemoveVotesByIds() { + void testRemoveVotesByIds() { User user = createUserWithRole(UserRoles.CHAIRPERSON.getRoleId()); Dataset dataset = createDataset(); Dac dac = createDac(); - Consent consent = createConsent(); datasetDAO.updateDatasetDacId(dataset.getDataSetId(), dac.getDacId()); - Election election = createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequestWithDatasetAndCollectionInfo(collection_id, + dataset.getDataSetId(), user.getUserId()); + Election election = createDataAccessElection(dar.getReferenceId(), dataset.getDataSetId()); Vote vote = createDacVote(user.getUserId(), election.getElectionId()); voteDAO.removeVotesByIds(Collections.singletonList(vote.getVoteId())); @@ -317,13 +372,17 @@ public void testRemoveVotesByIds() { } @Test - public void testFindVotesByUserId() { + void testFindVotesByUserId() { User user = createUserWithRole(UserRoles.CHAIRPERSON.getRoleId()); Dataset dataset = createDataset(); Dac dac = createDac(); - Consent consent = createConsent(); datasetDAO.updateDatasetDacId(dataset.getDataSetId(), dac.getDacId()); - Election election = createDataAccessElection(consent.getConsentId(), dataset.getDataSetId()); + String darCode = "DAR-1234567890"; + Integer collection_id = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), + new Date()); + DataAccessRequest dar = createDataAccessRequestWithDatasetAndCollectionInfo(collection_id, + dataset.getDataSetId(), user.getUserId()); + Election election = createDataAccessElection(dar.getReferenceId(), dataset.getDataSetId()); createChairpersonVote(user.getUserId(), election.getElectionId()); List userVotes = voteDAO.findVotesByUserId(user.getUserId()); @@ -332,7 +391,7 @@ public void testFindVotesByUserId() { } @Test - public void testUpdateRationaleByVoteIds() { + void testUpdateRationaleByVoteIds() { Dataset dataset = createDataset(); Dac dac = createDac(); User user = createUserWithRoleInDac(UserRoles.MEMBER.getRoleId(), dac.getDacId()); @@ -349,7 +408,7 @@ public void testUpdateRationaleByVoteIds() { } @Test - public void testFindVoteUsersByElectionReferenceIdList_Empty() { + void testFindVoteUsersByElectionReferenceIdList_Empty() { // Empty case List voteUsers = voteDAO.findVoteUsersByElectionReferenceIdList( List.of("invalid reference id")); @@ -357,7 +416,7 @@ public void testFindVoteUsersByElectionReferenceIdList_Empty() { } @Test - public void testFindVoteUsersByElectionReferenceIdList() { + void testFindVoteUsersByElectionReferenceIdList() { // Populated case requires: // * DAC // * Dataset @@ -461,20 +520,6 @@ private Vote createDacVote(Integer userId, Integer electionId) { return voteDAO.findVoteById(voteId); } - private Consent createConsent() { - String consentId = UUID.randomUUID().toString(); - consentDAO.insertConsent(consentId, - false, - "{\"generalUse\": true }", - "dul", - consentId, - "dulName", - new Date(), - new Date(), - "Group"); - return consentDAO.findConsentById(consentId); - } - private Vote createFinalVote(Integer userId, Integer electionId) { Integer voteId = voteDAO.insertVote(userId, electionId, VoteType.FINAL.getValue()); return voteDAO.findVoteById(voteId); diff --git a/src/test/java/org/broadinstitute/consent/http/resources/ConsentCasesResourceTest.java b/src/test/java/org/broadinstitute/consent/http/resources/ConsentCasesResourceTest.java deleted file mode 100644 index 99a22a32b9..0000000000 --- a/src/test/java/org/broadinstitute/consent/http/resources/ConsentCasesResourceTest.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.broadinstitute.consent.http.resources; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.openMocks; - -import jakarta.ws.rs.core.Response; -import java.util.Collections; -import java.util.List; -import java.util.UUID; -import org.broadinstitute.consent.http.enumeration.ElectionType; -import org.broadinstitute.consent.http.models.ConsentSummaryDetail; -import org.broadinstitute.consent.http.models.DataAccessRequestSummaryDetail; -import org.broadinstitute.consent.http.models.Summary; -import org.broadinstitute.consent.http.service.SummaryService; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; - -public class ConsentCasesResourceTest { - - @Mock - SummaryService summaryService; - - private ConsentCasesResource resource; - - @BeforeEach - public void setUp() { - openMocks(this); - } - - @Test - public void testGetConsentSummaryCases() { - when(summaryService.describeConsentSummaryCases()).thenReturn(new Summary()); - initResource(); - Response response = resource.getConsentSummaryCases(null); - assertEquals(200, response.getStatus()); - Object summary = response.getEntity(); - assertNotNull(summary); - } - - @Test - public void testGetConsentSummaryDetailFileInvalid() { - initResource(); - Response response = resource.getConsentSummaryDetailFile(UUID.randomUUID().toString(), null); - assertEquals(200, response.getStatus()); - Object summaryFile = response.getEntity(); - assertNull(summaryFile); - } - - @Test - public void testGetConsentSummaryDetailFileDUL() { - List details = Collections.emptyList(); - when(summaryService.describeConsentSummaryDetail()).thenReturn(details); - initResource(); - Response response = resource.getConsentSummaryDetailFile(ElectionType.TRANSLATE_DUL.getValue(), - null); - assertEquals(200, response.getStatus()); - Object summaryDetails = response.getEntity(); - assertNull(summaryDetails); - } - - @Test - public void testGetConsentSummaryDetailFileDataAccess() { - List details = Collections.emptyList(); - when(summaryService.listDataAccessRequestSummaryDetails()).thenReturn(details); - initResource(); - Response response = resource.getConsentSummaryDetailFile(ElectionType.DATA_ACCESS.getValue(), - null); - assertEquals(200, response.getStatus()); - Object summaryDetails = response.getEntity(); - assertNull(summaryDetails); - } - - @Test - public void testGetConsentSummaryDetailFileNoSelection() { - List details = Collections.emptyList(); - when(summaryService.listDataAccessRequestSummaryDetails()).thenReturn(details); - initResource(); - Response response = resource.getConsentSummaryDetailFile(null, null); - assertEquals(200, response.getStatus()); - Object summaryDetails = response.getEntity(); - assertNull(summaryDetails); - } - - private void initResource() { - resource = new ConsentCasesResource(summaryService); - } - -} diff --git a/src/test/java/org/broadinstitute/consent/http/resources/ConsentResourceTest.java b/src/test/java/org/broadinstitute/consent/http/resources/ConsentResourceTest.java deleted file mode 100644 index 511bc3af63..0000000000 --- a/src/test/java/org/broadinstitute/consent/http/resources/ConsentResourceTest.java +++ /dev/null @@ -1,170 +0,0 @@ -package org.broadinstitute.consent.http.resources; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.openMocks; - -import jakarta.ws.rs.core.Response; -import jakarta.ws.rs.core.UriBuilder; -import jakarta.ws.rs.core.UriInfo; -import java.net.URI; -import java.util.UUID; -import org.broadinstitute.consent.http.models.AuthUser; -import org.broadinstitute.consent.http.models.Consent; -import org.broadinstitute.consent.http.models.DataUseBuilder; -import org.broadinstitute.consent.http.models.User; -import org.broadinstitute.consent.http.service.AuditService; -import org.broadinstitute.consent.http.service.ConsentService; -import org.broadinstitute.consent.http.service.MatchService; -import org.broadinstitute.consent.http.service.UserService; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; - - -public class ConsentResourceTest { - - @Mock - private AuditService auditService; - @Mock - private ConsentService consentService; - @Mock - private MatchService matchService; - @Mock - private UserService userService; - @Mock - UriInfo info; - @Mock - UriBuilder builder; - - private ConsentResource resource; - - @BeforeEach - public void setUp() { - openMocks(this); - } - - private void initResource() { - when(builder.path(anyString())).thenReturn(builder); - when(builder.build()).thenReturn(URI.create("https://test.domain.org/some/path")); - when(info.getRequestUriBuilder()).thenReturn(builder); - resource = new ConsentResource(auditService, userService, consentService, matchService); - } - - @Test - public void testCreateConsent() throws Exception { - User dacUser = new User(); - dacUser.setEmail("test@email.com"); - AuthUser user = new AuthUser(dacUser.getEmail()); - Consent consent = new Consent(); - consent.setConsentId(UUID.randomUUID().toString()); - consent.setDataUse(new DataUseBuilder().setGeneralUse(true).build()); - - when(userService.findUserByEmail(any())).thenReturn(dacUser); - when(consentService.create(any())).thenReturn(consent); - doNothing().when(auditService).saveConsentAudit(any(), any(), any(), any()); - doNothing().when(matchService).reprocessMatchesForConsent(any()); - - initResource(); - - Response response = resource.createConsent(info, consent, user); - assertEquals(201, response.getStatus()); - } - - @Test - public void testUpdateConsent() throws Exception { - User dacUser = new User(); - dacUser.setEmail("test@email.com"); - AuthUser user = new AuthUser(dacUser.getEmail()); - Consent consent = new Consent(); - consent.setLastElectionArchived(true); // Unarchived consents cannot be updated. - consent.setConsentId(UUID.randomUUID().toString()); - consent.setDataUse(new DataUseBuilder().setGeneralUse(true).build()); - - when(userService.findUserByEmail(any())).thenReturn(dacUser); - when(consentService.retrieve(any())).thenReturn(consent); - when(consentService.update(any(), any())).thenReturn(consent); - doNothing().when(auditService).saveConsentAudit(any(), any(), any(), any()); - doNothing().when(matchService).reprocessMatchesForConsent(any()); - - initResource(); - - Response response = resource.update(consent.getConsentId(), consent, user); - assertEquals(200, response.getStatus()); - } - - @Test - public void testDeleteConsent() { - doNothing().when(consentService).delete(any()); - initResource(); - - Response response = resource.delete(UUID.randomUUID().toString()); - assertEquals(200, response.getStatus()); - } - - @Test - public void testMissingDataUseCreate() { - User dacUser = new User(); - dacUser.setEmail("test@email.com"); - AuthUser user = new AuthUser(dacUser.getEmail()); - Consent consent = new Consent(); - consent.setConsentId(UUID.randomUUID().toString()); - when(userService.findUserByEmail(any())).thenReturn(dacUser); - initResource(); - - Response response = resource.createConsent(info, consent, user); - assertEquals(400, response.getStatus()); - } - - @Test - public void testMissingDataUseUpdate() throws Exception { - User dacUser = new User(); - dacUser.setEmail("test@email.com"); - AuthUser user = new AuthUser(dacUser.getEmail()); - Consent consent = new Consent(); - consent.setConsentId(UUID.randomUUID().toString()); - when(consentService.retrieve(any())).thenReturn(consent); - when(userService.findUserByEmail(any())).thenReturn(dacUser); - initResource(); - - Response response = resource.update(consent.getConsentId(), consent, user); - assertEquals(400, response.getStatus()); - } - - @Test - public void testInvalidDULCreate() throws Exception { - User dacUser = new User(); - dacUser.setEmail("test@email.com"); - AuthUser user = new AuthUser(dacUser.getEmail()); - Consent consent = new Consent(); - consent.setDataUse(new DataUseBuilder().setGeneralUse(true).build()); - consent.setConsentId(UUID.randomUUID().toString()); - consent.setDataUseLetter(UUID.randomUUID().toString()); - when(consentService.retrieve(any())).thenReturn(consent); - when(userService.findUserByEmail(any())).thenReturn(dacUser); - initResource(); - - Response response = resource.createConsent(info, consent, user); - assertEquals(400, response.getStatus()); - } - - @Test - public void testInvalidDULUpdate() throws Exception { - User dacUser = new User(); - dacUser.setEmail("test@email.com"); - AuthUser user = new AuthUser(dacUser.getEmail()); - Consent consent = new Consent(); - consent.setConsentId(UUID.randomUUID().toString()); - consent.setDataUseLetter(UUID.randomUUID().toString()); - when(consentService.retrieve(any())).thenReturn(consent); - when(userService.findUserByEmail(any())).thenReturn(dacUser); - initResource(); - - Response response = resource.update(consent.getConsentId(), consent, user); - assertEquals(400, response.getStatus()); - } - -} diff --git a/src/test/java/org/broadinstitute/consent/http/resources/DataRequestCasesResourceTest.java b/src/test/java/org/broadinstitute/consent/http/resources/DataRequestCasesResourceTest.java deleted file mode 100644 index 65da623a05..0000000000 --- a/src/test/java/org/broadinstitute/consent/http/resources/DataRequestCasesResourceTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.broadinstitute.consent.http.resources; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.openMocks; - -import jakarta.ws.rs.core.Response; -import java.util.Collections; -import java.util.List; -import org.broadinstitute.consent.http.models.Summary; -import org.broadinstitute.consent.http.service.SummaryService; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; - -public class DataRequestCasesResourceTest { - - @Mock - SummaryService summaryService; - - private DataRequestCasesResource resource; - - @BeforeEach - public void setUp() { - openMocks(this); - } - - @Test - public void testGetDataRequestSummaryCases() { - when(summaryService.describeDataRequestSummaryCases(any())).thenReturn(new Summary()); - initResource(); - Response response = resource.getDataRequestSummaryCases(null, null); - assertEquals(200, response.getStatus()); - Summary summary = ((Summary) response.getEntity()); - assertNotNull(summary); - } - - @Test - public void testGetMatchSummaryCases() { - when(summaryService.describeMatchSummaryCases()).thenReturn(Collections.emptyList()); - initResource(); - Response response = resource.getMatchSummaryCases(null); - assertEquals(200, response.getStatus()); - List summaries = ((List) response.getEntity()); - assertTrue(summaries.isEmpty()); - } - - private void initResource() { - resource = new DataRequestCasesResource(summaryService); - } - -} diff --git a/src/test/java/org/broadinstitute/consent/http/service/ConsentServiceTest.java b/src/test/java/org/broadinstitute/consent/http/service/ConsentServiceTest.java deleted file mode 100644 index 99e11b2202..0000000000 --- a/src/test/java/org/broadinstitute/consent/http/service/ConsentServiceTest.java +++ /dev/null @@ -1,156 +0,0 @@ -package org.broadinstitute.consent.http.service; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.fail; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.openMocks; - -import java.sql.Timestamp; -import java.time.LocalDate; -import java.time.ZoneId; -import java.util.Date; -import org.broadinstitute.consent.http.db.ConsentDAO; -import org.broadinstitute.consent.http.db.ElectionDAO; -import org.broadinstitute.consent.http.enumeration.ElectionStatus; -import org.broadinstitute.consent.http.exceptions.UnknownIdentifierException; -import org.broadinstitute.consent.http.models.Consent; -import org.broadinstitute.consent.http.models.DataUse; -import org.broadinstitute.consent.http.models.Election; -import org.joda.time.DateTimeField; -import org.joda.time.Instant; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; - -public class ConsentServiceTest { - - private ConsentService service; - - @Mock - ConsentDAO consentDAO; - - @Mock - ElectionDAO electionDAO; - - @BeforeEach - public void setUp() { - openMocks(this); - } - - private void initService() { - service = new ConsentService(consentDAO, electionDAO); - } - - @Test - public void testCreate() { - Consent testConsent = this.getTestConsent(); - when(consentDAO.checkConsentById(any())) - .thenReturn(null); - when(consentDAO.getIdByName(any())) - .thenReturn(null); - when(consentDAO.checkConsentById("test consent")) - .thenReturn("test consent"); - doNothing().when(consentDAO) - .insertConsent(any(), any(), any(), any(), any(), any(), any(), any(), any()); - when(consentDAO.findConsentById(any())) - .thenReturn(testConsent); - initService(); - - Consent consent = service.create(testConsent); - assertNotNull(consent); - assertEquals(consent.getName(), testConsent.getName()); - } - - @Test - public void testUpdate() { - Timestamp updateDate = new Timestamp(new Date().getTime()); - LocalDate localDate = LocalDate.now(); - ZoneId defaultZoneId = ZoneId.systemDefault(); - Consent testConsent = this.getTestConsent(); - Timestamp prevTimestamp = new Timestamp( - Date.from(localDate.minusDays(1).atStartOfDay(defaultZoneId).toInstant()).getTime()); - testConsent.setLastUpdate(prevTimestamp); - testConsent.setSortDate(prevTimestamp); - - doNothing().when(consentDAO) - .updateConsent("test consent", testConsent.getRequiresManualReview(), - testConsent.getDataUse().toString(), - testConsent.getDataUseLetter(), testConsent.getName(), testConsent.getDulName(), - testConsent.getLastUpdate(), - testConsent.getSortDate(), - testConsent.getGroupName(), true); - when(consentDAO.checkConsentById("test consent")) - .thenReturn("test consent"); - when(consentDAO.findConsentById("test consent")) - .thenReturn(testConsent); - - initService(); - - Consent consent = service.update("test consent", testConsent); - assertNotNull(consent); - assertEquals(getDayOfYear(consent.getLastUpdate()), getDayOfYear(updateDate)); - assertEquals(getDayOfYear(consent.getSortDate()), getDayOfYear(updateDate)); - } - - private DateTimeField getDayOfYear(Timestamp timestamp) { - return new Instant(timestamp.getTime()).getChronology().dayOfYear(); - } - - @Test - public void testRetrieve() { - when(consentDAO.findConsentById("test consent")) - .thenReturn(this.getTestConsent()); - Election mockElection = this.getTestElection(); - when(electionDAO.findLastElectionByReferenceIdAndType(anyString(), anyString())).thenReturn( - mockElection); - - initService(); - Consent consent = null; - try { - consent = service.retrieve("test consent"); - } catch (UnknownIdentifierException unknownIdentifierException) { - fail(unknownIdentifierException.getMessage()); - } - assertNotNull(consent); - assertEquals(consent.getConsentId(), this.getTestConsent().getConsentId()); - assertEquals(consent.getLastElectionArchived(), mockElection.getArchived()); - assertEquals(consent.getLastElectionStatus(), mockElection.getStatus()); - } - - @Test - public void testGetByName() { - when(consentDAO.findConsentByName("test consent")) - .thenReturn(this.getTestConsent()); - initService(); - - Consent consent = null; - try { - consent = service.getByName("test consent"); - } catch (UnknownIdentifierException unknownIdentifierException) { - fail(unknownIdentifierException.getMessage()); - } - - assertNotNull(consent); - } - - private Consent getTestConsent() { - Consent consent = new Consent(false, "data use", - "test consent", new Timestamp(new Date().getTime()), new Timestamp(new Date().getTime()), - new Timestamp(new Date().getTime()), "test consent group"); - consent.setDataUse(new DataUse()); - - return consent; - } - - private Election getTestElection() { - Election mockElection = new Election(); - mockElection.setStatus(ElectionStatus.OPEN.getValue()); - mockElection.setArchived(false); - return mockElection; - } - -} diff --git a/src/test/java/org/broadinstitute/consent/http/service/DacServiceTest.java b/src/test/java/org/broadinstitute/consent/http/service/DacServiceTest.java index c11de4edce..4a86c65532 100644 --- a/src/test/java/org/broadinstitute/consent/http/service/DacServiceTest.java +++ b/src/test/java/org/broadinstitute/consent/http/service/DacServiceTest.java @@ -36,7 +36,6 @@ import org.broadinstitute.consent.http.enumeration.ElectionType; import org.broadinstitute.consent.http.enumeration.UserRoles; import org.broadinstitute.consent.http.models.AuthUser; -import org.broadinstitute.consent.http.models.Consent; import org.broadinstitute.consent.http.models.Dac; import org.broadinstitute.consent.http.models.DataAccessRequest; import org.broadinstitute.consent.http.models.DataAccessRequestData; @@ -50,7 +49,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mock; -public class DacServiceTest { +class DacServiceTest { private DacService service; @@ -83,7 +82,7 @@ private void initService() { } @Test - public void testFindAll() { + void testFindAll() { when(dacDAO.findAll()).thenReturn(Collections.emptyList()); initService(); @@ -91,7 +90,7 @@ public void testFindAll() { } @Test - public void testFindAllDACUsersBySearchString_case1() { + void testFindAllDACUsersBySearchString_case1() { when(dacDAO.findAll()).thenReturn(Collections.emptyList()); when(dacDAO.findAllDACUserMemberships()).thenReturn(Collections.emptyList()); initService(); @@ -100,7 +99,7 @@ public void testFindAllDACUsersBySearchString_case1() { } @Test - public void testFindAllDACUsersBySearchString_case2() { + void testFindAllDACUsersBySearchString_case2() { when(dacDAO.findAll()).thenReturn(getDacs()); when(dacDAO.findAllDACUserMemberships()).thenReturn(getDacUsers()); initService(); @@ -118,7 +117,7 @@ public void testFindAllDACUsersBySearchString_case2() { } @Test - public void testFindById() { + void testFindById() { int dacId = 1; when(dacDAO.findById(dacId)).thenReturn(getDacs().get(0)); when(dacDAO.findMembersByDacIdAndRoleId(dacId, UserRoles.CHAIRPERSON.getRoleId())).thenReturn( @@ -134,7 +133,7 @@ public void testFindById() { } @Test - public void testCreateDac() { + void testCreateDac() { when(dacDAO.createDac(anyString(), anyString(), any())).thenReturn(getDacs().get(0).getDacId()); initService(); @@ -143,7 +142,7 @@ public void testCreateDac() { } @Test - public void testCreateDacWithEmail() { + void testCreateDacWithEmail() { when(dacDAO.createDac(anyString(), anyString(), anyString(), any())).thenReturn( getDacs().get(0).getDacId()); initService(); @@ -153,7 +152,7 @@ public void testCreateDacWithEmail() { } @Test - public void testUpdateDac() { + void testUpdateDac() { doNothing().when(dacDAO).updateDac(anyString(), anyString(), any(), any()); initService(); @@ -165,7 +164,7 @@ public void testUpdateDac() { } @Test - public void testUpdateDacWithEmail() { + void testUpdateDacWithEmail() { doNothing().when(dacDAO).updateDac(anyString(), anyString(), anyString(), any(), any()); initService(); @@ -177,7 +176,7 @@ public void testUpdateDacWithEmail() { } @Test - public void testDeleteDac() { + void testDeleteDac() { doNothing().when(dacDAO).deleteDacMembers(anyInt()); doNothing().when(dacDAO).deleteDac(anyInt()); initService(); @@ -190,7 +189,7 @@ public void testDeleteDac() { } @Test - public void testFindDatasetsByDacId() { + void testFindDatasetsByDacId() { List datasets = getDatasets(); when(dataSetDAO.findDatasetsAssociatedWithDac(1)).thenReturn(datasets); @@ -202,7 +201,7 @@ public void testFindDatasetsByDacId() { } @Test - public void testFindMembersByDacId() { + void testFindMembersByDacId() { when(dacDAO.findMembersByDacId(anyInt())).thenReturn( Collections.singletonList(getDacUsers().get(0))); when(dacDAO.findUserRolesForUsers(any())).thenReturn(getDacUsers().get(0).getRoles()); @@ -214,7 +213,7 @@ public void testFindMembersByDacId() { } @Test - public void testAddDacMember() { + void testAddDacMember() { Gson gson = new Gson(); User user = getDacUsers().get(0); Dac dac = getDacs().get(0); @@ -245,7 +244,7 @@ public void testAddDacMember() { } @Test - public void testRemoveDacMember() { + void testRemoveDacMember() { Role role = new Role(UserRoles.MEMBER.getRoleId(), UserRoles.MEMBER.getRoleName()); Dac dac = getDacs().get(0); User member = getDacUsers().get(1); @@ -265,7 +264,7 @@ public void testRemoveDacMember() { } @Test - public void testRemoveDacChair() { + void testRemoveDacChair() { Role role = new Role(UserRoles.CHAIRPERSON.getRoleId(), UserRoles.CHAIRPERSON.getRoleName()); Dac dac = getDacs().get(0); User chair1 = getDacUsers().get(0); @@ -286,7 +285,7 @@ public void testRemoveDacChair() { } @Test - public void testRemoveDacChairFailure() { + void testRemoveDacChairFailure() { Role role = new Role(UserRoles.CHAIRPERSON.getRoleId(), UserRoles.CHAIRPERSON.getRoleName()); Dac dac = getDacs().get(0); User chair = getDacUsers().get(0); @@ -304,7 +303,7 @@ public void testRemoveDacChairFailure() { } @Test - public void testIsAuthUserAdmin_case1() { + void testIsAuthUserAdmin_case1() { when(userDAO.findUserByEmailAndRoleId(anyString(), anyInt())).thenReturn(getDacUsers().get(0)); initService(); @@ -312,7 +311,7 @@ public void testIsAuthUserAdmin_case1() { } @Test - public void testIsAuthUserAdmin_case2() { + void testIsAuthUserAdmin_case2() { when(userDAO.findUserByEmailAndRoleId(anyString(), anyInt())).thenReturn(null); initService(); @@ -320,7 +319,7 @@ public void testIsAuthUserAdmin_case2() { } @Test - public void testIsAuthUserChair_case1() { + void testIsAuthUserChair_case1() { when(userDAO.findUserByEmailAndRoleId(anyString(), anyInt())).thenReturn(getDacUsers().get(0)); initService(); @@ -328,7 +327,7 @@ public void testIsAuthUserChair_case1() { } @Test - public void testIsAuthUserChair_case2() { + void testIsAuthUserChair_case2() { when(userDAO.findUserByEmailAndRoleId(anyString(), anyInt())).thenReturn(null); initService(); @@ -336,7 +335,7 @@ public void testIsAuthUserChair_case2() { } @Test - public void testFilterDataAccessRequestsByDAC_adminCase() { + void testFilterDataAccessRequestsByDAC_adminCase() { User user = new User(); user.setRoles(new ArrayList<>()); user.getRoles().add(new UserRole(UserRoles.ADMIN.getRoleId(), UserRoles.ADMIN.getRoleName())); @@ -352,7 +351,7 @@ public void testFilterDataAccessRequestsByDAC_adminCase() { } @Test - public void testFilterDataAccessRequestsByDAC_memberCase_1() { + void testFilterDataAccessRequestsByDAC_memberCase_1() { // Member has access to DataSet 1 List memberDataSets = Collections.singletonList(getDatasets().get(0)); when(dataSetDAO.findDatasetsByAuthUserEmail(getMember().getEmail())).thenReturn(memberDataSets); @@ -368,7 +367,7 @@ public void testFilterDataAccessRequestsByDAC_memberCase_1() { } @Test - public void testFilterDataAccessRequestsByDAC_memberCase_2() { + void testFilterDataAccessRequestsByDAC_memberCase_2() { // Member has access to datasets List memberDataSets = Collections.singletonList(getDatasets().get(0)); when(dataSetDAO.findDatasetsByAuthUserEmail(getMember().getEmail())).thenReturn(memberDataSets); @@ -384,7 +383,7 @@ public void testFilterDataAccessRequestsByDAC_memberCase_2() { } @Test - public void testFilterDataAccessRequestsByDAC_memberCase_3() { + void testFilterDataAccessRequestsByDAC_memberCase_3() { // Member no direct access to datasets List memberDataSets = Collections.emptyList(); when(dataSetDAO.findDatasetsByAuthUserEmail(getMember().getEmail())).thenReturn(memberDataSets); @@ -400,7 +399,7 @@ public void testFilterDataAccessRequestsByDAC_memberCase_3() { } @Test - public void testFilterElectionsByDAC_adminCase() { + void testFilterElectionsByDAC_adminCase() { // User is an admin user when(userDAO.findUserByEmailAndRoleId(anyString(), anyInt())).thenReturn(getDacUsers().get(0)); initService(); @@ -408,12 +407,12 @@ public void testFilterElectionsByDAC_adminCase() { List elections = getElections(); Collection filtered = service.filterElectionsByDAC(elections, getUser()); - // As an admin, all consents should be returned. + // As an admin, all elections should be returned. assertEquals(elections.size(), filtered.size()); } @Test - public void testFilterElectionsByDAC_memberCase1() { + void testFilterElectionsByDAC_memberCase1() { // User is not an admin user when(userDAO.findUserByEmailAndRoleId(anyString(), anyInt())).thenReturn(null); @@ -427,12 +426,12 @@ public void testFilterElectionsByDAC_memberCase1() { List elections = getElections(); Collection filtered = service.filterElectionsByDAC(elections, getUser()); - // As a member, only direct-associated consents should be returned. + // As a member, only direct-associated datasets should be returned. assertEquals(memberDatasets.size(), filtered.size()); } @Test - public void testFilterElectionsByDAC_memberCase2() { + void testFilterElectionsByDAC_memberCase2() { // User is not an admin user when(userDAO.findUserByEmailAndRoleId(anyString(), anyInt())).thenReturn(null); @@ -461,7 +460,7 @@ public void testFilterElectionsByDAC_memberCase2() { } @Test - public void testFilterElectionsByDAC_memberCase3() { + void testFilterElectionsByDAC_memberCase3() { // User is not an admin user when(userDAO.findUserByEmailAndRoleId(anyString(), anyInt())).thenReturn(null); @@ -487,7 +486,7 @@ public void testFilterElectionsByDAC_memberCase3() { } @Test - public void testFindDacsByUserAdminCase() { + void testFindDacsByUserAdminCase() { List dacs = getDacs(); when(dacDAO.findDacsForEmail(anyString())).thenReturn(dacs); when(dacDAO.findAll()).thenReturn(dacs); @@ -500,7 +499,7 @@ public void testFindDacsByUserAdminCase() { } @Test - public void testFindDacsByUserChairCase() { + void testFindDacsByUserChairCase() { List dacs = getDacs(); when(dacDAO.findDacsForEmail(anyString())).thenReturn(dacs); when(dacDAO.findAll()).thenReturn(dacs); @@ -532,14 +531,6 @@ private List getElections() { }).collect(Collectors.toList()); } - /** - * @return A list of 5 consents - */ - private List getConsents() { - return IntStream.range(1, 5). - mapToObj(i -> new Consent()).collect(Collectors.toList()); - } - /** * @return A list of 5 DataAccessRequest with DataSet ids and Reference ids */ diff --git a/src/test/java/org/broadinstitute/consent/http/service/DataAccessRequestServiceTest.java b/src/test/java/org/broadinstitute/consent/http/service/DataAccessRequestServiceTest.java index fcfa92955b..a6f0a7687c 100644 --- a/src/test/java/org/broadinstitute/consent/http/service/DataAccessRequestServiceTest.java +++ b/src/test/java/org/broadinstitute/consent/http/service/DataAccessRequestServiceTest.java @@ -27,7 +27,6 @@ import java.util.Map; import java.util.UUID; import org.apache.commons.lang3.RandomUtils; -import org.broadinstitute.consent.http.db.ConsentDAO; import org.broadinstitute.consent.http.db.DAOContainer; import org.broadinstitute.consent.http.db.DacDAO; import org.broadinstitute.consent.http.db.DarCollectionDAO; @@ -42,7 +41,6 @@ import org.broadinstitute.consent.http.enumeration.HeaderDAR; import org.broadinstitute.consent.http.enumeration.UserRoles; import org.broadinstitute.consent.http.models.AuthUser; -import org.broadinstitute.consent.http.models.Consent; import org.broadinstitute.consent.http.models.DarCollection; import org.broadinstitute.consent.http.models.DataAccessRequest; import org.broadinstitute.consent.http.models.DataAccessRequestData; @@ -61,8 +59,6 @@ class DataAccessRequestServiceTest { - @Mock - private ConsentDAO consentDAO; @Mock private CounterService counterService; @Mock @@ -99,7 +95,6 @@ public void setUp() { private void initService() { DAOContainer container = new DAOContainer(); - container.setConsentDAO(consentDAO); container.setDataAccessRequestDAO(dataAccessRequestDAO); container.setDarCollectionDAO(darCollectionDAO); container.setInstitutionDAO(institutionDAO); @@ -269,12 +264,6 @@ void testCreateApprovedDARDocument() { institution.setName("Institution"); when(dataAccessRequestDAO.findByReferenceId(any())).thenReturn(dar); when(darCollectionDAO.findDARCollectionByReferenceId(any())).thenReturn(collection); - when(dataSetDAO.getAssociatedConsentIdByDatasetId(any())) - .thenReturn("CONS-1"); - - Consent consent = new Consent(); - consent.setConsentId("CONS-1"); - when(consentDAO.findConsentById("CONS-1")).thenReturn(consent); when(institutionDAO.findInstitutionById(any())).thenReturn(institution); initService(); try { @@ -308,14 +297,8 @@ void testCreateReviewedDARDocument() { when(darCollectionDAO.findDARCollectionByReferenceId(any())).thenReturn(collection); when(dataSetDAO.findDatasetById(any())).thenReturn(d); when(dataSetDAO.findDatasetsByIdList(any())).thenReturn(List.of(d)); - when(dataSetDAO.getAssociatedConsentIdByDatasetId(any())) - .thenReturn("CONS-1"); when(useRestrictionConverter.translateDataUse(any(), any())).thenReturn("Use is limited to research"); - Consent consent = new Consent(); - consent.setConsentId("CONS-1"); - consent.setName("Consent 1"); - when(consentDAO.findConsentById("CONS-1")).thenReturn(consent); initService(); try { diff --git a/src/test/java/org/broadinstitute/consent/http/service/DatasetServiceTest.java b/src/test/java/org/broadinstitute/consent/http/service/DatasetServiceTest.java index a9f5e2e4ac..95e0933222 100644 --- a/src/test/java/org/broadinstitute/consent/http/service/DatasetServiceTest.java +++ b/src/test/java/org/broadinstitute/consent/http/service/DatasetServiceTest.java @@ -822,7 +822,6 @@ private List getDatasets() { Dataset dataset = new Dataset(); dataset.setDataSetId(i); dataset.setName("Test Dataset " + i); - dataset.setConsentName("Test Consent " + i); dataset.setProperties(Collections.emptySet()); return dataset; }).collect(Collectors.toList()); diff --git a/src/test/java/org/broadinstitute/consent/http/service/EmailServiceTest.java b/src/test/java/org/broadinstitute/consent/http/service/EmailServiceTest.java index a8ace748eb..4f1c337ebf 100644 --- a/src/test/java/org/broadinstitute/consent/http/service/EmailServiceTest.java +++ b/src/test/java/org/broadinstitute/consent/http/service/EmailServiceTest.java @@ -18,7 +18,6 @@ import org.apache.commons.lang3.RandomUtils; import org.broadinstitute.consent.http.configurations.FreeMarkerConfiguration; import org.broadinstitute.consent.http.configurations.MailConfiguration; -import org.broadinstitute.consent.http.db.ConsentDAO; import org.broadinstitute.consent.http.db.DarCollectionDAO; import org.broadinstitute.consent.http.db.ElectionDAO; import org.broadinstitute.consent.http.db.MailMessageDAO; @@ -39,16 +38,13 @@ * Functional test emails will be directed to the private google group: * https://groups.google.com/a/broadinstitute.org/g/duos-dev */ -public class EmailServiceTest { +class EmailServiceTest { private EmailService service; @Mock private DarCollectionDAO collectionDAO; - @Mock - private ConsentDAO consentDAO; - @Mock private VoteDAO voteDAO; @@ -68,7 +64,7 @@ public class EmailServiceTest { private final static String serverUrl = "http://localhost:8000/#/"; @BeforeEach - public void setUp() { + void setUp() { } private void initService() { @@ -85,12 +81,12 @@ private void initService() { fmConfig.setDefaultEncoding("UTF-8"); fmConfig.setTemplateDirectory("/freemarker"); templateHelper = spy(new FreeMarkerTemplateHelper(fmConfig)); - service = new EmailService(collectionDAO, consentDAO, voteDAO, electionDAO, userDAO, + service = new EmailService(collectionDAO, voteDAO, electionDAO, userDAO, emailDAO, sendGridAPI, templateHelper, serverUrl); } @Test - public void testSendNewResearcherEmail() throws Exception { + void testSendNewResearcherEmail() throws Exception { initService(); User user = new User(); user.setUserId(1234); @@ -120,7 +116,7 @@ public void testSendNewResearcherEmail() throws Exception { } @Test - public void testFetchEmails() { + void testFetchEmails() { List mailMessages = generateMailMessageList(); initService(); when(emailDAO.fetchMessagesByType(any(), anyInt(), anyInt())).thenReturn(mailMessages); @@ -129,7 +125,7 @@ public void testFetchEmails() { } @Test - public void testFetchEmailsByCreateDate() { + void testFetchEmailsByCreateDate() { List mailMessages = generateMailMessageList(); initService(); Date startDate = new Date(); diff --git a/src/test/java/org/broadinstitute/consent/http/service/MatchServiceTest.java b/src/test/java/org/broadinstitute/consent/http/service/MatchServiceTest.java index f8db1a2690..c50e1feb25 100644 --- a/src/test/java/org/broadinstitute/consent/http/service/MatchServiceTest.java +++ b/src/test/java/org/broadinstitute/consent/http/service/MatchServiceTest.java @@ -27,7 +27,6 @@ import java.util.List; import java.util.UUID; import org.broadinstitute.consent.http.configurations.ServicesConfiguration; -import org.broadinstitute.consent.http.db.ConsentDAO; import org.broadinstitute.consent.http.db.DataAccessRequestDAO; import org.broadinstitute.consent.http.db.DatasetDAO; import org.broadinstitute.consent.http.db.MatchDAO; @@ -45,10 +44,8 @@ import org.mockito.Mockito; @SuppressWarnings({"unchecked", "resource"}) -public class MatchServiceTest { +class MatchServiceTest { - @Mock - ConsentDAO consentDAO; @Mock DatasetDAO datasetDAO; @Mock @@ -72,7 +69,7 @@ public class MatchServiceTest { private UseRestrictionConverter useRestrictionConverter; private void initService() { - service = new MatchService(clientMock, config, consentDAO, matchDAO, + service = new MatchService(clientMock, config, matchDAO, dataAccessRequestDAO, datasetDAO, useRestrictionConverter); } @@ -87,7 +84,7 @@ public void setUp() throws UnknownIdentifierException, IOException { } @Test - public void testInsertMatches() { + void testInsertMatches() { when(matchDAO.insertMatch(any(), any(), any(), any(), any(), any(), any())).thenReturn(1); doNothing().when(matchDAO).insertRationale(any(), any()); initService(); @@ -97,7 +94,7 @@ public void testInsertMatches() { } @Test - public void testFindMatchById() { + void testFindMatchById() { Match m = createMatchObject(); when(matchDAO.findMatchById(m.getId())).thenReturn(m); initService(); @@ -108,7 +105,7 @@ public void testFindMatchById() { } @Test - public void testFindMatchByIdNotFound() { + void testFindMatchByIdNotFound() { Match m = createMatchObject(); when(matchDAO.findMatchById(m.getId())).thenReturn(null); initService(); @@ -119,7 +116,7 @@ public void testFindMatchByIdNotFound() { } @Test - public void testFindMatchByConsentId() { + void testFindMatchByConsentId() { Match m = createMatchObject(); when(matchDAO.findMatchesByConsentId(any())).thenReturn(List.of(m)); initService(); @@ -131,7 +128,7 @@ public void testFindMatchByConsentId() { } @Test - public void testFindMatchByConsentIdNotFound() { + void testFindMatchByConsentIdNotFound() { Match m = createMatchObject(); when(matchDAO.findMatchesByConsentId(any())).thenReturn(List.of()); initService(); @@ -142,7 +139,7 @@ public void testFindMatchByConsentIdNotFound() { } @Test - public void testFindMatchForDataAccessRequest() { + void testFindMatchForDataAccessRequest() { DataAccessRequest dar = getSampleDataAccessRequest("DAR-2"); dar.setDatasetIds(List.of(1, 2, 3)); DataUseResponseMatchingObject responseObject = Mockito.mock( @@ -159,23 +156,7 @@ public void testFindMatchForDataAccessRequest() { } @Test - public void testCreateMatchesForConsent() { - Match m = createMatchObject(); - Dataset dataset = new Dataset(); - dataset.setDataSetId(1); - DataAccessRequest dar = new DataAccessRequest(); - dar.addDatasetId(1); - when(datasetDAO.getDatasetsForConsent(any())).thenReturn(List.of(dataset)); - when(dataAccessRequestDAO.findAllDataAccessRequests()).thenReturn(List.of(dar)); - initService(); - - service.createMatchesForConsent(m.getConsent()); - verify(datasetDAO, atLeastOnce()).getDatasetsForConsent(any()); - verify(dataAccessRequestDAO, atLeastOnce()).findAllDataAccessRequests(); - } - - @Test - public void testSingleEntitiesMatchV3EmptyDataset() { + void testSingleEntitiesMatchV3EmptyDataset() { DataAccessRequest dar = new DataAccessRequest(); initService(); assertThrows(IllegalArgumentException.class, () -> { @@ -184,7 +165,7 @@ public void testSingleEntitiesMatchV3EmptyDataset() { } @Test - public void testSingleEntitiesMatchV3EmptyDar() { + void testSingleEntitiesMatchV3EmptyDar() { Dataset dataset = new Dataset(); initService(); assertThrows(IllegalArgumentException.class, () -> { @@ -193,7 +174,7 @@ public void testSingleEntitiesMatchV3EmptyDar() { } @Test - public void testSingleEntitiesMatchV3Failure() { + void testSingleEntitiesMatchV3Failure() { Dataset dataset = new Dataset(); dataset.setDataSetId(1); dataset.setAlias(2); @@ -202,7 +183,6 @@ public void testSingleEntitiesMatchV3Failure() { dar.setDatasetIds(List.of(1, 2, 3)); Response response = Mockito.mock(Response.class); - when(datasetDAO.getDatasetsForConsent(any())).thenReturn(List.of(dataset)); when(dataAccessRequestDAO.findAllDataAccessRequests()).thenReturn(List.of(dar)); when(response.getStatus()).thenReturn(500); when(builder.post(any())).thenReturn(response); @@ -217,14 +197,13 @@ public void testSingleEntitiesMatchV3Failure() { } @Test - public void testSingleEntitiesMatchV3Approve() { + void testSingleEntitiesMatchV3Approve() { Dataset dataset = new Dataset(); dataset.setDataSetId(1); DataAccessRequest dar = getSampleDataAccessRequest("DAR-2"); dar.setDatasetIds(List.of(1, 2, 3)); String stringEntity = "{\"result\": \"APPROVE\", \"matchPair\": {}, \"failureReasons\": []}"; - when(datasetDAO.getDatasetsForConsent(any())).thenReturn(List.of(dataset)); when(dataAccessRequestDAO.findAllDataAccessRequests()).thenReturn(List.of(dar)); when(response.readEntity(any(Class.class))).thenReturn(stringEntity); when(response.getStatus()).thenReturn(200); @@ -240,14 +219,13 @@ public void testSingleEntitiesMatchV3Approve() { } @Test - public void testSingleEntitiesMatchV3Deny() { + void testSingleEntitiesMatchV3Deny() { Dataset dataset = new Dataset(); dataset.setDataSetId(1); DataAccessRequest dar = getSampleDataAccessRequest("DAR-2"); dar.setDatasetIds(List.of(1, 2, 3)); String stringEntity = "{\"result\": \"DENY\", \"matchPair\": {}, \"failureReasons\": []}"; - when(datasetDAO.getDatasetsForConsent(any())).thenReturn(List.of(dataset)); when(dataAccessRequestDAO.findAllDataAccessRequests()).thenReturn(List.of(dar)); when(response.readEntity(any(Class.class))).thenReturn(stringEntity); when(response.getStatus()).thenReturn(200); @@ -263,14 +241,13 @@ public void testSingleEntitiesMatchV3Deny() { } @Test - public void testSingleEntitiesMatchV3Abstain() { + void testSingleEntitiesMatchV3Abstain() { Dataset dataset = new Dataset(); dataset.setDataSetId(1); DataAccessRequest dar = getSampleDataAccessRequest("DAR-2"); dar.setDatasetIds(List.of(1, 2, 3)); String stringEntity = "{\"result\": \"ABSTAIN\", \"matchPair\": {}, \"failureReasons\": []}"; - when(datasetDAO.getDatasetsForConsent(any())).thenReturn(List.of(dataset)); when(dataAccessRequestDAO.findAllDataAccessRequests()).thenReturn(List.of(dar)); when(response.readEntity(any(Class.class))).thenReturn(stringEntity); when(response.getStatus()).thenReturn(200); @@ -286,7 +263,7 @@ public void testSingleEntitiesMatchV3Abstain() { } @Test - public void testFindMatchesByPurposeId() { + void testFindMatchesByPurposeId() { Match m = createMatchObject(); when(matchDAO.findMatchesByPurposeId(any())).thenReturn(List.of(m)); initService(); @@ -297,20 +274,7 @@ public void testFindMatchesByPurposeId() { } @Test - public void testReprocessMatchesForConsent() { - Match m = createMatchObject(); - when(matchDAO.findMatchesByConsentId(any())).thenReturn(List.of(m)); - initService(); - - try { - service.reprocessMatchesForConsent(m.getConsent()); - } catch (Exception e) { - fail(e.getMessage()); - } - } - - @Test - public void testReprocessMatchesForPurpose() { + void testReprocessMatchesForPurpose() { Match m = createMatchObject(); initService(); @@ -322,7 +286,7 @@ public void testReprocessMatchesForPurpose() { } @Test - public void testRemoveMatchesForPurpose() { + void testRemoveMatchesForPurpose() { initService(); service.removeMatchesForPurpose("DAR-2"); @@ -331,17 +295,7 @@ public void testRemoveMatchesForPurpose() { } @Test - public void testRemoveMatchesForConsent() { - Match m = createMatchObject(); - initService(); - - service.removeMatchesForConsent(m.getConsent()); - verify(matchDAO, atLeastOnce()).deleteRationalesByConsentIds(anyList()); - verify(matchDAO, atLeastOnce()).deleteMatchesByConsentId(any()); - } - - @Test - public void testFindMatchesForLatestDataAccessElectionsByPurposeIds() { + void testFindMatchesForLatestDataAccessElectionsByPurposeIds() { Match m = createMatchObject(); when(matchDAO.findMatchesForLatestDataAccessElectionsByPurposeIds(anyList())).thenReturn( List.of(m)); diff --git a/src/test/java/org/broadinstitute/consent/http/service/SummaryServiceTest.java b/src/test/java/org/broadinstitute/consent/http/service/SummaryServiceTest.java deleted file mode 100644 index a2ce70dc2c..0000000000 --- a/src/test/java/org/broadinstitute/consent/http/service/SummaryServiceTest.java +++ /dev/null @@ -1,307 +0,0 @@ -package org.broadinstitute.consent.http.service; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.ArgumentMatchers.notNull; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.openMocks; - -import java.sql.Timestamp; -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; -import org.apache.commons.collections4.ListUtils; -import org.apache.commons.lang3.RandomUtils; -import org.broadinstitute.consent.http.db.ConsentDAO; -import org.broadinstitute.consent.http.db.DarCollectionDAO; -import org.broadinstitute.consent.http.db.DatasetDAO; -import org.broadinstitute.consent.http.db.ElectionDAO; -import org.broadinstitute.consent.http.db.MatchDAO; -import org.broadinstitute.consent.http.db.UserDAO; -import org.broadinstitute.consent.http.db.VoteDAO; -import org.broadinstitute.consent.http.enumeration.AssociationType; -import org.broadinstitute.consent.http.enumeration.ElectionStatus; -import org.broadinstitute.consent.http.enumeration.ElectionType; -import org.broadinstitute.consent.http.enumeration.VoteType; -import org.broadinstitute.consent.http.models.Association; -import org.broadinstitute.consent.http.models.DarCollection; -import org.broadinstitute.consent.http.models.DataAccessRequest; -import org.broadinstitute.consent.http.models.DataAccessRequestData; -import org.broadinstitute.consent.http.models.DataAccessRequestSummaryDetail; -import org.broadinstitute.consent.http.models.Election; -import org.broadinstitute.consent.http.models.Match; -import org.broadinstitute.consent.http.models.Summary; -import org.broadinstitute.consent.http.models.User; -import org.broadinstitute.consent.http.models.Vote; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.mockito.Mockito; - -public class SummaryServiceTest { - - @Mock - private VoteDAO voteDAO; - @Mock - private ElectionDAO electionDAO; - @Mock - private UserDAO userDAO; - @Mock - private ConsentDAO consentDAO; - @Mock - private DatasetDAO datasetDAO; - @Mock - private MatchDAO matchDAO; - @Mock - private DarCollectionDAO darCollectionDAO; - @Mock - private DataAccessRequestService dataAccessRequestService; - - private SummaryService summaryService; - - @BeforeEach - public void setUp() throws Exception { - openMocks(this); - summaryService = Mockito.spy( - new SummaryService(dataAccessRequestService, voteDAO, electionDAO, userDAO, consentDAO, - datasetDAO, matchDAO, darCollectionDAO)); - } - - private void initService() { - summaryService = new SummaryService(dataAccessRequestService, voteDAO, electionDAO, userDAO, - consentDAO, - datasetDAO, matchDAO, darCollectionDAO); - } - - // Test that empty data will not throw errors - @Test - public void testListDataAccessRequestSummaryDetails_case1() { - initService(); - List details = summaryService.listDataAccessRequestSummaryDetails(); - assertTrue(details.isEmpty()); - } - - // Test that minimal data will produce minimal results. - // This unfortunately requires quite a bit of setup. - @Test - public void testListDataAccessRequestSummaryDetails_case2() { - User voteUser = new User(); - voteUser.setUserId(5); - voteUser.setDisplayName("Vote User Name"); - User darUser = new User(); - darUser.setUserId(10); - darUser.setDisplayName("DAR User Name"); - List accessElections = List.of(createElection(ElectionType.DATA_ACCESS.getValue())); - List rpElections = List.of(createElectionWithReferenceId(ElectionType.RP.getValue(), - accessElections.get(0).getReferenceId())); - List consentElections = List.of( - createElection(ElectionType.TRANSLATE_DUL.getValue())); - List accessElectionIds = accessElections.stream().map(Election::getElectionId) - .collect(Collectors.toList()); - List rpElectionIds = rpElections.stream().map(Election::getElectionId) - .collect(Collectors.toList()); - List consentElectionIds = consentElections.stream().map(Election::getElectionId) - .collect(Collectors.toList()); - List dars = List.of( - createDAR(accessElections.get(0).getReferenceId(), darUser.getUserId())); - List associations = List.of(createAssociation(dars.get(0).getDatasetIds().get(0), - consentElections.get(0).getReferenceId())); - List associatedConsentIds = List.of(consentElections.get(0).getReferenceId()); - List accessVotes = createVotes(accessElections.get(0).getElectionId(), - voteUser.getUserId()); - List rpVotes = createVotes(rpElections.get(0).getElectionId(), voteUser.getUserId()); - List consentVotes = createVotes(consentElections.get(0).getElectionId(), - voteUser.getUserId()); - List matchList = List.of( - createMatch(associatedConsentIds.get(0), dars.get(0).getReferenceId())); - List referenceIds = List.of(accessElections.get(0).getReferenceId()); - List datasetIds = dars.get(0).getDatasetIds(); - DarCollection collection = new DarCollection(); - collection.setDarCode("DAR-" + RandomUtils.nextInt(100, 200)); - - when(electionDAO.findElectionsWithFinalVoteByTypeAndStatus(ElectionType.DATA_ACCESS.getValue(), - ElectionStatus.CLOSED.getValue())).thenReturn(accessElections); - when(electionDAO.findElectionsWithFinalVoteByTypeAndStatus(ElectionType.RP.getValue(), - ElectionStatus.CLOSED.getValue())).thenReturn(rpElections); - when(dataAccessRequestService.getDataAccessRequestsByReferenceIds(anyList())).thenReturn(dars); - when(datasetDAO.getAssociationsForDatasetIdList(datasetIds)).thenReturn(associations); - when(electionDAO.findLastElectionsWithFinalVoteByReferenceIdsTypeAndStatus(associatedConsentIds, - ElectionStatus.CLOSED.getValue())).thenReturn(consentElections); - when(voteDAO.findVotesByElectionIds(accessElectionIds)).thenReturn(accessVotes); - when(voteDAO.findVotesByElectionIds(rpElectionIds)).thenReturn(rpVotes); - when(voteDAO.findVotesByElectionIds(consentElectionIds)).thenReturn(consentVotes); - when(matchDAO.findMatchesForPurposeIds(referenceIds)).thenReturn(matchList); - when(userDAO.findUsers(List.of(voteUser.getUserId()))).thenReturn(List.of(voteUser)); - when(userDAO.findUsers(List.of(darUser.getUserId()))).thenReturn(List.of(darUser)); - when(darCollectionDAO.findDARCollectionByCollectionId(anyInt())).thenReturn(collection); - - initService(); - List details = summaryService.listDataAccessRequestSummaryDetails(); - assertFalse(details.isEmpty()); - // Should be able to print without errors. - try { - String headers = details.get(0).headers(); - assertFalse(headers.isBlank()); - String val = details.get(0).toString(); - assertFalse(val.isBlank()); - } catch (Exception e) { - fail(e.getMessage()); - } - } - - // In this tests we won't validate the resulting file, we will just validate the methods being called for each response given by the mocks is accurate. - - @Test - public void testDescribeDataRequestSummaryCases() throws Exception { - String electionType = ElectionType.DATA_ACCESS.getValue(); - summaryService.describeDataRequestSummaryCases(electionType); - Mockito.verify(summaryService).getAccessSummaryCases(electionType); - electionType = ElectionType.RP.getValue(); - summaryService.describeDataRequestSummaryCases(electionType); - Mockito.verify(summaryService).getSummaryCases(electionType); - } - - @Test - public void testDescribeMatchSummaryCases() throws Exception { - when(matchDAO.countMatchesByResult(Boolean.TRUE)).thenReturn(2); - when(matchDAO.countMatchesByResult(Boolean.FALSE)).thenReturn(2); - - when(electionDAO.findLastElectionsWithFinalVoteByType( - ElectionType.DATA_ACCESS.getValue())).thenReturn( - electionsList(ElectionType.DATA_ACCESS.getValue(), "Open")); - List matchSummaryList = summaryService.describeMatchSummaryCases(); - assertTrue(matchSummaryList.size() == 2, "The list should have two elements: "); - assertTrue(matchSummaryList.get(0).getReviewedPositiveCases().equals(2), - "The list for matches should have two positive cases: "); - assertTrue(matchSummaryList.get(0).getReviewedNegativeCases().equals(2), - "The list for matches should have two negative cases: "); - assertTrue(matchSummaryList.get(0).getPendingCases().equals(0), - "The list for matches should have no pending cases: "); - - assertTrue(matchSummaryList.get(1).getReviewedPositiveCases().equals(0), - "The list for closed positive cases should be zero: "); - assertTrue(matchSummaryList.get(1).getReviewedNegativeCases().equals(0), - "The list for closed negative cases should be zero: "); - assertTrue(matchSummaryList.get(1).getPendingCases().equals(0), - "The list for pending cases should be zero: "); - - //This modifies the result for closed cases - when(electionDAO.findLastElectionsWithFinalVoteByType( - ElectionType.DATA_ACCESS.getValue())).thenReturn( - ListUtils.union(electionsList(ElectionType.DATA_ACCESS.getValue(), "Open"), - electionsList(ElectionType.DATA_ACCESS.getValue(), "Closed"))); - when(voteDAO.findVotesByElectionIds(notNull())).thenReturn( - randomVotesList(123, VoteType.AGREEMENT.getValue())); - - matchSummaryList = summaryService.describeMatchSummaryCases(); - assertTrue(matchSummaryList.size() == 2, "The list should have two elements: "); - assertTrue(matchSummaryList.get(0).getReviewedPositiveCases().equals(2), - "The list for matches should have two positive cases: "); - assertTrue(matchSummaryList.get(0).getReviewedNegativeCases().equals(2), - "The list for matches should have two negative cases: "); - assertTrue(matchSummaryList.get(0).getPendingCases().equals(0), - "The list for matches should have no pending cases: "); - - assertTrue(matchSummaryList.get(1).getReviewedPositiveCases().equals(2), - "The list for closed positive cases should be two: "); - assertTrue(matchSummaryList.get(1).getReviewedNegativeCases().equals(3), - "The list for closed negative cases should be three: "); - } - - /** - * Private methods for mocking - **/ - - private List electionsList(String electionType, String status) { - Election e1 = new Election(1, electionType, status, new Date(), "571fd0ca5ce51d1b148715f3", - new Date(), false, 1); - Election e2 = new Election(2, electionType, status, new Date(), "572fd0ca5ce51d1b148715f3", - new Date(), false, 2); - Election e3 = new Election(3, electionType, status, new Date(), "573fd0ca5ce51d1b148715f3", - new Date(), false, 3); - Election e4 = new Election(4, electionType, status, new Date(), "574fd0ca5ce51d1b148715f3", - new Date(), false, 4); - return Arrays.asList(e1, e2, e3, e4); - } - - private List randomVotesList(Integer userId, String voteType) { - Vote v1 = new Vote(1, false, userId, new Date(), new Date(), 1, "", voteType, false, false); - Vote v2 = new Vote(2, false, userId, new Date(), new Date(), 2, "", voteType, false, false); - Vote v3 = new Vote(3, false, userId, new Date(), new Date(), 3, "", voteType, false, false); - Vote v4 = new Vote(4, true, userId, new Date(), new Date(), 4, "", voteType, false, false); - Vote v5 = new Vote(5, true, userId, new Date(), new Date(), 5, "", voteType, false, false); - Vote nul = new Vote(6, null, userId, new Date(), new Date(), 6, "", voteType, false, false); - return Arrays.asList(v1, v2, v3, v4, v5, nul); - } - - private Match createMatch(String consentId, String referenceId) { - Match m = new Match(); - m.setConsent(consentId); - m.setPurpose(referenceId); - m.setMatch(true); - return m; - } - - private Association createAssociation(Integer datasetId, String consentId) { - Association a = new Association(); - a.setAssociationId(RandomUtils.nextInt(1, 100)); - a.setAssociationType(AssociationType.SAMPLE_SET.getValue()); - a.setDataSetId(datasetId); - a.setConsentId(consentId); - return a; - } - - private DataAccessRequest createDAR(String referenceId, Integer userId) { - DataAccessRequestData data = new DataAccessRequestData(); - data.setReferenceId(referenceId); - data.setDarCode("DAR-" + RandomUtils.nextInt(100, 200)); - data.setProjectTitle("Project-TEST"); - DataAccessRequest dar = new DataAccessRequest(); - dar.addDatasetId(1); - dar.setReferenceId(referenceId); - dar.setUserId(userId); - dar.setData(data); - dar.setSortDate(new Timestamp(new Date().getTime())); - return dar; - } - - private Election createElection(String electionType) { - ElectionType type = ElectionType.getFromValue(electionType); - Election e = new Election(); - e.setReferenceId(UUID.randomUUID().toString()); - e.setElectionType(type.getValue()); - e.setElectionId(type.ordinal()); - e.setCreateDate(new Date()); - e.setLastUpdate(new Date()); - e.setFinalVote(true); - e.setFinalVoteDate(new Date()); - e.setFinalAccessVote(true); - return e; - } - - private Election createElectionWithReferenceId(String electionType, String referenceId) { - Election e = createElection(electionType); - e.setReferenceId(referenceId); - return e; - } - - private List createVotes(Integer electionId, Integer userId) { - return Arrays.stream(VoteType.values()).map(t -> { - Vote v = new Vote(); - v.setVote(true); - v.setType(t.getValue()); - v.setElectionId(electionId); - v.setCreateDate(new Date()); - v.setUpdateDate(new Date()); - v.setUserId(userId); - return v; - } - ).toList(); - } - -} \ No newline at end of file diff --git a/src/test/java/org/broadinstitute/consent/http/service/dao/DarCollectionServiceDAOTest.java b/src/test/java/org/broadinstitute/consent/http/service/dao/DarCollectionServiceDAOTest.java index c691e040a3..4e4105b9e8 100644 --- a/src/test/java/org/broadinstitute/consent/http/service/dao/DarCollectionServiceDAOTest.java +++ b/src/test/java/org/broadinstitute/consent/http/service/dao/DarCollectionServiceDAOTest.java @@ -19,7 +19,6 @@ import org.broadinstitute.consent.http.enumeration.ElectionType; import org.broadinstitute.consent.http.enumeration.UserRoles; import org.broadinstitute.consent.http.enumeration.VoteType; -import org.broadinstitute.consent.http.models.Consent; import org.broadinstitute.consent.http.models.Dac; import org.broadinstitute.consent.http.models.DarCollection; import org.broadinstitute.consent.http.models.DataAccessRequest; @@ -35,7 +34,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class DarCollectionServiceDAOTest extends DAOTestHelper { +class DarCollectionServiceDAOTest extends DAOTestHelper { private DarCollectionServiceDAO serviceDAO; @@ -49,7 +48,7 @@ public void initService() { * - Elections created should be for the DAR/Dataset for the user */ @Test - public void testCreateElectionsForDarCollectionAdmin() throws Exception { + void testCreateElectionsForDarCollectionAdmin() throws Exception { User user = new User(); user.addRole(new UserRole(UserRoles.ADMIN.getRoleId(), UserRoles.ADMIN.getRoleName())); DarCollection collection = setUpDarCollectionWithDacDataset(); @@ -109,7 +108,7 @@ public void testCreateElectionsForDarCollectionAdmin() throws Exception { * - User is an Admin - Elections created should only be for ALL the DAR/Dataset combinations */ @Test - public void testCreateElectionsForDarCollectionWithMultipleDatasetsForAdmin() throws Exception { + void testCreateElectionsForDarCollectionWithMultipleDatasetsForAdmin() throws Exception { User user = new User(); user.addRole(new UserRole(UserRoles.ADMIN.getRoleId(), UserRoles.ADMIN.getRoleName())); DarCollection collection = setUpDarCollectionWithDacDataset(); @@ -161,7 +160,7 @@ public void testCreateElectionsForDarCollectionWithMultipleDatasetsForAdmin() th * combinations - Elections created should be for the DAR/Dataset for the user */ @Test - public void testCreateElectionsForDarCollectionChair() throws Exception { + void testCreateElectionsForDarCollectionChair() throws Exception { DarCollection collection = setUpDarCollectionWithDacDataset(); Optional dar = collection.getDars().values().stream().findFirst(); assertTrue(dar.isPresent()); @@ -209,7 +208,7 @@ public void testCreateElectionsForDarCollectionChair() throws Exception { * created should only be for the DAR/Dataset for the user */ @Test - public void testCreateElectionsForDarCollectionWithMultipleDatasetsForChair() throws Exception { + void testCreateElectionsForDarCollectionWithMultipleDatasetsForChair() throws Exception { // Start off with a collection and a single DAR DarCollection collection = setUpDarCollectionWithDacDataset(); Optional dar = collection.getDars().values().stream().findFirst(); @@ -274,7 +273,7 @@ public void testCreateElectionsForDarCollectionWithMultipleDatasetsForChair() th * elections are correctly archived */ @Test - public void testCreateElectionsForDarCollectionAfterCancelingEarlierElectionsAsAdmin() + void testCreateElectionsForDarCollectionAfterCancelingEarlierElectionsAsAdmin() throws Exception { User user = new User(); user.addRole(new UserRole(UserRoles.ADMIN.getRoleId(), UserRoles.ADMIN.getRoleName())); @@ -322,7 +321,7 @@ public void testCreateElectionsForDarCollectionAfterCancelingEarlierElectionsAsA * correctly - Elections created should only be for the DAR/Dataset for the user */ @Test - public void testCreateElectionsForDarCollectionAfterCancelingEarlierElectionsAsChair() + void testCreateElectionsForDarCollectionAfterCancelingEarlierElectionsAsChair() throws Exception { // Start off with a collection and a single DAR DarCollection collection = setUpDarCollectionWithDacDataset(); @@ -386,10 +385,7 @@ private DarCollection setUpDarCollectionWithDacDataset() { Dac dac = createDac(); createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); createUserWithRoleInDac(UserRoles.MEMBER.getRoleId(), dac.getDacId()); - Consent consent = createConsent(); Dataset dataset = createDatasetWithDac(dac.getDacId()); - consentDAO.insertConsentAssociation(consent.getConsentId(), ASSOCIATION_TYPE_TEST, - dataset.getDataSetId()); Integer collectionId = darCollectionDAO.insertDarCollection(darCode, user.getUserId(), new Date()); createDarForCollection(user, collectionId, dataset); @@ -413,10 +409,7 @@ private DataAccessRequest addDARWithDacAndDatasetToCollection(DarCollection coll Dac dac = createDac(); createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId()); createUserWithRoleInDac(UserRoles.MEMBER.getRoleId(), dac.getDacId()); - Consent consent = createConsent(); Dataset dataset = createDataset(); - consentDAO.insertConsentAssociation(consent.getConsentId(), ASSOCIATION_TYPE_TEST, - dataset.getDataSetId()); // Create new DAR with Dataset and add it to the collection User user = createUser(); @@ -469,20 +462,6 @@ private DataAccessRequest createDarForCollection(User user, Integer collectionId return dataAccessRequestDAO.findByReferenceId(dar.getReferenceId()); } - private Consent createConsent() { - String consentId = UUID.randomUUID().toString(); - consentDAO.insertConsent(consentId, - false, - "{\"generalUse\": true }", - "dul", - consentId, - "dulName", - new Date(), - new Date(), - "Group"); - return consentDAO.findConsentById(consentId); - } - private Dataset createDatasetWithDac(Integer dacId) { User user = createUser(); String name = "Name_" + RandomStringUtils.random(20, true, true);