Search in sources :

Example 6 with Criteria

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

the class FormGroupViewerTx method read.

// .//GEN-END:_destroy_2_be
// .//GEN-BEGIN:_read_1_be
/**
 * Returns the details for FormGroup.
 * @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 FormGroupViewerOutDto read(FormGroupViewerInDto 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
        FormGroupViewerOutDto 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 : FormGroupViewerOutDto(org.jaffa.modules.printing.components.formgroupviewer.dto.FormGroupViewerOutDto) Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW)

Example 7 with Criteria

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

the class FormGroupViewerTx method addRelatedDtos.

// .//GEN-END:_buildDto_3_be
// .//GEN-BEGIN:_addRelatedDtos_1_be
private void addRelatedDtos(UOW uow, FormGroupViewerOutDto output, FormGroup formGroup) throws UOWException {
    // .//GEN-BEGIN:_addRelatedDtos_FormUsage_1_be
    if (formGroup.getFormName() != null) {
        Criteria criteria = new Criteria();
        criteria.setTable(FormUsageMeta.getName());
        criteria.addCriteria(FormUsageMeta.FORM_NAME, formGroup.getFormName());
        criteria.addOrderBy("FormName", Criteria.ORDER_BY_ASC);
        // .//GEN-END:_addRelatedDtos_FormUsage_1_be
        // Add custom code to set the criteria before the query //GEN-FIRST:_addRelatedDtos_FormUsage_1
        // .//GEN-LAST:_addRelatedDtos_FormUsage_1
        // .//GEN-BEGIN:_addRelatedDtos_FormUsage_2_be
        Iterator itr = uow.query(criteria).iterator();
        while (itr.hasNext()) {
            FormUsage formUsage = (FormUsage) itr.next();
            FormUsageDto dto = new FormUsageDto();
            // .//GEN-END:_addRelatedDtos_FormUsage_2_be
            // Add custom code before all the setters //GEN-FIRST:_addRelatedDtos_FormUsage_2
            // .//GEN-LAST:_addRelatedDtos_FormUsage_2
            // .//GEN-BEGIN:_addRelatedDtos_FormUsage_EventName_1_be
            dto.setEventName(formUsage.getEventName());
            // .//GEN-END:_addRelatedDtos_FormUsage_EventName_1_be
            // .//GEN-BEGIN:_addRelatedDtos_FormUsage_FormAlternate_1_be
            dto.setFormAlternate(formUsage.getFormAlternate());
            // .//GEN-END:_addRelatedDtos_FormUsage_FormAlternate_1_be
            // .//GEN-BEGIN:_addRelatedDtos_FormUsage_Copies_1_be
            dto.setCopies(formUsage.getCopies());
            // .//GEN-END:_addRelatedDtos_FormUsage_Copies_1_be
            // .//GEN-BEGIN:_addRelatedDtos_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:_addRelatedDtos_FormUsage_Description_1_be
                    // Add custom code to modify the criteria //GEN-FIRST:_addRelatedDtos_FormUsage_Description_1
                    // .//GEN-LAST:_addRelatedDtos_FormUsage_Description_1
                    // .//GEN-BEGIN:_addRelatedDtos_FormUsage_Description_2_be
                    Iterator i = uow.query(criteriaFormEvent).iterator();
                    if (i.hasNext())
                        chainFormEventEventNameEventName = (FormEvent) i.next();
                }
            }
            // .//GEN-BEGIN:_addRelatedDtos_FormUsage_Description_3_be
            try {
                dto.setDescription(chainFormEventEventNameEventName.getDescription());
            } catch (NullPointerException e) {
            // Do nothing
            }
            // .//GEN-END:_addRelatedDtos_FormUsage_Description_3_be
            // Add custom code to pass values to the dto //GEN-FIRST:_addRelatedDtos_FormUsage_3
            // .//GEN-LAST:_addRelatedDtos_FormUsage_3
            // .//GEN-BEGIN:_addRelatedDtos_FormUsage_3_be
            output.addFormUsage(dto);
        }
    }
// .//GEN-END:_addRelatedDtos_FormUsage_3_be
// .//GEN-BEGIN:_addRelatedDtos_2_be
}
Also used : FormEvent(org.jaffa.modules.printing.domain.FormEvent) FormUsageDto(org.jaffa.modules.printing.components.formgroupviewer.dto.FormUsageDto) Criteria(org.jaffa.persistence.Criteria) FormUsage(org.jaffa.modules.printing.domain.FormUsage)

Example 8 with Criteria

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

the class FormSelectionMaintenanceTx method findOutDto.

// .//GEN-END:_buildDto_3_be
// All the custom code goes here//GEN-FIRST:_custom
// TODO-SWAT add script event here
/**
 * Searches for FormUsage objects.
 * @param input The criteria based on which the search will be performed.
 * @throws ApplicationExceptions This will be thrown if the criteria contains invalid data.
 * @throws FrameworkException Indicates some system error
 * @return The search results.
 */
