@Test public void testOverrideCtlDependency() throws IOException, ParseException { SchemaFormAvroConverter converter = new SchemaFormAvroConverter(new TestCtlSource()); String typeCtlReferencesSchema = TestAvroSchemas.getSchemaJson(TestAvroSchemas.TYPE_CTL_REFERENCES); RecordField schemaForm = converter.createSchemaFormFromSchema(typeCtlReferencesSchema); StringField nameField = getStringField(schemaForm, "recordName"); StringField namespaceField = getStringField(schemaForm, "recordNamespace"); FormField field = schemaForm.getFieldByName("version"); Assert.assertNotNull(field); Assert.assertTrue(field instanceof VersionField); VersionField versionField = (VersionField)field; versionField.setValue(null); nameField.setValue("TypeB"); namespaceField.setValue("org.kaaproject.ctl"); Assert.assertNotNull(versionField.getValue()); Assert.assertEquals(6, versionField.getValue().intValue()); FormContext context = schemaForm.getContext(); Assert.assertNotNull(context); List<FqnVersion> ctlDependencies = context.getCtlDependenciesList(); Assert.assertNotNull(ctlDependencies); Assert.assertEquals(1, ctlDependencies.size()); FqnVersion fqnVersion = ctlDependencies.get(0); Assert.assertNotNull(fqnVersion); Assert.assertEquals("org.kaaproject.ctl.TypeA", fqnVersion.getFqnString()); Assert.assertEquals(5, fqnVersion.getVersion()); }
public RecordField createSchemaFormFromSchema(String schemaString) throws IOException { ObjectMapper mapper = new ObjectMapper(); JsonNode node = mapper.readTree(schemaString); Schema.Parser parser = new Schema.Parser(); Set<Fqn> fqns = null; if (hasCtl) { JsonNode dependenciesNode = node.get(DEPENDENCIES); if (dependenciesNode != null && dependenciesNode.isArray()) { Map<String,Schema> types = new HashMap<>(); fqns = new HashSet<>(); for (int i=0;i<dependenciesNode.size();i++) { JsonNode dependencyNode = dependenciesNode.get(i); Fqn fqn = new Fqn(dependencyNode.get(FQN).asText()); types.put(fqn.getFqnString(), Schema.createRecord(fqn.getName(), null, fqn.getNamespace(), false)); fqns.add(fqn); } parser.addTypes(types); } } Schema schema = parser.parse(schemaString); return createSchemaFormFromSchema(schema, fqns); }
SchemaFormAvroConverter implements ConverterConstants, SchemaFormConstants { public RecordField createSchemaFormFromSchema(String schemaString) throws IOException { ObjectMapper mapper = new ObjectMapper(); JsonNode node = mapper.readTree(schemaString); Schema.Parser parser = new Schema.Parser(); Set<Fqn> fqns = null; if (hasCtl) { JsonNode dependenciesNode = node.get(DEPENDENCIES); if (dependenciesNode != null && dependenciesNode.isArray()) { Map<String,Schema> types = new HashMap<>(); fqns = new HashSet<>(); for (int i=0;i<dependenciesNode.size();i++) { JsonNode dependencyNode = dependenciesNode.get(i); Fqn fqn = new Fqn(dependencyNode.get(FQN).asText()); types.put(fqn.getFqnString(), Schema.createRecord(fqn.getName(), null, fqn.getNamespace(), false)); fqns.add(fqn); } parser.addTypes(types); } } Schema schema = parser.parse(schemaString); return createSchemaFormFromSchema(schema, fqns); } }
SchemaFormAvroConverter implements ConverterConstants, SchemaFormConstants { public RecordField createSchemaFormFromSchema(String schemaString) throws IOException { ObjectMapper mapper = new ObjectMapper(); JsonNode node = mapper.readTree(schemaString); Schema.Parser parser = new Schema.Parser(); Set<Fqn> fqns = null; if (hasCtl) { JsonNode dependenciesNode = node.get(DEPENDENCIES); if (dependenciesNode != null && dependenciesNode.isArray()) { Map<String,Schema> types = new HashMap<>(); fqns = new HashSet<>(); for (int i=0;i<dependenciesNode.size();i++) { JsonNode dependencyNode = dependenciesNode.get(i); Fqn fqn = new Fqn(dependencyNode.get(FQN).asText()); types.put(fqn.getFqnString(), Schema.createRecord(fqn.getName(), null, fqn.getNamespace(), false)); fqns.add(fqn); } parser.addTypes(types); } } Schema schema = parser.parse(schemaString); return createSchemaFormFromSchema(schema, fqns); } SchemaFormAvroConverter();  SchemaFormAvroConverter(CtlSource ctlSource); }
SchemaFormAvroConverter implements ConverterConstants, SchemaFormConstants { public RecordField createSchemaFormFromSchema(String schemaString) throws IOException { ObjectMapper mapper = new ObjectMapper(); JsonNode node = mapper.readTree(schemaString); Schema.Parser parser = new Schema.Parser(); Set<Fqn> fqns = null; if (hasCtl) { JsonNode dependenciesNode = node.get(DEPENDENCIES); if (dependenciesNode != null && dependenciesNode.isArray()) { Map<String,Schema> types = new HashMap<>(); fqns = new HashSet<>(); for (int i=0;i<dependenciesNode.size();i++) { JsonNode dependencyNode = dependenciesNode.get(i); Fqn fqn = new Fqn(dependencyNode.get(FQN).asText()); types.put(fqn.getFqnString(), Schema.createRecord(fqn.getName(), null, fqn.getNamespace(), false)); fqns.add(fqn); } parser.addTypes(types); } } Schema schema = parser.parse(schemaString); return createSchemaFormFromSchema(schema, fqns); } SchemaFormAvroConverter();  SchemaFormAvroConverter(CtlSource ctlSource); RecordField getEmptySchemaFormInstance(); RecordField createSchemaFormFromSchema(String schemaString); RecordField createSchemaFormFromSchema(Schema schema); RecordField createSchemaFormFromSchema(Schema schema, Set<Fqn> fqns); Schema createSchemaFromSchemaForm(RecordField field); static String createSchemaString(Schema schema, boolean pretty); }
SchemaFormAvroConverter implements ConverterConstants, SchemaFormConstants { public RecordField createSchemaFormFromSchema(String schemaString) throws IOException { ObjectMapper mapper = new ObjectMapper(); JsonNode node = mapper.readTree(schemaString); Schema.Parser parser = new Schema.Parser(); Set<Fqn> fqns = null; if (hasCtl) { JsonNode dependenciesNode = node.get(DEPENDENCIES); if (dependenciesNode != null && dependenciesNode.isArray()) { Map<String,Schema> types = new HashMap<>(); fqns = new HashSet<>(); for (int i=0;i<dependenciesNode.size();i++) { JsonNode dependencyNode = dependenciesNode.get(i); Fqn fqn = new Fqn(dependencyNode.get(FQN).asText()); types.put(fqn.getFqnString(), Schema.createRecord(fqn.getName(), null, fqn.getNamespace(), false)); fqns.add(fqn); } parser.addTypes(types); } } Schema schema = parser.parse(schemaString); return createSchemaFormFromSchema(schema, fqns); } SchemaFormAvroConverter();  SchemaFormAvroConverter(CtlSource ctlSource); RecordField getEmptySchemaFormInstance(); RecordField createSchemaFormFromSchema(String schemaString); RecordField createSchemaFormFromSchema(Schema schema); RecordField createSchemaFormFromSchema(Schema schema, Set<Fqn> fqns); Schema createSchemaFromSchemaForm(RecordField field); static String createSchemaString(Schema schema, boolean pretty);  }