Search in sources :

Example 16 with Actions

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

the class AtlasServiceTest method testActionDeserialization.

@Test
public void testActionDeserialization() throws Exception {
    File file = new File("src/test/resources/atlasmapping-actions.json");
    AtlasMapping mapping = mapper.readValue(file, AtlasMapping.class);
    Mappings mappings = mapping.getMappings();
    for (BaseMapping baseMapping : mappings.getMapping()) {
        if (MappingType.MAP.equals(baseMapping.getMappingType())) {
            List<Field> fields = ((Mapping) baseMapping).getOutputField();
            for (Field f : fields) {
                if (f.getActions() != null && f.getActions().getActions() != null && !f.getActions().getActions().isEmpty()) {
                    System.out.println("Found actions: " + f.getActions().getActions().size());
                }
            }
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) BaseMapping(io.atlasmap.v2.BaseMapping) File(java.io.File) BaseMapping(io.atlasmap.v2.BaseMapping) Test(org.junit.Test)

Example 17 with Actions

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

the class DefaultAtlasFieldActionService method loadFieldActions.

protected void loadFieldActions() {
    ClassLoader classLoader = this.getClass().getClassLoader();
    final ServiceLoader<AtlasFieldAction> fieldActionServiceLoader = ServiceLoader.load(AtlasFieldAction.class, classLoader);
    for (final AtlasFieldAction atlasFieldAction : fieldActionServiceLoader) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Loading FieldAction class: " + atlasFieldAction.getClass().getCanonicalName());
        }
        Class<?> clazz = atlasFieldAction.getClass();
        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            AtlasFieldActionInfo annotation = method.getAnnotation(AtlasFieldActionInfo.class);
            if (annotation != null) {
                ActionDetail det = new ActionDetail();
                det.setClassName(clazz.getName());
                det.setMethod(method.getName());
                det.setName(annotation.name());
                det.setSourceType(annotation.sourceType());
                det.setTargetType(annotation.targetType());
                det.setSourceCollectionType(annotation.sourceCollectionType());
                det.setTargetCollectionType(annotation.targetCollectionType());
                try {
                    det.setParameters(detectFieldActionParameters("io.atlasmap.v2." + annotation.name()));
                } catch (ClassNotFoundException e) {
                    LOG.error(String.format("Error detecting parameters for field action=%s msg=%s", annotation.name(), e.getMessage()), e);
                }
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Loaded FieldAction: " + det.getName());
                }
                listActionDetails().add(det);
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("Loaded %s Field Actions", listActionDetails().size()));
    }
}
Also used : ActionDetail(io.atlasmap.v2.ActionDetail) AtlasFieldAction(io.atlasmap.api.AtlasFieldAction) Method(java.lang.reflect.Method) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Example 18 with Actions

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

the class BaseMarshallerTest method generateActions.

private void generateActions(JsonField inputField) {
    Actions actions = new Actions();
    actions.getActions().add(new Camelize());
    actions.getActions().add(new Capitalize());
    actions.getActions().add(new Length());
    actions.getActions().add(new Lowercase());
    actions.getActions().add(new SeparateByDash());
    actions.getActions().add(new SeparateByUnderscore());
    actions.getActions().add(new Trim());
    actions.getActions().add(new TrimLeft());
    actions.getActions().add(new TrimRight());
    actions.getActions().add(new Uppercase());
    inputField.setActions(actions);
}
Also used : Camelize(io.atlasmap.v2.Camelize) TrimLeft(io.atlasmap.v2.TrimLeft) SeparateByUnderscore(io.atlasmap.v2.SeparateByUnderscore) Actions(io.atlasmap.v2.Actions) Length(io.atlasmap.v2.Length) Trim(io.atlasmap.v2.Trim) Lowercase(io.atlasmap.v2.Lowercase) Uppercase(io.atlasmap.v2.Uppercase) TrimRight(io.atlasmap.v2.TrimRight) Capitalize(io.atlasmap.v2.Capitalize) SeparateByDash(io.atlasmap.v2.SeparateByDash)

Example 19 with Actions

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

the class OverloadedFieldActionsTest method generateMappingDayOfWeek.

