Download presentation
Presentation is loading. Please wait.
Published byAllan Goodwin Modified over 9 years ago
1
Application Specific Module Tutorial Akos Balasko 02/07/2012 1
2
Outline Technical Session: Sample web-interface (JSP) Implement event-handler class Deploy it to Liferay-based gUSE Adjusting as a new component in gUSE 2
3
Overview Sample application: 3 Input file(inputval.txt) Output (internal file name: outputval.txt) Shell-script: Read and count numbers from input file and command line Command-line
4
Overview Button to create new Query List of created queries Each row is identified by the application id Status Date of creation Action Buttons 4
5
Information Transfer: Server Client CLIENT CODE ${dev} SERVER CODE public void doView(RenderRequest req, RenderResponse res) throws PortletException { ArrayList developers = new ArrayList (); developers.add(„10168"); developers.add(„10169"); req.setAttribute(„ developers ",developers); PortletRequestDispatcher dispatcher; dispatcher = getPortletContext().getRequestDispatcher(nextJSP); dispatcher.include(req, res); } CLIENT BROWSER (developers=[„10168” ; „10169”] ) 5
6
Information Transfer : Client Server CLIENT CODE ${dev} SERVER CODE public void processAction(ActionRequest request, ActionResponse response) throws PortletException { String action = ""; if ((request.getParameter("action") != null) && (!request.getParameter("action").equals(""))) { action = request.getParameter("action"); } if (action != null) { Method method = this.getClass().getMethod(action, new Class[]{ActionRequest.class, ActionResponse.class}); method.invoke(this, new Object[]{request, response}); } CLIENT BROWSER (action=„doHandleEvent; devs=„10168”) Call doHandleEvent 6
7
Information transfer : ActionHandler Rendering ACTION HANDLER public void doHandleEvent(ActionRequest request, ActionResponse response) throws PortletException { String selected_dev = request.getParameter(„devs"); //(selected_dev = 10168) response.setRenderParameter(„goahead", selected_dev); } Call doHandleEvent RENDER (DOVIEW) public void doView(RenderRequest req, RenderResponse res) throws PortletException { if (req.getParameter(„goahead") != null) { String devid = req.getParameter(„goahead"); } (goahead=„10168”) 7
8
Create JSP file 8
9
How to make JSR-286 compliant portlet from a class? 1.Extend it from GenericPortlet class 2.Create processAction method 3.Create doView method 4.Create eventhandler methods with ActionRequest and ActionResponse parameters 9
10
1. Extend it from GenericPortlet class Open MyFirstASMInterface.java for editing and extend it from GenericPortlet class: public class MyFirstASMInterface extends GenericPortlet { } 10
11
2. Create ProcessAction method public void processAction(ActionRequest request, ActionResponse response) throws PortletException { String action = ""; // Checking if the call contains multipart content boolean isMultipart = PortletFileUpload.isMultipartContent(request); if (!isMultipart) { // if not, it's a simple calling, let's get the name of the function from „action” parameter and check the reference of it if ((request.getParameter("action") != null) && (!request.getParameter("action").equals(""))) { action = request.getParameter("action"); } if (action != null) { try { // it's not null, invoke this function from the event-handler class and handle the possible exceptions Method method = this.getClass().getMethod(action, new Class[]{ActionRequest.class, ActionResponse.class}); method.invoke(this, new Object[]{request, response}); } catch (NoSuchMethodException e) { System.out.println("-----------------------No such method"); } catch (IllegalAccessException e) { System.out.println("----------------------Illegal access"); } catch (InvocationTargetException e) { System.out.println("-------------------Invocation target Exception"); e.printStackTrace(); } } else { // it contains multipart content, call the upload function and handle the next steps there doUpload(request, response); } 11
12
3.Create doView method public void doView(RenderRequest req, RenderResponse res) throws PortletException { try { String nextJSP = (String) req.getParameter("nextJSP"); if (nextJSP == null){ nextJSP = DISPLAY_PAGE; } // generating the JSP page PortletRequestDispatcher dispatcher; dispatcher = getPortletContext().getRequestDispatcher(nextJSP); dispatcher.include(req, res); } catch (IOException ex) { Logger.getLogger(ASM_SamplePortlet.class.getName()).log(Leve l.SEVERE, null,ex); } 12
13
First step to connect to gUSE private String DISPLAY_PAGE = "/jsp/asm_sample/asmsample.jsp"; ASMService asm_service = null; public MyFirstASMInterface() { asm_service = ASMService.getInstance(); } 13
14
Create new application Browser Client code Eventhandler code public void doCreateNewWorkflow(ActionRequest request, ActionResponse response) throws PortletException { try { String userId = request.getRemoteUser(); // getting workflows for All workflow developers Vector developers = asm_service.getWorkflowDevelopers(RepositoryItemTypeConstants.Application); Vector workflows = new Vector (); for (String dev: developers){ workflows.addAll(asm_service.getWorkflowsFromRepository(dev, RepositoryItemTypeConstants.Application)); } …..
15
Create new application …. // Getting the current workflow exported by the workflow developer …. ….latestWorkflow =w.getId().toString(); …. Calendar cal = Calendar.getInstance(); SimpleDateFormat udf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); String workflowName = WorkflowPrefix + "_"+ udf.format(cal.getTime()); asm_service.ImportWorkflow(userId,workflowName, workflowDeveloper, RepositoryItemTypeConstants.Application, latestWorkflow); } catch (Exception ex) { ex.printStackTrace(); } Eventhandler code
16
Create a table for the workflows to be listed Query Creation Date And Time Status Actions Browser Client code
17
Iterate through the workflows,get name and status ${fn:split(datetime,"-")[0]}/${fn:split(datetime,"-")[1]}/${fn:split(datetime,"-")[2]} at ${fn:split(datetime,"-")[3]}:${fn:split(datetime,"-")[4]}:${fn:split(datetime,"-")[5]} ${workflows.statusbean.status} ….. Browser Client code
18
Iterate through the workflows,get name and status Browser Eventhandler code public void doView(RenderRequest req, RenderResponse res) throws PortletException { try { String userID = req.getRemoteUser(); try { req.setAttribute("asm_instances", asm_service.getASMWorkflows(userID)); } catch (Exception e) { e.printStackTrace(); // not found notify file } …..
19
Show imported applications 1/2 doView method : … // passing arguments back, list of workflow that are already imported using getASMWorkflows(String userID) method req.setAttribute("asm_instances", asm_service.getASMWorkflows(userID) ); It returns : List, where ASMWorkflow is 19
20
20
21
Set inputs and Submit … Type the first number: Type the second number: Browser Client code
22
Set inputs and Submit public void doSubmit(ActionRequest request, ActionResponse response) throws PortletException { try { String userID = (String) request.getRemoteUser(); String selected_wf = request.getParameter("user_selected_instance"); String input_numb = request.getParameter("input_numb"); String actual_command_line = request.getParameter("command_line"); asm_service.setCommandLineArg(userID, selected_wf, "add", actual_command_line); try{ asm_service.setInputText(userID, input_numb,selected_wf, "add", "0"); }catch(Exception ex){ Logger.getLogger(ASM_SimplePortlet.class.getName()).log(Level.SEVERE, null, ex); } asm_service.submit(userID, selected_wf); } catch (ClassNotFoundException ex) { Logger.getLogger(ASM_SimplePortlet.class.getName()).log(Level.SEVERE, null, ex); } catch (InstantiationException ex) { Logger.getLogger(ASM_SimplePortlet.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(ASM_SimplePortlet.class.getName()).log(Level.SEVERE, null, ex); } Eventhandler code
23
Download method Browser Client code Eventhandler code @Override public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException { String userID = request.getRemoteUser(); Enumeration paramNames = request.getParameterNames(); String selected_wf = ""; while(paramNames.hasMoreElements()){ String act_param = (String)paramNames.nextElement(); if (act_param.startsWith(" download_ ")){ selected_wf = act_param.substring(9); }
24
Download method try { response.setContentType("application/zip"); response.setProperty("Content-Disposition", "inline; filename=\"" + selected_wf + "_enduser_outputs.zip\""); asm_service.getFileStream(userID, selected_wf, "add", "outputval.txt", response); } catch (Exception e) { e.printStackTrace(); } Eventhandler code
25
Delete method public void doDelete(ActionRequest request, ActionResponse response) throws PortletException { String userID = (String) request.getRemoteUser(); String selected_wf = request.getParameter("user_selected_instance"); asm_service.DeleteWorkflow(userID, selected_wf); } Browser Client code Eventhandler code
26
Deploy it to Liferay-based gUSE And set it as a new component in gUSE 26
27
Deploy it to Liferay-based gUSE Sign in as a user with admin roles (default username is : test@liferay.com, password is : test ) test@liferay.com 27
28
Deploy it to Liferay-based gUSE Navigate to Plugin Installer panel by clicking Manage -> Control Panel, and by selecting Plugins Installation from the menu in the left hand-side, finally clicking install More Portlets button and upload File link. 28
29
Adjusting it as a new component (just once) As admin, please go to Settings menu and select Internal Services 29
30
Adjusting it as a new component (just once) Click to New button and set the followings: Type of Component: portal Service group: gUSE URL of Component: http://localhost:8080/MyFirstASMInterfacehttp://localhost:8080/MyFirstASMInterface URL to initialize Component: http://localhost:8080/MyFirstASMInterface/init http://localhost:8080/MyFirstASMInterface/init Public URL of Component: http://localhost:8080/MyFirstASMInterfacehttp://localhost:8080/MyFirstASMInterface State: active Then click to Save button! 30
31
Adjusting it as a new component (just once) Click to copy component Properties tab Set http://localhost:8080/wspgrade as Source component and http://localhost:8080/MyFirstASMInterface as Destination one, then click to copyhttp://localhost:8080/wspgrade http://localhost:8080/MyFirstASMInterface 31
32
Adjusting it as a new component Finally initialize the whole portal again by calling http://localhost:8080/information/init.jsp http://localhost:8080/information/init.jsp (in some cases portal restart required.) 32
33
Creating new menuitem for it (just once) 33
34
Adding the portlet under this menu (just once) Click to „Add” and select „more” The newly developed portlet should be available under undefined group. Finally click to „add” in the row of the portlet 34
35
Thank you for your attention! Questions? 35
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.