public FormSelectionMaintenanceOutDto findOutDto(FormSelectionMaintenanceInDto input) throws FrameworkException, ApplicationExceptions {
    // TODO-SWAT fire script event here
    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);
        // Execute The Query
        Collection results = uow.query(criteria);
        // Convert the domain objects into the outbound dto
        FormSelectionMaintenanceOutDto output = buildOutDto(uow, results, input);
        // 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 : FormSelectionMaintenanceOutDto(org.jaffa.modules.printing.components.formselectionmaintenance.dto.FormSelectionMaintenanceOutDto) Criteria(org.jaffa.persistence.Criteria) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) UOW(org.jaffa.persistence.UOW)

Example 9 with Criteria

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

the class FormSelectionMaintenanceTx method buildCriteria.

// .//GEN-END:_find_3_be
// .//GEN-BEGIN:_buildCriteria_1_be
private Criteria buildCriteria(FormSelectionMaintenanceInDto input, UOW uow) {
    Criteria criteria = new Criteria();
    criteria.setTable(FormUsageMeta.getName());
    // .//GEN-END:_buildCriteria_1_be
    // Add custom criteria//GEN-FIRST:_buildCriteria_1
    FinderTx.addCriteria(input.getEvent(), FormUsageMeta.EVENT_NAME, criteria);
    // .//GEN-LAST:_buildCriteria_1
    // .//GEN-BEGIN:_buildCriteria_2_be
    // append an orderBy clause to the criteria
    OrderByField[] orderByFields = input.getOrderByFields();
    if (orderByFields != null) {
        for (int i = 0; i < orderByFields.length; i++) {
            OrderByField orderByField = orderByFields[i];
            int sort = Criteria.ORDER_BY_ASC;
            if (orderByField.getSortAscending() != null && !orderByField.getSortAscending().booleanValue())
                sort = Criteria.ORDER_BY_DESC;
            criteria.addOrderBy(orderByField.getFieldName(), sort);
        }
    }
    // .//GEN-BEGIN:_buildCriteria_3_be
    return criteria;
}
Also used : OrderByField(org.jaffa.components.finder.OrderByField) Criteria(org.jaffa.persistence.Criteria) AtomicCriteria(org.jaffa.persistence.AtomicCriteria)

Example 10 with Criteria

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

the class FormSelectionMaintenanceTx method buildOutDto.

