Exemplo n.º 1
0
 private Map<String, Object> recursiveGrabber(
     OdklRequest request, String userId, Map<String, Object> fullMap) {
   try {
     String response = api.sendRequest(request);
     JSONObject responseJson = JsonUtil.parseObject(response);
     Map<String, Object> grabberTemp = grabber(userId, responseJson);
     if (grabberTemp != null) {
       if (fullMap == null) {
         fullMap = grabberTemp;
       } else {
         fullMap = appendMap(fullMap, grabberTemp);
       }
     }
     if ((Boolean) responseJson.get("hasMore")) {
       String anchor = (String) responseJson.get("anchor");
       return recursiveGrabber(request.addParam("anchor", anchor), userId, fullMap);
     }
     return fullMap;
   } catch (OdklApiRuntimeException e) {
     if (LOGS) {
       System.out.println(
           String.format(
               "[ERR][uid%s] Runtime error while loading profile. Connection failed.", userId));
     }
   }
   return null;
 }
Exemplo n.º 2
0
 private JSONArray getAllMarksFromPhoto(String photoId) {
   try {
     OdklRequest request = api.createApiRequest("photos", "getTags").addParam("photo_id", photoId);
     String response = api.sendRequest(request);
     JSONObject responseJson = JsonUtil.parseObject(response);
     JSONArray marksArray = JsonUtil.getArray(responseJson, "photo_tags");
     return marksArray.isEmpty() ? null : marksArray;
   } catch (OdklApiRuntimeException e) {
     if (LOGS) {
       System.out.println(
           String.format(
               "[ERR][] Runtime error while loading marks from photo %s. Connection failed.",
               photoId));
     }
   }
   return null;
 }
Exemplo n.º 3
0
 private List<String> grabList(JSONObject responseJson) {
   List<String> fullList = new ArrayList<String>();
   JSONArray photos = JsonUtil.getArray(responseJson, "photos");
   for (int i = 0; i < photos.size(); i++) {
     JSONObject photo = (JSONObject) photos.get(i);
     fullList.add((String) photo.get("id"));
   }
   return fullList;
 }
Exemplo n.º 4
0
 private List<String> getUserAlbumIds(String userId) {
   try {
     OdklRequest request =
         api.createApiRequest("photos", "getAlbums")
             .addParam("fid", userId)
             .addParam("count", "100");
     JSONObject responseJson = JsonUtil.parseObject(api.sendRequest(request));
     JSONArray albumArray = JsonUtil.getArray(responseJson, "albums");
     List<String> albumIds = new ArrayList<String>();
     for (int i = 0; i < albumArray.size(); i++) {
       JSONObject album = (JSONObject) albumArray.get(i);
       albumIds.add(JsonUtil.getString(album, "aid"));
     }
     return albumIds;
   } catch (OdklApiRuntimeException e) {
     if (LOGS) {
       System.out.println(
           String.format(
               "[ERR][uid%s] Runtime error while loading user albums list. Connection failed.",
               userId));
     }
   }
   return null;
 }
Exemplo n.º 5
0
 private Map<String, Object> grabber(String userId, JSONObject responseJson) {
   JSONArray photos = JsonUtil.getArray(responseJson, "photos");
   Map<String, Object> photoIdOwnerIdTagsMap = new HashMap<String, Object>();
   int photosNum = 0;
   if (photos != null && photos.size() != 0) {
     for (int i = 0; i < photos.size(); i++) {
       photosNum++;
       JSONObject photo = (JSONObject) photos.get(i);
       String photoOwnerId = JsonUtil.getString(photo, "user_id");
       String imgUrl = JsonUtil.getString(photo, "pic640x480");
       String photoId = (String) photo.get("id");
       JSONObject currentTag = getUserMarkFromPhoto(userId, photoId);
       if (currentTag != null) {
         Map<String, Object> additionMap = new HashMap<String, Object>();
         additionMap.put("photoOwner", photoOwnerId);
         additionMap.put("tag", currentTag);
         photoIdOwnerIdTagsMap.put(photoId, additionMap);
       }
       loadImage(imgUrl, userId, photoId);
     }
   }
   photoIdOwnerIdTagsMap.put("photosNum", photosNum);
   return photoIdOwnerIdTagsMap;
 }
Exemplo n.º 6
0
 private List<String> recursiveGetPhotoList(
     OdklRequest request, String userId, List<String> fullList) {
   try {
     JSONObject responseJson = JsonUtil.parseObject(api.sendRequest(request));
     if (fullList == null) fullList = grabList(responseJson);
     else {
       fullList.addAll(grabList(responseJson));
     }
     if ((Boolean) responseJson.get("hasMore")) {
       String anchor = (String) responseJson.get("anchor");
       return recursiveGetPhotoList(request.addParam("anchor", anchor), userId, fullList);
     }
     return fullList;
   } catch (OdklApiRuntimeException e) {
     if (LOGS) {
       System.out.println(
           String.format(
               "[ERR][uid%s] Runtime error while loading photo list of the album. Connection failed.",
               userId));
     }
   }
   return null;
 }
Exemplo n.º 7
0
 private String getPhotoUrl(String photoId) {
   OdklRequest request =
       api.createApiRequest("photos", "getPhotoInfo").addParam("photo_id", photoId);
   JSONObject responseJson = JsonUtil.parseObject(api.sendRequest(request));
   return JsonUtil.getString(((JSONObject) responseJson.get("photo")), "pic640x480");
 }