Package com.google.gson

Examples of com.google.gson.JsonPrimitive


    }
    return a;
  }

  private void add(final JsonArray a, final Edit src) {
    a.add(new JsonPrimitive(src.getBeginA()));
    a.add(new JsonPrimitive(src.getEndA()));
    a.add(new JsonPrimitive(src.getBeginB()));
    a.add(new JsonPrimitive(src.getEndB()));
  }
View Full Code Here


      String[] bowArr = new String[tokensBOW.size()];
      JsonObject bowJson = new JsonObject();
      bowJson.add("#combine", Utils.createJsonArray(tokensBOW.toArray(bowArr)));

      JsonArray weightedQuery = new JsonArray();
      weightedQuery.add(new JsonPrimitive(tokenWeight));
      weightedQuery.add(bowJson);
      weightedQuery.add(new JsonPrimitive(phraseWeight));
      weightedQuery.add(bopJson);
      queryJson.add("#weight", weightedQuery);
    }else {     // k > 1
      // add phrase translations into a #weight array structure
      if (phraseWeight > 0) {
        JsonArray pArr = Utils.createJsonArrayFromProbabilities(translation.getPhraseDist());
        queryPJson.add("#weight", pArr);
      }

      // add token translations into a #combine of #weight array structures
      JsonArray tokensArr = new JsonArray();
      if (tokenWeight > 0) {
        for (String srcToken : stemmedSourceTokens) {
          HMapSFW nbestDist = translation.getDistributionOf(srcToken);

          if (defaultTokenizer.isStopWord(srcToken)){
            continue;
          }
          LOG.info("Processing "+srcToken);

          // combine translations from N-best AND bilingual dictionary
          List<PairOfFloatMap> tokenRepresentationList = new ArrayList<PairOfFloatMap>();

          // Pr{bitext}
          if (bitextWeight > 0) {
            HMapSFW bitextDist = clGenerator.getTranslations(origQuery.trim(), srcToken, pairsInGrammar, stemmed2Stemmed);
            if(bitextDist != null && !bitextDist.isEmpty()){
              tokenRepresentationList.add(new PairOfFloatMap(bitextDist, bitextWeight));
            }
          }

          // Pr{scfg}
          if (scfgWeight > 0) {
            HMapSFW scfgDist = scfgGenerator.getTranslations(origQuery.trim(), srcToken, probMap, stemmed2Stemmed);
            if (scfgDist != null && !scfgDist.isEmpty() ){
              tokenRepresentationList.add(new PairOfFloatMap(scfgDist, scfgWeight));
            }
          }

          // Pr{n-best}
          if (mtWeight > 0 && nbestDist != null && !nbestDist.isEmpty()) {
            Utils.normalize(nbestDist);
            tokenRepresentationList.add(new PairOfFloatMap(nbestDist, mtWeight));
          }

          JsonArray combinedArr;
          float scale = 1;
          if (scaling) {
            scale = scale * translation.getSourceTokenCnt().get(srcToken) / ((float)translation.getCount());
          }
          if(tokenRepresentationList.size() == 0) {
            continue;       // if empty distr., do not represent this source token in query
          } else if(tokenRepresentationList.size() == 1) {
            combinedArr = Utils.createJsonArrayFromProbabilities(Utils.scaleProbMap(lexProbThreshold, scale, tokenRepresentationList.get(0).getMap()));
          } else {
            combinedArr = Utils.createJsonArrayFromProbabilities(Utils.combineProbMaps(lexProbThreshold, scale, tokenRepresentationList));
          }

          JsonObject tokenWeightedArr = new JsonObject();         
          tokenWeightedArr.add("#weight", combinedArr);

          // optional: if this source token has occurred more than once per query, reflect this in the representation
          //  for (int i = 0; i < Math.ceil(tokenCount.get(srcToken)/(float)kBest); i++) {
          //    tokensArr.put(tokenWeightedArr);
          //  }
          tokensArr.add(tokenWeightedArr);
        }
        queryTJson.add("#combine", tokensArr);
      }

      // combine the token-based and phrase-based representations into a #combweight structure
      JsonArray queryJsonArr = new JsonArray();

      HMapSFW scaledPhrase2Weight = null;
      if (phraseWeight > 0) {
        scaledPhrase2Weight = Utils.scaleProbMap(lexProbThreshold, phraseWeight, translation.getPhraseDist());     
        for (String phrase : scaledPhrase2Weight.keySet()) {
          queryJsonArr.add(new JsonPrimitive(scaledPhrase2Weight.get(phrase)));
          queryJsonArr.add(new JsonPrimitive(phrase));
        }
      }
      if (tokenWeight > 0) {
        queryJsonArr.add(new JsonPrimitive(tokenWeight));
        queryJsonArr.add(queryTJson);
      }
      queryJson.add("#combweight", queryJsonArr);
    }

