/** * Search * * @param callbackObject * @throws CloudException * @throws IOException * @throws ExecutionException * @throws InterruptedException * @throws JSONException */ public void search(CloudObjectArrayCallback callbackObject) throws CloudException { String collectionString; if (this.collectionArray.size() > 0) { collectionString = ""; for (int i = 0; i < this.collectionArray.size(); i++) { collectionString += (i > 0 ? "," + this.collectionArray.get(i) : this.collectionArray.get(i)); } this.collectionName = collectionString; } else { collectionString = this.collectionName; } try { this.query.put("filtered", this.filtered); JSONObject params = new JSONObject(); params.put("collectionName", collectionString); params.put("query", this.query); params.put("sort", this.sort); params.put("limit", this.size); params.put("skip", this.from); params.put("key", CloudApp.getAppKey()); String url = CloudApp.getServerUrl() + "/data/" + CloudApp.getAppId() + "/" + this.collectionName + "/search"; CBResponse response = CBParser.callJson(url, "POST", params); if (response.getStatusCode() == 200) { JSONArray body = new JSONArray(response.getResponseBody()); CloudObject[] object = new CloudObject[body.length()]; for (int i = 0; i < object.length; i++) { object[i] = new CloudObject(body.getJSONObject(i).get("_tableName").toString()); object[i].document = body.getJSONObject(i); } callbackObject.done(object, null); } else { CloudException e = new CloudException(response.getError()); callbackObject.done((CloudObject[]) null, e); } } catch (JSONException e) { CloudException ee = new CloudException(e.getMessage()); callbackObject.done((CloudObject[]) null, ee); } }