Search in sources :

Example 41 with Client

use of gov.ca.cwds.rest.api.domain.cms.Client in project API by ca-cwds.

the class CmsReferralService method create.

/**
   * {@inheritDoc}
   * 
   * @see gov.ca.cwds.rest.services.CrudsService#create(gov.ca.cwds.rest.api.Request)
   */
@UnitOfWork(value = "cms")
@Override
public Response create(Request request) {
    assert request instanceof CmsReferral;
    CmsReferral cmsReferral = (CmsReferral) request;
    PostedReferral referral = this.referralService.create(cmsReferral.getReferral());
    String referralId = referral.getId();
    List<String> clientIds = new ArrayList<>();
    int clientInst = 0;
    String sourceTableCode = "C";
    Set<ClientUc> resultClientUc = new LinkedHashSet<>();
    Set<PostedClient> postedClients = new LinkedHashSet<>();
    if (cmsReferral.getClient() != null && !cmsReferral.getClient().isEmpty()) {
        for (Client incomingClient : cmsReferral.getClient()) {
            PostedClient savedClient = null;
            if (incomingClient.getExistingClientId() != null) {
                savedClient = clientService.findInboundId(incomingClient.getExistingClientId());
            }
            if (savedClient == null) {
                Client client = new Client(incomingClient.getExistingClientId(), incomingClient.getAdjudicatedDelinquentIndicator(), incomingClient.getAdoptionStatusCode(), incomingClient.getAlienRegistrationNumber(), incomingClient.getBirthCity(), incomingClient.getBirthCountryCodeType(), incomingClient.getBirthDate(), incomingClient.getBirthFacilityName(), incomingClient.getBirthStateCodeType(), incomingClient.getBirthplaceVerifiedIndicator(), incomingClient.getChildClientIndicatorVar(), incomingClient.getClientIndexNumber(), incomingClient.getCommentDescription(), incomingClient.getCommonFirstName(), incomingClient.getCommonLastName(), incomingClient.getCommonMiddleName(), incomingClient.getConfidentialityActionDate(), incomingClient.getConfidentialityInEffectIndicator(), incomingClient.getCreationDate(), incomingClient.getCurrCaChildrenServIndicator(), incomingClient.getCurrentlyOtherDescription(), incomingClient.getCurrentlyRegionalCenterIndicator(), incomingClient.getDeathDate(), incomingClient.getDeathDateVerifiedIndicator(), incomingClient.getDeathPlace(), incomingClient.getDeathReasonText(), incomingClient.getDriverLicenseNumber(), incomingClient.getDriverLicenseStateCodeType(), incomingClient.getEmailAddress(), incomingClient.getEstimatedDobCode(), incomingClient.getEthUnableToDetReasonCode(), incomingClient.getFatherParentalRightTermDate(), incomingClient.getGenderCode(), incomingClient.getHealthSummaryText(), incomingClient.getHispUnableToDetReasonCode(), incomingClient.getHispanicOriginCode(), incomingClient.getImmigrationCountryCodeType(), incomingClient.getImmigrationStatusType(), incomingClient.getIncapacitatedParentCode(), incomingClient.getIndividualHealthCarePlanIndicator(), incomingClient.getLimitationOnScpHealthIndicator(), incomingClient.getLiterateCode(), incomingClient.getMaritalCohabitatnHstryIndicatorVar(), incomingClient.getMaritalStatusType(), incomingClient.getMilitaryStatusCode(), incomingClient.getMotherParentalRightTermDate(), incomingClient.getNamePrefixDescription(), incomingClient.getNameType(), incomingClient.getOutstandingWarrantIndicator(), incomingClient.getPrevCaChildrenServIndicator(), incomingClient.getPrevOtherDescription(), incomingClient.getPrevRegionalCenterIndicator(), incomingClient.getPrimaryEthnicityType(), incomingClient.getPrimaryLanguageType(), incomingClient.getReligionType(), incomingClient.getSecondaryLanguageType(), incomingClient.getSensitiveHlthInfoOnFileIndicator(), incomingClient.getSensitivityIndicator(), incomingClient.getSoc158PlacementCode(), incomingClient.getSoc158SealedClientIndicator(), incomingClient.getSocialSecurityNumChangedCode(), incomingClient.getSocialSecurityNumber(), incomingClient.getSuffixTitleDescription(), incomingClient.getTribalAncestryClientIndicatorVar(), incomingClient.getTribalMembrshpVerifctnIndicatorVar(), incomingClient.getUnemployedParentCode(), incomingClient.getZippyCreatedIndicator(), null);
                PostedClient postedclient = this.clientService.create(client);
                postedClients.add(postedclient);
                clientIds.add(postedclient.getId());
                if (postedclient.getCommonFirstName() != null) {
                    ClientUc clientUc = new ClientUc(postedclient.getId(), sourceTableCode, postedclient.getCommonFirstName().toUpperCase(), postedclient.getCommonLastName().toUpperCase(), postedclient.getCommonMiddleName().toUpperCase());
                    clientUc = this.clientUcService.create(clientUc);
                    resultClientUc.add(clientUc);
                }
            } else {
                clientIds.add(savedClient.getId());
                postedClients.add(savedClient);
            }
        }
    }
    Set<PostedAllegation> resultAllegation = new LinkedHashSet<>();
    if (cmsReferral.getAllegation() != null && !cmsReferral.getAllegation().isEmpty()) {
        for (Allegation incomingAllegation : cmsReferral.getAllegation()) {
            Allegation allegation = new Allegation(incomingAllegation.getAbuseEndDate(), incomingAllegation.getAbuseFrequency(), incomingAllegation.getAbuseFrequencyPeriodCode(), incomingAllegation.getAbuseLocationDescription(), incomingAllegation.getAbuseStartDate(), incomingAllegation.getAllegationDispositionType(), incomingAllegation.getAllegationType(), incomingAllegation.getDispositionDescription(), incomingAllegation.getDispositionDate(), incomingAllegation.getInjuryHarmDetailIndicator(), incomingAllegation.getNonProtectingParentCode(), incomingAllegation.getStaffPersonAddedIndicator(), incomingAllegation.getVictimClientId(), incomingAllegation.getPerpetratorClientId(), referralId, incomingAllegation.getCountySpecificCode(), incomingAllegation.getZippyCreatedIndicator(), incomingAllegation.getPlacementFacilityType());
            PostedAllegation postedallegation = this.allegationService.create(allegation);
            resultAllegation.add(postedallegation);
        }
    }
    Set<CrossReport> resultCrossReport = new LinkedHashSet<>();
    if (cmsReferral.getCrossReport() != null && !cmsReferral.getCrossReport().isEmpty()) {
        for (CrossReport incomingCrossReport : cmsReferral.getCrossReport()) {
            CrossReport crossReport = new CrossReport(incomingCrossReport.getThirdId(), incomingCrossReport.getCrossReportMethodType(), incomingCrossReport.getFiledOutOfStateIndicator(), incomingCrossReport.getGovernmentOrgCrossRptIndicatorVar(), incomingCrossReport.getInformTime(), incomingCrossReport.getRecipientBadgeNumber(), incomingCrossReport.getRecipientPhoneExtensionNumber(), incomingCrossReport.getRecipientPhoneNumber(), incomingCrossReport.getInformDate(), incomingCrossReport.getRecipientPositionTitleDesc(), incomingCrossReport.getReferenceNumber(), referralId, incomingCrossReport.getLawEnforcementId(), incomingCrossReport.getStaffPersonId(), incomingCrossReport.getDescription(), incomingCrossReport.getRecipientName(), incomingCrossReport.getOutStateLawEnforcementAddr(), incomingCrossReport.getCountySpecificCode(), incomingCrossReport.getLawEnforcementIndicator(), incomingCrossReport.getOutStateLawEnforcementIndicator(), incomingCrossReport.getSatisfyCrossReportIndicator());
            crossReport = this.crossReportService.create(crossReport);
            resultCrossReport.add(crossReport);
        }
    }
    Set<ReferralClient> resultReferralClient = new LinkedHashSet<>();
    if (cmsReferral.getReferralClient() != null && !cmsReferral.getReferralClient().isEmpty()) {
        for (ReferralClient incomingReferralClient : cmsReferral.getReferralClient()) {
            ReferralClient referralClient = new ReferralClient(incomingReferralClient.getApprovalNumber(), incomingReferralClient.getApprovalStatusType(), incomingReferralClient.getDispositionClosureReasonType(), incomingReferralClient.getDispositionCode(), incomingReferralClient.getDispositionDate(), incomingReferralClient.getSelfReportedIndicator(), incomingReferralClient.getStaffPersonAddedIndicator(), referralId, (String) clientIds.toArray()[clientInst], incomingReferralClient.getDispositionClosureDescription(), incomingReferralClient.getAgeNumber(), incomingReferralClient.getAgePeriodCode(), incomingReferralClient.getCountySpecificCode(), incomingReferralClient.getMentalHealthIssuesIndicator(), incomingReferralClient.getAlcoholIndicator(), incomingReferralClient.getDrugIndicator());
            referralClient = this.referralClientService.create(referralClient);
            resultReferralClient.add(referralClient);
            clientInst++;
        }
    }
    PostedReporter savedreporter = new PostedReporter();
    if (cmsReferral.getReporter() != null) {
        Reporter incomingReporter = cmsReferral.getReporter();
        Reporter reporter = new Reporter(incomingReporter.getBadgeNumber(), incomingReporter.getCityName(), incomingReporter.getColltrClientRptrReltnshpType(), incomingReporter.getCommunicationMethodType(), incomingReporter.getConfidentialWaiverIndicator(), incomingReporter.getDrmsMandatedRprtrFeedback(), incomingReporter.getEmployerName(), incomingReporter.getFeedbackDate(), incomingReporter.getFeedbackRequiredIndicator(), incomingReporter.getFirstName(), incomingReporter.getLastName(), incomingReporter.getMandatedReporterIndicator(), incomingReporter.getMessagePhoneExtensionNumber(), incomingReporter.getMessagePhoneNumber(), incomingReporter.getMiddleInitialName(), incomingReporter.getNamePrefixDescription(), incomingReporter.getPrimaryPhoneNumber(), incomingReporter.getPrimaryPhoneExtensionNumber(), incomingReporter.getStateCodeType(), incomingReporter.getStreetName(), incomingReporter.getStreetNumber(), incomingReporter.getSuffixTitleDescription(), incomingReporter.getZipcode(), referralId, incomingReporter.getLawEnforcementId(), incomingReporter.getZipSuffixNumber(), incomingReporter.getCountySpecificCode());
        PostedReporter postedreporter = this.reporterService.create(reporter);
        savedreporter = postedreporter;
    }
    return new PostedCmsReferral(referral, postedClients, resultAllegation, resultCrossReport, resultReferralClient, savedreporter);
}
Also used : PostedCmsReferral(gov.ca.cwds.rest.api.domain.cms.PostedCmsReferral) CmsReferral(gov.ca.cwds.rest.api.domain.cms.CmsReferral) LinkedHashSet(java.util.LinkedHashSet) PostedClient(gov.ca.cwds.rest.api.domain.cms.PostedClient) ClientUc(gov.ca.cwds.rest.api.domain.cms.ClientUc) PostedCmsReferral(gov.ca.cwds.rest.api.domain.cms.PostedCmsReferral) PostedReporter(gov.ca.cwds.rest.api.domain.cms.PostedReporter) Reporter(gov.ca.cwds.rest.api.domain.cms.Reporter) ArrayList(java.util.ArrayList) PostedReporter(gov.ca.cwds.rest.api.domain.cms.PostedReporter) CrossReport(gov.ca.cwds.rest.api.domain.cms.CrossReport) PostedReferral(gov.ca.cwds.rest.api.domain.cms.PostedReferral) 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) PostedAllegation(gov.ca.cwds.rest.api.domain.cms.PostedAllegation) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) UnitOfWork(io.dropwizard.hibernate.UnitOfWork)

