Search in sources :

Example 16 with UOW

use of org.jaffa.persistence.UOW 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 17 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class FormDefinitionViewerTx method loadFormTemplate.

public byte[] loadFormTemplate(FormDefinitionViewerInDto input) throws FrameworkException, ApplicationExceptions {
    UOW uow = new UOW();
    try {
        Criteria criteria = new Criteria();
        criteria.setTable(FormTemplateMeta.getName());
        criteria.addCriteria(FormTemplateMeta.FORM_ID, input.getFormId());
        Iterator itr = uow.query(criteria).iterator();
        if (itr.hasNext()) {
            FormTemplate formTemplate = (FormTemplate) itr.next();
            formTemplateContents = formTemplate.getTemplateData();
        }
    } finally {
        if (uow != null)
            uow.rollback();
    }
    return formTemplateContents;
}
Also used : FormTemplate(org.jaffa.modules.printing.domain.FormTemplate) Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW)

Example 18 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class BusinessEventLogViewerTx method read.

// .//GEN-END:_destroy_2_be
// .//GEN-BEGIN:_read_1_be
/**
 * Returns the details for BusinessEventLog.
 * @param input The criteria based on which an object will be retrieved.
 * @throws ApplicationExceptions This will be thrown if the criteria contains invalid data.
 * @throws FrameworkException Indicates some system error.
 * @return The object details. A null indicates, the object was not found.
 */
public BusinessEventLogViewerOutDto read(BusinessEventLogViewerInDto 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();
        // Build the Criteria Object
        Criteria criteria = buildCriteria(input, uow);
        // .//GEN-END:_read_1_be
        // Add custom code before the query//GEN-FIRST:_read_1
        // .//GEN-LAST:_read_1
        // .//GEN-BEGIN:_read_2_be
        // Execute The Query
        Collection results = uow.query(criteria);
        // .//GEN-END:_read_2_be
        // Add custom code after the query//GEN-FIRST:_read_2
        // .//GEN-LAST:_read_2
        // .//GEN-BEGIN:_read_3_be
        // Convert the domain objects into the outbound dto
        BusinessEventLogViewerOutDto output = buildDto(uow, results);
        // Print Debug Information for the output
        if (log.isDebugEnabled()) {
            log.debug("Output: " + (output != null ? output.toString() : null));
        }
        return output;
    } finally {
        if (uow != null)
            uow.rollback();
    }
}
Also used : BusinessEventLogViewerOutDto(org.jaffa.modules.messaging.components.businesseventlogviewer.dto.BusinessEventLogViewerOutDto) Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW)

Example 19 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class RulesEngine method doValidationsForDomainField.

/**
 * Invokes the doFieldValidaions for the field.
 */
private static void doValidationsForDomainField(String domainClassName, String fieldName, Object fieldValue, UOW uow, boolean doOnlyMandatory) throws ValidationException, FrameworkException {
    String variation = VariationContext.getVariation();
    // determine the ClassMetaData
    ClassMetaData classMetaData = getClassMetaData(domainClassName, variation);
    // determine the core ClassMetaData, if required
    ClassMetaData coreClassMetaData = VariationContext.DEFAULT_VARIATION.equals(variation) ? null : getClassMetaData(domainClassName, VariationContext.DEFAULT_VARIATION);
    boolean localUow = false;
    try {
        String labelToken = null;
        // perform validations for the field
        if (classMetaData != null) {
            FieldMetaData fieldMetaData = classMetaData.getField(fieldName);
            if (fieldMetaData != null) {
                // create a UOW, if not passed in
                if (uow == null) {
                    uow = new UOW();
                    localUow = true;
                }
                FieldMetaData coreFieldMetaData = coreClassMetaData != null ? coreClassMetaData.getField(fieldName) : null;
                labelToken = getLabelToken(domainClassName, fieldMetaData.getName());
                doFieldValidaions(fieldValue, uow, doOnlyMandatory, labelToken, fieldMetaData, coreFieldMetaData);
            }
        }
        // perform validations for the field in the core file, if not defined in the variant file
        if (coreClassMetaData != null) {
            if (classMetaData == null || classMetaData.getField(fieldName) == null) {
                FieldMetaData fieldMetaData = coreClassMetaData.getField(fieldName);
                if (fieldMetaData != null) {
                    // create a UOW, if not passed in
                    if (uow == null) {
                        uow = new UOW();
                        localUow = true;
                    }
                    if (labelToken == null)
                        labelToken = getLabelToken(domainClassName, fieldMetaData.getName());
                    doFieldValidaions(fieldValue, uow, doOnlyMandatory, labelToken, fieldMetaData, null);
                }
            }
        }
    } finally {
        if (localUow && uow != null)
            uow.rollback();
    }
}
Also used : UOW(org.jaffa.persistence.UOW)

