use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.
the class AtlasPath method setCollectionIndexRecursively.
/**
* Sets the collection indexes recursively, which includes modifying path of the subsequent children.
* @param group parent field
* @param segmentIndex target segment index
* @param index index to set
*/
public static void setCollectionIndexRecursively(FieldGroup group, int segmentIndex, int index) {
AtlasPath path = new AtlasPath(group.getPath());
path.setCollectionIndex(segmentIndex, index);
group.setPath(path.toString());
for (Field f : group.getField()) {
if (f instanceof FieldGroup) {
setCollectionIndexRecursively((FieldGroup) f, segmentIndex, index);
} else {
AtlasPath fpath = new AtlasPath(f.getPath());
fpath.setCollectionIndex(segmentIndex, index);
f.setPath(fpath.toString());
}
}
}
use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.
the class DefaultAtlasValidationService method validateMapMapping.
private void validateMapMapping(List<Mapping> fieldMappings, List<Validation> validations, Set<String> usedIds) {
for (Mapping fieldMapping : fieldMappings) {
String mappingId = fieldMapping.getId();
FieldGroup sourceFieldGroup = fieldMapping.getInputFieldGroup();
List<Field> sourceFields = sourceFieldGroup != null ? sourceFieldGroup.getField() : fieldMapping.getInputField();
validateMappingId(mappingId, usedIds, validations);
Validators.MAP_INPUT_NOT_NULL.get().validate(sourceFields, validations, mappingId);
if (fieldMapping.getInputField() != null) {
Validators.MAP_INPUT_FIELD_NOT_EMPTY.get().validate(sourceFields, validations, mappingId);
}
Validators.MAP_OUTPUT_NOT_NULL.get().validate(fieldMapping.getOutputField(), validations, mappingId, ValidationStatus.WARN);
if (fieldMapping.getOutputField() != null) {
Validators.MAP_OUTPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getOutputField(), validations, mappingId, ValidationStatus.WARN);
}
}
}
use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.
the class DefaultAtlasValidationService method validateSeparateMapping.
private void validateSeparateMapping(List<Mapping> fieldMappings, List<Validation> validations, Set<String> usedIds) {
for (Mapping fieldMapping : fieldMappings) {
String mappingId = fieldMapping.getId();
validateMappingId(mappingId, usedIds, validations);
Validators.SEPARATE_INPUT_NOT_NULL.get().validate(fieldMapping.getInputField(), validations, mappingId);
if (fieldMapping.getInputField() != null) {
Validators.SEPARATE_INPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getInputField(), validations, mappingId);
// source must be a String type
}
Validators.SEPARATE_OUTPUT_NOT_NULL.get().validate(fieldMapping.getOutputField(), validations, mappingId, ValidationStatus.WARN);
Validators.SEPARATE_OUTPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getOutputField(), validations, mappingId, ValidationStatus.WARN);
if (fieldMapping.getOutputField() != null) {
for (Field field : fieldMapping.getOutputField()) {
Validators.SEPARATE_OUTPUT_FIELD_NOT_NULL.get().validate(field, validations, mappingId);
if (field.getIndex() == null || field.getIndex() < 0) {
Validators.SEPARATE_OUTPUT_FIELD_FIELD_ACTION_INDEX_POSITIVE.get().validate(field.getIndex(), validations, mappingId);
}
}
}
}
}
use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.
the class JsonModule method writeTargetValue.
@Override
public void writeTargetValue(AtlasInternalSession session) throws AtlasException {
JsonFieldWriter writer = session.getFieldWriter(getDocId(), JsonFieldWriter.class);
if (session.head().getTargetField() instanceof FieldGroup) {
FieldGroup targetFieldGroup = (FieldGroup) session.head().getTargetField();
if (targetFieldGroup.getField().size() > 0) {
for (Field f : targetFieldGroup.getField()) {
session.head().setTargetField(f);
writer.write(session);
}
return;
}
}
writer.write(session);
}
use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.
the class JsonModule method populateTargetField.
@Override
public void populateTargetField(AtlasInternalSession session) throws AtlasException {
Field sourceField = session.head().getSourceField();
Field targetField = session.head().getTargetField();
AtlasPath path = new AtlasPath(targetField.getPath());
FieldGroup targetFieldGroup = null;
if (path.hasCollection() && !path.isIndexedCollection()) {
targetFieldGroup = AtlasModelFactory.createFieldGroupFrom(targetField, true);
session.head().setTargetField(targetFieldGroup);
}
// Attempt to Auto-detect field type based on input value
if (targetField.getFieldType() == null && sourceField.getValue() != null) {
targetField.setFieldType(getConversionService().fieldTypeFromClass(sourceField.getValue().getClass()));
}
if (targetFieldGroup == null) {
if (sourceField instanceof FieldGroup) {
List<Field> subFields = ((FieldGroup) sourceField).getField();
if (subFields != null && subFields.size() > 0) {
Integer index = targetField.getIndex();
if (index != null) {
if (subFields.size() > index) {
sourceField = subFields.get(index);
} else {
AtlasUtil.addAudit(session, getDocId(), String.format("The number of source fields (%s) is smaller than target index (%s) - ignoring", subFields.size(), index), AuditStatus.WARN, null);
return;
}
} else {
// The last one wins for compatibility
sourceField = subFields.get(subFields.size() - 1);
}
session.head().setSourceField(sourceField);
}
}
super.populateTargetField(session);
} else if (sourceField instanceof FieldGroup) {
Field previousTargetSubField = null;
for (int i = 0; i < ((FieldGroup) sourceField).getField().size(); i++) {
Field sourceSubField = ((FieldGroup) sourceField).getField().get(i);
JsonField targetSubField = new JsonField();
AtlasJsonModelFactory.copyField(targetField, targetSubField, false);
getCollectionHelper().copyCollectionIndexes(sourceField, sourceSubField, targetSubField, previousTargetSubField);
previousTargetSubField = targetSubField;
targetFieldGroup.getField().add(targetSubField);
session.head().setSourceField(sourceSubField);
session.head().setTargetField(targetSubField);
super.populateTargetField(session);
}
session.head().setSourceField(sourceField);
session.head().setTargetField(targetFieldGroup);
} else {
JsonField targetSubField = new JsonField();
AtlasJsonModelFactory.copyField(targetField, targetSubField, false);
path.setVacantCollectionIndex(0);
targetSubField.setPath(path.toString());
targetFieldGroup.getField().add(targetSubField);
session.head().setTargetField(targetSubField);
super.populateTargetField(session);
session.head().setTargetField(targetFieldGroup);
}
if (LOG.isDebugEnabled()) {
LOG.debug("{}: processTargetFieldMapping completed: SourceField:[docId={}, path={}, type={}, value={}], TargetField:[docId={}, path={}, type={}, value={}]", getDocId(), sourceField.getDocId(), sourceField.getPath(), sourceField.getFieldType(), sourceField.getValue(), targetField.getDocId(), targetField.getPath(), targetField.getFieldType(), targetField.getValue());
}
}
Aggregations