Search in sources :

Example 1 with AttachmentGraph

use of org.jaffa.components.attachment.apis.data.AttachmentGraph in project jaffa-framework by jaffa-projects.

the class AttachmentService method deleteAttachment.

public static void deleteAttachment(UOW uow, String serializedKey) throws FrameworkException, ApplicationExceptions {
    AttachmentService service = new AttachmentService();
    AttachmentCriteria attachmentCriteria = new AttachmentCriteria();
    attachmentCriteria.setSerializedKey(StringCriteriaField.getStringCriteriaField(CriteriaField.RELATIONAL_EQUALS, serializedKey, null));
    AttachmentGraph[] graphs = service.localQuery(attachmentCriteria, uow);
    if (graphs != null && graphs.length > 0) {
        for (AttachmentGraph graph : graphs) {
            graph.setDeleteObject(Boolean.TRUE);
            service.localUpdate(null, graph, uow);
        }
    }
}
Also used : AttachmentCriteria(org.jaffa.components.attachment.apis.data.AttachmentCriteria) AttachmentGraph(org.jaffa.components.attachment.apis.data.AttachmentGraph)

Example 2 with AttachmentGraph

use of org.jaffa.components.attachment.apis.data.AttachmentGraph 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);
            }
        }
    }
}
Also used : AttachmentGraph(org.jaffa.components.attachment.apis.data.AttachmentGraph) Attachment(org.jaffa.components.attachment.domain.Attachment) IAttachmentData(org.jaffa.components.attachment.apis.IAttachmentData)

Example 3 with AttachmentGraph

use of org.jaffa.components.attachment.apis.data.AttachmentGraph 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());
            }
        }
    }
}
Also used : AttachmentGraph(org.jaffa.components.attachment.apis.data.AttachmentGraph) Attachment(org.jaffa.components.attachment.domain.Attachment) IAttachmentData(org.jaffa.components.attachment.apis.IAttachmentData)

Example 4 with AttachmentGraph

use of org.jaffa.components.attachment.apis.data.AttachmentGraph 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());
            }
        }
    }
}
Also used : AttachmentGraph(org.jaffa.components.attachment.apis.data.AttachmentGraph) Attachment(org.jaffa.components.attachment.domain.Attachment) IAttachmentData(org.jaffa.components.attachment.apis.IAttachmentData)

Example 5 with AttachmentGraph

use of org.jaffa.components.attachment.apis.data.AttachmentGraph in project jaffa-framework by jaffa-projects.

the class AttachmentService method cloneAttachment.

public static AttachmentUpdateResponse cloneAttachment(UOW uow, String oldSerializedKey, String newSerializedKey) throws FrameworkException, ApplicationExceptions {
    AttachmentService service = new AttachmentService();
    AttachmentCriteria attachmentCriteria = new AttachmentCriteria();
    attachmentCriteria.setSerializedKey(StringCriteriaField.getStringCriteriaField(CriteriaField.RELATIONAL_EQUALS, oldSerializedKey, null));
    AttachmentGraph attachmentGraph = new AttachmentGraph();
    attachmentGraph.setSerializedKey(newSerializedKey);
    AttachmentUpdateResponse[] attachmentUpdateResponses = service.localCloneOrMassUpdate(attachmentCriteria, attachmentGraph, true, uow);
    return attachmentUpdateResponses != null ? attachmentUpdateResponses[0] : null;
}
Also used : AttachmentCriteria(org.jaffa.components.attachment.apis.data.AttachmentCriteria) AttachmentGraph(org.jaffa.components.attachment.apis.data.AttachmentGraph) AttachmentUpdateResponse(org.jaffa.components.attachment.apis.data.AttachmentUpdateResponse)

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