use of io.atlasmap.v2.Json in project atlasmap by atlasmap.
the class AtlasJsonModelFactory method createJsonDocument.
/**
* Creates a JSON Document.
* @return JSON Document
*/
public static JsonDocument createJsonDocument() {
JsonDocument jsonDocument = new JsonDocument();
jsonDocument.setFields(new Fields());
return jsonDocument;
}
use of io.atlasmap.v2.Json in project atlasmap by atlasmap.
the class JsonFieldReaderTest method testReadParentCollectionEmptyItem.
@Test
public void testReadParentCollectionEmptyItem() throws Exception {
final String document = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("complex-repeated-result-empty-item.json").toURI())));
reader.setDocument(document);
FieldGroup address = new FieldGroup();
address.setFieldType(FieldType.COMPLEX);
address.setDocId("json");
address.setPath("/orders[]/address");
JsonField addressLine1 = AtlasJsonModelFactory.createJsonField();
addressLine1.setFieldType(FieldType.STRING);
addressLine1.setDocId("json");
addressLine1.setPath("/orders[]/address/addressLine1");
address.getField().add(addressLine1);
AtlasInternalSession session = mock(AtlasInternalSession.class);
when(session.head()).thenReturn(mock(Head.class));
when(session.head().getSourceField()).thenReturn(address);
Field readField = reader.read(session);
assertNotNull(readField);
assertEquals(FieldGroup.class, readField.getClass());
FieldGroup readGroup = FieldGroup.class.cast(readField);
assertEquals(2, readGroup.getField().size());
FieldGroup readAddress = (FieldGroup) readGroup.getField().get(0);
assertEquals("/orders[0]/address", readAddress.getPath());
assertEquals(1, readAddress.getField().size());
Field readAddressLine = (Field) readAddress.getField().get(0);
assertEquals("/orders[0]/address/addressLine1", readAddressLine.getPath());
assertEquals("123 Main St (1)", readAddressLine.getValue());
readAddress = (FieldGroup) readGroup.getField().get(1);
assertEquals("/orders[2]/address", readAddress.getPath());
assertEquals(1, readAddress.getField().size());
readAddressLine = (Field) readAddress.getField().get(0);
assertEquals("/orders[2]/address/addressLine1", readAddressLine.getPath());
assertEquals("123 Main St (3)", readAddressLine.getValue());
}
use of io.atlasmap.v2.Json in project atlasmap by atlasmap.
the class JsonFieldReaderTest method testReadParentCollection.
@Test
public void testReadParentCollection() throws Exception {
final String document = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("complex-repeated-result.json").toURI())));
reader.setDocument(document);
FieldGroup address = new FieldGroup();
address.setFieldType(FieldType.COMPLEX);
address.setDocId("json");
address.setPath("/orders[]/address");
JsonField addressLine1 = AtlasJsonModelFactory.createJsonField();
addressLine1.setFieldType(FieldType.STRING);
addressLine1.setDocId("json");
addressLine1.setPath("/orders[]/address/addressLine1");
address.getField().add(addressLine1);
AtlasInternalSession session = mock(AtlasInternalSession.class);
when(session.head()).thenReturn(mock(Head.class));
when(session.head().getSourceField()).thenReturn(address);
Field readField = reader.read(session);
assertNotNull(readField);
assertEquals(FieldGroup.class, readField.getClass());
FieldGroup readGroup = FieldGroup.class.cast(readField);
assertEquals(5, readGroup.getField().size());
for (int i = 0; i < 5; i++) {
FieldGroup readAddress = (FieldGroup) readGroup.getField().get(i);
assertEquals("/orders[" + i + "]/address", readAddress.getPath());
assertEquals(1, readAddress.getField().size());
Field readAddressLine = (Field) readAddress.getField().get(0);
assertEquals("/orders[" + i + "]/address/addressLine1", readAddressLine.getPath());
assertEquals("123 Main St (" + (i + 1) + ")", readAddressLine.getValue());
}
}
use of io.atlasmap.v2.Json in project atlasmap by atlasmap.
the class KafkaConnectModule method processPreValidation.
@Override
public void processPreValidation(AtlasInternalSession session) throws AtlasException {
if (session == null || session.getMapping() == null) {
throw new AtlasValidationException("Invalid session: Session and AtlasMapping must be specified");
}
Validations validations = session.getValidations();
KafkaConnectValidationService kafkaConnectValidationService = new KafkaConnectValidationService(getConversionService(), getFieldActionService());
kafkaConnectValidationService.setMode(getMode());
kafkaConnectValidationService.setDocId(getDocId());
List<Validation> kafkaConnectValidations = kafkaConnectValidationService.validateMapping(session.getMapping());
if (kafkaConnectValidations != null && !kafkaConnectValidations.isEmpty()) {
validations.getValidation().addAll(kafkaConnectValidations);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Detected " + kafkaConnectValidations.size() + " json validation notices");
}
if (LOG.isDebugEnabled()) {
LOG.debug("{}: processPreValidation completed", getDocId());
}
}
use of io.atlasmap.v2.Json in project atlasmap by atlasmap.
the class JsonSchemaInspectorTest method inspectJsonSchemaGeo.
// examples from json-schema.org
@Test
public void inspectJsonSchemaGeo() throws Exception {
final String schema = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/schema/geo.json")));
JsonDocument document = inspectionService.inspectJsonSchema(schema);
List<Field> fields = document.getFields().getField();
JsonField f = (JsonField) fields.get(0);
assertEquals("latitude", f.getName());
assertEquals("/latitude", f.getPath());
assertEquals(FieldType.NUMBER, f.getFieldType());
f = (JsonField) fields.get(1);
assertEquals("longitude", f.getName());
assertEquals("/longitude", f.getPath());
assertEquals(FieldType.NUMBER, f.getFieldType());
}
Aggregations