Search in sources :

Example 16 with Attachment

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;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException) Attachment(org.jaffa.components.attachment.domain.Attachment) Criteria(org.jaffa.persistence.Criteria)

Example 17 with Attachment

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();
    }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ApplicationException(org.jaffa.exceptions.ApplicationException) FrameworkException(org.jaffa.exceptions.FrameworkException) Attachment(org.jaffa.components.attachment.domain.Attachment) UOW(org.jaffa.persistence.UOW)

Example 18 with Attachment

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;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException) Attachment(org.jaffa.components.attachment.domain.Attachment) Criteria(org.jaffa.persistence.Criteria)

Example 19 with Attachment

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();
    }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ApplicationException(org.jaffa.exceptions.ApplicationException) FrameworkException(org.jaffa.exceptions.FrameworkException) Attachment(org.jaffa.components.attachment.domain.Attachment) UOW(org.jaffa.persistence.UOW)

Example 20 with Attachment

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);
    }
}
Also used : Attachment(org.jaffa.components.attachment.domain.Attachment) FrameworkException(org.jaffa.exceptions.FrameworkException) IOException(java.io.IOException)

Aggregations

Attachment (org.jaffa.components.attachment.domain.Attachment)20 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)9 FrameworkException (org.jaffa.exceptions.FrameworkException)7 ApplicationException (org.jaffa.exceptions.ApplicationException)5 Criteria (org.jaffa.persistence.Criteria)5 UOW (org.jaffa.persistence.UOW)5 IAttachmentData (org.jaffa.components.attachment.apis.IAttachmentData)4 AttachmentGraph (org.jaffa.components.attachment.apis.data.AttachmentGraph)4 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)3 IOException (java.io.IOException)1 AttachmentFinderOutDto (org.jaffa.components.attachment.components.attachmentfinder.dto.AttachmentFinderOutDto)1 AttachmentFinderOutRowDto (org.jaffa.components.attachment.components.attachmentfinder.dto.AttachmentFinderOutRowDto)1 AttachmentLookupOutDto (org.jaffa.components.attachment.components.attachmentlookup.dto.AttachmentLookupOutDto)1 AttachmentLookupOutRowDto (org.jaffa.components.attachment.components.attachmentlookup.dto.AttachmentLookupOutRowDto)1 AttachmentViewerOutDto (org.jaffa.components.attachment.components.attachmentviewer.dto.AttachmentViewerOutDto)1 DateTime (org.jaffa.datatypes.DateTime)1 ValidationException (org.jaffa.datatypes.ValidationException)1 AttachmentDto (org.jaffa.modules.messaging.components.businesseventlogviewer.dto.AttachmentDto)1 UOWException (org.jaffa.persistence.exceptions.UOWException)1 GraphCriteria (org.jaffa.soa.graph.GraphCriteria)1