Пример #1
0
  public void testcreateblog2() {
    System.out.println("Test Case to Create a Blog");
    Resource resource1 = client.resource(url);
    System.out.println("URL: " + url);
    JSONObject sendobject = new JSONObject();
    try {
      sendobject.put("subject", "sjsu_cmpe202");
      sendobject.put("description", "XML");
      sendobject.put("userid", "Shaunak");
      sendobject.put("timestamp", "11:53");

    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    String jsonStringObj = sendobject.toString();
    System.out.println("Create : " + jsonStringObj);
    ClientResponse created =
        resource1
            .contentType(MediaType.APPLICATION_JSON)
            .accept(MediaType.APPLICATION_JSON)
            .post(jsonStringObj);
    System.out.println(created.getStatusCode());
    System.out.println(created.getEntity(String.class));
  }
Пример #2
0
 @Override
 public void run() {
   System.out.println("PortalImportTask started at " + new Date().toString());
   if (mPhotoCollection == null) {
     System.err.println("mongod is not running");
     return;
   }
   PortalActivity activity = new PortalActivity();
   Set<String> imageUrlSet = new HashSet<String>();
   for (int temp = 0; activity.hasNext() && temp < 999; temp++) { // while (activity.hasNext()) {
     JSONArray dataList = activity.getNext();
     if (dataList == null) {
       imageUrlSet = null;
       System.err.println("Error loading activities");
       break;
     }
     for (int i = 0; i < dataList.length(); i++) {
       try {
         JSONObject obj = dataList.getJSONObject(i);
         String imageUrl = getImageURL(obj);
         if (imageUrl != null) {
           imageUrlSet.add(imageUrl);
           importActivity(obj, imageUrl);
         }
       } catch (JSONException e) {
         e.printStackTrace();
       }
     }
   }
   fixThumbnailImages();
   if (imageUrlSet != null) {
     fixActivities(imageUrlSet);
   }
   System.out.println("PortalImportTask finished at " + new Date().toString());
 }
  public JSONObject toJSON() {
    JSONObject json = new JSONObject();

    JSONObject LDPLJSON = new JSONObject();
    JSONObject GPJSON = new JSONObject();
    JSONObject optJSON = new JSONObject();

    try {
      double[] params = getParams();
      LDPLJSON
          .put("n", params[0])
          .put("A", params[1])
          .put("fa", params[2])
          .put("fb", params[3])
          .put(HDIFF, hDiff);

      GPJSON.put("lengthes", new Double[] {lengthes[0], lengthes[1], lengthes[2]});
      GPJSON
          .put("sigmaP", stdev)
          .put("sigmaN", sigmaN)
          .put("useMask", gpLDPL.getUseMask() ? 1 : 0)
          .put("constVar", gpLDPL.getOptConstVar());

      optJSON.put("optimizeHyperParameters", doHyperParameterOptimize ? 1 : 0);

      json.put(LDPLParameters, LDPLJSON);
      json.put(GPParameters, GPJSON);
      json.put(OPTIONS, optJSON);

    } catch (JSONException e) {
      e.printStackTrace();
    }

    return json;
  }
 static JSONArray parseFeatures(JSONObject json) {
   try {
     String type = json.getString("type");
     if (type.equals("FeatureCollection")) {
       JSONArray features = json.getJSONArray("features");
       return features;
     }
   } catch (JSONException e) {
     e.printStackTrace();
   }
   return null;
 }
 @Override
 public void settingFromJSON(JSONObject json) {
   int k;
   try {
     k = json.getInt(K_BEACONS_KEY);
     doNormalize = json.getBoolean(DO_NORMALIZE_KEY);
     kBeacons = k;
     System.out.println(this.toString());
   } catch (JSONException e) {
     e.printStackTrace();
   }
 }
  public void settingFromJSON(JSONObject json) {
    jsonParams = json;
    try {
      JSONObject ldplParams = json.getJSONObject(LDPLParameters);
      JSONObject gpParams = json.getJSONObject(GPParameters);
      JSONObject optJSON = json.getJSONObject(OPTIONS);

      // LDPLParameters
      double n = ldplParams.getDouble("n");
      double A = ldplParams.getDouble("A");
      double fa = ldplParams.getDouble("fa");
      double fb = ldplParams.getDouble("fb");
      if (ldplParams.containsKey(HDIFF)) {
        double hDiff = ldplParams.getDouble(HDIFF);
        this.setParams(new double[] {n, A, fa, fb});
        this.setHDiff(hDiff);
      }

      // GPParamters
      JSONArray jarray = gpParams.getJSONArray("lengthes");
      lengthes = JSONUtils.array1DfromJSONArray(jarray);
      stdev = gpParams.getDouble("sigmaP");
      sigmaN = gpParams.getDouble("sigmaN");

      boolean useMask = (gpParams.getInt("useMask") == 1);
      int optConstVar = gpParams.getInt("constVar");

      gpLDPL.setUseMask(useMask);
      gpLDPL.setOptConstVar(optConstVar);

      // Options
      doHyperParameterOptimize = optJSON.optBoolean("optimizeHyperParameters");
      if (!doHyperParameterOptimize) {
        doHyperParameterOptimize = optJSON.optInt("optimizeHyperParameters") == 1;
      }

      // Optional variables
      if (gpParams.containsKey(ARRAYS)) {
        JSONObject jobjArrays = gpParams.getJSONObject(ARRAYS);
        gpLDPL.fromJSON(jobjArrays);
      }
      if (json.containsKey(LIKELIHOOD_MODEL)) {
        JSONObject likelihoodJSON = json.getJSONObject(LIKELIHOOD_MODEL);
        LikelihoodModel likelihoodModel = LikelihoodModelFactory.create(likelihoodJSON);
        gpLDPL.setLikelihoodModel(likelihoodModel);
      } else {
        System.out.println("The key for [" + LIKELIHOOD_MODEL + "] was not found.");
      }

      if (json.containsKey(BEACON_FILTER)) {
        JSONObject bfJSON = json.getJSONObject(BEACON_FILTER);
        BeaconFilter bf = BeaconFilterFactory.create(bfJSON);
        beaconFilter = bf;
      } else {
        System.out.println("The key for [" + BEACON_FILTER + "] was not found.");
      }

    } catch (JSONException e) {
      e.printStackTrace();
    }
  }