Search in sources :

Example 46 with JsonField

use of io.atlasmap.json.v2.JsonField in project atlasmap by atlasmap.

the class JsonFieldWriterTest method read.

private AtlasInternalSession read(Path path, FieldType outputFieldType, String fieldPath) throws IOException, AtlasException {
    String document = new String(Files.readAllBytes(path));
    reader.setDocument(document);
    JsonField jsonField = AtlasJsonModelFactory.createJsonField();
    jsonField.setPath(fieldPath);
    jsonField.setFieldType(outputFieldType);
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(jsonField);
    Audits audits = new Audits();
    when(session.getAudits()).thenReturn(audits);
    reader.read(session);
    return session;
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) Head(io.atlasmap.spi.AtlasInternalSession.Head) Audits(io.atlasmap.v2.Audits) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession)

Example 47 with JsonField

use of io.atlasmap.json.v2.JsonField in project atlasmap by atlasmap.

the class JsonFieldWriterTest method testWriteHighlyComplexObject.

@Test
@Ignore
public // with nested arrays.
void testWriteHighlyComplexObject() throws Exception {
    JsonComplexType items = JsonComplexTypeFactory.createJsonComlexField();
    items.setPath("/items");
    items.setJsonFields(new JsonFields());
    write(items);
    JsonComplexType item = JsonComplexTypeFactory.createJsonComlexField();
    item.setJsonFields(new JsonFields());
    item.setPath("/items/item");
    item.setCollectionType(CollectionType.LIST);
    items.getJsonFields().getJsonField().add(item);
    write(item);
    JsonField itemid = new JsonField();
    itemid.setPath("/items/item/id");
    itemid.setValue("0001");
    itemid.setFieldType(FieldType.STRING);
    itemid.setStatus(FieldStatus.SUPPORTED);
    item.getJsonFields().getJsonField().add(itemid);
    write(itemid);
    JsonField type = new JsonField();
    type.setPath("/items/item/type");
    type.setValue("donut");
    type.setFieldType(FieldType.STRING);
    type.setStatus(FieldStatus.SUPPORTED);
    item.getJsonFields().getJsonField().add(type);
    write(type);
    JsonField name = new JsonField();
    name.setPath("/items/item/name");
    name.setValue("Cake");
    name.setFieldType(FieldType.STRING);
    name.setStatus(FieldStatus.SUPPORTED);
    item.getJsonFields().getJsonField().add(name);
    write(name);
    JsonField ppu = new JsonField();
    ppu.setPath("/items/item/ppu");
    ppu.setValue(0.55);
    ppu.setFieldType(FieldType.DOUBLE);
    ppu.setStatus(FieldStatus.SUPPORTED);
    item.getJsonFields().getJsonField().add(ppu);
    write(ppu);
    JsonComplexType batters = JsonComplexTypeFactory.createJsonComlexField();
    batters.setJsonFields(new JsonFields());
    batters.setPath("/items/item/batters");
    items.getJsonFields().getJsonField().add(batters);
    write(batters);
    JsonComplexType batter = JsonComplexTypeFactory.createJsonComlexField();
    batter.setPath("/items/item/batters/batter");
    batter.setJsonFields(new JsonFields());
    batter.setStatus(FieldStatus.SUPPORTED);
    batter.setCollectionType(CollectionType.LIST);
    batters.getJsonFields().getJsonField().add(batter);
    write(batter);
    JsonField batter1Id = new JsonField();
    batter1Id.setPath("/items/item/batters/batter/id");
    batter1Id.setValue("1001");
    batter1Id.setFieldType(FieldType.STRING);
    batter1Id.setStatus(FieldStatus.SUPPORTED);
    batter.getJsonFields().getJsonField().add(batter1Id);
    write(batter1Id);
    JsonField batter1Type = new JsonField();
    batter1Type.setPath("/items/item/batters/batter/type");
    batter1Type.setValue("Regular");
    batter1Type.setFieldType(FieldType.STRING);
    batter1Type.setStatus(FieldStatus.SUPPORTED);
    batter.getJsonFields().getJsonField().add(batter1Type);
    write(batter1Type);
    JsonField batter2Id = new JsonField();
    batter2Id.setPath("/items/item/batters/batter[1]/id");
    batter2Id.setValue("1002");
    batter2Id.setFieldType(FieldType.STRING);
    batter2Id.setStatus(FieldStatus.SUPPORTED);
    batter.getJsonFields().getJsonField().add(batter2Id);
    write(batter2Id);
    JsonField batter2Type = new JsonField();
    batter2Type.setPath("/items/item/batters/batter[1]/type");
    batter2Type.setValue("Chocolate");
    batter2Type.setFieldType(FieldType.STRING);
    batter2Type.setStatus(FieldStatus.SUPPORTED);
    batter.getJsonFields().getJsonField().add(batter2Type);
    write(batter2Type);
    JsonField batter3Id = new JsonField();
    batter3Id.setPath("/items/item/batters/batter[2]/id");
    batter3Id.setValue("1003");
    batter3Id.setFieldType(FieldType.STRING);
    batter3Id.setStatus(FieldStatus.SUPPORTED);
    batter.getJsonFields().getJsonField().add(batter3Id);
    write(batter3Id);
    JsonField batter3Type = new JsonField();
    batter3Type.setPath("/items/item/batters/batter[2]/type");
    batter3Type.setValue("Blueberry");
    batter3Type.setFieldType(FieldType.STRING);
    batter3Type.setStatus(FieldStatus.SUPPORTED);
    batter.getJsonFields().getJsonField().add(batter3Type);
    write(batter3Type);
    JsonField batter4Id = new JsonField();
    batter4Id.setPath("/items/item/batters/batter[3]/id");
    batter4Id.setValue("1004");
    batter4Id.setFieldType(FieldType.STRING);
    batter4Id.setStatus(FieldStatus.SUPPORTED);
    batter.getJsonFields().getJsonField().add(batter4Id);
    write(batter4Id);
    JsonField batter4Type = new JsonField();
    batter4Type.setPath("/items/item/batters/batter[3]/type");
    batter4Type.setValue("Devil's Food");
    batter4Type.setFieldType(FieldType.STRING);
    batter4Type.setStatus(FieldStatus.SUPPORTED);
    batter.getJsonFields().getJsonField().add(batter4Type);
    write(batter4Type);
    JsonComplexType topping = JsonComplexTypeFactory.createJsonComlexField();
    topping.setJsonFields(new JsonFields());
    topping.setPath("/items/item/topping");
    topping.setCollectionType(CollectionType.ARRAY);
    items.getJsonFields().getJsonField().add(topping);
    write(topping);
    JsonField topping1Id = new JsonField();
    topping1Id.setPath("/items/item/topping/id");
    topping1Id.setValue("5001");
    topping1Id.setFieldType(FieldType.STRING);
    topping1Id.setStatus(FieldStatus.SUPPORTED);
    topping.getJsonFields().getJsonField().add(topping1Id);
    write(topping1Id);
    JsonField topping1Type = new JsonField();
    topping1Type.setPath("/items/item/topping/type");
    topping1Type.setValue("None");
    topping1Type.setFieldType(FieldType.STRING);
    topping1Type.setStatus(FieldStatus.SUPPORTED);
    topping.getJsonFields().getJsonField().add(topping1Type);
    write(topping1Type);
    JsonField topping2Id = new JsonField();
    topping2Id.setPath("/items/item/topping/id[1]");
    topping2Id.setValue("5002");
    topping2Id.setFieldType(FieldType.STRING);
    topping2Id.setStatus(FieldStatus.SUPPORTED);
    topping.getJsonFields().getJsonField().add(topping2Id);
    write(topping2Id);
    JsonField topping2Type = new JsonField();
    topping2Type.setPath("/items/item/topping/type[1]");
    topping2Type.setValue("Glazed");
    topping2Type.setFieldType(FieldType.STRING);
    topping2Type.setStatus(FieldStatus.SUPPORTED);
    topping.getJsonFields().getJsonField().add(topping2Type);
    write(topping2Type);
    JsonField topping3Id = new JsonField();
    topping3Id.setPath("/items/item/topping/id[2]");
    topping3Id.setValue("5005");
    topping3Id.setFieldType(FieldType.STRING);
    topping3Id.setStatus(FieldStatus.SUPPORTED);
    topping.getJsonFields().getJsonField().add(topping3Id);
    write(topping3Id);
    JsonField topping3Type = new JsonField();
    topping3Type.setPath("/items/item/topping/type[2]");
    topping3Type.setValue("Sugar");
    topping3Type.setFieldType(FieldType.STRING);
    topping3Type.setStatus(FieldStatus.SUPPORTED);
    topping.getJsonFields().getJsonField().add(topping3Type);
    write(topping3Type);
    JsonField topping4Id = new JsonField();
    topping4Id.setPath("/items/item/topping/id[3]");
    topping4Id.setValue("5007");
    topping4Id.setFieldType(FieldType.STRING);
    topping4Id.setStatus(FieldStatus.SUPPORTED);
    topping.getJsonFields().getJsonField().add(topping4Id);
    write(topping4Id);
    JsonField topping4Type = new JsonField();
    topping4Type.setPath("/items/item/topping/type[3]");
    topping4Type.setValue("Powdered Sugar");
    topping4Type.setFieldType(FieldType.STRING);
    topping4Type.setStatus(FieldStatus.SUPPORTED);
    topping.getJsonFields().getJsonField().add(topping4Type);
    write(topping4Type);
    JsonField topping5Id = new JsonField();
    topping5Id.setPath("/items/item/topping/id[4]");
    topping5Id.setValue("5006");
    topping5Id.setFieldType(FieldType.STRING);
    topping5Id.setStatus(FieldStatus.SUPPORTED);
    topping.getJsonFields().getJsonField().add(topping5Id);
    write(topping5Id);
    JsonField topping5Type = new JsonField();
    topping5Type.setPath("/items/item/topping/type[4]");
    topping5Type.setValue("Chocolate with Sprinkles");
    topping5Type.setFieldType(FieldType.STRING);
    topping5Type.setStatus(FieldStatus.SUPPORTED);
    topping.getJsonFields().getJsonField().add(topping5Type);
    write(topping5Type);
    JsonField topping6Id = new JsonField();
    topping6Id.setPath("/items/item/topping/id[5]");
    topping6Id.setValue("5003");
    topping6Id.setFieldType(FieldType.STRING);
    topping6Id.setStatus(FieldStatus.SUPPORTED);
    topping.getJsonFields().getJsonField().add(topping6Id);
    write(topping6Id);
    JsonField topping6Type = new JsonField();
    topping6Type.setPath("/items/item/topping/type[5]");
    topping6Type.setValue("Chocolate");
    topping6Type.setFieldType(FieldType.STRING);
    topping6Type.setStatus(FieldStatus.SUPPORTED);
    topping.getJsonFields().getJsonField().add(topping6Type);
    write(topping6Type);
    JsonField topping7Id = new JsonField();
    topping7Id.setPath("/items/item/topping/id[6]");
    topping7Id.setValue("5004");
    topping7Id.setFieldType(FieldType.STRING);
    topping7Id.setStatus(FieldStatus.SUPPORTED);
    topping.getJsonFields().getJsonField().add(topping7Id);
    write(topping7Id);
    JsonField topping7Type = new JsonField();
    topping7Type.setPath("/items/item/topping/type[6]");
    topping7Type.setValue("Maple");
    topping7Type.setFieldType(FieldType.STRING);
    topping7Type.setStatus(FieldStatus.SUPPORTED);
    topping.getJsonFields().getJsonField().add(topping7Type);
    write(topping7Type);
    // repeat complex
    JsonComplexType item1 = JsonComplexTypeFactory.createJsonComlexField();
    item1.setJsonFields(new JsonFields());
    item1.setPath("/items/item[1]");
    item1.setCollectionType(CollectionType.LIST);
    items.getJsonFields().getJsonField().add(item1);
    write(item1);
    JsonField itemId1 = new JsonField();
    itemId1.setPath("/items/item[1]/id");
    itemId1.setValue("0002");
    itemId1.setFieldType(FieldType.STRING);
    itemId1.setStatus(FieldStatus.SUPPORTED);
    item1.getJsonFields().getJsonField().add(itemId1);
    write(itemId1);
    JsonField type1 = new JsonField();
    type1.setPath("/items/item[1]/type");
    type1.setValue("donut");
    type1.setFieldType(FieldType.STRING);
    type1.setStatus(FieldStatus.SUPPORTED);
    item.getJsonFields().getJsonField().add(type1);
    write(type1);
    JsonField name1 = new JsonField();
    name1.setPath("/items/item[1]/name");
    name1.setValue("Raised");
    name1.setFieldType(FieldType.STRING);
    name1.setStatus(FieldStatus.SUPPORTED);
    item.getJsonFields().getJsonField().add(name1);
    write(name1);
    JsonField ppu2 = new JsonField();
    ppu2.setPath("/items/item[1]/ppu");
    ppu2.setValue(0.55);
    ppu2.setFieldType(FieldType.DOUBLE);
    ppu2.setStatus(FieldStatus.SUPPORTED);
    item.getJsonFields().getJsonField().add(ppu2);
    write(ppu2);
    JsonComplexType batters1 = JsonComplexTypeFactory.createJsonComlexField();
    batters1.setJsonFields(new JsonFields());
    batters1.setPath("/items/item[1]/batters");
    items.getJsonFields().getJsonField().add(batters1);
    write(batters1);
    JsonComplexType batter1 = JsonComplexTypeFactory.createJsonComlexField();
    batter1.setPath("/items/item[1]/batters/batter");
    batter1.setJsonFields(new JsonFields());
    batter1.setStatus(FieldStatus.SUPPORTED);
    batter1.setCollectionType(CollectionType.LIST);
    batters1.getJsonFields().getJsonField().add(batter1);
    write(batter1);
    // FIXME this writes to the items/item/batters/batter and not at
    // items/item[1]/batters/batter
    // JsonField batter1_1_id = new JsonField();
    // batter1_1_id.setPath("/items/item[1]/batters/batter/id");
    // batter1_1_id.setValue("1001");
    // batter1_1_id.setFieldType(FieldType.STRING);
    // batter1_1_id.setStatus(FieldStatus.SUPPORTED);
    // batter1.getJsonFields().getJsonField().add(batter1_1_id);
    // writer.write(batter1_1_id, root);
    // 
    // JsonField batter1_1_type = new JsonField();
    // batter1_1_type.setPath("/items/item[1]/batters/batter/type");
    // batter1_1_type.setValue("Regular");
    // batter1_1_type.setFieldType(FieldType.STRING);
    // batter1_1_type.setStatus(FieldStatus.SUPPORTED);
    // batter1.getJsonFields().getJsonField().add(batter1_1_type);
    // writer.write(batter1_1_type, root);
    System.out.println(prettyPrintJson(writer.getRootNode().toString()));
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) JsonFields(io.atlasmap.json.v2.JsonFields) JsonComplexType(io.atlasmap.json.v2.JsonComplexType) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 48 with JsonField

