use of org.jaffa.exceptions.ApplicationException in project jaffa-framework by jaffa-projects.
the class ForeignKeyValidator method validateKey.
/**
* Apply the foreign-key validation at the property-level.
*/
private void validateKey(T targetObject, String[] fkFields, Object[] fkValues, RuleMetaData rule) throws ApplicationException, JaffaRulesFrameworkException {
if (log.isDebugEnabled()) {
log.debug("Applying the check " + rule + " for the fields " + StringHelper.stringArrayToString(fkFields) + " on " + targetObject);
}
// Find the 'public static boolean exists(UOW uow, Object key...)' method
Method m = findMethod(fkFields, rule);
// Invoke the 'public static boolean exists(UOW uow, Object key...)' method
Boolean result;
try {
result = (Boolean) m.invoke(null, fkValues);
} catch (Exception e) {
throw new JaffaRulesFrameworkException(e.getMessage(), null, e);
}
if (result == null || !result) {
String domainLabel = getObjectLabel(m.getDeclaringClass().getName(), null);
StringBuilder fkLabel = new StringBuilder();
for (int i = 0; i < fkFields.length; i++) {
if (i > 0) {
fkLabel.append(',');
}
fkLabel.append(getPropertyLabel(targetObject, fkFields[i]));
}
String fieldKeyLabel = fkLabel.toString();
String primaryKeyLabel = getPrimaryKeyLabel(m.getDeclaringClass().getName(), null);
if (primaryKeyLabel == null) {
primaryKeyLabel = fieldKeyLabel;
}
if (log.isDebugEnabled()) {
log.debug("ForeignKey validation for the value '" + fkValues + "' of '" + fkFields + "' failed against the domainObject '" + m.getDeclaringClass().getName() + '\'');
}
Object[] arguments = getErrorArgumentArray(targetObject, rule);
if (arguments.length == 0) {
arguments = new Object[] { domainLabel, primaryKeyLabel };
}
throw wrapException(new InvalidForeignKeyException(fkLabel.toString(), arguments), targetObject, rule);
}
}
use of org.jaffa.exceptions.ApplicationException in project jaffa-framework by jaffa-projects.
the class TransformerUtils method deleteBeanData.
static void deleteBeanData(String path, GraphDataObject source, UOW uow, ITransformationHandler handler, GraphMapping mapping, IPersistent domainObject) throws InstantiationException, IllegalAccessException, InvocationTargetException, ApplicationExceptions, FrameworkException {
try {
// Ensure the domain object has not been modified
domainObjectChangedTest(path, source, mapping, domainObject);
List<ITransformationHandler> handlers = null;
if (handler != null) {
handlers = handler.getTransformationHandlers();
}
// Fire 'startBean' handler
if (handlers != null) {
for (ITransformationHandler transformationHandler : handlers) {
transformationHandler.startBean(path, source, domainObject);
}
}
// ----------------------------------------------------------------
// Now loop through children, if there is one, delete it, and leave parent alone
boolean deleteChild = false;
// Reflect any related objects
Set relatedFields = mapping.getRelatedFields();
if (relatedFields != null) {
for (Object relatedField : relatedFields) {
String field = (String) relatedField;
Object value = getProperty(mapping.getDataFieldDescriptor(field), source);
if (value != null) {
if (value.getClass().isArray()) {
// The related field is an array of objects (one-to-many)
Object[] values = (Object[]) value;
for (int i = 0; i < values.length; i++) {
// Assumes its a DAO....what else could it be?
GraphDataObject dao = (GraphDataObject) values[i];
if (dao != null) {
deleteChild = true;
deleteChildBean(path + '.' + field + '[' + i + ']', dao, uow, handler, domainObject, mapping, field);
}
}
} else {
// The related field is a single object (one-to-many)
// Assumes its a DAO....what else could it be?
GraphDataObject dao = (GraphDataObject) value;
deleteChild = true;
deleteChildBean(path + '.' + field, dao, uow, handler, domainObject, mapping, field);
}
}
}
}
// Delete this record, as it had no children
if (!deleteChild) {
if (log.isDebugEnabled())
log.debug("UOW.Delete Domain Object");
// Fire 'startBeanDelete' handler
if (handlers != null) {
for (ITransformationHandler transformationHandler : handlers) {
transformationHandler.startBeanDelete(path, source, domainObject);
}
}
uow.delete(domainObject);
if (handlers != null) {
for (ITransformationHandler transformationHandler : handlers) {
transformationHandler.setChangeDone(true);
}
}
// Fire 'endBeanDelete' handler
if (handlers != null) {
for (ITransformationHandler transformationHandler : handlers) {
transformationHandler.endBeanDelete(path, source, domainObject);
}
}
}
// Fire 'endBean' handler
if (handlers != null) {
for (ITransformationHandler transformationHandler : handlers) {
transformationHandler.endBean(path, source, domainObject);
}
}
} catch (SkipTransformException e) {
if (log.isDebugEnabled())
log.debug("Processing of " + path + " will be skipped", e);
} catch (ApplicationException e) {
throw new ApplicationExceptions(e);
}
}
use of org.jaffa.exceptions.ApplicationException in project jaffa-framework by jaffa-projects.
the class FormSelectionMaintenanceComponent method print.
/**
* Generates all forms and/or labels for the current Event and Keyset.
* This method should be used when a User Interface is not needed.
* Prior to calling this method, set the Event and Keyset using
* setEvent(), setKey1(), setValue1(), setKey2(), setValue2(),setKey3(), setValue3(),
* setKey4(), setValue4(), setKey5(), setValue5(), setKey6(), setValue6().
* The forms and/or labels that match the current
* Event and Keyset will be printed and/or emailed.
* @throws ApplicationExceptions - When an exception occurs for a given
* Form or Label, the exception will be caught and added to the
* ApplicationExceptions.ApplicationExceptionArray. Therefore multiple
* exceptions may be caught and finally thrown at the end of this method.
* Forms and/or Labels that do not experience an exception will be
* generated successfully.
*/
public void print() throws ApplicationExceptions, Exception {
if (log.isDebugEnabled()) {
log.debug(" Begin generating forms and labels. ");
log.debug("Event = " + getEvent() + ".");
log.debug("Key 1 " + getKey1() + " = " + getValue1() + ".");
log.debug("Key 2 " + getKey2() + " = " + getValue2() + ".");
log.debug("Key 3 " + getKey3() + " = " + getValue3() + ".");
log.debug("Key 4 " + getKey4() + " = " + getValue4() + ".");
log.debug("Key 5 " + getKey5() + " = " + getValue5() + ".");
log.debug("Key 6 " + getKey6() + " = " + getValue6() + ".");
}
ApplicationExceptions appExps = new ApplicationExceptions();
GridModel gridModelRows = new GridModel();
FormSelectionMaintenanceOutDto finderOutDto = null;
setFormUserId(SecurityManager.getPrincipal() != null ? SecurityManager.getPrincipal().getName() : null);
// Validate that Event and Key1 are populated at a minimum.
if (getEvent() == null) {
throw new ApplicationExceptions(new MandatoryFieldException("[label.Jaffa.Printing.FormSelection.Event]"));
}
if (getKey1() == null || getValue1() == null) {
throw new ApplicationExceptions(new MandatoryFieldException("[label.Jaffa.Printing.FormSelection.Key1]"));
}
try {
finderOutDto = (FormSelectionMaintenanceOutDto) doInquiry2();
} catch (Exception ex) {
throw new ApplicationExceptions(new ApplicationException(ex.getMessage()));
}
if (finderOutDto != null && finderOutDto.getRowsCount() > 0) {
EditBoxModel printerModel = null;
GridModelRow gridModelRow = null;
FormSelectionMaintenanceOutRowDto[] rows = finderOutDto.getRows();
for (FormSelectionMaintenanceOutRowDto row : rows) {
gridModelRow = gridModelRows.newRow();
gridModelRow.addElement("select", new CheckBoxModel(Boolean.TRUE));
gridModelRow.addElement("formName", row.getFormName());
gridModelRow.addElement("formAlternateName", row.getFormAlternateName());
gridModelRow.addElement("formVariation", row.getFormVariation());
gridModelRow.addElement("event", row.getEvent());
gridModelRow.addElement("key1", row.getKey1());
gridModelRow.addElement("key2", row.getKey2());
gridModelRow.addElement("key3", row.getKey3());
gridModelRow.addElement("key4", row.getKey4());
gridModelRow.addElement("key5", row.getKey5());
gridModelRow.addElement("key6", row.getKey6());
gridModelRow.addElement("value1", row.getValue1());
gridModelRow.addElement("value2", row.getValue2());
gridModelRow.addElement("value3", row.getValue3());
gridModelRow.addElement("value4", row.getValue4());
gridModelRow.addElement("value5", row.getValue5());
gridModelRow.addElement("value6", row.getValue6());
printerModel = new EditBoxModel(row.getPrinter(), PrinterDefinitionMeta.META_PRINTER_ID);
printerModel.setMandatory(false);
gridModelRow.addElement("printer", printerModel);
gridModelRow.addElement("email", new EditBoxModel(getEmailAddress()));
gridModelRow.addElement("publish", new CheckBoxModel(Boolean.FALSE));
gridModelRow.addElement("copies", new EditBoxModel(row.getCopies()));
gridModelRow.addElement("object", row);
try {
ApplicationExceptions aes = new ApplicationExceptions();
validateFields(gridModelRow, aes, false);
if (aes != null && aes.size() > 0) {
for (Iterator i = aes.iterator(); i.hasNext(); ) {
ApplicationException appEx = (ApplicationException) i.next();
appExps.add(appEx);
}
} else {
m_tx.dispatchPrintRequest(createPrintRequestObject(gridModelRow, false));
}
} catch (Exception ex) {
if (ex instanceof ApplicationExceptions) {
for (ApplicationException appExp : ((ApplicationExceptions) ex).getApplicationExceptionArray()) {
appExps.add(appExp);
}
} else if (ex instanceof ApplicationException) {
appExps.add((ApplicationException) ex);
} else {
appExps.add(new ApplicationException(ex.getMessage()));
}
}
}
} else {
if (appExps.size() == 0) {
appExps.add(new FormSelectionException(FormSelectionException.NO_FORM_DEFINED_FOR_EVENT, getEvent()));
}
}
if (appExps != null && appExps.size() > 0) {
throw appExps;
}
if (log.isDebugEnabled()) {
log.debug(" Finished generating forms and labels. ");
}
}
use of org.jaffa.exceptions.ApplicationException in project jaffa-framework by jaffa-projects.
the class FormSelectionMaintenanceComponent method doUpdateDetail.
/**
* Show the AdditionalData Component.
* Pass the Additional Data Object if there is one.
*/
public FormKey doUpdateDetail(GridModelRow selectedRow, String actionPath) throws ApplicationExceptions, FrameworkException {
FormKey fk = null;
String additionalComponent = null;
try {
final FormSelectionMaintenanceOutRowDto rowDto = (FormSelectionMaintenanceOutRowDto) selectedRow.get("object");
additionalComponent = rowDto.getAdditionalDataComponent();
Component comp = (Component) run(additionalComponent);
BeanUtils.setProperty(comp, getKey1(), getValue1());
if (getKey2() != null) {
BeanUtils.setProperty(comp, getKey2(), getValue2());
}
if (getKey3() != null) {
BeanUtils.setProperty(comp, getKey3(), getValue3());
}
if (getKey4() != null) {
BeanUtils.setProperty(comp, getKey4(), getValue4());
}
if (getKey5() != null) {
BeanUtils.setProperty(comp, getKey5(), getValue5());
}
if (getKey6() != null) {
BeanUtils.setProperty(comp, getKey6(), getValue6());
}
// implements IAdditionalDataObject.
if (comp instanceof IAdditionalDataObject) {
((IAdditionalDataObject) comp).setAdditionalDataObject(rowDto.getAdditionalDataObject());
((IUpdateComponent) comp).addUpdateListener(new IUpdateListener() {
public void updateDone(EventObject source) {
try {
rowDto.setAdditionalDataObject(((IAdditionalDataObject) source.getSource()).getAdditionalDataObject());
} catch (Exception e) {
log.warn("Error setting the Additional Data Object after the Update", e);
}
}
});
}
comp.setReturnToFormKey(getResultsFormKey());
// Populate info to allow Web 2.0 component to return to this component
if (comp instanceof RiaWrapperComponent) {
RiaWrapperComponent c = (RiaWrapperComponent) comp;
c.getParameters().setProperty("returnToActionPath", actionPath);
c.getParameters().setProperty("returnToFormKey_componentId", comp.getReturnToFormKey().getComponentId());
}
fk = comp.display();
} catch (SecurityException se) {
log.error("SecurityException Occurred ", se);
throw new ApplicationExceptions(new FormSelectionException(FormSelectionException.SECURITY_EXCEPTION));
} catch (IllegalAccessException e) {
log.error("IllegalAccessException Occurred ", e);
} catch (InvocationTargetException e) {
log.error("InvocationTargetException Occurred ", e);
} catch (IllegalArgumentException e) {
log.error("IllegalArgumentException Occurred ", e);
} catch (ApplicationExceptions applicationException) {
throw applicationException;
} catch (FrameworkException frameworkException) {
throw frameworkException;
}
return fk;
}
use of org.jaffa.exceptions.ApplicationException in project jaffa-framework by jaffa-projects.
the class FormUsageMaintenanceTx method update.
// .//GEN-END:_prevalidateUpdate_1_be
// .//GEN-BEGIN:_update_1_be
/**
* Updates an existing instance of FormUsage.
* @param input The new values for the domain object.
* @throws ApplicationExceptions This will be thrown if the input contains invalid data.
* @throws FrameworkException Indicates some system error.
* @return The object details.
*/
public FormUsageMaintenanceRetrieveOutDto update(FormUsageMaintenanceUpdateInDto input) throws FrameworkException, ApplicationExceptions {
UOW uow = null;
try {
// Print Debug Information for the input
if (log.isDebugEnabled())
log.debug("Input: " + input);
// create the UOW
uow = new UOW();
// Preprocess the input
preprocess(uow, input);
// Retrieve the object
FormUsage domain = load(uow, input);
// Ensure the domain object has not been modified
domainObjectChangedTest(input.getPerformDirtyReadCheck(), domain, input.getLastChangedOn());
// Validate the foreign objects
validateForeignObjects(uow, input);
// Update the domain object
updateDomain(uow, input, domain, false);
uow.update(domain);
// Commit the changes
uow.commit();
// Print Debug Information for the output
if (log.isDebugEnabled())
log.debug("Successfully updated the domain object. Now retrieving the object details.");
// Build the outbound dto by performing a retrieve
FormUsageMaintenanceRetrieveInDto retrieveInDto = new FormUsageMaintenanceRetrieveInDto();
retrieveInDto.setHeaderDto(input.getHeaderDto());
retrieveInDto.setFormName(input.getFormName());
FormUsageMaintenanceRetrieveOutDto output = retrieve(retrieveInDto);
return output;
} catch (FrameworkException e) {
// If it is, then re-throw as ApplicationsExceptions, else throw the FrameworkException.
if (e.getCause() != null && e.getCause() instanceof ApplicationExceptions) {
throw (ApplicationExceptions) e.getCause();
} else if (e.getCause() != null && e.getCause() instanceof ApplicationException) {
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add((ApplicationException) e.getCause());
throw appExps;
} else
throw e;
} finally {
if (uow != null)
uow.rollback();
}
}
Aggregations