Search in sources :

Example 26 with ApplicationException

use of org.jaffa.exceptions.ApplicationException in project jaffa-framework by jaffa-projects.

the class UserMaintenanceTx method prevalidateCreate.

// .//GEN-END:_destroy_2_be
// .//GEN-BEGIN:_prevalidateCreate_1_be
/**
 * This method is used to perform prevalidations before creating a new instance of User.
 * @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 UserMaintenancePrevalidateOutDto prevalidateCreate(UserMaintenanceCreateInDto input) throws FrameworkException, ApplicationExceptions {
    UOW uow = null;
    try {
        // Print Debug Information for the input
        if (log.isDebugEnabled())
            log.debug("Input: " + (input != null ? input.toString() : null));
        // create the UOW
        uow = new UOW();
        // Preprocess the input
        preprocess(uow, input);
        // Do not allow a Duplicate record
        duplicateCheck(uow, input);
        // Validate the foreign objects
        validateForeignObjects(uow, input);
        // Create the domain object
        User domain = createDomain(uow, input, true);
        domain = postCreate(uow, input, domain, true);
        // Build the outbound dto
        UserMaintenancePrevalidateOutDto output = createPrevalidateOutDto(uow, domain, input);
        // Print Debug Information for the output
        if (log.isDebugEnabled())
            log.debug("Output: " + (output != null ? output.toString() : null));
        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();
    }
}
Also used : User(org.jaffa.applications.jaffa.modules.admin.domain.User) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ApplicationException(org.jaffa.exceptions.ApplicationException) FrameworkException(org.jaffa.exceptions.FrameworkException) UOW(org.jaffa.persistence.UOW)

Example 27 with ApplicationException

use of org.jaffa.exceptions.ApplicationException in project jaffa-framework by jaffa-projects.

the class UserMaintenanceTx method prevalidateUpdate.

// .//GEN-END:_retrieve_1_be
// .//GEN-BEGIN:_prevalidateUpdate_1_be
/**
 * This method is used to perform prevalidations before updating an existing instance of User.
 * @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 UserMaintenancePrevalidateOutDto prevalidateUpdate(UserMaintenanceUpdateInDto input) throws FrameworkException, ApplicationExceptions {
    UOW uow = null;
    try {
        // Print Debug Information for the input
        if (log.isDebugEnabled())
            log.debug("Input: " + (input != null ? input.toString() : null));
        // create the UOW
        uow = new UOW();
        // Preprocess the input
        preprocess(uow, input);
        // Retrieve the object
        User domain = load(uow, input);
        // Ensure the domain object has not been modified
        domainObjectChangedTest(input.getPerformDirtyReadCheck(), domain, input.getLastUpdatedOn());
        // Validate the foreign objects
        validateForeignObjects(uow, input);
        // Update the domain object
        updateDomain(uow, input, domain, true);
        // Build the outbound dto
        UserMaintenancePrevalidateOutDto output = createPrevalidateOutDto(uow, domain, input);
        // Print Debug Information for the output
        if (log.isDebugEnabled())
            log.debug("Output: " + (output != null ? output.toString() : null));
        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();
    }
}
Also used : User(org.jaffa.applications.jaffa.modules.admin.domain.User) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ApplicationException(org.jaffa.exceptions.ApplicationException) FrameworkException(org.jaffa.exceptions.FrameworkException) UOW(org.jaffa.persistence.UOW)

Example 28 with ApplicationException

use of org.jaffa.exceptions.ApplicationException in project jaffa-framework by jaffa-projects.

the class UserMaintenanceTx method delete.

// .//GEN-END:_update_1_be
// .//GEN-BEGIN:_delete_1_be
/**
 * Deletes an existing instance of User.
 * @param input The key values for the domain object to be deleted.
 * @throws ApplicationExceptions This will be thrown if the input contains invalid data.
 * @throws FrameworkException Indicates some system error.
 */
public void delete(UserMaintenanceDeleteInDto input) throws FrameworkException, ApplicationExceptions {
    UOW uow = null;
    try {
        // create the UOW
        uow = new UOW();
        // invoke the delete passing the UOW
        delete(input, uow);
        // Commit the changes
        uow.commit();
        // Print Debug Information for the output
        if (log.isDebugEnabled())
            log.debug("Successfully deleted the domain object");
    } 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();
    }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ApplicationException(org.jaffa.exceptions.ApplicationException) FrameworkException(org.jaffa.exceptions.FrameworkException) UOW(org.jaffa.persistence.UOW)

Example 29 with ApplicationException

use of org.jaffa.exceptions.ApplicationException 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());
                }
            }
        }
    }
}
Also used : Locale(java.util.Locale) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ValidationException(org.jaffa.datatypes.ValidationException) ApplicationException(org.jaffa.exceptions.ApplicationException) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException) File(java.io.File)

Example 30 with ApplicationException

use of org.jaffa.exceptions.ApplicationException in project jaffa-framework by jaffa-projects.

the class UserRequestMaintenanceTx method prevalidateCreate.

// .//GEN-END:_destroy_2_be
// .//GEN-BEGIN:_prevalidateCreate_1_be
/**
 * This method is used to perform prevalidations before creating a new instance of UserRequest.
 * @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 UserRequestMaintenancePrevalidateOutDto prevalidateCreate(UserRequestMaintenanceCreateInDto input) throws FrameworkException, ApplicationExceptions {
    UOW uow = null;
    try {
        // Print Debug Information for the input
        if (log.isDebugEnabled())
            log.debug("Input: " + (input != null ? input.toString() : null));
        // create the UOW
        uow = new UOW();
        // Preprocess the input
        preprocess(uow, input);
        // Do not allow a Duplicate record
        duplicateCheck(uow, input);
        // Validate the foreign objects
        validateForeignObjects(uow, input);
        // Create the domain object
        UserRequest domain = createDomain(uow, input, true);
        // Perform post create processing
        postCreate(uow, input, domain, true);
        // Build the outbound dto
        UserRequestMaintenancePrevalidateOutDto output = createPrevalidateOutDto(uow, domain, input);
        // Print Debug Information for the output
        if (log.isDebugEnabled())
            log.debug("Output: " + (output != null ? output.toString() : null));
        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();
    }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ApplicationException(org.jaffa.exceptions.ApplicationException) FrameworkException(org.jaffa.exceptions.FrameworkException) UOW(org.jaffa.persistence.UOW) UserRequest(org.jaffa.applications.jaffa.modules.user.domain.UserRequest)

Aggregations

ApplicationException (org.jaffa.exceptions.ApplicationException)125 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)114 FrameworkException (org.jaffa.exceptions.FrameworkException)97 UOW (org.jaffa.persistence.UOW)79 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 Iterator (java.util.Iterator)11 FormTemplate (org.jaffa.modules.printing.domain.FormTemplate)11 Criteria (org.jaffa.persistence.Criteria)11 Method (java.lang.reflect.Method)10 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 GraphMapping (org.jaffa.beans.moulding.mapping.GraphMapping)6 OutputCommand (org.jaffa.modules.printing.domain.OutputCommand)6 PrinterDefinition (org.jaffa.modules.printing.domain.PrinterDefinition)6 PrinterOutputType (org.jaffa.modules.printing.domain.PrinterOutputType)6 User (org.jaffa.applications.jaffa.modules.admin.domain.User)5 UserRequest (org.jaffa.applications.jaffa.modules.user.domain.UserRequest)5 UserTimeEntry (org.jaffa.applications.test.modules.time.domain.UserTimeEntry)5 Attachment (org.jaffa.components.attachment.domain.Attachment)5