Search in sources :

Example 1 with Response

use of gov.ca.cwds.rest.api.Response in project API by ca-cwds.

the class CmsNSHelper method handleResponse.

@SuppressWarnings("javadoc")
public Map<String, Map<CrudsService, Response>> handleResponse(Map<CrudsService, Request> cmsRequests, Map<CrudsService, Request> nsRequests) {
    Map<CrudsService, Response> cmsResponse = new HashMap<>();
    Map<CrudsService, Response> nsResponse = new HashMap<>();
    Map<String, Map<CrudsService, Response>> response = new HashMap<>();
    Response referral = null;
    Response person;
    org.hibernate.Session sessionCMS = cmsSessionFactory.openSession();
    org.hibernate.Session sessionNS = nsSessionFactory.openSession();
    try {
        // NOSONAR
        ManagedSessionContext.bind(sessionCMS);
        Transaction transactionCMS = sessionCMS.beginTransaction();
        for (CrudsService service : cmsRequests.keySet()) {
            try {
                referral = service.create(cmsRequests.get(service));
                cmsResponse.put(service, referral);
                sessionCMS.flush();
            } catch (Exception e) {
                transactionCMS.rollback();
                throw e;
            }
        }
        // NOSONAR
        ManagedSessionContext.bind(sessionNS);
        Transaction transactionNS = sessionNS.beginTransaction();
        for (CrudsService service : nsRequests.keySet()) {
            try {
                person = service.create(nsRequests.get(service));
                nsResponse.put(service, person);
                sessionNS.flush();
            } catch (Exception e) {
                transactionNS.rollback();
                transactionCMS.rollback();
                throw e;
            }
            try {
                transactionCMS.commit();
                transactionNS.commit();
            } catch (Exception e) {
                throw e;
            }
        }
    } finally {
        sessionCMS.close();
        sessionNS.close();
        // NOSONAR
        ManagedSessionContext.unbind(cmsSessionFactory);
        // NOSONAR
        ManagedSessionContext.unbind(nsSessionFactory);
    }
    response.put("cms", cmsResponse);
    response.put("ns", nsResponse);
    return response;
}
Also used : Response(gov.ca.cwds.rest.api.Response) Transaction(org.hibernate.Transaction) HashMap(java.util.HashMap) CrudsService(gov.ca.cwds.rest.services.CrudsService) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with Response

use of gov.ca.cwds.rest.api.Response in project API by ca-cwds.

the class CmsReferralServiceTest method createReturnsPostedCmsReferralWithIdenticalReferralIds.

@Test
public void createReturnsPostedCmsReferralWithIdenticalReferralIds() throws Exception {
    Response response = cmsReferralServiceResponse();
    PostedCmsReferral postedCmsReferral = (PostedCmsReferral) response;
    String referralId = ((CrossReport) postedCmsReferral.getCrossReport().toArray()[0]).getReferralId();
    assertThat(((ReferralClient) postedCmsReferral.getReferralClient().toArray()[0]).getReferralId(), is(referralId));
    assertThat(postedCmsReferral.getReporter().getReferralId(), is(referralId));
    assertThat(((Allegation) postedCmsReferral.getAllegation().toArray()[0]).getReferralId(), is(referralId));
}
Also used : Response(gov.ca.cwds.rest.api.Response) CrossReport(gov.ca.cwds.rest.api.domain.cms.CrossReport) PostedCmsReferral(gov.ca.cwds.rest.api.domain.cms.PostedCmsReferral) Test(org.junit.Test)

Example 3 with Response

use of gov.ca.cwds.rest.api.Response in project API by ca-cwds.

the class CmsReferralServiceTest method cmsReferralServiceResponse.

