Search in sources :

Example 1 with ConsentManage

use of org.broadinstitute.consent.http.models.ConsentManage in project consent by DataBiosphere.

the class ConsentManageMapper method map.

public ConsentManage map(ResultSet r, StatementContext ctx) throws SQLException {
    ConsentManage consentManage = new ConsentManage();
    consentManage.setConsentId(r.getString("consentId"));
    consentManage.setConsentName(r.getString("name"));
    consentManage.setCreateDate(r.getTimestamp("createDate"));
    if (r.getObject("dac_id") != null) {
        consentManage.setDacId(r.getInt("dac_id"));
    }
    consentManage.setSortDate(r.getTimestamp("sortDate"));
    consentManage.setElectionId(r.getInt(ElectionFields.ID.getValue()));
    consentManage.setElectionStatus(r.getString(ElectionFields.STATUS.getValue()));
    consentManage.setVersion(r.getInt(ElectionFields.VERSION.getValue()) < 10 ? '0' + String.valueOf(r.getInt(ElectionFields.VERSION.getValue())) : String.valueOf(r.getInt(ElectionFields.VERSION.getValue())));
    consentManage.setArchived(r.getBoolean(ElectionFields.ARCHIVED.getValue()));
    consentManage.setEditable(true);
    consentManage.setGroupName(r.getString("groupName"));
    consentManage.setUpdateStatus(r.getBoolean("updated"));
    return consentManage;
}
Also used : ConsentManage(org.broadinstitute.consent.http.models.ConsentManage)

Example 2 with ConsentManage

use of org.broadinstitute.consent.http.models.ConsentManage in project consent by DataBiosphere.

the class ConsentDAOTest method testFindConsentManageByStatus.

@Test
public void testFindConsentManageByStatus() {
    Consent consent = createConsent(null);
    DataSet dataset = createDataset();
    createAssociation(consent.getConsentId(), dataset.getDataSetId());
    Election election = createAccessElection(consent.getConsentId(), dataset.getDataSetId());
    List<ConsentManage> consentManages = consentDAO.findConsentManageByStatus(election.getStatus());
    List<String> consentIds = consentManages.stream().map(ConsentManage::getConsentId).collect(Collectors.toList());
    assertTrue(consentIds.contains(consent.getConsentId()));
}
Also used : Consent(org.broadinstitute.consent.http.models.Consent) DataSet(org.broadinstitute.consent.http.models.DataSet) ConsentManage(org.broadinstitute.consent.http.models.ConsentManage) Election(org.broadinstitute.consent.http.models.Election) Test(org.junit.Test)

Example 3 with ConsentManage

use of org.broadinstitute.consent.http.models.ConsentManage in project consent by DataBiosphere.

the class ConsentService method describeConsentManage.

public List<ConsentManage> describeConsentManage(AuthUser authUser) {
    List<ConsentManage> consentManageList = new ArrayList<>();
    consentManageList.addAll(collectUnreviewedConsents(consentDAO.findUnreviewedConsents()));
    consentManageList.addAll(consentDAO.findConsentManageByStatus(ElectionStatus.OPEN.getValue()));
    consentManageList.addAll(consentDAO.findConsentManageByStatus(ElectionStatus.CANCELED.getValue()));
    List<ConsentManage> closedElections = consentDAO.findConsentManageByStatus(ElectionStatus.CLOSED.getValue());
    closedElections.forEach(consentManage -> {
        Boolean vote = voteDAO.findChairPersonVoteByElectionId(consentManage.getElectionId());
        consentManage.setVote(vote != null && vote ? "Approved" : "Denied");
    });
    consentManageList.addAll(closedElections);
    consentManageList.sort((c1, c2) -> c2.getSortDate().compareTo(c1.getSortDate()));
    List<Election> openElections = electionDAO.findElectionsWithFinalVoteByTypeAndStatus(ElectionType.DATA_ACCESS.getValue(), ElectionStatus.OPEN.getValue());
    if (!openElections.isEmpty()) {
        List<String> referenceIds = openElections.stream().map(Election::getReferenceId).collect(Collectors.toList());
        List<DataAccessRequest> dataAccessRequests = dataAccessRequestDAO.findByReferenceIds(referenceIds);
        List<String> datasetIds = dataAccessRequests.stream().filter(Objects::nonNull).map(DataAccessRequest::getData).filter(Objects::nonNull).map(DataAccessRequestData::getDatasetDetail).filter(Objects::nonNull).flatMap(List::stream).map(DatasetDetailEntry::getDatasetId).filter(Objects::nonNull).collect(Collectors.toList());
        List<String> consentIds = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(datasetIds)) {
            List<Integer> datasetIdIntValues = datasetIds.stream().map(Integer::valueOf).collect(Collectors.toList());
            consentIds.addAll(consentDAO.getAssociationConsentIdsFromDatasetIds(datasetIdIntValues));
        }
        for (ConsentManage consentManage : consentManageList) {
            if (consentIds.stream().anyMatch(cm -> cm.equals(consentManage.getConsentId()))) {
                consentManage.setEditable(false);
            } else {
                consentManage.setEditable(true);
            }
        }
    }
    return dacService.filterConsentManageByDAC(consentManageList, authUser);
}
Also used : ConsentManage(org.broadinstitute.consent.http.models.ConsentManage) ArrayList(java.util.ArrayList) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Election(org.broadinstitute.consent.http.models.Election) Objects(java.util.Objects) DatasetDetailEntry(org.broadinstitute.consent.http.models.DatasetDetailEntry)

Aggregations

ConsentManage (org.broadinstitute.consent.http.models.ConsentManage)3 Election (org.broadinstitute.consent.http.models.Election)2 ArrayList (java.util.ArrayList)1 Objects (java.util.Objects)1 Consent (org.broadinstitute.consent.http.models.Consent)1 DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)1 DataSet (org.broadinstitute.consent.http.models.DataSet)1 DatasetDetailEntry (org.broadinstitute.consent.http.models.DatasetDetailEntry)1 Test (org.junit.Test)1