Search in sources :

Example 1 with Multiplicity

use of io.atlasmap.v2.Multiplicity in project atlasmap by atlasmap.

the class DefaultAtlasFieldActionService method processAction.

private Field processAction(Action action, ActionProcessor processor, FieldType sourceType, Field field) throws AtlasException {
    ActionDetail detail = processor.getActionDetail();
    Multiplicity multiplicity = detail.getMultiplicity() != null ? detail.getMultiplicity() : Multiplicity.ONE_TO_ONE;
    if (multiplicity == Multiplicity.MANY_TO_ONE) {
        return processManyToOne(action, processor, sourceType, field);
    }
    if (multiplicity == Multiplicity.ONE_TO_MANY) {
        if (field instanceof FieldGroup) {
            while (field instanceof FieldGroup) {
                field = ((FieldGroup) field).getField().get(0);
            }
        }
        return processOneToMany(action, processor, sourceType, field);
    }
    if (field instanceof FieldGroup) {
        return processActionForEachCollectionItem(action, processor, sourceType, (FieldGroup) field);
    }
    Object value = field.getValue();
    if (value != null && !isAssignableFieldType(detail.getSourceType(), sourceType)) {
        value = getConversionService().convertType(value, sourceType, detail.getSourceType());
    }
    value = processor.process(action, value);
    field.setFieldType(processor.getActionDetail().getTargetType());
    field.setValue(value);
    return field;
}
Also used : ActionDetail(io.atlasmap.v2.ActionDetail) FieldGroup(io.atlasmap.v2.FieldGroup) Multiplicity(io.atlasmap.v2.Multiplicity)

Example 2 with Multiplicity

use of io.atlasmap.v2.Multiplicity in project atlasmap by atlasmap.

the class JsonValidationServiceMultiplicityTest method testHappyPath.

@Test
public void testHappyPath() throws Exception {
    AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/atlasmapping-multiplicity-transformation-concatenate-split.json");
    assertNotNull(mapping);
    validations.addAll(sourceValidationService.validateMapping(mapping));
    validations.addAll(targetValidationService.validateMapping(mapping));
    assertFalse(validationHelper.hasErrors(), validationHelper.allValidationsToString());
    assertFalse(validationHelper.hasWarnings(), validationHelper.allValidationsToString());
    assertFalse(validationHelper.hasInfos(), validationHelper.allValidationsToString());
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.jupiter.api.Test)

Example 3 with Multiplicity

use of io.atlasmap.v2.Multiplicity in project atlasmap by atlasmap.

the class JsonValidationServiceMultiplicityTest method testCollectionInFieldGroup.

@Test
public void testCollectionInFieldGroup() throws Exception {
    AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/atlasmapping-multiplicity-transformation-concatenate-split.json");
    for (BaseMapping m : mapping.getMappings().getMapping()) {
        Mapping entry = (Mapping) m;
        if ("concatenate-from-field-group".equals(entry.getId())) {
            JsonField f = new JsonField();
            f.setCollectionType(CollectionType.LIST);
            f.setFieldType(FieldType.STRING);
            f.setPath("/sourceStringList<>");
            entry.getInputFieldGroup().getField().add(f);
            break;
        }
    }
    validations.addAll(sourceValidationService.validateMapping(mapping));
    validations.addAll(targetValidationService.validateMapping(mapping));
    assertFalse(validationHelper.hasErrors(), validationHelper.allValidationsToString());
    assertFalse(validationHelper.hasWarnings(), validationHelper.allValidationsToString());
    assertFalse(validationHelper.hasInfos(), validationHelper.allValidationsToString());
    assertEquals(0, validationHelper.getCount());
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) BaseMapping(io.atlasmap.v2.BaseMapping) BaseMapping(io.atlasmap.v2.BaseMapping) Test(org.junit.jupiter.api.Test)

Example 4 with Multiplicity

use of io.atlasmap.v2.Multiplicity in project atlasmap by atlasmap.

the class JsonValidationServiceMultiplicityTest method testCollectionInTargetFields.

@Test
public void testCollectionInTargetFields() throws Exception {
    AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/atlasmapping-multiplicity-transformation-concatenate-split.json");
    for (BaseMapping m : mapping.getMappings().getMapping()) {
        Mapping entry = (Mapping) m;
        if ("split-into-multiple-fields".equals(entry.getId())) {
            JsonField f = new JsonField();
            f.setCollectionType(CollectionType.LIST);
            f.setFieldType(FieldType.STRING);
            f.setPath("/targetStringList<>");
            entry.getOutputField().add(f);
            break;
        }
    }
    validations.addAll(sourceValidationService.validateMapping(mapping));
    validations.addAll(targetValidationService.validateMapping(mapping));
    assertFalse(validationHelper.hasErrors(), validationHelper.allValidationsToString());
    assertFalse(validationHelper.hasWarnings(), validationHelper.allValidationsToString());
    assertFalse(validationHelper.hasInfos(), validationHelper.allValidationsToString());
    assertEquals(0, validationHelper.getCount());
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) BaseMapping(io.atlasmap.v2.BaseMapping) BaseMapping(io.atlasmap.v2.BaseMapping) Test(org.junit.jupiter.api.Test)

Aggregations

AtlasMapping (io.atlasmap.v2.AtlasMapping)3 Test (org.junit.jupiter.api.Test)3 JsonField (io.atlasmap.json.v2.JsonField)2 BaseMapping (io.atlasmap.v2.BaseMapping)2 Mapping (io.atlasmap.v2.Mapping)2 ActionDetail (io.atlasmap.v2.ActionDetail)1 FieldGroup (io.atlasmap.v2.FieldGroup)1 Multiplicity (io.atlasmap.v2.Multiplicity)1