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