private FormSelectionMaintenanceOutDto buildOutDto(UOW uow, Collection results, FormSelectionMaintenanceInDto input) throws FrameworkException {
    FormSelectionMaintenanceOutDto output = new FormSelectionMaintenanceOutDto();
    // key=outputType, value=List of Printers
    Map<String, List<String>> printersPerOutputType = null;
    String variation = VariationContext.getVariation();
    String outputType = null;
    String[] keys = new String[6];
    if (input.getKey1() != null) {
        String[] keyArray = input.getKey1().getValues();
        keys[0] = keyArray[0];
    }
    if (input.getKey2() != null) {
        String[] keyArray = input.getKey2().getValues();
        keys[1] = keyArray[0];
    }
    if (input.getKey3() != null) {
        String[] keyArray = input.getKey3().getValues();
        keys[2] = keyArray[0];
    }
    if (input.getKey4() != null) {
        String[] keyArray = input.getKey4().getValues();
        keys[3] = keyArray[0];
    }
    if (input.getKey5() != null) {
        String[] keyArray = input.getKey5().getValues();
        keys[4] = keyArray[0];
    }
    if (input.getKey6() != null) {
        String[] keyArray = input.getKey6().getValues();
        keys[5] = keyArray[0];
    }
    if (log.isDebugEnabled())
        log.debug("Form Selection building OutDto using Event=" + input.getEvent() + ", key1=" + keys[0] + ", key2=" + keys[1] + ", key3=" + keys[2] + ", key4=" + keys[3] + ", key5=" + keys[4] + ", key6=" + keys[5] + ", variation=" + variation);
    for (Iterator i = results.iterator(); i.hasNext(); ) {
        FormUsage formUsage = (FormUsage) i.next();
        FormDefinition formDefinition = FormProcessor.findFormDefinition(uow, formUsage.getFormName(), formUsage.getFormAlternate(), variation, outputType, keys);
        if (formDefinition != null) {
            FormSelectionMaintenanceOutRowDto row = new FormSelectionMaintenanceOutRowDto();
            row.setFormName(formDefinition.getFormName());
            row.setCopies(formUsage.getCopies());
            if (input.getEvent() != null) {
                String[] mEvent = input.getEvent().getValues();
                row.setEvent(mEvent[0]);
            }
            if (keys[0] != null) {
                row.setKey1(keys[0]);
            }
            if (keys[1] != null) {
                row.setKey2(keys[1]);
            }
            if (keys[2] != null) {
                row.setKey3(keys[2]);
            }
            if (keys[3] != null) {
                row.setKey4(keys[3]);
            }
            if (keys[4] != null) {
                row.setKey5(keys[4]);
            }
            if (keys[5] != null) {
                row.setKey6(keys[5]);
            }
            if (input.getValue1() != null) {
                String[] mValue1 = input.getValue1().getValues();
                row.setValue1(mValue1[0]);
            }
            if (input.getValue2() != null) {
                String[] mValue2 = input.getValue2().getValues();
                row.setValue2(mValue2[0]);
            }
            if (input.getValue3() != null) {
                String[] mValue3 = input.getValue3().getValues();
                row.setValue3(mValue3[0]);
            }
            if (input.getValue4() != null) {
                String[] mValue4 = input.getValue4().getValues();
                row.setValue4(mValue4[0]);
            }
            if (input.getValue5() != null) {
                String[] mValue5 = input.getValue5().getValues();
                row.setValue5(mValue5[0]);
            }
            if (input.getValue6() != null) {
                String[] mValue6 = input.getValue6().getValues();
                row.setValue6(mValue6[0]);
            }
            // Use the form definition selected because it may have selected the "-RL" right-to-left alternate.
            if (formUsage.getFormAlternate() != null) {
                row.setFormAlternateName(formDefinition.getFormAlternate());
            }
            row.setVariation(formDefinition.getFormVariation());
            row.setAdditionalDataComponent(formDefinition.getAdditionalDataComponent());
            // Query on FormGroup to find FormType.
            Criteria criteria = new Criteria();
            criteria.setTable(FormGroupMeta.getName());
            criteria.addCriteria(FormGroupMeta.FORM_NAME, formUsage.getFormName());
            Collection col = uow.query(criteria);
            Iterator itr = col.iterator();
            if (itr.hasNext()) {
                FormGroup formGroup = (FormGroup) itr.next();
                row.setFormType(formGroup.getFormType());
            }
            // Default the printer if possible and only if it has not already been initialized
            if (row.getPrinter() == null && input.getDefaultPrinters() != null) {
                // Construct a Map of valid printers per outputType
                if (printersPerOutputType == null)
                    printersPerOutputType = determinePrintersPerOutputType(uow, input.getDefaultPrinters());
                // Get the first printer for an outputType
                List<String> printers = printersPerOutputType.get(formDefinition.getOutputType());
                if (printers != null && printers.size() >= 0)
                    row.setPrinter(printers.get(0));
            }
            if (row.getEmail() == null && (FormPrintFactory.ENGINE_TYPE_ITEXT.equals(row.getFormType()) || FormPrintFactory.ENGINE_TYPE_FOP.equals(row.getFormType())))
                row.setEmail(getUserEmail());
            output.addRows(row);
        }
    }
    return output;
}
Also used : FormGroup(org.jaffa.modules.printing.domain.FormGroup) Criteria(org.jaffa.persistence.Criteria) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) FormSelectionMaintenanceOutRowDto(org.jaffa.modules.printing.components.formselectionmaintenance.dto.FormSelectionMaintenanceOutRowDto) FormSelectionMaintenanceOutDto(org.jaffa.modules.printing.components.formselectionmaintenance.dto.FormSelectionMaintenanceOutDto) FormDefinition(org.jaffa.modules.printing.domain.FormDefinition) FormUsage(org.jaffa.modules.printing.domain.FormUsage)

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