private List<String> getDeltaFieldNamesForNewSchema(Schema originalSchema) { List<String> deltaFields = new ArrayList<>(); for (Field field : originalSchema.getFields()) { String deltaAttributeField = field.getJsonProp(this.attributeField).getValueAsText(); ObjectNode objectNode = getDeltaPropValue(deltaAttributeField); if (objectNode == null || objectNode.get(this.deltaPropName) == null) { continue; } if (Boolean.parseBoolean(objectNode.get(this.deltaPropName).toString())) { deltaFields.add(field.name()); } } log.info("Will use delta fields: " + deltaFields); return deltaFields; }
@Override public List<String> getNodeKeys() { LinkedList<String> out = new LinkedList<String>(); for (Iterator<String> i = node.getFieldNames(); i.hasNext();) { String name = i.next(); JsonNode child = node.get(name); if (child.isArray() || child.isObject()) out.add(name); } return out; }
@Override public boolean equals(Object o) { if (o == this) return true; if (o == null) return false; if (o.getClass() != getClass()) { return false; } ObjectNode other = (ObjectNode) o; if (other.size() != size()) { return false; } if (_children != null) { for (Map.Entry<String, JsonNode> en : _children.entrySet()) { String key = en.getKey(); JsonNode value = en.getValue(); JsonNode otherValue = other.get(key); if (otherValue == null || !otherValue.equals(value)) { return false; } } } return true; }
@Override public List<String> getPropertyKeys() { LinkedList<String> out = new LinkedList<String>(); for (Iterator<String> i = node.getFieldNames(); i.hasNext();) { String name = i.next(); JsonNode child = node.get(name); if (!child.isArray() && !child.isObject()) out.add(name); } return out; }
private List<FileData> recursiveShallowExport(List<FileData> files, CTLSchemaDto parent) throws Exception { files.add(this.shallowExport(parent)); ObjectNode object = new ObjectMapper().readValue(parent.getBody(), ObjectNode.class); ArrayNode dependencies = (ArrayNode) object.get(DEPENDENCIES); if (dependencies != null) { for (JsonNode node : dependencies) { ObjectNode dependency = (ObjectNode) node; String fqn = dependency.get(FQN).getTextValue(); Integer version = dependency.get(VERSION).getIntValue(); CTLSchemaDto child = this.findAnyCtlSchemaByFqnAndVerAndTenantIdAndApplicationId( fqn, version, parent.getMetaInfo().getTenantId(), parent.getMetaInfo().getApplicationId()); Validate.notNull(child, MessageFormat.format("The dependency [{0}] was not found!", fqn)); this.recursiveShallowExport(files, child); } } return files; } }
if (!object.has(TYPE) || !object.get(TYPE).isTextual() || !object.get(TYPE).getTextValue().equals("record")) { throw new IllegalArgumentException("The data provided is not a record!"); if (!object.has(NAMESPACE) || !object.get(NAMESPACE).isTextual()) { throw new IllegalArgumentException("No namespace specified!"); } else if (!object.has(NAME) || !object.get(NAME).isTextual()) { throw new IllegalArgumentException("No name specified!"); } else { fqn = object.get(NAMESPACE).getTextValue() + "." + object.get(NAME).getTextValue(); schema.setMetaInfo(metaInfo); if (!object.has(VERSION) || !object.get(VERSION).isInt()) { object.put(VERSION, 1); schema.setVersion(object.get(VERSION).asInt()); if (!object.has(DEPENDENCIES)) { schema.setDependencySet(dependencies); } else if (!object.get(DEPENDENCIES).isArray()) { throw new IllegalArgumentException("Illegal dependencies format!"); } else { for (JsonNode child : object.get(DEPENDENCIES)) { if (!child.isObject() || !child.has(FQN) || !child.get(FQN).isTextual() || !child.has(VERSION) || !child.get(VERSION).isInt()) {
@Override public boolean equals(Object o) { if (o == this) return true; if (o == null) return false; if (o.getClass() != getClass()) { return false; } ObjectNode other = (ObjectNode) o; if (other.size() != size()) { return false; } if (_children != null) { for (Map.Entry<String, JsonNode> en : _children.entrySet()) { String key = en.getKey(); JsonNode value = en.getValue(); JsonNode otherValue = other.get(key); if (otherValue == null || !otherValue.equals(value)) { return false; } } } return true; }
@SuppressWarnings("deprecation") @Override public Object getProperty(String name) { JsonNode child = node.get(name); if (child==null) return null; return child.getValueAsText(); }
@Override public ObjectNode toJson() { ObjectNode obj = super.toJson(); if (this.hasAttribute) { ObjectNode node = (ObjectNode) obj.get(NodePropertyParser.NODE_PROPERTY); node.put(AttributePropertyParser.ATTRIBUTE_PROPERTY, attribute); } return obj; }
@Override public boolean isProperty(String name) { JsonNode child = node.get(name); return (child!=null && !child.isArray() && !child.isObject()); }
private String determinePostType(ObjectNode node) { if (node.has("type")) { try { String type = node.get("type").getTextValue(); PostType.valueOf(type.toUpperCase()); return type; } catch (IllegalArgumentException e) { return "post"; } } return "post"; }
private String readString(ObjectNode node, String property) throws JsonSchemaValidationException { JsonNode reqNode = node.get(property); if (reqNode == null) { return null; } if (!reqNode.isTextual()) { throw new JsonSchemaValidationException(property + " property must be a string", "", reqNode, null); } return reqNode.asText(); }
@Override public IConfig getNode(String name) { JsonNode child = node.get(name); if (child == null) return null; if (child.isObject() || child.isArray()) return new JsonConfig(name, this, child); return null; }
private IndexerDefinitionBuilder getDefinitionFromNode(ObjectNode baseNode, String name) { JsonNode node = baseNode.get(name); if (node == null || node.isNull() || !node.isObject()) { throw new JsonFormatException("Unable to find object field: " + name); } return IndexerDefinitionJsonSerDeser.INSTANCE.fromJson((ObjectNode)node); } }
@Override public void setProperty(String name, Object value) { JsonNode child = node.get(name); if (child==null || !child.isArray() && !child.isObject()) getNode().put(name,MCast.objectToString(value)); }
/** * Given a {@link ContainerModel} JSON with an unknown field, deserialization should properly ignore it. */ @Test public void testDeserializeUnknownTaskModelField() throws IOException { ObjectNode jobModelJson = buildJobModelJson(); ObjectNode taskModelJson = (ObjectNode) jobModelJson.get("containers").get("1").get("tasks").get("test"); taskModelJson.put("unknown_task_model_key", "unknown_task_model_value"); assertEquals(this.jobModel, deserializeFromObjectNode(jobModelJson)); }
/** * Given a {@link ContainerModel} JSON with neither a processor-id nor a container-id, deserialization should fail. */ @Test(expected = SamzaException.class) public void testDeserializeContainerModelMissingProcessorIdAndContainerId() throws IOException { ObjectNode jobModelJson = buildJobModelJson(); ObjectNode containerModelJson = (ObjectNode) jobModelJson.get("containers").get("1"); containerModelJson.remove("processor-id"); deserializeFromObjectNode(jobModelJson); }
/** * Given a {@link ContainerModel} JSON with a processor-id and a container-id, deserialization should properly ignore * the container-id. */ @Test public void testDeserializeContainerIdAndProcessorId() throws IOException { ObjectNode jobModelJson = buildJobModelJson(); ObjectNode containerModelJson = (ObjectNode) jobModelJson.get("containers").get("1"); containerModelJson.put("container-id", 123); assertEquals(this.jobModel, deserializeFromObjectNode(jobModelJson)); }
/** * Given a {@link ContainerModel} JSON with an unknown field, deserialization should properly ignore it. */ @Test public void testDeserializeUnknownContainerModelField() throws IOException { ObjectNode jobModelJson = buildJobModelJson(); ObjectNode containerModelJson = (ObjectNode) jobModelJson.get("containers").get("1"); containerModelJson.put("unknown_container_model_key", "unknown_container_model_value"); assertEquals(this.jobModel, deserializeFromObjectNode(jobModelJson)); }
/** * Given a {@link ContainerModel} JSON without a processor-id but with a container-id, deserialization should use the * container-id to calculate the processor-id. */ @Test public void testDeserializeContainerModelOnlyContainerId() throws IOException { ObjectNode jobModelJson = buildJobModelJson(); ObjectNode containerModelJson = (ObjectNode) jobModelJson.get("containers").get("1"); containerModelJson.remove("processor-id"); containerModelJson.put("container-id", 1); assertEquals(this.jobModel, deserializeFromObjectNode(jobModelJson)); }