Search in sources :

Example 6 with Participant

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

the class ScreeningToReferralService method processParticipants.

private void processParticipants(ScreeningToReferral screeningToReferral, Set<ErrorMessage> messages, String dateStarted, String referralId, Set<Participant> resultParticipants, HashMap<Long, String> victimClient, HashMap<Long, String> perpatratorClient) {
    Set<Participant> participants = screeningToReferral.getParticipants();
    for (Participant incomingParticipant : participants) {
        try {
            if (!ParticipantValidator.hasValidRoles(incomingParticipant)) {
                String message = " Participant contains incompatiable roles ";
                ServiceException exception = new ServiceException(message);
                logError(message, exception, messages);
                // next participant
                continue;
            }
        } catch (Exception e1) {
            String message = e1.getMessage();
            logError(message, e1, messages);
            // next participant
            continue;
        }
        String genderCode = "";
        if (!incomingParticipant.getGender().isEmpty()) {
            genderCode = incomingParticipant.getGender().toUpperCase().substring(0, 1);
        }
        Set<String> roles = new HashSet<>(incomingParticipant.getRoles());
        /**
       * process the roles of this participant
       */
        for (String role : roles) {
            try {
                if (ParticipantValidator.roleIsReporterType(role) && (!ParticipantValidator.roleIsAnonymousReporter(role) && !ParticipantValidator.selfReported(incomingParticipant))) {
                    /*
             * CMS Reporter - if role is 'mandated reporter' or 'non-mandated reporter' and not
             * anonymous reporter or self-reported
             */
                    try {
                        savedReporter = processReporter(incomingParticipant, role, referralId, messages);
                        incomingParticipant.setLegacyId(savedReporter.getReferralId());
                        incomingParticipant.setLegacySourceTable(REPORTER_TABLE_NAME);
                    } catch (ServiceException e) {
                        String message = e.getMessage();
                        logError(message, e, messages);
                        // next role
                        continue;
                    }
                } else {
                    // reporter
                    if (!ParticipantValidator.roleIsAnonymousReporter(role)) {
                        String clientId;
                        if (incomingParticipant.getLegacyId() == null || incomingParticipant.getLegacyId().isEmpty()) {
                            // legacy Id not set - create a CLIENT row
                            PostedClient postedClient;
                            // not an anonymous reporter participant - create client
                            Client client = Client.createWithDefaults(incomingParticipant, dateStarted, genderCode);
                            buildErrors(messages, validator.validate(client));
                            postedClient = this.clientService.create(client);
                            clientId = postedClient.getId();
                            incomingParticipant.setLegacyId(clientId);
                            incomingParticipant.setLegacySourceTable(CLIENT_TABLE_NAME);
                        } else {
                            // legacy Id passed - check for existenct in CWS/CMS - no update yet
                            clientId = incomingParticipant.getLegacyId();
                            Client foundClient = this.clientService.find(clientId);
                            if (foundClient == null) {
                                String message = " Legacy Id of Participant does not correspond to an existing CWS/CMS Client ";
                                ServiceException se = new ServiceException(message);
                                logError(message, se, messages);
                                // next role
                                continue;
                            }
                        }
                        // CMS Referral Client
                        ReferralClient referralClient = ReferralClient.createWithDefault(ParticipantValidator.selfReported(incomingParticipant), referralId, clientId, DEFAULT_COUNTY_SPECIFIC_CODE, DEFAULT_APPROVAL_STATUS_CODE);
                        // validate referral client
                        buildErrors(messages, validator.validate(referralClient));
                        try {
                            gov.ca.cwds.rest.api.domain.cms.ReferralClient postedReferralClient = this.referralClientService.create(referralClient);
                        } catch (ServiceException se) {
                            logError(se.getMessage(), se, messages);
                        }
                        /*
               * determine other participant/roles attributes relating to CWS/CMS allegation
               */
                        if (ParticipantValidator.roleIsVictim(role)) {
                            victimClient.put(incomingParticipant.getId(), clientId);
                            // since this is the victim - process the ChildClient
                            try {
                                this.processChildClient(incomingParticipant, clientId, messages);
                            } catch (ServiceException e) {
                                String message = e.getMessage();
                                logError(message, e, messages);
                                // next role
                                continue;
                            }
                        }
                        if (ParticipantValidator.roleIsPerpetrator(role)) {
                            perpatratorClient.put(incomingParticipant.getId(), clientId);
                        }
                        try {
                            // addresses associated with a client
                            Participant resultParticipant = processClientAddress(incomingParticipant, referralId, clientId, messages);
                        } catch (ServiceException e) {
                            String message = e.getMessage();
                            logError(message, e, messages);
                            // next role
                            continue;
                        }
                    }
                }
            } catch (Exception e) {
                String message = e.getMessage();
                logError(message, e, messages);
            }
            resultParticipants.add(incomingParticipant);
        }
    // next role
    }
// next participant
}
Also used : ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) PostedClient(gov.ca.cwds.rest.api.domain.cms.PostedClient) ParseException(java.text.ParseException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) Participant(gov.ca.cwds.rest.api.domain.Participant) 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) PostedClient(gov.ca.cwds.rest.api.domain.cms.PostedClient) HashSet(java.util.HashSet) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient)

