private Schema parseDependencies(CTLSchemaDto schema, final Schema.Parser parser) throws Exception { if (schema.getDependencySet() != null) { for (CTLSchemaDto dependency : schema.getDependencySet()) { this.parseDependencies(dependency, parser); } } ObjectNode object = new ObjectMapper().readValue(schema.getBody(), ObjectNode.class); object.remove(DEPENDENCIES); String body = new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(object); return parser.parse(body); }
/** * Removes UUIDs from a json tree. * * @param json json tree node */ public static void removeUuids(JsonNode json) { boolean containerWithId = json.isContainerNode() && json.has(UUID_FIELD); boolean isArray = json.isArray(); boolean childIsNotArray = !(json.size() == 1 && json.getElements().next().isArray()); if (containerWithId && !isArray && childIsNotArray) { ((ObjectNode) json).remove(UUID_FIELD); } for (JsonNode node : json) { if (node.isContainerNode()) { removeUuids(node); } } } }
@Override public void remove(String key) { wrapped.remove(key); }
@Override public void remove(String key) { wrapped.remove(key); }
private void removeFieldProperty(String fieldName, String propertyName) { FieldProperty fp = FieldProperty.fromQueryName(propertyName); CheckConditions.checkArgument(fp != null, MessageFormat.format("field property %s not found!", propertyName)); String propertyValueDbName = fieldName + PROPERTY_CONNECTOR + propertyName; getNode().remove(propertyValueDbName); }
@Override public void removeField(String fieldName) { getNode().remove(fieldName); for (FieldProperty fp : FieldProperty.values()) { removeFieldProperty(fieldName, fp.getName()); } }
@Override public void removeProperty(String name) { JsonNode child = node.get(name); if (child!=null && !child.isArray() && !child.isObject()) getNode().remove(name); }
private void convertTetheredCable(final JsonNode obj) { final Iterator<JsonNode> nodes = obj.path("Connector").iterator(); while (nodes.hasNext()) { final ObjectNode node = (ObjectNode) nodes.next(); final JsonNode current = node.path("TetheredCable"); if (!current.isMissingNode() && !current.isNull()) { final int value = Integer.parseInt(current.asText()); node.put("TetheredCable", value); } if (current.isNull()) { node.remove("TetheredCable"); } } }
private void convertLongitude(final JsonNode obj) { final ObjectNode node = (ObjectNode) obj.path("ChargeDeviceLocation"); final JsonNode current = node.path("Longitude"); if (!current.isMissingNode() && !current.isNull()) { final double value = Double.parseDouble(current.asText()); node.put("Longitude", value); } if (current.isNull()) { node.remove("Longitude"); } }
private void convertLongitude(final JsonNode obj) { final ObjectNode node = (ObjectNode) obj.path("ChargeDeviceLocation"); final JsonNode current = node.path("Longitude"); if (!current.isMissingNode() && !current.isNull()) { final double value = Double.parseDouble(current.asText()); node.put("Longitude", value); } if (current.isNull()) { node.remove("Longitude"); } }
private void convertLatitude(final JsonNode obj) { final ObjectNode node = (ObjectNode) obj.path("ChargeDeviceLocation"); final JsonNode current = node.path("Latitude"); if (!current.isMissingNode() && !current.isNull()) { final double value = Double.parseDouble(current.asText()); node.put("Latitude", value); } if (current.isNull()) { node.remove("Latitude"); } }
private void convertLatitude(final JsonNode obj) { final ObjectNode node = (ObjectNode) obj.path("ChargeDeviceLocation"); final JsonNode current = node.path("Latitude"); if (!current.isMissingNode() && !current.isNull()) { final double value = Double.parseDouble(current.asText()); node.put("Latitude", value); } if (current.isNull()) { node.remove("Latitude"); } }
/** * 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); }
private void convertDeviceControllerWebsite(final JsonNode obj) { final ObjectNode node = (ObjectNode) obj.path("DeviceController"); final JsonNode current = node.path("Website"); if (!current.isMissingNode() && !current.isNull()) { node.put("Website", this.createValueDatatype("uri", current.asText())); } if (current.isNull()) { node.remove("Website"); } }
private void convertDeviceOwnerWebsite(final JsonNode obj) { final ObjectNode node = (ObjectNode) obj.path("DeviceOwner"); final JsonNode current = node.path("Website"); if (!current.isMissingNode() && !current.isNull()) { node.put("Website", this.createValueDatatype("uri", current.asText())); } if (current.isNull()) { node.remove("Website"); } }
private void convertDeviceControllerWebsite(final JsonNode obj) { final ObjectNode node = (ObjectNode) obj.path("DeviceController"); final JsonNode current = node.path("Website"); if (!current.isMissingNode() && !current.isNull()) { node.put("Website", this.createValueDatatype("uri", current.asText())); } if (current.isNull()) { node.remove("Website"); } }
private void convertDeviceOwnerWebsite(final JsonNode obj) { final ObjectNode node = (ObjectNode) obj.path("DeviceOwner"); final JsonNode current = node.path("Website"); if (!current.isMissingNode() && !current.isNull()) { node.put("Website", this.createValueDatatype("uri", current.asText())); } if (current.isNull()) { node.remove("Website"); } }
/** * Given a {@link ContainerModel} JSON with only an "id" field, deserialization should fail. * This verifies that even though {@link ContainerModel} has a getId method, the "id" field is not used, since * "processor-id" is the field that is supposed to be used. */ @Test(expected = SamzaException.class) public void testDeserializeContainerModelIdFieldOnly() throws IOException { ObjectNode jobModelJson = buildJobModelJson(); ObjectNode containerModelJson = (ObjectNode) jobModelJson.get("containers").get("1"); containerModelJson.remove("processor-id"); containerModelJson.put("id", 1); 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)); }