Search in sources :

Example 6 with TAttachment

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

the class AttachmentUploadClient method addUploadedFileItem.

public void addUploadedFileItem(FileItemData fileItemData) throws AttachmentMgtException, RemoteException {
    DataHandler handler = fileItemData.getDataHandler();
    TAttachment attachment = new TAttachment();
    attachment.setName(handler.getName());
    attachment.setContentType(handler.getContentType());
    // TODO: Remove this hard-coded value
    attachment.setCreatedBy("DummyUser");
    attachment.setContent(fileItemData.getDataHandler());
    String attachmentID = stub.add(attachment);
    log.info("Attachment was uploaded with id:" + attachmentID);
}
Also used : TAttachment(org.wso2.carbon.attachment.mgt.stub.types.TAttachment) DataHandler(javax.activation.DataHandler)

Example 7 with TAttachment

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

the class SampleAttachmentMgtClient method uploadAttachment.

private static String uploadAttachment() throws RemoteException, AttachmentMgtException {
    AttachmentMgtServiceStub stub = new AttachmentMgtServiceStub();
    Options options = new Options();
    options.setTo(new EndpointReference("http://127.0.0.1:9763/services/AttachmentMgtService/"));
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Boolean.TRUE);
    stub._getServiceClient().setOptions(options);
    TAttachment att = new TAttachment();
    // att.setId("ContentId");
    // att.setCreatedTime(Calendar.getInstance());
    att.setName("ContentName");
    att.setCreatedBy("DenisAuthor");
    att.setContentType("text/plain");
    // FileDataSource dataSource = new FileDataSource(new File("/home/denis/Desktop/note.txt"));
    FileDataSource dataSource = new FileDataSource(new File("/home/denis/Desktop/fromSoapUI.xml"));
    DataHandler fileDataHandler = new DataHandler(dataSource);
    att.setContent(fileDataHandler);
    String id = stub.add(att);
    if (log.isDebugEnabled()) {
        log.debug("Attachment uploaded with id: " + id);
    }
    return id;
}
Also used : Options(org.apache.axis2.client.Options) TAttachment(org.wso2.carbon.attachment.mgt.stub.types.TAttachment) AttachmentMgtServiceStub(org.wso2.carbon.attachment.mgt.stub.AttachmentMgtServiceStub) FileDataSource(javax.activation.FileDataSource) DataHandler(javax.activation.DataHandler) File(java.io.File) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 8 with TAttachment

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

the class SampleAttachmentMgtClient method getAttachmentInfo.

private static void getAttachmentInfo(String id) throws RemoteException, AttachmentMgtException {
    AttachmentMgtServiceStub stub = new AttachmentMgtServiceStub();
    Options options = new Options();
    options.setTo(new EndpointReference("http://127.0.0.1:9763/services/AttachmentMgtService/"));
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Boolean.TRUE);
    stub._getServiceClient().setOptions(options);
    TAttachment attachment = stub.getAttachmentInfo(id);
    if (log.isDebugEnabled()) {
        log.debug("Attachment details received. Id: " + attachment.getId());
    }
}
Also used : Options(org.apache.axis2.client.Options) TAttachment(org.wso2.carbon.attachment.mgt.stub.types.TAttachment) AttachmentMgtServiceStub(org.wso2.carbon.attachment.mgt.stub.AttachmentMgtServiceStub) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 9 with TAttachment

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

the class TransformerUtil method convertAttachment.

/**
 * Transform {@link Attachment} to (DTO) {@link TAttachment}
 *
 * @param attachment
 * @return
 */
public static TAttachment convertAttachment(Attachment attachment) throws AttachmentMgtException {
    TAttachment attachmentDTO = new TAttachment();
    attachmentDTO.setId(attachment.getId());
    attachmentDTO.setName(attachment.getName());
    attachmentDTO.setCreatedBy(attachment.getCreatedBy());
    Calendar cal = Calendar.getInstance();
    cal.setTime(attachment.getCreatedTime());
    attachmentDTO.setCreatedTime(cal);
    attachmentDTO.setContentType(attachment.getContentType());
    attachmentDTO.setContent(attachment.getContent());
    try {
        URI attachmentURI = new URI(attachment.getURL().toString());
        attachmentDTO.setUrl(attachmentURI);
    } catch (URI.MalformedURIException e) {
        log.error(e.getLocalizedMessage(), e);
        throw new AttachmentMgtException("Conversion of Attachment to TAttachment (DTO) failed due to reason : " + e.getLocalizedMessage(), e);
    }
    return attachmentDTO;
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException) TAttachment(org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment) Calendar(java.util.Calendar) URI(org.apache.axis2.databinding.types.URI)

Example 10 with TAttachment

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

the class TransformerUtil method convertAttachment.

/**
 * Transform (DTO) {@link TAttachment} to {@link Attachment}
 *
 * @param attachment
 * @return
 * @throws AttachmentMgtException
 */
public static Attachment convertAttachment(TAttachment attachment) throws AttachmentMgtException {
    Attachment attachmentDTO = null;
    attachmentDTO = new AttachmentImpl(attachment.getName(), attachment.getCreatedBy(), attachment.getContentType(), attachment.getContent(), attachment.getCreatedTime().getTime());
    return attachmentDTO;
}
Also used : TAttachment(org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment) Attachment(org.wso2.carbon.attachment.mgt.api.attachment.Attachment) AttachmentImpl(org.wso2.carbon.attachment.mgt.core.AttachmentImpl)

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