public boolean hasNonNull(String column) { return _data.hasNonNull(column); } }
/** * Gets an integer value. * * @param propertyName the property to get. * @return the boolean value */ public Integer getInt(String propertyName) { if (this.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) { return Integer.valueOf(this.propertyBag.get(propertyName).asInt()); } else { return null; } }
@Override public AttestationType getAttestationType(AttestationObject attestation) { if (attestation.getAttestationStatement().hasNonNull("x5c")) { return AttestationType.BASIC; } else if (attestation.getAttestationStatement().hasNonNull("ecdaaKeyId")) { return AttestationType.ECDAA; } else { return AttestationType.SELF_ATTESTATION; } }
/** * Gets a boolean value. * * @param propertyName the property to get. * @return the boolean value. */ public Boolean getBoolean(String propertyName) { if (this.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) { return this.propertyBag.get(propertyName).asBoolean(); } else { return null; } }
/** * Gets a long value. * * @param propertyName the property to get. * @return the long value */ public Long getLong(String propertyName) { if (this.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) { return Long.valueOf(this.propertyBag.get(propertyName).asLong()); } else { return null; } }
/** * Gets a JSONObject. * * @param propertyName the property to get. * @return the JSONObject. */ public ObjectNode getObject(String propertyName) { if (this.propertyBag.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) { ObjectNode jsonObj = (ObjectNode) this.propertyBag.get(propertyName); return jsonObj; } return null; }
/** * Gets a string value. * * @param propertyName the property to get. * @return the string value. */ public String getString(String propertyName) { if (this.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) { return this.propertyBag.get(propertyName).asText(); } else { return null; } }
/** * Gets a double value. * * @param propertyName the property to get. * @return the double value. */ public Double getDouble(String propertyName) { if (this.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) { return new Double(this.propertyBag.get(propertyName).asDouble()); } else { return null; } }
@Override public boolean apply(HalPath halPath, HalResource hal) { return hal.getModel().hasNonNull(fieldName); }
public static Class<?> getRealRequestClassType( Class<?> requestClassType, ObjectNode objectNode ){ if ( requestClassType == Condition.class ) { // we know this class has a discriminator field called "type" // if its present, use its given concrete class instead. // Now we know its a valid filter - get the value for the criterion. if (objectNode.hasNonNull(ApiStrings.Conditions.Arguments.TYPE)) { JsonNode node = objectNode.get(ApiStrings.Conditions.Arguments.TYPE); return ConditionType.getConditionClass(node.textValue()); } } // default is just to use the source request class. return requestClassType; } }
@Override public AlienEvent deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectMapper mapper = (ObjectMapper) jp.getCodec(); ObjectNode root = mapper.readTree(jp); Class<? extends AlienEvent> eventClass = null; String type = EventType.INSTANCE_STATE; if (root.hasNonNull(TYPE_FIELD)) { type = root.findValue(TYPE_FIELD).asText(); } eventClass = registry.get(type); if (eventClass == null) { return null; } return mapper.readValue(jp, eventClass); } }
/** * Gets a JSONObject collection. * * @param propertyName the property to get. * @return the JSONObject collection. */ public Collection<ObjectNode> getCollection(String propertyName) { Collection<ObjectNode> result = null; if (this.propertyBag.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) { result = new ArrayList<ObjectNode>(); for (JsonNode n : this.propertyBag.findValues(propertyName)) { result.add((ObjectNode) n); } } return result; }
/** * Gets a property value as Object. * * @param propertyName the property to get. * @return the value of the property. */ public Object get(String propertyName) { if (this.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) { return getValue(this.propertyBag.get(propertyName)); } else { return null; } }
final URI contextURL = tree.hasNonNull(Constants.JSON_CONTEXT) ? URI.create(tree.get(Constants.JSON_CONTEXT).textValue()) : null; if (contextURL != null) { if (tree.hasNonNull(Constants.JSON_COUNT)) { delta.setCount(tree.get(Constants.JSON_COUNT).asInt()); if (tree.hasNonNull(Constants.JSON_NEXT_LINK)) { delta.setNext(URI.create(tree.get(Constants.JSON_NEXT_LINK).textValue())); if (tree.hasNonNull(Constants.JSON_DELTA_LINK)) { delta.setDeltaLink(URI.create(tree.get(Constants.JSON_DELTA_LINK).textValue())); if (tree.hasNonNull(Constants.VALUE)) { JsonEntityDeserializer entityDeserializer = new JsonEntityDeserializer(serverMode); for (JsonNode jsonNode : tree.get(Constants.VALUE)) { final ObjectNode item = (ObjectNode) jsonNode; final ContextURL itemContextURL = item.hasNonNull(Constants.JSON_CONTEXT) ? ContextURLParser.parse(URI.create(item.get(Constants.JSON_CONTEXT).textValue())) : null; item.remove(Constants.JSON_CONTEXT);
final URI contextURL = tree.hasNonNull(Constants.JSON_CONTEXT) ? URI.create(tree.get(Constants.JSON_CONTEXT).textValue()) : null; if (contextURL != null) { if (tree.hasNonNull(Constants.JSON_COUNT)) { delta.setCount(tree.get(Constants.JSON_COUNT).asInt()); if (tree.hasNonNull(Constants.JSON_NEXT_LINK)) { delta.setNext(URI.create(tree.get(Constants.JSON_NEXT_LINK).textValue())); if (tree.hasNonNull(Constants.JSON_DELTA_LINK)) { delta.setDeltaLink(URI.create(tree.get(Constants.JSON_DELTA_LINK).textValue())); if (tree.hasNonNull(Constants.VALUE)) { JsonEntityDeserializer entityDeserializer = new JsonEntityDeserializer(serverMode); for (JsonNode jsonNode : tree.get(Constants.VALUE)) { final ObjectNode item = (ObjectNode) jsonNode; final ContextURL itemContextURL = item.hasNonNull(Constants.JSON_CONTEXT) ? ContextURLParser.parse(URI.create(item.get(Constants.JSON_CONTEXT).textValue())) : null; item.remove(Constants.JSON_CONTEXT);
private static void validatePersistentAnalysisRequiredFields(ObjectNode requestNode) { // Should have 'refresh_rate' and 'query' top-level keys, at least. assertTrue("Missing required top-level fields.", 2 <= requestNode.size()); assertTrue(requestNode.hasNonNull(KeenQueryConstants.REFRESH_RATE)); RefreshRate.validateRefreshRate(requestNode.get(KeenQueryConstants.REFRESH_RATE).asInt()); assertTrue(requestNode.hasNonNull(KeenQueryConstants.QUERY)); // The "query" should have the typical stuff (tested elsewhere) but also the "analysis_type" JsonNode queryNode = requestNode.get(KeenQueryConstants.QUERY); assertTrue(queryNode.hasNonNull(KeenQueryConstants.ANALYSIS_TYPE)); }
@Test public void testSavedQuery_Update_Simple() throws IOException { setMockResponsesForUpdate(); Map<String, Object> updates = new HashMap<String, Object>(); int refreshRate = 6 * 3600; // 6 hrs updates.put(KeenQueryConstants.REFRESH_RATE, refreshRate); Map<String, Object> updateResponse = savedQueryApi.updateQuery(TEST_RESOURCE_NAME, updates); ObjectNode requestNode = verifyPut(updateResponse, null, 1); assertTrue(requestNode.hasNonNull(KeenQueryConstants.REFRESH_RATE)); assertEquals(refreshRate, requestNode.get(KeenQueryConstants.REFRESH_RATE).asInt()); }
@Test public void testSavedQuery_UpdateHelpers_QueryName() throws IOException { setMockResponsesForUpdate(); String newQueryName = "new_name"; Map<String, Object> updateResponse = savedQueryApi.setQueryName(TEST_RESOURCE_NAME, newQueryName); ObjectNode requestNode = verifyPut(updateResponse, null, 1); assertTrue(requestNode.hasNonNull(KeenQueryConstants.QUERY_NAME)); assertEquals(newQueryName, requestNode.get(KeenQueryConstants.QUERY_NAME).asText()); }
@Test public void testSavedQuery_UpdateHelpers_RefreshRate() throws IOException { setMockResponsesForUpdate(); int refreshRate = RefreshRate.fromHours(8); Map<String, Object> updateResponse = savedQueryApi.setRefreshRate(TEST_RESOURCE_NAME, refreshRate); ObjectNode requestNode = verifyPut(updateResponse, null, 1); assertTrue(requestNode.hasNonNull(KeenQueryConstants.REFRESH_RATE)); assertEquals(refreshRate, requestNode.get(KeenQueryConstants.REFRESH_RATE).asInt()); }
private ObjectNode verifyPut(Map<String, Object> putResponse, String displayName, int numExtraFields) throws IOException { assertNotNull(putResponse); assertTrue(!putResponse.isEmpty()); // Even when we change the "query_name" the canned responses return the original name. But // we're not testing that the back end actually changes things, but rather that we parse // correctly. assertEquals(TEST_RESOURCE_NAME, putResponse.get(KeenQueryConstants.QUERY_NAME)); ObjectNode requestNode = getPersistentAnalysisRequestNode(); // Normally "refresh_rate" and "query" are in the request, but if "display_name" or updates // like "query_name" are in the PUT, there'll be more top-level nodes. assertEquals((null != displayName ? 3 : 2) + numExtraFields, requestNode.size()); if (null != displayName) { // Verify we added a "metadata" node. assertTrue(requestNode.hasNonNull(KeenQueryConstants.METADATA)); JsonNode metadataNode = requestNode.get(KeenQueryConstants.METADATA); assertTrue(metadataNode.hasNonNull(KeenQueryConstants.DISPLAY_NAME)); assertEquals(displayName, metadataNode.get(KeenQueryConstants.DISPLAY_NAME).asText()); } return requestNode; }