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());
}
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());
}
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);
}
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);
}
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();
}
}
}
Aggregations