use of org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment in project carbon-business-process by wso2.
the class AttachmentUploadClient method addUploadedFileItem.
/**
* Upload the attachment and return the attachment id
* @param fileItemData wrapper for the attachment
* @return attachment id for the uploaded attachment
* @throws AttachmentMgtException If an error occurred in the back-end component
* @throws RemoteException if an error during the communication
*/
public String addUploadedFileItem(FileItemData fileItemData) throws AttachmentMgtException, RemoteException, ExceptionException {
DataHandler handler = fileItemData.getDataHandler();
TAttachment attachment = new TAttachment();
attachment.setName(handler.getName());
attachment.setContentType(handler.getContentType());
attachment.setCreatedBy(getUserName());
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
attachment.setCreatedTime(calendar);
attachment.setContent(handler);
String attachmentID = stub.add(attachment);
log.info("Attachment was uploaded with id:" + attachmentID);
return attachmentID;
}
use of org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment in project carbon-business-process by wso2.
the class AttachmentMgtDAOBasicOperationsTest method createAttachment.
/**
* Creates an attachment stub bean which is consumable by the Back-End server interface
* {@link org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtServiceSkeletonInterface}
*
* @return an attachment stub bean which is consumable by the Back-End server interface
*/
private TAttachment createAttachment() {
dummyAttachment = new TAttachment();
dummyAttachment.setName("DummyName");
dummyAttachment.setContentType("DummyContentType");
dummyAttachment.setCreatedBy("DummyUser");
DataHandler handler = new DataHandler(new FileDataSource(new File("src" + File.separator + "test" + File.separator + "resources" + File.separator + "dbConfig.xml")));
dummyAttachment.setContent(handler);
return dummyAttachment;
}
use of org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment in project carbon-business-process by wso2.
the class AttachmentDownloadServlet method doGet.
/**
* Logic that will be executed for a get request.
*
* @param request the HTTP Servlet request.
* @param response the HTTP Servlet response.
* @throws ServletException if an error occurred.
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String url = request.getRequestURI();
String attachmentUniqueID = url.substring(url.lastIndexOf("/") + 1);
InputStream contentStream = null;
ServletOutputStream servletOutputStream = null;
try {
TAttachment fileAttachment = getFileFromUniqueID(url);
response.setHeader("Content-Disposition", "attachment; filename=" + fileAttachment.getName());
response.setContentType(fileAttachment.getContentType());
contentStream = fileAttachment.getContent().getInputStream();
servletOutputStream = response.getOutputStream();
IOUtils.copy(contentStream, servletOutputStream);
servletOutputStream.flush();
} catch (AttachmentMgtException e) {
throw new ServletException(e.getLocalizedMessage(), e);
} finally {
IOUtils.closeQuietly(contentStream);
IOUtils.closeQuietly(servletOutputStream);
}
}
use of org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment in project carbon-business-process by wso2.
the class AttachmentManagerService method getAttachmentInfoFromURL.
/**
* {@inheritDoc}
*/
@Override
public TAttachment getAttachmentInfoFromURL(final String attachmentURL) throws AttachmentMgtException {
try {
// Extracting the attachment uri
String attachmentUniqueID = attachmentURL.substring(attachmentURL.lastIndexOf("/") + 1);
AttachmentDAO attachmentDAO = getDaoConnectionFactory().getDAOConnection().getAttachmentMgtDAOFactory().getAttachmentInfoFromURL(attachmentUniqueID);
Attachment attachment = getDaoTransformFactory().convertAttachment(attachmentDAO);
return TransformerUtil.convertAttachment(attachment);
} catch (org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException e) {
String errorMsg = "org.wso2.carbon.attachment.mgt.core.service.AttachmentManagerService.getAttachmentInfoFromURL operation failed. " + "Reason:" + e.getLocalizedMessage();
log.error(errorMsg, e);
throw new AttachmentMgtException(errorMsg, e);
}
}
use of org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment in project carbon-business-process by wso2.
the class AttachmentManagerService method getAttachmentInfo.
/**
* {@inheritDoc}
*/
@Override
public TAttachment getAttachmentInfo(final String id) throws AttachmentMgtException {
try {
AttachmentDAO attachmentDAO = getDaoConnectionFactory().getDAOConnection().getAttachmentMgtDAOFactory().getAttachmentInfo(id);
Attachment attachment = getDaoTransformFactory().convertAttachment(attachmentDAO);
return TransformerUtil.convertAttachment(attachment);
} catch (org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException e) {
String errorMsg = "org.wso2.carbon.attachment.mgt.core.service" + ".AttachmentManagerService.getAttachmentInfo operation failed. " + "Reason:" + e.getLocalizedMessage();
log.error(errorMsg, e);
throw new AttachmentMgtException(errorMsg, e);
}
}
Aggregations