Example 20 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class RulesEngine method doValidationsForDomainObject.

/**
 * Invokes the doFieldValidaions for each field of the ClassMetaData object for the domainObject.
 */
private static void doValidationsForDomainObject(Object domainObject, UOW uow, boolean doOnlyMandatory) throws ValidationException, FrameworkException {
    String variation = VariationContext.getVariation();
    boolean localUow = false;
    try {
        // create a UOW, if not passed in
        if (uow == null) {
            uow = new UOW();
            localUow = true;
        }
        // Determine the domain class. A persistent object could very well be a proxy. Hence invoke the appropriate method
        String domainClassName = domainObject instanceof IPersistent ? uow.getActualPersistentClass(domainObject).getName() : domainObject.getClass().getName();
        // determine the ClassMetaData
        ClassMetaData classMetaData = getClassMetaData(domainClassName, variation);
        // determine the core ClassMetaData, if required
        ClassMetaData coreClassMetaData = VariationContext.DEFAULT_VARIATION.equals(variation) ? null : getClassMetaData(domainClassName, VariationContext.DEFAULT_VARIATION);
        // perform validations for all the fields
        if (classMetaData != null) {
            FieldMetaData[] fields = classMetaData.getFields();
            for (int i = 0; i < fields.length; i++) {
                FieldMetaData fieldMetaData = fields[i];
                FieldMetaData coreFieldMetaData = coreClassMetaData != null ? coreClassMetaData.getField(fieldMetaData.getName()) : null;
                String labelToken = getLabelToken(domainClassName, fieldMetaData.getName());
                Object fieldValue = getFieldValue(domainObject, fieldMetaData.getName());
                doFieldValidaions(fieldValue, uow, doOnlyMandatory, labelToken, fieldMetaData, coreFieldMetaData);
            }
        }
        // perform validations for the fields in the core file, which are not defined in the variant file
        if (coreClassMetaData != null) {
            FieldMetaData[] fields = coreClassMetaData.getFields();
            for (int i = 0; i < fields.length; i++) {
                FieldMetaData fieldMetaData = fields[i];
                if (classMetaData == null || classMetaData.getField(fieldMetaData.getName()) == null) {
                    // create a UOW, if not passed in
                    if (uow == null) {
                        uow = new UOW();
                        localUow = true;
                    }
                    String labelToken = getLabelToken(domainClassName, fieldMetaData.getName());
                    Object fieldValue = getFieldValue(domainObject, fieldMetaData.getName());
                    doFieldValidaions(fieldValue, uow, doOnlyMandatory, labelToken, fieldMetaData, null);
                }
            }
        }
    } finally {
        if (localUow && uow != null)
            uow.rollback();
    }
}
Also used : IPersistent(org.jaffa.persistence.IPersistent) UOW(org.jaffa.persistence.UOW)

Aggregations

UOW (org.jaffa.persistence.UOW)259 Criteria (org.jaffa.persistence.Criteria)138 FrameworkException (org.jaffa.exceptions.FrameworkException)99 ApplicationException (org.jaffa.exceptions.ApplicationException)88 AtomicCriteria (org.jaffa.persistence.AtomicCriteria)87 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)82 Iterator (java.util.Iterator)47 TransactionCriteria (org.jaffa.transaction.apis.data.TransactionCriteria)33 TransactionFieldCriteria (org.jaffa.transaction.apis.data.TransactionFieldCriteria)33 ArrayList (java.util.ArrayList)19 Transaction (org.jaffa.transaction.domain.Transaction)19 Map (java.util.Map)16 LinkedHashMap (java.util.LinkedHashMap)13 HashMap (java.util.HashMap)12 DateTime (org.jaffa.datatypes.DateTime)11 FormTemplate (org.jaffa.modules.printing.domain.FormTemplate)10 IPersistent (org.jaffa.persistence.IPersistent)10 Method (java.lang.reflect.Method)9 Collection (java.util.Collection)8 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)8