List of usage examples for com.google.gson JsonObject get
public JsonElement get(String memberName)
From source file:com.balajeetm.mystique.util.gson.lever.JsonQuery.java
License:Open Source License
/** * Query async./* ww w.j av a 2 s . c o m*/ * * @param array the array * @param query the query * @return the observable */ private Flux<JsonElement> queryAsync(JsonArray array, JsonObject query) { return Flux.fromIterable(array).publishOn(Schedulers.elastic()) .filter(json -> filter(json, query.get("where"))).compose(obs -> { Long limit = jsonLever.asLong(query.get("limit"), 0L); return limit > 0 ? obs.take(limit.intValue()) : obs; }).publishOn(Schedulers.elastic()) .compose(obs -> StringUtils.equals(jsonLever.getString(query, "select"), "count") ? obs.count().map(count -> new JsonPrimitive(count)) : obs.map(json -> select(json, query.get("select")))); }
From source file:com.balajeetm.mystique.util.gson.lever.JsonQuery.java
License:Open Source License
/** * Query async./*from w ww .j ava 2s. c om*/ * * @param obj the obj * @param query the query * @return the observable */ private Flux<JsonElement> queryAsync(JsonElement obj, JsonObject query) { return Flux.just(obj).publishOn(Schedulers.elastic()).filter(json -> filter(json, query.get("where"))) .compose(obs -> { Long limit = jsonLever.asLong(query.get("limit"), 0L); return limit > 0 ? obs.take(limit.intValue()) : obs; }).publishOn(Schedulers.elastic()) .compose(obs -> StringUtils.equals(jsonLever.getString(query, "select"), "count") ? obs.count().map(count -> new JsonPrimitive(count)) : obs.map(json -> select(json, query.get("select")))); }
From source file:com.balajeetm.mystique.util.gson.lever.JsonQuery.java
License:Open Source License
/** * Equals filter.//from w ww . j ava 2 s . c o m * * @param json the json * @param condition the condition * @return the boolean */ private Boolean equalsFilter(JsonElement json, JsonObject condition) { return jsonLever.asJsonElement(condition.get("value"), JsonNull.INSTANCE) .equals(jsonLever.get(json, jsonLever.asJsonArray(condition.get("field"), new JsonArray()))); }
From source file:com.balajeetm.mystique.util.gson.lever.JsonQuery.java
License:Open Source License
/** * In filter./*from w w w . j ava 2s. c om*/ * * @param json the json * @param condition the condition * @return the boolean */ private Boolean inFilter(JsonElement json, JsonObject condition) { return jsonLever.asJsonArray(condition.get("value"), new JsonArray()) .contains(jsonLever.get(json, jsonLever.asJsonArray(condition.get("field"), new JsonArray()))); }
From source file:com.balajeetm.mystique.util.gson.lever.JsonQuery.java
License:Open Source License
/** * Validate.//from w ww . j av a 2s. c o m * * @param query the query * @return the string */ private String validate(JsonObject query) { if (jsonLever.isNull(jsonLever.get(query, "select"))) { return "select field of the query cannot be null"; } JsonElement from = query.get("from"); if (!(jsonLever.isObject(from) || jsonLever.isArray(from))) { return "from field must be a valid json object or array"; } JsonElement where = jsonLever.get(query, "where"); if (jsonLever.isNotNull(where) && !jsonLever.isArray(where)) { return "where field must be a valid json array"; } JsonElement limit = jsonLever.get(query, "limit"); if (jsonLever.isNotNull(limit) && !jsonLever.isNumber(limit)) { return "limit must be a valid number"; } return "valid"; }
From source file:com.basho.riakcs.client.impl.RiakCSClientImpl.java
License:Open Source License
public void addAdditionalACLToBucket(String bucketName, String emailAddress, Permission permission) throws RiakCSException { try {/*from w w w. j a v a 2 s .co m*/ JsonObject oldACL = getACLForBucket(bucketName); JsonObject newGrant = new JsonObject(); JsonObject grantee = new JsonObject(); grantee.addProperty("emailAddress", emailAddress); newGrant.add("grantee", grantee); newGrant.addProperty("permission", permission.toString()); oldACL.get("grantsList").getAsJsonArray().add(newGrant); addAdditionalACLImpl(bucketName, "", oldACL); } catch (Exception e) { throw new RiakCSException(e); } }
From source file:com.basho.riakcs.client.impl.RiakCSClientImpl.java
License:Open Source License
public void addAdditionalACLToObject(String bucketName, String objectKey, String emailAddress, Permission permission) throws RiakCSException { try {/*from w ww. j a v a 2 s . c o m*/ JsonObject oldACL = getACLForObject(bucketName, objectKey); JsonObject newGrant = new JsonObject(); JsonObject grantee = new JsonObject(); grantee.addProperty("emailAddress", emailAddress); newGrant.add("grantee", grantee); newGrant.addProperty("permission", permission.toString()); oldACL.get("grantsList").getAsJsonArray().add(newGrant); addAdditionalACLImpl(bucketName, objectKey, oldACL); } catch (Exception e) { throw new RiakCSException(e); } }
From source file:com.basho.riakcs.client.impl.RiakCSClientImpl.java
License:Open Source License
private void addAdditionalACLImpl(String bucketName, String objectKey, JsonObject acl) throws Exception { StringBuilder aclText = new StringBuilder(); aclText.append("<AccessControlPolicy>"); aclText.append("<Owner><ID>").append(acl.getAsJsonObject("owner").get("id").getAsString()).append("</ID>"); aclText.append("<DisplayName>").append(acl.getAsJsonObject("owner").get("displayName").getAsString()) .append("</DisplayName></Owner>"); aclText.append("<AccessControlList>"); JsonArray grantsList = acl.getAsJsonArray("grantsList"); for (int pt = 0; pt < grantsList.size(); pt++) { JsonObject grant = grantsList.get(pt).getAsJsonObject(); aclText.append("<Grant><Permission>").append(grant.getAsJsonObject("permission").getAsString()) .append("</Permission>"); aclText.append("<Grantee"); aclText.append(" ").append("xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"); if (grant.getAsJsonObject("grantee").has("id")) { aclText.append(" xsi:type='CanonicalUser'>"); aclText.append("<ID>").append(grant.getAsJsonObject("grantee").get("id").getAsString()) .append("</ID>"); } else {/*w w w.j av a2s. com*/ aclText.append(" xsi:type='AmazonCustomerByEmail'>"); aclText.append("<EmailAddress>") .append(grant.getAsJsonObject("grantee").get("emailAddress").getAsString()) .append("</EmailAddress>"); } aclText.append("</Grantee>"); aclText.append("</Grant>"); } aclText.append("</AccessControlList>"); aclText.append("</AccessControlPolicy>"); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("acl", null); InputStream dataInputStream = new ByteArrayInputStream(aclText.toString().getBytes("UTF-8")); Map<String, String> headers = new HashMap<String, String>(); headers.put("Content-Type", "application/xml"); CommunicationLayer comLayer = getCommunicationLayer(); URL url = comLayer.generateCSUrl(bucketName, objectKey, parameters); comLayer.makeCall(CommunicationLayer.HttpMethod.PUT, url, dataInputStream, headers); }
From source file:com.basho.riakcs.client.impl.RiakCSClientImpl.java
License:Open Source License
public static void copyBucketBetweenSystems(RiakCSClient fromSystem, String fromBucket, RiakCSClient toSystem, String toBucket) throws RiakCSException { try {// w w w . j a va 2 s .com JsonObject response = fromSystem.listObjectNames(fromBucket); JsonArray resultList = response.getAsJsonArray("objectList"); System.out.println("Number of Objects to transfer: " + resultList.size() + "\n"); for (int pt = 0; pt < resultList.size(); pt++) { String key = resultList.get(pt).getAsJsonObject().get("key").getAsString(); File tempFile = File.createTempFile("cscopy-", ".bin"); //Retrieve Object FileOutputStream outputStream = new FileOutputStream(tempFile); JsonObject objectData = fromSystem.getObject(fromBucket, key, outputStream); outputStream.close(); //Upload Object Map<String, String> headers = new HashMap<String, String>(); headers.put("Content-Type", objectData.get("contenttype").getAsString()); Map<String, String> metadata = null; if (objectData.has("metadata") && !objectData.getAsJsonObject("metadata").entrySet().isEmpty()) { metadata = new HashMap<String, String>(); Set<Map.Entry<String, JsonElement>> metadataRaw = objectData.getAsJsonObject("metadata") .entrySet(); for (Map.Entry<String, JsonElement> entry : metadataRaw) { metadata.put(entry.getKey(), entry.getValue().getAsString()); } } FileInputStream inputStream = new FileInputStream(tempFile); toSystem.createObject(toBucket, key, inputStream, headers, metadata); inputStream.close(); tempFile.delete(); } } catch (Exception e) { throw new RiakCSException(e); } }
From source file:com.bbk.cgac.controller.pagecontroller.ax.SampleAjaxPageController.java
@Override public void execute() throws IOException { //Sample Code //Test Request JsonElement jel = mJson;/*from w w w . j a va2 s .co m*/ if (jel.isJsonArray()) { JsonArray jarr = jel.getAsJsonArray(); if (jarr.get(0).isJsonObject()) { JsonObject jobj = jarr.get(0).getAsJsonObject(); System.out.println("JsonObject ."); System.out.println("a: " + jobj.get("a")); } if (jarr.get(1).isJsonArray()) { JsonArray jarr2 = jarr.get(1).getAsJsonArray(); System.out.println("jarr[1]? JsonArray ."); } } //Test Response (Example) TempObj obj = new TempObj("Kim"); String arg01 = JSON.parseToString(obj); TempObj obj1 = new TempObj("Lee"); String arg02 = JSON.parseToString(obj1); mResponse.setContentType("text/html;charset=UTF-8"); mResponse.getWriter().write("[" + arg01 + "," + arg02 + "]"); }