use of org.apache.commons.lang3.Validate 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 org.apache.commons.lang3.Validate in project hive by apache.
the class HiveSchemaTool method validateSequences.
boolean validateSequences(Connection conn) throws HiveMetaException {
Map<String, Pair<String, String>> seqNameToTable = new ImmutableMap.Builder<String, Pair<String, String>>().put("MDatabase", Pair.of("DBS", "DB_ID")).put("MRole", Pair.of("ROLES", "ROLE_ID")).put("MGlobalPrivilege", Pair.of("GLOBAL_PRIVS", "USER_GRANT_ID")).put("MTable", Pair.of("TBLS", "TBL_ID")).put("MStorageDescriptor", Pair.of("SDS", "SD_ID")).put("MSerDeInfo", Pair.of("SERDES", "SERDE_ID")).put("MColumnDescriptor", Pair.of("CDS", "CD_ID")).put("MTablePrivilege", Pair.of("TBL_PRIVS", "TBL_GRANT_ID")).put("MTableColumnStatistics", Pair.of("TAB_COL_STATS", "CS_ID")).put("MPartition", Pair.of("PARTITIONS", "PART_ID")).put("MPartitionColumnStatistics", Pair.of("PART_COL_STATS", "CS_ID")).put("MFunction", Pair.of("FUNCS", "FUNC_ID")).put("MIndex", Pair.of("IDXS", "INDEX_ID")).put("MStringList", Pair.of("SKEWED_STRING_LIST", "STRING_LIST_ID")).build();
System.out.println("Validating sequence number for SEQUENCE_TABLE");
boolean isValid = true;
try {
Statement stmt = conn.createStatement();
for (String seqName : seqNameToTable.keySet()) {
String tableName = seqNameToTable.get(seqName).getLeft();
String tableKey = seqNameToTable.get(seqName).getRight();
String seqQuery = getDbCommandParser(dbType).needsQuotedIdentifier() ? ("select t.\"NEXT_VAL\" from \"SEQUENCE_TABLE\" t WHERE t.\"SEQUENCE_NAME\"='org.apache.hadoop.hive.metastore.model." + seqName + "'") : ("select t.NEXT_VAL from SEQUENCE_TABLE t WHERE t.SEQUENCE_NAME='org.apache.hadoop.hive.metastore.model." + seqName + "'");
String maxIdQuery = getDbCommandParser(dbType).needsQuotedIdentifier() ? ("select max(\"" + tableKey + "\") from \"" + tableName + "\"") : ("select max(" + tableKey + ") from " + tableName);
ResultSet res = stmt.executeQuery(maxIdQuery);
if (res.next()) {
long maxId = res.getLong(1);
if (maxId > 0) {
ResultSet resSeq = stmt.executeQuery(seqQuery);
if (!resSeq.next()) {
isValid = false;
System.err.println("Missing SEQUENCE_NAME " + seqName + " from SEQUENCE_TABLE");
} else if (resSeq.getLong(1) < maxId) {
isValid = false;
System.err.println("NEXT_VAL for " + seqName + " in SEQUENCE_TABLE < max(" + tableKey + ") in " + tableName);
}
}
}
}
System.out.println((isValid ? "Succeeded" : "Failed") + " in sequence number validation for SEQUENCE_TABLE");
return isValid;
} catch (SQLException e) {
throw new HiveMetaException("Failed to validate sequence number for SEQUENCE_TABLE", e);
}
}
use of org.apache.commons.lang3.Validate in project API by ca-cwds.
the class ScreeningToReferralService method createCmsReferral.
private String createCmsReferral(ScreeningToReferral screeningToReferral, Set<ErrorMessage> messages, String dateStarted, String timeStarted) {
String referralId = null;
if (screeningToReferral.getReferralId() == null || screeningToReferral.getReferralId().isEmpty()) {
// the legacy id is not set - create the referral
String longTextId = generateLongTextId(screeningToReferral, messages);
// create a CMS Referral
Referral referral = null;
try {
referral = Referral.createWithDefaults(ParticipantValidator.anonymousReporter(screeningToReferral), communicationsMethodCode, screeningToReferral.getName(), dateStarted, timeStarted, referralResponseTypeCode, longTextId, DEFAULT_COUNTY_SPECIFIC_CODE, DEFAULT_APPROVAL_STATUS_CODE, DEFAULT_STAFF_PERSON_ID);
} catch (Exception e1) {
String message = e1.getMessage();
logError(message, e1, messages);
}
buildErrors(messages, validator.validate(referral));
PostedReferral postedReferral = this.referralService.create(referral);
referralId = postedReferral.getId();
} else {
// Referral ID passed - validate that Referral exist in CWS/CMS - no update for now
referralId = screeningToReferral.getReferralId();
Referral foundReferral = this.referralService.find(referralId);
if (foundReferral == null) {
String message = "Legacy Id does not correspond to an existing CMS/CWS Referral";
ServiceException se = new ServiceException(message);
logError(message, se, messages);
}
}
return referralId;
}
use of org.apache.commons.lang3.Validate in project API by ca-cwds.
the class AddressValidationService method fetchValidatedAddresses.
/**
* Returns all valid addresses, up to the default number set in {@link SmartyStreetsDao}
*
* @param address The address to validate
* @return array of {@link ValidatedAddress}
* @throws ServiceException due to SmartyStreets error, I/O error, etc.
*/
public ValidatedAddress[] fetchValidatedAddresses(Address address) throws ServiceException {
ValidatedAddress[] addresses = null;
try {
SmartyStreet smartyStreet = new SmartyStreet(smartyStreetsDao);
addresses = smartyStreet.usStreetSingleAddress(address.getStreetAddress(), address.getCity(), address.getState(), address.getZip());
} catch (Exception e) {
throw new ServiceException("ERROR calling usStreetSingleAddress in SmartyStreet", e);
}
return addresses;
}
Aggregations