use of org.wso2.carbon.attachment.mgt.core.exceptions.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;
}
use of org.wso2.carbon.attachment.mgt.core.exceptions.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;
}
use of org.wso2.carbon.attachment.mgt.core.exceptions.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);
}
}
Aggregations