Search in sources :

Example 6 with AttachmentGraph

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());
                }
            }
        }
    }
}
Also used : AttachmentGraph(org.jaffa.components.attachment.apis.data.AttachmentGraph) Attachment(org.jaffa.components.attachment.domain.Attachment) GraphCriteria(org.jaffa.soa.graph.GraphCriteria) Criteria(org.jaffa.persistence.Criteria) IAttachmentData(org.jaffa.components.attachment.apis.IAttachmentData)

Aggregations

AttachmentGraph (org.jaffa.components.attachment.apis.data.AttachmentGraph)6 IAttachmentData (org.jaffa.components.attachment.apis.IAttachmentData)4 Attachment (org.jaffa.components.attachment.domain.Attachment)4 AttachmentCriteria (org.jaffa.components.attachment.apis.data.AttachmentCriteria)2 AttachmentUpdateResponse (org.jaffa.components.attachment.apis.data.AttachmentUpdateResponse)1 Criteria (org.jaffa.persistence.Criteria)1 GraphCriteria (org.jaffa.soa.graph.GraphCriteria)1