use of org.jaffa.modules.printing.domain.FormTemplate in project jaffa-framework by jaffa-projects.
the class FormDefinitionViewerTx method loadFormTemplate.
public byte[] loadFormTemplate(FormDefinitionViewerInDto input) throws FrameworkException, ApplicationExceptions {
UOW uow = new UOW();
try {
Criteria criteria = new Criteria();
criteria.setTable(FormTemplateMeta.getName());
criteria.addCriteria(FormTemplateMeta.FORM_ID, input.getFormId());
Iterator itr = uow.query(criteria).iterator();
if (itr.hasNext()) {
FormTemplate formTemplate = (FormTemplate) itr.next();
formTemplateContents = formTemplate.getTemplateData();
}
} finally {
if (uow != null)
uow.rollback();
}
return formTemplateContents;
}
use of org.jaffa.modules.printing.domain.FormTemplate in project jaffa-framework by jaffa-projects.
the class FormCache method getTemplate.
/**
* Get the template file out of the BLOB's, write them to a file, and
* return the path to that file.
* A temp location for this can be defined, and in this case it will
* cache them there and only read them from the database if they don't exist,
* or are older that the database time stamp.
*/
public String getTemplate(FormDefinition form, String engineType) throws FrameworkException {
String extn = ".tpl";
if (FormPrintFactory.ENGINE_TYPE_ITEXT.equals(engineType) || FormPrintFactory.ENGINE_TYPE_PDFLIB.equals(engineType)) {
extn = ".pdf";
} else if (FormPrintFactory.ENGINE_TYPE_FOP.equals(engineType)) {
extn = ".xslt";
}
File temp = new File(getTemplatePath(), form.getFormId() + extn);
// See if a cached version can be returned
if (temp.exists() && ((form.getLastChangedOn() == null && form.getCreatedOn() != null && temp.lastModified() > form.getCreatedOn().timeInMillis()) || (form.getLastChangedOn() != null && temp.lastModified() > form.getLastChangedOn().timeInMillis()))) {
// If this is itext, make sure the CSV file is also current
if (FormPrintFactory.ENGINE_TYPE_ITEXT.equals(engineType)) {
File tempCsv = new File(getTemplatePath(), form.getFormId() + extn + ".csv");
// See if a cached version can be returned
if (tempCsv.exists() && ((form.getLastChangedOn() == null && form.getCreatedOn() != null && tempCsv.lastModified() > form.getCreatedOn().timeInMillis()) || (form.getLastChangedOn() != null && tempCsv.lastModified() > form.getLastChangedOn().timeInMillis()))) {
log.debug("Use Cached Template/CSV :" + temp.getAbsolutePath());
return temp.getAbsolutePath();
}
} else {
log.debug("Use Cached Template :" + temp.getAbsolutePath());
return temp.getAbsolutePath();
}
}
// Extract this from the Database
FormTemplate formTemp = form.getFormTemplateObject();
if (formTemp == null)
return null;
// Write out the template file
if (temp.exists())
temp.delete();
if (formTemp.getTemplateData() != null) {
if (!temp.getParentFile().exists())
temp.getParentFile().mkdirs();
try {
if (FormPrintFactory.ENGINE_TYPE_FOP.equals(engineType)) {
InputStream xsltTransformer = URLHelper.getInputStream(XSLT_TRANSFORMER);
try {
// Do all necessary transformations to the form XSLT file
XmlTransformerUtil.transform(formTemp.getTemplateData(), xsltTransformer, temp);
} catch (TransformerException e) {
String err = "Failed to Transform and write the Form Template " + temp.getAbsolutePath();
log.error(err, e);
throw new EngineProcessingException(err, e);
}
} else {
try (FileOutputStream fos = new FileOutputStream(temp)) {
fos.write(formTemp.getTemplateData());
}
}
log.debug("Written Template File " + temp.getAbsolutePath());
} catch (IOException e) {
String err = "Failed to write Template File " + temp.getAbsolutePath();
log.error(err, e);
throw new EngineProcessingException(err, e);
}
} else {
log.warn("No Template In Form Definition " + form.getFormId() + "(Name=" + form.getFormName() + ",Alt=" + form.getFormAlternate() + ",Variation=" + form.getFormVariation() + ",Output" + form.getOutputType());
}
File tempLayout = null;
// If the engine type is itext, specify where the CSV file should be written
if (FormPrintFactory.ENGINE_TYPE_ITEXT.equals(engineType))
tempLayout = new File(getTemplatePath(), form.getFormId() + ".pdf.csv");
// See if there is layout data needed
if (tempLayout != null) {
if (tempLayout.exists())
tempLayout.delete();
if (formTemp.getLayoutData() != null) {
try (FileOutputStream fos = new FileOutputStream(tempLayout)) {
fos.write(formTemp.getLayoutData());
log.debug("Written Template Layout File " + tempLayout.getAbsolutePath());
} catch (IOException e) {
String err = "Failed to write Layout File " + tempLayout.getAbsolutePath();
log.error(err, e);
throw new EngineProcessingException(err, e);
}
}
}
// return the temp file
return temp.getAbsolutePath();
}
use of org.jaffa.modules.printing.domain.FormTemplate in project jaffa-framework by jaffa-projects.
the class FormTemplateLookupTx method buildDto.
// .//GEN-END:_buildCriteria_3_be
// .//GEN-BEGIN:_buildDto_1_be
private FormTemplateLookupOutDto buildDto(UOW uow, Collection results, FormTemplateLookupInDto input) throws UOWException {
FormTemplateLookupOutDto output = new FormTemplateLookupOutDto();
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;
}
FormTemplateLookupOutRowDto row = new FormTemplateLookupOutRowDto();
FormTemplate formTemplate = (FormTemplate) 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_FormId_1_be
row.setFormId(formTemplate.getFormId());
// .//GEN-END:_buildDto_FormId_1_be
// .//GEN-BEGIN:_buildDto_TemplateData_1_be
row.setTemplateData(formTemplate.getTemplateData());
// .//GEN-END:_buildDto_TemplateData_1_be
// .//GEN-BEGIN:_buildDto_LayoutData_1_be
row.setLayoutData(formTemplate.getLayoutData());
// .//GEN-END:_buildDto_LayoutData_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;
}
use of org.jaffa.modules.printing.domain.FormTemplate in project jaffa-framework by jaffa-projects.
the class FormTemplateMaintenanceTx method load.
// .//GEN-END:_preprocessUpdate_2_be
// .//GEN-BEGIN:_loadUpdate_1_be
/**
* Retrieve the domain object.
*/
private FormTemplate load(UOW uow, FormTemplateMaintenanceUpdateInDto input) throws FrameworkException, ApplicationExceptions {
FormTemplate domain = null;
Criteria criteria = new Criteria();
criteria.setTable(FormTemplateMeta.getName());
// .//GEN-END:_loadUpdate_1_be
// Add custom criteria //GEN-FIRST:_loadUpdate_1
// .//GEN-LAST:_loadUpdate_1
// .//GEN-BEGIN:_loadUpdate_2_be
criteria.addCriteria(FormTemplateMeta.FORM_ID, input.getFormId());
criteria.setLocking(Criteria.LOCKING_PARANOID);
Iterator itr = uow.query(criteria).iterator();
if (itr.hasNext())
domain = (FormTemplate) itr.next();
// .//GEN-BEGIN:_loadUpdate_3_be
if (domain == null) {
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add(new DomainObjectNotFoundException(FormTemplateMeta.getLabelToken()));
throw appExps;
}
return domain;
}
use of org.jaffa.modules.printing.domain.FormTemplate in project jaffa-framework by jaffa-projects.
the class FormTemplateMaintenanceTx 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 FormTemplate.
* @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 FormTemplateMaintenancePrevalidateOutDto prevalidateCreate(FormTemplateMaintenanceCreateInDto 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
FormTemplate domain = createDomain(uow, input, true);
// Perform post create processing
postCreate(uow, input, domain, true);
// Build the outbound dto
FormTemplateMaintenancePrevalidateOutDto 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();
}
}
Aggregations