View Full Code Here

      // unless the token has less than 3 characters, in which bigram segmentation will only return
      // the token itself
      if (numTransPerToken == 1 && !bigramSegment) {
        String trans = getBestTranslation(origQuery, token);
        if (trans != null) {
          tokenTranslations.add(new JsonPrimitive(trans));
        }
      } else {
        JsonObject tokenTrans = new JsonObject();
        JsonArray weights = Utils.createJsonArrayFromProbabilities(getTranslations(origQuery, token, probMap, stemmed2Stemmed));
        if (weights != null) {
View Full Code Here

  }

  public static JsonArray createJsonArray(String[] elements) {
    JsonArray arr = new JsonArray();
    for (String s: elements) {
      arr.add(new JsonPrimitive(s));
    }
    return arr;
  }
View Full Code Here

      return null;
    }

    JsonArray arr = new JsonArray();
    for(Entry<String> entry : probMap.entrySet()) {
      arr.add(new JsonPrimitive(entry.getValue()));
      arr.add(new JsonPrimitive(entry.getKey()));
    }
    return arr;
  }
View Full Code Here

      // and we're not doing bigram segmentation (which requires a weighted structure since it
      // splits a single token into multiple ones)
      if (numTransPerToken == 1 && !bigramSegment) {
        String trans = getBestTranslation(token);
        if (trans != null) {
          tokenTranslations.add(new JsonPrimitive(trans));
        }
      } else {
        JsonObject tokenTrans = new JsonObject();
        HMapSFW distr = getTranslations(origQuery, token, phrasePairs, stemmed2Stemmed);
  JsonArray weights = Utils.createJsonArrayFromProbabilities(distr);
View Full Code Here

        }
        sb.append("<input type=\"button\" onclick=\"ducc_confirm_terminate_reservation("+id+")\" value=\"Terminate\" "+disabled+"/>");
      }
    }
    sb.append("</span>");
    row.add(new JsonPrimitive(sb.toString()));
    // Id
    sb = new StringBuffer();
    if(reservationType.equals("Managed")) {
      sb.append("<span>");
      sb.append("<a href=\"reservation.details.html?id="+id+"\">"+id+"</a>");
      sb.append("</span>");
    }
    else {
      sb.append("<span>");
      sb.append(id);
      sb.append("</span>");
    }
    row.add(new JsonPrimitive(sb.toString()));
    // Start
    sb = new StringBuffer();
    sb.append("<span title=\""+DuccConstants.hintPreferencesDateStyle+"\">");
    sb.append(getTimeStamp(request,duccwork.getDuccId(), duccwork.getStandardInfo().getDateOfSubmission()));
    sb.append("</span>");
    row.add(new JsonPrimitive(sb.toString()));
    // Duration
    sb = new StringBuffer();
    if(duccwork instanceof DuccWorkReservation) {
      DuccWorkReservation reservation = (DuccWorkReservation) duccwork;
      switch(reservation.getReservationState()) {
      case Completed:
        sb.append("<span>");
        String duration = getDuration(request,reservation);
        String decoratedDuration = decorateDuration(request,reservation, duration);
        sb.append(decoratedDuration);
        sb.append("</span>");
        break;
      default:
        sb.append("<span class=\"health_green\""+">");
        duration = getDuration(request,reservation,now);
        decoratedDuration = decorateDuration(request,reservation, duration);
        sb.append(decoratedDuration);
        sb.append("</span>");
        break;
      }
    }
    else if(duccwork instanceof DuccWorkJob) {
      DuccWorkJob job = (DuccWorkJob) duccwork;
      switch(job.getJobState()) {
      case Completed:
        sb.append("<span>");
        String duration = getDuration(request,job);
        String decoratedDuration = decorateDuration(request,job, duration);
        sb.append(decoratedDuration);
        sb.append("</span>");
        break;
      default:
        sb.append("<span class=\"health_green\""+">");
        duration = getDuration(request,job,now);
        decoratedDuration = decorateDuration(request,job, duration);
        sb.append(decoratedDuration);
        sb.append("</span>");
        break;
      }
    }
    row.add(new JsonPrimitive(sb.toString()));
    // User
    sb = new StringBuffer();
    String title = "";
    String submitter = duccwork.getStandardInfo().getSubmitter();
    if(submitter != null) {
      title = "title=\"submitter PID@host: "+submitter+"\"";
    }
    sb.append("<span "+title+">");
    UserId userId = new UserId(duccwork.getStandardInfo().getUser());
    sb.append(userId.toString());
    sb.append("</span>");
    row.add(new JsonPrimitive(sb.toString()));
    // Class
    row.add(new JsonPrimitive(stringNormalize(duccwork.getSchedulingInfo().getSchedulingClass(),messages.fetch("default"))));
    // Type
    sb = new StringBuffer();
    sb.append(reservationType);
    row.add(new JsonPrimitive(sb.toString()));
    // State
    sb = new StringBuffer();
    String state = duccwork.getStateObject().toString();
    sb.append("<span>");
    if(duccData.isLive(duccId)) {
      if(duccwork.isOperational()) {
        sb.append("<span class=\"active_state\">");
      }
      else {
        sb.append("<span class=\"completed_state\">");
      }
      sb.append(state);
      sb.append("</span>");
    }
    else {
      sb.append("<span class=\"historic_state\">");
      sb.append(state);
      sb.append("</span>");
    }
    sb.append("</span>");
    row.add(new JsonPrimitive(sb.toString()));
    // Reason
    sb = new StringBuffer();
    if(duccwork instanceof DuccWorkReservation) {
      DuccWorkReservation reservation = (DuccWorkReservation) duccwork;
      switch(reservation.getCompletionType()) {
      case Undefined:
        break;
      case CanceledByUser:
      case CanceledByAdmin:
        try {
          String cancelUser = duccwork.getStandardInfo().getCancelUser();
          if(cancelUser != null) {
            sb.append("<span title=\"canceled by "+cancelUser+"\">");
            sb.append(duccwork.getCompletionTypeObject().toString());
            sb.append("</span>");
          }
          else {             
            IRationale rationale = reservation.getCompletionRationale();
            if(rationale != null) {
              sb.append("<span title=\""+rationale+"\">");
              sb.append(duccwork.getCompletionTypeObject().toString());
              sb.append("</span>");
            }
            else {
              sb.append(duccwork.getCompletionTypeObject().toString());
            }
           
          }
        }
        catch(Exception e) {
          IRationale rationale = reservation.getCompletionRationale();
          if(rationale != null) {
            sb.append("<span title=\""+rationale+"\">");
            sb.append(duccwork.getCompletionTypeObject().toString());
            sb.append("</span>");
          }
          else {
            sb.append(duccwork.getCompletionTypeObject().toString());
          }
        }
        break;
      default:
        IRationale rationale = reservation.getCompletionRationale();
        if(rationale != null) {
          sb.append("<span title=\""+rationale+"\">");
          sb.append(duccwork.getCompletionTypeObject().toString());
          sb.append("</span>");
        }
        else {
          sb.append(duccwork.getCompletionTypeObject().toString());
        }
        break;
      }
    }
    else if(duccwork instanceof DuccWorkJob) {
      // Reason
      DuccWorkJob job = (DuccWorkJob) duccwork;
      sb = getReason(job,DuccType.Reservation);
    }
    row.add(new JsonPrimitive(sb.toString()));
    // Allocation
    sb = new StringBuffer();
    sb.append("<span>");
    sb.append(duccwork.getSchedulingInfo().getInstancesCount());
    sb.append("</span>");
    row.add(new JsonPrimitive(sb.toString()));
    // User Processes
    sb = new StringBuffer();
    TreeMap<String,Integer> nodeMap = new TreeMap<String,Integer>();
    if(duccwork instanceof DuccWorkReservation) {
      DuccWorkReservation reservation = (DuccWorkReservation) duccwork;
      if(!reservation.getReservationMap().isEmpty()) {
        IDuccReservationMap map = reservation.getReservationMap();
        for (DuccId key : map.keySet()) {
          IDuccReservation value = reservation.getReservationMap().get(key);
          String node = value.getNodeIdentity().getName();
          if(!nodeMap.containsKey(node)) {
            nodeMap.put(node,new Integer(0));
          }
          Integer count = nodeMap.get(node);
          count++;
          nodeMap.put(node,count);
        }
      }
     
      boolean qualify = false;
      if(!nodeMap.isEmpty()) {
        if(nodeMap.keySet().size() > 1) {
          qualify = true;
        }
      }
      ArrayList<String> qualifiedPids = new ArrayList<String>();
      if(duccwork.isOperational()) {
        DuccMachinesData machinesData = DuccMachinesData.getInstance();
        for (String node: nodeMap.keySet()) {
          NodeId nodeId = new NodeId(node);
          List<String> nodePids = machinesData.getPids(nodeId, userId);
          for( String pid : nodePids ) {
            if(qualify) {
              qualifiedPids.add(node+":"+pid);
            }
            else {
              qualifiedPids.add(pid);
            }
          }
        }
      }
      if(qualifiedPids.size() > 0) {
        String list = "";
        for( String entry : qualifiedPids ) {
          list += entry+" ";
        }
        sb.append("<span title=\""+list.trim()+"\">");
        sb.append(""+qualifiedPids.size());
        sb.append("</span>");
      }
      else {
        sb.append(""+qualifiedPids.size());
      }
    }
    else {
      DuccWorkJob job = (DuccWorkJob) duccwork;
      if(job.isOperational()) {
        sb.append(duccwork.getSchedulingInfo().getInstancesCount());
      }
      else {
        sb.append("0");
      }
      Iterator<DuccId> iterator = job.getProcessMap().keySet().iterator();
      while(iterator.hasNext()) {
        DuccId processId = iterator.next();
        IDuccProcess process = job.getProcessMap().get(processId);
        String node = process.getNodeIdentity().getName();
        nodeMap.put(node, 1);
      }
    }
    row.add(new JsonPrimitive(sb.toString()));
    // Size
    sb = new StringBuffer();
    sb.append("<span>");
    String size = duccwork.getSchedulingInfo().getShareMemorySize();
    MemoryUnits units = duccwork.getSchedulingInfo().getShareMemoryUnits();
    sb.append(getProcessMemorySize(duccId,type,size,units));
    sb.append("</span>");
    row.add(new JsonPrimitive(sb.toString()));
    // List
    sb = new StringBuffer();
    sb.append("<span>");
    if(!nodeMap.isEmpty()) {
      boolean useList = false;
      if(nodeMap.size() > 1) {
        useList = true;
      }
      if(useList) {
        sb.append("<select>");
      }
      for (String node: nodeMap.keySet()) {
        String option = node;
        Integer count = nodeMap.get(node);
        if(count > 1) {
          option += " "+"["+count+"]";
        }
        if(useList) {
          sb.append("<option>");
        }
        sb.append(option);
        if(useList) {
          sb.append("</option>");
        }
      }
      if(useList) {
        sb.append("</select>");
      }
    }
    sb.append("</span>");
    row.add(new JsonPrimitive(sb.toString()));
    // Description
    sb = new StringBuffer();
    String description = stringNormalize(duccwork.getStandardInfo().getDescription(),messages.fetch("none"));
    switch(DuccCookies.getDescriptionStyle(request)) {
    case Long:
    default:
      sb.append("<span title=\""+DuccConstants.hintPreferencesDescriptionStyleShort+"\">");
      sb.append(description);
      sb.append("</span>");
      break;
    case Short:
      String shortDescription = getShortDescription(description);
      if(shortDescription == null) {
        sb.append("<span>");
        sb.append(description);
        sb.append("</span>");
      }
      else {
        sb.append("<span title=\""+description+"\">");
        sb.append(shortDescription);
        sb.append("</span>");
      }
      break;
    }
    row.add(new JsonPrimitive(sb.toString()));
   
    return row;
  }
