Search in sources :

Example 6 with Json

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;
}
Also used : Fields(io.atlasmap.v2.Fields)

Example 7 with Json

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());
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) Field(io.atlasmap.v2.Field) JsonField(io.atlasmap.json.v2.JsonField) Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) FieldGroup(io.atlasmap.v2.FieldGroup) Test(org.junit.jupiter.api.Test)

Example 8 with Json

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());
    }
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) Field(io.atlasmap.v2.Field) JsonField(io.atlasmap.json.v2.JsonField) Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) FieldGroup(io.atlasmap.v2.FieldGroup) Test(org.junit.jupiter.api.Test)

Example 9 with Json

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());
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Validations(io.atlasmap.v2.Validations) AtlasValidationException(io.atlasmap.api.AtlasValidationException)

Example 10 with Json

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());
}
Also used : JsonEnumField(io.atlasmap.json.v2.JsonEnumField) Field(io.atlasmap.v2.Field) JsonField(io.atlasmap.json.v2.JsonField) JsonField(io.atlasmap.json.v2.JsonField) JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)15 Field (io.atlasmap.v2.Field)12 AtlasMapping (io.atlasmap.v2.AtlasMapping)11 JsonField (io.atlasmap.json.v2.JsonField)7 File (java.io.File)7 FieldGroup (io.atlasmap.v2.FieldGroup)6 AtlasException (io.atlasmap.api.AtlasException)5 AtlasValidationException (io.atlasmap.api.AtlasValidationException)4 ProcessMappingResponse (io.atlasmap.v2.ProcessMappingResponse)4 Response (javax.ws.rs.core.Response)4 AtlasPath (io.atlasmap.core.AtlasPath)3 JavaField (io.atlasmap.java.v2.JavaField)3 JsonDataSource (io.atlasmap.json.v2.JsonDataSource)3 DataSource (io.atlasmap.v2.DataSource)3 XmlDataSource (io.atlasmap.xml.v2.XmlDataSource)3 Test (org.junit.Test)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 AtlasConversionException (io.atlasmap.api.AtlasConversionException)2 JsonDocument (io.atlasmap.json.v2.JsonDocument)2