Search in sources :

Example 56 with Field

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

the class JavaFieldReaderTest method testReadTopmostArrayComplex.

@Test
public void testReadTopmostArrayComplex() throws Exception {
    TargetTestClass[] complexArray = new TargetTestClass[] { new TargetTestClass(), new TargetTestClass(), new TargetTestClass() };
    complexArray[0].setAddress(new TargetAddress());
    complexArray[0].getAddress().setAddressLine1("123 any street");
    complexArray[2].setAddress(new TargetAddress());
    complexArray[2].getAddress().setAddressLine1("1234 any street");
    reader.setDocument(complexArray);
    read("/[0]/address/addressLine1", FieldType.STRING);
    assertEquals(0, audits.size());
    assertEquals("123 any street", field.getValue());
    assertEquals(0, audits.size());
    readGroup("/[]/address/addressLine1", FieldType.STRING);
    assertEquals(0, audits.size());
    assertNotNull(fieldGroup);
    assertEquals(2, fieldGroup.getField().size());
    Field f = fieldGroup.getField().get(0);
    assertEquals("/[0]/address/addressLine1", f.getPath());
    assertEquals("123 any street", f.getValue());
    f = fieldGroup.getField().get(1);
    assertEquals("/[2]/address/addressLine1", f.getPath());
    assertEquals("1234 any street", f.getValue());
    assertEquals(0, audits.size());
}
Also used : Field(io.atlasmap.v2.Field) JavaField(io.atlasmap.java.v2.JavaField) TargetAddress(io.atlasmap.java.test.TargetAddress) TargetTestClass(io.atlasmap.java.test.TargetTestClass) Test(org.junit.jupiter.api.Test)

Example 57 with Field

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

the class JavaFieldReaderTest method testReadParent.

@Test
public void testReadParent() throws Exception {
    TargetTestClass source = new TargetTestClass();
    LinkedList<TargetContact> contactList = new LinkedList<>();
    for (int i = 0; i < 5; i++) {
        TargetContact c = new TargetContact();
        c.setFirstName("f" + i);
        c.setLastName("l" + i);
        c.setPhoneNumber("p" + i);
        c.setZipCode("z" + i);
        contactList.add(c);
    }
    source.setContactList(contactList);
    reader.setDocument(source);
    FieldGroup contactListGroup = new FieldGroup();
    contactListGroup.setDocId("TargetTestClass");
    contactListGroup.setPath("/contactList<>");
    contactListGroup.setFieldType(FieldType.COMPLEX);
    contactListGroup.setCollectionType(CollectionType.LIST);
    Field firstNameField = new JavaField();
    firstNameField.setDocId("TargetTestClass");
    firstNameField.setPath("/contactList<>/firstName");
    firstNameField.setFieldType(FieldType.STRING);
    contactListGroup.getField().add(firstNameField);
    fieldGroup = (FieldGroup) read(contactListGroup);
    assertEquals(0, audits.size());
    assertEquals("/contactList<>", fieldGroup.getPath());
    assertEquals(FieldType.COMPLEX, fieldGroup.getFieldType());
    assertEquals(CollectionType.LIST, fieldGroup.getCollectionType());
    assertEquals(5, fieldGroup.getField().size());
    Field contact0 = fieldGroup.getField().get(0);
    assertEquals(FieldGroup.class, contact0.getClass());
    FieldGroup contact0Group = (FieldGroup) contact0;
    assertEquals(1, contact0Group.getField().size());
    assertEquals("/contactList<0>", contact0Group.getPath());
    assertEquals(FieldType.COMPLEX, contact0Group.getFieldType());
    Field firstName0 = contact0Group.getField().get(0);
    assertEquals("/contactList<0>/firstName", firstName0.getPath());
    assertEquals(FieldType.STRING, firstName0.getFieldType());
    assertEquals("f0", firstName0.getValue());
    contactListGroup.setPath("/contactList<1>");
    firstNameField.setPath("/contactList<1>/firstName");
    fieldGroup = (FieldGroup) read(contactListGroup);
    assertEquals(0, audits.size());
    assertEquals(1, fieldGroup.getField().size());
    Field firstName1 = fieldGroup.getField().get(0);
    assertEquals("/contactList<1>/firstName", firstName1.getPath());
    assertEquals(FieldType.STRING, firstName1.getFieldType());
    assertEquals("f1", firstName1.getValue());
}
Also used : Field(io.atlasmap.v2.Field) JavaField(io.atlasmap.java.v2.JavaField) JavaField(io.atlasmap.java.v2.JavaField) FieldGroup(io.atlasmap.v2.FieldGroup) TargetContact(io.atlasmap.java.test.TargetContact) TargetTestClass(io.atlasmap.java.test.TargetTestClass) LinkedList(java.util.LinkedList) Test(org.junit.jupiter.api.Test)

Example 58 with Field

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

the class BaseJavaFieldWriterTest method write.

protected void write(String path, int targetValue) throws AtlasException {
    Field field = createIntField(path, targetValue);
    write(field);
}
Also used : Field(io.atlasmap.v2.Field) JavaEnumField(io.atlasmap.java.v2.JavaEnumField) JavaField(io.atlasmap.java.v2.JavaField)

Example 59 with Field

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

the class BaseJavaFieldWriterTest method writeComplex.

protected void writeComplex(String path, Object targetValue) throws AtlasException {
    Field field = createField(path, targetValue, FieldType.COMPLEX);
    write(field);
}
Also used : Field(io.atlasmap.v2.Field) JavaEnumField(io.atlasmap.java.v2.JavaEnumField) JavaField(io.atlasmap.java.v2.JavaField)

Example 60 with Field

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

the class JavaFieldWriter method commitWriting.

/**
 * Commits queued write tasks.
 * @param session session
 * @throws AtlasException unexpected error
 */
public void commitWriting(AtlasInternalSession session) throws AtlasException {
    Field targetField = session.head().getTargetField();
    try {
        if (targetField instanceof FieldGroup) {
            FieldGroup targetFieldGroup = (FieldGroup) targetField;
            if (targetFieldGroup.getField().size() > 0) {
                for (Field f : targetFieldGroup.getField()) {
                    session.head().setTargetField(f);
                    doCommitWriting(session);
                }
            } else {
                AtlasPath path = new AtlasPath(targetField.getPath());
                if (path.getLastSegment().getCollectionType() != CollectionType.NONE) {
                    // create an empty collection
                    doCommitWriting(session);
                }
            }
            return;
        }
        doCommitWriting(session);
    } finally {
        if (!this.pathParentQueue.isEmpty()) {
            LOG.warn("Discarding uncommitted entry in the queue: {}", this.pathParentQueue);
            this.pathParentQueue.clear();
        }
    }
}
Also used : JavaEnumField(io.atlasmap.java.v2.JavaEnumField) Field(io.atlasmap.v2.Field) JavaField(io.atlasmap.java.v2.JavaField) FieldGroup(io.atlasmap.v2.FieldGroup) AtlasPath(io.atlasmap.core.AtlasPath)

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