View Full Code Here

    }
    else {
      JsonArray row = new JsonArray();
      if(DuccData.getInstance().isPublished()) {
        // Terminate
        row.add(new JsonPrimitive("no reservations"));
      }
      else {
        // Terminate
        row.add(new JsonPrimitive("no data"));
      }
      // Id
      row.add(new JsonPrimitive(""));
      // Start
      row.add(new JsonPrimitive(""));
      // End
      row.add(new JsonPrimitive(""));
      // User
      row.add(new JsonPrimitive(""));
      // Class
      row.add(new JsonPrimitive(""));
      // Type
      row.add(new JsonPrimitive(""));
      // State
      row.add(new JsonPrimitive(""));
      // Reason
      row.add(new JsonPrimitive(""));
      // Allocation
      row.add(new JsonPrimitive(""));
      // User Processes
      row.add(new JsonPrimitive(""));
      // Size
      row.add(new JsonPrimitive(""));
      // List
      row.add(new JsonPrimitive(""));
      // Description
      row.add(new JsonPrimitive(""));
      data.add(row);
    }
   
    jsonResponse.add("aaData", data);
   
View Full Code Here

              }
            }
          }
          col.append("</span>");
        }
        row.add(new JsonPrimitive(col.toString()));
        // Stop
        col = new StringBuffer();
        if(type.equals(typeRegistered)) {
          col.append("<span class=\"ducc-col-stop\">");
          if(buttonsEnabled) {
            if(ping_only) {
              if(ping_active) {
                col.append("<input type=\"button\" onclick=\"ducc_confirm_service_stop("+sid+")\" value=\"Stop\" "+getDisabledWithHover(request,user)+"/>");
              }
            }
            else {
              if(!deployments.equals("0")) {
                col.append("<input type=\"button\" onclick=\"ducc_confirm_service_stop("+sid+")\" value=\"Stop\" "+getDisabledWithHover(request,user)+"/>");
              }
            }
          }
          col.append("</span>");
        }
        row.add(new JsonPrimitive(col.toString()));
        // Id
        String id = "<a href=\"service.details.html?name="+name+"\">"+key+"</a>";
        row.add(new JsonPrimitive(id));
        // Name
        row.add(new JsonPrimitive(name));
        // Type
        row.add(new JsonPrimitive(type));
        // State
        String state = DuccHandlerUtils.getUninterpreted(propertiesMeta, IServicesRegistry.service_state);
        String s0 = "<span>";
        String s1 = state;
        String s2 = "<span>";
        if(state.equalsIgnoreCase(IServicesRegistry.constant_Available)) {
          String statistics = propertiesMeta.getProperty(IServicesRegistry.service_statistics);
          if(statistics != null) {
            statistics = statistics.trim();
            if(statistics.length() > 0) {
              s0 = "<span title=\""+statistics+"\">";
            }
          }
        }
        row.add(new JsonPrimitive(s0+s1+s2));
        // Pinging
        String pinging = DuccHandlerUtils.getInterpretedUpDown(state, propertiesMeta, IServicesRegistry.ping_active);
        String decoratedPinging = DuccHandlerUtils.getDecorated(pinging);
        row.add(new JsonPrimitive(decoratedPinging));
        // Health
        if(propertiesMeta.containsKey(IServicesRegistry.submit_error)) {
          String decoratedHealth = DuccHandlerUtils.getDecorated("Error",propertiesMeta.getProperty(IServicesRegistry.submit_error));
          row.add(new JsonPrimitive(decoratedHealth));
        }
        else {
          String health = DuccHandlerUtils.getInterpretedGoodPoor(state, propertiesMeta, IServicesRegistry.service_healthy);
          String statistics = null;
          if(state.equalsIgnoreCase(IServicesRegistry.constant_Available)) {
            statistics = propertiesMeta.getProperty(IServicesRegistry.service_statistics);
            if(statistics != null) {
              statistics = statistics.trim();
            }
          }
          String decoratedHealth = DuccHandlerUtils.getDecorated(health,statistics);
          row.add(new JsonPrimitive(decoratedHealth));
        }
        // Instances
        if(ping_only) {
          row.add(new JsonPrimitive(""));
        }
        else {
          row.add(new JsonPrimitive(instances));
        }
        // Deployments
        if(ping_only) {
          row.add(new JsonPrimitive(""));
        }
        else {
          row.add(new JsonPrimitive(deployments));
        }
        // User
        row.add(new JsonPrimitive(getValue(propertiesMeta,IStateServices.user,"")));
        // Class
        if(ping_only) {
          row.add(new JsonPrimitive("["+IServicesRegistry.ping_only+"]"));
        }
        else {
          row.add(new JsonPrimitive(getValue(propertiesSvc,IStateServices.scheduling_class,"")));
        }
        // Size
        if(ping_only) {
          row.add(new JsonPrimitive(""));
        }
        else {
          row.add(new JsonPrimitive(getValue(propertiesSvc,IStateServices.process_memory_size,"")));
        }
        // Jobs     
        String jobs = "0";
        if(serviceToJobsMap.containsKey(name)) {
          ArrayList<DuccId> duccIds = serviceToJobsMap.get(name);
          int size = duccIds.size();
          if(size > 0) {
            StringBuffer idList = new StringBuffer();
            for(DuccId duccId : duccIds) {
              if(idList.length() > 0) {
                idList.append(",");
              }
              idList.append(duccId);
            }
            String title = "active Job Id list: "+idList;
            jobs = "<span title=\""+title+"\">"+size+"</span>";
          }
        }
        row.add(new JsonPrimitive(jobs));
        // Services
        String services = "0";
        if(serviceToServicesMap.containsKey(name)) {
          ArrayList<String> duccIds = serviceToServicesMap.get(name);
          int size = duccIds.size();
          if(size > 0) {
            StringBuffer idList = new StringBuffer();
            for(String duccId : duccIds) {
              if(idList.length() > 0) {
                idList.append(",");
              }
              idList.append(duccId);
            }
            String title = "active Service Id list: "+idList;
            services = "<span title=\""+title+"\">"+size+"</span>";
          }
        }
        row.add(new JsonPrimitive(services));
        // Reservations
        String reservations = "0";
        if(serviceToReservationsMap.containsKey(name)) {
          ArrayList<DuccId> duccIds = serviceToReservationsMap.get(name);
          int size = duccIds.size();
          if(size > 0) {
            StringBuffer idList = new StringBuffer();
            for(DuccId duccId : duccIds) {
              if(idList.length() > 0) {
                idList.append(",");
              }
              idList.append(duccId);
            }
            String title = "active Reservation Id list: "+idList;
            reservations = "<span title=\""+title+"\">"+size+"</span>";
          }
        }
        row.add(new JsonPrimitive(reservations));
        // Description
        StringBuffer sb = new StringBuffer();
        String description = getValue(propertiesSvc,IStateServices.description,"");
        switch(DuccCookies.getDescriptionStyle(request)) {
        case Long:
        default:
          sb.append("<span title=\""+DuccConstants.hintPreferencesDescriptionStyleShort+"\">");
          sb.append(description);
          sb.append("</span>");
          break;
        case Short:
          String shortDescription = getShortDescription(description);
          if(shortDescription == null) {
            sb.append("<span>");
            sb.append(description);
            sb.append("</span>");
          }
          else {
            sb.append("<span title=\""+description+"\">");
            sb.append(shortDescription);
            sb.append("</span>");
          }
          break;
        }
        row.add(new JsonPrimitive(sb.toString()));
       
        data.add(row);
      }
    }
    else {
      JsonArray row = new JsonArray();
      // Start
      row.add(new JsonPrimitive(""));
      // Stop
      row.add(new JsonPrimitive(""));
      // Id
      row.add(new JsonPrimitive(""));
      // Name
      row.add(new JsonPrimitive(""));
      // Type
      row.add(new JsonPrimitive(""));
      // State
      row.add(new JsonPrimitive(""));
      // Pinging
      row.add(new JsonPrimitive(""));
      // Health
      row.add(new JsonPrimitive(""));
      // Instances
      row.add(new JsonPrimitive(""));
      // Deployments
      row.add(new JsonPrimitive(""));
      // User
      row.add(new JsonPrimitive(""));
      // Class
      row.add(new JsonPrimitive(""));
      // Size
      row.add(new JsonPrimitive(""));
      // Jobs
      row.add(new JsonPrimitive(""));
      // Services
      row.add(new JsonPrimitive(""));
      // Reservations
      row.add(new JsonPrimitive(""));
      // Description
      row.add(new JsonPrimitive(""));
      data.add(row);
    }
   
    jsonResponse.add("aaData", data);
   
