use of org.jaffa.modules.printing.domain.FormTemplate in project jaffa-framework by jaffa-projects.
the class FormDefinitionMaintenanceTx method create.
// .//GEN-END:_prevalidateCreate_1_be
// .//GEN-BEGIN:_create_1_be
/**
* Persists a new instance of FormDefinition.
* @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 FormDefinitionMaintenanceRetrieveOutDto create(FormDefinitionMaintenanceCreateInDto 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
FormDefinition domain = createDomain(uow, input, false);
uow.add(domain);
domain = postCreate(uow, input, domain, false);
FormTemplate formTemplate = createOrLoadFormTemplate(uow, input, domain, false);
if (formTemplate != null && formTemplate.isModified()) {
if (formTemplate.isDatabaseOccurence())
uow.update(formTemplate);
else
uow.add(formTemplate);
}
// 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.");
if (input.getFormId() == null) {
if (log.isDebugEnabled())
log.debug("The Key is not set completely. Probably using AutoGenerated keys. Cannot re-retrieve the object details. Returning NULL instead");
return null;
}
// Build the outbound dto by performing a retrieve
FormDefinitionMaintenanceRetrieveInDto retrieveInDto = new FormDefinitionMaintenanceRetrieveInDto();
retrieveInDto.setHeaderDto(input.getHeaderDto());
retrieveInDto.setFormId(input.getFormId());
FormDefinitionMaintenanceRetrieveOutDto 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.FormTemplate in project jaffa-framework by jaffa-projects.
the class FormDefinitionMaintenanceTx method createOrLoadFormTemplate.
// .//GEN-END:_domainObjectChangedTest_1_be
// .//GEN-BEGIN:_createOrLoadFormTemplate_1_be
/**
* Create Or Load an existing instance of FormTemplate which has a 1-to-1 relationship with the domain object.
*/
private FormTemplate createOrLoadFormTemplate(UOW uow, FormDefinitionMaintenanceCreateInDto input, FormDefinition domain, boolean fromPrevalidate) throws FrameworkException, ApplicationExceptions {
FormTemplate formTemplate = null;
ApplicationExceptions appExps = null;
// .//GEN-BEGIN:_createOrLoadFormTemplate_2_be
if (domain.getFormId() != null) {
// load an existing instance
Criteria criteria = new Criteria();
criteria.setTable(FormTemplateMeta.getName());
criteria.addCriteria(FormTemplateMeta.FORM_ID, domain.getFormId());
// .//GEN-END:_createOrLoadFormTemplate_2_be
// Add custom code//GEN-FIRST:_createOrLoadFormTemplate_2
// .//GEN-LAST:_createOrLoadFormTemplate_2
// .//GEN-BEGIN:_createOrLoadFormTemplate_3_be
Iterator itrOne = uow.query(criteria).iterator();
if (itrOne.hasNext())
formTemplate = (FormTemplate) itrOne.next();
}
// create if it doesn't already exist
if (formTemplate == null)
formTemplate = new FormTemplate();
// Update the template if a file has been uploaded
if (input.getFormTemplate() != null) {
try {
formTemplate.setTemplateData(input.getTemplateData());
} catch (ValidationException e) {
throw new ApplicationExceptions(new ApplicationException("exception.Jaffa.Printing.FormDefinitionMaintenance.UploadTemplateData") {
});
}
}
if (input.getFieldLayout() != null) {
try {
formTemplate.setLayoutData(input.getLayoutData());
} catch (ValidationException e) {
throw new ApplicationExceptions(new ApplicationException("exception.Jaffa.Printing.FormDefinitionMaintenance.UploadLayOutData") {
});
}
}
if (!formTemplate.isDatabaseOccurence() && formTemplate.isModified()) {
// Finally set the join-fields
try {
formTemplate.updateFormId(domain.getFormId());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
}
// .//GEN-BEGIN:_createOrLoadFormTemplate_5_be
if (appExps != null && appExps.size() > 0)
throw appExps;
return formTemplate;
}
use of org.jaffa.modules.printing.domain.FormTemplate in project jaffa-framework by jaffa-projects.
the class FormDefinitionMaintenanceTx 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 FormDefinition.
* @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 FormDefinitionMaintenancePrevalidateOutDto prevalidateCreate(FormDefinitionMaintenanceCreateInDto 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
FormDefinition domain = createDomain(uow, input, true);
domain = postCreate(uow, input, domain, true);
FormTemplate formTemplate = createOrLoadFormTemplate(uow, input, domain, true);
// Build the outbound dto
FormDefinitionMaintenancePrevalidateOutDto 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();
}
}
Aggregations