use of org.broadinstitute.consent.http.enumeration.ElectionStatus in project consent by DataBiosphere.
the class DarCollectionService method createElectionsForDarCollection.
/**
* DarCollections with no elections, or with previously canceled elections, are valid
* for initiating a new set of elections. Elections in open, closed, pending, or final
* states are not valid.
*
* @param user The User initiating new elections for a collection
* @param collection The DarCollection
* @return The updated DarCollection
*/
public DarCollection createElectionsForDarCollection(User user, DarCollection collection) {
final List<String> invalidStatuses = Stream.of(ElectionStatus.CLOSED, ElectionStatus.OPEN, ElectionStatus.FINAL, ElectionStatus.PENDING_APPROVAL).map(ElectionStatus::getValue).collect(Collectors.toList());
List<String> referenceIds = collection.getDars().values().stream().map(DataAccessRequest::getReferenceId).collect(Collectors.toList());
if (!referenceIds.isEmpty()) {
List<Election> nonCanceledElections = electionDAO.findLastElectionsByReferenceIds(referenceIds).stream().filter(e -> invalidStatuses.contains(e.getStatus())).collect(Collectors.toList());
if (!nonCanceledElections.isEmpty()) {
logger.error("Non-canceled elections exist for collection: " + collection.getDarCollectionId());
throw new IllegalArgumentException("Non-canceled elections exist for this collection.");
}
}
try {
collectionServiceDAO.createElectionsForDarCollection(collection);
collection.getDars().values().forEach(dar -> {
Election accessElection = electionDAO.findLastElectionByReferenceIdAndType(dar.getReferenceId(), ElectionType.DATA_ACCESS.getValue());
if (Objects.nonNull(accessElection)) {
List<Vote> votes = voteDAO.findVotesByElectionId(accessElection.getElectionId());
try {
emailNotifierService.sendNewCaseMessageToList(votes, accessElection);
} catch (Exception e) {
logger.error("Unable to send new case message to DAC members for DAR: " + dar.getReferenceId());
}
} else {
logger.error("Did not find a created access election for DAR: " + dar.getReferenceId());
}
});
} catch (Exception e) {
logger.error("Exception creating elections and votes for collection: " + collection.getDarCollectionId());
}
return darCollectionDAO.findDARCollectionByCollectionId(collection.getDarCollectionId());
}
Aggregations