use of org.jaffa.exceptions.ApplicationException in project jaffa-framework by jaffa-projects.
the class FormGroupMaintenanceTx method create.
// .//GEN-END:_prevalidateCreate_1_be
// .//GEN-BEGIN:_create_1_be
/**
* Persists a new instance of FormGroup.
* @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 FormGroupMaintenanceRetrieveOutDto create(FormGroupMaintenanceCreateInDto input) throws FrameworkException, ApplicationExceptions {
UOW uow = null;
try {
// Print Debug Information for the input
if (log.isDebugEnabled())
log.debug("Input: " + input);
// 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
FormGroup 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
FormGroupMaintenanceRetrieveInDto retrieveInDto = new FormGroupMaintenanceRetrieveInDto();
retrieveInDto.setHeaderDto(input.getHeaderDto());
retrieveInDto.setFormName(input.getFormName());
FormGroupMaintenanceRetrieveOutDto 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.exceptions.ApplicationException in project jaffa-framework by jaffa-projects.
the class PrinterOutputTypeMaintenanceTx method prevalidateUpdate.
// .//GEN-END:_retrieve_1_be
// .//GEN-BEGIN:_prevalidateUpdate_1_be
/**
* This method is used to perform prevalidations before updating an existing instance of PrinterOutputType.
* @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 PrinterOutputTypeMaintenancePrevalidateOutDto prevalidateUpdate(PrinterOutputTypeMaintenanceUpdateInDto input) throws FrameworkException, ApplicationExceptions {
UOW uow = null;
try {
// Print Debug Information for the input
if (log.isDebugEnabled())
log.debug("Input: " + input);
// create the UOW
uow = new UOW();
// Preprocess the input
preprocess(uow, input);
// Retrieve the object
PrinterOutputType domain = load(uow, input);
// Ensure the domain object has not been modified
domainObjectChangedTest(input.getPerformDirtyReadCheck(), domain, input.getLastChangedOn());
// Validate the foreign objects
validateForeignObjects(uow, input);
// Update the domain object
updateDomain(uow, input, domain, true);
// Build the outbound dto
PrinterOutputTypeMaintenancePrevalidateOutDto output = createPrevalidateOutDto(uow, domain, input);
// Print Debug Information for the output
if (log.isDebugEnabled())
log.debug("Output: " + output);
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.exceptions.ApplicationException in project jaffa-framework by jaffa-projects.
the class PrinterOutputTypeMaintenanceTx 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 PrinterOutputType.
* @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 PrinterOutputTypeMaintenancePrevalidateOutDto prevalidateCreate(PrinterOutputTypeMaintenanceCreateInDto input) throws FrameworkException, ApplicationExceptions {
UOW uow = null;
try {
// Print Debug Information for the input
if (log.isDebugEnabled())
log.debug("Input: " + input);
// 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
PrinterOutputType domain = createDomain(uow, input, true);
domain = postCreate(uow, input, domain, true);
// Build the outbound dto
PrinterOutputTypeMaintenancePrevalidateOutDto output = createPrevalidateOutDto(uow, domain, input);
// Print Debug Information for the output
if (log.isDebugEnabled())
log.debug("Output: " + output);
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.exceptions.ApplicationException in project jaffa-framework by jaffa-projects.
the class FormData method renderTemplate.
public String[] renderTemplate() throws ApplicationExceptions {
if (m_velocityTemplate != null && m_velocityTemplate.length() > 0 && !m_velocityTemplate.startsWith("???")) {
try {
VelocityTemplateHelper vth = new VelocityTemplateHelper();
vth.setDataSource(this);
vth.setTemplate(m_velocityTemplate);
return (vth.renderTemplateLines());
} catch (FormPrintException fpe) {
fpe.printStackTrace();
throw new ApplicationExceptions(new ApplicationException("exception.org.jaffa.modules.printing.services.FormData.VelocityTemplateError") {
});
}
} else {
return (null);
}
}
use of org.jaffa.exceptions.ApplicationException in project jaffa-framework by jaffa-projects.
the class FormProcessor method process.
/**
* Process the FormPrintRequest. This will look at the form definition to use, locate it, build the
* databean to use, and generate the output form. If follow-on forms are needed these will be generated
* and merged in. It will then either print or email the generate form.<p>
* Modified so 'null' DocumentObject will not create blank pages. If no pages are added, nothing will be delivered
*
* @param request the object that contains the key to the data, the form to be printed and
* details about the printer and/or email that should be used for the output
* @throws org.jaffa.exceptions.FrameworkException thrown if there is an infrastructure error
* @throws org.jaffa.exceptions.ApplicationExceptions throw if there is an application error that should be repoted to the user
*/
public static void process(FormPrintRequest request) throws FrameworkException, ApplicationExceptions {
if (log.isDebugEnabled()) {
log.debug("Begin processing form print request. Form name = " + request.getFormName() + ", Form Alternate = " + request.getFormAlternateName() + ", Form Variation = " + request.getVariation() + ", Printer Id = " + request.getPrinterId() + ", Email Address = " + request.getEmailToAddresses() + ", User = " + request.getUserName() + ", Copies = " + request.getPrintCopies());
}
Map<IDataBean, DocumentPrintedListener> printedListeners = new HashMap<IDataBean, DocumentPrintedListener>();
File outFile = null;
UOW uow = new UOW();
FormCache cache = new FormCache();
MultiFormPrintEngine engine = null;
// Get Locale Country
Locale localeObject = LocaleContext.getLocale();
String country = localeObject != null ? localeObject.getCountry() : null;
String formOutputType = null;
try {
// Lookup the printer, to get the output type
PrinterDefinition printer = null;
String outputType = null;
if (request.getPrinterId() != null) {
printer = PrinterDefinition.findByPK(uow, request.getPrinterId());
if (printer == null) {
log.error("Invalid printer id on form request: Printer = " + request.getPrinterId());
throw new ApplicationExceptions(new DomainObjectNotFoundException(PrinterDefinitionMeta.getLabelToken()));
}
outputType = printer.getOutputType();
}
String formName = request.getFormName();
String alternateName = request.getFormAlternateName();
String variation = request.getVariation();
String[] keyNames = null;
if (request.getKeys() != null) {
keyNames = (String[]) request.getKeys().keySet().toArray(new String[] {});
}
Object firstDom = null;
int documentCounter = 0;
// Main assemble loop if this has follow-on forms
while (formName != null) {
FormDefinition formDefinition = findFormDefinition(uow, formName, alternateName, variation, outputType, keyNames);
if (formDefinition == null) {
if (outputType == null) {
log.error("Form Not Found. Name=" + request.getFormName() + ", Alt=" + request.getFormAlternateName() + ", Variation=" + request.getVariation() + ", OutputType=" + outputType);
throw new ApplicationExceptions(new DomainObjectNotFoundException(FormDefinitionMeta.getLabelToken()));
} else {
outputType = null;
formDefinition = findFormDefinition(uow, formName, alternateName, variation, outputType, keyNames);
if (formDefinition == null) {
log.error("Form Not Found. Name=" + request.getFormName() + ", Alt=" + request.getFormAlternateName() + ", Variation=" + request.getVariation() + ", OutputType=" + outputType);
throw new ApplicationExceptions(new DomainObjectNotFoundException(FormDefinitionMeta.getLabelToken()));
} else {
throw new ApplicationExceptions(new ApplicationException("exception.org.jaffa.modules.printing.services.FormProcessor.OutputTypeMismatch") {
});
}
}
}
formOutputType = formDefinition.getOutputType();
// See if we have the DOM for this form already, if not build it
IDataBean data = cache.lookupForm(formDefinition);
if (data == null) {
// build the form DOM
data = buildDataBean(request, formDefinition);
cache.addForm(formDefinition, data);
// the FormPrintRequest or as a FollowOnFormAlternate.
if (alternateName == null) {
if (data.getFormAlternateName() != null) {
log.debug("Form " + formName + " switch to alternateName " + data.getFormAlternateName() + " from " + alternateName);
alternateName = data.getFormAlternateName();
continue;
}
}
}
// Add this form for printing
if (engine == null) {
// set up the engine
engine = new MultiFormPrintEngine();
// get the form type so the correct factory can be set...
try {
engine.setEngineType(formDefinition.getFormGroupObject().getFormType());
} catch (ValidationException e) {
// This should only happen if the FormGroup object is not found
throw new ApplicationExceptions(e);
}
}
String templateName = cache.getTemplate(formDefinition, engine.getEngineType());
// If data.getDocumentRoot() is an object array, add a document for each entry in the array.
if (data.getDocumentRoot() != null && data.getDocumentRoot().getClass().isArray()) {
Object[] doms = (Object[]) data.getDocumentRoot();
for (int i = 0; i < doms.length; i++) {
if (firstDom == null) {
firstDom = doms[i];
}
// Only add document if it has data
if (doms[i] != null) {
documentCounter++;
engine.addDocument(templateName, doms[i]);
}
}
if ("<CREATE XML FILE>".equals(formDefinition.getRemarks())) {
writeXsdAndXml(doms[0]);
}
} else {
if (firstDom == null) {
firstDom = data.getDocumentRoot();
}
// Only add document if it has data
if (data.getDocumentRoot() != null) {
documentCounter++;
engine.addDocument(templateName, data.getDocumentRoot());
}
if ("<CREATE XML FILE>".equals(formDefinition.getRemarks())) {
writeXsdAndXml(data.getDocumentRoot());
}
}
// Get the DocumentPrintedListerers for this DataBean, if they have not already be aquired
if (!printedListeners.containsKey(data)) {
printedListeners.put(data, data.getDocumentPrintedListener());
}
// Get the follow-on form so it will be process in the next iteration
formName = formDefinition.getFollowOnFormName();
alternateName = formDefinition.getFollowOnFormAlternate();
}
if (documentCounter == 0) {
log.debug("No pages added to engine, dataBeans were null. No output will be generated");
} else {
// Set override page size for PDF forms
if ("PDF".equals(formOutputType)) {
String pageSize = printer != null && printer.getScaleToPageSize() != null ? printer.getScaleToPageSize() : null;
if (pageSize == null) {
pageSize = (String) ContextManagerFactory.instance().getProperty("jaffa.printing.defaultScaleToPageSize" + "." + country);
}
if (pageSize != null && !"".equals(pageSize)) {
engine.setPageSize(pageSize);
}
}
// Generate the output
engine.generate();
// Get the generated output
if (request.getSaveFileName() != null) {
outFile = engine.writeForm(new File(request.getSaveFileName()));
} else {
outFile = engine.writeForm();
}
if (log.isDebugEnabled()) {
log.debug("Created file : " + (outFile == null ? "NULL!!" : outFile.getAbsolutePath()));
}
// Send file to printer and email if required
if (outFile != null) {
FormDelivery.deliver(request, outFile, firstDom);
}
if (log.isDebugEnabled()) {
log.debug("Returned from delivering the form. Print File: " + (outFile == null ? "NULL" : outFile.getAbsolutePath()));
}
// Invoke all the DocumentPrintedListerer
for (DocumentPrintedListener listener : printedListeners.values()) {
if (listener != null) {
listener.documentPrinted(new EventObject(request));
}
}
if (log.isDebugEnabled()) {
log.debug("Returned from setting form printed date. Print File: " + (outFile == null ? "NULL" : outFile.getAbsolutePath()));
}
}
} finally {
if (uow != null) {
// This UOW should have not been used for updates!!!
uow.rollback();
}
// Clean up the temporary file unless it has been written specifically for web publishing
if (outFile != null) {
if (log.isDebugEnabled()) {
log.debug("FILE NOT CLEANED UP IN DEBUG MODE: " + outFile.getAbsolutePath());
} else if (request.getSaveFileName() == null) {
if (!outFile.delete()) {
log.error("Failed to delete the temporary form file " + outFile.getAbsolutePath());
}
}
}
}
}
Aggregations