@Override public Object apply(List<Object> args, Context context) throws ParseException { String config = (String) args.get(0); if(config == null) { return null; } SensorParserConfig configObj = (SensorParserConfig) PARSER.deserialize(config); FieldTransformer stellarTransformer = getStellarTransformer(configObj); String[] headers = new String[] { "Field", "Transformation"}; String[][] data = new String[stellarTransformer.getConfig().size()][2]; int i = 0; for(Map.Entry<String, Object> kv : stellarTransformer.getConfig().entrySet()) { data[i++] = new String[] {kv.getKey(), kv.getValue().toString()}; } return FlipTable.of(headers, data); }
private static void pruneEmptyStellarTransformers(SensorParserConfig config) { List<FieldTransformer> toRemove = new ArrayList<>(); List<FieldTransformer> fieldTransformations = config.getFieldTransformations(); for(FieldTransformer transformer : fieldTransformations) { if(transformer.getFieldTransformation().getClass().getName() .equals(FieldTransformations.STELLAR.getMappingClass().getName()) && transformer.getConfig().isEmpty() ) { toRemove.add(transformer); } } for(FieldTransformer t : toRemove) { fieldTransformations.remove(t); } } private static FieldTransformer getStellarTransformer(SensorParserConfig config) {
@Override public Object apply(List<Object> args, Context context) throws ParseException { String config = (String) args.get(0); if(config == null) { return null; } SensorParserConfig configObj = (SensorParserConfig) PARSER.deserialize(config); FieldTransformer stellarTransformer = getStellarTransformer(configObj); Map<String, String> additionalTransforms = (Map<String, String>) args.get(1); if(additionalTransforms == null || additionalTransforms.isEmpty()) { return config; } for(Map.Entry<String, String> kv : additionalTransforms.entrySet()) { stellarTransformer.getConfig().put(kv.getKey(), kv.getValue()); } List<String> output = new ArrayList<>(); output.addAll(stellarTransformer.getConfig().keySet()); stellarTransformer.setOutput(output); try { return JSONUtils.INSTANCE.toJSON(configObj, true); } catch (JsonProcessingException e) { LOG.error("Unable to convert object to JSON: {}", configObj, e); return config; } }
@Override public Object apply(List<Object> args, Context context) throws ParseException { String config = (String) args.get(0); if(config == null) { return null; } SensorParserConfig configObj = (SensorParserConfig) PARSER.deserialize(config); FieldTransformer stellarTransformer = getStellarTransformer(configObj); List<String> removals = (List<String>)args.get(1); if(removals == null || removals.isEmpty()) { return config; } for(String removal : removals) { stellarTransformer.getConfig().remove(removal); } List<String> output = new ArrayList<>(); output.addAll(stellarTransformer.getConfig().keySet()); stellarTransformer.setOutput(output); pruneEmptyStellarTransformers(configObj); try { return JSONUtils.INSTANCE.toJSON(configObj, true); } catch (JsonProcessingException e) { LOG.error("Unable to convert object to JSON: {}", configObj, e); return config; } }
@Override public int hashCode() { int result = getInput() != null ? getInput().hashCode() : 0; result = 31 * result + (getOutput() != null ? getOutput().hashCode() : 0); result = 31 * result + (getTransformation() != null ? getTransformation().hashCode() : 0); result = 31 * result + (getConfig() != null ? getConfig().hashCode() : 0); return result; } }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; FieldTransformer that = (FieldTransformer) o; if (getInput() != null ? !getInput().equals(that.getInput()) : that.getInput() != null) return false; if (getOutput() != null ? !getOutput().equals(that.getOutput()) : that.getOutput() != null) return false; if (getTransformation() != null ? !getTransformation().equals(that.getTransformation()) : that.getTransformation() != null) return false; return getConfig() != null ? getConfig().equals(that.getConfig()) : that.getConfig() == null; }