Search in sources :

Example 81 with Field

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);
                }
            }
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

Example 82 with Field

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);
    }
}
Also used : Field(io.atlasmap.v2.Field) FieldGroup(io.atlasmap.v2.FieldGroup) ArrayList(java.util.ArrayList) List(java.util.List)

Example 83 with Field

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);
            }
        }
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Field(io.atlasmap.v2.Field)

Example 84 with Field

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));
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Field(io.atlasmap.v2.Field) FieldGroup(io.atlasmap.v2.FieldGroup)

Example 85 with Field

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);
        }
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Field(io.atlasmap.v2.Field) AtlasPath(io.atlasmap.core.AtlasPath)

Aggregations

Field (io.atlasmap.v2.Field)221 FieldGroup (io.atlasmap.v2.FieldGroup)86 Test (org.junit.jupiter.api.Test)67 SimpleField (io.atlasmap.v2.SimpleField)62 Field (org.apache.tapestry5.Field)46 JavaField (io.atlasmap.java.v2.JavaField)45 ArrayList (java.util.ArrayList)42 Mapping (io.atlasmap.v2.Mapping)39 Test (org.testng.annotations.Test)39 AtlasPath (io.atlasmap.core.AtlasPath)29 ConstantField (io.atlasmap.v2.ConstantField)29 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)26 AtlasException (io.atlasmap.api.AtlasException)25 JsonField (io.atlasmap.json.v2.JsonField)25 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)25 PropertyField (io.atlasmap.v2.PropertyField)22 AtlasMapping (io.atlasmap.v2.AtlasMapping)21 KafkaConnectField (io.atlasmap.kafkaconnect.v2.KafkaConnectField)19 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)19 Head (io.atlasmap.spi.AtlasInternalSession.Head)18