use of org.broadinstitute.consent.http.exceptions.UnknownIdentifierException in project consent by DataBiosphere.
the class MatchService method findConsent.
private Consent findConsent(String consentId) {
Consent consent = null;
try {
consent = consentDAO.findConsentById(consentId);
if (Objects.isNull(consent)) {
throw new UnknownIdentifierException(String.format("Could not find consent with id %s", consentId));
}
Election election = electionDAO.findLastElectionByReferenceIdAndType(consentId, ElectionType.TRANSLATE_DUL.getValue());
if (election != null) {
consent.setLastElectionStatus(election.getStatus());
consent.setLastElectionArchived(election.getArchived());
}
} catch (UnknownIdentifierException e) {
logger.error("Consent for specified id does not exist: " + consentId);
}
return consent;
}
use of org.broadinstitute.consent.http.exceptions.UnknownIdentifierException in project consent by DataBiosphere.
the class ConsentElectionResourceTest method testCreateConsentElectionForDac_noConsent.
@Test
public void testCreateConsentElectionForDac_noConsent() throws UnknownIdentifierException {
Election election = getElection();
Dac dac = getDac();
Consent consent = getConsent(dac.getDacId());
when(consentService.getById(anyString())).thenThrow(new UnknownIdentifierException(""));
initResource();
Response response = resource.createConsentElectionForDac(user, info, consent.getConsentId(), dac.getDacId(), election);
Assert.assertNotNull(response);
Assert.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
}
use of org.broadinstitute.consent.http.exceptions.UnknownIdentifierException in project consent by DataBiosphere.
the class ConsentServiceTest method testRetrieve.
@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) {
Assert.fail(unknownIdentifierException.getMessage());
}
Assert.assertNotNull(consent);
Assert.assertEquals(consent.getConsentId(), this.getTestConsent().getConsentId());
Assert.assertEquals(consent.getLastElectionArchived(), mockElection.getArchived());
Assert.assertEquals(consent.getLastElectionStatus(), mockElection.getStatus());
}
use of org.broadinstitute.consent.http.exceptions.UnknownIdentifierException in project consent by DataBiosphere.
the class ConsentServiceTest method testUpdateConsentDul.
@Test
public void testUpdateConsentDul() {
when(consentDAO.checkConsentById("test consent")).thenReturn("test consent");
when(consentDAO.findConsentById("test consent")).thenReturn(this.getTestConsent());
Election mockElection = this.getTestElection();
when(electionDAO.findLastElectionByReferenceIdAndType(anyString(), anyString())).thenReturn(mockElection);
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(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any());
initService();
Consent consent = null;
try {
consent = service.updateConsentDul("test consent", "data use letter", "dul name");
} catch (UnknownIdentifierException unknownIdentifierException) {
Assert.fail(unknownIdentifierException.getMessage());
}
Assert.assertNotNull(consent);
}
use of org.broadinstitute.consent.http.exceptions.UnknownIdentifierException in project consent by DataBiosphere.
the class ConsentService method retrieve.
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;
}
Aggregations