protected AtlasMapping generateMappingDayOfWeek(Class<?> clazz) {
    AtlasMapping m = new AtlasMapping();
    DataSource s = new DataSource();
    s.setDataSourceType(DataSourceType.SOURCE);
    s.setUri("atlas:java?className=io.atlasmap.java.test.SourceFlatPrimitiveClass");
    DataSource t = new DataSource();
    t.setDataSourceType(DataSourceType.TARGET);
    t.setUri("atlas:java?className=io.atlasmap.java.test.TargetFlatPrimitiveClass");
    m.getDataSource().add(s);
    m.getDataSource().add(t);
    Mapping mfm = AtlasModelFactory.createMapping(MappingType.MAP);
    JavaField srcF = new JavaField();
    Actions acts = new Actions();
    srcF.setActions(acts);
    JavaField tgtF = new JavaField();
    if (clazz.isAssignableFrom(String.class)) {
        srcF.setPath("boxedStringField");
        srcF.getActions().getActions().add(new DayOfWeekString());
        tgtF.setPath("boxedStringField");
    } else if (clazz.isAssignableFrom(Integer.class)) {
        srcF.setPath("intField");
        srcF.getActions().getActions().add(new DayOfWeekInteger());
        tgtF.setPath("boxedStringField");
    }
    mfm.getInputField().add(srcF);
    mfm.getOutputField().add(tgtF);
    Mappings maps = new Mappings();
    maps.getMapping().add(mfm);
    m.setMappings(maps);
    return m;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) Mappings(io.atlasmap.v2.Mappings) Actions(io.atlasmap.v2.Actions) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) DataSource(io.atlasmap.v2.DataSource)

Example 20 with Actions

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

the class AtlasBaseActionsTest method runActionTestList.

public Object runActionTestList(List<Action> actions, String sourceFirstName, Object targetExpected, Class<?> targetClassExpected) throws Exception {
    System.out.println("Now running test for actions: " + actions);
    System.out.println("Input: " + sourceFirstName);
    System.out.println("Expected output: " + targetExpected);
    Mapping m = new Mapping();
    m.setMappingType(MappingType.MAP);
    m.getInputField().add(this.sourceField);
    m.getOutputField().add(this.targetField);
    if (actions != null) {
        m.getOutputField().get(0).setActions(new Actions());
        m.getOutputField().get(0).getActions().getActions().addAll(actions);
    }
    DataSource src = new DataSource();
    src.setDataSourceType(DataSourceType.SOURCE);
    src.setUri(this.docURI);
    DataSource tgt = new DataSource();
    tgt.setDataSourceType(DataSourceType.TARGET);
    tgt.setUri(this.docURI);
    AtlasMapping atlasMapping = new AtlasMapping();
    atlasMapping.setName("fieldactiontest");
    atlasMapping.setMappings(new Mappings());
    atlasMapping.getMappings().getMapping().add(m);
    atlasMapping.getDataSource().add(src);
    atlasMapping.getDataSource().add(tgt);
    String tmpFile = "target/fieldactions-" + this.getClass().getSimpleName() + "-tmp.txt";
    DefaultAtlasContextFactory.getInstance().getMappingService().saveMappingAsFile(atlasMapping, new File(tmpFile), AtlasMappingFormat.XML);
    AtlasContext context = atlasContextFactory.createContext(new File(tmpFile).toURI());
    AtlasSession session = context.createSession();
    session.setDefaultSourceDocument(createSource(sourceFirstName));
    context.process(session);
    Object targetActual = session.getDefaultTargetDocument();
    assertNotNull(targetActual);
    targetActual = getTargetValue(targetActual, targetClassExpected);
    if (targetExpected != null) {
        assertEquals(targetExpected, targetActual);
    }
    return targetActual;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) Actions(io.atlasmap.v2.Actions) AtlasContext(io.atlasmap.api.AtlasContext) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) SubString(io.atlasmap.v2.SubString) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) DataSource(io.atlasmap.v2.DataSource)

Aggregations

Actions (io.atlasmap.v2.Actions)15 AtlasMapping (io.atlasmap.v2.AtlasMapping)10 Mapping (io.atlasmap.v2.Mapping)9 Test (org.junit.Test)8 Trim (io.atlasmap.v2.Trim)7 SimpleField (io.atlasmap.v2.SimpleField)5 ActionDetail (io.atlasmap.v2.ActionDetail)4 Capitalize (io.atlasmap.v2.Capitalize)4 Lowercase (io.atlasmap.v2.Lowercase)4 SeparateByDash (io.atlasmap.v2.SeparateByDash)4 SeparateByUnderscore (io.atlasmap.v2.SeparateByUnderscore)4 StringList (io.atlasmap.v2.StringList)4 TrimLeft (io.atlasmap.v2.TrimLeft)4 TrimRight (io.atlasmap.v2.TrimRight)4 Uppercase (io.atlasmap.v2.Uppercase)4 Camelize (io.atlasmap.v2.Camelize)3 Field (io.atlasmap.v2.Field)3 Length (io.atlasmap.v2.Length)3 Mappings (io.atlasmap.v2.Mappings)3 File (java.io.File)3