Search in sources :

Example 1 with UnknownIdentifierException

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;
}
Also used : Consent(org.broadinstitute.consent.http.models.Consent) UnknownIdentifierException(org.broadinstitute.consent.http.exceptions.UnknownIdentifierException) Election(org.broadinstitute.consent.http.models.Election)

Example 2 with UnknownIdentifierException

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());
}
Also used : Response(javax.ws.rs.core.Response) Consent(org.broadinstitute.consent.http.models.Consent) UnknownIdentifierException(org.broadinstitute.consent.http.exceptions.UnknownIdentifierException) Dac(org.broadinstitute.consent.http.models.Dac) Election(org.broadinstitute.consent.http.models.Election) Test(org.junit.Test)

Example 3 with UnknownIdentifierException

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());
}
Also used : Consent(org.broadinstitute.consent.http.models.Consent) UnknownIdentifierException(org.broadinstitute.consent.http.exceptions.UnknownIdentifierException) Election(org.broadinstitute.consent.http.models.Election) Test(org.junit.Test)

Example 4 with UnknownIdentifierException

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);
}
Also used : ZoneId(java.time.ZoneId) Consent(org.broadinstitute.consent.http.models.Consent) UnknownIdentifierException(org.broadinstitute.consent.http.exceptions.UnknownIdentifierException) Election(org.broadinstitute.consent.http.models.Election) Timestamp(java.sql.Timestamp) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 5 with UnknownIdentifierException

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;
}
Also used : Consent(org.broadinstitute.consent.http.models.Consent) UnknownIdentifierException(org.broadinstitute.consent.http.exceptions.UnknownIdentifierException) Election(org.broadinstitute.consent.http.models.Election)

Aggregations

UnknownIdentifierException (org.broadinstitute.consent.http.exceptions.UnknownIdentifierException)9 Consent (org.broadinstitute.consent.http.models.Consent)8 Election (org.broadinstitute.consent.http.models.Election)7 Test (org.junit.Test)5 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 Timestamp (java.sql.Timestamp)1 LocalDate (java.time.LocalDate)1 ZoneId (java.time.ZoneId)1 Date (java.util.Date)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 Consumes (javax.ws.rs.Consumes)1 NotFoundException (javax.ws.rs.NotFoundException)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1 AuthUser (org.broadinstitute.consent.http.models.AuthUser)1 Dac (org.broadinstitute.consent.http.models.Dac)1 User (org.broadinstitute.consent.http.models.User)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1