Search in sources :

Example 6 with AttachmentDAO

use of org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO in project carbon-business-process by wso2.

the class AttachmentMgtDAOTransformerFactoryImpl method convertAttachment.

@Override
public AttachmentDAO convertAttachment(Attachment attachment) throws AttachmentMgtException {
    AttachmentDAO attachmentDAO = new AttachmentDAOImpl();
    attachmentDAO.setName(attachment.getName());
    attachmentDAO.setCreatedBy(attachment.getCreatedBy());
    attachmentDAO.setContent(attachment.getContent());
    attachmentDAO.setContentType(attachment.getContentType());
    return attachmentDAO;
}
Also used : AttachmentDAO(org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO) AttachmentDAOImpl(org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.openjpa.entity.AttachmentDAOImpl)

Example 7 with AttachmentDAO

use of org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO in project carbon-business-process by wso2.

the class AttachmentManagerService method add.

/**
 * {@inheritDoc}
 */
@Override
public String add(final TAttachment attachment) throws AttachmentMgtException {
    if (log.isDebugEnabled() && attachment != null) {
        log.debug("Saving the attachment with id " + attachment.getId());
    }
    try {
        Attachment att = TransformerUtil.convertAttachment(attachment);
        // 1. get Att-Mgt DAO Conn factory
        // 2. get Att-Mgt DAO Connection
        // 3. addAttachment
        // getDaoConnectionFactory().getDAOConnection().addAttachment(att);
        AttachmentDAO daoImpl = getDaoConnectionFactory().getDAOConnection().getAttachmentMgtDAOFactory().addAttachment(att);
        return daoImpl.getID().toString();
    } catch (org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException ex) {
        String errMsg = "org.wso2.carbon.attachment.mgt.core.service.AttachmentManagerService.add " + "operation failed. Reason:" + ex.getLocalizedMessage();
        log.error(errMsg, ex);
        throw new AttachmentMgtException(errMsg, ex);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException) AttachmentDAO(org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO) TAttachment(org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment) Attachment(org.wso2.carbon.attachment.mgt.api.attachment.Attachment)

Example 8 with AttachmentDAO

use of org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO in project carbon-business-process by wso2.

the class TransformerUtils method transformAttachments.

public static TAttachmentInfo[] transformAttachments(List<AttachmentDAO> attachmentList) {
    TAttachmentInfo[] array = new TAttachmentInfo[attachmentList.size()];
    int counter = 0;
    for (AttachmentDAO attachmentDAO : attachmentList) {
        TAttachmentInfo attachmentInfo = new TAttachmentInfo();
        attachmentInfo.setAccessType(attachmentDAO.getAccessType());
        try {
            log.debug("TAttachmentInfo(DTO) has the contentCategory, but the AttachmentDAO(DAO) doesn't support " + "that attribute. Assume default attachment category as mime: " + HumanTaskConstants.ATTACHMENT_CONTENT_CATEGORY_MIME);
            attachmentInfo.setContentCategory(new URI(HumanTaskConstants.ATTACHMENT_CONTENT_CATEGORY_MIME));
        } catch (URI.MalformedURIException e) {
            log.error(e.getLocalizedMessage(), e);
        }
        try {
            String attachmentURI = attachmentDAO.getValue();
            URI attachmentURL = HumanTaskServerHolder.getInstance().getAttachmentService().getAttachmentService().getAttachmentInfoFromURL(attachmentURI).getUrl();
            attachmentInfo.setIdentifier(attachmentURL);
        } catch (AttachmentMgtException e) {
            log.error(e.getLocalizedMessage(), e);
        }
        attachmentInfo.setContentType(attachmentDAO.getContentType());
        Calendar cal = Calendar.getInstance();
        cal.setTime(attachmentDAO.getAttachedAt());
        attachmentInfo.setAttachedTime(cal);
        TUser user = new TUser();
        user.setTUser(attachmentDAO.getAttachedBy().getName());
        attachmentInfo.setAttachedBy(user);
        attachmentInfo.setName(attachmentDAO.getName());
        array[counter] = attachmentInfo;
        counter++;
    }
    return array;
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException) Calendar(java.util.Calendar) URI(org.apache.axis2.databinding.types.URI)

Example 9 with AttachmentDAO

use of org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO in project carbon-business-process by wso2.

the class TransformerUtils method generateAttachmentDAOFromID.

/**
 * Generate an {@code AttachmentDAO} for a given attachment-id
 *
 * @param task task to be associated with the particular attachment
 * @param attachmentID id of the attachment, so this will be used to extract attachment information from the
 * attachment-mgt OSGi service
 *
 * @return reference to the created {@code AttachmentDAO}
 * @throws HumanTaskException If if was failed to retrieve data from the attachment-mgt OSGi service
 */
public static AttachmentDAO generateAttachmentDAOFromID(TaskDAO task, String attachmentID) throws HumanTaskException {
    try {
        org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment attachment = HumanTaskServerHolder.getInstance().getAttachmentService().getAttachmentService().getAttachmentInfo(attachmentID);
        AttachmentDAO dao = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getDaoConnectionFactory().getConnection().createAttachment();
        // Constructing the attachment DAO from the DTO
        dao.setName(attachment.getName());
        dao.setContentType(attachment.getContentType());
        dao.setTask((Task) task);
        String attachmentURL = attachment.getUrl().toString();
        // Extracting the attachment uri
        String attachmentUniqueID = attachmentURL.substring(attachmentURL.lastIndexOf("/") + 1);
        dao.setValue(attachmentUniqueID);
        dao.setAttachedAt(attachment.getCreatedTime().getTime());
        OrganizationalEntityDAO orgEntityDAO = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getDaoConnectionFactory().getConnection().createNewOrgEntityObject(attachment.getCreatedBy(), OrganizationalEntityDAO.OrganizationalEntityType.USER);
        dao.setAttachedBy((OrganizationalEntity) orgEntityDAO);
        // TODO : "AccessType is not supported by Attachment-Mgt DTOs. So using a dummy value: " + HumanTaskConstants.DEFAULT_ATTACHMENT_ACCESS_TYPE);
        dao.setAccessType(HumanTaskConstants.DEFAULT_ATTACHMENT_ACCESS_TYPE);
        return dao;
    } catch (AttachmentMgtException e) {
        String errorMsg = "Attachment Data retrieval operation failed for attachment id:" + attachmentID + ". " + "Reason:";
        log.error(e.getLocalizedMessage(), e);
        throw new HumanTaskException(errorMsg + e.getLocalizedMessage(), e);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException) org.wso2.carbon.humantask.client.api.types(org.wso2.carbon.humantask.client.api.types) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException)

Aggregations

AttachmentDAO (org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO)7 AttachmentMgtException (org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException)5 Attachment (org.wso2.carbon.attachment.mgt.api.attachment.Attachment)3 TAttachment (org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment)3 List (java.util.List)2 Query (javax.persistence.Query)2 AttachmentDAOImpl (org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.openjpa.entity.AttachmentDAOImpl)2 AttachmentMgtException (org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException)2 Calendar (java.util.Calendar)1 URI (org.apache.axis2.databinding.types.URI)1 org.wso2.carbon.humantask.client.api.types (org.wso2.carbon.humantask.client.api.types)1 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)1