Example 42 with Client

use of gov.ca.cwds.rest.api.domain.cms.Client in project API by ca-cwds.

the class ScreeningToReferralServiceTest method testWithClientExsitSuccess.

@SuppressWarnings("javadoc")
@Test
public void testWithClientExsitSuccess() throws Exception {
    Referral referralDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReferral.json"), Referral.class);
    gov.ca.cwds.data.persistence.cms.Referral referralToCreate = new gov.ca.cwds.data.persistence.cms.Referral("0123456ABC", referralDomain, "2016-10-31");
    when(referralDao.create(any(gov.ca.cwds.data.persistence.cms.Referral.class))).thenReturn(referralToCreate);
    ChildClient childClient = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/childClient.json"), ChildClient.class);
    gov.ca.cwds.data.persistence.cms.ChildClient childClientToCreate = new gov.ca.cwds.data.persistence.cms.ChildClient("1234567ABC", childClient, "0XA");
    when(childClientDao.create(any(gov.ca.cwds.data.persistence.cms.ChildClient.class))).thenReturn(childClientToCreate);
    Set<Client> clientDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validClient.json"), new TypeReference<Set<Client>>() {
    });
    gov.ca.cwds.data.persistence.cms.Client clientToCreate = new gov.ca.cwds.data.persistence.cms.Client("1234567ABC", (Client) clientDomain.toArray()[0], "2016-10-31");
    when(clientDao.create(any(gov.ca.cwds.data.persistence.cms.Client.class))).thenReturn(clientToCreate);
    when(clientDao.find("1234567ABC")).thenReturn(clientToCreate);
    Set<ReferralClient> referralClientDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReferralClient.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");
    when(referralClientDao.create(any(gov.ca.cwds.data.persistence.cms.ReferralClient.class))).thenReturn(referralClientToCreate);
    Set<Allegation> allegationDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validAllegation.json"), new TypeReference<Set<Allegation>>() {
    });
    gov.ca.cwds.data.persistence.cms.Allegation allegationToCreate = new gov.ca.cwds.data.persistence.cms.Allegation("2345678ABC", (Allegation) allegationDomain.toArray()[0], "2016-10-31");
    when(allegationDao.create(any(gov.ca.cwds.data.persistence.cms.Allegation.class))).thenReturn(allegationToCreate);
    Set<CrossReport> crossReportDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validCrossReport.json"), new TypeReference<Set<CrossReport>>() {
    });
    gov.ca.cwds.data.persistence.cms.CrossReport crossReportToCreate = new gov.ca.cwds.data.persistence.cms.CrossReport("3456789ABC", // ((CrossReport) crossReportDomain).getThirdId(),
    (CrossReport) crossReportDomain.toArray()[0], "OXA");
    when(crossReportDao.create(any(gov.ca.cwds.data.persistence.cms.CrossReport.class))).thenReturn(crossReportToCreate);
    Reporter reporterDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReporter.json"), Reporter.class);
    gov.ca.cwds.data.persistence.cms.Reporter reporterToCreate = new gov.ca.cwds.data.persistence.cms.Reporter(reporterDomain, "ABC");
    when(reporterDao.create(any(gov.ca.cwds.data.persistence.cms.Reporter.class))).thenReturn(reporterToCreate);
    Address addressDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validAddress.json"), Address.class);
    gov.ca.cwds.data.persistence.cms.Address addressToCreate = new gov.ca.cwds.data.persistence.cms.Address("3456789ABC", addressDomain, "ABC");
    when(addressDao.create(any(gov.ca.cwds.data.persistence.cms.Address.class))).thenReturn(addressToCreate);
    when(addressDao.find("3456789ABC")).thenReturn(addressToCreate);
    ClientAddress clientAddressDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validClientAddress.json"), ClientAddress.class);
    gov.ca.cwds.data.persistence.cms.ClientAddress clientAddressToCreate = new gov.ca.cwds.data.persistence.cms.ClientAddress("3456789ABC", clientAddressDomain, "ABC");
    when(clientAddressDao.create(any(gov.ca.cwds.data.persistence.cms.ClientAddress.class))).thenReturn(clientAddressToCreate);
    when(clientAddressDao.find("3456789ABC")).thenReturn(clientAddressToCreate);
    LongText longTextDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validLongText.json"), LongText.class);
    gov.ca.cwds.data.persistence.cms.LongText longTextToCreate = new gov.ca.cwds.data.persistence.cms.LongText("567890ABC", longTextDomain, "ABC");
    when(longTextDao.create(any(gov.ca.cwds.data.persistence.cms.LongText.class))).thenReturn(longTextToCreate);
    ScreeningToReferral screeningToReferral = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/clientIdExist.json"), ScreeningToReferral.class);
    try {
        Response response = screeningToReferralService.create(screeningToReferral);
        assertThat(response.getClass(), is(PostedScreeningToReferral.class));
        assertThat(response.hasMessages(), is(equalTo(false)));
    } catch (Exception e) {
        // System.out.println("error = " + e.getMessage());
        Assert.fail("Unexpected ServiceException was thrown" + e.getMessage());
    }
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Address(gov.ca.cwds.rest.api.domain.cms.Address) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) ChildClient(gov.ca.cwds.rest.api.domain.cms.ChildClient) Allegation(gov.ca.cwds.rest.api.domain.cms.Allegation) Client(gov.ca.cwds.rest.api.domain.cms.Client) ChildClient(gov.ca.cwds.rest.api.domain.cms.ChildClient) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) LongText(gov.ca.cwds.rest.api.domain.cms.LongText) Reporter(gov.ca.cwds.rest.api.domain.cms.Reporter) ExpectedException(org.junit.rules.ExpectedException) Response(gov.ca.cwds.rest.api.Response) CrossReport(gov.ca.cwds.rest.api.domain.cms.CrossReport) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) Referral(gov.ca.cwds.rest.api.domain.cms.Referral) CmsReferral(gov.ca.cwds.rest.api.domain.cms.CmsReferral) ScreeningToReferral(gov.ca.cwds.rest.api.domain.ScreeningToReferral) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) ScreeningToReferral(gov.ca.cwds.rest.api.domain.ScreeningToReferral) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) Test(org.junit.Test)

