Search in sources :

Example 1 with OutputCommand

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

the class PrinterOutputTypeViewerTx method addRelatedDtos.

// .//GEN-END:_buildDto_3_be
// .//GEN-BEGIN:_addRelatedDtos_1_be
private void addRelatedDtos(UOW uow, PrinterOutputTypeViewerOutDto output, PrinterOutputType printerOutputType) throws UOWException {
    // .//GEN-BEGIN:_addRelatedDtos_OutputCommand_1_be
    if (printerOutputType.getOutputType() != null) {
        Criteria criteria = new Criteria();
        criteria.setTable(OutputCommandMeta.getName());
        criteria.addCriteria(OutputCommandMeta.OUTPUT_TYPE, printerOutputType.getOutputType());
        criteria.addOrderBy("OutputCommandId", Criteria.ORDER_BY_ASC);
        // .//GEN-END:_addRelatedDtos_OutputCommand_1_be
        // Add custom code to set the criteria before the query //GEN-FIRST:_addRelatedDtos_OutputCommand_1
        // .//GEN-LAST:_addRelatedDtos_OutputCommand_1
        // .//GEN-BEGIN:_addRelatedDtos_OutputCommand_2_be
        Iterator itr = uow.query(criteria).iterator();
        while (itr.hasNext()) {
            OutputCommand outputCommand = (OutputCommand) itr.next();
            OutputCommandDto dto = new OutputCommandDto();
            // .//GEN-END:_addRelatedDtos_OutputCommand_2_be
            // Add custom code before all the setters //GEN-FIRST:_addRelatedDtos_OutputCommand_2
            // .//GEN-LAST:_addRelatedDtos_OutputCommand_2
            // .//GEN-BEGIN:_addRelatedDtos_OutputCommand_OutputCommandId_1_be
            dto.setOutputCommandId(outputCommand.getOutputCommandId());
            // .//GEN-END:_addRelatedDtos_OutputCommand_OutputCommandId_1_be
            // .//GEN-BEGIN:_addRelatedDtos_OutputCommand_OutputType_1_be
            dto.setOutputType(outputCommand.getOutputType());
            // .//GEN-END:_addRelatedDtos_OutputCommand_OutputType_1_be
            // .//GEN-BEGIN:_addRelatedDtos_OutputCommand_SequenceNo_1_be
            dto.setSequenceNo(outputCommand.getSequenceNo());
            // .//GEN-END:_addRelatedDtos_OutputCommand_SequenceNo_1_be
            // .//GEN-BEGIN:_addRelatedDtos_OutputCommand_OsPattern_1_be
            dto.setOsPattern(outputCommand.getOsPattern());
            // .//GEN-END:_addRelatedDtos_OutputCommand_OsPattern_1_be
            // .//GEN-BEGIN:_addRelatedDtos_OutputCommand_CommandLine_1_be
            dto.setCommandLine(outputCommand.getCommandLine());
            // .//GEN-END:_addRelatedDtos_OutputCommand_CommandLine_1_be
            // .//GEN-BEGIN:_addRelatedDtos_OutputCommand_CreatedOn_1_be
            dto.setCreatedOn(outputCommand.getCreatedOn());
            // .//GEN-END:_addRelatedDtos_OutputCommand_CreatedOn_1_be
            // .//GEN-BEGIN:_addRelatedDtos_OutputCommand_CreatedBy_1_be
            dto.setCreatedBy(outputCommand.getCreatedBy());
            // .//GEN-END:_addRelatedDtos_OutputCommand_CreatedBy_1_be
            // .//GEN-BEGIN:_addRelatedDtos_OutputCommand_LastChangedOn_1_be
            dto.setLastChangedOn(outputCommand.getLastChangedOn());
            // .//GEN-END:_addRelatedDtos_OutputCommand_LastChangedOn_1_be
            // .//GEN-BEGIN:_addRelatedDtos_OutputCommand_LastChangedBy_1_be
            dto.setLastChangedBy(outputCommand.getLastChangedBy());
            // .//GEN-END:_addRelatedDtos_OutputCommand_LastChangedBy_1_be
            // Add custom code to pass values to the dto //GEN-FIRST:_addRelatedDtos_OutputCommand_3
            // .//GEN-LAST:_addRelatedDtos_OutputCommand_3
            // .//GEN-BEGIN:_addRelatedDtos_OutputCommand_3_be
            output.addOutputCommand(dto);
        }
    }
// .//GEN-END:_addRelatedDtos_OutputCommand_3_be
// .//GEN-BEGIN:_addRelatedDtos_2_be
}
Also used : OutputCommand(org.jaffa.modules.printing.domain.OutputCommand) OutputCommandDto(org.jaffa.modules.printing.components.printeroutputtypeviewer.dto.OutputCommandDto) Criteria(org.jaffa.persistence.Criteria)

