private Map<Integer, JSONObject> listSessions() throws IOException { String sessionsUrl = livyUrl + "/sessions"; int numSessions; JSONObject sessionsInfo; Map<Integer, JSONObject> sessionsMap = new HashMap<>(); Map<String, String> headers = new HashMap<>(); headers.put("Content-Type", APPLICATION_JSON); headers.put("X-Requested-By", USER); try { sessionsInfo = readJSONFromUrl(sessionsUrl, headers); numSessions = sessionsInfo.getJSONArray("sessions").length(); for (int i = 0; i < numSessions; i++) { int currentSessionId = sessionsInfo.getJSONArray("sessions").getJSONObject(i).getInt("id"); JSONObject currentSession = sessionsInfo.getJSONArray("sessions").getJSONObject(i); sessionsMap.put(currentSessionId, currentSession); } } catch (JSONException e) { throw new IOException(e); } return sessionsMap; }
@Override public List<SModelCheckerInstance> getAllRepositoryModelCheckers() throws ServerException, UserException { requireRealUserAuthentication(); try { List<SModelCheckerInstance> modelCheckers = new ArrayList<SModelCheckerInstance>(); String content = NetUtils.getContent(new URL(getServiceMap().get(SettingsInterface.class).getServiceRepositoryUrl() + "/modelcheckers"), 5000); JSONObject root = new JSONObject(new JSONTokener(content)); JSONArray modelCheckersJson = root.getJSONArray("modelcheckers"); for (int i = 0; i < modelCheckersJson.length(); i++) { JSONObject modelCheckerJson = modelCheckersJson.getJSONObject(i); SModelCheckerInstance sModelChecker = new SModelCheckerInstance(); sModelChecker.setName(modelCheckerJson.getString("name")); sModelChecker.setCode(modelCheckerJson.getString("code")); sModelChecker.setDescription(modelCheckerJson.getString("description")); sModelChecker.setModelCheckerPluginClassName(modelCheckerJson.getString("modelCheckerPluginClassName")); modelCheckers.add(sModelChecker); } return modelCheckers; } catch (Exception e) { return handleException(e); } }
JSONArray extendedDataSchemasJson = root.getJSONArray("extendeddataschemas"); for (int i = 0; i < extendedDataSchemasJson.length(); i++) { JSONObject extendedDataSchemaJson = extendedDataSchemasJson.getJSONObject(i);
@Override public Iterable<CimProject> parse(final JSONObject json) throws JSONException { return projectsParser.parse(json.getJSONArray("projects")); } }
public static Optional<JSONArray> getOptionalArray(final JSONObject jsonObject, final String attributeName) throws JSONException { return jsonObject.has(attributeName) ? Optional.of(jsonObject.getJSONArray(attributeName)) : Optional.<JSONArray>absent(); }
@SuppressWarnings("unused") public static JSONArray getNestedArray(JSONObject json, String... path) throws JSONException { for (int i = 0; i < path.length - 1; i++) { String s = path[i]; json = json.getJSONObject(s); } return json.getJSONArray(path[path.length - 1]); }
public static Optional<JSONArray> getOptionalArray(final JSONObject jsonObject, final String attributeName) throws JSONException { return jsonObject.has(attributeName) ? Optional.of(jsonObject.getJSONArray(attributeName)) : Optional.<JSONArray>absent(); }
public List<Member> createMembersListFromJson(JSONObject results) { List<Member> members = new ArrayList<>(); try { JSONArray records = results.getJSONArray("records"); for (int i = 0; i < records.length(); i++) { members.add(createMemberFromSalesForceRecord(records.getJSONObject(i))); } } catch (JSONException e) { throw new RuntimeException("Error getting member records from SalesForce JSON", e); } return members; }
@Override public Operations parse(final JSONObject json) throws JSONException { final Collection<OperationGroup> linkGroups = JsonParseUtil.parseJsonArray(json.getJSONArray("linkGroups"), groupParser); return new Operations(linkGroups); } }
String content = NetUtils.getContent(url, 5000); JSONObject root = new JSONObject(new JSONTokener(content)); JSONArray services = root.getJSONArray("services"); for (int i = 0; i < services.length(); i++) { JSONObject service = services.getJSONObject(i);
@Override public BulkOperationResult<BasicIssue> parse(final JSONObject json) throws JSONException { final Collection<BasicIssue> issues = JsonParseUtil.parseJsonArray(json.getJSONArray("issues"), new BasicIssueJsonParser()); final Collection<BulkOperationErrorResult> errors = JsonParseUtil.parseJsonArray(json.getJSONArray("errors"), new IssueErrorJsonParser()); return new BulkOperationResult<BasicIssue>(issues, errors); }
public Transition parse(JSONObject json, int id) throws JSONException { final String name = json.getString("name"); final Collection<Transition.Field> fields = JsonParseUtil.parseJsonArray(json.getJSONArray("fields"), transitionFieldJsonParser); return new Transition(name, id, fields); }
public Transition parse(JSONObject json, int id) throws JSONException { final String name = json.getString("name"); final Collection<Transition.Field> fields = JsonParseUtil.parseJsonArray(json.getJSONArray("fields"), transitionFieldJsonParser); return new Transition(name, id, fields); }
@Override public SearchResult parse(JSONObject json) throws JSONException { final int startAt = json.getInt("startAt"); final int maxResults = json.getInt("maxResults"); final int total = json.getInt("total"); final Collection<BasicIssue> issues = JsonParseUtil.parseJsonArray(json.getJSONArray("issues"), basicIssueJsonParser); return new SearchResult(startAt, maxResults, total, issues); } }
@Override public ChangelogGroup parse(JSONObject json) throws JSONException { final DateTime created = JsonParseUtil.parseDateTime(json, "created"); final BasicUser author = json.has("author") ? JsonParseUtil.parseBasicUser(json.getJSONObject("author")) : null; final Collection<ChangelogItem> items = JsonParseUtil.parseJsonArray(json.getJSONArray("items"), changelogItemJsonParser); return new ChangelogGroup(author, created, items); } }
@Override public Votes parse(JSONObject json) throws JSONException { final BasicVotes basicVotes = basicVotesJsonParser.parse(json); final Collection<BasicUser> users = JsonParseUtil.parseJsonArray(json.getJSONArray("voters"), basicUserJsonParser); return new Votes(basicVotes.getSelf(), basicVotes.getVotes(), basicVotes.hasVoted(), users); } }
private void verifyAccesibleNodeLabels(JSONObject queueJson, Set<String> accesibleNodeLabels) throws JSONException { JSONArray nodeLabels = queueJson.getJSONArray("nodeLabels"); assertEquals("number of accessible Node Labels not matching", accesibleNodeLabels.size(), nodeLabels.length()); for (int i = 0; i < nodeLabels.length(); i++) { assertTrue("Invalid accessible node label : " + nodeLabels.getString(i), accesibleNodeLabels.contains(nodeLabels.getString(i))); } }
private CimFieldInfo parseIssueFieldInfo(JSONObject json, String id) throws JSONException { final boolean required = json.getBoolean("required"); final String name = JsonParseUtil.getOptionalString(json, "name"); final FieldSchema schema = fieldSchemaJsonParser.parse(json.getJSONObject("schema")); final Set<StandardOperation> operations = parseOperations(json.getJSONArray("operations")); final Iterable<Object> allowedValues = parseAllowedValues(json.optJSONArray("allowedValues"), schema); final URI autoCompleteUri = JsonParseUtil.parseOptionalURI(json, "autoCompleteUrl"); return new CimFieldInfo(id, required, name, schema, operations, allowedValues, autoCompleteUri); }
private JSONObject getSubQueue(JSONObject queue, String subQueue) throws JSONException { JSONArray queues = queue.getJSONObject("queues").getJSONArray("queue"); for (int i=0; i<queues.length(); ++i) { checkResourcesUsed(queues.getJSONObject(i)); if (queues.getJSONObject(i).getString("queueName").equals(subQueue) ) { return queues.getJSONObject(i); } } return null; }
private void verifyReservationCount(int count) throws Exception { WebResource resource = constructWebResource(LIST_RESERVATION_PATH) .queryParam("queue", DEFAULT_QUEUE); JSONObject json = testListReservationHelper(resource); if (count == 1) { // If there are any number other than one reservation, this will throw. json.getJSONObject("reservations"); } else { JSONArray reservations = json.getJSONArray("reservations"); assertTrue(reservations.length() == count); } }