Search in sources :

Example 41 with Attachment

use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project carbon-business-process by wso2.

the class SampleAttachmentMgtClient method removeAttachment.

private static void removeAttachment(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);
    if (log.isDebugEnabled()) {
        log.debug("Attachment removed status:" + stub.remove(id));
    }
}
Also used : Options(org.apache.axis2.client.Options) AttachmentMgtServiceStub(org.wso2.carbon.attachment.mgt.stub.AttachmentMgtServiceStub) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 42 with Attachment

use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment 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 43 with Attachment

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

Example 44 with Attachment

use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project carbon-business-process by wso2.

the class AttachmentMgtDAOBasicOperationsTest method testAttachmentDAORemoveTest.

/**
 * This method tests the attachment removal functionality
 */
public void testAttachmentDAORemoveTest() {
    AttachmentManagerService service = new AttachmentManagerService();
    try {
        if (service.remove(attachmentID)) {
            log.info("Attachment with id: " + attachmentID + " was successfully removed from data-source.");
            assertTrue("Attachment successfully has been removed from data-source.", true);
        } else {
            Assert.fail("Attachment with id: " + attachmentID + " couldn't be removed.");
        }
    } catch (AttachmentMgtException e) {
        log.error(e.getLocalizedMessage(), e);
        Assert.fail("Attachment removal 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)

Example 45 with Attachment

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

Aggregations

HashMap (java.util.HashMap)11 AttachmentMgtException (org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException)11 TAttachment (org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment)10 DataHandler (javax.activation.DataHandler)9 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)9 ArrayList (java.util.ArrayList)8 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)8 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)8 File (java.io.File)7 Response (javax.ws.rs.core.Response)7 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)7 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)7 TopLevelNode (org.ballerinalang.model.tree.TopLevelNode)6 AttachmentDAO (org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO)6 BaseTaskService (org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)5 IOException (java.io.IOException)4 List (java.util.List)4 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)4 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)4 Attachment (org.wso2.carbon.attachment.mgt.api.attachment.Attachment)4