Example 43 with Client

use of gov.ca.cwds.rest.api.domain.cms.Client in project API by ca-cwds.

the class ScreeningToReferralServiceTest method testAllegationNotPointingToPerpetratorFail.

@SuppressWarnings("javadoc")
@Test
public void testAllegationNotPointingToPerpetratorFail() throws Exception {
    Referral referralDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReferral.json"), Referral.class);
    gov.ca.cwds.data.persistence.cms.Referral referralToCreate = new gov.ca.cwds.data.persistence.cms.Referral("0123456ABC", referralDomain, "2016-10-31");
    when(referralDao.create(any(gov.ca.cwds.data.persistence.cms.Referral.class))).thenReturn(referralToCreate);
    ChildClient childClient = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/childClient.json"), ChildClient.class);
    gov.ca.cwds.data.persistence.cms.ChildClient childClientToCreate = new gov.ca.cwds.data.persistence.cms.ChildClient("1234567ABC", childClient, "0XA");
    when(childClientDao.create(any(gov.ca.cwds.data.persistence.cms.ChildClient.class))).thenReturn(childClientToCreate);
    Set<Client> clientDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validClient.json"), new TypeReference<Set<Client>>() {
    });
    gov.ca.cwds.data.persistence.cms.Client clientToCreate = new gov.ca.cwds.data.persistence.cms.Client("1234567ABC", (Client) clientDomain.toArray()[0], "2016-10-31");
    when(clientDao.create(any(gov.ca.cwds.data.persistence.cms.Client.class))).thenReturn(clientToCreate);
    Set<ReferralClient> referralClientDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReferralClient.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");
    when(referralClientDao.create(any(gov.ca.cwds.data.persistence.cms.ReferralClient.class))).thenReturn(referralClientToCreate);
    Set<Allegation> allegationDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validAllegation.json"), new TypeReference<Set<Allegation>>() {
    });
    gov.ca.cwds.data.persistence.cms.Allegation allegationToCreate = new gov.ca.cwds.data.persistence.cms.Allegation("2345678ABC", (Allegation) allegationDomain.toArray()[0], "2016-10-31");
    when(allegationDao.create(any(gov.ca.cwds.data.persistence.cms.Allegation.class))).thenReturn(allegationToCreate);
    Set<CrossReport> crossReportDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validCrossReport.json"), new TypeReference<Set<CrossReport>>() {
    });
    gov.ca.cwds.data.persistence.cms.CrossReport crossReportToCreate = new gov.ca.cwds.data.persistence.cms.CrossReport("3456789ABC", // ((CrossReport) crossReportDomain).getThirdId(),
    (CrossReport) crossReportDomain.toArray()[0], "OXA");
    when(crossReportDao.create(any(gov.ca.cwds.data.persistence.cms.CrossReport.class))).thenReturn(crossReportToCreate);
    Reporter reporterDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReporter.json"), Reporter.class);
    gov.ca.cwds.data.persistence.cms.Reporter reporterToCreate = new gov.ca.cwds.data.persistence.cms.Reporter(reporterDomain, "ABC");
    when(reporterDao.create(any(gov.ca.cwds.data.persistence.cms.Reporter.class))).thenReturn(reporterToCreate);
    Address addressDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validAddress.json"), Address.class);
    gov.ca.cwds.data.persistence.cms.Address addressToCreate = new gov.ca.cwds.data.persistence.cms.Address("345678ABC", addressDomain, "ABC");
    when(addressDao.create(any(gov.ca.cwds.data.persistence.cms.Address.class))).thenReturn(addressToCreate);
    ClientAddress clientAddressDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validClientAddress.json"), ClientAddress.class);
    gov.ca.cwds.data.persistence.cms.ClientAddress clientAddressToCreate = new gov.ca.cwds.data.persistence.cms.ClientAddress("456789ABC", clientAddressDomain, "ABC");
    when(clientAddressDao.create(any(gov.ca.cwds.data.persistence.cms.ClientAddress.class))).thenReturn(clientAddressToCreate);
    LongText longTextDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validLongText.json"), LongText.class);
    gov.ca.cwds.data.persistence.cms.LongText longTextToCreate = new gov.ca.cwds.data.persistence.cms.LongText("567890ABC", longTextDomain, "ABC");
    when(longTextDao.create(any(gov.ca.cwds.data.persistence.cms.LongText.class))).thenReturn(longTextToCreate);
    ScreeningToReferral screeningToReferral = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/invalid/allegationNotPointingToPerpetrator.json"), ScreeningToReferral.class);
    Boolean theErrorDetected = false;
    Response response = screeningToReferralService.create(screeningToReferral);
    if (response.hasMessages()) {
        Set<ErrorMessage> messages = response.getMessages();
        for (ErrorMessage message : messages) {
            if (message.getMessage() != null) {
                if (message.getMessage().contains("Allegation/Perpetrator Person Id does not contain a Participant with a role of Perpetrator")) {
                    theErrorDetected = true;
                }
            }
        }
        assertThat(theErrorDetected, is(equalTo(true)));
    } else {
        Assert.fail("Expected error was not detected");
    }
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Address(gov.ca.cwds.rest.api.domain.cms.Address) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) ChildClient(gov.ca.cwds.rest.api.domain.cms.ChildClient) Allegation(gov.ca.cwds.rest.api.domain.cms.Allegation) Client(gov.ca.cwds.rest.api.domain.cms.Client) ChildClient(gov.ca.cwds.rest.api.domain.cms.ChildClient) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) LongText(gov.ca.cwds.rest.api.domain.cms.LongText) 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) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) Referral(gov.ca.cwds.rest.api.domain.cms.Referral) CmsReferral(gov.ca.cwds.rest.api.domain.cms.CmsReferral) ScreeningToReferral(gov.ca.cwds.rest.api.domain.ScreeningToReferral) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) ScreeningToReferral(gov.ca.cwds.rest.api.domain.ScreeningToReferral) ErrorMessage(gov.ca.cwds.rest.api.domain.error.ErrorMessage) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) Test(org.junit.Test)

