use of org.jaffa.modules.printing.domain.PrinterDefinition in project jaffa-framework by jaffa-projects.
the class FormSelectionMaintenanceTx method determinePrintersPerOutputType.
/**
* Creates a Map of printers keyed by the outputType.
* @param uow The UOW.
* @param defaultPrinters The printers to be added to the Map. If a printer is invalid, it'll be ignored.
* @return Map of printers keyed by the outputType.
* @throws FrameworkException Indicates some system error
*/
private Map<String, List<String>> determinePrintersPerOutputType(UOW uow, String[] defaultPrinters) throws FrameworkException {
// Log the input
if (log.isDebugEnabled()) {
StringBuffer buf = new StringBuffer("Input to determinePrintersPerOutputType(): ");
for (int i = 0; i < defaultPrinters.length; i++) {
if (i > 0)
buf.append(',');
buf.append(defaultPrinters[i]);
}
log.debug(buf.toString());
}
// Generate the Map
Map<String, List<String>> printersPerOutputType = new HashMap<String, List<String>>();
for (String printer : defaultPrinters) {
PrinterDefinition pd = PrinterDefinition.findByPK(uow, printer);
if (pd != null && pd.getOutputType() != null) {
List<String> printers = printersPerOutputType.get(pd.getOutputType());
if (printers == null) {
printers = new LinkedList<String>();
printersPerOutputType.put(pd.getOutputType(), printers);
}
printers.add(printer);
} else {
if (log.isDebugEnabled())
log.debug("The default printer '" + printer + "' has not been setup for JaffaComponentsPrinting. It'll be ignored");
}
}
// Log the output
if (log.isDebugEnabled()) {
StringBuffer buf = new StringBuffer("Output from determinePrintersPerOutputType():\n");
for (Map.Entry<String, List<String>> me : printersPerOutputType.entrySet()) {
buf.append(me.getKey()).append('=');
boolean printerAdded = false;
for (String printer : me.getValue()) {
if (!printerAdded)
printerAdded = true;
else
buf.append(',');
buf.append(printer);
}
buf.append('\n');
}
log.debug(buf.toString());
}
return printersPerOutputType;
}
use of org.jaffa.modules.printing.domain.PrinterDefinition in project jaffa-framework by jaffa-projects.
the class PrinterOutputType method newPrinterDefinitionObject.
/**
* Creates a new PrinterDefinition object and initializes the related fields.
* This will uncache the related PrinterDefinition objects.
* @throws ValidationException if an invalid value is passed.
* @throws FrameworkException Indicates some system error
* @return the related PrinterDefinition object with the initialized related fields.
*/
public PrinterDefinition newPrinterDefinitionObject() throws ValidationException, FrameworkException {
m_printerDefinitionCollection = null;
PrinterDefinition printerDefinition = new PrinterDefinition();
printerDefinition.setOutputType(getOutputType());
// .//GEN-BEGIN:printerDefinitionArray_3_be
return printerDefinition;
}
use of org.jaffa.modules.printing.domain.PrinterDefinition 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();
}
}
use of org.jaffa.modules.printing.domain.PrinterDefinition in project jaffa-framework by jaffa-projects.
the class PrinterDefinitionMaintenanceTx method create.
// .//GEN-END:_prevalidateCreate_1_be
// .//GEN-BEGIN:_create_1_be
/**
* Persists a new instance of PrinterDefinition.
* @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 PrinterDefinitionMaintenanceRetrieveOutDto create(PrinterDefinitionMaintenanceCreateInDto 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
PrinterDefinition domain = createDomain(uow, input, false);
uow.add(domain);
// Perform post create processing
postCreate(uow, input, domain, false);
// Commit the changes
uow.commit();
// Print Debug Information for the output
if (log.isDebugEnabled())
log.debug("Successfully created the domain object. Now retrieving the object details.");
// Build the outbound dto by performing a retrieve
PrinterDefinitionMaintenanceRetrieveInDto retrieveInDto = new PrinterDefinitionMaintenanceRetrieveInDto();
retrieveInDto.setHeaderDto(input.getHeaderDto());
retrieveInDto.setPrinterId(input.getPrinterId());
PrinterDefinitionMaintenanceRetrieveOutDto output = retrieve(retrieveInDto);
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();
}
}
use of org.jaffa.modules.printing.domain.PrinterDefinition in project jaffa-framework by jaffa-projects.
the class PrinterDefinitionMaintenanceTx method retrieve.
// .//GEN-END:_create_1_be
// .//GEN-BEGIN:_retrieve_1_be
/**
* Returns the details for PrinterDefinition.
* @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 PrinterDefinitionMaintenanceRetrieveOutDto retrieve(PrinterDefinitionMaintenanceRetrieveInDto 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
PrinterDefinition domain = load(uow, input);
// Convert the domain objects into the outbound dto
PrinterDefinitionMaintenanceRetrieveOutDto output = buildRetrieveOutDto(uow, input, domain);
// 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();
}
}
Aggregations