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;
}
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);
}
}
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;
}
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);
}
}
Aggregations