Search in sources :

Example 1 with TAttachment

use of org.wso2.carbon.attachment.mgt.stub.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;
}
Also used : TAttachment(org.wso2.carbon.attachment.mgt.stub.types.TAttachment) Calendar(java.util.Calendar) DataHandler(javax.activation.DataHandler) Date(java.util.Date)

Example 2 with TAttachment

use of org.wso2.carbon.attachment.mgt.stub.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;
}
Also used : TAttachment(org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment) FileDataSource(javax.activation.FileDataSource) DataHandler(javax.activation.DataHandler) File(java.io.File)

Example 3 with TAttachment

use of org.wso2.carbon.attachment.mgt.stub.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);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException) ServletException(javax.servlet.ServletException) TAttachment(org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment) ServletOutputStream(javax.servlet.ServletOutputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream)

Example 4 with TAttachment

use of org.wso2.carbon.attachment.mgt.stub.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);
    }
}
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 5 with TAttachment

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

Aggregations

TAttachment (org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment)10 AttachmentMgtException (org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException)6 DataHandler (javax.activation.DataHandler)4 Attachment (org.wso2.carbon.attachment.mgt.api.attachment.Attachment)4 TAttachment (org.wso2.carbon.attachment.mgt.stub.types.TAttachment)4 AttachmentDAO (org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO)3 File (java.io.File)2 Calendar (java.util.Calendar)2 FileDataSource (javax.activation.FileDataSource)2 EndpointReference (org.apache.axis2.addressing.EndpointReference)2 Options (org.apache.axis2.client.Options)2 AttachmentManagerService (org.wso2.carbon.attachment.mgt.core.service.AttachmentManagerService)2 AttachmentMgtServiceStub (org.wso2.carbon.attachment.mgt.stub.AttachmentMgtServiceStub)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 ServletException (javax.servlet.ServletException)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 URI (org.apache.axis2.databinding.types.URI)1 AttachmentImpl (org.wso2.carbon.attachment.mgt.core.AttachmentImpl)1