use of gov.ca.cwds.rest.api.domain.Allegation in project API by ca-cwds.
the class ScreeningToReferralService method processAllegations.
/*
* CMS Allegation - one for each allegation
*/
private Set<Allegation> processAllegations(ScreeningToReferral scr, String referralId, HashMap<Long, String> perpatratorClient, HashMap<Long, String> victimClient, Set<ErrorMessage> messages) throws ServiceException {
Set<Allegation> processedAllegations = new HashSet<>();
Set<Allegation> allegations;
String victimClientId = "";
String perpatratorClientId = "";
allegations = scr.getAllegations();
if (allegations == null || allegations.isEmpty()) {
String message = " Referral must have at least one Allegation ";
ServiceException exception = new ServiceException(message);
logError(message, exception, messages);
return processedAllegations;
}
for (Allegation allegation : allegations) {
try {
if (!ParticipantValidator.isVictimParticipant(scr, allegation.getVictimPersonId())) {
String message = " Allegation/Victim Person Id does not contain a Participant with a role of Victim ";
ServiceException exception = new ServiceException(message);
logError(message, exception, messages);
}
} catch (Exception e) {
logError(e.getMessage(), e, messages);
// next allegation
continue;
}
if (victimClient.containsKey(allegation.getVictimPersonId())) {
// this is the legacy Id (CLIENT) of the victime
victimClientId = victimClient.get(allegation.getVictimPersonId());
}
if (allegation.getPerpetratorPersonId() != 0) {
try {
if (!ParticipantValidator.isPerpetratorParticipant(scr, allegation.getPerpetratorPersonId())) {
String message = " Allegation/Perpetrator Person Id does not contain a Participant with a role of Perpetrator ";
ServiceException exception = new ServiceException(message);
logError(message, exception, messages);
}
} catch (Exception e) {
logError(e.getMessage(), e, messages);
// next allegation
continue;
}
}
if (perpatratorClient.containsKey(allegation.getPerpetratorPersonId())) {
// this is the legacy Id (CLIENT) of the perpetrator
perpatratorClientId = perpatratorClient.get(allegation.getPerpetratorPersonId());
}
if (victimClientId.isEmpty()) {
String message = " Victim could not be determined for an allegation ";
ServiceException exception = new ServiceException(message);
logError(message, exception, messages);
// next allegation
continue;
}
if (allegation.getLegacyId() == null || allegation.getLegacyId().isEmpty()) {
// create an allegation in CMS legacy database
gov.ca.cwds.rest.api.domain.cms.Allegation cmsAllegation = new gov.ca.cwds.rest.api.domain.cms.Allegation("", DEFAULT_CODE, "", scr.getLocationType(), "", DEFAULT_CODE, allegationTypeCode, scr.getReportNarrative(), "", false, DEFAULT_NON_PROTECTING_PARENT_CODE, false, victimClientId, perpatratorClientId, referralId, DEFAULT_COUNTY_SPECIFIC_CODE, false, DEFAULT_CODE);
buildErrors(messages, validator.validate(cmsAllegation));
PostedAllegation postedAllegation = this.allegationService.create(cmsAllegation);
allegation.setLegacyId(postedAllegation.getId());
allegation.setLegacySourceTable(ALLEGATION_TABLE_NAME);
processedAllegations.add(allegation);
} else {
gov.ca.cwds.rest.api.domain.cms.Allegation foundAllegation = this.allegationService.find(allegation.getLegacyId());
if (foundAllegation == null) {
String message = " Legacy Id on Allegation does not correspond to an existing CMS/CWS Allegation ";
ServiceException se = new ServiceException(message);
logError(message, se, messages);
// next allegation
continue;
}
}
}
return processedAllegations;
}
use of gov.ca.cwds.rest.api.domain.Allegation in project API by ca-cwds.
the class ScreeningToReferralService method create.
@UnitOfWork(value = "cms")
@Override
public Response create(Request request) {
ScreeningToReferral screeningToReferral = (ScreeningToReferral) request;
Set<ErrorMessage> messages = new HashSet<ErrorMessage>();
verifyReferralHasValidParticipants(screeningToReferral, messages);
String dateStarted = extractStartDate(screeningToReferral, messages);
String timeStarted = extractStartTime(screeningToReferral, messages);
String referralId = createCmsReferral(screeningToReferral, messages, dateStarted, timeStarted);
createReferralAddress(screeningToReferral, messages);
Set<Participant> resultParticipants = new HashSet<>();
HashMap<Long, String> victimClient = new HashMap<>();
HashMap<Long, String> perpatratorClient = new HashMap<>();
processParticipants(screeningToReferral, messages, dateStarted, referralId, resultParticipants, victimClient, perpatratorClient);
Set<CrossReport> resultCrossReports = createCrossReports(screeningToReferral, messages, referralId);
Set<Allegation> resultAllegations = createAllegations(screeningToReferral, messages, referralId, victimClient, perpatratorClient);
PostedScreeningToReferral pstr = PostedScreeningToReferral.createWithDefaults(referralId, screeningToReferral, resultParticipants, resultCrossReports, resultAllegations);
pstr.setMessages(messages);
return pstr;
}
Aggregations