public boolean isEmpty() { return jsonObject.isEmpty(); }
public String getJavaScript() { final StringBuilder js = new StringBuilder("Hippo.Events.publish('"); js.append(name); js.append("'"); if (!parameters.isEmpty()) { js.append(","); js.append(parameters.toString()); } js.append(");"); return js.toString(); }
public boolean isEmpty() { return getJSONObject().isEmpty(); } }
private static boolean isBundle(JSONObject o) { if (!o.isEmpty()) { final Object val = o.get(o.keys().next()); if (val instanceof String) { return true; } } return false; }
/** * Downloads summary. * It will be either functional or aggregate depending on server settings; */ public JSONObject downloadSummary(Master master) { JSONObject summary = getFunctionalReport(master); if (summary != null && !summary.isEmpty()) { notifier.notifyInfo("Got functional report from server"); return summary; } summary = getSummary(master); if (summary != null && !summary.isEmpty()) { notifier.notifyInfo("Got aggregated report from server"); return summary; } return new JSONObject(); }
public FlowStates getFlowStates() { JSONObject fs = getState().getJSONObject(FLOW_STATE_KEY); FlowStates flowStates = new FlowStates(); if (fs == null) { return flowStates; } if (!(fs == null || fs.isEmpty())) { flowStates.fromJSON(fs); } return flowStates; }
public JSONObject getContent() { Iterator keys = jsonObject.keys(); if (keys.hasNext()) { String rootKey = (String) keys.next(); JSONObject r = jsonObject.getJSONObject(rootKey); if (r == null || r.isNullObject() || r.isEmpty()) { l.debug("The JSON object doesn't contain the root object=" + jsonObject.toString()); throw new GdcRestApiException("The JSON object doesn't contain the root object=" + jsonObject.toString()); } JSONObject c = r.getJSONObject("content"); if (c == null || c.isNullObject() || c.isEmpty()) { l.debug("The JSON object doesn't contain the content tag object=" + jsonObject.toString()); throw new GdcRestApiException("The JSON object doesn't contain the content tag object=" + jsonObject.toString()); } return c; } else { l.debug("The JSON object doesn't contain any root object=" + jsonObject.toString()); throw new GdcRestApiException("The JSON object doesn't contain any root object=" + jsonObject.toString()); } }
public JSONObject getMeta() { Iterator keys = jsonObject.keys(); if (keys.hasNext()) { String rootKey = (String) keys.next(); JSONObject r = jsonObject.getJSONObject(rootKey); if (r == null || r.isNullObject() || r.isEmpty()) { l.debug("The JSON object doesn't contain the root object=" + jsonObject.toString()); throw new GdcRestApiException("The JSON object doesn't contain the root object=" + jsonObject.toString()); } JSONObject m = r.getJSONObject("meta"); if (m == null || m.isNullObject() || m.isEmpty()) { l.debug("The JSON object doesn't contain the meta tag object=" + jsonObject.toString()); throw new GdcRestApiException("The JSON object doesn't contain the meta tag object=" + jsonObject.toString()); } return m; } else { l.debug("The JSON object doesn't contain any root object=" + jsonObject.toString()); throw new GdcRestApiException("The JSON object doesn't contain any root object=" + jsonObject.toString()); } }
/** * Checks if the migration is finished * * @param link the link returned from the start loading * @return the loading status */ public String getMigrationStatus(String link) throws HttpMethodException { l.debug("Getting project migration status uri=" + link); HttpMethod ptm = createGetMethod(getServerUrl() + link); try { String response = executeMethodOk(ptm); JSONObject task = JSONObject.fromObject(response); JSONObject state = task.getJSONObject("taskState"); if (state != null && !state.isNullObject() && !state.isEmpty()) { String status = state.getString("status"); l.debug("Migration status=" + status); return status; } else { l.debug("No taskState structure in the migration status!"); throw new GdcRestApiException("No taskState structure in the migration status!"); } } finally { ptm.releaseConnection(); } }
public void showclaims(InputLine inputLine) throws Exception { if (grant == null || showHelp(inputLine)) { showClaimsHelp(); return; } if (claims == null || claims.isEmpty()) { say("(no claims found)"); } else { say(claims.toString(2)); } }
/** * Extracts the object's identifier * * @return the GoodData object identifier */ public String getIdentifier() { Iterator keys = jsonObject.keys(); if (keys.hasNext()) { String rootKey = (String) keys.next(); JSONObject r = jsonObject.getJSONObject(rootKey); if (r == null || r.isNullObject() || r.isEmpty()) { l.debug("The JSON object doesn't contain the root object=" + jsonObject.toString()); throw new GdcRestApiException("The JSON object doesn't contain the root object=" + jsonObject.toString()); } JSONObject m = r.getJSONObject("meta"); if (m == null || m.isNullObject() || m.isEmpty()) { l.debug("The JSON object doesn't contain the meta tag object=" + jsonObject.toString()); throw new GdcRestApiException("The JSON object doesn't contain the meta tag object=" + jsonObject.toString()); } return m.getString("identifier"); } else { l.debug("The JSON object doesn't contain any root object=" + jsonObject.toString()); throw new GdcRestApiException("The JSON object doesn't contain any root object=" + jsonObject.toString()); } }
private GdcUser getUserFromUri(String userUri) { l.debug("Getting user from uri: " + userUri); HttpMethod req = createGetMethod( getServerUrl() + userUri); try { String resp = executeMethodOk(req); JSONObject parsedResp = JSONObject.fromObject(resp); if (parsedResp == null || parsedResp.isNullObject() || parsedResp.isEmpty()) { l.debug("Can't getUserFromUri for uri " + userUri + ". Invalid response."); throw new GdcRestApiException("Can't getUserFromUri for uri " + userUri + ". Invalid response."); } return new GdcUser(parsedResp); } catch (HttpMethodException ex) { l.debug("Error getUserFromUri.", ex); throw new GdcRestApiException("Error getUserFromUri", ex); } finally { req.releaseConnection(); } }
private GdcRole getRoleFromUri(String roleUri) { l.debug("Getting role from uri: " + roleUri); HttpMethod req = createGetMethod( getServerUrl() + roleUri); try { String resp = executeMethodOk(req); JSONObject parsedResp = JSONObject.fromObject(resp); if (parsedResp == null || parsedResp.isNullObject() || parsedResp.isEmpty()) { l.debug("Can't getRoleFromUri for uri " + roleUri + ". Invalid response."); throw new GdcRestApiException("Can't getRoleFromUri for uri " + roleUri + ". Invalid response."); } return new GdcRole(parsedResp); } catch (HttpMethodException ex) { l.debug("Error getRoleFromUri.", ex); throw new GdcRestApiException("Error getRoleFromUri", ex); } finally { req.releaseConnection(); } }
/** * Strips all keys that should not be sent to the create method */ public void stripKeysForCreate() { Iterator keys = jsonObject.keys(); if (keys.hasNext()) { String rootKey = (String) keys.next(); JSONObject r = jsonObject.getJSONObject(rootKey); if (r == null || r.isNullObject() || r.isEmpty()) { l.debug("The JSON object doesn't contain the root object=" + jsonObject.toString()); throw new GdcRestApiException("The JSON object doesn't contain the root object=" + jsonObject.toString()); } JSONObject m = r.getJSONObject("meta"); if (m == null || m.isNullObject() || m.isEmpty()) { l.debug("The JSON object doesn't contain the meta tag object=" + jsonObject.toString()); throw new GdcRestApiException("The JSON object doesn't contain the meta tag object=" + jsonObject.toString()); } m.discard("uri"); } else { l.debug("The JSON object doesn't contain any root object=" + jsonObject.toString()); throw new GdcRestApiException("The JSON object doesn't contain any root object=" + jsonObject.toString()); } }
public Map<String, Object> process(Map<String, Object> claims) { ServletDebugUtil.dbg(this, "starting processing"); if(config == null || config.isEmpty()){ ServletDebugUtil.dbg(this, "NO configuration, returning."); return claims; } logicBlocks = createLogicBlocks(config, claims); ServletDebugUtil.dbg(this, "created " + logicBlocks.size() + " logic blocks."); logicBlocks.execute(); executed = true; ServletDebugUtil.dbg(this, "Finished processing, returned claims are"); ServletDebugUtil.dbg(this, claims.toString()); return claims; }
public JSONObject toJSON() { JSONObject o = new JSONObject(); if (has(name)) o.put("name", name); if (has(developerId)) o.put("developerId", developerId); if (has(email)) o.put("email", email); if (!o.isEmpty()) { return o; } else { return null; } }
public void getat(InputLine inputLine) throws Exception { /* if(!canGetAT){ say("Sorry, but you have not gotten a grant yet here, so you cannot get an access token."); }*/ if (grant == null || showHelp(inputLine)) { getATHelp(); return; } currentATResponse = getOA2S().getAccessToken(getDummyAsset(), grant); Object x = currentATResponse.getParameters().get(RAW_ID_TOKEN); if (x == null) { x = ""; } else { rawIdToken = x.toString(); } claims = (JSONObject) currentATResponse.getParameters().get(ID_TOKEN); if (inputLine.hasArg(CLAIMS_FLAG)) { if (claims.isEmpty()) { say("(no claims found)"); } else { say(claims.toString(2)); } } printTokens(); }
@Test public void testFetchDiffWithOtherDiff() throws Exception { JSONObject otherDiff = TestUtils.getJSONFromFile(getClass(), "fetchDiffResponseMissingDiff"); mockConduitResponse(differentialClient, otherDiff); JSONObject response = differentialClient.fetchDiff(); assertTrue(response.isEmpty()); }
public void getrt(InputLine inputLine) throws Exception { if (showHelp(inputLine)) { getRTHelp(); return; } RTResponse rtResponse = getOA2S().refresh(dummyAsset.getIdentifier().toString()); dummyAsset = (OA2Asset) getCe().getAssetStore().get(dummyAsset.getIdentifier().toString()); // Have to update the AT reponse here every time or no token state is preserved. currentATResponse = new ATResponse2(dummyAsset.getAccessToken(), dummyAsset.getRefreshToken()); currentATResponse.setParameters(rtResponse.getParameters()); JSONObject json = JSONObject.fromObject(currentATResponse.getParameters()); claims = json; if (inputLine.hasArg(CLAIMS_FLAG)) { if (json.isEmpty()) { say("(no claims found)"); } else { say(json.toString(2)); } } printTokens(); }
/** * @see com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object , * com.thoughtworks.xstream.io.HierarchicalStreamWriter, * com.thoughtworks.xstream.converters.MarshallingContext) */ public void marshal( Object value, HierarchicalStreamWriter writer, MarshallingContext context) { if (value instanceof RulesList) { RulesList obj = (RulesList) value; for (JSONObject rule : obj.getRules()) { if (!rule.isEmpty() && !rule.isNullObject() && !rule.isArray()) { writer.startNode("Rule"); for (Object key : rule.keySet()) { writer.startNode((String) key); writeChild(writer, rule.get(key)); writer.endNode(); } writer.endNode(); } } } else if (value instanceof JSONObject) { JSONObject obj = (JSONObject) value; writeChild(writer, obj); } }