Example 44 with Client

use of gov.ca.cwds.rest.api.domain.cms.Client in project API by ca-cwds.

the class ScreeningToReferralServiceTest method testAddressExsitSuccess.

@SuppressWarnings("javadoc")
@Test
public void testAddressExsitSuccess() throws Exception {
    Referral referralDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReferral.json"), Referral.class);
    gov.ca.cwds.data.persistence.cms.Referral referralToCreate = new gov.ca.cwds.data.persistence.cms.Referral("0123456ABC", referralDomain, "2016-10-31");
    when(referralDao.create(any(gov.ca.cwds.data.persistence.cms.Referral.class))).thenReturn(referralToCreate);
    ChildClient childClient = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/childClient.json"), ChildClient.class);
    gov.ca.cwds.data.persistence.cms.ChildClient childClientToCreate = new gov.ca.cwds.data.persistence.cms.ChildClient("1234567ABC", childClient, "0XA");
    when(childClientDao.create(any(gov.ca.cwds.data.persistence.cms.ChildClient.class))).thenReturn(childClientToCreate);
    Set<Client> clientDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validClient.json"), new TypeReference<Set<Client>>() {
    });
    gov.ca.cwds.data.persistence.cms.Client clientToCreate = new gov.ca.cwds.data.persistence.cms.Client("1234567ABC", (Client) clientDomain.toArray()[0], "2016-10-31");
    when(clientDao.create(any(gov.ca.cwds.data.persistence.cms.Client.class))).thenReturn(clientToCreate);
    when(clientDao.find("1234567ABC")).thenReturn(clientToCreate);
    Set<ReferralClient> referralClientDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReferralClient.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");
    when(referralClientDao.create(any(gov.ca.cwds.data.persistence.cms.ReferralClient.class))).thenReturn(referralClientToCreate);
    Set<Allegation> allegationDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validAllegation.json"), new TypeReference<Set<Allegation>>() {
    });
    gov.ca.cwds.data.persistence.cms.Allegation allegationToCreate = new gov.ca.cwds.data.persistence.cms.Allegation("2345678ABC", (Allegation) allegationDomain.toArray()[0], "2016-10-31");
    when(allegationDao.create(any(gov.ca.cwds.data.persistence.cms.Allegation.class))).thenReturn(allegationToCreate);
    when(allegationDao.find("2345678ABC")).thenReturn(allegationToCreate);
    Set<CrossReport> crossReportDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validCrossReport.json"), new TypeReference<Set<CrossReport>>() {
    });
    gov.ca.cwds.data.persistence.cms.CrossReport crossReportToCreate = new gov.ca.cwds.data.persistence.cms.CrossReport("3456789ABC", // ((CrossReport) crossReportDomain).getThirdId(),
    (CrossReport) crossReportDomain.toArray()[0], "OXA");
    when(crossReportDao.create(any(gov.ca.cwds.data.persistence.cms.CrossReport.class))).thenReturn(crossReportToCreate);
    when(crossReportDao.find("3456789ABC")).thenReturn(crossReportToCreate);
    Reporter reporterDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReporter.json"), Reporter.class);
    gov.ca.cwds.data.persistence.cms.Reporter reporterToCreate = new gov.ca.cwds.data.persistence.cms.Reporter(reporterDomain, "ABC");
    when(reporterDao.create(any(gov.ca.cwds.data.persistence.cms.Reporter.class))).thenReturn(reporterToCreate);
    Address addressDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validAddress.json"), Address.class);
    gov.ca.cwds.data.persistence.cms.Address addressToCreate = new gov.ca.cwds.data.persistence.cms.Address("345678ABC", addressDomain, "ABC");
    when(addressDao.create(any(gov.ca.cwds.data.persistence.cms.Address.class))).thenReturn(addressToCreate);
    when(addressDao.find("345678ABC")).thenReturn(addressToCreate);
    ClientAddress clientAddressDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validClientAddress.json"), ClientAddress.class);
    gov.ca.cwds.data.persistence.cms.ClientAddress clientAddressToCreate = new gov.ca.cwds.data.persistence.cms.ClientAddress("345678ABC", clientAddressDomain, "ABC");
    when(clientAddressDao.create(any(gov.ca.cwds.data.persistence.cms.ClientAddress.class))).thenReturn(clientAddressToCreate);
    when(clientAddressDao.find("345678ABC")).thenReturn(clientAddressToCreate);
    LongText longTextDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validLongText.json"), LongText.class);
    gov.ca.cwds.data.persistence.cms.LongText longTextToCreate = new gov.ca.cwds.data.persistence.cms.LongText("567890ABC", longTextDomain, "ABC");
    when(longTextDao.create(any(gov.ca.cwds.data.persistence.cms.LongText.class))).thenReturn(longTextToCreate);
    ScreeningToReferral screeningToReferral = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/addressExist.json"), ScreeningToReferral.class);
    try {
        Response response = screeningToReferralService.create(screeningToReferral);
        assertThat(response.getClass(), is(PostedScreeningToReferral.class));
        assertThat(response.hasMessages(), is(equalTo(false)));
    } catch (Exception e) {
        // System.out.println("error = " + e.getMessage());
        Assert.fail("Unexpected ServiceException was thrown" + e.getMessage());
    }
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Address(gov.ca.cwds.rest.api.domain.cms.Address) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) ChildClient(gov.ca.cwds.rest.api.domain.cms.ChildClient) Allegation(gov.ca.cwds.rest.api.domain.cms.Allegation) Client(gov.ca.cwds.rest.api.domain.cms.Client) ChildClient(gov.ca.cwds.rest.api.domain.cms.ChildClient) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) LongText(gov.ca.cwds.rest.api.domain.cms.LongText) Reporter(gov.ca.cwds.rest.api.domain.cms.Reporter) ExpectedException(org.junit.rules.ExpectedException) Response(gov.ca.cwds.rest.api.Response) CrossReport(gov.ca.cwds.rest.api.domain.cms.CrossReport) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) Referral(gov.ca.cwds.rest.api.domain.cms.Referral) CmsReferral(gov.ca.cwds.rest.api.domain.cms.CmsReferral) ScreeningToReferral(gov.ca.cwds.rest.api.domain.ScreeningToReferral) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) ScreeningToReferral(gov.ca.cwds.rest.api.domain.ScreeningToReferral) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) Test(org.junit.Test)