Example 2 with OutputCommand

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

the class FormDelivery method sendToPrinter.

/**
 * Send the generated document to the specified printer
 * @param printerId Printer name, should be defined in PrinterDefinitions
 * @param copies Number of copies to print
 * @param document Source file to print
 * @throws ApplicationExceptions Thrown if any funtional issue ocurred when executing
 * @throws FrameworkException Thrown if any framework issue ocurred when executing
 */
public static void sendToPrinter(String printerId, int copies, File document) throws FrameworkException, ApplicationExceptions {
    UOW uow = new UOW();
    try {
        // Read the printer definition
        PrinterDefinition printer = PrinterDefinition.findByPK(uow, printerId);
        if (printer == null) {
            log.error("Unknown printer in print request : " + printerId);
            throw new ApplicationExceptions(new DomainObjectNotFoundException(PrinterDefinitionMeta.getLabelToken()));
        }
        PrinterOutputType outputType = printer.getPrinterOutputTypeObject();
        // See if this is direct printing
        if (Boolean.TRUE.equals(outputType.getDirectPrinting())) {
            printDirect(printer, document, copies);
        } else {
            // Find an external command line that will print this document
            String commandLine = null;
            String os = System.getProperty("os.name");
            for (OutputCommand command : outputType.getOutputCommandArray()) {
                if (Pattern.matches(command.getOsPattern(), os)) {
                    commandLine = command.getCommandLine();
                    break;
                }
            }
            if (commandLine == null) {
                log.error("Can't find matching command line for Output Type " + outputType.getOutputType() + " on OS " + os);
                throw new ApplicationExceptions(new DomainObjectNotFoundException(OutputCommandMeta.getLabelToken()));
            }
            // Now try and print the document with the command
            printViaCommand(printer, document, copies, commandLine);
        }
    } catch (ApplicationException e) {
        ApplicationExceptions aes = new ApplicationExceptions();
        aes.add(e);
        throw aes;
    } finally {
        if (uow != null)
            // This UOW should have not been used for updates!!!
            uow.rollback();
    }
}
Also used : PrinterDefinition(org.jaffa.modules.printing.domain.PrinterDefinition) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) PrinterOutputType(org.jaffa.modules.printing.domain.PrinterOutputType) ApplicationException(org.jaffa.exceptions.ApplicationException) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException) OutputCommand(org.jaffa.modules.printing.domain.OutputCommand) UOW(org.jaffa.persistence.UOW)

Example 3 with OutputCommand

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

the class OutputCommandFinderTx method buildDto.

