@Override public void processAction(ActionRequest portletReq, ActionResponse portletResp) throws PortletException, IOException { LOGGER.entering(LOG_CLASS, "main portlet processAction entry"); portletResp.setRenderParameters(portletReq.getParameterMap()); long tid = Thread.currentThread().getId(); portletReq.setAttribute(THREADID_ATTR, tid); StringWriter writer = new StringWriter(); }
private static void assertHeaders(ActionRequest<?> request, Map<String, String> headers) { if (headers.size() == 0) { assertThat(request.getHeaders() == null || request.getHeaders().size() == 0, equalTo(true)); } else { assertThat(request.getHeaders(), notNullValue()); assertThat(request.getHeaders().size(), equalTo(headers.size())); for (String key : request.getHeaders()) { assertThat(headers.get(key), equalTo(request.getHeader(key))); } } }
private static void assertContext(ActionRequest<?> request, Map<String, String> context) { if (context.size() == 0) { assertThat(request.isContextEmpty(), is(true)); } else { ImmutableOpenMap map = request.getContext(); assertThat(map, notNullValue()); assertThat(map.size(), equalTo(context.size())); for (Object key : map.keys()) { assertThat(context.get(key), equalTo(request.getFromContext(key))); } } }
/** * Process an action request. * * @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, * javax.portlet.ActionResponse) */ public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException { if (request.getParameter(FORM_SUBMIT) != null) { // Set form text in the session bean Vlado2PortletSessionBean sessionBean = getSessionBean(request); if (sessionBean != null) sessionBean.setFormText(request.getParameter(FORM_TEXT)); } if (request.getParameter(EDIT_SUBMIT) != null) { PortletPreferences prefs = request.getPreferences(); try { prefs.setValue(EDIT_KEY, request.getParameter(EDIT_TEXT)); prefs.store(); } catch (ReadOnlyException roe) { } catch (ValidatorException ve) { } } if (request.getParameter(CONFIG_SUBMIT) != null) { PortletPreferences prefs = request.getPreferences(); try { prefs.setValue(CONFIG_KEY, request.getParameter(CONFIG_TEXT)); prefs.store(); } catch (ReadOnlyException roe) { } catch (ValidatorException ve) { } } }
public void init(int i, ActionRequest actionRequest) throws Exception { if (actionRequest.getFieldValue(i, "jobid") != null && actionRequest.getFieldValue(i, "jobid").trim().length() > 0) { this.setJobid(Integer.parseInt(actionRequest.getFieldValue(i, "jobid"))); } if (actionRequest.getFieldValue(i, "jobname") != null) { this.setJobname(actionRequest.getFieldValue(i, "jobname")); } if (actionRequest.getFieldValue(i, "time") != null) { this.setTime(actionRequest.getFieldValue(i, "time")); } if (actionRequest.getFieldValue(i, "info") != null) { this.setInfo(actionRequest.getFieldValue(i, "info")); } }
@Override public void processAction(ActionRequest portletReq, ActionResponse portletResp) throws PortletException, IOException { LOGGER.entering(LOG_CLASS, "main portlet processAction entry"); portletResp.setRenderParameters(portletReq.getParameterMap()); long tid = Thread.currentThread().getId(); portletReq.setAttribute(THREADID_ATTR, tid); StringWriter writer = new StringWriter(); // Now do the actual dispatch String target = JSP_PREFIX + "DispatcherReqRespTests3_SPEC2_19_IncludeJSPActionResponse" + JSP_SUFFIX + "?" + QUERY_STRING; PortletRequestDispatcher rd = portletConfig.getPortletContext().getRequestDispatcher(target); rd.include(portletReq, portletResp); }
/** * Inserts the project to boomark in new listItem (task) records, a record is created for each of * the listIds (taskCategoryIds) specified. * * <p>Returns boolean on whether the operation was successful. Once one failure occurs the method * returns false without further processing. * * @param db - the database connection * @param existingTasks - the list of tasks already persisted * @param listIds - this list of listIds that will have the projectIdToBookmark saved * @param userId - the id of the user inserting the records * @param projectIdToBookmark - the id of the project that is being bookmarked * @param projectNameToBookmark - the name that will saved for the bookmark (task) * @param projectIdOfLists - the id of the project that owns the lists * @param request - the request * @return boolean on whether the operation was successful * @throws SQLException - generated trying to retrieve data */ private boolean saveToLists( Connection db, TaskList existingTasks, Collection<Integer> listIds, int userId, int projectIdToBookmark, String projectNameToBookmark, int projectIdOfLists, ActionRequest request) throws SQLException { Set<Integer> existingIds = new HashSet<Integer>(existingTasks.size()); Set<Integer> createForTaskCategoryIds = new HashSet<Integer>(listIds); for (Task task : existingTasks) { existingIds.add(task.getCategoryId()); } // find all the task category ids that do not already have tasks (these will have tasks // inserted) createForTaskCategoryIds.removeAll(existingIds); if (!createForTaskCategoryIds.isEmpty()) { boolean recordInserted = false; LookupList priorityList = CacheUtils.getLookupList("lookup_task_priority"); if (priorityList.isEmpty()) throw new RuntimeException("Could not load task priorities"); // just default to the top priority int priorityId = priorityList.get(0).getId(); for (LookupElement priority : priorityList) { if (priority.getDefaultItem()) { priorityList.get(0).getId(); break; } } // Parameters TaskList taskList = new TaskList(); for (Integer taskCategoryId : createForTaskCategoryIds) { Task task = new Task(); task.setEnteredBy(userId); task.setOwner(userId); task.setDescription(projectNameToBookmark); task.setModifiedBy(userId); task.setProjectId(projectIdOfLists); task.setLinkModuleId(Constants.TASK_CATEGORY_PROJECTS); task.setLinkItemId(projectIdToBookmark); task.setCategoryId(taskCategoryId); task.setPriority(priorityId); // Verify the specified category is in the same project TaskCategoryList list = new TaskCategoryList(); list.setProjectId(projectIdOfLists); list.setCategoryId(taskCategoryId); list.buildList(db); if (list.size() == 0) { return false; } recordInserted = task.insert(db); if (!recordInserted) { request.getPortletSession().setAttribute("task", task); return false; } taskList.add(task); } // Trigger the workflow PortalUtils.processInsertHook(request, taskList); return recordInserted; } else { return true; // no inserts needed } }
@Override public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException { String ctx = request.getContextPath(); boolean isClose = "true".equals(request.getParameter("close")); if (isClose) { // Clean up the session LOG.debug("Closing the form"); request.getPortletSession().removeAttribute(VIEW_TYPE); response.sendRedirect(ctx + CLOSE_PAGE); return; } int projectIdToBookmark = Integer.valueOf(request.getParameter(PROJECT_ID_TO_BOOKMARK)); int projectIdOfLists = Integer.valueOf(request.getParameter(PROJECT_ID_OF_LISTS)); String newListName = request.getParameter(NEW_LIST_NAME); // If the user selected an item in the drop-down, then that means they are // changing lists int pidToCompare = Integer.valueOf(request.getParameter("pidToCompare")); boolean isChangePidOfLists = pidToCompare != projectIdOfLists; if (isChangePidOfLists) { LOG.debug("A new project has been selected: " + projectIdOfLists); response.setRenderParameter(PROJECT_ID_OF_LISTS, String.valueOf(projectIdOfLists)); return; } try { LOG.debug("Saving the form..."); boolean isSuccess; User user = PortalUtils.getUser(request); int userId = user.getId(); Connection db = PortalUtils.useConnection(request); Project projectOfLists = new Project(db, projectIdOfLists); Project projectToBookmark = new Project(db, projectIdToBookmark); Collection<Integer> listIds = getListIds(request.getParameterValues(LIST)); // verify user can modify lists for project boolean isAddNewList = false; if (ProjectUtils.hasAccess(projectOfLists.getId(), user, "project-lists-modify")) { if (!StringUtils.hasText(newListName) && (listIds.size() == 0)) { System.out.println("Error need to show From"); request.getPortletSession().setAttribute(ACTION_ERROR, "Choose a list or create one"); request.getPortletSession().setAttribute(VIEW_TYPE, VIEW_FORM_PAGE); return; } if (StringUtils.hasText(newListName)) { if (!ProjectUtils.hasAccess(projectOfLists.getId(), user, "project-lists-add")) { request .getPortletSession() .setAttribute(ACTION_ERROR, "Not authorized to create new list"); request.getPortletSession().setAttribute(VIEW_TYPE, VIEW_FORM_PAGE); return; } int newListId = saveNewList(db, projectIdOfLists, newListName); if (newListId == -1) { request.getPortletSession().setAttribute(ACTION_ERROR, "Unable to create new list."); request.getPortletSession().setAttribute(VIEW_TYPE, SAVE_FAILURE); return; } else { listIds.add(newListId); isAddNewList = true; } } TaskList existingTasks = findExistingTasksForProjects(db, projectIdOfLists, projectIdToBookmark); // check to see if the user is deleting tasks (listItems) if ((isAddNewList && existingTasks.size() > listIds.size() - 1) || !isAddNewList && existingTasks.size() > listIds.size()) { if (!ProjectUtils.hasAccess(projectOfLists.getId(), user, "project-lists-delete")) { request .getPortletSession() .setAttribute(ACTION_ERROR, "Not authorized to delete items"); request.getPortletSession().setAttribute(VIEW_TYPE, VIEW_FORM_PAGE); return; } else { deleteFromLists(db, existingTasks, listIds); } } isSuccess = saveToLists( db, existingTasks, listIds, userId, projectIdToBookmark, projectToBookmark.getTitle(), projectIdOfLists, request); } else { isSuccess = false; request.getPortletSession().setAttribute(ACTION_ERROR, "Not authorized to bookmark"); } if (isSuccess) { // Close the panel, everything went well response.sendRedirect(ctx + "/close_panel_refresh.jsp"); } else { request.getPortletSession().setAttribute(VIEW_TYPE, SAVE_FAILURE); } } catch (SQLException e) { e.printStackTrace(); throw new RuntimeException(e); } }
private static void putContext(ActionRequest<?> request, Map<String, String> context) { for (Map.Entry<String, String> header : context.entrySet()) { request.putInContext(header.getKey(), header.getValue()); } }
private static void putHeaders(ActionRequest<?> request, Map<String, String> headers) { for (Map.Entry<String, String> header : headers.entrySet()) { request.putHeader(header.getKey(), header.getValue()); } }