Search in sources :

Example 26 with AttachmentMgtException

use of org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException in project carbon-business-process by wso2.

the class BPELMessageReceiver method persistAttachments.

/**
 * Upload each attachment from attachment-map and returns a list of attachment ids.
 *
 * @param attachmentsMap
 * @return list of attachment ids
 */
private List<String> persistAttachments(Attachments attachmentsMap) {
    List<String> attachmentIdList = new ArrayList<String>();
    // for each attachment upload it
    for (String id : attachmentsMap.getAllContentIDs()) {
        DataHandler attachmentContent = attachmentsMap.getDataHandler(id);
        try {
            String attachmentID = BPELServerHolder.getInstance().getAttachmentService().getAttachmentService().add(createAttachmentDTO(attachmentContent));
            attachmentIdList.add(attachmentID);
            log.info("Attachment added. ID : " + attachmentID);
        } catch (AttachmentMgtException e) {
            log.error(e.getLocalizedMessage(), e);
        }
    }
    return attachmentIdList;
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException) ArrayList(java.util.ArrayList) DataHandler(javax.activation.DataHandler)

Example 27 with AttachmentMgtException

use of org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException 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 28 with AttachmentMgtException

use of org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException 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

AttachmentMgtException (org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException)11 AttachmentMgtException (org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException)9 TAttachment (org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment)8 AttachmentDAO (org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO)7 DataHandler (javax.activation.DataHandler)4 Query (javax.persistence.Query)4 Attachment (org.wso2.carbon.attachment.mgt.api.attachment.Attachment)4 AttachmentManagerService (org.wso2.carbon.attachment.mgt.core.service.AttachmentManagerService)4 TAttachment (org.wso2.carbon.attachment.mgt.stub.types.TAttachment)4 Calendar (java.util.Calendar)3 EndpointReference (org.apache.axis2.addressing.EndpointReference)3 Options (org.apache.axis2.client.Options)3 AttachmentMgtServiceStub (org.wso2.carbon.attachment.mgt.stub.AttachmentMgtServiceStub)3 List (java.util.List)2 Callable (java.util.concurrent.Callable)2 URI (org.apache.axis2.databinding.types.URI)2 AttachmentDAOImpl (org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.openjpa.entity.AttachmentDAOImpl)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1