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
}
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());
}
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());
}
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));
}
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));
}
Aggregations