Search in sources :

Example 11 with TAttachment

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

the class AttachmentMgtDAOBasicOperationsTest method testAttachmentDAOGetInfoFromURLTest.

/**
 * This method tests whether it's possible to get the attachment-info for a given attachment url
 */
public void testAttachmentDAOGetInfoFromURLTest() {
    AttachmentManagerService service = new AttachmentManagerService();
    try {
        // Request for the attachment using the attachment id
        TAttachment attachmentFromID = service.getAttachmentInfo(attachmentID);
        // request for the attachment using attachment url
        TAttachment attachmentFromURL = service.getAttachmentInfoFromURL(attachmentFromID.getUrl().toString());
        assertEquals(attachmentFromID.getId(), attachmentFromURL.getId());
        log.info("Attachment information retrieved for uri : " + attachmentFromURL.getUrl().toString());
    } catch (AttachmentMgtException e) {
        log.error(e.getLocalizedMessage(), e);
        Assert.fail("Attachment information retrieval failed due to reason: " + e.getLocalizedMessage());
    }
}
Also used : AttachmentManagerService(org.wso2.carbon.attachment.mgt.core.service.AttachmentManagerService) AttachmentMgtException(org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException) TAttachment(org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment)

Example 12 with TAttachment

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

the class AttachmentMgtDAOBasicOperationsTest method testAttachmentDAOGetInfoTest.

/**
 * This method tests whether it's possible to get the attachment-info for a given attachment id
 */
public void testAttachmentDAOGetInfoTest() {
    AttachmentManagerService service = new AttachmentManagerService();
    try {
        TAttachment attachment = service.getAttachmentInfo(attachmentID);
        dummyAttachment = createAttachment();
        assertEquals(dummyAttachment.getName(), attachment.getName());
        assertEquals(dummyAttachment.getCreatedBy(), attachment.getCreatedBy());
        assertEquals(dummyAttachment.getContentType(), attachment.getContentType());
        log.info("Attachment information retrieved for id : " + attachment.getId());
    } catch (AttachmentMgtException e) {
        log.error(e.getLocalizedMessage(), e);
        Assert.fail("Attachment information retrieval failed due to reason: " + e.getLocalizedMessage());
    }
}
Also used : AttachmentManagerService(org.wso2.carbon.attachment.mgt.core.service.AttachmentManagerService) AttachmentMgtException(org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException) TAttachment(org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment)

Example 13 with TAttachment

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

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

the class BPELMessageReceiver method createAttachmentDTO.

private TAttachment createAttachmentDTO(DataHandler attachmentHandler) {
    TAttachment attachment = new TAttachment();
    String attachmentName = attachmentHandler.getName();
    attachment.setName(attachmentName);
    log.warn("Couldn't determine the name of BPEL client. So the owner of the attachment:" + attachmentName + " " + "will be the default bpel client" + org.wso2.carbon.bpel.core.BPELConstants.DAFAULT_BPEL_CLIENT);
    attachment.setCreatedBy(org.wso2.carbon.bpel.core.BPELConstants.DAFAULT_BPEL_CLIENT);
    attachment.setContentType(attachmentHandler.getContentType());
    // As well there are some other parameters to be set.
    attachment.setContent(attachmentHandler);
    return attachment;
}
Also used : TAttachment(org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment)

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