300 likes | 417 Views
Enhancing portlets with charts and secure directory service. Tomasz Kuczyński. docentt@man.poznan.pl. Poznan Supercomputing and Networking Center. Goals of today’s tutorial. Introduce your portlets enhancement possibilities with some core GridSphere services
E N D
Enhancing portlets with charts and secure directory service Tomasz Kuczyński docentt@man.poznan.pl Poznan Supercomputing and Networking Center
Goals of today’s tutorial • Introduce your portlets enhancement possibilities with some core GridSphere services • Write a portlet using the Secure Directory GridSphere service • Learn charting with GridSphere services • Have a great time !
Assumptions and requirements • We assume that: • You are familiar with GridSphere • You are familiar with portlet development • Require: • You have GridSphere installed on your machine (please consult GridSphere development tutorial) • sdcharttutorial from CVS • You are ready for development session :-) cd gridsphere/; mkdir projects; cd projects cvs -d :pserver:anonymous@portal.aei.mpg.de:/home/repository co sdcharttutorial
Secure Directory Service • Providing secure, logical file systems: • for each user of the portlet • for other GridSphere services • shared amongst portlet/portal users • Sharing files of the portlet: • with other portlet • between portlet/portal users • Easy utilization: • methods corresponding to operations on standard file systems (copy, move, delete ...) • transparent access to files with HTTP protocol
Chart Service • Providing JFreeChart wrapper for GridSphere • 17 types of charts including: • Pie, Pie3D • Bar, Bar3D, StackedBar, StackedBar3D • Area, Line, Gantt • other • Utilizing Secure Directory Service • Easy utilization: • transparent chart generation • XML based dataset and chart settings representations • transparent access to charts with HTTP protocol
Preparations • Make sure your GridSphere is correctly installed • Install tutorial • Startup tomcat, log in to the portal, subscribe to and view sdcharttutorial group • Check content of Secure Directory in your Tomcat • Upload some file with Hello Secure Directory Portlet, and check content again cd gridsphere/projects/sdcharttutorial; ant install ls –laR $CATALINA_HOME/webapps/gridsphere/WEB-INF/secure
Hello Secure Directory - source • Look at following portlet in src/org/gridlab/gridsphere/secdirtutorial/portlets/HelloSecDirPortlet.java package org.gridlab.gridsphere.secdirtutorial.portlets; ... import org.gridlab.gridsphere.services.core.secdir.SecureDirectoryService; import org.gridlab.gridsphere.services.core.secdir.FileInfo; import org.gridlab.gridsphere.services.core.secdir.FileLocationID; ... import org.apache.oro.text.perl.Perl5Util; public class HelloSecDirPortlet extends ActionPortlet{ private static final String VIEW_JSP = "secdir/view.jsp"; private static final String VIEW_ERROR_JSP = "secdir/error.jsp"; private SecureDirectoryService secureDirectoryService = null; public static final String ROOT_DIR = "secdirandcharttutorial"; public static final String ROOT_PATH = "/some/path/"; private Perl5Util util = new Perl5Util();
Hello Secure Directory - source public void init(javax.portlet.PortletConfig portletConfig) throws ... javax.portlet.PortletException { super.init(portletConfig); try{ secureDirectoryService = (SecureDirectoryService) ... createPortletService(SecureDirectoryService.class); DEFAULT_VIEW_PAGE = "showFile"; }catch(PortletServiceException e){ DEFAULT_VIEW_PAGE = VIEW_ERROR_JSP; } } public void showFile(RenderFormEvent event) throws PortletException { String userID = (String) ((Map) event.getRenderRequest().getAttribute... (PortletRequest.USER_INFO)).get("user.id"); UserData userData = new UserData(); try { if (!secureDirectoryService.categoryExistsForUser(userID, ROOT_DIR)) secureDirectoryService.createCategoryForUser(userID, ROOT_DIR);
Hello Secure Directory - source FileInfo[] fileList = secureDirectoryService.getFileList(... secureDirectoryService.createFileLocationID(userID, ROOT_DIR, ROOT_PATH)); String[] fileURIs = null; if (fileList != null) { fileURIs = new String[fileList.length]; for (int i = 0; i < fileList.length; ++i) { if (!fileList[i].isDirectory()) { FileLocationID fileLocationID = secureDirectoryService.... createFileLocationID(userID, ROOT_DIR, ROOT_PATH + fileList[i].getResource()); fileURIs[i] = secureDirectoryService.getDownloadFileUrl... (fileLocationID, fileList[i].getResource(), null); } } } userData.setFileList(fileList); userData.setFileURIs(fileURIs); } catch (Exception e) { log.error("Secure service unavailable", e); } event.getRenderRequest().setAttribute("userData", userData); setNextState(event.getRenderRequest(), VIEW_JSP); }
Hello Secure Directory - source public void uploadFile(ActionFormEvent event) throws PortletException { String userID = (String) ((Map) event.getActionRequest().getAttribute... (PortletRequest.USER_INFO)).get("user.id"); try { FileInputBean fi = event.getFileInputBean("userfile"); String filename = fi.getFileName(); if (fi.getSize() < FileInputBean.MAX_UPLOAD_SIZE) { filename = util.substitute("s!\\\\!/!g", filename); if (util.match("m!/([^/]+)$!", filename)) { filename = util.group(1); } filename = util.substitute("s! !!g", filename); secureDirectoryService.addFile(secureDirectoryService.create... FileLocationID(userID, ROOT_DIR, ROOT_PATH + filename), fi.getInputStream()); } else log.error("Size of uploaded file is to big"); } catch (Exception ie) {} } }
Hello Secure Directory - source package org.gridlab.gridsphere.secdirtutorial.portlets; import org.gridlab.gridsphere.services.core.secdir.FileInfo; public class UserData { private FileInfo[] fileList; private String[] fileURIs; public FileInfo[] getFileList() { return fileList; } public void setFileList(FileInfo[] fileList) { this.fileList = fileList; } public String[] getFileURIs() { return fileURIs; } public void setFileURIs(String[] fileURIs) { this.fileURIs = fileURIs; } }
SecDir Service- summary • Check also: • webapp/jsp/secdir/view.jsp • webapp/jsp/secdir/error.jsp • More advanced examples: • Commander, Banner and Web Clipping portlets in extras webapp (utilization of Secure Directory Service with portlets) • Chart Service in GridSphere (utilization of Secure Directory Service with other service) cd gridsphere/; mkdir projects; cd projects cvs -d :pserver:anonymous@portal.aei.mpg.de:/home/repository co extras
Hello Chart 1- source • Look at following portlet in src/org/gridlab/gridsphere/charttutorial/portlets/HelloChartPortlet1.java package org.gridlab.gridsphere.charttutorial.portlets; ... import org.gridlab.gridsphere.services.core.charts.*; import org.gridlab.gridsphere.services.core.secdir.FileLocationID; ... public class HelloChartPortlet1 extends ActionPortlet{ private ChartService chartService = null; private static final String VIEW_JSP = "charts/view1.jsp"; private static final String VIEW_ERROR_JSP = "charts/error.jsp"; public void init(PortletConfig portletConfig) throws PortletException { super.init(portletConfig); try { chartService = (ChartService) createPortletService(ChartService.class); DEFAULT_VIEW_PAGE = "viewChart"; } catch (PortletServiceException e) { DEFAULT_VIEW_PAGE = VIEW_ERROR_JSP; } }
Hello Chart 1- source public void viewChart(RenderFormEvent event) throws PortletException { String userID = (String) ((Map) event.getRenderRequest().getAttribute... (PortletRequest.USER_INFO)).get("user.id"); FileLocationID chartLocationID = chartService.createChartLocationID(userID, HelloSecDirPortlet.ROOT_DIR, HelloSecDirPortlet.ROOT_PATH + "ChartTest1"); String chartURL = chartService.getChartUrl(chartLocationID); ImageBean imageBean = event.getImageBean("chart1"); if (chartURL != null) imageBean.setSrc(chartURL); setNextState(event.getRenderRequest(), VIEW_JSP); } public void createChart(ActionFormEvent event) throws PortletException { String userID = (String) ((Map) event.getActionRequest().getAttribute... (PortletRequest.USER_INFO)).get("user.id"); org.jfree.data.DefaultPieDataset dataset = new ... org.jfree.data.DefaultPieDataset(); dataset.setValue("Pacific", 179700); dataset.setValue("Atlantic", 106463); dataset.setValue("Indian", 74917);
Hello Chart1 - source try { FileLocationID chartLocationID = chartService.createChartLocationID(userID, HelloSecDirPortlet.ROOT_DIR, HelloSecDirPortlet.ROOT_PATH + "ChartTest1"); ChartDescriptor chartDescriptor = chartService.createPie3DChart... (chartLocationID, dataset); SeriesPaint seriesPaintPacific = new SeriesPaint(); SeriesPaint seriesPaintAtlantic = new SeriesPaint(); SeriesPaint seriesPaintIndian = new SeriesPaint(); Color blue = new Color(); blue.setBlue(255); Color white = new Color(); white.setBlue(255); white.setRed(255); white.setGreen(255); Color grey = new Color(); grey.setBlue(200); grey.setRed(200); grey.setGreen(200);
Hello Chart1 - source seriesPaintPacific.setColor(blue); seriesPaintIndian.setColor(white); seriesPaintAtlantic.setColor(grey); chartDescriptor.getChartInfo().getPlot().addSeriesPaint(0, ... seriesPaintPacific); chartDescriptor.getChartInfo().getPlot().addSeriesPaint(1,... seriesPaintAtlantic); chartDescriptor.getChartInfo().getPlot().addSeriesPaint(2, ... seriesPaintIndian); chartDescriptor.getChartInfo().getPlot().setForegroundAlpha(0.5f); BackgroundPaint backgroundPaint = new BackgroundPaint(); Gradient background = new Gradient(); GradientPoint point1 = new GradientPoint(); point1.setColor(white); point1.setX(0); point1.setY(0); GradientPoint point2 = new GradientPoint(); point2.setColor(blue); point2.setX(400); point2.setY(300);
Hello Chart1 - source background.addGradientPoint(point1); background.addGradientPoint(point2); backgroundPaint.setGradient(background); chartDescriptor.getChartInfo().getPlot().setBackgroundPaint... (backgroundPaint); chartDescriptor.getChartInfo().setLegend(false); chartDescriptor.getChartInfo().getPlot().getSettings().getPie().... setLabelGenerator("{0} Ocean is {2}"); chartService.setChartDescriptor(chartLocationID, chartDescriptor); chartService.setChartTitle(chartLocationID, "Area of oceans ... [mln * km2]"); } catch (Exception ie) {} } }
Hello Chart 2- source • Look at following portlet in src/org/gridlab/gridsphere/charttutorial/portlets/HelloChartPortlet2.java package org.gridlab.gridsphere.charttutorial.portlets; ... import org.gridlab.gridsphere.services.core.charts.*; import org.gridlab.gridsphere.services.core.secdir.FileLocationID; ... public class HelloChartPortlet2 extends ActionPortlet { private ChartService chartService = null; private static final String VIEW_JSP = "charts/view2.jsp"; private static final String VIEW_ERROR_JSP = "charts/error.jsp"; public void init(PortletConfig portletConfig) throws PortletException { super.init(portletConfig); try { chartService = (ChartService) createPortletService(ChartService.class); DEFAULT_VIEW_PAGE = "viewChart"; } catch (PortletServiceException e) { DEFAULT_VIEW_PAGE = VIEW_ERROR_JSP; } }
Hello Chart2 - source public void viewChart(RenderFormEvent event) throws PortletException { String userID = (String) ((Map) event.getRenderRequest().getAttribute... (PortletRequest.USER_INFO)).get("user.id"); FileLocationID chartLocationID = chartService.createChartLocationID(userID, HelloSecDirPortlet.ROOT_DIR, HelloSecDirPortlet.ROOT_PATH + "ChartTest2"); String chartURL = chartService.getChartUrl(chartLocationID); ImageBean imageBean = event.getImageBean("chart2"); if (chartURL != null) imageBean.setSrc(chartURL); setNextState(event.getRenderRequest(), VIEW_JSP); } public void createChart(ActionFormEvent event) throws PortletException { String userID = (String) ((Map) event.getActionRequest().getAttribute... (PortletRequest.USER_INFO)).get("user.id"); org.jfree.data.DefaultCategoryDataset dataset = new org.jfree.data.... DefaultCategoryDataset(); dataset.setValue(179700, "Pacific", "Ocean"); dataset.setValue(106463, "Atlantic", "Ocean"); dataset.setValue(74917, "Indian", "Ocean"); dataset.setValue(44406, "Asia", "Land"); dataset.setValue(29853, "Africa", "Land");
Hello Chart2 - source dataset.setValue(24298, "North America", "Land"); dataset.setValue(17684, "South America", "Land"); dataset.setValue(13176, "Antarctic", "Land"); dataset.setValue(9763, "Europe", "Land"); dataset.setValue(8936, "Australia", "Land"); try { FileLocationID chartLocationID = chartService.createChartLocationID(userID, HelloSecDirPortlet.ROOT_DIR, HelloSecDirPortlet.ROOT_PATH + "ChartTest2"); ChartDescriptor chartDescriptor = chartService. ... createStackedBar3DChart(chartLocationID, dataset); Category category = chartDescriptor.getChartInfo().getPlot().... getSettings().getCategory(); category.setRangeAxisLabel("area [mln * km2]"); category.setDomainAxisLabel(""); category.setPlotOrientation("PlotOrientation.HORIZONTAL"); SeriesPaint pacificPaint = new SeriesPaint(); Gradient pacificGradient = new Gradient(); GradientPoint point1 = new GradientPoint(); GradientPoint point2 = new GradientPoint();
Hello Chart2 - source Color yellow = new Color(); yellow.setGreen(255); yellow.setRed(255); Color white = new Color(); white.setBlue(255); white.setRed(255); white.setGreen(255); point1.setColor(white); point1.setX(100); point1.setY(0); point2.setColor(yellow); point2.setX(200); point2.setY(0); pacificGradient.addGradientPoint(point1); pacificGradient.addGradientPoint(point2); pacificPaint.setGradient(pacificGradient); chartDescriptor.getChartInfo().getPlot().addSeriesPaint(pacificPaint); chartDescriptor.getFileInfo().getImage().setFilename(... HelloSecDirPortlet.ROOT_PATH + "Chart2Test_but_other_filename"); BackgroundPaint backgroundPaint = new BackgroundPaint();
Hello Chart2 - source Color lgreen = new Color(); ... backgroundPaint.setColor(lgreen); chartDescriptor.getChartInfo().setBackgroundPaint(backgroundPaint); chartDescriptor.getChartInfo().getPlot().setForegroundAlpha(0.75f); chartService.setChartDescriptor(chartLocationID, chartDescriptor); chartService.setChartTitle(chartLocationID, "Area of Oceans ... and Continents"); } catch (Exception ie) {} } public void createChartNoData(ActionFormEvent event) throws ... PortletException { String userID = (String) ((Map) event.getActionRequest().getAttribute(... PortletRequest.USER_INFO)).get("user.id"); org.jfree.data.DefaultCategoryDataset dataset = new org.jfree.data.... DefaultCategoryDataset(); try { FileLocationID chartLocationID = chartService.createChartLocationID(userID, HelloSecDirPortlet.ROOT_DIR, HelloSecDirPortlet.ROOT_PATH + "ChartTest2"); chartService.createStackedBarChart(chartLocationID, dataset); } catch (Exception ie) {} ...
Hello Chart 3- source • Look at following portlet in src/org/gridlab/gridsphere/charttutorial/portlets/HelloChartPortlet3.java package org.gridlab.gridsphere.charttutorial.portlets; ... import org.gridlab.gridsphere.services.core.charts.*; import org.gridlab.gridsphere.services.core.secdir.FileLocationID; ... public class HelloChartPortlet3 extends ActionPortlet { private ChartService chartService = null; private static final String VIEW_JSP = "charts/view3.jsp"; private static final String VIEW_ERROR_JSP = "charts/error.jsp"; public void init(PortletConfig portletConfig) throws PortletException { super.init(portletConfig); try { chartService = (ChartService) createPortletService(ChartService.class); DEFAULT_VIEW_PAGE = "viewChart"; } catch (PortletServiceException e) { DEFAULT_VIEW_PAGE = VIEW_ERROR_JSP; } }
Hello Chart3 - source public void viewChart(RenderFormEvent event) throws PortletException { String userID = (String) ((Map) event.getRenderRequest().getAttribute... (PortletRequest.USER_INFO)).get("user.id"); FileLocationID chartLocationID = chartService.createChartLocationID(userID, HelloSecDirPortlet.ROOT_DIR, HelloSecDirPortlet.ROOT_PATH + "ChartTest3"); String chartURL = chartService.getChartUrl(chartLocationID); ImageBean imageBean = event.getImageBean("chart3"); if (chartURL != null) imageBean.setSrc(chartURL); setNextState(event.getRenderRequest(), VIEW_JSP); } public void createChart(ActionFormEvent event) throws PortletException { String userID = (String) ((Map) event.getActionRequest().getAttribute... (PortletRequest.USER_INFO)).get("user.id"); org.jfree.data.DefaultCategoryDataset dataset = new org.jfree.data.... DefaultCategoryDataset(); dataset.setValue(979, "South America", "Salto del Angel"); dataset.setValue(604, "Europe", "Giessbach"); dataset.setValue(580, "Oceania", "Sutherland"); dataset.setValue(491, "North America", "Ribbon"); dataset.setValue(422, "Europe", "Gavarnie");
Hello Chart3 - source ... try { FileLocationID chartLocationID = chartService.createChartLocationID(userID, HelloSecDirPortlet.ROOT_DIR, HelloSecDirPortlet.ROOT_PATH + "ChartTest3"); ChartDescriptor chartDescriptor = chartService.createBar3DChart(... chartLocationID, dataset); chartDescriptor.getChartInfo().getPlot().getSettings().getCategory().... setRangeAxisLabel("height [m]"); chartDescriptor.getChartInfo().getPlot().getSettings().getCategory().... setDomainAxisLabel("name"); Image image = chartDescriptor.getFileInfo().getImage(); image.setWidth(950); image.setHeight(400); image.setQuality(1.0f); image.setType("JPEG"); Subtitle subtitle = new Subtitle(); subtitle.setText("Obviously this is not full list ;-)"); chartDescriptor.getChartInfo().setSubtitle(subtitle); chartDescriptor.getChartInfo().getPlot().setForegroundAlpha(0.25f); chartService.setChartDescriptor(chartLocationID, chartDescriptor); chartService.setChartTitle(chartLocationID, "Waterfalls of the World"); } catch (Exception ie) {} ...
Chart Service - summary • Check also: • webapp/jsp/charts/view1.jsp • webapp/jsp/charts/view2.jsp • webapp/jsp/charts/view3.jsp • webapp/jsp/charts/error.jsp • Datasets and chart descriptor are stored in SecDir as XML files, that are validated against XML Schemas (editing these files causes automatic chart regeneration when next getChartURL()is performed) • More advanced examples: • GridSphere Services of SSH Session Server Framework (more information on Open Grid Portals web site)
Questions ? For more information visit: • GridSphere http://www.gridsphere.org • GridLab http://www.gridlab.org • Open Grid Portals http://www.opengridportals.com • JFreeChart http://www.jfree.org/jfreechart/ Thank you