Example 45 with Client

use of gov.ca.cwds.rest.api.domain.cms.Client in project API by ca-cwds.

the class ScreeningToReferralServiceTest method testAllegationNotPointingToVictimFail.

@SuppressWarnings("javadoc")
@Test
public void testAllegationNotPointingToVictimFail() throws Exception {
    Referral referralDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReferral.json"), Referral.class);
    gov.ca.cwds.data.persistence.cms.Referral referralToCreate = new gov.ca.cwds.data.persistence.cms.Referral("0123456ABC", referralDomain, "2016-10-31");
    when(referralDao.create(any(gov.ca.cwds.data.persistence.cms.Referral.class))).thenReturn(referralToCreate);
    ChildClient childClient = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/childClient.json"), ChildClient.class);
    gov.ca.cwds.data.persistence.cms.ChildClient childClientToCreate = new gov.ca.cwds.data.persistence.cms.ChildClient("1234567ABC", childClient, "0XA");
    when(childClientDao.create(any(gov.ca.cwds.data.persistence.cms.ChildClient.class))).thenReturn(childClientToCreate);
    Set<Client> clientDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validClient.json"), new TypeReference<Set<Client>>() {
    });
    gov.ca.cwds.data.persistence.cms.Client clientToCreate = new gov.ca.cwds.data.persistence.cms.Client("1234567ABC", (Client) clientDomain.toArray()[0], "2016-10-31");
    when(clientDao.create(any(gov.ca.cwds.data.persistence.cms.Client.class))).thenReturn(clientToCreate);
    Set<ReferralClient> referralClientDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReferralClient.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");
    when(referralClientDao.create(any(gov.ca.cwds.data.persistence.cms.ReferralClient.class))).thenReturn(referralClientToCreate);
    Set<Allegation> allegationDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validAllegation.json"), new TypeReference<Set<Allegation>>() {
    });
    gov.ca.cwds.data.persistence.cms.Allegation allegationToCreate = new gov.ca.cwds.data.persistence.cms.Allegation("2345678ABC", (Allegation) allegationDomain.toArray()[0], "2016-10-31");
    when(allegationDao.create(any(gov.ca.cwds.data.persistence.cms.Allegation.class))).thenReturn(allegationToCreate);
    Set<CrossReport> crossReportDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validCrossReport.json"), new TypeReference<Set<CrossReport>>() {
    });
    gov.ca.cwds.data.persistence.cms.CrossReport crossReportToCreate = new gov.ca.cwds.data.persistence.cms.CrossReport("3456789ABC", // ((CrossReport) crossReportDomain).getThirdId(),
    (CrossReport) crossReportDomain.toArray()[0], "OXA");
    when(crossReportDao.create(any(gov.ca.cwds.data.persistence.cms.CrossReport.class))).thenReturn(crossReportToCreate);
    Reporter reporterDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReporter.json"), Reporter.class);
    gov.ca.cwds.data.persistence.cms.Reporter reporterToCreate = new gov.ca.cwds.data.persistence.cms.Reporter(reporterDomain, "ABC");
    when(reporterDao.create(any(gov.ca.cwds.data.persistence.cms.Reporter.class))).thenReturn(reporterToCreate);
    Address addressDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validAddress.json"), Address.class);
    gov.ca.cwds.data.persistence.cms.Address addressToCreate = new gov.ca.cwds.data.persistence.cms.Address("345678ABC", addressDomain, "ABC");
    when(addressDao.create(any(gov.ca.cwds.data.persistence.cms.Address.class))).thenReturn(addressToCreate);
    ClientAddress clientAddressDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validClientAddress.json"), ClientAddress.class);
    gov.ca.cwds.data.persistence.cms.ClientAddress clientAddressToCreate = new gov.ca.cwds.data.persistence.cms.ClientAddress("456789ABC", clientAddressDomain, "ABC");
    when(clientAddressDao.create(any(gov.ca.cwds.data.persistence.cms.ClientAddress.class))).thenReturn(clientAddressToCreate);
    LongText longTextDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validLongText.json"), LongText.class);
    gov.ca.cwds.data.persistence.cms.LongText longTextToCreate = new gov.ca.cwds.data.persistence.cms.LongText("567890ABC", longTextDomain, "ABC");
    when(longTextDao.create(any(gov.ca.cwds.data.persistence.cms.LongText.class))).thenReturn(longTextToCreate);
    ScreeningToReferral screeningToReferral = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/invalid/allegationNotPointingToVictim.json"), ScreeningToReferral.class);
    Boolean theErrorDetected = false;
    Response response = screeningToReferralService.create(screeningToReferral);
    if (response.hasMessages()) {
        Set<ErrorMessage> messages = response.getMessages();
        for (ErrorMessage message : messages) {
            if (message.getMessage() != null) {
                if (message.getMessage().contains("Allegation/Victim Person Id does not contain a Participant with a role of Victim")) {
                    theErrorDetected = true;
                }
            }
        }
        assertThat(theErrorDetected, is(equalTo(true)));
    } else {
        Assert.fail("Expected error was not detected");
    }
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Address(gov.ca.cwds.rest.api.domain.cms.Address) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) ChildClient(gov.ca.cwds.rest.api.domain.cms.ChildClient) Allegation(gov.ca.cwds.rest.api.domain.cms.Allegation) Client(gov.ca.cwds.rest.api.domain.cms.Client) ChildClient(gov.ca.cwds.rest.api.domain.cms.ChildClient) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) LongText(gov.ca.cwds.rest.api.domain.cms.LongText) 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) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) Referral(gov.ca.cwds.rest.api.domain.cms.Referral) CmsReferral(gov.ca.cwds.rest.api.domain.cms.CmsReferral) ScreeningToReferral(gov.ca.cwds.rest.api.domain.ScreeningToReferral) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) ScreeningToReferral(gov.ca.cwds.rest.api.domain.ScreeningToReferral) ErrorMessage(gov.ca.cwds.rest.api.domain.error.ErrorMessage) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) Test(org.junit.Test)

