Package edu.uga.galileo.voci.bo

Examples of edu.uga.galileo.voci.bo.Command


   *      javax.servlet.http.HttpServletResponse)
   */
  @Override
  protected void handleRequest( HttpServletRequest request, HttpServletResponse response )
  {
    Command command = (Command) request.getAttribute("command");
    boolean goToUserList = false;
    String cancel;
    int userId = 0;
    boolean isCancel = false;
    boolean isHistory = false;
    if (command.getModifier() != null)
    {
      isHistory = command.getModifier().equalsIgnoreCase("history");
    }

    if (((cancel = request.getParameter("cancelChanges")) != null) && (cancel.equals("yes")))
    {     
      request.setAttribute("successMessage", "Your changes have been cancelled.");
      isCancel = true;
      listUsers(request, response, command);
    }

    // add or update user
    if ((request.getParameter("userId") != null) && (!isCancel) && (!isHistory))
    {
      userId = Integer.valueOf(request.getParameter("userId"));
      if (userId == -1)
      {
        // add new user
        addNewUser(request, response, command);
      }
      else
      {
        if (userId > 0)
        {
          // update user information
          updateUser(request, response, command);
        }
      }
    }

    if ((command.getModifier() != null) && (command.getModifier().trim().length() > 0))
    {
      if ((command.getModifier().equalsIgnoreCase("list")) || (goToUserList))
      {
        listUsers(request, response, command);
      }

      if (command.getModifier().equalsIgnoreCase("add"))
      {
        processAddRequest(request, response, command);
      }

      if (command.getModifier().equalsIgnoreCase("update"))
      {
        processUpdateRequest(request, response, command);
      }

      if (command.getModifier().equalsIgnoreCase("history"))
      {
        handleHistory(request, response, command);
      }
    }

View Full Code Here


  protected void handleRequest(HttpServletRequest request,
      HttpServletResponse response) {
    User user = (User) request.getSession().getAttribute("user");
    ArrayList<String> errors = new ArrayList<String>();
    HashMap<String, String> fieldMessages = new HashMap<String, String>();
    Command command = (Command) request.getAttribute("command");
    WorkflowManager workflowManager = new WorkflowManager();

    // handle the "view vs. admin"-specific changes
    String openNodesAttributeName = command.isViewCommand() ? "openViewNodes"
        : "openTreeNodes";
    String contentListPage = "/"
        + command.getDisplayProject()
        + (command.isViewCommand() ? "/Content.jsp"
            : "/admin/ContentList.jsp");
    String vboViewPage = "/"
        + command.getDisplayProject()
        + (command.isViewCommand() ? "/VBODisplay.jsp"
            : "/admin/Community.jsp");
    if (command.isViewCommand()) {
      request.setAttribute("vboType", "Community");
    }

    // then do the regular page processing
    ArrayList<Integer> openNodes = (ArrayList<Integer>) request
        .getSession().getAttribute(openNodesAttributeName);
    if (openNodes == null) {
      openNodes = new ArrayList<Integer>();
    }

    boolean goToList = true;
    String cancel;

    if ((command.getModifier() != null)
        && (command.getModifier().equals("items"))) {
      // get the listing of items that belong to this community
      getItemWrappersForNode(command, (User) request.getSession()
          .getAttribute("user"), request);
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("search"))) {
      // prep for search functions
      setSearchObject(command, new CommunityManager(), request, errors);
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("open"))) {
      // open nodes in the content tree
      openNodes(command, request, openNodesAttributeName, openNodes);
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("close"))) {
      // close nodes in the content tree
      closeNodes(command, request, openNodesAttributeName, openNodes);
    } else if (((cancel = request.getParameter("cancelChanges")) != null)
        && (cancel.equals("yes"))) {
      // user has elected to cancel changes made to a form
      request.setAttribute("successMessages",
          "Your changes have been cancelled.");
      int idToCancel = Integer.parseInt(request
          .getParameter("communityId"));
      ContentLockManager.unlockContentByTypeAndID(ContentType.COMMUNITY
          .getValue(), idToCancel);
      goToList = true;
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("add"))) {
      goToList = handleCommunityAddRequest(request, command, errors,
          user, openNodes, openNodesAttributeName);
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("update"))
        && (!command.isViewCommand())) {
      goToList = handleCommunityUpdateRequest(request, command, errors,
          user, openNodes, fieldMessages);
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("view"))
        && (command.isViewCommand())) {
      goToList = handleCommunityViewRequest(request, command);
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("delete"))) {
      goToList = handleCommunityDeleteRequest(request, command, errors,
          user);
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("history"))) {
      goToList = handleHistoryRequest(request, command, errors, user);
    }

    Community community = request.getAttribute("community") == null ? null
        : (Community) request.getAttribute("community");

    // one last permissions check if we're on our way to the edit page
    if ((community != null)
        && (!command.isViewCommand())
        && (errors.size() == 0)
        && (fieldMessages.size() == 0)
        && (!goToList)
        && (!workflowManager.canEdit(user, command.getProject(),
            command.getCommand(), community.getCommunityId()))) {
      errors.add("You don't have permission to "
          + "work on the requested content.");
      goToList = true;
    }

    if (errors.size() > 0) {
      request.setAttribute("errorMessage", generateErrorMessage(errors));
    }

    if (fieldMessages.size() > 0) {
      request.setAttribute("fieldMessages", fieldMessages);
    }

    if (goToList) {
      // we're on our way back to the content tree

      // the request dispatcher's forward method strips anchors, so we
      // set page target here and let the ContentList.jsp handle it
      // in the body tag's onload event.
      if (community != null) {
        request.setAttribute("jumpToTarget", "#node"
            + community.getCommunityId());
      }

      // only get the content tree if we're not on the search page
      if ((command.getModifier() == null)
          || (!command.getModifier().equals("search"))) {
        ArrayList<VBOTreeNodeWrapper> tree = TreeManager.getInstance()
            .getTreeNodeWrappers(
                command.getProject(),
                openNodes,
                command.isViewCommand() ? true : false,
                -1,
                (User) request.getSession()
                    .getAttribute("user"));
        request.setAttribute("tree", tree);
      }

      // if this is from a search, flag it as such for the ContentList.jsp
      // page
      if (request.getParameter("fs") != null) {
        command.setModifier("search");
        ArrayList<String> other = new ArrayList<String>();
        other.add("results");
        command.setOther(other);
      }

      try {
        request.getRequestDispatcher(
            response.encodeURL(contentListPage)).forward(request,
            response);
      } catch (ServletException e) {
        Logger.error("Couldn't forward request to " + contentListPage,
            e);
      } catch (IOException e) {
        Logger.error("Couldn't forward request to " + contentListPage,
            e);
      }
    } else {
      // we're going to the community add/edit or view page
      request.setAttribute(command.isViewCommand() ? "vbo" : "community",
          community);
      ArrayList<AuditLog> historyRecords = (new AuditLogManager())
          .getUpdateRecords(
              ((HashMap<String, Project>) getServletContext()
                  .getAttribute("projectMap")).get(
                  command.getProject()).getProjectId(),
              ContentType.COMMUNITY, community.getCommunityId());
      if ((historyRecords != null) && (historyRecords.size() > 0)) {
        request.setAttribute("history", historyRecords);
      }
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  @Override
  protected void handleRequest(HttpServletRequest request,
      HttpServletResponse response) {
    Command command = (Command) request.getAttribute("command");
    ItemManager itemManager = new ItemManager();
    WorkflowManager workflowManager = new WorkflowManager();
    User user = (User) request.getSession().getAttribute("user");
    ArrayList<String> errors = new ArrayList<String>();
    HashMap<String, String> fieldMessages = new HashMap<String, String>();
    Item item = null;
    boolean updated = false;

    // handle the "view vs. admin"-specific changes
    String openNodesAttributeName = command.isViewCommand() ? "openViewNodes"
        : "openTreeNodes";
    String contentListPage = "/"
        + command.getDisplayProject()
        + (command.isViewCommand() ? "/Content.jsp"
            : "/admin/ContentList.jsp");
    String vboViewPage = "/"
        + command.getDisplayProject()
        + (command.isViewCommand() ? "/VBODisplay.jsp"
            : "/admin/Item.jsp");
    if (command.isViewCommand()) {
      request.setAttribute("vboType", "Item");
    }

    // then do the regular page processing
    ArrayList<Integer> openNodes = (ArrayList<Integer>) request
        .getSession().getAttribute(openNodesAttributeName);
    if (openNodes == null) {
      openNodes = new ArrayList<Integer>();
    }

    boolean goToList = true;
    String cancel;

    if ((command.getModifier() != null)
        && (command.getModifier().equals("search"))) {
      // prep for search functions
      setSearchObject(command, new ItemManager(), request, errors);
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("open"))) {
      // open nodes in the content tree
      openNodes(command, request, "openTreeNodes", openNodes);
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("close"))) {
      // close nodes in the content tree
      closeNodes(command, request, "openTreeNodes", openNodes);
    } else if (((cancel = request.getParameter("cancelChanges")) != null)
        && (cancel.equals("yes"))) {
      // user is canceling changes made to the item edit form
      request.setAttribute("successMessages",
          "Your changes have been cancelled.");
      int idToCancel = Integer.parseInt(request.getParameter("itemId"));
      ContentLockManager.unlockContentByTypeAndID(ContentType.ITEM
          .getValue(), idToCancel);
      goToList = true;
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("add"))) {
      // user has requested an item to add
      goToList = false;
      try {
        item = itemManager.getItem(command, -1, false);
        if ((command.getOther() != null)
            && (command.getOther().get(0).equals("to"))) {
          int parentId = Integer.parseInt(command.getOther().get(1));
          // verify that the user can edit the requested parent
          if (!workflowManager.canEdit(user, command.getProject(),
              command.getCommand(), parentId)) {
            errors.add("You don't have permission to add a "
                + "item to the requested object.");
            goToList = true;
          } else {
            try {
              ContentType parentType = DAOFactory.getHelperDAO()
                  .getContentTypeById(parentId);
              if (parentType != ContentType.ITEM) {
                if (!openNodes.contains(parentId)) {
                  openNodes.add(parentId);
                  request.getSession().setAttribute(
                      "openTreeNodes", openNodes);
                }
                request.setAttribute("parentId", String
                    .valueOf(parentId));
              } else {
                errors.add("You can't add a bundle to "
                    + "the requested element type.");
                goToList = true;
              }
            } catch (NoAvailableDAOException e) {
              Logger.fatal("Couldn't get helper DAO", e);
              errors
                  .add("A fatal internal error has occurred.  "
                      + "Please contact the system administrator.");
              goToList = true;
            }
          }
        } else {
          errors
              .add("An item must be added to a parent collection or community.");
        }
      } catch (NoSuchItemException e) {
        Logger.error("An empty item couldn't be created.", e);
        errors.add("Empty item couldn't be constructed.");
        goToList = true;
      }
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("delete"))) {
      // user is deleting an item
      try {
        int itemId = Integer.parseInt(command.getOther().get(0));
        if (!workflowManager.canEdit(user, command.getProject(),
            command.getCommand(), itemId)) {
          errors.add("You don't have permission to delete "
              + "the requested item.");
        } else {
          try {
            item = itemManager.getItemForUpdate(command, itemId,
                false, request.getSession());
            itemManager.deleteItem(item, ((User) request
                .getSession().getAttribute("user")));
            updated = true;
            request.setAttribute("successMessage", "Item " + itemId
                + " successfully deleted.");
          } catch (NoSuchItemException e) {
            errors.add("The item to delete either doesn't exist, "
                + "or it isn't empty and can't be deleted.");
          } catch (SQLException e) {
            Logger.error("Couldn't delete item.", e);
            errors
                .add("A database error occurred processing your request.");
          } catch (ContentLockedException e) {
            errors.add(e.getMessage());
          }
        }
      } catch (NumberFormatException e) {
        errors.add("Invalid item ID format.");
      } catch (NullPointerException e) {
        errors.add("Invalid item ID format.");
      }
      goToList = true;
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("view"))
        && (command.isViewCommand())) {
      // user is requesting a page from the public face
      goToList = false;

      try {
        item = itemManager.getItem(command, Integer.parseInt(command
            .getOther().get(0)), true);
      } catch (NumberFormatException e) {
        Logger.warn("Couldn't get requested item: "
            + command.getOther() == null ? "{null}" : command
            .getOther().get(0));
        goToList = true;
      } catch (NoSuchItemException e) {
        Logger.warn("Couldn't get requested item: "
            + command.getOther() == null ? "{null}" : command
            .getOther().get(0));
        goToList = true;
      }

      if (item != null) {
        request.setAttribute("vbo", item);
        int resultsPerPage = Configuration.getInt("publicItemsPerPage");
        request.setAttribute("resultsPerPage", resultsPerPage);
        request
            .setAttribute("crumbSet", TreeManager.getInstance()
                .getBreadCrumbsForVBO(command.getProject(),
                    item, true));
      }
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("update"))
        && (!command.isViewCommand())) {
      // user has requested a document to update, or has submitted an
      // update to a document from the form
      if ((command.getOther() != null) && (command.getOther().size() > 1)) {
        request.getSession().setAttribute("itemListStart",
            command.getOther().get(1));
        request.getSession().setAttribute("itemListCount",
            command.getOther().get(2));
        request.getSession().setAttribute("itemListParent",
            command.getOther().get(3));
      }

      int parentId = -1;
      goToList = false;
      if (request.getParameter("parentId") != null) {
        parentId = Integer.parseInt(request.getParameter("parentId"));
        // verify that the user can edit the requested parent
        if (!workflowManager.canEdit(user, command.getProject(),
            command.getCommand(), parentId)) {
          errors.add("You don't have permission to add a "
              + "item to the requested object.");
          goToList = true;
        } else {
          request.setAttribute("parentId", request
              .getParameter("parentId"));
        }
      }

      if (!goToList) {
        try {
          int itemId;
          boolean isFormSubmission = false;
          if (request.getParameter("itemId") != null) {
            // the id comes from the request if it's a form
            // submission
            itemId = Integer.parseInt(request
                .getParameter("itemId"));
            isFormSubmission = true;
          } else {
            // the id comes from the "other" portion of the command
            // if the user's clicked the item for editing
            itemId = Integer.parseInt(command.getOther().get(0));
          }

          if (itemId == -1) {
            // this is a new item
            try {
              item = itemManager.getItem(command, -1, false);
            } catch (NoSuchItemException e) {
              Logger.error("An empty item couldn't be created.",
                  e);
              errors.add("Empty item couldn't be constructed.");
              goToList = true;
            }
          } else {
            // this is an existing item
            // first make sure that the user can edit it
            if (!workflowManager.canEdit(user,
                command.getProject(), command.getCommand(),
                itemId)) {
              errors.add("You don't have permission to edit "
                  + "the requested item.");
              goToList = true;
            } else {
              try {
                item = itemManager.getItemForUpdate(command,
                    itemId, false, request.getSession());
              } catch (NoSuchItemException e) {
                Logger.warn("Requested item (" + itemId
                    + ") couldn't be retrieved", e);
                errors.add("Requested item (" + itemId
                    + ") couldn't be retrieved");
                goToList = true;
              } catch (ContentLockedException e) {
                errors.add(e.getMessage());
                goToList = true;
              }
            }
          }

          if ((isFormSubmission) && (item != null)) {
            String oldData = item.toString();

            populateVBOFromRequest(item, request, fieldMessages,
                true);

            String addToRepeatables = request
                .getParameter("addToRepeatables");
            if ((addToRepeatables == null)
                || (addToRepeatables.trim().length() == 0)) {

              if (oldData.equals(item.toString())) {
                errors.add("No changes detected.");
              }

              if ((errors.size() == 0)
                  && (fieldMessages.size() == 0)) {
                try {
                  if (item.getId() == -1) {
                    itemManager.addItem(user, item,
                        parentId);
                    request.setAttribute("successMessage",
                        "Item successfully added.");
                  } else {
                    itemManager.updateItem(item,
                        ((User) request.getSession()
                            .getAttribute("user")),
                        oldData);
                    updated = true;
                    request
                        .setAttribute(
                            "successMessage",
                            "Item '"
                                + item
                                    .getMetadataBasedTitle()
                                + "' successfully updated.");
                    if ((request.getParameter("fs") != null)
                        && (request
                            .getSession()
                            .getAttribute(
                                "searchResults") != null)) {
                      SearchManager
                          .updateSessionSearchResults(
                              request, item);
                    }
                  }

                  goToList = true;
                } catch (NoSuchItemException e) {
                  Logger.warn("Item " + item.getItemId()
                      + " couldn't be found for update",
                      e);
                  errors.add(e.getMessage());
                } catch (SQLException e) {
                  Logger
                      .error(
                          "Couldn't add an item to the database",
                          e);
                  errors
                      .add("A database problem occurred while updating your item: "
                          + e.getMessage());
                }
              }
            }
          }

          request.setAttribute("item", item);
        } catch (NumberFormatException e) {
          errors.add("Invalid item ID");
          goToList = true;
        }

        if (fieldMessages.size() != 0) {
          String plural = "";
          if (fieldMessages.size() > 1) {
            plural = "s";
          }
          errors.add("Form field" + plural
              + " failed validation (see below).");
        }
      }
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("history"))) {
      // user is requesting an old item record from the audit log
      goToList = false;

      String[] vals = command.getOther().get(0).split("\\|");
      AuditLogManager alm = new AuditLogManager();
      int itemId = -1;
      try {
        itemId = Integer.parseInt(vals[2]);
        if (!workflowManager.canEdit(user, command.getProject(),
            command.getCommand(), itemId)) {
          errors.add("You don't have permission to edit "
              + "the requested item.");
          goToList = true;
        } else {
          AuditLog record = alm.getRecord(Integer.parseInt(vals[0]),
              ContentType.valueOf(Integer.parseInt(vals[1])),
              (itemId = Integer.parseInt(vals[2])), Timestamp
                  .valueOf(vals[3]));
          String data = record.getDataExport();
          item = new Item();
          item.fromString(data);
        }
      } catch (NullPointerException e) {
        goToList = true;
        errors.add("Invalid history request format.");
      } catch (NumberFormatException e) {
        goToList = true;
        errors.add("Invalid history request format.");
      } catch (NoSuchAuditLogRecordException e) {
        errors.add("The history record requested couldn't be located.");
      } catch (DataTypeMismatchException e) {
        Logger.error("Data type mismatch occurred pulling "
            + command.getOther().get(0) + " from the audit log", e);
        errors
            .add("A system error was encountered (DataTypeMismatch). "
                + "Please contact a system administrator.");
      }

      if (!goToList) {
        if (item == null) {
          try {
            item = itemManager.getItem(command, itemId, false);
          } catch (NoSuchItemException e) {
            goToList = true;
            errors.add("No such item (" + itemId + ") found.");
          }
        }
      }

      request.setAttribute("isDirty", "t");
    }

    // one last permissions check if we're on our way to the edit page
    if ((item != null)
        && (!command.isViewCommand())
        && (errors.size() == 0)
        && (fieldMessages.size() == 0)
        && (!goToList)
        && (!workflowManager.canEdit(user, command.getProject(),
            command.getCommand(), item.getItemId()))) {
      errors.add("You don't have permission to "
          + "work on the requested content.");
      goToList = true;
    }

    if (errors.size() > 0) {
      request.setAttribute("errorMessage", generateErrorMessage(errors));
    }

    if (fieldMessages.size() > 0) {
      request.setAttribute("fieldMessages", fieldMessages);
    }

    if (goToList) {
      // the request dispatcher's forward method strips anchors, so we
      // set page target here and let the ContentList.jsp handle it
      // in the body tag's onload event.
      if (item != null) {
        if (request.getParameter("parentId") != null) {
          request.setAttribute("jumpToTarget", "#node"
              + request.getParameter("parentId"));
        } else {
          request.setAttribute("jumpToTarget", "#node"
              + item.getItemId());
        }
      }

      if ((command.getModifier() == null)
          || (!command.getModifier().equals("search"))) {
        ArrayList<VBOTreeNodeWrapper> tree = TreeManager.getInstance()
            .getTreeNodeWrappers(
                command.getProject(),
                openNodes,
                command.isViewCommand() ? true : false,
                -1,
                (User) request.getSession()
                    .getAttribute("user"));
        request.setAttribute("tree", tree);
      }

      // if this is from a search, flag it as such for the ContentList.jsp
      // page
      if (request.getParameter("fs") != null) {
        command.setModifier("search");
        ArrayList<String> other = new ArrayList<String>();
        other.add("results");
        command.setOther(other);
      } else if ((updated)
          && (request.getSession().getAttribute("savedCommand") != null)) {
        command = (Command) request.getSession().getAttribute(
            "savedCommand");
        try {
          request.getRequestDispatcher(
              response.encodeURL("/do" + command.buildURL()))
              .forward(request, response);
          return;
        } catch (ServletException e) {
          Logger.error("Couldn't forward request ContentList.jsp", e);
        } catch (IOException e) {
          Logger.error("Couldn't forward request ContentList.jsp", e);
        }
      }

      try {
        request.getRequestDispatcher(
            response.encodeURL(contentListPage)).forward(request,
            response);
      } catch (ServletException e) {
        Logger.error("Couldn't forward request to " + contentListPage,
            e);
      } catch (IOException e) {
        Logger.error("Couldn't forward request to " + contentListPage,
            e);
      }
    } else {
      ArrayList<GUIElement> guiElements = item.getGUIElements();
      String addToRepeatables = request.getParameter("addToRepeatables");
      if ((addToRepeatables != null)
          && (addToRepeatables.trim().length() > 0)) {
        for (GUIElement guiElem : guiElements) {
          if (guiElem.getName().equals(addToRepeatables)) {
            guiElem.setRepeatableElementsToAdd(3);
            request.setAttribute("isDirty", "t");
            break;
          }
        }
      }
      request.setAttribute("elements", guiElements);

      request.setAttribute("item", item);
      ArrayList<AuditLog> historyRecords = (new AuditLogManager())
          .getUpdateRecords(
              ((HashMap<String, Project>) getServletContext()
                  .getAttribute("projectMap")).get(
                  command.getProject()).getProjectId(),
              ContentType.ITEM, item.getItemId());
      if ((historyRecords != null) && (historyRecords.size() > 0)) {
        request.setAttribute("history", historyRecords);
      }

View Full Code Here

   * @see edu.uga.galileo.voci.servlet.ControlledHttpServlet#handleRequest(javax.servlet.http.HttpServletRequest,
   *      javax.servlet.http.HttpServletResponse)
   */
  protected void handleRequest(HttpServletRequest request,
      HttpServletResponse response) {
    Command command = (Command) request.getAttribute("command");
    try {
      Project project = DAOFactory.getProjectDAO().getProject(
          command.getProject());
      request.setAttribute("project", project);
    } catch (NoSuchProjectException e1) {
      Logger.warn("The requested project (" + command.getProject()
          + ") couldn't be retrieved", e1);
      request.setAttribute("errorMsg",
          "Information about this project couldn't "
              + "be retrieved.");
    } catch (NoAvailableDAOException e1) {
      Logger.fatal("The project DAO couldn't be retrieved", e1);
      request.setAttribute("errorMsg",
          "Information about this project couldn't "
              + "be retrieved.  This is a FATAL error, so "
              + "please stop what you're doing and contact "
              + "a system administrator.");
    }
    try {
      request.getRequestDispatcher(
          response.encodeURL("/" + command.getDisplayProject()
              + "/Welcome.jsp")).forward(request, response);
    } catch (ServletException e) {
      Logger.error("Couldn't forward to Welcome.jsp", e);
    } catch (IOException e) {
      Logger.error("Couldn't forward to Welcome.jsp", e);
View Full Code Here

      Configuration.addConfigValue("debugLevel", debugLevel);
      Logger.setLogLevel(Integer.parseInt(debugLevel));
    }

    // ...then on to the basics
    Command command = (Command) request.getAttribute("command");

    HashMap<String, String> configMap = new HashMap<String, String>();
    Set<String> keySet = Configuration.getKeys();
    for (String key : keySet) {
      configMap.put(key, Configuration.getString(key));
    }
    request.setAttribute("configMap", configMap);

    HashMap<String, String> headerMap = new HashMap<String, String>();
    java.util.Enumeration e = request.getHeaderNames();
    String header;
    while (e.hasMoreElements()) {
      header = (String) e.nextElement();
      headerMap.put(header, request.getHeader(header).replaceAll(
          "([,|;])", "$1 "));
    }
    request.setAttribute("headerMap", headerMap);

    HashMap<String, String> contextMap = new HashMap<String, String>();
    contextMap.put("getContextPath", request.getContextPath());
    contextMap.put("getPathInfo", request.getPathInfo());
    contextMap.put("getPathTranslated", request.getPathTranslated());
    contextMap.put("getQueryString", request.getQueryString());
    contextMap.put("getRequestURI", request.getRequestURI());
    contextMap.put("getRequestURL", request.getRequestURL().toString());
    contextMap.put("getServletPath", request.getServletPath());
    request.setAttribute("contextMap", contextMap);

    HashMap<String,String> sessionUserMap = new HashMap<String,String>();
    HashMap<String,HttpSession> sessionMap = SessionTracker.getSessionMap();
    String[] keys = new String[sessionMap.size()];
    keys = sessionMap.keySet().toArray(keys);
    HttpSession session;
    for (String key : keys) {
      session = sessionMap.get(key);
      if (session.getAttribute("user")!=null) {
        sessionUserMap.put(key, ((User)session.getAttribute("user")).getUserName());
      } else {
        sessionUserMap.put(key, "{guest user}");
      }
    }
    request.setAttribute("activeSessions", sessionUserMap);

    try {
      request.getRequestDispatcher(
          response.encodeURL("/" + command.getDisplayProject()
              + "/Information.jsp")).forward(request, response);
    } catch (ServletException e1) {
      Logger.error("Couldn't forward to Information.jsp", e1);
    } catch (IOException e1) {
      Logger.error("Couldn't forward to Information.jsp", e1);
View Full Code Here

   *      javax.servlet.http.HttpServletResponse)
   */
  @SuppressWarnings("unchecked")
  protected void handleRequest(HttpServletRequest request,
      HttpServletResponse response) {
    Command command = (Command) request.getAttribute("command");
    ProjectManager manager = new ProjectManager();

    Project project = null;
    ArrayList<String> errors = new ArrayList<String>();
    HashMap<String, String> fieldMessages = new HashMap<String, String>();

    // first check to see if we're just pulling a record from the history
    try {
      if ((command.getModifier() != null)
          && (command.getModifier().equals("history"))) {
        String[] vals = command.getOther().get(0).split("\\|");
        AuditLogManager alm = new AuditLogManager();
        try {
          AuditLog record = alm.getRecord(Integer.parseInt(vals[0]),
              ContentType.valueOf(Integer.parseInt(vals[1])),
              Integer.parseInt(vals[2]), Timestamp
                  .valueOf(vals[3]));
          String data = record.getDataExport();
          project = new Project();
          project.fromString(data);
          request.setAttribute("isDirty", "t");
        } catch (NullPointerException e) {
          errors.add("Invalid history request format.");
        } catch (NumberFormatException e) {
          errors.add("Invalid history request format.");
        } catch (NoSuchAuditLogRecordException e) {
          errors
              .add("The history record requested couldn't be located.");
        } catch (DataTypeMismatchException e) {
          Logger.error(
              "Data type mismatch occurred pulling "
                  + command.getOther().get(0)
                  + " from the audit log", e);
          errors
              .add("A system error was encountered (DataTypeMismatch). "
                  + "Please contact a system administrator.");
        }

        if (project == null) {
          project = manager.getProject(command.getProject());
        }
      } else {
        // if it's not from history, then...
        project = manager.getProject(command.getProject());

        String cancel;
        if (((cancel = request.getParameter("cancelChanges")) != null)
            && (cancel.equals("yes"))) {
          request.setAttribute("successMessage",
              "Your changes have been cancelled.");
        } else {
          if (request.getParameter("projectId") != null) {
            // this is an update from the project form if the
            // projectId param is set
            String oldVersion = project.toString();
            if ((project.getProjectId() != Integer.parseInt(request
                .getParameter("projectId")))
                || (!project.getHandle().equals(
                    request.getParameter("handle")))
                || (!project.getHandle().equals(
                    command.getProject()))) {
              errors
                  .add("Form corruption occurred ... please try again.");
            } else {
              // go ahead and populate the data from the request
              populateVBOFromRequest(project, request,
                  fieldMessages, true);
            }

            if (project.toString().equals(oldVersion)) {
              errors.add("No changes detected.");
            }

            if ((errors.size() == 0) && (fieldMessages.size() == 0)) {
              User user = (User) request.getSession()
                  .getAttribute("user");
              manager.updateProject(project, user, oldVersion);
              request.setAttribute("successMessage",
                  "Project successfully updated <span class=\"tinyformtext\">("
                      + Calendar.getInstance().getTime()
                          .toString() + ")</span>");
            }
          }
        }
      }
    } catch (NoSuchProjectException e) {
      Logger.fatal("Project handle '" + command.getProject()
          + "' doesn't exist!", e);
      request
          .setAttribute(
              "errorMessage",
              "The requested project couldn't be located.  "
                  + "This is a FATAL error, so please stop working in this area, "
                  + "and contact the system administrator.");
    }

    request.setAttribute("project", project);
    // put the project's history in the request scope (the project itself
    // is in the application scope)
    ArrayList<AuditLog> historyRecords = (new AuditLogManager())
        .getUpdateRecords(project.getProjectId(), ContentType.PROJECT,
            project.getProjectId());
    if ((historyRecords != null) && (historyRecords.size() > 0)) {
      request.setAttribute("history", historyRecords);
    }

    // set up error and field messages, as appropriate
    if ((errors.size() > 0) || (fieldMessages.size() > 0)) {
      if (fieldMessages.size() > 0) {
        String plural = "";
        if (fieldMessages.size() > 1) {
          plural = "s";
        }
        errors.add("Form field" + plural
            + " failed validation (see below).");
      }

      request.setAttribute("errorMessage", generateErrorMessage(errors));
      request.setAttribute("fieldMessages", fieldMessages);
    }

    try {
      request.getRequestDispatcher(
          response.encodeURL("/" + command.getDisplayProject()
              + "/admin/Projects.jsp"))
          .forward(request, response);
    } catch (ServletException e) {
      Logger.error("Couldn't dispatch to /" + command.getDisplayProject()
          + "/admin/Projects.jsp", e);
    } catch (IOException e) {
      Logger.error("Couldn't dispatch to /" + command.getDisplayProject()
          + "/admin/Projects.jsp", e);
    }
  }
View Full Code Here

  protected void handleRequest(HttpServletRequest request,
      HttpServletResponse response) {
    User user = (User) request.getSession().getAttribute("user");
    ArrayList<String> errors = new ArrayList<String>();
    HashMap<String, String> fieldMessages = new HashMap<String, String>();
    Command command = (Command) request.getAttribute("command");
    WorkflowManager workflowManager = new WorkflowManager();

    // handle the "view vs. admin"-specific changes
    String openNodesAttributeName = command.isViewCommand() ? "openViewNodes"
        : "openTreeNodes";
    String contentListPage = "/"
        + command.getDisplayProject()
        + (command.isViewCommand() ? "/Content.jsp"
            : "/admin/ContentList.jsp");
    String vboViewPage = "/"
        + command.getDisplayProject()
        + (command.isViewCommand() ? "/VBODisplay.jsp"
            : "/admin/Bundle.jsp");
    if (command.isViewCommand()) {
      request.setAttribute("vboType", "Bundle");
    }

    // then do the regular page processing
    ArrayList<Integer> openNodes = (ArrayList<Integer>) request
        .getSession().getAttribute(openNodesAttributeName);
    if (openNodes == null) {
      openNodes = new ArrayList<Integer>();
    }

    boolean goToList = true;
    String cancel;

    if ((command.getModifier() != null)
        && (command.getModifier().equals("items"))) {
      // get the listing of items that belong to this bundle
      getItemWrappersForNode(command, (User) request.getSession()
          .getAttribute("user"), request);
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("search"))) {
      // prep for search functions
      setSearchObject(command, new BundleManager(), request, errors);
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("open"))) {
      // open nodes in the content tree
      openNodes(command, request, openNodesAttributeName, openNodes);
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("close"))) {
      // close nodes in the content tree
      closeNodes(command, request, openNodesAttributeName, openNodes);
    } else if (((cancel = request.getParameter("cancelChanges")) != null)
        && (cancel.equals("yes"))) {
      // user has elected to cancel changes made to a form
      request.setAttribute("successMessages",
          "Your changes have been cancelled.");
      int idToCancel = Integer.parseInt(request.getParameter("bundleId"));
      ContentLockManager.unlockContentByTypeAndID(ContentType.COMMUNITY
          .getValue(), idToCancel);
      goToList = true;
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("add"))) {
      goToList = handleBundleAddRequest(request, command, errors, user,
          openNodes, openNodesAttributeName);
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("delete"))) {
      goToList = handleBundleDeleteRequest(request, command, errors, user);
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("update"))
        && (!command.isViewCommand())) {
      goToList = handleBundleUpdateRequest(request, command, errors,
          user, openNodes, fieldMessages);
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("view"))
        && (command.isViewCommand())) {
      goToList = handleBundleViewRequest(request, command);
    } else if ((command.getModifier() != null)
        && (command.getModifier().equals("history"))) {
      goToList = handleHistoryRequest(request, command, errors, user);
    }

    Bundle bundle = request.getAttribute("bundle") == null ? null
        : (Bundle) request.getAttribute("bundle");

    // one last permissions check if we're on our way to the edit page
    if ((bundle != null)
        && (!command.isViewCommand())
        && (errors.size() == 0)
        && (fieldMessages.size() == 0)
        && (!goToList)
        && (!workflowManager.canEdit(user, command.getProject(),
            command.getCommand(), bundle.getBundleId()))) {
      errors.add("You don't have permission to "
          + "work on the requested content.");
      goToList = true;
    }

    if (errors.size() > 0) {
      request.setAttribute("errorMessage", generateErrorMessage(errors));
    }

    if (fieldMessages.size() > 0) {
      request.setAttribute("fieldMessages", fieldMessages);
    }

    if (goToList) {
      // the request dispatcher's forward method strips anchors, so we
      // set page target here and let the ContentList.jsp handle it
      // in the body tag's onload event.
      if (bundle != null) {
        request.setAttribute("jumpToTarget", "#node"
            + bundle.getBundleId());
      }

      ArrayList<VBOTreeNodeWrapper> tree = TreeManager.getInstance()
          .getTreeNodeWrappers(command.getProject(), openNodes,
              command.isViewCommand() ? true : false, -1,
              (User) request.getSession().getAttribute("user"));
      request.setAttribute("tree", tree);

      // if this is from a search, flag it as such for the ContentList.jsp
      // page
      if (request.getParameter("fs") != null) {
        command.setModifier("search");
        ArrayList<String> other = new ArrayList<String>();
        other.add("results");
        command.setOther(other);
      }

      try {
        request.getRequestDispatcher(
            response.encodeURL(contentListPage)).forward(request,
            response);
      } catch (ServletException e) {
        Logger.error("Couldn't forward request to " + contentListPage,
            e);
      } catch (IOException e) {
        Logger.error("Couldn't forward request to " + contentListPage,
            e);
      }
    } else {
      ArrayList<GUIElement> guiElements = bundle.getGUIElements();
      String addToRepeatables = request.getParameter("addToRepeatables");
      if ((addToRepeatables != null)
          && (addToRepeatables.trim().length() > 0)) {
        for (GUIElement guiElem : guiElements) {
          if (guiElem.getName().equals(addToRepeatables)) {
            guiElem.setRepeatableElementsToAdd(3);
            request.setAttribute("isDirty", "t");
            break;
          }
        }
      }
      request.setAttribute("elements", guiElements);

      request.setAttribute(command.isViewCommand() ? "vbo" : "bundle",
          bundle);
      ArrayList<AuditLog> historyRecords = (new AuditLogManager())
          .getUpdateRecords(
              ((HashMap<String, Project>) getServletContext()
                  .getAttribute("projectMap")).get(
                  command.getProject()).getProjectId(),
              ContentType.BUNDLE, bundle.getBundleId());
      if ((historyRecords != null) && (historyRecords.size() > 0)) {
        request.setAttribute("history", historyRecords);
      }
View Full Code Here

   *      javax.servlet.http.HttpServletResponse)
   */
  @Override
  protected void handleRequest(HttpServletRequest request,
      HttpServletResponse response) {
    Command command = (Command) request.getAttribute("command");
    boolean goToRoleList = false;
    String cancel;
    int roleId = 0;
    boolean isCancel = false;
    boolean isHistory = false;
    if (command.getModifier() != null) {
      isHistory = command.getModifier().equalsIgnoreCase("history");
    }

    if (((cancel = request.getParameter("cancelChanges")) != null)
        && (cancel.equals("yes"))) {
      Logger.debug("\n\n user clicked cancel \n\n");
      request.setAttribute("successMessage",
          "Your changes have been cancelled.");
      isCancel = true;
      listRoles(request, response, command);
    }

    // add or update role
    if ((request.getParameter("roleId") != null) && (!isCancel)
        && (!isHistory)) {
      roleId = Integer.valueOf(request.getParameter("roleId"));
      if (roleId == -1) {
        // add top level role
        addTopLevelRole(request, response, command);
      }
      if ((roleId > 0)
          && (request.getParameter("isChild")
              .equalsIgnoreCase("true"))) {
        // add child role
        addChildRole(request, response, command);
      } else {
        if (roleId > 0) {
          // update role information
          updateRole(request, response, command);
        }
      }

    }

    if ((command.getModifier() != null)
        && (command.getModifier().trim().length() > 0)) {
      if ((command.getModifier().equalsIgnoreCase("list"))
          || (goToRoleList)) {
        listRoles(request, response, command);
      }
      if (command.getModifier().equalsIgnoreCase("addTopRole")) {
        processAddTopRoleRequest(request, response, command);
      }
      if (command.getModifier().equalsIgnoreCase("addChildRole")) {
        processAddChildRoleRequest(request, response, command);
      }
      if (command.getModifier().equalsIgnoreCase("update")) {
        processUpdateRequest(request, response, command);
      }
      if (command.getModifier().equalsIgnoreCase("delete")) {
        deleteRole(request, response, command);
      }
      if (command.getModifier().equalsIgnoreCase("history")) {
        handleHistory(request, response, command);
      }
    }

  }
View Full Code Here

    SearchResult[] sortedResults = new SearchResult[results.size()];
    sortedResults = results.toArray(sortedResults);
    Arrays.sort(sortedResults);

    // set up a basic command for passing to the various managers
    Command command = null;
    try {
      command = new Command((new ProjectManager())
          .getProjectHandle(projectId), null, null, null);
    } catch (NoSuchProjectException e) {
      Logger.error("Couldn't get project ID", e);
    }

    ArrayList<SearchResult> finalResults = new ArrayList<SearchResult>();
    if (command != null) {
      // then fill an arraylist to the maximum number of results with
      // the weight-sorted results
      int totalResults = 0;
      int maxResults = Configuration.getInt("maximumQueryResults");
      MetadataManager metadataManager = new MetadataManager();
      ProjectManager projectManager = new ProjectManager();
      for (SearchResult result : sortedResults) {
        try {
          command.setProject(projectManager.getProjectHandle(result
              .getProjectId()));
        } catch (NoSuchProjectException e) {
          Logger.error("Couldn't find project handle for ID "
              + result.getProjectId());
        }
View Full Code Here

TOP

Related Classes of edu.uga.galileo.voci.bo.Command

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.