public static JSONObject adjustKeys(JSONObject enrichedMessage, JSONObject enrichedField, String field, String prefix) { if ( !enrichedField.isEmpty()) { for (Object enrichedKey : enrichedField.keySet()) { if(!StringUtils.isEmpty(prefix)) { enrichedMessage.put(field + "." + enrichedKey, enrichedField.get(enrichedKey)); } else { enrichedMessage.put(enrichedKey, enrichedField.get(enrichedKey)); } } } return enrichedMessage; }
private JSONObject extractMapValues(ObjectToJsonConverter pConverter, Stack<String> pPathParts, boolean jsonify, Map<Object, Object> pMap, int pLength) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); int i = 0; for(Map.Entry entry : pMap.entrySet()) { Stack<String> paths = (Stack<String>) pPathParts.clone(); try { ret.put(entry.getKey(), pConverter.extractObject(entry.getValue(), paths, jsonify)); if (++i > pLength) { break; } } catch (ValueFaultHandler.AttributeFilteredException exp) { // Filtered out ... } } if (ret.isEmpty() && pLength > 0) { // Not a single value passed the filter throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
private Object extractAll(ObjectToJsonConverter pConverter, T pValue, Stack<String> pPathParts, boolean jsonify) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); for (Map.Entry<String, AttributeExtractor<T>> entry : extractorMap.entrySet()) { Stack<String> paths = (Stack<String>) pPathParts.clone(); try { Object value = entry.getValue().extract(pValue); ret.put(entry.getKey(),pConverter.extractObject(value, paths, jsonify)); } catch (AttributeExtractor.SkipAttributeException e) { // Skip this one ... continue; } catch (ValueFaultHandler.AttributeFilteredException e) { // ... and this, too continue; } } if (ret.isEmpty()) { // Everything filtered, bubble up ... throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
private Object convertMxBeanMapToJson(TabularData pTd, Stack<String> pExtraArgs, ObjectToJsonConverter pConverter) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); for (Object rowObject : pTd.values()) { CompositeData row = (CompositeData) rowObject; Stack<String> path = (Stack<String>) pExtraArgs.clone(); Object keyObject = row.get("key"); if (keyObject != null) { try { Object value = pConverter.extractObject(row.get("value"), path, true); ret.put(keyObject.toString(), value); } catch (ValueFaultHandler.AttributeFilteredException exp) { // Skip to next object since attribute was filtered } } } if (!pTd.isEmpty() && ret.isEmpty()) { // Bubble up if not a single thingy has been found throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
private Object extractCompleteCdAsJson(ObjectToJsonConverter pConverter, CompositeData pData, Stack<String> pPath) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); for (String key : (Set<String>) pData.getCompositeType().keySet()) { Stack<String> path = (Stack<String>) pPath.clone(); try { ret.put(key, pConverter.extractObject(pData.get(key), path, true)); } catch (ValueFaultHandler.AttributeFilteredException exp) { // Ignore this key; } } if (ret.isEmpty()) { // If every key was filtered, this composite data should be skipped completely throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
_LOG.debug("[Metron] Cleaned message: {}", cleanedMessage); if (cleanedMessage == null || cleanedMessage.isEmpty()) { throw new Exception("Unable to clean message: " + rawMessage);
enrichedMessage.put("adapter." + adapter.getClass().getSimpleName().toLowerCase() + ".begin.ts", "" + System.currentTimeMillis()); try { if (rawMessage == null || rawMessage.isEmpty()) throw new Exception("Could not parse binary stream to JSON"); if (key == null) if (!enrichedMessage.isEmpty()) { collector.emit(enrichmentType, new Values(key, enrichedMessage, subGroup));
/** * Ensures that if we try to transform with a field which does not exist, it does not * 1. throw an exception * 2. do any transformation. */ @Test public void testStellar_negative() throws Exception { SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(stellarConfig)); FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null); //no input fields => no transformation JSONObject input = new JSONObject(new HashMap<String, Object>() {{ }}); handler.transformAndUpdate(input, Context.EMPTY_CONTEXT()); Assert.assertFalse(input.containsKey("utc_timestamp")); Assert.assertTrue(input.isEmpty()); }
/** * concerts all time values into a normalised time in memo json object from database * example timestamps to translate * { * "suppressedtime":"2016-08-04 16:11:16.01+01", * "suppresseduntil":"2016-08-04 16:11:16.01+01", * "lasteventtime":"2016-08-04 16:11:16.01+01", * "alarmacktime":"2016-08-04 07:34:04.617+01", * "firsteventtime":"2016-08-04 16:11:16.01+01", * "firstautomationtime":"2016-08-04 16:12:03.272205+01", * "lastautomationtime":"2016-08-04 16:12:03.272205+01" * } * @param jsonObject * @return */ public JSONObject jsonMemoTimeNormaliser(JSONObject jsonObject){ if(jsonObject.isEmpty()) return jsonObject; String created= (jsonObject.get("created")==null) ? null : timeNormaliser(jsonObject.get("created").toString()); if (created!=null) jsonObject.put("created", created); String updated= (jsonObject.get("updated")==null) ? null : timeNormaliser(jsonObject.get("updated").toString()); if (updated!=null) jsonObject.put("suppresseduntil", updated); return jsonObject; }
private JSONObject extractMapValues(ObjectToJsonConverter pConverter, Stack<String> pPathParts, boolean jsonify, Map<Object, Object> pMap, int pLength) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); int i = 0; for(Map.Entry entry : pMap.entrySet()) { Stack<String> paths = (Stack<String>) pPathParts.clone(); try { ret.put(entry.getKey(), pConverter.extractObject(entry.getValue(), paths, jsonify)); if (++i > pLength) { break; } } catch (ValueFaultHandler.AttributeFilteredException exp) { // Filtered out ... } } if (ret.isEmpty() && pLength > 0) { // Not a single value passed the filter throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
private JSONObject extractMapValues(ObjectToJsonConverter pConverter, Stack<String> pPathParts, boolean jsonify, Map<Object, Object> pMap, int pLength) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); int i = 0; for(Map.Entry entry : pMap.entrySet()) { Stack<String> paths = (Stack<String>) pPathParts.clone(); try { ret.put(entry.getKey(), pConverter.extractObject(entry.getValue(), paths, jsonify)); if (++i > pLength) { break; } } catch (ValueFaultHandler.AttributeFilteredException exp) { // Filtered out ... } } if (ret.isEmpty() && pLength > 0) { // Not a single value passed the filter throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
private JSONObject extractMapValues(ObjectToJsonConverter pConverter, Stack<String> pPathParts, boolean jsonify, Map<Object, Object> pMap, int pLength) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); int i = 0; for(Map.Entry entry : pMap.entrySet()) { Stack<String> paths = (Stack<String>) pPathParts.clone(); try { ret.put(entry.getKey(), pConverter.extractObject(entry.getValue(), paths, jsonify)); if (++i > pLength) { break; } } catch (ValueFaultHandler.AttributeFilteredException exp) { // Filtered out ... } } if (ret.isEmpty() && pLength > 0) { // Not a single value passed the filter throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
private Object extractAll(ObjectToJsonConverter pConverter, T pValue, Stack<String> pPathParts, boolean jsonify) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); for (Map.Entry<String, AttributeExtractor<T>> entry : extractorMap.entrySet()) { Stack<String> paths = (Stack<String>) pPathParts.clone(); try { Object value = entry.getValue().extract(pValue); ret.put(entry.getKey(),pConverter.extractObject(value, paths, jsonify)); } catch (AttributeExtractor.SkipAttributeException e) { // Skip this one ... continue; } catch (ValueFaultHandler.AttributeFilteredException e) { // ... and this, too continue; } } if (ret.isEmpty()) { // Everything filtered, bubble up ... throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
private Object extractAll(ObjectToJsonConverter pConverter, T pValue, Stack<String> pPathParts, boolean jsonify) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); for (Map.Entry<String, AttributeExtractor<T>> entry : extractorMap.entrySet()) { Stack<String> paths = (Stack<String>) pPathParts.clone(); try { Object value = entry.getValue().extract(pValue); ret.put(entry.getKey(),pConverter.extractObject(value, paths, jsonify)); } catch (AttributeExtractor.SkipAttributeException e) { // Skip this one ... continue; } catch (ValueFaultHandler.AttributeFilteredException e) { // ... and this, too continue; } } if (ret.isEmpty()) { // Everything filtered, bubble up ... throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
private Object extractAll(ObjectToJsonConverter pConverter, T pValue, Stack<String> pPathParts, boolean jsonify) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); for (Map.Entry<String, AttributeExtractor<T>> entry : extractorMap.entrySet()) { Stack<String> paths = (Stack<String>) pPathParts.clone(); try { Object value = entry.getValue().extract(pValue); ret.put(entry.getKey(),pConverter.extractObject(value, paths, jsonify)); } catch (AttributeExtractor.SkipAttributeException e) { // Skip this one ... continue; } catch (ValueFaultHandler.AttributeFilteredException e) { // ... and this, too continue; } } if (ret.isEmpty()) { // Everything filtered, bubble up ... throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
private Object convertMxBeanMapToJson(TabularData pTd, Stack<String> pExtraArgs, ObjectToJsonConverter pConverter) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); for (Object rowObject : pTd.values()) { CompositeData row = (CompositeData) rowObject; Stack<String> path = (Stack<String>) pExtraArgs.clone(); Object keyObject = row.get("key"); if (keyObject != null) { try { Object value = pConverter.extractObject(row.get("value"), path, true); ret.put(keyObject.toString(), value); } catch (ValueFaultHandler.AttributeFilteredException exp) { // Skip to next object since attribute was filtered } } } if (!pTd.isEmpty() && ret.isEmpty()) { // Bubble up if not a single thingy has been found throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
private Object convertMxBeanMapToJson(TabularData pTd, Stack<String> pExtraArgs, ObjectToJsonConverter pConverter) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); for (Object rowObject : pTd.values()) { CompositeData row = (CompositeData) rowObject; Stack<String> path = (Stack<String>) pExtraArgs.clone(); Object keyObject = row.get("key"); if (keyObject != null) { try { Object value = pConverter.extractObject(row.get("value"), path, true); ret.put(keyObject.toString(), value); } catch (ValueFaultHandler.AttributeFilteredException exp) { // Skip to next object since attribute was filtered } } } if (!pTd.isEmpty() && ret.isEmpty()) { // Bubble up if not a single thingy has been found throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
private Object extractCompleteCdAsJson(ObjectToJsonConverter pConverter, CompositeData pData, Stack<String> pPath) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); for (String key : (Set<String>) pData.getCompositeType().keySet()) { Stack<String> path = (Stack<String>) pPath.clone(); try { ret.put(key, pConverter.extractObject(pData.get(key), path, true)); } catch (ValueFaultHandler.AttributeFilteredException exp) { // Ignore this key; } } if (ret.isEmpty()) { // If every key was filtered, this composite data should be skipped completely throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
private Object extractCompleteCdAsJson(ObjectToJsonConverter pConverter, CompositeData pData, Stack<String> pPath) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); for (String key : (Set<String>) pData.getCompositeType().keySet()) { Stack<String> path = (Stack<String>) pPath.clone(); try { ret.put(key, pConverter.extractObject(pData.get(key), path, true)); } catch (ValueFaultHandler.AttributeFilteredException exp) { // Ignore this key; } } if (ret.isEmpty()) { // If every key was filtered, this composite data should be skipped completely throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
private Object extractCompleteCdAsJson(ObjectToJsonConverter pConverter, CompositeData pData, Stack<String> pPath) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); for (String key : (Set<String>) pData.getCompositeType().keySet()) { Stack<String> path = (Stack<String>) pPath.clone(); try { ret.put(key, pConverter.extractObject(pData.get(key), path, true)); } catch (ValueFaultHandler.AttributeFilteredException exp) { // Ignore this key; } } if (ret.isEmpty()) { // If every key was filtered, this composite data should be skipped completely throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }