Пример #1
0
 private boolean containsPublishedFiles(IStorage dir, IDesignerUser user, String timeStamp) {
   for (Version version : user.getVersions()) {
     if (!version.getTime().equals(timeStamp)) continue;
     for (String res : version.resources) {
       IPath resPath = new Path(res);
       while (resPath.segment(0).equals(".")) resPath = resPath.removeFirstSegments(1);
       if (dir.getName().equals(resPath.segment(0))) {
         return true;
       }
     }
   }
   return false;
 }
Пример #2
0
 public Reviewer isVaild(String name, String id, String versionTime) {
   IDesignerUser user = getDesignerUser(name);
   if (versionTime == null) {
     if (user.getLatestVersion() != null) versionTime = user.getLatestVersion().getTime();
   }
   if (versionTime == null) return null;
   List<Version> versionList = user.getVersions();
   for (Version version : versionList) {
     if (version.getTime().equals(versionTime)) {
       List<Reviewer> reviewers = version.getReviewers();
       for (Reviewer reviewer : reviewers) {
         if (reviewer.getEmail().equals(id)) {
           return reviewer;
         }
       }
     }
   }
   return null;
 }
Пример #3
0
  public void publish(String name, Version version) {
    IDesignerUser user = getDesignerUser(name);
    IStorage commentingDir = user.getCommentingDirectory();
    if (!commentingDir.exists()) {
      commentingDir.mkdir();
      (baseDirectory.newInstance(commentingDir, "snapshot")).mkdir();
      (baseDirectory.newInstance(commentingDir, "livedoc")).mkdir();
    }

    initVersionDir(user, version.getTime());
    saveVersionFile(user);

    // Persist review information
    this.saveReviewerVersionFiles(version);
  }
Пример #4
0
  private void loadUser(String name) {
    IStorage versionFile;
    if (ServerManager.LOCAL_INSTALL || Constants.LOCAL_INSTALL_USER_NAME.equals(name)) {
      versionFile =
          this.baseDirectory.newInstance(this.baseDirectory, "/.review/snapshot/versions.xml");
    } else {
      versionFile =
          this.baseDirectory.newInstance(
              this.baseDirectory, "/" + name + "/.review/snapshot/versions.xml");
    }
    IDesignerUser user = new DesignerUser(name);

    if (versionFile.exists()) {
      VersionFile file = new VersionFile();
      List<Version> versions = file.load(versionFile);
      for (Version version : versions) {
        user.addVersion(version);
        if (file.latestVersionID != null && version.getVersionID().equals(file.latestVersionID)) {
          user.setLatestVersion(version);
        }
      }
    }
    users.put(name, user);
  }
Пример #5
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);
    }
  }
Пример #6
0
    public List<Version> load(IStorage file) {
      ArrayList<Version> objects = new ArrayList<Version>();
      InputStream input = null;
      if (file.exists()) {
        try {
          DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
          input = file.getInputStream();
          Document document = parser.parse(input);
          Element rootElement = document.getDocumentElement();
          NodeList latestVersion = rootElement.getElementsByTagName("latestVersion");
          latestVersionID = ((Element) latestVersion.item(0)).getAttribute("id");
          NodeList versionElements = rootElement.getElementsByTagName("version");
          for (int i = 0; i < versionElements.getLength(); i++) {
            Element versionElement = (Element) versionElements.item(i);

            String versionID = versionElement.getAttribute("id");
            String time = versionElement.getAttribute("time");
            String versionTitle = versionElement.getAttribute("title");
            String isDraftString = versionElement.getAttribute("isDraft");
            boolean isDraft = Boolean.parseBoolean(isDraftString);
            String dueDate = versionElement.getAttribute("dueDate");
            String width = versionElement.getAttribute("desireWidth");
            String height = versionElement.getAttribute("desireHeight");
            boolean isHasClosedManually =
                Boolean.parseBoolean(versionElement.getAttribute("hasClosedManually"));
            String restartFrom = versionElement.getAttribute("restartFrom");
            String description = versionElement.getAttribute("description");
            boolean receiveEmail =
                Boolean.parseBoolean(versionElement.getAttribute("receiveEmail"));
            boolean hasRestarted =
                Boolean.parseBoolean(versionElement.getAttribute("hasRestarted"));
            Version version = new Version(versionID, time, isDraft, dueDate, width, height);
            if (versionTitle == null) versionTitle = "";
            version.setVersionTitle(versionTitle);
            version.setHasClosedManually(isHasClosedManually);
            version.setRestartFrom(restartFrom);
            version.setDescription(description);
            version.setReceiveEmail(receiveEmail);
            version.setHasRestarted(hasRestarted);

            NodeList reviewers = versionElement.getElementsByTagName("reviewer");
            for (int j = 0; j < reviewers.getLength(); j++) {
              Element reviewer = (Element) reviewers.item(j);

              String reviewerName = reviewer.getAttribute("name");
              String reviewerEmail = reviewer.getAttribute("email");
              version.addReviewer(
                  ReviewManager.getReviewManager().getReviewer(reviewerName, reviewerEmail));
            }

            NodeList resources = versionElement.getElementsByTagName("resource");
            for (int j = 0; j < resources.getLength(); j++) {
              Element resource = (Element) resources.item(j);

              String path = resource.getAttribute("path");
              version.addResource(path);
            }
            objects.add(version);
          }
        } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (ParserConfigurationException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (SAXException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } finally {
          try {
            if (input != null) input.close();
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
      }
      return objects;
    }
Пример #7
0
    public void save(IStorage file, org.davinci.server.review.user.IDesignerUser user) {
      OutputStream out = null;
      try {
        if (!file.exists())
          try {
            file.createNewFile();
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }

        try {
          out = file.getOutputStream();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.newDocument();

        Element rootElement = document.createElement("user");
        document.appendChild(rootElement);

        Element latestVersionElement = document.createElement("latestVersion");
        latestVersionElement.setAttribute("id", user.getLatestVersion().getVersionID());
        latestVersionElement.setAttribute("title", user.getLatestVersion().getVersionTitle());
        latestVersionElement.setAttribute("time", user.getLatestVersion().getTime());

        rootElement.appendChild(latestVersionElement);

        for (Version version : user.getVersions()) {
          Element element = document.createElement("version");
          element.setAttribute("id", version.getVersionID());
          element.setAttribute("title", version.getVersionTitle());
          element.setAttribute("time", version.getTime());
          element.setAttribute("isDraft", version.isDraft() ? "true" : "false");
          element.setAttribute("dueDate", version.dueDateString());
          element.setAttribute("desireWidth", version.getDesireWidth() + "");
          element.setAttribute("desireHeight", version.getDesireHeight() + "");
          element.setAttribute(
              "hasClosedManually", Boolean.toString(version.isHasClosedManually()));
          element.setAttribute("restartFrom", version.getRestartFrom());
          element.setAttribute("description", version.getDescription());
          element.setAttribute("receiveEmail", version.isReceiveEmail() ? "true" : "false");
          element.setAttribute("hasRestarted", version.isHasRestarted() ? "true" : "false");
          for (Reviewer reviewer : version.getReviewers()) {
            Element reviewerElement = document.createElement("reviewer");
            reviewerElement.setAttribute("name", reviewer.getUserName());
            reviewerElement.setAttribute("email", reviewer.getEmail());

            element.appendChild(reviewerElement);
          }
          for (String resource : version.resources) {
            Element resourceElement = document.createElement("resource");
            resourceElement.setAttribute("path", resource);
            element.appendChild(resourceElement);
          }
          rootElement.appendChild(element);
        }

        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.METHOD, "xml"); // $NON-NLS-1$
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); // $NON-NLS-1$
        transformer.setOutputProperty(OutputKeys.INDENT, "yes"); // $NON-NLS-1$
        DOMSource source = new DOMSource(document);
        StreamResult result = new StreamResult(out);

        transformer.transform(source, result);

      } catch (TransformerFactoryConfigurationError e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (TransformerConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (TransformerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } finally {
        try {
          if (out != null) {
            out.close();
          }
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
Пример #8
0
 /** ************************************************* */
 private void saveReviewerVersionFiles(Version version) {
   List<Reviewer> reviewers = version.getReviewers();
   for (Reviewer reviewer : reviewers) {
     this.saveReviewerVersionFile(reviewer);
   }
 }