Search in sources :

Example 1 with Criteria

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

the class FormGroupMaintenanceTx method addRelatedDtosToRetrieveOut.

// .//GEN-END:_createPrevalidateOutDto_2_be
// .//GEN-BEGIN:_addRelatedDtosToRetrieveOut_1_be
/**
 * Add related objects to FormGroupMaintenanceRetrieveOutDto
 */
private void addRelatedDtosToRetrieveOut(UOW uow, FormGroup formGroup, FormGroupMaintenanceRetrieveOutDto output) throws FrameworkException, ApplicationExceptions {
    // .//GEN-BEGIN:_addRelatedDtosToRetrieveOut_FormUsage_1_be
    if (formGroup.getFormName() != null) {
        Criteria criteria = new Criteria();
        criteria.setTable(FormUsageMeta.getName());
        criteria.addCriteria(FormUsageMeta.FORM_NAME, formGroup.getFormName());
        criteria.addOrderBy("EventName", Criteria.ORDER_BY_ASC);
        // .//GEN-END:_addRelatedDtosToRetrieveOut_FormUsage_1_be
        // Add custom code to set the criteria before the query//GEN-FIRST:_addRelatedDtosToRetrieveOut_FormUsage_1
        // .//GEN-LAST:_addRelatedDtosToRetrieveOut_FormUsage_1
        // .//GEN-BEGIN:_addRelatedDtosToRetrieveOut_FormUsage_2_be
        Iterator itrMany = uow.query(criteria).iterator();
        while (itrMany.hasNext()) {
            FormUsage formUsage = (FormUsage) itrMany.next();
            FormUsageDto dto = new FormUsageDto();
            // .//GEN-END:_addRelatedDtosToRetrieveOut_FormUsage_2_be
            // Add custom code before all the setters//GEN-FIRST:_addRelatedDtosToRetrieveOut_FormUsage_2
            // .//GEN-LAST:_addRelatedDtosToRetrieveOut_FormUsage_2
            // .//GEN-BEGIN:_addRelatedDtosToRetrieveOut_FormUsage_EventName_1_be
            dto.setEventName(formUsage.getEventName());
            // .//GEN-END:_addRelatedDtosToRetrieveOut_FormUsage_EventName_1_be
            // .//GEN-BEGIN:_addRelatedDtosToRetrieveOut_FormUsage_FormAlternate_1_be
            dto.setFormAlternate(formUsage.getFormAlternate());
            // .//GEN-END:_addRelatedDtosToRetrieveOut_FormUsage_FormAlternate_1_be
            // .//GEN-BEGIN:_addRelatedDtosToRetrieveOut_FormUsage_Copies_1_be
            dto.setCopies(formUsage.getCopies());
            // .//GEN-END:_addRelatedDtosToRetrieveOut_FormUsage_Copies_1_be
            // .//GEN-BEGIN:_addRelatedDtosToRetrieveOut_FormUsage_Description_1_be
            FormEvent chainFormEventEventNameEventName = null;
            {
                if (formUsage.getEventName() != null) {
                    Criteria criteriaFormEvent = new Criteria();
                    criteriaFormEvent.setTable(FormEventMeta.getName());
                    criteriaFormEvent.addCriteria(FormEventMeta.EVENT_NAME, formUsage.getEventName());
                    // .//GEN-END:_addRelatedDtosToRetrieveOut_FormUsage_Description_1_be
                    // Add custom code to modify the criteria//GEN-FIRST:_addRelatedDtosToRetrieveOut_FormUsage_Description_1
                    // .//GEN-LAST:_addRelatedDtosToRetrieveOut_FormUsage_Description_1
                    // .//GEN-BEGIN:_addRelatedDtosToRetrieveOut_FormUsage_Description_2_be
                    Iterator i = uow.query(criteriaFormEvent).iterator();
                    if (i.hasNext())
                        chainFormEventEventNameEventName = (FormEvent) i.next();
                }
            }
            // .//GEN-BEGIN:_addRelatedDtosToRetrieveOut_FormUsage_Description_3_be
            try {
                dto.setDescription(chainFormEventEventNameEventName.getDescription());
            } catch (NullPointerException e) {
            // Do nothing
            }
            // .//GEN-END:_addRelatedDtosToRetrieveOut_FormUsage_Description_3_be
            // Add custom code to pass values to the dto//GEN-FIRST:_addRelatedDtosToRetrieveOut_FormUsage_3
            // .//GEN-LAST:_addRelatedDtosToRetrieveOut_FormUsage_3
            // .//GEN-BEGIN:_addRelatedDtosToRetrieveOut_FormUsage_3_be
            output.addFormUsage(dto);
        }
    // .//GEN-END:_addRelatedDtosToRetrieveOut_FormUsage_3_be
    // .//GEN-BEGIN:_addRelatedDtosToRetrieveOut_FormUsage_6_be
    }
// .//GEN-END:_addRelatedDtosToRetrieveOut_FormUsage_6_be
// .//GEN-BEGIN:_addRelatedDtosToRetrieveOut_2_be
}
Also used : FormEvent(org.jaffa.modules.printing.domain.FormEvent) Criteria(org.jaffa.persistence.Criteria) FormUsage(org.jaffa.modules.printing.domain.FormUsage)

