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; }
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; }
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; }
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; }