public Response cmsReferralServiceResponse() throws Exception {
    Referral referralDomain = MAPPER.readValue(fixture("fixtures/domain/cms/CmsReferral/valid/referralCmsReferral.json"), Referral.class);
    gov.ca.cwds.data.persistence.cms.Referral referralToCreate = new gov.ca.cwds.data.persistence.cms.Referral("ABC1234567", referralDomain, "2016-10-31");
    Set<Client> clientDomain = MAPPER.readValue(fixture("fixtures/domain/cms/CmsReferral/valid/clientCmsReferral.json"), new TypeReference<Set<Client>>() {
    });
    gov.ca.cwds.data.persistence.cms.Client clientToCreate = new gov.ca.cwds.data.persistence.cms.Client("ABC1234567", (Client) clientDomain.toArray()[0], "2016-10-31");
    Set<ReferralClient> referralClientDomain = MAPPER.readValue(fixture("fixtures/domain/cms/CmsReferral/valid/referralClientCmsReferral.json"), new TypeReference<Set<ReferralClient>>() {
    });
    gov.ca.cwds.data.persistence.cms.ReferralClient referralClientToCreate = new gov.ca.cwds.data.persistence.cms.ReferralClient((ReferralClient) referralClientDomain.toArray()[0], "2016-10-31");
    Set<Allegation> allegationDomain = MAPPER.readValue(fixture("fixtures/domain/cms/CmsReferral/valid/allegationCmsReferral.json"), new TypeReference<Set<Allegation>>() {
    });
    gov.ca.cwds.data.persistence.cms.Allegation allegationToCreate = new gov.ca.cwds.data.persistence.cms.Allegation("ABC1234567", (Allegation) allegationDomain.toArray()[0], "2016-10-31");
    Set<CrossReport> crossReportDomain = MAPPER.readValue(fixture("fixtures/domain/cms/CmsReferral/valid/crossReportCmsReferral.json"), new TypeReference<Set<CrossReport>>() {
    });
    gov.ca.cwds.data.persistence.cms.CrossReport crossReportToCreate = new gov.ca.cwds.data.persistence.cms.CrossReport("1234ABC123", // ((CrossReport) crossReportDomain).getThirdId(),
    (CrossReport) crossReportDomain.toArray()[0], "OXA");
    Reporter reporterDomain = MAPPER.readValue(fixture("fixtures/domain/cms/CmsReferral/valid/reporterCmsReferral.json"), Reporter.class);
    gov.ca.cwds.data.persistence.cms.Reporter reporterToCreate = new gov.ca.cwds.data.persistence.cms.Reporter(reporterDomain, "OXA");
    Referral referralRequest = new Referral(referralToCreate);
    ReferralClient referralClientRequest = new ReferralClient(referralClientToCreate);
    Set<ReferralClient> referralClientRequestSet = new LinkedHashSet<>();
    referralClientRequestSet.add(referralClientRequest);
    Client clientRequest = new Client(clientToCreate, false);
    Set<Client> clientRequestSet = new LinkedHashSet<>();
    clientRequestSet.add(clientRequest);
    Allegation allegationRequest = new Allegation(allegationToCreate);
    Set<Allegation> allegationRequestSet = new LinkedHashSet<>();
    allegationRequestSet.add(allegationRequest);
    CrossReport crossReportRequest = new CrossReport(crossReportToCreate);
    Set<CrossReport> crossReportRequestSet = new LinkedHashSet<>();
    crossReportRequestSet.add(crossReportRequest);
    Reporter reporterRequest = new Reporter(reporterToCreate);
    when(referralDao.create(any(gov.ca.cwds.data.persistence.cms.Referral.class))).thenReturn(referralToCreate);
    when(clientDao.create(any(gov.ca.cwds.data.persistence.cms.Client.class))).thenReturn(clientToCreate);
    when(referralClientDao.create(any(gov.ca.cwds.data.persistence.cms.ReferralClient.class))).thenReturn(referralClientToCreate);
    when(allegationDao.create(any(gov.ca.cwds.data.persistence.cms.Allegation.class))).thenReturn(allegationToCreate);
    when(crossReportDao.create(any(gov.ca.cwds.data.persistence.cms.CrossReport.class))).thenReturn(crossReportToCreate);
    when(reporterDao.create(any(gov.ca.cwds.data.persistence.cms.Reporter.class))).thenReturn(reporterToCreate);
    CmsReferral cmsReferral = new CmsReferral(referralRequest, clientRequestSet, allegationRequestSet, crossReportRequestSet, referralClientRequestSet, reporterRequest);
    Response response = cmsReferralService.create(cmsReferral);
    return response;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PostedCmsReferral(gov.ca.cwds.rest.api.domain.cms.PostedCmsReferral) CmsReferral(gov.ca.cwds.rest.api.domain.cms.CmsReferral) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) PostedAllegation(gov.ca.cwds.rest.api.domain.cms.PostedAllegation) Allegation(gov.ca.cwds.rest.api.domain.cms.Allegation) Client(gov.ca.cwds.rest.api.domain.cms.Client) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) PostedClient(gov.ca.cwds.rest.api.domain.cms.PostedClient) PostedReporter(gov.ca.cwds.rest.api.domain.cms.PostedReporter) Reporter(gov.ca.cwds.rest.api.domain.cms.Reporter) Response(gov.ca.cwds.rest.api.Response) CrossReport(gov.ca.cwds.rest.api.domain.cms.CrossReport) Referral(gov.ca.cwds.rest.api.domain.cms.Referral) PostedReferral(gov.ca.cwds.rest.api.domain.cms.PostedReferral) PostedCmsReferral(gov.ca.cwds.rest.api.domain.cms.PostedCmsReferral) CmsReferral(gov.ca.cwds.rest.api.domain.cms.CmsReferral) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient)