use of io.atlasmap.json.v2.JsonField in project atlasmap by atlasmap.

the class JsonFieldWriterTest method testWriteFlatPrimitiveObjectRooted.

@Test
public void testWriteFlatPrimitiveObjectRooted() throws Exception {
    JsonField booleanField = AtlasJsonModelFactory.createJsonField();
    booleanField.setFieldType(FieldType.BOOLEAN);
    booleanField.setValue(false);
    booleanField.setPath("/SourceFlatPrimitive/booleanField");
    booleanField.setStatus(FieldStatus.SUPPORTED);
    write(booleanField);
    JsonField charField = AtlasJsonModelFactory.createJsonField();
    charField.setFieldType(FieldType.CHAR);
    charField.setValue('a');
    charField.setPath("/SourceFlatPrimitive/charField");
    charField.setStatus(FieldStatus.SUPPORTED);
    write(charField);
    JsonField doubleField = AtlasJsonModelFactory.createJsonField();
    doubleField.setFieldType(FieldType.DOUBLE);
    doubleField.setValue(-27152745.3422);
    doubleField.setPath("/SourceFlatPrimitive/doubleField");
    doubleField.setStatus(FieldStatus.SUPPORTED);
    write(doubleField);
    JsonField floatField = AtlasJsonModelFactory.createJsonField();
    floatField.setFieldType(FieldType.FLOAT);
    floatField.setValue(-63988281.00);
    floatField.setPath("/SourceFlatPrimitive/floatField");
    floatField.setStatus(FieldStatus.SUPPORTED);
    write(floatField);
    JsonField intField = AtlasJsonModelFactory.createJsonField();
    intField.setFieldType(FieldType.INTEGER);
    intField.setValue(8281);
    intField.setPath("/SourceFlatPrimitive/intField");
    intField.setStatus(FieldStatus.SUPPORTED);
    write(intField);
    JsonField shortField = AtlasJsonModelFactory.createJsonField();
    shortField.setFieldType(FieldType.SHORT);
    shortField.setValue(81);
    shortField.setPath("/SourceFlatPrimitive/shortField");
    shortField.setStatus(FieldStatus.SUPPORTED);
    write(shortField);
    JsonField longField = AtlasJsonModelFactory.createJsonField();
    longField.setFieldType(FieldType.LONG);
    longField.setValue(3988281);
    longField.setPath("/SourceFlatPrimitive/longField");
    longField.setStatus(FieldStatus.SUPPORTED);
    write(longField);
    Assert.assertThat(writer.getRootNode().toString(), Is.is("{\"SourceFlatPrimitive\":{\"booleanField\":false,\"charField\":\"a\",\"doubleField\":-27152745.3422,\"floatField\":-63988281,\"intField\":8281,\"shortField\":81,\"longField\":3988281}}"));
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) Test(org.junit.Test)