Example 2 with Criteria

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

the class FormGroupMaintenanceTx method deleteRelatedObjects.

// .//GEN-END:_addRelatedDtosToRetrieveOut_2_be
// .//GEN-BEGIN:_deleteRelatedObjects_1_be
/**
 * Delete the related domain objects if the 'Cascading' constraint is specified. Throw an exception in case 'Restricted' constraint is specified.
 */
private void deleteRelatedObjects(UOW uow, FormGroupMaintenanceDeleteInDto input, FormGroup formGroup) throws FrameworkException, ApplicationExceptions {
    ApplicationExceptions appExps = null;
    // .//GEN-BEGIN:_deleteRelatedObjects_FormUsage_1_be
    if (formGroup.getFormName() != null) {
        Criteria criteria = new Criteria();
        criteria.setTable(FormUsageMeta.getName());
        criteria.addCriteria(FormUsageMeta.FORM_NAME, formGroup.getFormName());
        // .//GEN-END:_deleteRelatedObjects_FormUsage_1_be
        // Add custom code to set the criteria before the query//GEN-FIRST:_deleteRelatedObjects_FormUsage_1
        // .//GEN-LAST:_deleteRelatedObjects_FormUsage_1
        // .//GEN-BEGIN:_deleteRelatedObjects_FormUsage_5_be
        Collection col = uow.query(criteria);
        Iterator itr = col.iterator();
        if (itr.hasNext()) {
            col.clear();
            if (log.isDebugEnabled())
                log.debug("The related formUsage object having 'Restricted Delete Constraint' was found. Delete cannot be performed");
            if (appExps == null)
                appExps = new ApplicationExceptions();
            appExps.add(new RelatedDomainObjectFoundException(FormUsageMeta.getLabelToken()));
        }
    // .//GEN-END:_deleteRelatedObjects_FormUsage_5_be
    // .//GEN-BEGIN:_deleteRelatedObjects_FormUsage_6_be
    }
    // .//GEN-BEGIN:_deleteRelatedObjects_2_be
    if (appExps != null)
        throw appExps;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) Criteria(org.jaffa.persistence.Criteria) RelatedDomainObjectFoundException(org.jaffa.exceptions.RelatedDomainObjectFoundException)

Example 3 with Criteria

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

the class FormGroupMaintenanceTx method load.

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

Example 4 with Criteria

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

the class FormGroupMaintenanceTx method createFormUsageEntry.

