Search in sources :

Example 1 with PrinterOutputType

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

the class PrinterOutputTypeViewerTx method buildDto.

// .//GEN-END:_buildCriteria_3_be
// .//GEN-BEGIN:_buildDto_1_be
private PrinterOutputTypeViewerOutDto buildDto(UOW uow, Collection results) throws UOWException {
    PrinterOutputTypeViewerOutDto output = null;
    Iterator itr = results.iterator();
    if (itr.hasNext()) {
        // just return the details for the 1st record retrieved.
        PrinterOutputType printerOutputType = (PrinterOutputType) itr.next();
        output = new PrinterOutputTypeViewerOutDto();
        // .//GEN-END:_buildDto_1_be
        // Add custom code before all the setters //GEN-FIRST:_buildDto_1
        // .//GEN-LAST:_buildDto_1
        // .//GEN-BEGIN:_buildDto_OutputType_1_be
        output.setOutputType(printerOutputType.getOutputType());
        // .//GEN-END:_buildDto_OutputType_1_be
        // .//GEN-BEGIN:_buildDto_Description_1_be
        output.setDescription(printerOutputType.getDescription());
        // .//GEN-END:_buildDto_Description_1_be
        // .//GEN-BEGIN:_buildDto_DirectPrinting_1_be
        output.setDirectPrinting(printerOutputType.getDirectPrinting());
        // .//GEN-END:_buildDto_DirectPrinting_1_be
        // .//GEN-BEGIN:_buildDto_CreatedOn_1_be
        output.setCreatedOn(printerOutputType.getCreatedOn());
        // .//GEN-END:_buildDto_CreatedOn_1_be
        // .//GEN-BEGIN:_buildDto_CreatedBy_1_be
        output.setCreatedBy(printerOutputType.getCreatedBy());
        // .//GEN-END:_buildDto_CreatedBy_1_be
        // .//GEN-BEGIN:_buildDto_LastChangedOn_1_be
        output.setLastChangedOn(printerOutputType.getLastChangedOn());
        // .//GEN-END:_buildDto_LastChangedOn_1_be
        // .//GEN-BEGIN:_buildDto_LastChangedBy_1_be
        output.setLastChangedBy(printerOutputType.getLastChangedBy());
        // .//GEN-END:_buildDto_LastChangedBy_1_be
        // .//GEN-BEGIN:_buildDto_2_be
        // Add related objects, if required
        addRelatedDtos(uow, output, printerOutputType);
    // .//GEN-END:_buildDto_2_be
    // Add custom code to pass values to the dto //GEN-FIRST:_buildDto_2
    // .//GEN-LAST:_buildDto_2
    // .//GEN-BEGIN:_buildDto_3_be
    }
    return output;
}
Also used : PrinterOutputTypeViewerOutDto(org.jaffa.modules.printing.components.printeroutputtypeviewer.dto.PrinterOutputTypeViewerOutDto) PrinterOutputType(org.jaffa.modules.printing.domain.PrinterOutputType)

Example 2 with PrinterOutputType

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

the class FormDefinition method findPrinterOutputTypeObject.

/**
 * Finds the related foreign PrinterOutputType object.
 * If checkExistenceOnly is false, then the foreign object will be fetched and assigned to the corresponding member variable of this class.
 * If checkExistenceOnly is true, then a mere existence check is performed for the foreign object, as oppposed to fetching all the values for that object.
 */
private void findPrinterOutputTypeObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
    UOW uow = getUOW();
    boolean localUow = false;
    try {
        if (m_printerOutputTypeObject == null && getOutputType() != null) {
            Criteria criteria = new Criteria();
            criteria.setTable(PrinterOutputTypeMeta.getName());
            criteria.addCriteria(PrinterOutputTypeMeta.OUTPUT_TYPE, getOutputType());
            if (checkExistenceOnly)
                criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
            Number count = null;
            if (uow == null || !uow.isActive()) {
                uow = new UOW();
                localUow = true;
            }
            Iterator itr = uow.query(criteria).iterator();
            if (itr.hasNext()) {
                if (checkExistenceOnly)
                    count = (Number) ((Map) itr.next()).get(Criteria.ID_FUNCTION_COUNT);
                else
                    m_printerOutputTypeObject = (PrinterOutputType) itr.next();
            }
            if (m_printerOutputTypeObject == null && (count == null || count.intValue() <= 0))
                throw new InvalidForeignKeyException(FormDefinitionMeta.META_OUTPUT_TYPE.getLabelToken(), new Object[] { PrinterOutputTypeMeta.getLabelToken(), PrinterOutputTypeMeta.META_OUTPUT_TYPE.getLabelToken() });
        }
    } finally {
        if (localUow && uow != null)
            uow.rollback();
    }
}
Also used : PrinterOutputType(org.jaffa.modules.printing.domain.PrinterOutputType) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException)

Example 3 with PrinterOutputType

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

the class OutputCommand method findPrinterOutputTypeObject.

/**
 * Finds the related foreign PrinterOutputType object.
 * If checkExistenceOnly is false, then the foreign object will be fetched and assigned to the corresponding member variable of this class.
 * If checkExistenceOnly is true, then a mere existence check is performed for the foreign object, as oppposed to fetching all the values for that object.
 */
