use of org.jaffa.components.attachment.apis.IAttachmentData in project jaffa-framework by jaffa-projects.
the class AttachmentHandler method endBeanLoad.
/**
* Called after a bean has been loaded.
* @param path This is the source path of this graph, used when processing a more complex tree, where this is the path to get to this root object being processed.
* @param source the domain object that was just queried.
* @param target the graph object being molded.
* @param filter Filter object that it is used to control what fields are populated or the target objects.
* @param originalCriteria the original graph criteria.
* @throws ApplicationException if any Application error occurs.
* @throws ApplicationExceptions if multiple Application errors occur.
* @throws FrameworkException if an internal error occurs.
*/
@Override
public void endBeanLoad(String path, Object source, Object target, MappingFilter filter, GraphCriteria originalCriteria) throws ApplicationException, ApplicationExceptions, FrameworkException {
checkFunctionAccess((Attachment) source, false);
if (source instanceof Attachment && target instanceof AttachmentGraph) {
AttachmentGraph attachmentGraph = (AttachmentGraph) target;
Attachment attachment = (Attachment) source;
IAttachmentData attachmentDataImpl = AttachmentFactory.getAttachmentDataImpl();
if (attachmentDataImpl != null && attachment.getDocumentReferenceId() != null && (originalCriteria.getResultGraphRules() == null || originalCriteria.getResultGraphRules().length == 0 || !Arrays.asList(originalCriteria.getResultGraphRules()).contains("-data"))) {
byte[] data = attachmentDataImpl.read(attachment.getDocumentReferenceId());
if (data != null) {
attachmentGraph.setData(data);
}
}
}
}
use of org.jaffa.components.attachment.apis.IAttachmentData in project jaffa-framework by jaffa-projects.
the class AttachmentHandler method endBeanClone.
@Override
public void endBeanClone(String path, Object source, Object target, Object newGraph) throws ApplicationException, ApplicationExceptions, FrameworkException {
if (source instanceof AttachmentGraph && target instanceof Attachment) {
AttachmentGraph attachmentGraph = (AttachmentGraph) source;
Attachment attachment = (Attachment) target;
IAttachmentData attachmentDataImpl = AttachmentFactory.getAttachmentDataImpl();
if (attachmentDataImpl != null && attachment.getDocumentReferenceId() != null) {
if (attachmentDataImpl.read(attachment.getDocumentReferenceId()) == null) {
attachmentDataImpl.create(attachment.getDocumentReferenceId(), attachmentGraph.getData());
}
}
}
}
use of org.jaffa.components.attachment.apis.IAttachmentData in project jaffa-framework by jaffa-projects.
the class AttachmentHandler method endBeanAdd.
public void endBeanAdd(String path, Object source, Object target) throws ApplicationException, ApplicationExceptions, FrameworkException {
if (source instanceof AttachmentGraph && target instanceof Attachment) {
AttachmentGraph attachmentGraph = (AttachmentGraph) source;
Attachment attachment = (Attachment) target;
IAttachmentData attachmentDataImpl = AttachmentFactory.getAttachmentDataImpl();
if (attachmentDataImpl != null && attachment.getDocumentReferenceId() != null) {
if (attachmentDataImpl.read(attachment.getDocumentReferenceId()) == null) {
attachmentDataImpl.create(attachment.getDocumentReferenceId(), attachmentGraph.getData());
}
}
}
}
use of org.jaffa.components.attachment.apis.IAttachmentData in project jaffa-framework by jaffa-projects.
the class Attachment method validate.
// .//GEN-END:preUpdate_2_be
// All the custom code goes here//GEN-FIRST:custom
/**
* {@inheritDoc}
*/
@Override
public void validate() throws ApplicationExceptions, FrameworkException {
IAttachmentData attachmentDataImpl = AttachmentFactory.getAttachmentDataImpl();
// Ensure that the attachment is specified
if (attachmentDataImpl == null) {
if (getOriginalFileName() == null || ("E".equals(getAttachmentType()) && (getData() == null || getData().length == 0)))
throw new ApplicationExceptions(new MandatoryFieldException(AttachmentMeta.META_ORIGINAL_FILE_NAME.getLabelToken()));
// Blank out the uploaded data, if any, for a non-embedded attachment
if (!"E".equals(getAttachmentType()) && getData() != null) {
if (log.isDebugEnabled())
log.debug("Ensuring that the uploaded data, if any, is blanked out for a non-embedded attachment");
try {
setData(null);
} catch (ValidationException e) {
throw new ApplicationExceptions(e);
}
}
}
// Generate the technical-key, if required
if (getAttachmentId() == null) {
try {
IVoucherGenerator vg = VoucherGeneratorFactory.instance();
vg.setUow(getUOW());
vg.setDomainClassName(getClass().getName());
vg.setFieldName(AttachmentMeta.ATTACHMENT_ID);
vg.setLabelToken(AttachmentMeta.META_ATTACHMENT_ID.getLabelToken());
setAttachmentId(vg.generate());
} catch (ValidationException e) {
throw new ApplicationExceptions(e);
}
}
if (getDocumentReferenceId() == null && attachmentDataImpl != null) {
if (log.isDebugEnabled())
log.debug("Attachment is stored in external data repository");
try {
IVoucherGenerator vg = VoucherGeneratorFactory.instance();
vg.setUow(getUOW());
vg.setDomainClassName(getClass().getName());
vg.setFieldName(AttachmentMeta.DOCUMENT_REFERENCE_ID);
vg.setLabelToken(AttachmentMeta.META_DOCUMENT_REFERENCE_ID.getLabelToken());
setDocumentReferenceId(vg.generate());
} catch (ValidationException e) {
throw new ApplicationExceptions(e);
}
}
if (getDocumentReferenceId() != null && attachmentDataImpl != null) {
try {
setAttachmentType("D");
// Null out attachment data as it is stored in document repository
setData(null);
} catch (ValidationException e) {
throw new ApplicationExceptions(e);
}
}
super.validate();
}
use of org.jaffa.components.attachment.apis.IAttachmentData in project jaffa-framework by jaffa-projects.
the class AttachmentHandler method endBeanDelete.
public void endBeanDelete(String path, Object source, Object target) throws ApplicationException, ApplicationExceptions, FrameworkException {
if (source instanceof AttachmentGraph && target instanceof Attachment) {
AttachmentGraph attachmentGraph = (AttachmentGraph) source;
Attachment attachment = (Attachment) target;
IAttachmentData attachmentDataImpl = AttachmentFactory.getAttachmentDataImpl();
if (attachmentDataImpl != null && attachment.getDocumentReferenceId() != null) {
Criteria c = new Criteria();
c.setTable(AttachmentMeta.getName());
c.addCriteria(AttachmentMeta.DOCUMENT_REFERENCE_ID, attachment.getDocumentReferenceId());
c.addCriteria(AttachmentMeta.ATTACHMENT_ID, Criteria.RELATIONAL_NOT_EQUALS, attachment.getAttachmentId());
c.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
Iterator<Attachment> iterator = attachment.getUOW().query(c).iterator();
if (iterator.hasNext()) {
Number count = (Number) ((Map) iterator.next()).get(Criteria.ID_FUNCTION_COUNT);
if (count == null || count.intValue() == 0) {
attachmentDataImpl.delete(attachment.getDocumentReferenceId());
}
}
}
}
}
Aggregations