Last active
June 15, 2020 23:28
-
-
Save jardineworks/c4e73bfcc770dd17fbc0 to your computer and use it in GitHub Desktop.
dev.life | Parallel Processing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SECTION #0: Introduction and Presentation | |
| ========================================= | |
| (use slideshow) | |
| SECTION #1: Creating a "Report Request" portlet plugin | |
| ======================================================= | |
| 1. Create a new MVC portlet plugin project (in eclipse) called "dev-life-report-portlet" | |
| 2. Create a new class in the src/main/java folder with the following definition. | |
| package com.jardineworks.dev.life.liferay.portlet.report; | |
| import java.io.IOException; | |
| import javax.portlet.ActionRequest; | |
| import javax.portlet.ActionResponse; | |
| import javax.portlet.PortletException; | |
| import javax.portlet.ProcessAction; | |
| import javax.portlet.RenderRequest; | |
| import javax.portlet.RenderResponse; | |
| import com.liferay.portal.kernel.log.Log; | |
| import com.liferay.portal.kernel.log.LogFactoryUtil; | |
| import com.liferay.portal.kernel.util.ParamUtil; | |
| import com.liferay.util.bridges.mvc.MVCPortlet; | |
| /** | |
| * <p> | |
| * Implementation class for the ReportRequest portlet. This class is used to process requests sent to the Report Request Portlet. | |
| * </p> | |
| * | |
| * @author andrew jardine | jardine works inc. | |
| */ | |
| public class ReportRequestPortlet extends MVCPortlet | |
| { | |
| // class logger | |
| private static final Log _log = LogFactoryUtil.getLog(ReportRequestPortlet.class); | |
| public static final String PARAM_REPORT_ID = "reportId"; | |
| public static final String PARAM_REPORT_SECTIONS = "reportSections"; | |
| /** | |
| * Handler for the RENDER phase of the portlet lifecycle. | |
| * | |
| * @param renderRequest {@link javax.portlet.RenderRequest} | |
| * @param renderResponse {@link javax.portlet.RenderResponse} | |
| */ | |
| @Override | |
| public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException | |
| { | |
| super.render(renderRequest, renderResponse); | |
| } | |
| /** | |
| * Handler for the ACTION phase of the portlet lifecycle. | |
| * | |
| * @param renderRequest {@link javax.portlet.ActionRequest} | |
| * @param renderResponse {@link javax.portlet.ActionResponse} | |
| */ | |
| @ProcessAction(name = "requestReport") | |
| public void requestReport(ActionRequest actionRequest, ActionResponse actionResponse) | |
| { | |
| if ( _log.isInfoEnabled() ) | |
| _log.info("Report request recevied."); | |
| String reportId = ParamUtil.getString(actionRequest, PARAM_REPORT_ID); | |
| String[] reportSections = ParamUtil.getParameterValues(actionRequest, PARAM_REPORT_SECTIONS); | |
| try | |
| { | |
| // create the report request here | |
| } | |
| catch (Exception e) | |
| { | |
| _log.error("Error occurred while trying to save request for report with id " + reportId, e); | |
| } | |
| if ( _log.isInfoEnabled() ) | |
| _log.info("Report request " + reportId + " processed."); | |
| } | |
| } | |
| 3. Update the portlet.xml file with the following definition. | |
| <?xml version="1.0"?> | |
| <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0"> | |
| <portlet> | |
| <portlet-name>dev-liferay-report-portlet</portlet-name> | |
| <display-name>Report Request Portlet</display-name> | |
| <portlet-class>com.jardineworks.dev.life.liferay.portlet.report.ReportRequestPortlet</portlet-class> | |
| <init-param> | |
| <name>view-template</name> | |
| <value>/html/report-request/view.jsp</value> | |
| </init-param> | |
| <expiration-cache>0</expiration-cache> | |
| <supports> | |
| <mime-type>text/html</mime-type> | |
| </supports> | |
| <portlet-info> | |
| <title>Report Requestt</title> | |
| <short-title>Report Request</short-title> | |
| <keywords>reporting, request</keywords> | |
| </portlet-info> | |
| <security-role-ref> | |
| <role-name>administrator</role-name> | |
| </security-role-ref> | |
| <security-role-ref> | |
| <role-name>guest</role-name> | |
| </security-role-ref> | |
| <security-role-ref> | |
| <role-name>power-user</role-name> | |
| </security-role-ref> | |
| <security-role-ref> | |
| <role-name>user</role-name> | |
| </security-role-ref> | |
| </portlet> | |
| </portlet-app> | |
| 4. Update the liferay-display.xml found in the WEB-INF folder with the following | |
| <?xml version="1.0"?> | |
| <!DOCTYPE display PUBLIC "-//Liferay//DTD Display 6.2.0//EN" "http://www.liferay.com/dtd/liferay-display_6_2_0.dtd"> | |
| <display> | |
| <category name="category.dev.life"> | |
| <portlet id="dev-liferay-report-portlet" /> | |
| </category> | |
| </display> | |
| 5. Create the following folder structure under webapp /html/common and /html/report-request | |
| 6. Add the JSTL libraries and taglibs to the project using the liferay-plugin-package.properties file | |
| 7. Inside the /html/common create a file called init.jsp with the following content | |
| <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> | |
| <%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %> | |
| <%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %> | |
| <%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %> | |
| <%@ taglib uri="http://liferay.com/tld/theme" prefix="theme" %> | |
| <%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %> | |
| <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> | |
| <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> | |
| <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> | |
| <%@ page import="javax.portlet.PortletPreferences"%> | |
| <%@ page import="com.liferay.portlet.PortletPreferencesFactoryUtil"%> | |
| <%@ page import="com.liferay.portal.kernel.util.Validator"%> | |
| <%@ page import="com.liferay.portal.kernel.util.ParamUtil"%> | |
| <%@ page import="com.liferay.portal.kernel.util.GetterUtil"%> | |
| <%@ page import="com.liferay.portal.kernel.util.StringPool"%> | |
| <%@ page import="com.liferay.portal.kernel.util.Constants"%> | |
| <%@ page import="java.util.List" %> | |
| <%@ page import="java.util.Map" %> | |
| <%@ page import="java.util.ArrayList" %> | |
| <%@ page import="java.util.Arrays" %> | |
| <%@ page import="java.util.Iterator" %> | |
| <%@ page import="com.liferay.portal.kernel.log.LogFactoryUtil" %> | |
| <%@ page import="com.liferay.portal.kernel.log.Log" %> | |
| <%@page import="com.liferay.portlet.PortletURLFactoryUtil"%> | |
| <%@page import="com.liferay.portal.kernel.portlet.LiferayPortletURL"%> | |
| <%@page import="com.liferay.portal.kernel.portlet.LiferayPortlet"%> | |
| <%@page import="com.liferay.portal.service.LayoutLocalServiceUtil"%> | |
| <%@page import="com.liferay.portal.model.Layout"%> | |
| <portlet:defineObjects /> | |
| <theme:defineObjects/> | |
| <% | |
| PortletPreferences preferences = renderRequest.getPreferences(); | |
| String portletResource = ParamUtil.getString( request, "portletResource" ); | |
| if ( Validator.isNotNull( portletResource ) ) | |
| { | |
| preferences = PortletPreferencesFactoryUtil.getPortletSetup( request, portletResource ); | |
| } | |
| String redirect = ParamUtil.getString( request, "redirect" ); | |
| %> | |
| 8. Inside /html/request-portlet create a file called init.jsp with the following content. | |
| 9. Move the view.jsp from the webapp root to the /html/request-portlet and update the content with the following | |
| <%@ include file="init.jsp" %> | |
| <portlet:actionURL name="reportRequest" var="reportRequestActionURL" /> | |
| <aui:form name="fm" method="post" action="${ reportRequestActionURL }"> | |
| <aui:fieldset> | |
| <aui:input name="reportId" disabled="true" value="${ nextReportId }" /> | |
| <aui:input type="checkbox" name="reportSections"label="summary" inlineLabel="true" /> | |
| <aui:input type="checkbox" name="reportSections"label="costs" inlineLabel="true" /> | |
| <aui:input type="checkbox" name="reportSections"label="roi" inlineLabel="true" /> | |
| <aui:input type="checkbox" name="reportSections"label="metrics" inlineLabel="true" /> | |
| <aui:input type="checkbox" name="reportSections"label="recommendations" inlineLabel="true" /> | |
| </aui:fieldset> | |
| <aui:button-row> | |
| <aui:button type="submit" value="save" /> | |
| </aui:button-row> | |
| </aui:form> | |
| 10. Create a new package/class com.jardineworks.dev.life.liferay.portlet.report.util.ReportWebKeys with the following definition | |
| package com.jardineworks.dev.life.liferay.portlet.report.util; | |
| /** | |
| * <p> | |
| * Constants class used to store attribute names for values that are stored in request or response objects, sessions, etc. | |
| * </p> | |
| * | |
| * @author andrew jardine | jardine works inc. | |
| */ | |
| public class ReportWebKeys | |
| { | |
| public static final String NEXT_REPORT_ID = "nextReportId"; | |
| } | |
| 11. | |
| SECTION #2: Adding a Scheduled Task | |
| ==================================== | |
| SECTION #3: Parallel Report Generation | |
| ======================================= | |
| SECTION #4: Parallel Report Section Generation | |
| =============================================== | |
| SECTION #5: Report Assembler | |
| ============================= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment