Package org.davinci.server.util

Examples of org.davinci.server.util.JSONWriter


   *
   * @return
   */
  @Override
  public String toString() {
    JSONWriter writer = new JSONWriter(false);
   
    //StringBuffer jsonFormat = new StringBuffer("{");

    Field[] fields = this.getClass().getDeclaredFields();
    Boolean inclusive;
    String fieldName;
    Object returnValue;
    for (int i = 0; i < fields.length; i++) {
      fieldName = fields[i].getName();
      inclusive = Comment.fieldInclusionMap.get(fieldName);
      if (Boolean.TRUE.equals(inclusive)) {
        try {
          returnValue = fields[i].get(this);
          if ("created".equals(fieldName)) {
            SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATE_PATTERN);
            sdf.setCalendar(Calendar.getInstance(new SimpleTimeZone(0, "GMT")));
            returnValue = sdf.format((Date) returnValue);
          }
          if ("email".equals(fieldName)) {
            ReviewManager commentingManager = ReviewManager.getReviewManager();
            Reviewer reviewerUser = commentingManager.getReviewer(returnValue.toString());
            String displayName = reviewerUser.getDisplayName();
            writer.addField("displayName", null != displayName ? displayName: returnValue.toString());
          }
        } catch (Exception e) {
          returnValue = new Object();
          e.printStackTrace();
        }
       
        writer.addField(fieldName, null == returnValue ? "" : returnValue.toString());
      }
    }
    return writer.getJSON();
  }
View Full Code Here


        // Library[] libs =
        // ServerManager.getServerManager().getLibraryManager().getAllLibraries();
        String base = req.getParameter("base");
        ILibInfo[] installedLibs = user.getLibs(base);

        JSONWriter jsonWriter = new JSONWriter(true);
        jsonWriter.startObject().addFieldName("userLibs").startArray();
        ILibraryManager libMan = ServerManager.getServerManager().getLibraryManager();
        for (int i = 0; i < installedLibs.length; i++) {
            String id = installedLibs[i].getId();
            String version = installedLibs[i].getVersion();
            Library lib = libMan.getLibrary(id, version);
            /* if library doesn't exist continue */
            if (lib == null) {
                continue;
            }
            jsonWriter.startObject().addField("id", id);
            jsonWriter.addField("version", version);
            jsonWriter.addField("metaRoot", lib.getMetadataPath());
            String required = installedLibs[i].getRequired();
            jsonWriter.addField("required", required!=null && (Boolean.parseBoolean(required)?true:false));
           
            jsonWriter.addField("hasSource", lib.getSourcePath()!=null);
           
            if( installedLibs[i].getVirtualRoot()!=null)
              jsonWriter.addField("root", installedLibs[i].getVirtualRoot());
            jsonWriter.endObject();
        }
        jsonWriter.endArray().endObject();
        this.responseString = jsonWriter.getJSON();
        resp.setContentType("application/json;charset=UTF-8");
    }
View Full Code Here

      DavinciProject project = new DavinciProject();
      project.setOwnerId(du.getName());
      ReviewCacheManager.$.republish(project,vTime, version);
    }
   
    JSONWriter writer = new JSONWriter(true);
    writer.startObject();
    writer.addField("result", "OK");
    writer.addField("version", version.getTime());
    writer.addField("designer", du.getName());
    if (savingDraft) {
      ReviewManager.getReviewManager().saveDraft(du, version);
    } else {
      ReviewManager.getReviewManager().publish(du, version);
 
      String requestUrl = req.getRequestURL().toString();
      // set is used to filter duplicate email. Only send mail to one email
      // one time.
      Set<String> set = new HashSet<String>();
      String emailResult = null;
      for (Reviewer reviewer : reviewers) {
        String mail = reviewer.getEmail();
        if (mail != null && !mail.equals("") && set.add(mail)) {
          String url = ReviewManager.getReviewManager().getReviewUrl(user.getUserID(), version.getTime(), requestUrl, zazl);
          String htmlContent = getHtmlContent(user, message, url);
          String subject = Utils.getTemplates().getProperty(Constants.TEMPLATE_INVITATION_SUBJECT_PREFIX) + " " + versionTitle;
          emailResult = notifyRelatedPersons(mail, subject, htmlContent);
        }
      }
      if (emailResult != null) {
        writer.addField("emailResult", emailResult);
      }
    }
    writer.endObject();
    this.responseString = writer.getJSON();
        resp.setContentType("application/json;charset=UTF-8");
  }
View Full Code Here

    ReviewManager commentingManager = ReviewManager.getReviewManager();

    String userEmail = user.getPerson().getEmail();
    Reviewer reviewerUser = commentingManager.getReviewer(userEmail);

    JSONWriter writer = new JSONWriter(true);
    Iterator<ReviewerVersion> iterator = reviewerUser.getReviewerVersions();
    while (iterator.hasNext()) {
      ReviewerVersion reviewerVersion = iterator.next();

      String reviewDesignerID = reviewerVersion.getDesignerID();
      String reviewTime = reviewerVersion.getTimeVersion();
      if (designerIDParm == null || designerIDParm.equals("") || designerIDParm.equals(reviewDesignerID)) {
        IDesignerUser designerUser = commentingManager.getDesignerUser(reviewDesignerID);
        /* designer user removed from the system (or never existed) */
        if(designerUser==null) continue;
        Version version = designerUser.getVersion(reviewTime);

        if (version != null) {
          if (version.containsUser(userEmail)) {
            writer.startObject();
            writer.addField("designerId", reviewDesignerID);
            writer.addField("designerEmail", designerUser.getRawUser().getPerson().getEmail());
            writer.addField("designerDisplayName", designerUser.getRawUser().getPerson().getDisplayName() );
            writer.addField("versionTitle", version.getVersionTitle());
            writer.addField("versionId", version.getVersionID());
            writer.addField("dueDate", version.dueDateString());
            writer.addField("timeStamp", version.getTime());
            writer.addField("closed", version.isClosed());
            writer.addField("closedManual",version.isHasClosedManually());
            writer.addField("isDraft", version.isDraft());
            writer.addField("width", version.getDesireWidth());
            writer.addField("height", version.getDesireHeight());
            writer.addField("restartFrom",version.getRestartFrom());
            writer.addField("receiveEmail", version.isReceiveEmail());
            writer.addField("hasRestarted", version.isHasRestarted());
            if(version.getDescription()!="") {
              writer.addField("description", version.getDescription());
            }
           
            writer.addFieldName("reviewers");
            writer.startArray();
   
            for(Reviewer reviewer:version.getReviewers()){
              writer.startObject();
              writer.addField("name", reviewer.getUserID());
              writer.addField("displayName", reviewer.getDisplayName());
              writer.addField("email", reviewer.getEmail());
              writer.endObject();
            }
            writer.endArray();
            writer.endObject();
          }
        } else {
          //NOTE: Could not find version created by given designer... this could happen if a review has been deleted, but not
          //removed from the given reviewer's xml file. This could be an opportunity to prune the reviewer's index file.
        }
      }
    }
    this.responseString = writer.getJSON();
        resp.setContentType("application/json;charset=UTF-8");
  }
View Full Code Here

    if(designerName ==null||designerName.equals(""))
      designerName = user.getUserID();
    IDesignerUser designer = commentingManager.getDesignerUser(designerName);
    Version version = designer.getVersion(req.getParameter("version"));
    List<String> resource = version.getResources();
    JSONWriter writer = new JSONWriter(true);
    for (String it : resource) {
      writer.startObject();
      writer.addField("path", it);
      writer.endObject();
    }

    this.responseString = writer.getJSON();
        resp.setContentType("application/json;charset=UTF-8");
  }
View Full Code Here

        return false;
    }

    public static String vRsourcesToJson(IVResource listFiles[], boolean fullPath) {

        JSONWriter jsonWriter = new JSONWriter(true);
        for (int j = 0; j < listFiles.length; j++) {
            if (Resource.isHidden(listFiles[j])) {
                continue;
            }

            String pathName = null;
            if (fullPath) {
                pathName = listFiles[j].getPath();
            } else {
                pathName = listFiles[j].getName();
            }

            jsonWriter.startObject().addField("name", pathName);
            jsonWriter.addField("isDir", listFiles[j].isDirectory());
            jsonWriter.addField("isNew", listFiles[j].isNew());
            jsonWriter.addField("readOnly", listFiles[j].readOnly());
            jsonWriter.addField("isDirty", listFiles[j].isDirty());
            if (listFiles[j] instanceof VLibraryResource) {
                VLibraryResource r = (VLibraryResource) listFiles[j];
                jsonWriter.addField("libraryId", r.getLibraryId());
                jsonWriter.addField("libVersion", r.getLibraryVersion());
            }

            jsonWriter.endObject();
        }
        return jsonWriter.getJSON();
    }
View Full Code Here

        return jsonWriter.getJSON();
    }

    public static String foundVRsourcesToJson(IVResource listFiles[], IUser user) {

        JSONWriter jsonWriter = new JSONWriter(true);
        for (int i = 0; i < listFiles.length; i++) {
            ArrayList parents = new ArrayList();
            // parents.add(workspace);
            if (Resource.isHidden(listFiles[i])) {
                continue;
            }
            parents.addAll(Arrays.asList(listFiles[i].getParents()));

            String name = listFiles[i].getPath();
            jsonWriter.startObject().addField("file", name).addFieldName("parents").startArray();
            for (int j = 0; j < parents.size(); j++) {
                if (Resource.isHidden((IVResource) parents.get(j))) {
                    continue;
                }
                jsonWriter.startObject().addField("name", ((IVResource) parents.get(j)).getName());
                jsonWriter.addFieldName("members").startArray();

                String parentPath = ((IVResource) parents.get(j)).getPath();

                IVResource[] members = user.listFiles(parentPath);
                for (int k = 0; k < members.length; k++) {
                    if (Resource.isHidden(members[k])) {
                        continue;
                    }
                    jsonWriter.startObject().addField("isDir", members[k].isDirectory());
                    jsonWriter.addField("name", members[k].getName());
                    jsonWriter.addField("readOnly", members[k].readOnly());
                    jsonWriter.addField("isDirty", members[k].isDirty());
                    if (members[k] instanceof VLibraryResource) {
                        VLibraryResource r = (VLibraryResource) members[k];
                        jsonWriter.addField("libraryId", r.getLibraryId());
                        jsonWriter.addField("libVersion", r.getLibraryVersion());
                    }

                    jsonWriter.endObject();
                }
                jsonWriter.endArray();
                jsonWriter.endObject();

            }
            jsonWriter.endArray();
            jsonWriter.endObject();
        }
        return jsonWriter.getJSON();
    }
View Full Code Here

      }
        return result;
    }

    private String requestBuild(Map<String, List<String>> dependencies) throws IOException {
        JSONWriter jsonWriter = new JSONWriter(false);
        jsonWriter/*.startObject()*/
          .addField("optimise", "shrinksafe")
          .addField("cdn", "none")
          .addField("platforms", "all")
          .addField("themes", "claro")
          .addField("cssOptimise", "comments");
        jsonWriter.addFieldName("packages").startArray();
        jsonWriter.startObject().addField("name", "dojo").addField("version","1.8.0").endObject();
//TODO: add supplemental packages like maqetta.*
//        jsonWriter.startObject().addField("name", supplemental).addField("version","1.0.0").endObject();
        jsonWriter.endArray();
        jsonWriter.addFieldName("layers").startArray();
        jsonWriter.startObject();
        jsonWriter.addField("name", "dojo.js");
        jsonWriter.addFieldName("modules");
        jsonWriter.startArray();
      List<String> requiredDojoModules = dependencies.get("requiredDojoModules");
        for(int i = 0; i < requiredDojoModules.size(); i++) {
            jsonWriter.startObject();
          jsonWriter.addField("name", requiredDojoModules.get(i));
          jsonWriter.addField("package", "dojo");
            jsonWriter.endObject();
        }
        jsonWriter.endArray();
        jsonWriter.endObject();
        jsonWriter.endArray();
//        jsonWriter.endObject();
        String content = jsonWriter.getJSON();

        HttpClient client = new HttpClient();
        PostMethod method = new PostMethod(buildBase + "/api/build");
        theLogger.finest("/api/build: " + content);
        try {
View Full Code Here

    @Override
    public void handleCommand(HttpServletRequest req, HttpServletResponse resp, IUser user) throws IOException {
        Library[] libs = ServerManager.getServerManager().getLibraryManager().getAllLibraries();

        JSONWriter jsonWriter = new JSONWriter(true);
        jsonWriter.startObject().addFieldName("userLibs").startArray();
        for (int i = 0; i < libs.length; i++) {
            String id = libs[i].getID();
            String version = libs[i].getVersion();
            jsonWriter.startObject().addField("id", id);
            jsonWriter.addField("version", version);
            jsonWriter.addField("root", libs[i].getDefaultRoot());
            String required = libs[i].getRequired();
            jsonWriter.addField("required", required!=null || (Boolean.parseBoolean(required)?true:false));
            jsonWriter.addField("hasSource", libs[i].getSourcePath()!=null);
            jsonWriter.endObject();
        }
        jsonWriter.endArray().endObject();
        this.responseString = jsonWriter.getJSON();
        resp.setContentType("application/json;charset=UTF-8");
    }
View Full Code Here

TOP

Related Classes of org.davinci.server.util.JSONWriter

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.