Search in sources :

Example 6 with AttachmentMgtException

use of org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException 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;
}
Also used : AttachmentDAO(org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO) AttachmentDAOImpl(org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.openjpa.entity.AttachmentDAOImpl)

Example 7 with AttachmentMgtException

use of org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException 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 8 with AttachmentMgtException

use of org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException 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)

Example 9 with AttachmentMgtException

use of org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException 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 10 with AttachmentMgtException

use of org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException 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)

Aggregations

AttachmentMgtException (org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException)11 AttachmentMgtException (org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException)9 TAttachment (org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment)8 AttachmentDAO (org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO)7 DataHandler (javax.activation.DataHandler)4 Query (javax.persistence.Query)4 Attachment (org.wso2.carbon.attachment.mgt.api.attachment.Attachment)4 AttachmentManagerService (org.wso2.carbon.attachment.mgt.core.service.AttachmentManagerService)4 TAttachment (org.wso2.carbon.attachment.mgt.stub.types.TAttachment)4 Calendar (java.util.Calendar)3 EndpointReference (org.apache.axis2.addressing.EndpointReference)3 Options (org.apache.axis2.client.Options)3 AttachmentMgtServiceStub (org.wso2.carbon.attachment.mgt.stub.AttachmentMgtServiceStub)3 List (java.util.List)2 Callable (java.util.concurrent.Callable)2 URI (org.apache.axis2.databinding.types.URI)2 AttachmentDAOImpl (org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.openjpa.entity.AttachmentDAOImpl)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1