use of org.jaffa.exceptions.FrameworkException in project jaffa-framework by jaffa-projects.
the class DemoLogger method log.
private void log(Collection<IPersistent> objectsToLog, Collection<String> serializedObjects) throws ApplicationExceptions, FrameworkException {
// In which case, do rememeber to invoke the flush() method on the UOW!
if (objectsToLog != null) {
try {
for (IPersistent obj : objectsToLog) {
StringWriter writer = new StringWriter();
JAXBContext jc = JAXBContext.newInstance(new Class[] { obj.getClass() });
Marshaller marshaller = jc.createMarshaller();
marshaller.marshal(obj, writer);
serializedObjects.add(writer.toString());
writer.close();
}
} catch (Exception e) {
throw ExceptionHelper.throwAFR(e);
}
}
}
use of org.jaffa.exceptions.FrameworkException in project jaffa-framework by jaffa-projects.
the class BeanMoulder method deleteBean.
/**
* Take a source object and delete it or delete is children if it has any
* @param path The path of this object being processed. This identifies possible parent
* and/or indexed entries where this object is contained.
* @param source Source object to mould from, typically a DomainDAO
* @param uow Transaction handle all creates/update will be performed within.
* Throws an exception if null.
* @param handler Possible bean handler to be used when processing this source object graph
* @throws ApplicationExceptions Thrown if one or more application logic errors are generated during moulding
* @throws FrameworkException Thrown if any runtime moulding error has occured.
*/
public static void deleteBean(String path, DomainDAO source, UOW uow, MouldHandler handler) throws ApplicationExceptions, FrameworkException {
log.debug("Delete Bean " + path);
// Call custom validation code in the DAO
source.validate();
ApplicationExceptions aes = new ApplicationExceptions();
if (uow == null) {
String err = "UOW Required";
log.error(err);
throw new RuntimeException(err);
}
try {
IPersistent domainObject = null;
GraphMapping mapping = MappingFactory.getInstance(source);
Map keys = new LinkedHashMap();
Class doClass = mapping.getDomainClass();
// Get the key fields used in the domain object
boolean gotKeys = fillInKeys(path, source, mapping, keys);
// read DO based on key
if (gotKeys) {
// get the method on the DO to read via PK
Method[] ma = doClass.getMethods();
Method findByPK = null;
for (int i = 0; i < ma.length; i++) {
if (ma[i].getName().equals("findByPK")) {
if (ma[i].getParameterTypes().length == (keys.size() + 1) && (ma[i].getParameterTypes())[0] == UOW.class) {
// Found with name and correct no. of input params
findByPK = ma[i];
break;
}
}
}
if (findByPK == null) {
aes.add(new DomainObjectNotFoundException(doClass.getName()));
throw aes;
}
// Build input array
Object[] inputs = new Object[keys.size() + 1];
{
inputs[0] = uow;
int i = 1;
for (Iterator it = keys.values().iterator(); it.hasNext(); i++) {
inputs[i] = it.next();
}
}
// Find Object based on key
domainObject = (IPersistent) findByPK.invoke(null, inputs);
} else
log.debug("Object " + path + " has either missing or null key values - Assume Create is needed");
// Error if DO not found
if (domainObject == null) {
String label = doClass.getName();
// Try and use meta data to get domain objects label
try {
label = PersistentHelper.getLabelToken(doClass.getName());
} catch (Exception e) {
// ignore any problem trying to get the label!
}
aes.add(new DomainObjectNotFoundException(label + " (path=" + path + ")"));
throw aes;
}
// Process the delete, either on this DO, or a related DO if there is one
deleteBeanData(path, source, uow, handler, mapping, domainObject);
} catch (IllegalAccessException e) {
MouldException me = new MouldException(MouldException.ACCESS_ERROR, path, e.getMessage());
log.error(me.getLocalizedMessage(), e);
throw me;
} catch (InvocationTargetException e) {
if (e.getCause() != null) {
if (e.getCause() instanceof FrameworkException)
throw (FrameworkException) e.getCause();
if (e.getCause() instanceof ApplicationExceptions)
throw (ApplicationExceptions) e.getCause();
if (e.getCause() instanceof ApplicationException) {
aes.add((ApplicationException) e.getCause());
throw aes;
}
}
MouldException me = new MouldException(MouldException.INVOCATION_ERROR, path, e);
log.error(me.getLocalizedMessage(), me.getCause());
throw me;
} catch (InstantiationException e) {
MouldException me = new MouldException(MouldException.INSTANTICATION_ERROR, path, e.getMessage());
log.error(me.getLocalizedMessage(), e);
throw me;
}
// } catch (Exception e) {
// throw handleException(e,aes);
// }
}
use of org.jaffa.exceptions.FrameworkException in project jaffa-framework by jaffa-projects.
the class BeanMoulder method deleteChildBean.
/**
* Take a source object and try and mold it back it its domain object.
* This is the same as updateParent, except from the way it retrieved the
* record, and the way it creates a new record.
*/
private static void deleteChildBean(String path, DomainDAO source, UOW uow, MouldHandler handler, IPersistent parentDomain, GraphMapping parentMapping, String parentField) throws ApplicationExceptions, FrameworkException {
log.debug("Delete Child Bean " + path);
// Call custom validation code in the DAO
source.validate();
ApplicationExceptions aes = new ApplicationExceptions();
if (uow == null) {
String err = "UOW Required";
log.error(err);
throw new RuntimeException(err);
}
String relationshipName = parentMapping.getDomainFieldName(parentField);
if (relationshipName.endsWith("Array"))
relationshipName = relationshipName.substring(0, relationshipName.length() - 5);
if (relationshipName.endsWith("Object"))
relationshipName = relationshipName.substring(0, relationshipName.length() - 6);
try {
IPersistent domainObject = null;
GraphMapping mapping = MappingFactory.getInstance(source);
Map keys = new LinkedHashMap();
Class doClass = mapping.getDomainClass();
boolean gotKeys = false;
if (mapping.getKeyFields() == null || mapping.getKeyFields().size() == 0) {
// No keys, must be one-to-one
log.debug("Find 'one-to-one' object - " + path);
// Just use the getXxxObject method to get the related domain object,
// if there is one...
domainObject = (IPersistent) getProperty(parentMapping.getDomainFieldDescriptor(parentField), parentDomain);
if (domainObject == null)
log.debug("Not Found - " + path);
} else {
// Get the key fields used in the domain object. Use the findXxxxxCriteria() method,
// then add the extra fields to the criteria object, to get the unique record.
gotKeys = fillInKeys(path, source, mapping, keys);
// read DO based on key
if (gotKeys) {
// get the method to get the PK criteria (i.e. public Criteria findVendorSiteCriteria(); )
Method findCriteria = null;
String methodName = "find" + StringHelper.getUpper1(relationshipName) + "Criteria";
try {
findCriteria = parentDomain.getClass().getMethod(methodName, new Class[] {});
} catch (NoSuchMethodException e) {
log.error("Find method '" + methodName + "' not found!");
}
if (findCriteria == null)
throw new MouldException(MouldException.METHOD_NOT_FOUND, path, methodName);
// Find Criteria For Related Object
Criteria criteria = (Criteria) findCriteria.invoke(parentDomain, new Object[] {});
// Add extra key info...
for (Iterator it = keys.keySet().iterator(); it.hasNext(); ) {
String keyField = (String) it.next();
Object value = keys.get(keyField);
keyField = StringHelper.getUpper1(mapping.getDomainFieldName(keyField));
criteria.addCriteria(keyField, value);
log.debug(path + "- Add to criteria:" + keyField + "=" + value);
}
// See if we get an object :-)
Iterator itr = uow.query(criteria).iterator();
if (itr.hasNext())
domainObject = (IPersistent) itr.next();
if (itr.hasNext()) {
// Error, multiple objects found
MultipleDomainObjectsFoundException m = new MultipleDomainObjectsFoundException(criteria.getTable() + " @ " + path);
aes.add(m);
throw aes;
}
}
}
// Error if DO not found
if (domainObject == null) {
aes.add(new DomainObjectNotFoundException(doClass.getName() + " @ " + path));
throw aes;
}
// Process the delete, either on this DO, or a related DO if there is one
deleteBeanData(path, source, uow, handler, mapping, domainObject);
} catch (IllegalAccessException e) {
MouldException me = new MouldException(MouldException.ACCESS_ERROR, path, e.getMessage());
log.error(me.getLocalizedMessage(), e);
throw me;
} catch (InvocationTargetException e) {
if (e.getCause() != null) {
if (e.getCause() instanceof FrameworkException)
throw (FrameworkException) e.getCause();
if (e.getCause() instanceof ApplicationExceptions)
throw (ApplicationExceptions) e.getCause();
if (e.getCause() instanceof ApplicationException) {
aes.add((ApplicationException) e.getCause());
throw aes;
}
}
MouldException me = new MouldException(MouldException.INVOCATION_ERROR, path, e);
log.error(me.getLocalizedMessage(), me.getCause());
throw me;
} catch (InstantiationException e) {
MouldException me = new MouldException(MouldException.INSTANTICATION_ERROR, path, e.getMessage());
log.error(me.getLocalizedMessage(), e);
throw me;
}
}
use of org.jaffa.exceptions.FrameworkException in project jaffa-framework by jaffa-projects.
the class FinderAction method do_Search_Clicked.
/**
* Invokes the doValidate() method and then the displayResults() method on the component.
* @return The FormKey for the Results screen.
*/
public FormKey do_Search_Clicked() {
FormKey fk = null;
FinderForm myForm = (FinderForm) form;
FinderComponent2 myComp = (FinderComponent2) myForm.getComponent();
if (myForm.doValidate(request)) {
try {
myComp.performInquiry();
fk = myComp.getResultsFormKey(true);
if (FinderComponent2.EXPORT_TYPE_XML.equals(myComp.getExportType())) {
Object dto = myComp.getFinderOutDto();
if (dto == null)
dto = "";
else
dto = dto.toString();
request.setAttribute(FinderComponent2.ATTRIBUTE_EXPORT_TYPE_XML, dto);
} else
request.removeAttribute(FinderComponent2.ATTRIBUTE_EXPORT_TYPE_XML);
} catch (ApplicationExceptions e) {
if (log.isDebugEnabled())
log.debug("Search Failed");
myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, e);
} catch (FrameworkException e) {
log.error(null, e);
myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, "error.framework.general");
}
}
try {
if (fk == null)
fk = myComp.displayCriteria();
} catch (ApplicationExceptions e) {
if (log.isDebugEnabled())
log.debug("Search Failed");
myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, e);
} catch (FrameworkException e) {
log.error(null, e);
myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, "error.framework.general");
}
if (fk == null)
fk = myComp.getCriteriaFormKey();
return fk;
}
use of org.jaffa.exceptions.FrameworkException in project jaffa-framework by jaffa-projects.
the class FinderAction method do_SaveQuery_Clicked.
public FormKey do_SaveQuery_Clicked() {
FormKey fk = null;
FinderForm myForm = (FinderForm) form;
FinderComponent2 myComp = (FinderComponent2) myForm.getComponent();
if (myForm.doValidate(request) && myForm.doValidateForSaveQuery(request)) {
try {
myComp.saveQuery();
fk = myComp.displayCriteria();
} catch (ApplicationException e) {
if (log.isDebugEnabled())
log.debug("ModifySearch Failed");
myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, e);
} catch (ApplicationExceptions e) {
if (log.isDebugEnabled())
log.debug("ModifySearch Failed");
myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, e);
} catch (FrameworkException e) {
log.error(null, e);
myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, "error.framework.general");
}
}
// Direct User back to current form
if (fk == null)
fk = myComp.getCriteriaFormKey();
return fk;
}
Aggregations