use of org.jaffa.components.attachment.domain.Attachment in project jaffa-framework by jaffa-projects.
the class AttachmentMaintenanceTx method load.
// .//GEN-END:_preprocessRetrieve_2_be
// .//GEN-BEGIN:_loadRetrieve_1_be
/**
* Retrieve the domain object.
*/
private Attachment load(UOW uow, AttachmentMaintenanceRetrieveInDto input) throws FrameworkException, ApplicationExceptions {
Attachment domain = null;
Criteria criteria = new Criteria();
criteria.setTable(AttachmentMeta.getName());
// .//GEN-END:_loadRetrieve_1_be
// Add custom criteria //GEN-FIRST:_loadRetrieve_1
// .//GEN-LAST:_loadRetrieve_1
// .//GEN-BEGIN:_loadRetrieve_2_be
criteria.addCriteria(AttachmentMeta.ATTACHMENT_ID, input.getAttachmentId());
Iterator itr = uow.query(criteria).iterator();
if (itr.hasNext())
domain = (Attachment) itr.next();
// .//GEN-BEGIN:_loadRetrieve_3_be
if (domain == null) {
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add(new DomainObjectNotFoundException(AttachmentMeta.getLabelToken()));
throw appExps;
}
return domain;
}
use of org.jaffa.components.attachment.domain.Attachment in project jaffa-framework by jaffa-projects.
the class AttachmentMaintenanceTx method retrieve.
// .//GEN-END:_create_1_be
// .//GEN-BEGIN:_retrieve_1_be
/**
* Returns the details for Attachment.
* @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 AttachmentMaintenanceRetrieveOutDto retrieve(AttachmentMaintenanceRetrieveInDto 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
Attachment domain = load(uow, input);
// Convert the domain objects into the outbound dto
AttachmentMaintenanceRetrieveOutDto output = buildRetrieveOutDto(uow, input, domain);
// 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.components.attachment.domain.Attachment in project jaffa-framework by jaffa-projects.
the class AttachmentMaintenanceTx method load.
// .//GEN-END:_preprocessDelete_2_be
// .//GEN-BEGIN:_loadDelete_1_be
/**
* Retrieve the domain object.
*/
private Attachment load(UOW uow, AttachmentMaintenanceDeleteInDto input) throws FrameworkException, ApplicationExceptions {
Attachment domain = null;
Criteria criteria = new Criteria();
criteria.setTable(AttachmentMeta.getName());
// .//GEN-END:_loadDelete_1_be
// Add custom criteria //GEN-FIRST:_loadDelete_1
// .//GEN-LAST:_loadDelete_1
// .//GEN-BEGIN:_loadDelete_2_be
criteria.addCriteria(AttachmentMeta.ATTACHMENT_ID, input.getAttachmentId());
criteria.setLocking(Criteria.LOCKING_PARANOID);
Iterator itr = uow.query(criteria).iterator();
if (itr.hasNext())
domain = (Attachment) itr.next();
// .//GEN-BEGIN:_loadDelete_3_be
if (domain == null) {
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add(new DomainObjectNotFoundException(AttachmentMeta.getLabelToken()));
throw appExps;
}
return domain;
}
use of org.jaffa.components.attachment.domain.Attachment in project jaffa-framework by jaffa-projects.
the class AttachmentMaintenanceTx method create.
// .//GEN-END:_prevalidateCreate_1_be
// .//GEN-BEGIN:_create_1_be
/**
* Persists a new instance of Attachment.
* @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 AttachmentMaintenanceRetrieveOutDto create(AttachmentMaintenanceCreateInDto 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
Attachment domain = createDomain(uow, input, false);
uow.add(domain);
domain = 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.");
if (input.getAttachmentId() == 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
AttachmentMaintenanceRetrieveInDto retrieveInDto = new AttachmentMaintenanceRetrieveInDto();
retrieveInDto.setHeaderDto(input.getHeaderDto());
retrieveInDto.setAttachmentId(input.getAttachmentId());
AttachmentMaintenanceRetrieveOutDto 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.components.attachment.domain.Attachment in project jaffa-framework by jaffa-projects.
the class AttachmentService method createAttachment.
/**
* Creates an Attachment domain object based on the input.
* @param attachTo the domain object to which the attachment is related. It is used for determining the serializedKey of the Attachment domain object being created.
* @param attachment the attachment. It is used for determining the data and originalFileName of the Attachment domain object being created.
* @throws FrameworkException If any system error occurs.
* @throws ApplicationExceptions If any application error occurs.
* @return the Attachment domain object.
*/
public static Attachment createAttachment(IPersistent attachTo, Object attachment) throws FrameworkException, ApplicationExceptions {
try {
Attachment a = new Attachment();
a.setSerializedKey(PersistentHelper.generateSerializedKey(attachTo));
a.setAttachmentType("E");
a.setData(createAttachmentData(attachment));
a.setOriginalFileName(createAttachmentName(attachment));
a.setContentType(createContentType(attachment));
// a.setRemarks(null);
if (log.isDebugEnabled())
log.debug("Created attachment object " + a);
return a;
} catch (Exception e) {
throw ExceptionHelper.throwAFR(e);
}
}
Aggregations