use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.
the class DefaultAtlasValidationService method validateCombineMapping.
private void validateCombineMapping(List<Mapping> fieldMappings, List<Validation> validations, Set<String> usedIds) {
for (Mapping fieldMapping : fieldMappings) {
String mappingId = fieldMapping.getId();
validateMappingId(mappingId, usedIds, validations);
Validators.COMBINE_OUTPUT_NOT_NULL.get().validate(fieldMapping.getOutputField(), validations, mappingId);
if (fieldMapping.getOutputField() != null) {
Validators.COMBINE_OUTPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getOutputField(), validations, mappingId);
// source must be a String type
}
Validators.COMBINE_INPUT_NOT_NULL.get().validate(fieldMapping.getInputField(), validations, mappingId, ValidationStatus.WARN);
Validators.COMBINE_INPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getInputField(), validations, mappingId, ValidationStatus.WARN);
if (fieldMapping.getInputField() != null) {
for (Field field : fieldMapping.getInputField()) {
Validators.COMBINE_INPUT_FIELD_NOT_NULL.get().validate(field, validations, mappingId);
if (field.getIndex() == null || field.getIndex() < 0) {
Validators.COMBINE_INPUT_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 BaseModuleValidationService method validateMapMapping.
/**
* Validates MAP mapping.
* @param mapping mapping
* @param validations a container to put the result validations
*/
protected void validateMapMapping(Mapping mapping, List<Validation> validations) {
if (mapping == null || mapping.getInputField() == null || (mapping.getInputFieldGroup() == null && mapping.getInputField().size() <= 0) || mapping.getOutputField() == null || mapping.getOutputField().size() <= 0) {
return;
}
String mappingId = mapping.getId();
if (getMode() == AtlasModuleMode.SOURCE) {
FieldGroup sourceFieldGroup = mapping.getInputFieldGroup();
if (sourceFieldGroup != null) {
validateFieldGroup(mappingId, sourceFieldGroup, FieldDirection.SOURCE, validations);
} else {
List<Field> sourceFields = mapping.getInputField();
sourceFields.forEach(sourceField -> {
validateField(mappingId, null, sourceField, FieldDirection.SOURCE, validations);
});
}
} else if (getMode() == AtlasModuleMode.TARGET) {
List<Field> targetFields = mapping.getOutputField();
if (targetFields.size() == 1 && Integer.valueOf(0).equals(targetFields.get(0).getIndex())) {
// The index should not have been set as there's only one item
targetFields.get(0).setIndex(null);
}
int i = 0;
List<Field> sourceFields = mapping.getInputField();
for (Field targetField : targetFields) {
if (sourceFields.size() > i) {
validateField(mappingId, sourceFields.get(i), targetField, FieldDirection.TARGET, validations);
} else {
validateField(mappingId, null, targetField, FieldDirection.TARGET, validations);
}
i++;
}
}
if (getMode() == AtlasModuleMode.SOURCE) {
validateFieldCombinations(mapping, validations);
}
}
use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.
the class BaseModuleValidationService method validateSeparateMapping.
/**
* Validates separate mapping.
* @deprecated
* @param mapping mapping
* @param validations a container to put the result validations
*/
@Deprecated
protected void validateSeparateMapping(Mapping mapping, List<Validation> validations) {
if (mapping == null) {
return;
}
final List<Field> sourceFields = mapping.getInputField();
final Field sourceField = (sourceFields != null && !sourceFields.isEmpty()) ? sourceFields.get(0) : null;
if (sourceField == null) {
return;
}
List<Field> targetFields = mapping.getOutputField();
String mappingId = mapping.getId();
if (getMode() == AtlasModuleMode.SOURCE && matchDocIdOrNull(sourceField.getDocId())) {
// check that the source field is of type String else error
if (sourceField.getFieldType() != null && sourceField.getFieldType() != FieldType.STRING) {
Validation validation = new Validation();
validation.setScope(ValidationScope.MAPPING);
validation.setId(mapping.getId());
validation.setMessage(String.format("Source field '%s' must be of type '%s' for a Separate Mapping", getFieldName(sourceField), FieldType.STRING));
validation.setStatus(ValidationStatus.ERROR);
validations.add(validation);
}
validateField(mappingId, null, sourceField, FieldDirection.SOURCE, validations);
if (targetFields != null) {
// we should convert per module validations to plugin style
for (Field targetField : targetFields) {
mappingFieldPairValidator.validateFieldTypes(validations, mappingId, sourceField, targetField);
}
}
} else if (targetFields != null) {
// TARGET
for (Field targetField : targetFields) {
if (matchDocIdOrNull(targetField.getDocId())) {
validateField(mappingId, null, targetField, FieldDirection.TARGET, validations);
}
}
}
}
use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.
the class BaseModuleValidationService method validateFieldCombinations.
/**
* Validate the combination of source field(s) and target field(s).
* @param mapping mapping
* @param validations a container to put the result validations
*/
protected void validateFieldCombinations(Mapping mapping, List<Validation> validations) {
String mappingId = mapping.getId();
FieldGroup sourceFieldGroup = mapping.getInputFieldGroup();
List<Field> sourceFields = mapping.getInputField();
List<Field> targetFields = mapping.getOutputField();
if (sourceFieldGroup != null || (sourceFields != null && sourceFields.size() > 1)) {
if (targetFields.size() > 1) {
Validation validation = new Validation();
validation.setScope(ValidationScope.MAPPING);
validation.setId(mappingId);
validation.setMessage("Multiple fields can not be selected on both of Source and Target");
validation.setStatus(ValidationStatus.ERROR);
validations.add(validation);
}
if (sourceFieldGroup != null) {
mappingFieldPairValidator.validateFieldTypes(validations, mappingId, sourceFieldGroup, targetFields.get(0));
} else {
mappingFieldPairValidator.validateFieldTypes(validations, mappingId, sourceFields, targetFields.get(0));
}
} else if (targetFields != null && targetFields.size() > 1) {
mappingFieldPairValidator.validateFieldTypes(validations, mappingId, sourceFields.get(0), targetFields);
} else {
mappingFieldPairValidator.validateFieldTypes(validations, mappingId, sourceFields.get(0), targetFields.get(0));
}
}
use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.
the class MultipleFieldSelectionValidator method validate.
/**
* Validates multiple fields selection.
* @param validations a container to put the result {@link Validation}.
* @param mappingId mapping ID
* @param direction direction
* @param fields fields
*/
public void validate(List<Validation> validations, String mappingId, FieldDirection direction, List<Field> fields) {
if (fields.size() <= 1) {
return;
}
for (Field f : fields) {
if (!service.matchDocIdOrNull(f.getDocId())) {
continue;
}
AtlasPath path = new AtlasPath(f.getPath());
if (path.hasCollection()) {
Validation validation = new Validation();
validation.setScope(ValidationScope.MAPPING);
validation.setId(mappingId);
validation.setMessage(String.format("A %s field contained in a collection can not be selected with other %s field: ['%s']", direction.value(), direction.value(), f.getPath()));
validation.setStatus(ValidationStatus.ERROR);
validations.add(validation);
}
}
}
Aggregations