use of org.jaffa.datatypes.ValidationException in project jaffa-framework by jaffa-projects.
the class FormGroupMaintenanceTx method createFormUsageEntry.
// .//GEN-END:_deleteRelatedObjects_2_be
// All the custom code goes here//GEN-FIRST:_custom
// Add the related FormUsage
private void createFormUsageEntry(UOW uow, FormGroupMaintenanceUpdateInDto input, boolean fromPrevalidate) throws FrameworkException, ApplicationExceptions {
ApplicationExceptions appExps = null;
try {
if (input.getFormName() != null) {
Criteria criteria = new Criteria();
criteria.setTable(FormUsageMeta.getName());
criteria.addCriteria(FormUsageMeta.FORM_NAME, input.getFormName());
Collection col = uow.query(criteria);
// Iterator itr = col.iterator();
for (int i = 0; i < input.getFormUsageCount(); i++) {
boolean found = false;
FormUsageDto inputFormUsageDto = input.getFormUsage(i);
for (Iterator itr = col.iterator(); itr.hasNext(); ) {
FormUsage formusage = (FormUsage) itr.next();
if (inputFormUsageDto.getEventName().equals(formusage.getEventName())) {
try {
formusage.updateFormAlternate(inputFormUsageDto.getFormAlternate());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
formusage.updateCopies(inputFormUsageDto.getCopies());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
if (appExps != null && appExps.size() > 0)
throw appExps;
if (!fromPrevalidate) {
if (log.isDebugEnabled())
log.debug("Creating FormUsage: " + formusage);
uow.update(formusage);
found = true;
}
break;
} else {
continue;
}
}
if (!found) {
FormUsage formUsage = new FormUsage();
formUsage.setEventName(inputFormUsageDto.getEventName());
formUsage.setFormName(input.getFormName());
formUsage.setFormAlternate(inputFormUsageDto.getFormAlternate());
formUsage.setCopies(inputFormUsageDto.getCopies());
if (!fromPrevalidate) {
if (log.isDebugEnabled())
log.debug("Creating FormUsage: " + formUsage);
uow.add(formUsage);
}
}
}
for (Iterator itr = col.iterator(); itr.hasNext(); ) {
boolean found = false;
FormUsage formusage = (FormUsage) itr.next();
for (int i = 0; i < input.getFormUsageCount(); i++) {
FormUsageDto inputFormUsageDto = input.getFormUsage(i);
if (formusage.getEventName().equals(inputFormUsageDto.getEventName())) {
found = true;
break;
}
}
if (!found) {
if (!fromPrevalidate) {
if (log.isDebugEnabled())
log.debug("Creating FormUsage: " + formusage);
uow.delete(formusage);
}
}
}
}
} catch (ValidationException e) {
throw new ApplicationExceptions(e);
}
}
use of org.jaffa.datatypes.ValidationException in project jaffa-framework by jaffa-projects.
the class FormGroupMaintenanceTx method createDomain.
// .//GEN-END:_duplicateCheck_4_be
// .//GEN-BEGIN:_createDomain_1_be
/**
* Create the domain object.
*/
private FormGroup createDomain(UOW uow, FormGroupMaintenanceCreateInDto input, boolean fromPrevalidate) throws FrameworkException, ApplicationExceptions {
FormGroup domain = new FormGroup();
ApplicationExceptions appExps = null;
// .//GEN-BEGIN:_createDomain_2_be
try {
domain.updateFormName(input.getFormName());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateDescription(input.getDescription());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateFormType(input.getFormType());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
// .//GEN-BEGIN:_createDomain_3_be
if (appExps != null && appExps.size() > 0)
throw appExps;
return domain;
}
use of org.jaffa.datatypes.ValidationException in project jaffa-framework by jaffa-projects.
the class FormEventMaintenanceTx method createDomain.
// .//GEN-END:_duplicateCheck_4_be
// .//GEN-BEGIN:_createDomain_1_be
/**
* Create the domain object.
*/
private FormEvent createDomain(UOW uow, FormEventMaintenanceCreateInDto input, boolean fromPrevalidate) throws FrameworkException, ApplicationExceptions {
FormEvent domain = new FormEvent();
ApplicationExceptions appExps = null;
// .//GEN-BEGIN:_createDomain_2_be
try {
domain.updateEventName(input.getEventName());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateDescription(input.getDescription());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
// .//GEN-BEGIN:_createDomain_3_be
if (appExps != null && appExps.size() > 0)
throw appExps;
return domain;
}
use of org.jaffa.datatypes.ValidationException in project jaffa-framework by jaffa-projects.
the class FormDefinitionMaintenanceTx method updateDomain.
// .//GEN-END:_loadUpdate_3_be
// .//GEN-BEGIN:_updateDomain_1_be
/**
* Update the domain object and add it to the UOW.
*/
private void updateDomain(UOW uow, FormDefinitionMaintenanceUpdateInDto input, FormDefinition domain, boolean fromPrevalidate) throws FrameworkException, ApplicationExceptions {
ApplicationExceptions appExps = null;
// .//GEN-END:_updateDomain_1_be
// Add custom code//GEN-FIRST:_updateDomain_1
// if FormTemplate and FieldLayout fields are null, set them to their current domain values, so
// the generated code does not set them to null.
String origFormTemplate = input.getFormTemplate();
String origFieldLayout = input.getFieldLayout();
if (input.getFormTemplate() == null)
input.setFormTemplate(domain.getFormTemplate());
if (input.getFieldLayout() == null)
input.setFieldLayout(domain.getFieldLayout());
// .//GEN-BEGIN:_updateDomain_2_be
try {
domain.updateFormName(input.getFormName());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateFormAlternate(input.getFormAlternate());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateFormVariation(input.getFormVariation());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateOutputType(input.getOutputType());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateFormTemplate(input.getFormTemplate());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateFieldLayout(input.getFieldLayout());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateDescription(input.getDescription());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateRemarks(input.getRemarks());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateDomFactory(input.getDomFactory());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateDomClass(input.getDomClass());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateDomKey1(input.getDomKey1());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateDomKey2(input.getDomKey2());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateDomKey3(input.getDomKey3());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateDomKey4(input.getDomKey4());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateDomKey5(input.getDomKey5());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateDomKey6(input.getDomKey6());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateAdditionalDataComponent(input.getAdditionalDataComponent());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateFollowOnFormName(input.getFollowOnFormName());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateFollowOnFormAlternate(input.getFollowOnFormAlternate());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
if (!fromPrevalidate)
domain.updateLastChangedOn(new DateTime());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
if (!fromPrevalidate && input.getHeaderDto() != null && input.getHeaderDto().getUserId() != null)
domain.updateLastChangedBy(input.getHeaderDto().getUserId());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
// .//GEN-END:_updateDomain_2_be
// Add custom code//GEN-FIRST:_updateDomain_2
// Restore the original value in the input object incase any other logic relies on them
input.setFormTemplate(origFormTemplate);
input.setFieldLayout(origFieldLayout);
// .//GEN-BEGIN:_updateDomain_3_be
if (appExps != null && appExps.size() > 0)
throw appExps;
}
use of org.jaffa.datatypes.ValidationException in project jaffa-framework by jaffa-projects.
the class RulesEngine method invokeRules.
/**
* This will invoke all the rules for a field.
*/
private static void invokeRules(Object fieldValue, UOW uow, boolean doOnlyMandatory, String labelToken, FieldMetaData fieldMetaData) throws ValidationException, FrameworkException {
RuleMetaData[] rules = fieldMetaData.getRules();
for (int i = 0; i < rules.length; i++) {
RuleMetaData rule = rules[i];
IFieldValidator validator = null;
try {
FieldValidatorMetaData fieldValidatorMetaData = ValidatorMetaDataService.getFieldValidatorMetaData(rule.getName());
if (!doOnlyMandatory || fieldValidatorMetaData.getMandatory()) {
// Create an instance of the validator
validator = (IFieldValidator) Class.forName(fieldValidatorMetaData.getClassName()).newInstance();
// Perform the initialization
validator.init();
// Set some values
validator.setValue(fieldValue);
validator.setLabelToken(labelToken);
validator.setUow(uow);
// Set the Parameters, if specified in the validators.xml file
if (fieldValidatorMetaData.getParameters() != null) {
for (Iterator itr = fieldValidatorMetaData.getParameters().entrySet().iterator(); itr.hasNext(); ) {
Map.Entry me = (Map.Entry) itr.next();
BeanHelper.setField(validator, (String) me.getKey(), (String) me.getValue());
}
}
// Set the Parameters provided in the rules.xml file
for (Iterator itr = rule.getParameters().entrySet().iterator(); itr.hasNext(); ) {
Map.Entry me = (Map.Entry) itr.next();
BeanHelper.setField(validator, (String) me.getKey(), (String) me.getValue());
}
// Now perform validation
if (log.isDebugEnabled())
log.debug("Invoking the rule " + rule.getName() + " for field " + fieldMetaData.getName());
validator.validate();
}
} catch (ValidationException e) {
throw e;
} catch (FrameworkException e) {
throw e;
} catch (Exception e) {
String str = "Error thrown while trying to invoke the rules for the field '" + labelToken + "', having the value '" + fieldValue + "', using the fieldMetaData - " + fieldMetaData;
log.error(str, e);
throw new RulesEngineException(RulesEngineException.RULE_INVOCATION_FAILED, new Object[] { labelToken, fieldValue }, e);
} finally {
if (validator != null) {
validator.cleanup();
validator = null;
}
}
}
}
Aggregations