Search in sources :

Example 1 with Trim

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

the class BaseMarshallerTest method generateActions.

private Actions generateActions() {
    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());
    return 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 2 with Trim

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

the class ExpressionFieldAction method process.

/**
 * Processes expression field action.
 * @param action action model
 * @param args expression arguments
 * @return processed
 * @throws ExpressionException expression processing error
 */
@Deprecated
@AtlasActionProcessor
public static Object process(io.atlasmap.v2.Expression action, List<Object> args) throws ExpressionException {
    if (action.getExpression() == null || action.getExpression().trim().isEmpty()) {
        return null;
    }
    Expression parsedExpression = Expression.parse(action.getExpression(), DefaultAtlasFunctionResolver.getInstance());
    Field answer = parsedExpression.evaluate((index) -> {
        try {
            return wrapWithField(args.get(Integer.parseInt(index)));
        } catch (Throwable e) {
            throw new ExpressionException("Invalid variable: " + index);
        }
    });
    return unwrapField(answer);
}
Also used : Field(io.atlasmap.v2.Field) AtlasModelFactory.unwrapField(io.atlasmap.v2.AtlasModelFactory.unwrapField) AtlasModelFactory.wrapWithField(io.atlasmap.v2.AtlasModelFactory.wrapWithField) Expression(io.atlasmap.expression.Expression) ExpressionException(io.atlasmap.expression.ExpressionException) AtlasActionProcessor(io.atlasmap.spi.AtlasActionProcessor)

Example 3 with Trim

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

the class AtlasBaseActionsTest method testActions.

@Test
public void testActions() throws Exception {
    List<ActionDetail> actions = DefaultAtlasContextFactory.getInstance().getFieldActionService().listActionDetails();
    for (ActionDetail d : actions) {
        System.out.println(d.getName());
    }
    this.runActionTest(new Uppercase(), "fname", "FNAME", String.class);
    this.runActionTest(new Lowercase(), "fnAme", "fname", String.class);
    this.runActionTest(new Trim(), " fname ", "fname", String.class);
    this.runActionTest(new TrimLeft(), " fname ", "fname ", String.class);
    this.runActionTest(new TrimRight(), " fname ", " fname", String.class);
    this.runActionTest(new Capitalize(), "fname", "Fname", String.class);
    this.runActionTest(new SeparateByDash(), "f:name", "f-name", String.class);
    this.runActionTest(new SeparateByUnderscore(), "f-na_me", "f_na_me", String.class);
    SubString s = new SubString();
    s.setStartIndex(0);
    s.setEndIndex(3);
    this.runActionTest(s, "12345", "123", String.class);
    SubStringAfter s1 = new SubStringAfter();
    s1.setStartIndex(3);
    s1.setEndIndex(null);
    s1.setMatch("foo");
    this.runActionTest(s1, "foobarblah", "blah", String.class);
    SubStringBefore s2 = new SubStringBefore();
    s2.setStartIndex(3);
    s2.setEndIndex(null);
    s2.setMatch("blah");
    this.runActionTest(s2, "foobarblah", "bar", String.class);
    PadStringRight ps = new PadStringRight();
    ps.setPadCharacter("X");
    ps.setPadCount(5);
    this.runActionTest(ps, "fname", "fnameXXXXX", String.class);
    PadStringLeft pl = new PadStringLeft();
    pl.setPadCharacter("X");
    pl.setPadCount(5);
    this.runActionTest(pl, "fname", "XXXXXfname", String.class);
/* ref https://github.com/atlasmap/atlasmap/issues/674
        String result = (String) runActionTest(new GenerateUUID(), "fname", null, String.class);
        assertTrue(Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}").matcher(result)
                .matches());
        */
}
Also used : ActionDetail(io.atlasmap.v2.ActionDetail) SeparateByUnderscore(io.atlasmap.v2.SeparateByUnderscore) Trim(io.atlasmap.v2.Trim) TrimRight(io.atlasmap.v2.TrimRight) SubString(io.atlasmap.v2.SubString) SubStringAfter(io.atlasmap.v2.SubStringAfter) PadStringLeft(io.atlasmap.v2.PadStringLeft) SeparateByDash(io.atlasmap.v2.SeparateByDash) TrimLeft(io.atlasmap.v2.TrimLeft) Uppercase(io.atlasmap.v2.Uppercase) Lowercase(io.atlasmap.v2.Lowercase) Capitalize(io.atlasmap.v2.Capitalize) PadStringRight(io.atlasmap.v2.PadStringRight) SubStringBefore(io.atlasmap.v2.SubStringBefore) Test(org.junit.jupiter.api.Test)

