Search in sources :

Example 96 with Field

use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.

the class AtlasJsonModelFactory method cloneFieldGroup.

/**
 * Clones the FieldGroup.
 * @param group FieldGroup
 * @return cloned
 */
public static FieldGroup cloneFieldGroup(FieldGroup group) {
    FieldGroup clone = AtlasModelFactory.copyFieldGroup(group);
    List<Field> newChildren = new ArrayList<>();
    for (Field child : group.getField()) {
        if (child instanceof FieldGroup) {
            newChildren.add(cloneFieldGroup((FieldGroup) child));
        } else {
            newChildren.add(cloneField((JsonField) child, true));
        }
    }
    clone.getField().addAll(newChildren);
    return clone;
}
Also used : Field(io.atlasmap.v2.Field) FieldGroup(io.atlasmap.v2.FieldGroup) ArrayList(java.util.ArrayList)

Example 97 with Field

use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.

the class JsonFieldReaderTest method testJsonFieldTopmostArrayObject.

@Test
public void testJsonFieldTopmostArrayObject() throws Exception {
    final String document = "[\n" + "\t{\n" + "\t\t\"color\": \"red\",\n" + "\t\t\"value\": \"#f00\"\n" + "\t},\n" + "\t{\n" + "\t\t\"color\": \"green\",\n" + "\t\t\"value\": \"#0f0\"\n" + "\t},\n" + "\t{\n" + "\t\t\"color\": \"blue\",\n" + "\t\t\"value\": \"#00f\"\n" + "\t}]";
    reader.setDocument(document);
    JsonField field = AtlasJsonModelFactory.createJsonField();
    field.setPath("/<0>/color");
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(field);
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("red", field.getValue());
    field.setPath("/<1>/value");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("#0f0", field.getValue());
    field.setFieldType(null);
    field.setPath("/<>/color");
    Field readField = reader.read(session);
    assertEquals(FieldGroup.class, readField.getClass());
    FieldGroup readFieldGroup = (FieldGroup) readField;
    assertEquals(3, readFieldGroup.getField().size());
    assertEquals("red", readFieldGroup.getField().get(0).getValue());
    assertEquals("green", readFieldGroup.getField().get(1).getValue());
    assertEquals("blue", readFieldGroup.getField().get(2).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 98 with Field

use of com.google.firestore.admin.v1.Field 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 99 with Field

use of com.google.firestore.admin.v1.Field 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 100 with Field

use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.

the class KafkaConnectFieldWriter method write.

@Override
public void write(AtlasInternalSession session) throws AtlasException {
    if (this.schema == null) {
        throw new AtlasException("Kafka Connect schema must be set to write Kafka Connect object");
    }
    Field targetField = session.head().getTargetField();
    if (targetField == null) {
        throw new AtlasException(new IllegalArgumentException("Target field cannot be null"));
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Field: " + AtlasModelFactory.toString(targetField));
        LOG.debug("Field type=" + targetField.getFieldType() + " path=" + targetField.getPath() + " v=" + targetField.getValue());
    }
    AtlasPath path = new AtlasPath(targetField.getPath());
    this.root = writeSegment(path, 0, root, schema, targetField);
}
Also used : Field(io.atlasmap.v2.Field) AtlasPath(io.atlasmap.core.AtlasPath) AtlasException(io.atlasmap.api.AtlasException)

Aggregations

Field (io.atlasmap.v2.Field)221 FieldGroup (io.atlasmap.v2.FieldGroup)86 Test (org.junit.jupiter.api.Test)67 SimpleField (io.atlasmap.v2.SimpleField)62 Field (org.apache.tapestry5.Field)46 JavaField (io.atlasmap.java.v2.JavaField)45 ArrayList (java.util.ArrayList)42 Mapping (io.atlasmap.v2.Mapping)39 Test (org.testng.annotations.Test)39 AtlasPath (io.atlasmap.core.AtlasPath)29 ConstantField (io.atlasmap.v2.ConstantField)29 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)26 AtlasException (io.atlasmap.api.AtlasException)25 JsonField (io.atlasmap.json.v2.JsonField)25 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)25 PropertyField (io.atlasmap.v2.PropertyField)22 AtlasMapping (io.atlasmap.v2.AtlasMapping)21 KafkaConnectField (io.atlasmap.kafkaconnect.v2.KafkaConnectField)19 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)19 Head (io.atlasmap.spi.AtlasInternalSession.Head)18