// .//GEN-END:_buildCriteria_3_be
// .//GEN-BEGIN:_buildDto_1_be
private OutputCommandFinderOutDto buildDto(UOW uow, Collection results, OutputCommandFinderInDto input) throws UOWException {
    OutputCommandFinderOutDto output = new OutputCommandFinderOutDto();
    int maxRecords = input.getMaxRecords() != null ? input.getMaxRecords().intValue() : 0;
    int counter = 0;
    for (Iterator i = results.iterator(); i.hasNext(); ) {
        if (++counter > maxRecords && maxRecords > 0) {
            output.setMoreRecordsExist(Boolean.TRUE);
            break;
        }
        OutputCommandFinderOutRowDto row = new OutputCommandFinderOutRowDto();
        OutputCommand outputCommand = (OutputCommand) i.next();
        // .//GEN-END:_buildDto_1_be
        // Add custom code before all the setters //GEN-FIRST:_buildDto_1
        // .//GEN-LAST:_buildDto_1
        // .//GEN-BEGIN:_buildDto_OutputCommandId_1_be
        row.setOutputCommandId(outputCommand.getOutputCommandId());
        // .//GEN-END:_buildDto_OutputCommandId_1_be
        // .//GEN-BEGIN:_buildDto_OutputType_1_be
        row.setOutputType(outputCommand.getOutputType());
        // .//GEN-END:_buildDto_OutputType_1_be
        // .//GEN-BEGIN:_buildDto_SequenceNo_1_be
        row.setSequenceNo(outputCommand.getSequenceNo());
        // .//GEN-END:_buildDto_SequenceNo_1_be
        // .//GEN-BEGIN:_buildDto_OsPattern_1_be
        row.setOsPattern(outputCommand.getOsPattern());
        // .//GEN-END:_buildDto_OsPattern_1_be
        // .//GEN-BEGIN:_buildDto_CommandLine_1_be
        row.setCommandLine(outputCommand.getCommandLine());
        // .//GEN-END:_buildDto_CommandLine_1_be
        // .//GEN-BEGIN:_buildDto_CreatedOn_1_be
        row.setCreatedOn(outputCommand.getCreatedOn());
        // .//GEN-END:_buildDto_CreatedOn_1_be
        // .//GEN-BEGIN:_buildDto_CreatedBy_1_be
        row.setCreatedBy(outputCommand.getCreatedBy());
        // .//GEN-END:_buildDto_CreatedBy_1_be
        // .//GEN-BEGIN:_buildDto_LastChangedOn_1_be
        row.setLastChangedOn(outputCommand.getLastChangedOn());
        // .//GEN-END:_buildDto_LastChangedOn_1_be
        // .//GEN-BEGIN:_buildDto_LastChangedBy_1_be
        row.setLastChangedBy(outputCommand.getLastChangedBy());
        // .//GEN-END:_buildDto_LastChangedBy_1_be
        // Add custom code to pass values to the dto //GEN-FIRST:_buildDto_2
        // .//GEN-LAST:_buildDto_2
        // .//GEN-BEGIN:_buildDto_3_be
        output.addRows(row);
    }
    return output;
}
Also used : OutputCommandFinderOutRowDto(org.jaffa.modules.printing.components.outputcommandfinder.dto.OutputCommandFinderOutRowDto) OutputCommand(org.jaffa.modules.printing.domain.OutputCommand) OutputCommandFinderOutDto(org.jaffa.modules.printing.components.outputcommandfinder.dto.OutputCommandFinderOutDto)

Example 4 with OutputCommand

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

