Esempio n. 1
0
 @SuppressWarnings("unchecked")
 private JSONArray copyVisits() {
   if (this.visits == null) {
     return null;
   }
   JSONArray out = new JSONArray();
   out.addAll(this.visits);
   return out;
 }
 /**
  * 获取当前用户的县级机关、市级机关、省级机关
  *
  * @param codetablename
  * @return
  */
 @RequestMapping(value = "/getLoginDeptInfo")
 @ResponseBody
 @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
 public JSONArray getLoginDeptInfo() {
   JSONArray result = new JSONArray();
   List<OptionObject> list = CurrentUserInfo.getInstance().getOrgInfo();
   result.addAll(list);
   return result;
 }
Esempio n. 3
0
  @RequiresLogin
  public void list() throws IOException {
    JSONArray array = new JSONArray();
    String path = getPath();

    List<JSONObject> edits = getEdits(path);

    array.addAll(edits);
    print(array.toString());
  }
Esempio n. 4
0
  public JSONObject toJSON(String contextRoot) {
    JSONObject json = new JSONObject();
    json.put(ID, id);
    json.put(URL, url);
    json.put(TYPE, type.toString());
    json.put(FILENAME, contextRoot + IMAGES_PATH + id + IMAGE_SUFFIX);
    json.put(LAST_MODIFIED, determineLastModified());

    if (components != null) {
      JSONArray componentsJa = new JSONArray();
      componentsJa.addAll(components);
      json.put(COMPONENTS, componentsJa);
    }
    return json;
  }
  public JSONArray getCommands() {
    JSONArray commands = new JSONArray();
    JSONObject createCommand = new JSONObject();
    String parentId = parent != null ? parent.id : rootComponentId;

    createCommand.put("Command", "CREATE COMPONENT");
    createCommand.put("ComponentId", id);
    createCommand.put("ParentId", parentId);
    createCommand.put("Type", type.name());

    commands.add(createCommand);
    commands.addAll(attributes.getCommands());

    return commands;
  }
Esempio n. 6
0
  @RequiresLogin
  public void recent() throws IOException {
    int editIndex;
    try {
      editIndex = Integer.parseInt(getCtx().popParam());
    } catch (Exception e) {
      getCtx().getResp().sendError(400, "Couldn't get index of recent edit");
      return;
    }

    String path = getPath();

    List<JSONObject> editList = getEdits(path);

    JSONArray array = new JSONArray();
    array.addAll(editList.subList(editIndex, editList.size()));
    print(array.toString());
  }
Esempio n. 7
0
  private static JSONArray getJsonArrayOfMessages(List<Message> messages) {

    // Java * approach
    /*
        List<JSONObject> jsonMessages = messages.stream()
                .map(MessageHelper::messageToJSONObject)
                .collect(Collectors.toList());
    */

    List<JSONObject> jsonMessages = new LinkedList<>();
    for (Message message : messages) {
      jsonMessages.add(messageToJSONObject(message));
    }

    JSONArray array = new JSONArray();
    array.addAll(jsonMessages);
    return array;
  }
Esempio n. 8
0
 public List<String> grabUserPhotosWithMetadata(String targetId) {
   if (!checkUser(targetId)) {
     try {
       if (LOGS) System.out.println(String.format("[MSG][uid%s] Starting grab.", targetId));
       JsonUser userJson = new JsonUser(targetId);
       JSONArray friendsArray = new JSONArray();
       List<String> friendsList = api.friends().getFriends(targetId);
       if (friendsList != null) {
         friendsArray.addAll(friendsList);
         userJson.setFriends(friendsArray);
       }
       if (LOGS)
         System.out.println(
             String.format("[MSG][uid%s] Grabbing marked photos from user friends.", targetId));
       userJson.addMetainfo(
           grabUserMarkedPhotos(targetId)); // grab marked photos from friends albums
       if (LOGS)
         System.out.println(
             String.format("[MSG][uid%s] Grabbing photos from personal album.", targetId));
       userJson.addMetainfo(grabUserPhotos(targetId)); // grab user photos from personal album
       if (LOGS)
         System.out.println(
             String.format("[MSG][uid%s] Grabbing marked photos from all user albums.", targetId));
       userJson.addMetainfo(
           grabUserMarkedPhotosFromPersonalAlbums(
               targetId)); // grab user marked photos from all his albums (except his personal
       // album)
       if (!userJson.isEmpty()) {
         userJson.writeJson();
         if (LOGS) System.out.println(String.format("[MSG][uid%s] Finished grab.", targetId));
       }
       return friendsList;
     } catch (OdklApiException a) {
       if (LOGS) System.out.println(String.format("[ERR][uid%s] Privacy error.", targetId));
     }
   } else {
     List<String> friendsList = api.friends().getFriends(targetId);
     if (friendsList != null) {
       return friendsList;
     }
   }
   return null;
 }