// .//GEN-END:_deleteRelatedObjects_2_be
// All the custom code goes here//GEN-FIRST:_custom
// Add the related FormUsage
private void createFormUsageEntry(UOW uow, FormGroupMaintenanceUpdateInDto input, boolean fromPrevalidate) throws FrameworkException, ApplicationExceptions {
    ApplicationExceptions appExps = null;
    try {
        if (input.getFormName() != null) {
            Criteria criteria = new Criteria();
            criteria.setTable(FormUsageMeta.getName());
            criteria.addCriteria(FormUsageMeta.FORM_NAME, input.getFormName());
            Collection col = uow.query(criteria);
            // Iterator itr = col.iterator();
            for (int i = 0; i < input.getFormUsageCount(); i++) {
                boolean found = false;
                FormUsageDto inputFormUsageDto = input.getFormUsage(i);
                for (Iterator itr = col.iterator(); itr.hasNext(); ) {
                    FormUsage formusage = (FormUsage) itr.next();
                    if (inputFormUsageDto.getEventName().equals(formusage.getEventName())) {
                        try {
                            formusage.updateFormAlternate(inputFormUsageDto.getFormAlternate());
                        } catch (ValidationException e) {
                            if (appExps == null)
                                appExps = new ApplicationExceptions();
                            appExps.add(e);
                        }
                        try {
                            formusage.updateCopies(inputFormUsageDto.getCopies());
                        } catch (ValidationException e) {
                            if (appExps == null)
                                appExps = new ApplicationExceptions();
                            appExps.add(e);
                        }
                        if (appExps != null && appExps.size() > 0)
                            throw appExps;
                        if (!fromPrevalidate) {
                            if (log.isDebugEnabled())
                                log.debug("Creating FormUsage: " + formusage);
                            uow.update(formusage);
                            found = true;
                        }
                        break;
                    } else {
                        continue;
                    }
                }
                if (!found) {
                    FormUsage formUsage = new FormUsage();
                    formUsage.setEventName(inputFormUsageDto.getEventName());
                    formUsage.setFormName(input.getFormName());
                    formUsage.setFormAlternate(inputFormUsageDto.getFormAlternate());
                    formUsage.setCopies(inputFormUsageDto.getCopies());
                    if (!fromPrevalidate) {
                        if (log.isDebugEnabled())
                            log.debug("Creating FormUsage: " + formUsage);
                        uow.add(formUsage);
                    }
                }
            }
            for (Iterator itr = col.iterator(); itr.hasNext(); ) {
                boolean found = false;
                FormUsage formusage = (FormUsage) itr.next();
                for (int i = 0; i < input.getFormUsageCount(); i++) {
                    FormUsageDto inputFormUsageDto = input.getFormUsage(i);
                    if (formusage.getEventName().equals(inputFormUsageDto.getEventName())) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    if (!fromPrevalidate) {
                        if (log.isDebugEnabled())
                            log.debug("Creating FormUsage: " + formusage);
                        uow.delete(formusage);
                    }
                }
            }
        }
    } catch (ValidationException e) {
        throw new ApplicationExceptions(e);
    }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ValidationException(org.jaffa.datatypes.ValidationException) Criteria(org.jaffa.persistence.Criteria) FormUsage(org.jaffa.modules.printing.domain.FormUsage)

Example 5 with Criteria

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

the class FormGroupMaintenanceTx method load.

// .//GEN-END:_preprocessRetrieve_2_be
// .//GEN-BEGIN:_loadRetrieve_1_be
/**
 * Retrieve the domain object.
 */
private FormGroup load(UOW uow, FormGroupMaintenanceRetrieveInDto input) throws FrameworkException, ApplicationExceptions {
    FormGroup domain = null;
    Criteria criteria = new Criteria();
    criteria.setTable(FormGroupMeta.getName());
    // .//GEN-END:_loadRetrieve_1_be
    // Add custom criteria//GEN-FIRST:_loadRetrieve_1
    // .//GEN-LAST:_loadRetrieve_1
    // .//GEN-BEGIN:_loadRetrieve_2_be
    criteria.addCriteria(FormGroupMeta.FORM_NAME, input.getFormName());
    Iterator itr = uow.query(criteria).iterator();
    if (itr.hasNext())
        domain = (FormGroup) itr.next();
    // .//GEN-BEGIN:_loadRetrieve_3_be
    if (domain == null) {
        ApplicationExceptions appExps = new ApplicationExceptions();
        appExps.add(new DomainObjectNotFoundException(FormGroupMeta.getLabelToken()));
        throw appExps;
    }
    return domain;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException) FormGroup(org.jaffa.modules.printing.domain.FormGroup) Criteria(org.jaffa.persistence.Criteria)

Aggregations

Criteria (org.jaffa.persistence.Criteria)300 UOW (org.jaffa.persistence.UOW)136 AtomicCriteria (org.jaffa.persistence.AtomicCriteria)124 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)66 Iterator (java.util.Iterator)53 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)39 TransactionCriteria (org.jaffa.transaction.apis.data.TransactionCriteria)32 TransactionFieldCriteria (org.jaffa.transaction.apis.data.TransactionFieldCriteria)32 OrderByField (org.jaffa.components.finder.OrderByField)28 Map (java.util.Map)23 ArrayList (java.util.ArrayList)17 DateTime (org.jaffa.datatypes.DateTime)16 FrameworkException (org.jaffa.exceptions.FrameworkException)14 ApplicationException (org.jaffa.exceptions.ApplicationException)13 DuplicateKeyException (org.jaffa.exceptions.DuplicateKeyException)13 Transaction (org.jaffa.transaction.domain.Transaction)13 Collection (java.util.Collection)12 LinkedHashMap (java.util.LinkedHashMap)11 IPersistent (org.jaffa.persistence.IPersistent)11 HashMap (java.util.HashMap)9