use of gov.ca.cwds.rest.api.domain.cms.ChildClient in project API by ca-cwds.
the class ChildClientResourceTest method updateValidatesEntity.
// @Test
public void updateValidatesEntity() throws Exception {
ChildClient serialized = MAPPER.readValue(fixture("fixtures/domain/legacy/ChildClient/invalid/tribalCustomaryAdoptionDate/invalidFormat.json"), ChildClient.class);
int status = inMemoryResource.client().target(ROOT_RESOURCE).request().accept(MediaType.APPLICATION_JSON).put(Entity.entity(serialized, MediaType.APPLICATION_JSON)).getStatus();
assertThat(status, is(422));
}
use of gov.ca.cwds.rest.api.domain.cms.ChildClient 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.cms.ChildClient in project API by ca-cwds.
the class ScreeningToReferralServiceTest method testWithReferralDoesNotExistFail.
@SuppressWarnings("javadoc")
@Test
public void testWithReferralDoesNotExistFail() 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);
when(referralDao.find("0123456ABC")).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/withReferralIdNotExist.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 != null) {
if (message.getMessage().contains("Legacy Id does not correspond to an existing CMS/CWS Referral")) {
theErrorDetected = true;
}
}
}
assertThat(theErrorDetected, is(equalTo(true)));
} else {
Assert.fail("Expected error messages were not thrown");
}
}
use of gov.ca.cwds.rest.api.domain.cms.ChildClient in project API by ca-cwds.
the class ScreeningToReferralServiceTest method testIncompatiableRolesVictimPerpetratorFail.
@SuppressWarnings("javadoc")
@Test
public void testIncompatiableRolesVictimPerpetratorFail() 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/incompatiableRoleVictimPerpetrator.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("Participant contains incompatiable roles")) {
theErrorDetected = true;
}
}
}
assertThat(theErrorDetected, is(equalTo(true)));
} else {
Assert.fail("Expected error messages were not thrown");
}
}
use of gov.ca.cwds.rest.api.domain.cms.ChildClient in project API by ca-cwds.
the class ScreeningToReferralServiceTest method testScreeningToReferralWithoutAllegationFail.
@SuppressWarnings("javadoc")
@Test
public // R - 03895
void testScreeningToReferralWithoutAllegationFail() 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/invalid/withoutAllegation.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("Referral must have at least one Allegation")) {
theErrorDetected = true;
}
}
}
assertThat(theErrorDetected, is(equalTo(true)));
} else {
Assert.fail("Expected error was not detected");
}
}
Aggregations