use of gov.ca.cwds.rest.api.domain.cms.ReferralClient in project API by ca-cwds.
the class ReferralClientServiceTest method createReturnsNonNull.
@SuppressWarnings("javadoc")
@Test
public void createReturnsNonNull() throws Exception {
ReferralClient referralClientDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/ReferralClient/valid/valid.json"), ReferralClient.class);
gov.ca.cwds.data.persistence.cms.ReferralClient toCreate = new gov.ca.cwds.data.persistence.cms.ReferralClient(referralClientDomain, "ABC");
ReferralClient request = new ReferralClient(toCreate);
when(referralClientDao.create(any(gov.ca.cwds.data.persistence.cms.ReferralClient.class))).thenReturn(toCreate);
ReferralClient postedReferralClient = referralClientService.create(request);
assertThat(postedReferralClient, is(notNullValue()));
}
use of gov.ca.cwds.rest.api.domain.cms.ReferralClient in project API by ca-cwds.
the class NonLACountyTriggersTest method testChecksReferralClientCreatedCountyOwnership.
/*
* Test for checking the referral Client CountyOnwership created or updated through the PUT method
*/
@SuppressWarnings("javadoc")
@Test
public void testChecksReferralClientCreatedCountyOwnership() throws Exception {
ReferralClient referralClientDomain = MAPPER.readValue(fixture("fixtures/legacy/business/rules/nonLaCountyTrigger/referralClientValid.json"), ReferralClient.class);
gov.ca.cwds.data.persistence.cms.ReferralClient toCreate = new gov.ca.cwds.data.persistence.cms.ReferralClient(referralClientDomain, "ABC");
ReferralClient request = new ReferralClient(toCreate);
when(countyOwnershipDao.find(any(String.class))).thenReturn(null);
when(countyOwnershipDao.create(any(CountyOwnership.class))).thenAnswer(new Answer<CountyOwnership>() {
@Override
public CountyOwnership answer(InvocationOnMock invocation) throws Throwable {
CountyOwnership report = (CountyOwnership) invocation.getArguments()[0];
countyOwnership = report;
return report;
}
});
nonLaCountyTriggers.createAndUpdateReferralClientCoutyOwnership(toCreate);
Assert.assertNotNull(countyOwnership);
assertThat(countyOwnership.getEntityCode(), is(equalTo("C")));
}
use of gov.ca.cwds.rest.api.domain.cms.ReferralClient in project API by ca-cwds.
the class ReferralClientResourceTest method udpateDelegatesToResourceDelegate.
/*
* Update Tests
*/
@Test
public void udpateDelegatesToResourceDelegate() throws Exception {
ReferralClient serialized = MAPPER.readValue(fixture("fixtures/domain/legacy/ReferralClient/valid/valid.json"), ReferralClient.class);
inMemoryResource.client().target(ROOT_RESOURCE).request().accept(MediaType.APPLICATION_JSON).put(Entity.entity(serialized, MediaType.APPLICATION_JSON));
verify(resourceDelegate).update(eq(null), eq(serialized));
}
use of gov.ca.cwds.rest.api.domain.cms.ReferralClient in project API by ca-cwds.
the class ReferralClientResourceTest method createValidatesEntity.
@Test
public void createValidatesEntity() throws Exception {
ReferralClient serialized = MAPPER.readValue(fixture("fixtures/domain/legacy/ReferralClient/invalid/clientIdMissing.json"), ReferralClient.class);
int status = inMemoryResource.client().target(ROOT_RESOURCE).request().accept(MediaType.APPLICATION_JSON).post(Entity.entity(serialized, MediaType.APPLICATION_JSON)).getStatus();
assertThat(status, is(422));
}
use of gov.ca.cwds.rest.api.domain.cms.ReferralClient 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
}
Aggregations