Example 49 with JsonField

use of io.atlasmap.json.v2.JsonField in project atlasmap by atlasmap.

the class JsonValidationServiceTest method testValidateMappingInvalidCombineInputFieldType.

@Test
public void testValidateMappingInvalidCombineInputFieldType() {
    AtlasMapping atlasMapping = getAtlasMappingFullValid();
    Mapping combineFieldMapping = AtlasModelFactory.createMapping(MappingType.COMBINE);
    combineFieldMapping.setId("combine.firstName.lastName");
    JsonField bIJavaField = jsonModelFactory.createJsonField();
    bIJavaField.setFieldType(FieldType.STRING);
    bIJavaField.setValue(Boolean.TRUE);
    bIJavaField.setPath("firstName");
    combineFieldMapping.getInputField().add(bIJavaField);
    JsonField sOJavaField = jsonModelFactory.createJsonField();
    sOJavaField.setFieldType(FieldType.BOOLEAN);
    sOJavaField.setPath("lastName");
    sOJavaField.setIndex(0);
    combineFieldMapping.getOutputField().add(sOJavaField);
    atlasMapping.getMappings().getMapping().add(combineFieldMapping);
    validations.addAll(sourceValidationService.validateMapping(atlasMapping));
    validations.addAll(targetValidationService.validateMapping(atlasMapping));
    assertTrue(validationHelper.hasErrors());
    assertFalse(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
    assertEquals(new Integer(1), new Integer(validationHelper.getCount()));
    Validation validation = validations.get(0);
    assertNotNull(validation);
    assertEquals(ValidationScope.MAPPING, validation.getScope());
    assertEquals("combine.firstName.lastName", validation.getId());
    assertEquals("Output field 'lastName' must be of type 'STRING' for a Combine Mapping", validation.getMessage());
    assertEquals(ValidationStatus.ERROR, validation.getStatus());
}
Also used : Validation(io.atlasmap.v2.Validation) JsonField(io.atlasmap.json.v2.JsonField) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 50 with JsonField

use of io.atlasmap.json.v2.JsonField in project atlasmap by atlasmap.

the class SchemaInspectorTest method inspectJsonSchemaSimpleArray.

@Test
public void inspectJsonSchemaSimpleArray() throws Exception {
    final String schema = "{\"$schema\": \"http://json-schema.org/\"," + " \"type\": \"array\"," + " \"items\": { \"type\": \"integer\"}}";
    JsonDocument document = inspectionService.inspectJsonSchema(schema);
    assertNotNull(document);
    assertEquals(1, document.getFields().getField().size());
    JsonField jsonField = (JsonField) document.getFields().getField().get(0);
    assertEquals(FieldStatus.UNSUPPORTED, jsonField.getStatus());
    assertEquals(CollectionType.LIST, jsonField.getCollectionType());
    assertEquals(FieldType.INTEGER, jsonField.getFieldType());
    assertNull(jsonField.getName());
    assertNull(jsonField.getPath());
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.Test)

Aggregations

JsonField (io.atlasmap.json.v2.JsonField)63 Test (org.junit.Test)45 JsonDocument (io.atlasmap.json.v2.JsonDocument)30 JsonComplexType (io.atlasmap.json.v2.JsonComplexType)15 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)10 Head (io.atlasmap.spi.AtlasInternalSession.Head)8 AtlasMapping (io.atlasmap.v2.AtlasMapping)7 Mapping (io.atlasmap.v2.Mapping)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Field (io.atlasmap.v2.Field)4 Validation (io.atlasmap.v2.Validation)4 AtlasMappingUtil (io.atlasmap.core.AtlasMappingUtil)2 DefaultAtlasConversionService (io.atlasmap.core.DefaultAtlasConversionService)2 AtlasJsonModelFactory (io.atlasmap.json.v2.AtlasJsonModelFactory)2 AtlasModuleDetail (io.atlasmap.spi.AtlasModuleDetail)2 AtlasModuleMode (io.atlasmap.spi.AtlasModuleMode)2 AtlasModelFactory (io.atlasmap.v2.AtlasModelFactory)2 DataSource (io.atlasmap.v2.DataSource)2 DataSourceType (io.atlasmap.v2.DataSourceType)2 FieldType (io.atlasmap.v2.FieldType)2