Example 4 with Trim

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

the class BaseMarshallerTest method generateActions.

private ArrayList<Action> generateActions() {
    ArrayList<Action> actions = new ArrayList<Action>();
    actions.add(new Camelize());
    actions.add(new Capitalize());
    actions.add(new Length());
    actions.add(new Lowercase());
    actions.add(new SeparateByDash());
    actions.add(new SeparateByUnderscore());
    actions.add(new Trim());
    actions.add(new TrimLeft());
    actions.add(new TrimRight());
    actions.add(new Uppercase());
    return actions;
}
Also used : Action(io.atlasmap.v2.Action) SeparateByUnderscore(io.atlasmap.v2.SeparateByUnderscore) Trim(io.atlasmap.v2.Trim) TrimRight(io.atlasmap.v2.TrimRight) ArrayList(java.util.ArrayList) SeparateByDash(io.atlasmap.v2.SeparateByDash) Camelize(io.atlasmap.v2.Camelize) TrimLeft(io.atlasmap.v2.TrimLeft) Length(io.atlasmap.v2.Length) Lowercase(io.atlasmap.v2.Lowercase) Uppercase(io.atlasmap.v2.Uppercase) Capitalize(io.atlasmap.v2.Capitalize)

Example 5 with Trim

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

the class BaseMarshallerTest method generateConstantMapping.

protected AtlasMapping generateConstantMapping() {
    AtlasMapping mapping = generateAtlasMapping();
    ConstantField inputField = new ConstantField();
    ArrayList<Action> actions = new ArrayList<Action>();
    actions.add(new Trim());
    populateFieldComplexObject(inputField, actions, CollectionType.ARRAY, FieldStatus.SUPPORTED, FieldType.INTEGER);
    populateFieldSimpleObject(inputField, 3, "docid", "/path", false, "bar");
    Mapping fm = (Mapping) mapping.getMappings().getMapping().get(0);
    fm.getInputField().add(inputField);
    fm.getOutputField().add(inputField);
    populateMapping(fm, MappingType.MAP, "MapPropertyFieldAlias", ",", ",");
    populateMappingString(fm, "description", "id", "lookupTableName", "strategy", "strategyClassName");
    return mapping;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Action(io.atlasmap.v2.Action) ConstantField(io.atlasmap.v2.ConstantField) Trim(io.atlasmap.v2.Trim) ArrayList(java.util.ArrayList) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

Aggregations

Trim (io.atlasmap.v2.Trim)10 Action (io.atlasmap.v2.Action)7 Capitalize (io.atlasmap.v2.Capitalize)6 Lowercase (io.atlasmap.v2.Lowercase)6 SeparateByDash (io.atlasmap.v2.SeparateByDash)6 SeparateByUnderscore (io.atlasmap.v2.SeparateByUnderscore)6 TrimLeft (io.atlasmap.v2.TrimLeft)6 TrimRight (io.atlasmap.v2.TrimRight)6 Uppercase (io.atlasmap.v2.Uppercase)6 ArrayList (java.util.ArrayList)5 Camelize (io.atlasmap.v2.Camelize)4 Length (io.atlasmap.v2.Length)4 Test (org.junit.jupiter.api.Test)3 ActionDetail (io.atlasmap.v2.ActionDetail)2 AtlasMapping (io.atlasmap.v2.AtlasMapping)2 GenerateUUID (io.atlasmap.v2.GenerateUUID)2 Mapping (io.atlasmap.v2.Mapping)2 PadStringLeft (io.atlasmap.v2.PadStringLeft)2 PadStringRight (io.atlasmap.v2.PadStringRight)2 SubString (io.atlasmap.v2.SubString)2