the class PrinterOutputTypeMaintenanceTx 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, PrinterOutputTypeMaintenanceDeleteInDto input, PrinterOutputType printerOutputType) throws FrameworkException, ApplicationExceptions {
    ApplicationExceptions appExps = null;
    // .//GEN-BEGIN:_deleteRelatedObjects_OutputCommand_1_be
    if (printerOutputType.getOutputType() != null) {
        Criteria criteria = new Criteria();
        criteria.setTable(OutputCommandMeta.getName());
        criteria.addCriteria(OutputCommandMeta.OUTPUT_TYPE, printerOutputType.getOutputType());
        criteria.setLocking(Criteria.LOCKING_PARANOID);
        // .//GEN-END:_deleteRelatedObjects_OutputCommand_1_be
        // Add custom code to set the criteria before the query //GEN-FIRST:_deleteRelatedObjects_OutputCommand_1
        // .//GEN-LAST:_deleteRelatedObjects_OutputCommand_1
        // .//GEN-BEGIN:_deleteRelatedObjects_OutputCommand_2_be
        Iterator itr = uow.query(criteria).iterator();
        while (itr.hasNext()) {
            OutputCommand outputCommand = (OutputCommand) itr.next();
            if (log.isDebugEnabled())
                log.debug("Invoking the org.jaffa.modules.printing.components.outputcommandmaintenance.tx.OutputCommandMaintenanceTx class to cascade delete the related object " + outputCommand);
            org.jaffa.modules.printing.components.outputcommandmaintenance.dto.OutputCommandMaintenanceDeleteInDto deleteInDto = new org.jaffa.modules.printing.components.outputcommandmaintenance.dto.OutputCommandMaintenanceDeleteInDto();
            deleteInDto.setHeaderDto(input.getHeaderDto());
            deleteInDto.setOutputCommandId(outputCommand.getOutputCommandId());
            org.jaffa.modules.printing.components.outputcommandmaintenance.tx.OutputCommandMaintenanceTx tx = new org.jaffa.modules.printing.components.outputcommandmaintenance.tx.OutputCommandMaintenanceTx();
            // .//GEN-END:_deleteRelatedObjects_OutputCommand_2_be
            // Add custom code to set any addtional criteria before the delete //GEN-FIRST:_deleteRelatedObjects_OutputCommand_2
            // .//GEN-LAST:_deleteRelatedObjects_OutputCommand_2
            // .//GEN-BEGIN:_deleteRelatedObjects_OutputCommand_3_be
            tx.delete(deleteInDto, uow);
            tx.destroy();
        }
    // .//GEN-END:_deleteRelatedObjects_OutputCommand_3_be
    // .//GEN-BEGIN:_deleteRelatedObjects_OutputCommand_6_be
    }
    // .//GEN-BEGIN:_deleteRelatedObjects_2_be
    if (appExps != null)
        throw appExps;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) OutputCommand(org.jaffa.modules.printing.domain.OutputCommand) Criteria(org.jaffa.persistence.Criteria) org.jaffa.modules.printing.components.printeroutputtypemaintenance.dto(org.jaffa.modules.printing.components.printeroutputtypemaintenance.dto)

Example 5 with OutputCommand

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

the class OutputCommandMaintenanceTx 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 OutputCommand.
 * @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 OutputCommandMaintenancePrevalidateOutDto prevalidateCreate(OutputCommandMaintenanceCreateInDto 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
        OutputCommand domain = createDomain(uow, input, true);
        domain = postCreate(uow, input, domain, true);
        // Build the outbound dto
        OutputCommandMaintenancePrevalidateOutDto 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) OutputCommand(org.jaffa.modules.printing.domain.OutputCommand) UOW(org.jaffa.persistence.UOW)

Aggregations

OutputCommand (org.jaffa.modules.printing.domain.OutputCommand)19 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)11 ApplicationException (org.jaffa.exceptions.ApplicationException)6 FrameworkException (org.jaffa.exceptions.FrameworkException)6 Criteria (org.jaffa.persistence.Criteria)6 UOW (org.jaffa.persistence.UOW)6 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)4 PrinterDefinition (org.jaffa.modules.printing.domain.PrinterDefinition)2 ValidationException (org.jaffa.datatypes.ValidationException)1 InvalidForeignKeyException (org.jaffa.datatypes.exceptions.InvalidForeignKeyException)1 DuplicateKeyException (org.jaffa.exceptions.DuplicateKeyException)1 RelatedDomainObjectFoundException (org.jaffa.exceptions.RelatedDomainObjectFoundException)1 OutputCommandFinderOutDto (org.jaffa.modules.printing.components.outputcommandfinder.dto.OutputCommandFinderOutDto)1 OutputCommandFinderOutRowDto (org.jaffa.modules.printing.components.outputcommandfinder.dto.OutputCommandFinderOutRowDto)1 OutputCommandLookupOutDto (org.jaffa.modules.printing.components.outputcommandlookup.dto.OutputCommandLookupOutDto)1 OutputCommandLookupOutRowDto (org.jaffa.modules.printing.components.outputcommandlookup.dto.OutputCommandLookupOutRowDto)1 OutputCommandViewerOutDto (org.jaffa.modules.printing.components.outputcommandviewer.dto.OutputCommandViewerOutDto)1 org.jaffa.modules.printing.components.printeroutputtypemaintenance.dto (org.jaffa.modules.printing.components.printeroutputtypemaintenance.dto)1 OutputCommandDto (org.jaffa.modules.printing.components.printeroutputtypeviewer.dto.OutputCommandDto)1 PrinterOutputType (org.jaffa.modules.printing.domain.PrinterOutputType)1