private void findPrinterOutputTypeObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
    UOW uow = getUOW();
    boolean localUow = false;
    try {
        if (m_printerOutputTypeObject == null && getOutputType() != null) {
            Criteria criteria = new Criteria();
            criteria.setTable(PrinterOutputTypeMeta.getName());
            criteria.addCriteria(PrinterOutputTypeMeta.OUTPUT_TYPE, getOutputType());
            if (checkExistenceOnly)
                criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
            Number count = null;
            if (uow == null || !uow.isActive()) {
                uow = new UOW();
                localUow = true;
            }
            Iterator itr = uow.query(criteria).iterator();
            if (itr.hasNext()) {
                if (checkExistenceOnly)
                    count = (Number) ((Map) itr.next()).get(Criteria.ID_FUNCTION_COUNT);
                else
                    m_printerOutputTypeObject = (PrinterOutputType) itr.next();
            }
            if (m_printerOutputTypeObject == null && (count == null || count.intValue() <= 0))
                throw new InvalidForeignKeyException(OutputCommandMeta.META_OUTPUT_TYPE.getLabelToken(), new Object[] { PrinterOutputTypeMeta.getLabelToken(), PrinterOutputTypeMeta.META_OUTPUT_TYPE.getLabelToken() });
        }
    } finally {
        if (localUow && uow != null)
            uow.rollback();
    }
}
Also used : PrinterOutputType(org.jaffa.modules.printing.domain.PrinterOutputType) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException)

Example 4 with PrinterOutputType

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

the class PrinterDefinition method findPrinterOutputTypeObject.

/**
 * Finds the related foreign PrinterOutputType object.
 * If checkExistenceOnly is false, then the foreign object will be fetched and assigned to the corresponding member variable of this class.
 * If checkExistenceOnly is true, then a mere existence check is performed for the foreign object, as oppposed to fetching all the values for that object.
 */
private void findPrinterOutputTypeObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
    UOW uow = getUOW();
    boolean localUow = false;
    try {
        if (m_printerOutputTypeObject == null && getOutputType() != null) {
            Criteria criteria = new Criteria();
            criteria.setTable(PrinterOutputTypeMeta.getName());
            criteria.addCriteria(PrinterOutputTypeMeta.OUTPUT_TYPE, getOutputType());
            if (checkExistenceOnly)
                criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
            Number count = null;
            if (uow == null || !uow.isActive()) {
                uow = new UOW();
                localUow = true;
            }
            Iterator itr = uow.query(criteria).iterator();
            if (itr.hasNext()) {
                if (checkExistenceOnly)
                    count = (Number) ((Map) itr.next()).get(Criteria.ID_FUNCTION_COUNT);
                else
                    m_printerOutputTypeObject = (PrinterOutputType) itr.next();
            }
            if (m_printerOutputTypeObject == null && (count == null || count.intValue() <= 0))
                throw new InvalidForeignKeyException(PrinterDefinitionMeta.META_OUTPUT_TYPE.getLabelToken(), new Object[] { PrinterOutputTypeMeta.getLabelToken(), PrinterOutputTypeMeta.META_OUTPUT_TYPE.getLabelToken() });
        }
    } finally {
        if (localUow && uow != null)
            uow.rollback();
    }
}
Also used : PrinterOutputType(org.jaffa.modules.printing.domain.PrinterOutputType) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException)

Example 5 with PrinterOutputType

use of org.jaffa.modules.printing.domain.PrinterOutputType 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)

Aggregations

PrinterOutputType (org.jaffa.modules.printing.domain.PrinterOutputType)17 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)10 ApplicationException (org.jaffa.exceptions.ApplicationException)6 UOW (org.jaffa.persistence.UOW)6 FrameworkException (org.jaffa.exceptions.FrameworkException)5 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)4 InvalidForeignKeyException (org.jaffa.datatypes.exceptions.InvalidForeignKeyException)3 Criteria (org.jaffa.persistence.Criteria)3 DateTime (org.jaffa.datatypes.DateTime)1 ValidationException (org.jaffa.datatypes.ValidationException)1 PrinterOutputTypeFinderOutDto (org.jaffa.modules.printing.components.printeroutputtypefinder.dto.PrinterOutputTypeFinderOutDto)1 PrinterOutputTypeFinderOutRowDto (org.jaffa.modules.printing.components.printeroutputtypefinder.dto.PrinterOutputTypeFinderOutRowDto)1 PrinterOutputTypeLookupOutDto (org.jaffa.modules.printing.components.printeroutputtypelookup.dto.PrinterOutputTypeLookupOutDto)1 PrinterOutputTypeLookupOutRowDto (org.jaffa.modules.printing.components.printeroutputtypelookup.dto.PrinterOutputTypeLookupOutRowDto)1 PrinterOutputTypeViewerOutDto (org.jaffa.modules.printing.components.printeroutputtypeviewer.dto.PrinterOutputTypeViewerOutDto)1 OutputCommand (org.jaffa.modules.printing.domain.OutputCommand)1 PrinterDefinition (org.jaffa.modules.printing.domain.PrinterDefinition)1