public Iterable<Index<? extends Element>> getIndices() { List<Index<? extends Element>> indices = new ArrayList<Index<? extends Element>>(); JSONArray json = RestHelper.getResultArray(this.graphURI + RexsterTokens.SLASH_INDICES); for (int ix = 0; ix < json.length(); ix++) { JSONObject index = json.optJSONObject(ix); Class c; String clazz = index.optString(RexsterTokens.CLASS); if (clazz.toLowerCase().contains(RexsterTokens.VERTEX)) c = Vertex.class; else if (clazz.toLowerCase().contains(RexsterTokens.EDGE)) c = Edge.class; else throw new RuntimeException("Can not determine whether " + clazz + " is a vertex or edge class"); indices.add(new RexsterIndex(this, index.optString(RexsterTokens.NAME), c)); } return indices; }
private Map<String, Map<String, Long>> parseDagCounters( JSONObject countersNode ) throws JSONException { if( countersNode == null ) return null; JSONArray counterGroupNodes = countersNode.optJSONArray( ATSConstants.COUNTER_GROUPS ); if( counterGroupNodes == null ) return null; Map<String, Map<String, Long>> counters = new HashMap<>(); int numCounterGroups = counterGroupNodes.length(); for( int i = 0; i < numCounterGroups; i++ ) parseCounterGroup( counters, counterGroupNodes.optJSONObject( i ) ); return counters; }
private Map<String, Map<String, Long>> parseDagCounters( JSONObject countersNode ) throws JSONException { if( countersNode == null ) return null; JSONArray counterGroupNodes = countersNode.optJSONArray( ATSConstants.COUNTER_GROUPS ); if( counterGroupNodes == null ) return null; Map<String, Map<String, Long>> counters = new HashMap<>(); int numCounterGroups = counterGroupNodes.length(); for( int i = 0; i < numCounterGroups; i++ ) parseCounterGroup( counters, counterGroupNodes.optJSONObject( i ) ); return counters; }
protected void fillBuffer(final Queue<Edge> queue, final int start, final int end) { final JSONObject object = RestHelper.get(this.uri + this.createSeparator() + RexsterTokens.REXSTER_OFFSET_START + RexsterTokens.EQUALS + start + RexsterTokens.AND + RexsterTokens.REXSTER_OFFSET_END + RexsterTokens.EQUALS + end); JSONArray array = object.optJSONArray(RexsterTokens.RESULTS); for (int ix = 0; ix < array.length(); ix++) { queue.add(new RexsterEdge(array.optJSONObject(ix), this.graph)); } } }
protected void fillBuffer(final Queue<Vertex> queue, final int start, final int end) { final JSONObject object = RestHelper.get(this.uri + this.createSeparator() + RexsterTokens.REXSTER_OFFSET_START + RexsterTokens.EQUALS + start + RexsterTokens.AND + RexsterTokens.REXSTER_OFFSET_END + RexsterTokens.EQUALS + end); JSONArray array = object.optJSONArray(RexsterTokens.RESULTS); for (int ix = 0; ix < array.length(); ix++) { queue.add(new RexsterVertex(array.optJSONObject(ix), this.graph)); } } }
public static enum TYPE_STRICT {any,all,should};
/** * Parse events from json * * @param eventNodes * @param eventList * @throws JSONException */ public static void parseEvents(JSONArray eventNodes, List<Event> eventList) throws JSONException { if (eventNodes == null) { return; } for (int i = 0; i < eventNodes.length(); i++) { JSONObject eventNode = eventNodes.optJSONObject(i); final String eventInfo = eventNode.optString(Constants.EVENT_INFO); final String eventType = eventNode.optString(Constants.EVENT_TYPE); final long time = eventNode.optLong(Constants.EVENT_TIME_STAMP); Event event = new Event(eventInfo, eventType, time); eventList.add(event); } }
assertTrue("Fields MUST contain at least a single value!",jValues.length() > 0); for(int i=0;i<jValues.length();i++){ JSONObject fieldValue = jValues.optJSONObject(i); assertNotNull("Values for field "+key+" does contain an value " + "that is not an JSONObject "+jValues.optString(i),
private TezCountersProto.Builder parseDagCounters(JSONObject countersNode) throws JSONException { if (countersNode == null) { return null; } TezCountersProto.Builder countersProto = TezCountersProto.newBuilder(); final JSONArray counterGroupNodes = countersNode.optJSONArray(ATSConstants.COUNTER_GROUPS); if (counterGroupNodes != null) { final int numCounterGroups = counterGroupNodes.length(); for (int i = 0; i < numCounterGroups; i++) { TezCounterGroupProto.Builder counterGroupBuilder = parseCounterGroup(counterGroupNodes.optJSONObject(i)); if (counterGroupBuilder != null) { countersProto.addCounterGroups(counterGroupBuilder); } } } return countersProto; }
JSONArray array = jsonObject.optJSONArray(key); boolean listOrObject = array.optJSONObject(0) != null; String stringValue = listOrObject ? array.optJSONObject(i).toString() : array.optString(i);
jsonObject.optJSONObject(Constants.ENTITY)); } else { JSONObject subJsonObject = relatedEntities.optJSONObject(0); if (subJsonObject != null) { String nodeId = subJsonObject.optString(Constants.ENTITY_TYPE); subJsonObject = relatedEntities.optJSONObject(1); if (subJsonObject != null) { String containerId = subJsonObject.optString(Constants.ENTITY_TYPE);
if (counterGroupNodes != null) { for (int i = 0; i < counterGroupNodes.length(); i++) { JSONObject counterGroupNode = counterGroupNodes.optJSONObject(i); final String groupName = counterGroupNode.optString(Constants.COUNTER_GROUP_NAME); final String groupDisplayName = counterGroupNode.optString( JSONObject counterNode = counterNodes.optJSONObject(j); final String counterName = counterNode.getString(Constants.COUNTER_NAME); final String counterDisplayName =
private static void fromJSONEdges(final FaunusVertex vertex, final JSONArray edges, final Direction direction) throws JSONException, IOException { if (null != edges) { for (int i = 0; i < edges.length(); i++) { final JSONObject edge = edges.optJSONObject(i); FaunusEdge faunusEdge = null; if (direction.equals(Direction.IN)) { faunusEdge = (FaunusEdge) graphson.edgeFromJson(edge, new FaunusVertex(edge.optLong(GraphSONTokens._OUT_V)), vertex); } else if (direction.equals(Direction.OUT)) { faunusEdge = (FaunusEdge) graphson.edgeFromJson(edge, vertex, new FaunusVertex(edge.optLong(GraphSONTokens._IN_V))); } if (faunusEdge != null) { vertex.addEdge(direction, faunusEdge); } } } }
@Test public void testDefaultRangeConstraintDatatypeProperty() throws IOException, JSONException { FieldQueryTestCase test = new FieldQueryTestCase( "{"+ "'selected': [ 'http:\\/\\/www.test.org\\/test#field'], " + "'constraints': [{ " + "'type': 'range', " + "'field': 'http:\\/\\/www.test.org\\/test#field', " + "'lowerBound': 1000," + "'inclusive': true," + "}]" + "}", false); //expect BadRequest //now execute the test RequestExecutor re = executeQuery(test); JSONObject jQuery = assertResponseQuery(re.getContent()); JSONArray jConstraints = jQuery.optJSONArray("constraints"); assertNotNull("Result Query does not contain the constraints Array",jConstraints); assertTrue("Result Query Constraint Array does not contain the expected Constraint", jConstraints.length() == 1); JSONObject jConstraint = jConstraints.optJSONObject(0); assertNotNull("Constraint Array does not contain JSONObjects",jConstraint); assertTrue("Returned Query does not contain the default data type",jConstraint.has("datatype")); } }
@Test public void testValueConstraintDefaultDataType() throws IOException, JSONException { FieldQueryTestCase test = new FieldQueryTestCase( "{"+ "'selected': [ 'http:\\/\\/www.test.org\\/test#field'], " + "'constraints': [{ " + "'type': 'value'," + "'value': 'Paris'," + "'field': 'http:\\/\\/www.test.org\\/test#field'" + "}]," + "}", false); //expect BadRequest //now execute the test RequestExecutor re = executeQuery(test); JSONObject jQuery = assertResponseQuery(re.getContent()); JSONArray jConstraints = jQuery.optJSONArray("constraints"); assertNotNull("Result Query does not contain the constraints Array",jConstraints); assertTrue("Result Query Constraint Array does not contain the expected Constraint", jConstraints.length() == 1); JSONObject jConstraint = jConstraints.optJSONObject(0); assertNotNull("Constraint Array does not contain JSONObjects",jConstraint); assertTrue("Returned Query does not contain the default data type",jConstraint.has("datatype")); } @Test
@Test public void testDefaultTextConstraintPatternTypeProperty() throws IOException, JSONException { FieldQueryTestCase test = new FieldQueryTestCase( "{"+ "'selected': [ 'http:\\/\\/www.test.org\\/test#field'], " + "'constraints': [{ " + "'type': 'text', " + "'text': 'Paris', " + "'field': 'http:\\/\\/www.test.org\\/test#field', " + "}]" + "}", false); //expect BadRequest //now execute the test RequestExecutor re = executeQuery(test); JSONObject jQuery = assertResponseQuery(re.getContent()); JSONArray jConstraints = jQuery.optJSONArray("constraints"); assertNotNull("Result Query does not contain the constraints Array",jConstraints); assertTrue("Result Query Constraint Array does not contain the expected Constraint", jConstraints.length() == 1); JSONObject jConstraint = jConstraints.optJSONObject(0); assertNotNull("Constraint Array does not contain JSONObjects",jConstraint); assertTrue("The 'patternType' property MUST BE set for returned TextConstraints", jConstraint.has("patternType")); assertEquals("Default for patternType MUST BE 'none'", "none", jConstraint.getString("patternType")); } @Test
assertEquals("Result Query is expected to have a single constraint", 1, jConstraints.length()); JSONObject constraint = jConstraints.optJSONObject(0); assertNotNull("'constraints' array does not contain a JSONObject but "+jConstraints.get(0), constraint);