use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment 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);
}
}
use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment 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.api.attachment.Attachment 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.api.attachment.Attachment 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.api.attachment.Attachment in project carbon-business-process by wso2.
the class AttachmentUploadExecutor method execute.
@Override
public boolean execute(HttpServletRequest request, HttpServletResponse response) throws IOException {
PrintWriter out = response.getWriter();
String webContext = (String) request.getAttribute(CarbonConstants.WEB_CONTEXT);
String serverURL = (String) request.getAttribute(CarbonConstants.SERVER_URL);
String cookie = (String) request.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
Map<String, ArrayList<String>> formFieldsMap = getFormFieldsMap();
String redirect = null;
try {
if (formFieldsMap.get("redirect") != null) {
redirect = formFieldsMap.get("redirect").get(0);
}
ArrayList<FileItemData> fileItemsMap = getFileItemsMap().get("fileToUpload");
FileItemData fileToBeUpload = fileItemsMap.get(0);
if (fileItemsMap == null || fileItemsMap.isEmpty() || fileItemsMap.size() != 1) {
String msg = "File uploading failed.";
log.error(msg);
out.write("<textarea>" + "(function(){i18n.fileUplodedFailed();})();" + "</textarea>");
return true;
}
AttachmentUploadClient client = new AttachmentUploadClient(configurationContext, serverURL + "AttachmentMgtService", cookie);
response.setContentType("text/html; charset=utf-8");
client.addUploadedFileItem(fileToBeUpload);
String msg = "Your attachment has been uploaded successfully. Please refresh this page in a while to see " + "the status of the new process.";
if (redirect != null) {
CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.INFO, request, response, getContextRoot(request) + "/" + webContext + "/" + redirect);
} else {
CarbonUIMessage.sendCarbonUIMessage(msg, CarbonUIMessage.INFO, request);
}
return true;
} catch (Exception ex) {
String errMsg = "File upload failed.";
log.error(errMsg, ex);
if (redirect != null) {
CarbonUIMessage.sendCarbonUIMessage(errMsg, CarbonUIMessage.ERROR, request, response, getContextRoot(request) + "/" + webContext + "/" + redirect);
} else {
CarbonUIMessage.sendCarbonUIMessage(errMsg, CarbonUIMessage.ERROR, request);
}
}
return false;
}
Aggregations