Search in sources :

Example 61 with ApplicationExceptions

use of org.jaffa.exceptions.ApplicationExceptions 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;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ValidationException(org.jaffa.datatypes.ValidationException) DateTime(org.jaffa.datatypes.DateTime)

Example 62 with ApplicationExceptions

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

the class FormDefinitionMaintenanceTx method load.

// .//GEN-END:_preprocessDelete_2_be
// .//GEN-BEGIN:_loadDelete_1_be
/**
 * Retrieve the domain object.
 */
private FormDefinition load(UOW uow, FormDefinitionMaintenanceDeleteInDto input) throws FrameworkException, ApplicationExceptions {
    FormDefinition domain = null;
    Criteria criteria = new Criteria();
    criteria.setTable(FormDefinitionMeta.getName());
    // .//GEN-END:_loadDelete_1_be
    // Add custom criteria//GEN-FIRST:_loadDelete_1
    // .//GEN-LAST:_loadDelete_1
    // .//GEN-BEGIN:_loadDelete_2_be
    criteria.addCriteria(FormDefinitionMeta.FORM_ID, input.getFormId());
    criteria.setLocking(Criteria.LOCKING_PARANOID);
    Iterator itr = uow.query(criteria).iterator();
    if (itr.hasNext())
        domain = (FormDefinition) itr.next();
    // .//GEN-BEGIN:_loadDelete_3_be
    if (domain == null) {
        ApplicationExceptions appExps = new ApplicationExceptions();
        appExps.add(new DomainObjectNotFoundException(FormDefinitionMeta.getLabelToken()));
        throw appExps;
    }
    return domain;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException) Criteria(org.jaffa.persistence.Criteria) FormDefinition(org.jaffa.modules.printing.domain.FormDefinition)

Example 63 with ApplicationExceptions

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

the class FormDefinitionMaintenanceTx method preprocess.

// .//GEN-END:_buildRetrieveOutDto_3_be
// .//GEN-BEGIN:_preprocessUpdate_1_be
/**
 * Preprocess the input for the update method.
 */
private void preprocess(UOW uow, FormDefinitionMaintenanceUpdateInDto input) throws FrameworkException, ApplicationExceptions {
    if (input.getFollowOnFormName() != null) {
        Criteria criteria = new Criteria();
        criteria.setTable(FormGroupMeta.getName());
        criteria.addCriteria(FormGroupMeta.FORM_NAME, input.getFollowOnFormName());
        Iterator it = uow.query(criteria).iterator();
        if (!it.hasNext())
            throw new ApplicationExceptions(new ApplicationException("exception.Jaffa.Printing.FormDefinitionMaintenance.ValidFollowOnForm") {
            });
    }
// .//GEN-LAST:_preprocessUpdate_1
// .//GEN-BEGIN:_preprocessUpdate_2_be
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ApplicationException(org.jaffa.exceptions.ApplicationException) Criteria(org.jaffa.persistence.Criteria)

Example 64 with ApplicationExceptions

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

the class FormDefinitionMaintenanceTx 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 FormDefinition.
 * @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 FormDefinitionMaintenancePrevalidateOutDto prevalidateUpdate(FormDefinitionMaintenanceUpdateInDto 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
        FormDefinition 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, true);
        FormTemplate formTemplate = createOrLoadFormTemplate(uow, input, domain, true);
        // Build the outbound dto
        FormDefinitionMaintenancePrevalidateOutDto 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) FormTemplate(org.jaffa.modules.printing.domain.FormTemplate) UOW(org.jaffa.persistence.UOW) FormDefinition(org.jaffa.modules.printing.domain.FormDefinition)

Example 65 with ApplicationExceptions

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

the class FormDefinitionMaintenanceTx method domainObjectChangedTest.

// .//GEN-END:_deleteRelatedObjects_2_be
// .//GEN-BEGIN:_domainObjectChangedTest_1_be
/**
 * Ensure the domain object has not been modified.
 */
private void domainObjectChangedTest(Boolean performDirtyReadCheck, FormDefinition domain, org.jaffa.datatypes.DateTime lastChangedOn) throws FrameworkException, ApplicationExceptions {
    if (performDirtyReadCheck != null && performDirtyReadCheck.booleanValue()) {
        if (lastChangedOn == null ? domain.getLastChangedOn() != null : !lastChangedOn.equals(domain.getLastChangedOn())) {
            DomainObjectChangedException e = new DomainObjectChangedException(domain.getLastChangedBy(), Formatter.format(domain.getLastChangedOn()));
            ApplicationExceptions aes = new ApplicationExceptions();
            aes.add(e);
            throw aes;
        }
    }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) DomainObjectChangedException(org.jaffa.exceptions.DomainObjectChangedException)

Aggregations

ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)575 FrameworkException (org.jaffa.exceptions.FrameworkException)307 FormKey (org.jaffa.presentation.portlet.FormKey)205 ApplicationException (org.jaffa.exceptions.ApplicationException)116 GridModel (org.jaffa.presentation.portlet.widgets.model.GridModel)104 GridModelRow (org.jaffa.presentation.portlet.widgets.model.GridModelRow)103 UOW (org.jaffa.persistence.UOW)82 Criteria (org.jaffa.persistence.Criteria)66 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)59 MandatoryFieldException (org.jaffa.datatypes.exceptions.MandatoryFieldException)23 ValidationException (org.jaffa.datatypes.ValidationException)21 Iterator (java.util.Iterator)16 InvocationTargetException (java.lang.reflect.InvocationTargetException)15 Method (java.lang.reflect.Method)15 FormTemplate (org.jaffa.modules.printing.domain.FormTemplate)15 DuplicateKeyException (org.jaffa.exceptions.DuplicateKeyException)14 OutputCommand (org.jaffa.modules.printing.domain.OutputCommand)11 MalformedURLException (java.net.MalformedURLException)10 UserRequest (org.jaffa.applications.jaffa.modules.user.domain.UserRequest)10 PrinterDefinition (org.jaffa.modules.printing.domain.PrinterDefinition)10