Search in sources :

Example 21 with FormTemplate

use of org.jaffa.modules.printing.domain.FormTemplate in project jaffa-framework by jaffa-projects.

the class FormDefinitionMaintenanceTx method create.

// .//GEN-END:_prevalidateCreate_1_be
// .//GEN-BEGIN:_create_1_be
/**
 * Persists a new 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 FormDefinitionMaintenanceRetrieveOutDto create(FormDefinitionMaintenanceCreateInDto 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
        FormDefinition domain = createDomain(uow, input, false);
        uow.add(domain);
        domain = postCreate(uow, input, domain, false);
        FormTemplate formTemplate = createOrLoadFormTemplate(uow, input, domain, false);
        if (formTemplate != null && formTemplate.isModified()) {
            if (formTemplate.isDatabaseOccurence())
                uow.update(formTemplate);
            else
                uow.add(formTemplate);
        }
        // Commit the changes
        uow.commit();
        // Print Debug Information for the output
        if (log.isDebugEnabled())
            log.debug("Successfully created the domain object. Now retrieving the object details.");
        if (input.getFormId() == null) {
            if (log.isDebugEnabled())
                log.debug("The Key is not set completely. Probably using AutoGenerated keys. Cannot re-retrieve the object details. Returning NULL instead");
            return null;
        }
        // Build the outbound dto by performing a retrieve
        FormDefinitionMaintenanceRetrieveInDto retrieveInDto = new FormDefinitionMaintenanceRetrieveInDto();
        retrieveInDto.setHeaderDto(input.getHeaderDto());
        retrieveInDto.setFormId(input.getFormId());
        FormDefinitionMaintenanceRetrieveOutDto 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();
    }
}
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 22 with FormTemplate

use of org.jaffa.modules.printing.domain.FormTemplate in project jaffa-framework by jaffa-projects.

the class FormDefinitionMaintenanceTx method createOrLoadFormTemplate.

// .//GEN-END:_domainObjectChangedTest_1_be
// .//GEN-BEGIN:_createOrLoadFormTemplate_1_be
/**
 * Create Or Load an existing instance of FormTemplate which has a 1-to-1 relationship with the domain object.
 */
private FormTemplate createOrLoadFormTemplate(UOW uow, FormDefinitionMaintenanceCreateInDto input, FormDefinition domain, boolean fromPrevalidate) throws FrameworkException, ApplicationExceptions {
    FormTemplate formTemplate = null;
    ApplicationExceptions appExps = null;
    // .//GEN-BEGIN:_createOrLoadFormTemplate_2_be
    if (domain.getFormId() != null) {
        // load an existing instance
        Criteria criteria = new Criteria();
        criteria.setTable(FormTemplateMeta.getName());
        criteria.addCriteria(FormTemplateMeta.FORM_ID, domain.getFormId());
        // .//GEN-END:_createOrLoadFormTemplate_2_be
        // Add custom code//GEN-FIRST:_createOrLoadFormTemplate_2
        // .//GEN-LAST:_createOrLoadFormTemplate_2
        // .//GEN-BEGIN:_createOrLoadFormTemplate_3_be
        Iterator itrOne = uow.query(criteria).iterator();
        if (itrOne.hasNext())
            formTemplate = (FormTemplate) itrOne.next();
    }
    // create if it doesn't already exist
    if (formTemplate == null)
        formTemplate = new FormTemplate();
    // Update the template if a file has been uploaded
    if (input.getFormTemplate() != null) {
        try {
            formTemplate.setTemplateData(input.getTemplateData());
        } catch (ValidationException e) {
            throw new ApplicationExceptions(new ApplicationException("exception.Jaffa.Printing.FormDefinitionMaintenance.UploadTemplateData") {
            });
        }
    }
    if (input.getFieldLayout() != null) {
        try {
            formTemplate.setLayoutData(input.getLayoutData());
        } catch (ValidationException e) {
            throw new ApplicationExceptions(new ApplicationException("exception.Jaffa.Printing.FormDefinitionMaintenance.UploadLayOutData") {
            });
        }
    }
    if (!formTemplate.isDatabaseOccurence() && formTemplate.isModified()) {
        // Finally set the join-fields
        try {
            formTemplate.updateFormId(domain.getFormId());
        } catch (ValidationException e) {
            if (appExps == null)
                appExps = new ApplicationExceptions();
            appExps.add(e);
        }
    }
    // .//GEN-BEGIN:_createOrLoadFormTemplate_5_be
    if (appExps != null && appExps.size() > 0)
        throw appExps;
    return formTemplate;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ValidationException(org.jaffa.datatypes.ValidationException) ApplicationException(org.jaffa.exceptions.ApplicationException) FormTemplate(org.jaffa.modules.printing.domain.FormTemplate) Criteria(org.jaffa.persistence.Criteria)

Example 23 with FormTemplate

use of org.jaffa.modules.printing.domain.FormTemplate in project jaffa-framework by jaffa-projects.

the class FormDefinitionMaintenanceTx 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 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 prevalidateCreate(FormDefinitionMaintenanceCreateInDto 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
        FormDefinition domain = createDomain(uow, input, true);
        domain = postCreate(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)

Aggregations

FormTemplate (org.jaffa.modules.printing.domain.FormTemplate)23 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)15 ApplicationException (org.jaffa.exceptions.ApplicationException)11 UOW (org.jaffa.persistence.UOW)10 FrameworkException (org.jaffa.exceptions.FrameworkException)9 Criteria (org.jaffa.persistence.Criteria)7 FormDefinition (org.jaffa.modules.printing.domain.FormDefinition)4 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)3 ValidationException (org.jaffa.datatypes.ValidationException)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 TransformerException (javax.xml.transform.TransformerException)1 FormTemplateFinderOutDto (org.jaffa.modules.printing.components.formtemplatefinder.dto.FormTemplateFinderOutDto)1 FormTemplateFinderOutRowDto (org.jaffa.modules.printing.components.formtemplatefinder.dto.FormTemplateFinderOutRowDto)1 FormTemplateLookupOutDto (org.jaffa.modules.printing.components.formtemplatelookup.dto.FormTemplateLookupOutDto)1 FormTemplateLookupOutRowDto (org.jaffa.modules.printing.components.formtemplatelookup.dto.FormTemplateLookupOutRowDto)1 FormTemplateViewerOutDto (org.jaffa.modules.printing.components.formtemplateviewer.dto.FormTemplateViewerOutDto)1 EngineProcessingException (org.jaffa.modules.printing.services.exceptions.EngineProcessingException)1