use of org.jaffa.components.attachment.apis.data.AttachmentGraph 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