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