List of usage examples for com.liferay.portal.kernel.util PortalUtil getUserId
public static long getUserId(PortletRequest portletRequest)
From source file:com.liferay.salesforce.portlet.SalesforceContactsPortlet.java
License:Apache License
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws IOException, PortletException { HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(resourceResponse); ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY); httpServletResponse.setContentType(ContentTypes.TEXT); String requestMethod = ParamUtil.getString(resourceRequest, "type"); resourceResponse.setContentType(ContentTypes.TEXT_JAVASCRIPT); String username = getUsername(resourceRequest); try {//from w ww . ja v a2 s. co m if (themeDisplay.isSignedIn() && (requestMethod != null) && requestMethod.equals(_CONTACTS) && username != null) { MessageBatch messageBatch = SalesforceContactLocalServiceUtil.getContactsByUserName( PortalUtil.getDefaultCompanyId(), username, Arrays.asList(FIELD_NAMES), PortalUtil.getUserId(resourceRequest)); httpServletResponse.getWriter().print(MessageBatchConverter.getJSONString(messageBatch)); httpServletResponse.flushBuffer(); } else if (themeDisplay.isSignedIn() && (requestMethod != null) && requestMethod.equals(_CONTACTS_FOR_ACCOUNT) && username != null) { String accountId = resourceRequest.getParameter("accId"); MessageBatch messageBatch = SalesforceContactLocalServiceUtil.getContactsByAccountId( PortalUtil.getDefaultCompanyId(), accountId, Arrays.asList(FIELD_NAMES), PortalUtil.getUserId(resourceRequest)); httpServletResponse.getWriter().print(MessageBatchConverter.getJSONString(messageBatch)); httpServletResponse.flushBuffer(); } else { httpServletResponse.getWriter().print(""); httpServletResponse.flushBuffer(); } } catch (SystemException e) { throw new PortletException("Unable to process request", e); } }
From source file:com.liferay.salesforce.portlet.SalesforceOpportunityPortlet.java
License:Apache License
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws IOException, PortletException { HttpServletResponse response = PortalUtil.getHttpServletResponse(resourceResponse); ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY); response.setContentType("text"); String requestMethod = ParamUtil.getString(resourceRequest, "type"); resourceResponse.setContentType("text/javascript"); String username = getUsername(resourceRequest); try {//from w ww . j av a 2 s . c om if (themeDisplay.isSignedIn() && (requestMethod != null) && requestMethod.equals("opps") && username != null) { MessageBatch messageBatch = SalesforceOpportunityLocalServiceUtil.getOpportunitiesByUserName( PortalUtil.getDefaultCompanyId(), username, Arrays.asList(FIELD_NAMES), PortalUtil.getUserId(resourceRequest)); response.getWriter().print(MessageBatchConverter.getJSONString(messageBatch)); response.flushBuffer(); } else if (themeDisplay.isSignedIn() && (requestMethod != null) && requestMethod.equals("accountDetails") && username != null) { String accountName = resourceRequest.getParameter("accountNm"); MessageBatch messageBatch = SalesforceAccountLocalServiceUtil.getAccountsByName( PortalUtil.getDefaultCompanyId(), accountName, Arrays.asList(DETAIL_FIELD_NAMES), PortalUtil.getUserId(resourceRequest)); response.getWriter().print(MessageBatchConverter.getPivotedJSONString(messageBatch)); response.flushBuffer(); } else { response.getWriter().print(""); response.flushBuffer(); } } catch (SystemException e) { e.printStackTrace(); throw new PortletException("Unable to process request", e); } }
From source file:it.infn.ct.indigo.futuregateway.portlet.action.FGEditAppMVCRenderCommand.java
License:Apache License
@Override public final String render(final RenderRequest renderRequest, final RenderResponse renderResponse) throws PortletException { String appId;//w w w .ja v a 2 s . co m ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY); try { Map<String, String> infras = fgServerManager.getInfrastructures(themeDisplay.getCompanyId(), themeDisplay.getUserId()); if (infras.isEmpty()) { return "/application-no-infras.jsp"; } renderRequest.setAttribute(FGServerConstants.INFRASTRUCTURE_COLLECTION, infras); } catch (Exception e) { if (e instanceof IOException) { SessionErrors.add(renderRequest, e.getClass()); return "/error.jsp"; } else { throw new PortletException(e); } } appId = ParamUtil.getString(renderRequest, FGServerConstants.VIEW_EDIT_RESOURCE_ID, null); if (appId != null) { try { String application = fgServerManager.getResource(PortalUtil.getCompanyId(renderRequest), FGServerConstants.APPLICATION_COLLECTION, appId, PortalUtil.getUserId(renderRequest)); JSONObject appJ = JSONFactoryUtil.createJSONObject(application); renderRequest.setAttribute("app_id", appJ.getString("id")); renderRequest.setAttribute("app_name", appJ.getString("name")); renderRequest.setAttribute("app_description", appJ.getString("description")); renderRequest.setAttribute("app_enabled", appJ.getBoolean("enabled")); renderRequest.setAttribute("app_outcome", appJ.getString("outcome")); Map<String, String> paramValues = new HashMap<>(); Map<String, String> paramDescs = new HashMap<>(); JSONArray params = appJ.getJSONArray("parameters"); if (params != null) { for (int i = 0; i < params.length(); i++) { JSONObject par = params.getJSONObject(i); paramValues.put(par.getString("name"), par.getString("value")); paramDescs.put(par.getString("name"), par.getString("description")); } } renderRequest.setAttribute("app_parameters_values", paramValues); renderRequest.setAttribute("app_parameters_descriptions", paramDescs); JSONArray files = appJ.getJSONArray("files"); Set<String> fileNames = new HashSet<>(); if (files != null) { for (int i = 0; i < files.length(); i++) { fileNames.add(files.getJSONObject(i).getString("name")); } } renderRequest.setAttribute("app_file_names", fileNames); JSONArray infras = appJ.getJSONArray("infrastructures"); Set<String> infraIds = new HashSet<>(); if (infras != null) { for (int i = 0; i < infras.length(); i++) { infraIds.add(infras.getString(i)); } } renderRequest.setAttribute("app_infras", infraIds); } catch (Exception ex) { log.error(ex.getMessage()); SessionErrors.add(renderRequest, FGServerManager.class); } } return "/add_application.jsp"; }
From source file:it.infn.ct.indigo.futuregateway.portlet.action.FGEditInfraMVCRenderCommand.java
License:Apache License
@Override public final String render(final RenderRequest renderRequest, final RenderResponse renderResponse) throws PortletException { String infraId;/*w w w. j a va 2s.c o m*/ try { PortalUtil.getSelectedUser(renderRequest); } catch (Exception e) { if (e instanceof PrincipalException) { SessionErrors.add(renderRequest, e.getClass()); return "/error.jsp"; } else { throw new PortletException(e); } } infraId = ParamUtil.getString(renderRequest, FGServerConstants.VIEW_EDIT_RESOURCE_ID, null); if (infraId != null) { try { String infrastructure = fgServerManager.getResource(PortalUtil.getCompanyId(renderRequest), FGServerConstants.INFRASTRUCTURE_COLLECTION, infraId, PortalUtil.getUserId(renderRequest)); JSONObject infraJ = JSONFactoryUtil.createJSONObject(infrastructure); renderRequest.setAttribute("infra_id", infraJ.getString("id")); renderRequest.setAttribute("infra_name", infraJ.getString("name")); renderRequest.setAttribute("infra_description", infraJ.getString("description")); renderRequest.setAttribute("infra_enabled", infraJ.getBoolean("enabled")); renderRequest.setAttribute("infra_virtual", infraJ.getBoolean("virtual")); Map<String, String> paramValues = new HashMap<>(); Map<String, String> paramDescs = new HashMap<>(); JSONArray params = infraJ.getJSONArray("parameters"); if (params != null) { for (int i = 0; i < params.length(); i++) { JSONObject par = params.getJSONObject(i); paramValues.put(par.getString("name"), par.getString("value")); paramDescs.put(par.getString("name"), par.getString("description")); } } renderRequest.setAttribute("infra_parameters_values", paramValues); renderRequest.setAttribute("infra_parameters_descriptions", paramDescs); } catch (Exception ex) { log.error(ex.getMessage()); SessionErrors.add(renderRequest, FGServerManager.class); } } return "/add_infrastructure.jsp"; }
From source file:jorgediazest.missingrefchecker.portlet.MissingReferencesCheckerPortlet.java
License:Open Source License
@SuppressWarnings("unchecked") public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { PortletConfig portletConfig = (PortletConfig) renderRequest .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG); List<String> outputList = null; List<MissingRefInfo> listMissingRefInfo = (List<MissingRefInfo>) renderRequest .getAttribute("missingReferencesList"); if (listMissingRefInfo != null) { outputList = MissingRefCheckerOutput.generateCSVOutputCheckReferences(portletConfig, renderRequest.getLocale(), listMissingRefInfo); }/* ww w. j a v a 2 s .co m*/ Map<Reference, Reference> references = (Map<Reference, Reference>) renderRequest .getAttribute("referencesMap"); if (references != null) { outputList = MissingRefCheckerOutput.generateCSVOutputMappingList(portletConfig, renderRequest.getLocale(), references); } String outputScript = OutputUtils.listStringToString(outputList); FileEntry exportCsvFileEntry = null; try { InputStream inputStream = null; if (Validator.isNotNull(outputScript)) { inputStream = new ByteArrayInputStream(outputScript.getBytes(StringPool.UTF8)); } String portletId = portletConfig.getPortletName(); Repository repository = OutputUtils.getPortletRepository(portletId); OutputUtils.cleanupPortletFileEntries(repository, 8 * 60); long userId = PortalUtil.getUserId(renderRequest); String fileName = "missing-references_output_" + userId + "_" + System.currentTimeMillis() + ".csv"; exportCsvFileEntry = OutputUtils.addPortletFileEntry(repository, inputStream, userId, fileName, "text/plain"); if (exportCsvFileEntry != null) { ResourceURL exportCsvResourceURL = renderResponse.createResourceURL(); exportCsvResourceURL.setResourceID(exportCsvFileEntry.getTitle()); renderRequest.setAttribute("exportCsvResourceURL", exportCsvResourceURL.toString()); } } catch (Exception e) { _log.error(e, e); } super.doView(renderRequest, renderResponse); }
From source file:jorgediazest.stagingchecker.portlet.StagingCheckerPortlet.java
License:Open Source License
public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { PortletConfig portletConfig = (PortletConfig) renderRequest .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG); List<String> outputList = StagingCheckerOutput.generateCSVOutput(portletConfig, renderRequest); String outputScript = OutputUtils.listStringToString(outputList); FileEntry exportCsvFileEntry = null; try {/*from www . ja v a2 s. c om*/ InputStream inputStream = null; if (Validator.isNotNull(outputScript)) { inputStream = new ByteArrayInputStream(outputScript.getBytes(StringPool.UTF8)); } String portletId = portletConfig.getPortletName(); Repository repository = OutputUtils.getPortletRepository(portletId); OutputUtils.cleanupPortletFileEntries(repository, 8 * 60); long userId = PortalUtil.getUserId(renderRequest); String fileName = "staging-checker_output_" + userId + "_" + System.currentTimeMillis() + ".csv"; exportCsvFileEntry = OutputUtils.addPortletFileEntry(repository, inputStream, userId, fileName, "text/plain"); if (exportCsvFileEntry != null) { ResourceURL exportCsvResourceURL = renderResponse.createResourceURL(); exportCsvResourceURL.setResourceID(exportCsvFileEntry.getTitle()); renderRequest.setAttribute("exportCsvResourceURL", exportCsvResourceURL.toString()); } } catch (Exception e) { _log.error(e, e); } try { List<Long> siteGroupIds = this.getSiteGroupIds(); renderRequest.setAttribute("groupIdList", siteGroupIds); List<String> groupDescriptionList = getSiteGroupDescriptions(siteGroupIds); renderRequest.setAttribute("groupDescriptionList", groupDescriptionList); } catch (SystemException se) { throw new PortletException(se); } try { List<Model> modelList = this.getModelList(); renderRequest.setAttribute("modelList", modelList); } catch (SystemException se) { throw new PortletException(se); } int numberOfThreads = getNumberOfThreads(renderRequest); renderRequest.setAttribute("numberOfThreads", numberOfThreads); super.doView(renderRequest, renderResponse); }