Пример #1
0
  /*
   * (non-Javadoc)
   *
   * @see org.davinci.server.user.impl.UserManager#addUser(java.lang.String,
   * java.lang.String, java.lang.String)
   */
  public IUser addUser(String userName, String password, String email) throws UserException {

    if (checkUserExists(userName)) {
      throw new UserException(UserException.ALREADY_EXISTS);
    }

    if (this.maxUsers > 0 && this.usersCount >= this.maxUsers) {
      throw new UserException(UserException.MAX_USERS);
    }
    IPerson person = this.personManager.addPerson(userName, password, email);
    if (person != null) {

      IUser user = newUser(person, this.baseDirectory.newInstance(this.baseDirectory, userName));
      //  users.put(userName, user);
      // File userDir = user.getUserDirectory();
      // userDir.mkdir();
      // File settingsDir = user.getSettingsDirectory();
      // settingsDir.mkdir();
      IVResource project = user.createProject(IDavinciServerConstants.DEFAULT_PROJECT);

      this.usersCount++;
      return user;
    }
    return null;
  }
Пример #2
0
  public IUser getSingleUser() {
    if (localUser == null) {
      class LocalPerson implements IPerson {
        public String getEmail() {
          return "";
        }

        public String getFirstName() {
          return "";
        }

        public String getLastName() {
          return "";
        }

        public String getUserID() {
          return IDavinciServerConstants.LOCAL_INSTALL_USER;
        }
      }

      IStorage userDir = this.baseDirectory;
      userDir.mkdir();

      localUser = new User(new LocalPerson(), userDir);
      IStorage settingsDir =
          this.baseDirectory.newInstance(userDir, IDavinciServerConstants.SETTINGS_DIRECTORY_NAME);
      if (!settingsDir.exists()) {
        settingsDir.mkdir();
        IVResource project = localUser.createProject(IDavinciServerConstants.DEFAULT_PROJECT);
      }
    }
    return localUser;
  }
Пример #3
0
  @Override
  public void handleCommand(HttpServletRequest req, HttpServletResponse resp, IUser user)
      throws IOException {
    ReviewObject reviewInfo = (ReviewObject) req.getSession().getAttribute(Constants.REVIEW_INFO);
    if (null == reviewInfo) {
      /*
       * create a review object so we can comment immediately.
       */
      reviewInfo = new ReviewObject(user.getUserName());
      reviewInfo.setDesignerEmail(user.getPerson().getEmail());
      req.getSession().setAttribute(Constants.REVIEW_INFO, reviewInfo);
    }
    String designerName = reviewInfo.getDesignerName();
    IDesignerUser du = ReviewManager.getReviewManager().getDesignerUser(designerName);
    DavinciProject project = new DavinciProject();
    project.setOwnerId(du.getName());

    Comment comment = extractComment(req, project);
    Comment existingComm = ReviewCacheManager.$.getComment(project, comment.getId());
    Version version = du.getVersion(existingComm.getPageVersion());
    isUpdateStatus = Boolean.parseBoolean(req.getParameter("isUpdateStatus"));
    try {
      if (version != null && version.isClosed() && !isUpdateStatus) {
        throw new Exception(
            "The version is closed by others during your editting. Please reload the review data.");
      }

      List<Comment> commentList = new ArrayList<Comment>(1);
      commentList.add(comment);
      updateComments(commentList);
    } catch (Exception e) {
      e.printStackTrace();
      errorString = "The review is failed to be updated. Reason: " + e.getMessage();
      resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, errorString);
    }
  }
Пример #4
0
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    if (serverManager == null) {
      initialize();
    }
    revieweeName = req.getParameter("revieweeuser");
    String contextString = req.getContextPath();

    String pathInfo = req.getPathInfo();
    IUser user = (IUser) req.getSession().getAttribute(IDavinciServerConstants.SESSION_USER);
    if (ServerManager.DEBUG_IO_TO_CONSOLE) {
      System.out.println("Review Servlet request: " + pathInfo + ", logged in=" + (user != null));
    }

    if (user == null) {
      req.getSession()
          .setAttribute(IDavinciServerConstants.REDIRECT_TO, req.getRequestURL().toString());
      resp.sendRedirect(this.getLoginUrl(req));
      return;
    }

    if (pathInfo == null || pathInfo.equals("")) {
      ReviewObject reviewObject =
          (ReviewObject) req.getSession().getAttribute(Constants.REVIEW_INFO);
      if (reviewObject == null) {
        // Because the requested URL is /review the empty review object
        // means we do not have a designer name: Error.
        resp.sendRedirect(this.getLoginUrl(req));
        return;
      } else {
        resp.addCookie(
            new Cookie(Constants.REVIEW_COOKIE_DESIGNER, reviewObject.getDesignerName()));
        resp.addCookie(
            new Cookie(Constants.REVIEW_COOKIE_DESIGNER_EMAIL, reviewObject.getDesignerEmail()));

        if (reviewObject.getCommentId() != null) {
          resp.addCookie(new Cookie(Constants.REVIEW_COOKIE_CMTID, reviewObject.getCommentId()));
        }
        if (reviewObject.getFile() != null) {
          resp.addCookie(new Cookie(Constants.REVIEW_COOKIE_FILE, reviewObject.getFile()));
        }
        writeReviewPage(req, resp, "review.html");
      }
    } else {
      IPath path = new Path(pathInfo);
      String prefix = path.segment(0);
      if (prefix == null) {
        resp.sendRedirect(contextString + "/review");
        return;
      }

      if (prefix.equals(IDavinciServerConstants.APP_URL.substring(1))
          || prefix.equals(Constants.CMD_URL.substring(1))) {
        // Forward to DavinciPageServlet such as "/app/img/1.jpg" or "cmd/getUserInfo"
        req.getRequestDispatcher(pathInfo).forward(req, resp);
        return;
      }

      if (handleReviewRequest(req, resp, path) || handleLibraryRequest(req, resp, path, user)) {
        return;
      }

      // Check if it is a valid user name.
      // If it is a valid user name, do login
      // Else, error.
      IUser designer = userManager.getUser(prefix);
      if (designer == null) {
        resp.sendRedirect(this.getLoginUrl(req));
        return;
      } else {
        ReviewObject reviewObject = new ReviewObject(prefix);
        reviewObject.setDesignerEmail(designer.getPerson().getEmail());
        if (path.segmentCount() > 2) {
          // Token = 20100101/project1/folder1/sample1.html/default
          String commentId = path.segment(path.segmentCount() - 1);
          String fileName = path.removeLastSegments(1).removeFirstSegments(1).toPortableString();
          reviewObject.setFile(fileName);
          reviewObject.setCommentId(commentId);
        }
        req.getSession().setAttribute(Constants.REVIEW_INFO, reviewObject);
        resp.sendRedirect(contextString + "/review");
        return;
      }
    }
  }