List of usage examples for com.liferay.portal.kernel.servlet SessionErrors add
public static void add(PortletRequest portletRequest, String key)
From source file:atc.otn.ckan.portlets.OrganizationUploader.java
@ProcessAction(name = "orgDocument") public void orgDocument(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException, PortalException, SystemException { //********************** Variables ********************** ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); User user = themeDisplay.getUser();//from w w w. j a v a 2 s .com DocumentManager dm = new DocumentManager(); Folder folder; UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest); File file; String fileName; Folder parentFolder; long repositoryId; String mimeType; String fileURL = ""; CKANClient client; JSONObject datasetData = new JSONObject(), resource = new JSONObject(), dTankresource = new JSONObject(); JSONArray resources = new JSONArray(), extras = new JSONArray(), tags = new JSONArray(), dTankresources = new JSONArray(); String[] tagsStr; String datasetURL = ""; String dTankDatasetURL = ""; String organizationId; InputStream in = null; Properties p = new Properties(); //get the repository id repositoryId = themeDisplay.getScopeGroupId(); //get the CKAN folder parentFolder = DLAppServiceUtil.getFolder(repositoryId, PARENT_FOLDER_ID, ROOT_FOLDER_NAME); //init CKAN client client = new CKANClient(); long now = new Date().getTime(); //********************** Action ********************** try { in = this.getClass().getResourceAsStream("/portlet.properties"); p.load(in); organizationId = p.getProperty("CKAN.organizationID"); logger.info("uploading document...."); //get the file uploaded file = uploadPortletRequest.getFile("fileInput"); //if file was given after all if (uploadPortletRequest.getFile("fileInput") != null && file.exists()) { fileName = uploadPortletRequest.getFileName("fileInput"); mimeType = uploadPortletRequest.getContentType("fileInput"); //folder = dm.createUserFolder(actionRequest, themeDisplay); fileURL = dm.uploadFile(themeDisplay, actionRequest, parentFolder, file, fileName, mimeType); file.delete(); } else if (ParamUtil.getString(uploadPortletRequest, "link") != null) { fileURL = ParamUtil.getString(uploadPortletRequest, "link"); } tagsStr = ParamUtil.getString(uploadPortletRequest, "tags").split(","); logger.info(ParamUtil.getString(uploadPortletRequest, "tags")); //create json objects as ckan requires them resource.put("url", fileURL); /* Give the resource the same name as the package */ resource.put("name", ParamUtil.getString(uploadPortletRequest, "dstitle")); //resource.put("name", ParamUtil.getString(uploadPortletRequest,"dname")); //resource.put("description", ParamUtil.getString(uploadPortletRequest,"description")); resource.put("format", ParamUtil.getString(uploadPortletRequest, "format")); resources.put(resource); /* Don't upload to CKAN xlxs,xls and csv files */ if (!resource.getString("format").equals("XLSX") && !resource.getString("format").equals("XLS") && !resource.getString("format").equals("CSV")) { for (String tag : tagsStr) { if (!tag.isEmpty()) { tags.put(new JSONObject().put("name", tag)); } } //convert title of dataset to ascii characters for the url to be valid String stringName = ParamUtil.getString(uploadPortletRequest, "dstitle").toLowerCase().replace(" ", "-"); String nameForUrl = java.net.URLEncoder.encode(stringName.toString(), "ascii").replace("%", "-") .toLowerCase(); datasetData.put("title", ParamUtil.getString(uploadPortletRequest, "dstitle")); datasetData.put("name", nameForUrl + now); datasetData.put("owner_org", organizationId); datasetData.put("notes", ParamUtil.getString(uploadPortletRequest, "notes")); datasetData.put("url", ParamUtil.getString(uploadPortletRequest, "source")); datasetData.put("version", ParamUtil.getString(uploadPortletRequest, "version")); datasetData.put("author", ParamUtil.getString(uploadPortletRequest, "author")); datasetData.put("license_id", ParamUtil.getString(uploadPortletRequest, "license")); datasetData.put("resources", resources); if (tags.length() > 0) { datasetData.put("tags", tags); } //Store dataset in CKAN datasetURL = client.addOrganizationDataset(user.getUserId(), datasetData); if (!datasetURL.startsWith("http")) { actionRequest.setAttribute("ckanerror", datasetURL); SessionErrors.add(actionRequest, "ckanerror"); } else { SessionMessages.add(actionRequest, "ckansuccess"); System.out.println("uploaded to CKAN " + datasetURL); } } // End CKAN UPload else {// Upload to Datatank if (!fileURL.equals("")) { JSONObject dtankData = new JSONObject(); /*Remove everything after the .xls*/ int ext = 0; if ((ext = fileURL.indexOf(".xls/")) > 0) { fileURL = fileURL.substring(0, ext + 4); } else if ((ext = fileURL.indexOf(".xlsx/")) > 0) { fileURL = fileURL.substring(0, ext + 5); } else if ((ext = fileURL.indexOf(".csv")) > 0) { fileURL = fileURL.substring(0, ext + 4); } System.out.println("Datatank resource url: " + fileURL); String dTankformat = ParamUtil.getString(uploadPortletRequest, "format").toLowerCase(); if (dTankformat.equals("xlsx")) { dTankformat = "xls"; } dtankData.put("description", ParamUtil.getString(uploadPortletRequest, "notes")); dtankData.put("uri", fileURL); dtankData.put("type", dTankformat); dtankData.put("title", ParamUtil.getString(uploadPortletRequest, "dstitle")); dTankDatasetURL = client.addToDataTank(dtankData, dTankformat, ParamUtil.getString(uploadPortletRequest, "dstitle").toLowerCase().replace(" ", "_") + now); if (dTankDatasetURL.startsWith("http:")) { logger.info("uploaded to Datatank: " + dTankDatasetURL); if (client.getDatatankTransform(dTankDatasetURL)) { /*Now store the file back in CKAN*/ dTankresource.put("url", dTankDatasetURL + ".geojson"); /* Give the resource the same name as the package */ dTankresource.put("name", ParamUtil.getString(uploadPortletRequest, "dstitle")); //resource.put("name", ParamUtil.getString(uploadPortletRequest,"dname")); //resource.put("description", ParamUtil.getString(uploadPortletRequest,"description")); dTankresource.put("format", "geojson"); dTankresources.put(dTankresource); for (String tag : tagsStr) { if (!tag.isEmpty()) { tags.put(new JSONObject().put("name", tag)); } } datasetData.put("title", ParamUtil.getString(uploadPortletRequest, "dstitle")); datasetData.put("name", ParamUtil.getString(uploadPortletRequest, "dstitle") .toLowerCase().replace(" ", "-") + now); datasetData.put("owner_org", organizationId); datasetData.put("notes", ParamUtil.getString(uploadPortletRequest, "notes")); datasetData.put("url", ParamUtil.getString(uploadPortletRequest, "source")); datasetData.put("version", ParamUtil.getString(uploadPortletRequest, "version")); datasetData.put("author", ParamUtil.getString(uploadPortletRequest, "author")); datasetData.put("license_id", ParamUtil.getString(uploadPortletRequest, "license")); //if uploaded file format is xls or csv if (ParamUtil.getString(uploadPortletRequest, "format").toLowerCase().equals("csv") || ParamUtil.getString(uploadPortletRequest, "format").toLowerCase() .equals("xls") || ParamUtil.getString(uploadPortletRequest, "format").toLowerCase() .equals("xlsx")) { client = new CKANClient(); //get the bbox value from geojson coming from Datatank extras = client.getExtent(dTankDatasetURL); //prepare the jsonArray from service to insert it as a custom field in CKAN String extrStr = extras.toString().replaceAll("[\\[\\]]", ""); List<HashMap<String, String>> extraDictionaries = new ArrayList<HashMap<String, String>>(); HashMap<String, String> extraDictionary = new HashMap<String, String>(); extraDictionary.put("value", extrStr); extraDictionary.put("key", "extent"); extraDictionaries.add(extraDictionary); datasetData.put("extras", extraDictionaries); } datasetData.put("resources", dTankresources); if (tags.length() > 0) { datasetData.put("tags", tags); } //Store dataset in CKAN datasetURL = client.addOrganizationDataset(user.getUserId(), datasetData); if (!datasetURL.startsWith("http")) { actionRequest.setAttribute("ckanerror", datasetURL); SessionErrors.add(actionRequest, "ckanerror"); } //actionRequest.setAttribute("dTanksuccess", dTankDatasetURL +".geojson"); actionRequest.setAttribute("dTanksuccess", "Your dataset is succefully transformed into geojson.<br /> Go to <a href='/my-datasets'>My Datasets</a> to view it!"); SessionMessages.add(actionRequest, "dTanksuccess"); logger.info("Dtank transofrmed succesfully stored in CKAN: " + datasetURL); } else { actionRequest.setAttribute("dTankerror", "Your file could not be transformed into geojson format.<br /> Please check if it has column headers and if the records contain coordinates. For excel files, the system will try to transform data found in the first sheet which should be named 'sheet1'"); SessionErrors.add(actionRequest, "dTankerror"); } } else { actionRequest.setAttribute("dTankerror", "Your file could not be transformed into geojson format"); SessionErrors.add(actionRequest, "dTankerror"); } } } PortletURL actionUrl = PortletURLFactoryUtil.create(actionRequest, themeDisplay.getPortletDisplay().getId(), themeDisplay.getPlid(), PortletRequest.ACTION_PHASE); String redirectUrl = actionUrl.toString().replaceAll("upload-organization-dataset", "organization-datasets"); actionResponse.sendRedirect(redirectUrl); } catch (Exception e) { e.printStackTrace(); } }
From source file:atc.otn.ckan.portlets.Uploader.java
@ProcessAction(name = "uploadDocument") public void uploadDocument(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException, PortalException, SystemException { //********************** Variables ********************** ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); User user = themeDisplay.getUser();// w w w.j a v a 2 s . c o m DocumentManager dm = new DocumentManager(); Folder folder; UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest); File file; String fileName; Folder parentFolder; long repositoryId; String mimeType; String fileURL = ""; CKANClient client; JSONObject datasetData = new JSONObject(), resource = new JSONObject(), dTankresource = new JSONObject(); JSONArray resources = new JSONArray(), extras = new JSONArray(), tags = new JSONArray(), dTankresources = new JSONArray(); String[] tagsStr; String datasetURL = ""; String dTankDatasetURL = ""; //get the repository id repositoryId = themeDisplay.getScopeGroupId(); //get the CKAN folder parentFolder = DLAppServiceUtil.getFolder(repositoryId, PARENT_FOLDER_ID, ROOT_FOLDER_NAME); //init CKAN client client = new CKANClient(); long now = new Date().getTime(); //********************** Action ********************** try { // logger.info("uploading document...."); //get the file uploaded file = uploadPortletRequest.getFile("fileInput"); //if file was given after all if (uploadPortletRequest.getFile("fileInput") != null && file.exists()) { fileName = uploadPortletRequest.getFileName("fileInput"); mimeType = uploadPortletRequest.getContentType("fileInput"); //folder = dm.createUserFolder(actionRequest, themeDisplay); fileURL = dm.uploadFile(themeDisplay, actionRequest, parentFolder, file, fileName, mimeType); file.delete(); } else if (ParamUtil.getString(uploadPortletRequest, "link") != null) { fileURL = ParamUtil.getString(uploadPortletRequest, "link"); } tagsStr = ParamUtil.getString(uploadPortletRequest, "tags").split(","); logger.info(ParamUtil.getString(uploadPortletRequest, "tags")); //create json objects as ckan requires them resource.put("url", fileURL); /* Give the resource the same name as the package */ resource.put("name", ParamUtil.getString(uploadPortletRequest, "dstitle")); //resource.put("name", ParamUtil.getString(uploadPortletRequest,"dname")); //resource.put("description", ParamUtil.getString(uploadPortletRequest,"description")); resource.put("format", ParamUtil.getString(uploadPortletRequest, "format")); resources.put(resource); /* Don't upload to CKAN xlxs,xls and csv files */ if (!resource.getString("format").equals("XLSX") && !resource.getString("format").equals("XLS") && !resource.getString("format").equals("CSV")) { for (String tag : tagsStr) { if (!tag.isEmpty()) { tags.put(new JSONObject().put("name", tag)); } } //convert title of dataset to ascii characters for the url to be valid String stringName = ParamUtil.getString(uploadPortletRequest, "dstitle").toLowerCase().replace(" ", "-"); String nameForUrl = java.net.URLEncoder.encode(stringName.toString(), "ascii").replace("%", "-") .toLowerCase(); datasetData.put("title", ParamUtil.getString(uploadPortletRequest, "dstitle")); datasetData.put("name", nameForUrl + now); datasetData.put("owner_org", user.getUserId() + "_org"); datasetData.put("notes", ParamUtil.getString(uploadPortletRequest, "notes")); datasetData.put("url", ParamUtil.getString(uploadPortletRequest, "source")); datasetData.put("version", ParamUtil.getString(uploadPortletRequest, "version")); datasetData.put("author", ParamUtil.getString(uploadPortletRequest, "author")); datasetData.put("license_id", ParamUtil.getString(uploadPortletRequest, "license")); datasetData.put("resources", resources); if (tags.length() > 0) { datasetData.put("tags", tags); } //Store dataset in CKAN datasetURL = client.addUserDataset(user.getUserId(), datasetData); if (!datasetURL.startsWith("http")) { actionRequest.setAttribute("ckanerror", datasetURL); SessionErrors.add(actionRequest, "ckanerror"); } else { SessionMessages.add(actionRequest, "ckansuccess"); System.out.println("uploaded to CKAN " + datasetURL); } } // End CKAN UPload else {// Upload to Datatank if (!fileURL.equals("")) { JSONObject dtankData = new JSONObject(); /*Remove everything after the .xls*/ int ext = 0; if ((ext = fileURL.indexOf(".xls/")) > 0) { fileURL = fileURL.substring(0, ext + 4); } else if ((ext = fileURL.indexOf(".xlsx/")) > 0) { fileURL = fileURL.substring(0, ext + 5); } else if ((ext = fileURL.indexOf(".csv")) > 0) { fileURL = fileURL.substring(0, ext + 4); } System.out.println("Datatank resource url: " + fileURL); String dTankformat = ParamUtil.getString(uploadPortletRequest, "format").toLowerCase(); if (dTankformat.equals("xlsx")) { dTankformat = "xls"; } dtankData.put("description", ParamUtil.getString(uploadPortletRequest, "notes")); dtankData.put("uri", fileURL); dtankData.put("type", dTankformat); dtankData.put("title", ParamUtil.getString(uploadPortletRequest, "dstitle")); dTankDatasetURL = client.addToDataTank(dtankData, dTankformat, ParamUtil.getString(uploadPortletRequest, "dstitle").toLowerCase().replace(" ", "_") + now); if (dTankDatasetURL.startsWith("http:")) { logger.info("uploaded to Datatank: " + dTankDatasetURL); if (client.getDatatankTransform(dTankDatasetURL)) { /*Now store the file back in CKAN*/ dTankresource.put("url", dTankDatasetURL + ".geojson"); /* Give the resource the same name as the package */ dTankresource.put("name", ParamUtil.getString(uploadPortletRequest, "dstitle")); //resource.put("name", ParamUtil.getString(uploadPortletRequest,"dname")); //resource.put("description", ParamUtil.getString(uploadPortletRequest,"description")); dTankresource.put("format", "geojson"); dTankresources.put(dTankresource); for (String tag : tagsStr) { if (!tag.isEmpty()) { tags.put(new JSONObject().put("name", tag)); } } datasetData.put("title", ParamUtil.getString(uploadPortletRequest, "dstitle")); datasetData.put("name", ParamUtil.getString(uploadPortletRequest, "dstitle") .toLowerCase().replace(" ", "-") + now); datasetData.put("owner_org", user.getUserId() + "_org"); datasetData.put("notes", ParamUtil.getString(uploadPortletRequest, "notes")); datasetData.put("url", ParamUtil.getString(uploadPortletRequest, "source")); datasetData.put("version", ParamUtil.getString(uploadPortletRequest, "version")); datasetData.put("author", ParamUtil.getString(uploadPortletRequest, "author")); datasetData.put("license_id", ParamUtil.getString(uploadPortletRequest, "license")); //if uploaded file format is xls or csv if (ParamUtil.getString(uploadPortletRequest, "format").toLowerCase().equals("csv") || ParamUtil.getString(uploadPortletRequest, "format").toLowerCase() .equals("xls") || ParamUtil.getString(uploadPortletRequest, "format").toLowerCase() .equals("xlsx")) { client = new CKANClient(); //get the bbox value from geojson coming from Datatank extras = client.getExtent(dTankDatasetURL); //prepare the jsonArray from service to insert it as a custom field in CKAN String extrStr = extras.toString().replaceAll("[\\[\\]]", ""); List<HashMap<String, String>> extraDictionaries = new ArrayList<HashMap<String, String>>(); HashMap<String, String> extraDictionary = new HashMap<String, String>(); extraDictionary.put("value", extrStr); extraDictionary.put("key", "extent"); extraDictionaries.add(extraDictionary); datasetData.put("extras", extraDictionaries); } datasetData.put("resources", dTankresources); if (tags.length() > 0) { datasetData.put("tags", tags); } //Store dataset in CKAN datasetURL = client.addUserDataset(user.getUserId(), datasetData); if (!datasetURL.startsWith("http")) { actionRequest.setAttribute("ckanerror", datasetURL); SessionErrors.add(actionRequest, "ckanerror"); } //actionRequest.setAttribute("dTanksuccess", dTankDatasetURL +".geojson"); actionRequest.setAttribute("dTanksuccess", "Your dataset is succefully transformed into geojson.<br /> Go to <a href='/my-datasets'>My Datasets</a> to view it!"); SessionMessages.add(actionRequest, "dTanksuccess"); logger.info("Dtank transofrmed succesfully stored in CKAN: " + datasetURL); } else { actionRequest.setAttribute("dTankerror", "Your file could not be transformed into geojson format.<br /> Please check if it has column headers and if the records contain coordinates. For excel files, the system will try to transform data found in the first sheet which should be named 'sheet1'"); SessionErrors.add(actionRequest, "dTankerror"); } } else { actionRequest.setAttribute("dTankerror", "Your file could not be transformed into geojson format"); SessionErrors.add(actionRequest, "dTankerror"); } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:au.com.permeance.liferay.portlet.documentlibrary.action.DownloadFolderZipAction.java
License:Open Source License
@Override public void serveResource(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig, ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception { long repositoryId = ParamUtil.getLong(resourceRequest, "repositoryId"); long folderId = ParamUtil.getLong(resourceRequest, "folderId"); try {//from w ww .j a v a 2 s. c o m downloadFolder(resourceRequest, resourceResponse); } catch (Exception e) { String msg = "Error downloading folder " + folderId + " from repository " + repositoryId + " : " + e.getMessage(); s_log.error(msg, e); SessionErrors.add(resourceRequest, e.getClass().getName()); resourceResponse.setProperty(ResourceResponse.HTTP_STATUS_CODE, "" + HttpStatus.SC_MOVED_TEMPORARILY); resourceResponse.addProperty("Location", resourceResponse.createRenderURL().toString()); } }
From source file:au.com.permeance.liferay.portlet.patchingtoolinfo.PatchingToolInfoMVCPortlet.java
License:Open Source License
@Override public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { if (LOG.isDebugEnabled()) { LOG.debug("do view ..."); }/*w ww . j ava2 s . com*/ try { PatchingToolResults patchingToolResults = lookupPatchingToolResults(); if (LOG.isDebugEnabled()) { LOG.debug("adding patching tool results to portlet session : " + patchingToolResults); } SessionMessages.add(renderRequest, "success"); PortletSession portletSession = renderRequest.getPortletSession(); portletSession.setAttribute(PortletKeys.SESSION_KEY_PATCHING_TOOL_RESULTS, patchingToolResults); super.doView(renderRequest, renderResponse); } catch (Exception e) { LOG.error("Error processing view: " + e.getMessage()); SessionErrors.add(renderRequest, "error"); PortletSession portletSession = renderRequest.getPortletSession(); portletSession.setAttribute(PortletKeys.REQUEST_KEY_PATCHING_TOOL_ERROR_TYPE, e.getClass().getName()); portletSession.setAttribute(PortletKeys.REQUEST_KEY_PATCHING_TOOL_ERROR_MESSAGE, e.getMessage()); portletSession.setAttribute(PortletKeys.REQUEST_KEY_PATCHING_TOOL_ERROR_EXCEPTION, e); include(TEMPLATE_PAGE_PATH_ERROR, renderRequest, renderResponse); } if (LOG.isDebugEnabled()) { LOG.debug("dispatch to view ..."); } }
From source file:au.com.permeance.liferay.portlets.workflow.WebContentWorkflowPortlet.java
License:Open Source License
@Override public void processAction(final ActionRequest actionRequest, final ActionResponse actionResponse) throws IOException, PortletException { final long groupId = ParamUtil.getLong(actionRequest, "groupId"); final ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); final Enumeration<String> paramNames = actionRequest.getParameterNames(); boolean success = true; while (paramNames.hasMoreElements()) { final String name = paramNames.nextElement(); if (!name.startsWith(_PREFIX)) { continue; }//from www .j a v a2 s . c o m final long structureId = GetterUtil.getLong(name.substring(_PREFIX.length(), name.length()), -1l); if (structureId >= 0) { String workflowDefinition = ParamUtil.getString(actionRequest, name); try { WorkflowDefinitionLinkLocalServiceUtil.updateWorkflowDefinitionLink(themeDisplay.getUserId(), themeDisplay.getCompanyId(), groupId, JournalArticle.class.getName(), structureId, 0, workflowDefinition); } catch (SystemException e) { _log.warn("Error processing action: " + e.getMessage(), e); SessionErrors.add(actionRequest, e.toString()); success = false; } catch (PortalException e) { _log.warn("Error processing action: " + e.getMessage(), e); SessionErrors.add(actionRequest, e.toString()); success = false; } } } if (success) { SessionMessages.add(actionRequest, "success"); } sendRedirect(actionRequest, actionResponse); }
From source file:ca.efendi.datafeeds.web.internal.portlet.DatafeedsAdminPortlet.java
License:Apache License
public void addFtpSubscription(final ActionRequest request, final ActionResponse response) throws Exception { final ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(THEME_DISPLAY); final FtpSubscription ftpSubscription = ftpSubscriptionFromRequest(request); final ArrayList<String> errors = new ArrayList<String>(); if (FtpSubscriptionValidator.validate(request, errors)) { _ftpSubscriptionLocalService.addFtpSubscription(ftpSubscription); SessionMessages.add(request, "product-saved-successfully"); } else {/* w w w .j a va 2 s. co m*/ SessionErrors.add(request, "fields-required"); } }
From source file:ca.efendi.datafeeds.web.internal.portlet.DatafeedsAdminPortlet.java
License:Apache License
public void updateFtpSubscription(final ActionRequest request, final ActionResponse response) throws PortalException, SystemException { final ArrayList<String> errors = new ArrayList<>(); final ServiceContext serviceContext = ServiceContextFactory.getInstance(FtpSubscription.class.getName(), request);//from w w w .ja va2 s. co m long ftpSubscriptionId = ParamUtil.getLong(request, "ftpSubscriptionId"); FtpSubscription ftpSubscriptionFromRequest = ftpSubscriptionFromRequest(request); if (!FtpSubscriptionValidator.validate(request, errors)) { for (final String error : errors) { SessionErrors.add(request, error); } request.setAttribute(DatafeedsPortletKeys.FTP_SUBSCRIPTION_ENTRY, ftpSubscriptionFromRequest); response.setRenderParameter("jspPage", editFtpSubscriptionJSP); return; } if (ftpSubscriptionId > 0) { // Updating try { FtpSubscription ftp = _ftpSubscriptionLocalService.getFtpSubscription(ftpSubscriptionId); if (ftp != null) { ftp.setModifiedDate(new Date()); ftp.setFtpHost(ParamUtil.getString(request, "ftpHost")); ftp.setFtpUser(ParamUtil.getString(request, "ftpUser")); ftp.setFtpPassword(ParamUtil.getString(request, "ftpPassword")); ftp.setFtpFolder(ParamUtil.getString(request, "ftpFolder")); ftp.setFtpDatafeedName(ParamUtil.getString(request, "ftpDatafeedName")); ftp.setFtpFile(ParamUtil.getString(request, "ftpFile")); ftp.setFtpDatafeedDescription(ParamUtil.getString(request, "ftpDatafeedDescription")); _ftpSubscriptionLocalService.updateFtpSubscription(ftp); SessionMessages.add(request, "ftp-subscription-added"); } } catch (final PortalException e) { errors.add("failed-to-update"); } catch (final SystemException e) { errors.add("failed-to-update"); } } else { // Adding try { _ftpSubscriptionLocalService.addFtpSubscription(ftpSubscriptionFromRequest, ftpSubscriptionFromRequest.getUserId(), serviceContext); } catch (final SystemException e) { errors.add("failed-to-add"); } } // response.setRenderParameter("jspPage", "/html/view2.jsp"); }
From source file:ca.efendi.datafeeds.web.internal.portlet.DatafeedsAdminPortlet.java
License:Apache License
@Override public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { try {/*from w w w.j ava 2 s . c om*/ FtpSubscription ftpSubscription = null; final long ftpSubscriptionId = ParamUtil.getLong(renderRequest, "ftpSubscriptionId"); if (ftpSubscriptionId > 0) { ftpSubscription = _ftpSubscriptionLocalService.getFtpSubscription(ftpSubscriptionId); } else { ftpSubscription = _ftpSubscriptionLocalService.createFtpSubscription(0); } renderRequest.setAttribute(DatafeedsPortletKeys.FTP_SUBSCRIPTION_ENTRY, ftpSubscription); } catch (final Exception e) { if (e instanceof NoSuchFtpSubscriptionException) { SessionErrors.add(renderRequest, e.getClass().getName()); } else { throw new PortletException(e); } } super.render(renderRequest, renderResponse); }
From source file:ch.inofix.referencemanager.web.internal.portlet.ReferenceManagerPortlet.java
License:Apache License
/** * // w w w . j a v a 2 s . com * @param actionRequest * @param actionResponse * @since 1.0.0 * @throws Exception */ public void importBibTeXFile(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest); File file = uploadPortletRequest.getFile("file"); String fileName = file.getName(); long userId = themeDisplay.getUserId(); long groupId = themeDisplay.getScopeGroupId(); boolean privateLayout = themeDisplay.getLayout().isPrivateLayout(); String servletContextName = request.getSession().getServletContext().getServletContextName(); String[] servletContextNames = new String[] { servletContextName }; Map<String, String[]> parameterMap = new HashMap<String, String[]>(actionRequest.getParameterMap()); parameterMap.put("servletContextNames", servletContextNames); if (Validator.isNotNull(file)) { String message = PortletUtil.translate("upload-successfull-import-will-finish-in-a-separate-thread"); ServiceContext serviceContext = ServiceContextFactory.getInstance(Reference.class.getName(), uploadPortletRequest); _referenceService.importReferencesInBackground(userId, fileName, groupId, privateLayout, parameterMap, file, serviceContext); SessionMessages.add(actionRequest, "request_processed", message); } else { SessionErrors.add(actionRequest, "file-not-found"); } }
From source file:com.beorn.onlinepayment.portlet.AdminPortlet.java
License:Open Source License
public void editSeller(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException { try {/* w w w . j a v a2 s.c o m*/ ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); long sellerId = ParamUtil.getLong(actionRequest, "sellerId"); String name = ParamUtil.getString(actionRequest, "name"); boolean active = ParamUtil.getBoolean(actionRequest, "active"); if (Validator.isNull(name)) SessionErrors.add(actionRequest, "name-required"); if (!SessionErrors.isEmpty(actionRequest)) { actionResponse.setRenderParameters(actionRequest.getParameterMap()); return; } ServiceContext serviceContext = ServiceContextFactory.getInstance(Seller.class.getName(), actionRequest); Seller seller; if (sellerId == 0) { PaymentAppPermission.check(permissionChecker, themeDisplay.getScopeGroupId(), ActionKeys.ADD_SELLER); seller = SellerLocalServiceUtil.addSeller(themeDisplay.getUserId(), name, active, serviceContext); } else { SellerPermission.check(permissionChecker, sellerId, ActionKeys.UPDATE); seller = SellerLocalServiceUtil.updateSeller(sellerId, name, active, serviceContext); } String redirect = ParamUtil.getString(actionRequest, "successURL"); redirect = HttpUtil.setParameter(redirect, "_1_WAR_onlinepaymentportlet_sellerId", seller.getSellerId()); actionResponse.sendRedirect(redirect); SessionMessages.add(actionRequest, "edit-seller.success"); } catch (Exception e) { _log.error(e); actionResponse.setRenderParameters(actionRequest.getParameterMap()); SessionErrors.add(actionRequest, e.getClass().getName()); } }