Example 4 with Response

use of gov.ca.cwds.rest.api.Response in project API by ca-cwds.

the class ReferralClientServiceTest method findReturnsNullWhenNotFound.

@SuppressWarnings("javadoc")
@Test
public void findReturnsNullWhenNotFound() throws Exception {
    ReferralClient expected = MAPPER.readValue(fixture("fixtures/domain/legacy/ReferralClient/valid/valid.json"), ReferralClient.class);
    gov.ca.cwds.data.persistence.cms.ReferralClient referralClient = new gov.ca.cwds.data.persistence.cms.ReferralClient(expected, "ABC");
    Response found = referralClientService.find(referralClient.getPrimaryKey().toString());
    assertThat(found, is(nullValue()));
}
Also used : Response(gov.ca.cwds.rest.api.Response) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) Test(org.junit.Test)

Example 5 with Response

use of gov.ca.cwds.rest.api.Response in project API by ca-cwds.

the class ReferralServiceTest method testFindReturnsNullWhenNotFound.

@Override
@Test
public void testFindReturnsNullWhenNotFound() throws Exception {
    Response found = referralService.find("ABC1234567");
    assertThat(found, is(nullValue()));
}
Also used : Response(gov.ca.cwds.rest.api.Response) Test(org.junit.Test)

Aggregations

Response (gov.ca.cwds.rest.api.Response)83 Test (org.junit.Test)80 ReferralClient (gov.ca.cwds.rest.api.domain.cms.ReferralClient)46 CrossReport (gov.ca.cwds.rest.api.domain.cms.CrossReport)45 Allegation (gov.ca.cwds.rest.api.domain.cms.Allegation)44 Client (gov.ca.cwds.rest.api.domain.cms.Client)44 Referral (gov.ca.cwds.rest.api.domain.cms.Referral)44 PostedScreeningToReferral (gov.ca.cwds.rest.api.domain.PostedScreeningToReferral)43 ChildClient (gov.ca.cwds.rest.api.domain.cms.ChildClient)43 CmsReferral (gov.ca.cwds.rest.api.domain.cms.CmsReferral)43 LongText (gov.ca.cwds.rest.api.domain.cms.LongText)43 Reporter (gov.ca.cwds.rest.api.domain.cms.Reporter)43 LinkedHashSet (java.util.LinkedHashSet)43 Set (java.util.Set)43 ScreeningToReferral (gov.ca.cwds.rest.api.domain.ScreeningToReferral)42 Address (gov.ca.cwds.rest.api.domain.cms.Address)42 ClientAddress (gov.ca.cwds.rest.api.domain.cms.ClientAddress)42 ErrorMessage (gov.ca.cwds.rest.api.domain.error.ErrorMessage)22 ExpectedException (org.junit.rules.ExpectedException)16 PostedCmsReferral (gov.ca.cwds.rest.api.domain.cms.PostedCmsReferral)3