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));
}
}
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;
}
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;
}
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());
}
}
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());
}
}
Aggregations