Esempio n. 9
0
 /**
  * 得到单根JSON对象
  *
  * @return
  * @throws ImetaFormException
  */
 @SuppressWarnings("unchecked")
 @Override
 public JSONObject getFormJo() throws BIJSONException {
   JSONObject formJo = super.getFormJo();
   if (this.content != null && this.content.size() > 0) {
     JSONArray sub = new JSONArray();
     for (ComponentMetaInterface dataMeta : this.content) {
       if (dataMeta != null) {
         if (dataMeta instanceof ComplexComponentMeta) {
           if (((ComplexComponentMeta) dataMeta).isMultiRoot()) {
             sub.addAll(((ComplexComponentMeta) dataMeta).getFormJa());
           } else {
             sub.add(dataMeta.getFormJo());
           }
         } else {
           sub.add(dataMeta.getFormJo());
         }
       }
     }
     formJo.put(HTML.TAG_CONTENT, sub);
   }
   return formJo;
 }
Esempio n. 10
0
  /** Give the users search criteria (item count and price range), find products in that range. */
  @SuppressWarnings("unchecked")
  private void findProducts() throws IOException, ParseException {
    int page = 0;
    int priceRange = 2;
    // Get first 100 lowest priced products listed in Zappos.
    String reply = GetResult(page);
    JSONArray resultArray = resultParse(reply);

    // Lowest priced product, offcourse the first one.
    double lowestPrice = getDouble(resultArray.get(0));

    // If you can't match users criteria with the lowest priced item, return NULL.
    if ((lowestPrice * itemCount) < (totalPrice + priceRange)) {

      // We can proceed, find the max price given the min price.
      maxPrice = totalPrice - (itemCount - 1) * (lowestPrice);

      // We have first page, fetch the next page.
      page++;

      // Last product price.
      Double lastPrice = getDouble(resultArray.get(resultArray.size() - 1));

      // Keep fetching till we get products within our search range.
      while (lastPrice < maxPrice) {
        String nextPage = GetResult(page);

        JSONArray nextArray = resultParse(nextPage);

        // append new page of results to original array
        resultArray.addAll(nextArray);

        // get new last product and price
        lastPrice = getDouble(nextArray.get(nextArray.size() - 1));

        page++;
      }

      allProductList.add(new Product((JSONObject) resultArray.get(0)));

      // count how many times a price has already shown up
      int already = 1;
      int numPrices = 1;
      // go through the whole
      for (int i = 1; i < resultArray.size() && getDouble(resultArray.get(i)) < maxPrice; i++) {
        System.out.println("I : " + i);
        double currentPrice = getDouble(resultArray.get(i));
        if (currentPrice > allProductList.get(numPrices - 1).getPrice()) {
          allProductList.add(new Product((JSONObject) resultArray.get(i)));
          numPrices++;
          already = 1;
        } else if (Math.abs(currentPrice - allProductList.get(numPrices - 1).getPrice()) < TOL
            && already < itemCount) {
          allProductList.add(new Product((JSONObject) resultArray.get(i)));
          numPrices++;
          already++;
        } else {
          // Finding products with the same price as the last one added to the productObjects list
          while (i < resultArray.size()
              && Math.abs(currentPrice - allProductList.get(numPrices - 1).getPrice()) < TOL) {
            i++;
            currentPrice = getDouble(resultArray.get(i));
          }
          i++;
          already = 0;
        }
      }
    }
  }
