use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.
the class AtlasModuleSupportTest method testListTargetPathsListOfBaseMapping.
@Test
public void testListTargetPathsListOfBaseMapping() {
List<BaseMapping> mappings = null;
assertEquals(0, AtlasModuleSupport.listTargetPaths(mappings).size());
mappings = new ArrayList<>();
assertEquals(0, AtlasModuleSupport.listTargetPaths(mappings).size());
Mapping mapping = new Mapping();
Field field = new MockField();
field.setPath("MockPath");
mapping.getOutputField().add(field);
mappings.add(mapping);
assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
Collection collection = null;
mappings.add(collection);
assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
collection = new Collection();
mappings.add(collection);
assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
Mappings mapings = new Mappings();
collection.setMappings(mapings);
assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
}
use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.
the class DocumentJavaFieldReader method read.
@Override
public void read(AtlasInternalSession session) throws AtlasException {
try {
Field sourceField = session.head().getSourceField();
Method getter = null;
if (sourceField.getFieldType() == null && (sourceField instanceof JavaField || sourceField instanceof JavaEnumField)) {
getter = resolveGetMethod(sourceDocument, sourceField);
if (getter == null) {
AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Unable to auto-detect sourceField type path=%s docId=%s", sourceField.getPath(), sourceField.getDocId()), sourceField.getPath(), AuditStatus.WARN, null);
return;
}
Class<?> returnType = getter.getReturnType();
sourceField.setFieldType(conversionService.fieldTypeFromClass(returnType));
if (LOG.isTraceEnabled()) {
LOG.trace("Auto-detected sourceField type p=" + sourceField.getPath() + " t=" + sourceField.getFieldType());
}
}
populateSourceFieldValue(session, sourceField, sourceDocument, getter);
if (LOG.isDebugEnabled()) {
LOG.debug("Processed input field sPath=" + sourceField.getPath() + " sV=" + sourceField.getValue() + " sT=" + sourceField.getFieldType() + " docId: " + sourceField.getDocId());
}
} catch (Exception e) {
throw new AtlasException(e);
}
}
use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.
the class BaseDocumentWriterTest method write.
protected void write(String path, StateEnumClassLong targetValue) throws AtlasException {
Field field = createEnumField(path, targetValue);
setTargetValue(targetValue);
write(field);
}
use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.
the class JavaFieldReader method read.
@Override
public Field read(AtlasInternalSession session) throws AtlasException {
try {
Field field = session.head().getSourceField();
if (sourceDocument == null) {
AtlasUtil.addAudit(session, field, String.format("Unable to read sourceField (path=%s), document (docId=%s) is null", field.getPath(), field.getDocId()), AuditStatus.ERROR, null);
}
AtlasPath path = new AtlasPath(field.getPath());
List<Field> fields = getFieldsForPath(session, sourceDocument, field, path, 0);
if (LOG.isDebugEnabled()) {
LOG.debug("Processed input field sPath=" + field.getPath() + " sV=" + field.getValue() + " sT=" + field.getFieldType() + " docId: " + field.getDocId());
}
if (path.hasCollection() && !path.isIndexedCollection()) {
FieldGroup fieldGroup = AtlasModelFactory.createFieldGroupFrom(field, true);
fieldGroup.getField().addAll(fields);
session.head().setSourceField(fieldGroup);
return fieldGroup;
} else if (fields.size() == 1) {
field.setValue(fields.get(0).getValue());
return field;
} else {
return field;
}
} catch (Exception e) {
throw new AtlasException(e);
}
}
use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.
the class JavaFieldReader method populateCollectionItems.
private FieldGroup populateCollectionItems(JavaChildAccessor accessor, Field field) throws AtlasException {
if (accessor == null || accessor.getCollectionType() == CollectionType.NONE) {
throw new AtlasException(String.format("Couldn't find a collection object for field %s:%s", field.getDocId(), field.getPath()));
}
FieldGroup group = field instanceof FieldGroup ? (FieldGroup) field : AtlasModelFactory.createFieldGroupFrom(field, true);
for (int i = 0; i < accessor.getCollectionValues().size(); i++) {
AtlasPath itemPath = new AtlasPath(group.getPath());
List<SegmentContext> segments = itemPath.getSegments(true);
itemPath.setCollectionIndex(segments.size() - 1, i);
if (field instanceof FieldGroup) {
FieldGroup itemGroup = AtlasJavaModelFactory.cloneFieldGroup((FieldGroup) field);
AtlasPath.setCollectionIndexRecursively(itemGroup, segments.size(), i);
populateChildFields(accessor.getValueAt(i), itemGroup, itemPath);
group.getField().add(itemGroup);
} else {
Field itemField = AtlasJavaModelFactory.cloneJavaField(field, false);
itemField.setPath(itemPath.toString());
itemField.setValue(accessor.getValueAt(i));
group.getField().add(itemField);
}
}
return group;
}
Aggregations