Search in sources :

Example 16 with AttachmentMgtException

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

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

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

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

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

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