Esempio n. 11
0
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    try {
      JSONParser parser = new JSONParser();
      String originalRouteJsonString = request.getParameter("originalroutejsontext");
      JSONObject originalRouteJsonObject = (JSONObject) parser.parse(originalRouteJsonString);
      JSONObject routes = (JSONObject) ((JSONArray) originalRouteJsonObject.get("routes")).get(0);
      JSONArray legs = (JSONArray) routes.get("legs");
      JSONArray steps = (JSONArray) ((JSONObject) legs.get(0)).get("steps");

      String routeID = request.getParameter("routeid");
      // System.out.println("Route steps loaded in a JSONArray...size is " + steps.size());

      List<Double> stepLats = new ArrayList<Double>();
      List<Double> stepLngs = new ArrayList<Double>();

      for (int i = 0; i < steps.size(); i++) {
        JSONObject temp = (JSONObject) ((JSONObject) steps.get(i)).get("end_location");
        // System.out.println("Lat of end_location of step " + i + " " + temp.get("lat"));
        stepLats.add(Double.parseDouble(temp.get("lat").toString()));
        stepLngs.add(Double.parseDouble(temp.get("lng").toString()));
      }
      // System.out.println("All steps set with size " + stepLngs.size() + " and " +
      // stepLats.size());

      // System.out.println("Skipping route boxer...");
      // RouteBoxer routeBoxer = new RouteBoxer(stepLats, stepLngs,
      // Double.parseDouble(request.getParameter("radius")));

      // if(routeBoxer.getFlag())
      //  throw new RuntimeException("Could not create boxes for the route");

      // List<Double> boxLats = routeBoxer.getLats();
      // List<Double> boxLngs = routeBoxer.getLngs();

      // System.out.println("Calculated boxes with number of lats " + boxLats.size() + " and number
      // of lngs " + boxLngs.size());

      double r = Double.parseDouble(request.getParameter("radius").toString());
      int radius = r > RADIUS_TO_LOOK_FOR_PLACES ? RADIUS_TO_LOOK_FOR_PLACES : (int) r;

      String[] types = request.getParameter("keywords").split(",");
      System.out.println("Size of types is " + types.length);

      JSONObject finalPlacesJSONObject = new JSONObject();

      for (int j = 0; j < types.length; j++) {
        JSONArray jsonArrayForType = new JSONArray();

        for (int i = 0; i < stepLats.size(); i++) {
          JSONObject placesAroundLocationJSONObject =
              (JSONObject)
                  parser.parse(
                      GoogleMap.getPlacesAroundLocation(
                          stepLats.get(i), stepLngs.get(i), radius, types[j]));
          JSONArray placesAroundLocationJSONArray =
              (JSONArray) placesAroundLocationJSONObject.get("results");

          if (!placesAroundLocationJSONArray.isEmpty()) {
            jsonArrayForType.addAll(placesAroundLocationJSONArray);
          }
        }
        finalPlacesJSONObject.put(types[j], jsonArrayForType);
      }
      List<String> place_ids = new ArrayList<String>();

      finalPlacesJSONObject = removeDuplicatePlaces(finalPlacesJSONObject);
      finalPlacesJSONObject =
          filterPlacesRandomly(finalPlacesJSONObject, FINAL_PLACES_NUMBER_PER_REQUEST, place_ids);

      // System.out.println("MAGIC " + place_ids.toString());
      DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
      MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();

      // add places as a property of original route entity
      Entity originalRouteEntity =
          datastore.get(KeyFactory.createKey("Route", Long.parseLong(routeID)));
      Text placesJsonAsText = new Text(finalPlacesJSONObject.toJSONString());
      originalRouteEntity.setProperty("placesJSON", placesJsonAsText);
      datastore.put(originalRouteEntity);
      // System.out.println("SUCCESS written places to datastore");

      // add task for fetching place reviews to queue
      QueueFactory.getDefaultQueue()
          .add(
              TaskOptions.Builder.withUrl("/waypointsreview")
                  .param("places", place_ids.toString()));

      System.out.println("Task to get reviews added to queue");
      // We cache the route entity
      String cacheKey = "route-" + routeID;
      syncCache.put(cacheKey, originalRouteEntity);
    } catch (Exception e) {
      System.out.println("ERROR " + e.getMessage());
      e.printStackTrace();
    }
  }