Search in sources :

Example 1 with SubStringAfter

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

the class StringComplexFieldActions method subStringAfter.

@AtlasFieldActionInfo(name = "SubStringAfter", sourceType = FieldType.STRING, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String subStringAfter(Action action, String input) {
    if (input == null || input.length() == 0) {
        return input;
    }
    if (action == null || !(action instanceof SubStringAfter) || ((SubStringAfter) action).getStartIndex() == null || ((SubStringAfter) action).getStartIndex() < 0 || ((SubStringAfter) action).getMatch() == null || (((SubStringAfter) action).getEndIndex() != null && ((SubStringAfter) action).getEndIndex() < ((SubStringAfter) action).getStartIndex())) {
        throw new IllegalArgumentException("SubStringAfter action must be specified with a positive startIndex and a string to match");
    }
    SubStringAfter subStringAfter = (SubStringAfter) action;
    int idx = input.indexOf(subStringAfter.getMatch());
    if (idx < 0) {
        return input;
    }
    idx = idx + subStringAfter.getMatch().length();
    return doSubString(input.substring(idx), subStringAfter.getStartIndex(), subStringAfter.getEndIndex());
}
Also used : SubStringAfter(io.atlasmap.v2.SubStringAfter) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Example 2 with SubStringAfter

use of io.atlasmap.v2.SubStringAfter 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);
    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) GenerateUUID(io.atlasmap.v2.GenerateUUID) SubString(io.atlasmap.v2.SubString) 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.Test)

Example 3 with SubStringAfter

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

the class StringComplexFieldActionsTest method testSubStringAfter.

@Test
public void testSubStringAfter() {
    SubStringAfter action = new SubStringAfter();
    action.setStartIndex(3);
    action.setEndIndex(null);
    action.setMatch("foo");
    assertNull(StringComplexFieldActions.subStringAfter(action, null));
    assertEquals("", StringComplexFieldActions.subStringAfter(action, ""));
    assertEquals("blah", StringComplexFieldActions.subStringAfter(action, "foobarblah"));
    assertEquals("blahfoo", StringComplexFieldActions.subStringAfter(action, "foobarblahfoo"));
    assertEquals("barblah", StringComplexFieldActions.subStringAfter(action, "barblah"));
    action.setEndIndex(7);
    assertEquals("blah", StringComplexFieldActions.subStringAfter(action, "foobarblahfoo"));
    action.setEndIndex(3);
    assertEquals("", StringComplexFieldActions.subStringAfter(action, "foobarblahfoo"));
    try {
        StringComplexFieldActions.subStringAfter(null, "aa");
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
        assertTrue(true);
    }
    try {
        SubStringAfter err = new SubStringAfter();
        StringComplexFieldActions.subStringAfter(err, "aa");
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
        assertTrue(true);
    }
    try {
        SubStringAfter err = new SubStringAfter();
        err.setEndIndex(5);
        err.setStartIndex(0);
        StringComplexFieldActions.subStringAfter(err, "aa");
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
        assertTrue(true);
    }
    try {
        SubStringAfter err = new SubStringAfter();
        err.setEndIndex(0);
        err.setStartIndex(5);
        StringComplexFieldActions.subStringAfter(err, "aa");
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
        assertTrue(true);
    }
}
Also used : SubStringAfter(io.atlasmap.v2.SubStringAfter) Test(org.junit.Test)

Aggregations

SubStringAfter (io.atlasmap.v2.SubStringAfter)3 Test (org.junit.Test)2 AtlasFieldActionInfo (io.atlasmap.spi.AtlasFieldActionInfo)1 ActionDetail (io.atlasmap.v2.ActionDetail)1 Capitalize (io.atlasmap.v2.Capitalize)1 GenerateUUID (io.atlasmap.v2.GenerateUUID)1 Lowercase (io.atlasmap.v2.Lowercase)1 PadStringLeft (io.atlasmap.v2.PadStringLeft)1 PadStringRight (io.atlasmap.v2.PadStringRight)1 SeparateByDash (io.atlasmap.v2.SeparateByDash)1 SeparateByUnderscore (io.atlasmap.v2.SeparateByUnderscore)1 SubString (io.atlasmap.v2.SubString)1 SubStringBefore (io.atlasmap.v2.SubStringBefore)1 Trim (io.atlasmap.v2.Trim)1 TrimLeft (io.atlasmap.v2.TrimLeft)1 TrimRight (io.atlasmap.v2.TrimRight)1 Uppercase (io.atlasmap.v2.Uppercase)1