use of org.jaffa.exceptions.DomainObjectNotFoundException in project jaffa-framework by jaffa-projects.
the class UserTimeEntryViewerComponent method doInquiry.
// .//GEN-END:_display_2_be
// .//GEN-BEGIN:_inquiry_1_be
private void doInquiry() throws ApplicationExceptions, FrameworkException {
UserTimeEntryViewerInDto inputDto = new UserTimeEntryViewerInDto();
// .//GEN-END:_inquiry_1_be
// Add custom code before building the input dto //GEN-FIRST:_inquiry_1
// .//GEN-LAST:_inquiry_1
// .//GEN-BEGIN:_inquiry_2_be
inputDto.setUserName(m_userName);
inputDto.setProjectCode(m_projectCode);
inputDto.setTask(m_task);
inputDto.setPeriodStart(m_periodStart);
inputDto.setPeriodEnd(m_periodEnd);
inputDto.setHeaderDto(createHeaderDto());
// create the Tx
if (m_tx == null)
m_tx = (IUserTimeEntryViewer) Factory.createObject(IUserTimeEntryViewer.class);
// .//GEN-END:_inquiry_2_be
// Add custom code before invoking the Tx //GEN-FIRST:_inquiry_2
// .//GEN-LAST:_inquiry_2
// .//GEN-BEGIN:_inquiry_3_be
// now get the details
m_outputDto = m_tx.read(inputDto);
// uncache the widgets
getUserSession().getWidgetCache(getComponentId()).clear();
// throw an exception if the output is null
if (m_outputDto == null) {
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add(new DomainObjectNotFoundException(UserTimeEntryMeta.getLabelToken()));
throw appExps;
}
}
use of org.jaffa.exceptions.DomainObjectNotFoundException in project jaffa-framework by jaffa-projects.
the class BeanMoulder method updateBean.
/**
* Take a source object and try and mold it back it its domain object
* @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 updateBean(String path, DomainDAO source, UOW uow, MouldHandler handler) throws ApplicationExceptions, FrameworkException {
log.debug("Update 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() + " @ " + path));
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");
// Create object if not found
if (domainObject == null) {
// NEW OBJECT, create and reflect keys
log.debug("DO '" + mapping.getDomainClassShortName() + "' not found with key, create a new one...");
domainObject = (IPersistent) doClass.newInstance();
// set the key fields
for (Iterator it = keys.keySet().iterator(); it.hasNext(); ) {
String keyField = (String) it.next();
Object value = keys.get(keyField);
updateProperty(mapping.getDomainFieldDescriptor(keyField), value, domainObject);
}
} else {
log.debug("Found DO '" + mapping.getDomainClassShortName() + "' with key,");
}
// Now update all domain fields
updateBeanData(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.DomainObjectNotFoundException in project jaffa-framework by jaffa-projects.
the class UserTimeEntryMaintenanceTx method load.
// .//GEN-END:_preprocessDelete_2_be
// .//GEN-BEGIN:_loadDelete_1_be
/**
* Retrieve the domain object.
*/
private UserTimeEntry load(UOW uow, UserTimeEntryMaintenanceDeleteInDto input) throws FrameworkException, ApplicationExceptions {
UserTimeEntry domain = null;
Criteria criteria = new Criteria();
criteria.setTable(UserTimeEntryMeta.getName());
// .//GEN-END:_loadDelete_1_be
// Add custom criteria //GEN-FIRST:_loadDelete_1
// .//GEN-LAST:_loadDelete_1
// .//GEN-BEGIN:_loadDelete_2_be
criteria.addCriteria(UserTimeEntryMeta.USER_NAME, input.getUserName());
criteria.addCriteria(UserTimeEntryMeta.PROJECT_CODE, input.getProjectCode());
criteria.addCriteria(UserTimeEntryMeta.TASK, input.getTask());
criteria.addCriteria(UserTimeEntryMeta.PERIOD_START, input.getPeriodStart());
criteria.addCriteria(UserTimeEntryMeta.PERIOD_END, input.getPeriodEnd());
criteria.setLocking(Criteria.LOCKING_PARANOID);
Iterator itr = uow.query(criteria).iterator();
if (itr.hasNext())
domain = (UserTimeEntry) itr.next();
// .//GEN-BEGIN:_loadDelete_3_be
if (domain == null) {
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add(new DomainObjectNotFoundException(UserTimeEntryMeta.getLabelToken()));
throw appExps;
}
return domain;
}
use of org.jaffa.exceptions.DomainObjectNotFoundException in project jaffa-framework by jaffa-projects.
the class UserViewerComponent method doInquiry.
// .//GEN-END:_display_2_be
// .//GEN-BEGIN:_inquiry_1_be
private void doInquiry() throws ApplicationExceptions, FrameworkException {
UserViewerInDto inputDto = new UserViewerInDto();
// .//GEN-END:_inquiry_1_be
// Add custom code before building the input dto //GEN-FIRST:_inquiry_1
// .//GEN-LAST:_inquiry_1
// .//GEN-BEGIN:_inquiry_2_be
inputDto.setUserName(m_userName);
inputDto.setHeaderDto(createHeaderDto());
// create the Tx
if (m_tx == null)
m_tx = (IUserViewer) Factory.createObject(IUserViewer.class);
// .//GEN-END:_inquiry_2_be
// Add custom code before invoking the Tx //GEN-FIRST:_inquiry_2
// .//GEN-LAST:_inquiry_2
// .//GEN-BEGIN:_inquiry_3_be
// now get the details
m_outputDto = m_tx.read(inputDto);
// uncache the widgets
getUserSession().getWidgetCache(getComponentId()).clear();
// Add custom code after invoking the Tx //GEN-FIRST:_inquiry_3
if (m_outputDto != null && m_outputDto.getStatus() != null) {
m_outputDto.setStatusDescription("[label.Jaffa.Admin.User.Status." + m_outputDto.getStatus() + ']');
}
// throw an exception if the output is null
if (m_outputDto == null) {
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add(new DomainObjectNotFoundException(UserMeta.getLabelToken()));
throw appExps;
}
}
use of org.jaffa.exceptions.DomainObjectNotFoundException in project jaffa-framework by jaffa-projects.
the class FormProcessor method process.
/**
* Process the FormPrintRequest. This will look at the form definition to use, locate it, build the
* databean to use, and generate the output form. If follow-on forms are needed these will be generated
* and merged in. It will then either print or email the generate form.<p>
* Modified so 'null' DocumentObject will not create blank pages. If no pages are added, nothing will be delivered
*
* @param request the object that contains the key to the data, the form to be printed and
* details about the printer and/or email that should be used for the output
* @throws org.jaffa.exceptions.FrameworkException thrown if there is an infrastructure error
* @throws org.jaffa.exceptions.ApplicationExceptions throw if there is an application error that should be repoted to the user
*/
public static void process(FormPrintRequest request) throws FrameworkException, ApplicationExceptions {
if (log.isDebugEnabled()) {
log.debug("Begin processing form print request. Form name = " + request.getFormName() + ", Form Alternate = " + request.getFormAlternateName() + ", Form Variation = " + request.getVariation() + ", Printer Id = " + request.getPrinterId() + ", Email Address = " + request.getEmailToAddresses() + ", User = " + request.getUserName() + ", Copies = " + request.getPrintCopies());
}
Map<IDataBean, DocumentPrintedListener> printedListeners = new HashMap<IDataBean, DocumentPrintedListener>();
File outFile = null;
UOW uow = new UOW();
FormCache cache = new FormCache();
MultiFormPrintEngine engine = null;
// Get Locale Country
Locale localeObject = LocaleContext.getLocale();
String country = localeObject != null ? localeObject.getCountry() : null;
String formOutputType = null;
try {
// Lookup the printer, to get the output type
PrinterDefinition printer = null;
String outputType = null;
if (request.getPrinterId() != null) {
printer = PrinterDefinition.findByPK(uow, request.getPrinterId());
if (printer == null) {
log.error("Invalid printer id on form request: Printer = " + request.getPrinterId());
throw new ApplicationExceptions(new DomainObjectNotFoundException(PrinterDefinitionMeta.getLabelToken()));
}
outputType = printer.getOutputType();
}
String formName = request.getFormName();
String alternateName = request.getFormAlternateName();
String variation = request.getVariation();
String[] keyNames = null;
if (request.getKeys() != null) {
keyNames = (String[]) request.getKeys().keySet().toArray(new String[] {});
}
Object firstDom = null;
int documentCounter = 0;
// Main assemble loop if this has follow-on forms
while (formName != null) {
FormDefinition formDefinition = findFormDefinition(uow, formName, alternateName, variation, outputType, keyNames);
if (formDefinition == null) {
if (outputType == null) {
log.error("Form Not Found. Name=" + request.getFormName() + ", Alt=" + request.getFormAlternateName() + ", Variation=" + request.getVariation() + ", OutputType=" + outputType);
throw new ApplicationExceptions(new DomainObjectNotFoundException(FormDefinitionMeta.getLabelToken()));
} else {
outputType = null;
formDefinition = findFormDefinition(uow, formName, alternateName, variation, outputType, keyNames);
if (formDefinition == null) {
log.error("Form Not Found. Name=" + request.getFormName() + ", Alt=" + request.getFormAlternateName() + ", Variation=" + request.getVariation() + ", OutputType=" + outputType);
throw new ApplicationExceptions(new DomainObjectNotFoundException(FormDefinitionMeta.getLabelToken()));
} else {
throw new ApplicationExceptions(new ApplicationException("exception.org.jaffa.modules.printing.services.FormProcessor.OutputTypeMismatch") {
});
}
}
}
formOutputType = formDefinition.getOutputType();
// See if we have the DOM for this form already, if not build it
IDataBean data = cache.lookupForm(formDefinition);
if (data == null) {
// build the form DOM
data = buildDataBean(request, formDefinition);
cache.addForm(formDefinition, data);
// the FormPrintRequest or as a FollowOnFormAlternate.
if (alternateName == null) {
if (data.getFormAlternateName() != null) {
log.debug("Form " + formName + " switch to alternateName " + data.getFormAlternateName() + " from " + alternateName);
alternateName = data.getFormAlternateName();
continue;
}
}
}
// Add this form for printing
if (engine == null) {
// set up the engine
engine = new MultiFormPrintEngine();
// get the form type so the correct factory can be set...
try {
engine.setEngineType(formDefinition.getFormGroupObject().getFormType());
} catch (ValidationException e) {
// This should only happen if the FormGroup object is not found
throw new ApplicationExceptions(e);
}
}
String templateName = cache.getTemplate(formDefinition, engine.getEngineType());
// If data.getDocumentRoot() is an object array, add a document for each entry in the array.
if (data.getDocumentRoot() != null && data.getDocumentRoot().getClass().isArray()) {
Object[] doms = (Object[]) data.getDocumentRoot();
for (int i = 0; i < doms.length; i++) {
if (firstDom == null) {
firstDom = doms[i];
}
// Only add document if it has data
if (doms[i] != null) {
documentCounter++;
engine.addDocument(templateName, doms[i]);
}
}
if ("<CREATE XML FILE>".equals(formDefinition.getRemarks())) {
writeXsdAndXml(doms[0]);
}
} else {
if (firstDom == null) {
firstDom = data.getDocumentRoot();
}
// Only add document if it has data
if (data.getDocumentRoot() != null) {
documentCounter++;
engine.addDocument(templateName, data.getDocumentRoot());
}
if ("<CREATE XML FILE>".equals(formDefinition.getRemarks())) {
writeXsdAndXml(data.getDocumentRoot());
}
}
// Get the DocumentPrintedListerers for this DataBean, if they have not already be aquired
if (!printedListeners.containsKey(data)) {
printedListeners.put(data, data.getDocumentPrintedListener());
}
// Get the follow-on form so it will be process in the next iteration
formName = formDefinition.getFollowOnFormName();
alternateName = formDefinition.getFollowOnFormAlternate();
}
if (documentCounter == 0) {
log.debug("No pages added to engine, dataBeans were null. No output will be generated");
} else {
// Set override page size for PDF forms
if ("PDF".equals(formOutputType)) {
String pageSize = printer != null && printer.getScaleToPageSize() != null ? printer.getScaleToPageSize() : null;
if (pageSize == null) {
pageSize = (String) ContextManagerFactory.instance().getProperty("jaffa.printing.defaultScaleToPageSize" + "." + country);
}
if (pageSize != null && !"".equals(pageSize)) {
engine.setPageSize(pageSize);
}
}
// Generate the output
engine.generate();
// Get the generated output
if (request.getSaveFileName() != null) {
outFile = engine.writeForm(new File(request.getSaveFileName()));
} else {
outFile = engine.writeForm();
}
if (log.isDebugEnabled()) {
log.debug("Created file : " + (outFile == null ? "NULL!!" : outFile.getAbsolutePath()));
}
// Send file to printer and email if required
FormDelivery.deliver(request, outFile, firstDom);
if (log.isDebugEnabled()) {
log.debug("Returned from delivering the form. Print File: " + (outFile == null ? "NULL" : outFile.getAbsolutePath()));
}
// Invoke all the DocumentPrintedListerer
for (DocumentPrintedListener listener : printedListeners.values()) {
if (listener != null) {
listener.documentPrinted(new EventObject(request));
}
}
if (log.isDebugEnabled()) {
log.debug("Returned from setting form printed date. Print File: " + (outFile == null ? "NULL" : outFile.getAbsolutePath()));
}
}
} finally {
if (uow != null) {
// This UOW should have not been used for updates!!!
uow.rollback();
}
// Clean up the temporary file unless it has been written specifically for web publishing
if (outFile != null) {
if (log.isDebugEnabled()) {
log.debug("FILE NOT CLEANED UP IN DEBUG MODE: " + outFile.getAbsolutePath());
} else if (request.getSaveFileName() == null) {
if (!outFile.delete()) {
log.error("Failed to delete the temporary form file " + outFile.getAbsolutePath());
}
}
}
}
}
Aggregations