<%@page import="com.plumtree.remote.prc.IRemoteSession, com.plumtree.remote.prc.RemoteSessionFactory, com.plumtree.remote.prc.collaboration.*,com.plumtree.remote.prc.collaboration.project.*, com.plumtree.remote.portlet.*,java.util.*,java.text.*" %> <%! //gets the project manager private IProjectManager getProjectManager(HttpServletRequest req, HttpServletResponse res, JspWriter pout) throws Exception { IProjectManager projectManager = null; IPortletContext portletContext = PortletContextFactory.createPortletContext(req, res); IPortletRequest portletRequest = portletContext.getRequest(); String loginToken = portletRequest.getLoginToken(); if (null == loginToken) { pout.println("Unable to retrieve the login token. Confirm that the login token has been checked in the Advanced Settings page of the Web Service."); } //get the remote session com.plumtree.remote.prc.IRemoteSession portalSession = portletContext.getRemotePortalSession(); //get a collab factory and a project manager ICollaborationFactory collabFactory = portalSession.getCollaborationFactory(); projectManager = collabFactory.getProjectManager(); return projectManager; } %> <% //booleans for create, remove and search boolean create = false; boolean remove = false; boolean search = false; //optional name and description for create String name = request.getParameter("name"); String description = request.getParameter("description"); //project id required for remove int projectID = -1; //search text required for search String searchText = request.getParameter("searchText"); //determine which option we are using- create, remove, or search. String select = request.getParameter("projectMethod"); if (null != select) { if (select.equals("create")) { create = true; } else if (select.equals("remove")) { remove = true; } else if (select.equals("search")) { search = true; } } //if any of these is true, set hosted display mode if (create || remove || search) { IPortletContext portletContext = PortletContextFactory.createPortletContext(request, response); IPortletResponse portletResponse = portletContext.getResponse(); portletResponse.setHostedDisplayMode(HostedDisplayMode.Hosted); } //see if we have a project id- if so, convert it to an int. String strProjectID = request.getParameter("projectID"); if (null != strProjectID) { try { projectID = Integer.parseInt(strProjectID); } catch (Exception e) { out.println("Unable to parse projectID of " + strProjectID); } } %> <% if (create) { //if no name or description, show text boxes for name and description, and a submit button if (null == name || null == description) { %> <% } else //create a project and print out the project id { name = (null == name) ? "ExampleProject" : name; description = (null == description) ? "ExampleProjectDescription" : description; //create the project IProjectManager projectManager = getProjectManager(request, response, out); IProject project = projectManager.createProject(name, description); //if you want to set additional properties, make sure that store() is called or the changes will not be persisted. //for example: /* project.setStatus(ProjectStatus.NOT_STARTED); project.setStartDate(new Date()); */ //call store before asking for the id. project.store(); %> <% } } if (remove) { //if no project ID, add a text box for projectID, and a submit button if (projectID == -1) { %> <% } else { //remove the project IProjectManager projectManager = getProjectManager(request, response, out); IProject project = projectManager.getProject(projectID); //squawk if the project could not be retrieved if (null == project) { %> <% } else { //remove projectManager.removeProject(project); %> <% } } } if (search) { //if no search text, add a text box for search text, and a submit button if (null == searchText) { %> <% } else { //perform the search IProjectManager projectManager = getProjectManager(request, response, out); IProjectFilter projectFilter = projectManager.createProjectFilter(); //hard-code the max results to 10 projectFilter.setMaximumResults(10); //set the query projectFilter.setNameSearchText(searchText); //execute the search and print out the results IProject[] projects = projectManager.queryProjects(projectFilter); if (projects.length > 0) { %> <% for (int i = 0; i < projects.length; i++) { IProject project = projects[i]; %> <% } } else { %> <% } } } %>
Project Name: "/>
Project Description: "/>
<% out.println("ID of newly created project is " + project.getID()); %>
Project ID: "/>
<%out.println("Unable to retrieve project with ID of " + projectID);%>
<%out.println("Project with id of " + projectID + " removed.");%>
Search Text: "/>
Search Results
Project Name Project ID
<%out.println(project.getName());%> <%out.println(project.getID());%>
<%out.println("No projects found using search query of " + searchText);%>