View Full Code Here

        }
      }
      row = new JsonArray();
      // Release ALL Stuck JPs
      String releaseAll = buildReleaseAll(request, factsList);
      row.add(new JsonPrimitive(releaseAll));
      // Status
      row.add(new JsonPrimitive("Total"));
      // IP
      row.add(new JsonPrimitive(""));
      // Name
      row.add(new JsonPrimitive(""));
      // Reserve: total
      row.add(new JsonPrimitive(sumReserve));
      // Memory: total
      row.add(new JsonPrimitive(sumMemory));
      // Swap: inuse
      row.add(new JsonPrimitive(sumSwap));
      // Alien PIDs
      row.add(new JsonPrimitive(sumAliens));
      // Shares: total
      row.add(new JsonPrimitive(sumSharesTotal));
      // Shares:inuse
      row.add(new JsonPrimitive(sumSharesInuse));
      // Heartbeat: last
      row.add(new JsonPrimitive(""));
      data.add(row);
      // Individual Machines
      listIterator = factsList.listIterator();
      while(listIterator.hasNext()) {
        MachineFacts facts = listIterator.next();
        row = new JsonArray();
        // Release Machine Stuck JPs
        String releaseMachine = buildReleaseMachine(request, facts);
        row.add(new JsonPrimitive(releaseMachine));
        // Status
        sb = new StringBuffer();
        String status = facts.status;
        if(status.equals("down")) {
          sb.append("<span class=\"health_red\""+">");
          sb.append(status);
          sb.append("</span>");
        }
        else if(status.equals("up")) {
          sb.append("<span class=\"health_green\""+">");
          sb.append(status);
          sb.append("</span>");
        }
        else {
          sb.append(status);
        }
        row.add(new JsonPrimitive(sb.toString()));
        // IP
        row.add(new JsonPrimitive(facts.ip));
        // Name
        row.add(new JsonPrimitive(facts.name));
        // Reserve
        row.add(new JsonPrimitive(facts.reserve));
        // Memory: total
        row.add(new JsonPrimitive(facts.memory));
        // Swap: inuse
        sb = new StringBuffer();
        String swapping = facts.swap;
        if(swapping.equals("0")) {
          sb.append(swapping);
        }
        else {
          sb.append("<span class=\"health_red\">");
          sb.append(swapping);
          sb.append("</span>");
        }
        row.add(new JsonPrimitive(sb.toString()));
        // Alien PIDs
        sb = new StringBuffer();
        long aliens = facts.aliens.size();
        if(aliens == 0) {
          sb.append(aliens);
        }
        else {
          sb.append("<span class=\"health_red\">");
          sb.append(aliens);
          sb.append("</span>");
        }
        row.add(new JsonPrimitive(sb.toString()));
        // Shares: total
        row.add(new JsonPrimitive(facts.sharesTotal));
        // Shares:inuse
        row.add(new JsonPrimitive(facts.sharesInuse));
        // Heartbeat: last
        row.add(new JsonPrimitive(facts.heartbeat));
        data.add(row);
      }
    }
    else {
      row = new JsonArray();
      // Release
      row.add(new JsonPrimitive(""));
      // Status
      row.add(new JsonPrimitive(""));
      // IP
      row.add(new JsonPrimitive(""));
      // Name
      row.add(new JsonPrimitive(""));
      // Reserve
      row.add(new JsonPrimitive(""));
      // Memory: total
      row.add(new JsonPrimitive(""));
      // Swap: inuse
      row.add(new JsonPrimitive(""));
      // Alien PIDs
      row.add(new JsonPrimitive(""));
      // Shares: total
      row.add(new JsonPrimitive(""));
      // Shares:inuse
      row.add(new JsonPrimitive(""));
      // Heartbeat: last
      row.add(new JsonPrimitive(""));
      data.add(row);
    }
   
    jsonResponse.add("aaData", data);
   
View Full Code Here

TOP

Related Classes of com.google.gson.JsonPrimitive

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.