Example 7 with Participant

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

the class ReporterTest method createWithDefaultsShouldInitializeWithDefaultValues.

@Test
public void createWithDefaultsShouldInitializeWithDefaultValues() {
    String streetNumber = "1";
    String streetName = "main";
    String streetAddress = streetNumber + " " + streetName;
    String city = "sacramento";
    String state = "ca";
    Integer zipCode = 12345;
    String type = "type";
    gov.ca.cwds.rest.api.domain.Address address = new gov.ca.cwds.rest.api.domain.Address("legacy_source_table", "legacy_id", streetAddress, city, state, zipCode, type);
    String referralId = "referralId";
    boolean isMandatedReporter = true;
    String firstName = "firstName";
    String lastName = "lastName";
    Participant participant = new Participant(5L, "legacy_source_table", "legacy_client_id", firstName, lastName, "gender", "ssn", "date_of_birth", 7L, 8L, new HashSet(), new HashSet());
    String countyCode = "countyCode";
    Short stateCode = new Short("0");
    Reporter reporter = Reporter.createWithDefaults(referralId, isMandatedReporter, address, participant, countyCode, stateCode);
    assertEquals("Expected badgeNumber field to have been initialized with value", "", reporter.getBadgeNumber());
    assertEquals("Expected colltrClientRptrReltnshpType field to have been initialized with value", new Short("0"), reporter.getColltrClientRptrReltnshpType());
    assertEquals("Expected communicationMethodType field to have been initialized with value", new Short("0"), reporter.getCommunicationMethodType());
    assertEquals("Expected confidentialWaiverIndicator field to have been initialized with value", false, reporter.getConfidentialWaiverIndicator());
    assertEquals("Expected drmsMandatedRprtrFeedback field to have been initialized with value", "", reporter.getDrmsMandatedRprtrFeedback());
    assertEquals("Expected employerName field to have been initialized with value", "", reporter.getEmployerName());
    assertEquals("Expected feedbackDate field to have been initialized with value", "", reporter.getFeedbackDate());
    assertEquals("Expected feedbackRequiredIndicator field to have been initialized with value", false, reporter.getFeedbackRequiredIndicator());
    assertEquals("Expected messagePhoneExtensionNumber field to have been initialized with value", new Integer("0"), reporter.getMessagePhoneExtensionNumber());
    assertEquals("Expected messagePhoneNumber field to have been initialized with value", new BigDecimal(0), reporter.getMessagePhoneNumber());
    assertEquals("Expected middleInitialName field to have been initialized with value", "", reporter.getMiddleInitialName());
    assertEquals("Expected namePrefixDescription field to have been initialized with value", "", reporter.getNamePrefixDescription());
    assertEquals("Expected primaryPhoneNumber field to have been initialized with value", new BigDecimal(0), reporter.getPrimaryPhoneNumber());
    assertEquals("Expected primaryPhoneExtensionNumber field to have been initialized with value", new Integer("0"), reporter.getPrimaryPhoneExtensionNumber());
    assertEquals("Expected suffixTitleDescription field to have been initialized with value", "", reporter.getSuffixTitleDescription());
    assertEquals("Expected lawEnforcementId field to have been initialized with value", "", reporter.getLawEnforcementId());
    assertEquals("Expected zipSuffixNumber field to have been initialized with value", new Short("0"), reporter.getZipSuffixNumber());
}
Also used : BigDecimal(java.math.BigDecimal) Participant(gov.ca.cwds.rest.api.domain.Participant) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with Participant

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