Aggregations

Client (gov.ca.cwds.rest.api.domain.cms.Client)60 Test (org.junit.Test)52 ReferralClient (gov.ca.cwds.rest.api.domain.cms.ReferralClient)47 Allegation (gov.ca.cwds.rest.api.domain.cms.Allegation)46 CmsReferral (gov.ca.cwds.rest.api.domain.cms.CmsReferral)46 CrossReport (gov.ca.cwds.rest.api.domain.cms.CrossReport)46 LinkedHashSet (java.util.LinkedHashSet)46 Referral (gov.ca.cwds.rest.api.domain.cms.Referral)45 Reporter (gov.ca.cwds.rest.api.domain.cms.Reporter)45 Set (java.util.Set)45 Response (gov.ca.cwds.rest.api.Response)44 ChildClient (gov.ca.cwds.rest.api.domain.cms.ChildClient)43 PostedScreeningToReferral (gov.ca.cwds.rest.api.domain.PostedScreeningToReferral)42 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 LongText (gov.ca.cwds.rest.api.domain.cms.LongText)42 ErrorMessage (gov.ca.cwds.rest.api.domain.error.ErrorMessage)22 ExpectedException (org.junit.rules.ExpectedException)17 PostedClient (gov.ca.cwds.rest.api.domain.cms.PostedClient)14