the class ReporterTest method streetNameShouldNotIncludeTypeOfStreetsOrMultiPartStreetNames.

@Test
public void streetNameShouldNotIncludeTypeOfStreetsOrMultiPartStreetNames() {
    String streetAddress = "1 San Andreas Blvd";
    gov.ca.cwds.rest.api.domain.Address address = new gov.ca.cwds.rest.api.domain.Address("legacy_source_table", "legacy_id", streetAddress, "city", "state", 12345, "type");
    Participant participant = new Participant(5L, "legacy_source_table", "legacy_client_id", "firstName", "lastName", "gender", "ssn", "date_of_birth", 7L, 8L, new HashSet(), new HashSet());
    Reporter reporter = Reporter.createWithDefaults("referralId", true, address, participant, "countyCode", new Short("0"));
    assertEquals("Street Number not parsed from street address", "San", reporter.getStreetName());
}
Also used : Participant(gov.ca.cwds.rest.api.domain.Participant) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with Participant

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

the class ParticipantResourceTest method testPostValidatesEntity.

@Override
@Test
public void testPostValidatesEntity() throws Exception {
    roles.add("victim");
    Address address = new Address("", "", "123 First St", "San Jose", "CA", 94321, "Home");
    addresses.add(address);
    Participant participant = new Participant(1, "", "", "Marge", "Simpson", "Female", "11122333", "11-01-2017", 123, 456, roles, addresses);
    int status = inMemoryResource.client().target(ROOT_RESOURCE).request().accept(MediaType.APPLICATION_JSON).post(Entity.entity(participant, MediaType.APPLICATION_JSON)).getStatus();
    assertThat(status, is(422));
}
Also used : Address(gov.ca.cwds.rest.api.domain.Address) Participant(gov.ca.cwds.rest.api.domain.Participant) Test(org.junit.Test)

Example 10 with Participant

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

the class ParticipantResourceTest method testDelete200ResourceSuccess.

@Override
@Test
public void testDelete200ResourceSuccess() throws Exception {
    roles.add("victim");
    Address address = new Address("", "", "123 First St", "San Jose", "CA", 94321, "Home");
    addresses.add(address);
    Participant participant = new Participant(1, "", "", "Marge", "Simpson", "Female", "111223333", "2017-01-23", 123, 456, roles, addresses);
    int status = inMemoryResource.client().target(ROOT_RESOURCE).request().accept(MediaType.APPLICATION_JSON).post(Entity.entity(participant, MediaType.APPLICATION_JSON)).getStatus();
    assertThat(status, is(204));
}
Also used : Address(gov.ca.cwds.rest.api.domain.Address) Participant(gov.ca.cwds.rest.api.domain.Participant) Test(org.junit.Test)

Aggregations

Participant (gov.ca.cwds.rest.api.domain.Participant)18 Test (org.junit.Test)13 HashSet (java.util.HashSet)12 Address (gov.ca.cwds.rest.api.domain.Address)3 ImmutableSet (com.google.common.collect.ImmutableSet)1 Address (gov.ca.cwds.data.persistence.ns.Address)1 Screening (gov.ca.cwds.data.persistence.ns.Screening)1 Allegation (gov.ca.cwds.rest.api.domain.Allegation)1 CrossReport (gov.ca.cwds.rest.api.domain.CrossReport)1 Person (gov.ca.cwds.rest.api.domain.Person)1 PostedScreening (gov.ca.cwds.rest.api.domain.PostedScreening)1 PostedScreeningToReferral (gov.ca.cwds.rest.api.domain.PostedScreeningToReferral)1 ScreeningRequest (gov.ca.cwds.rest.api.domain.ScreeningRequest)1 ScreeningResponse (gov.ca.cwds.rest.api.domain.ScreeningResponse)1 ScreeningToReferral (gov.ca.cwds.rest.api.domain.ScreeningToReferral)1 ChildClient (gov.ca.cwds.rest.api.domain.cms.ChildClient)1 Client (gov.ca.cwds.rest.api.domain.cms.Client)1 PostedAllegation (gov.ca.cwds.rest.api.domain.cms.PostedAllegation)1 PostedClient (gov.ca.cwds.rest.api.domain.cms.PostedClient)1 ReferralClient (gov.ca.cwds.rest.api.domain.cms.ReferralClient)1