Search in sources :

Example 1 with Length

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

the class DefaultAtlasFieldActionService method detectFieldActionParameters.

protected Properties detectFieldActionParameters(String actionClassName) throws ClassNotFoundException {
    Class<?> actionClazz = Class.forName(actionClassName);
    Properties props = null;
    for (Method method : actionClazz.getMethods()) {
        // Find setters to avoid the get / is confusion
        if (method.getParameterCount() == 1 && method.getName().startsWith("set")) {
            // We have a parameter
            if (props == null) {
                props = new Properties();
            }
            Property prop = null;
            for (Parameter param : method.getParameters()) {
                prop = new Property();
                prop.setName(camelize(method.getName().substring("set".length())));
                prop.setFieldType(getConversionService().fieldTypeFromClass(param.getType()));
                props.getProperty().add(prop);
            }
        }
    }
    return props;
}
Also used : Parameter(java.lang.reflect.Parameter) Method(java.lang.reflect.Method) Properties(io.atlasmap.v2.Properties) Property(io.atlasmap.v2.Property)

Example 2 with Length

use of io.atlasmap.v2.Length 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 3 with Length

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

the class StringLengthValidatorTest method testValidateInvalid.

@Test
public void testValidateInvalid() {
    String pass = "";
    validator.validate(pass, validations, "testValidateInvalid");
    assertTrue(validationHelper.hasErrors());
    assertEquals(new Integer(1), new Integer(validationHelper.getAllValidations().size()));
    Validation validation = validations.get(0);
    assertNotNull(validation);
    assertEquals(ValidationScope.MAPPING, validation.getScope());
    assertEquals("testValidateInvalid", validation.getId());
    assertTrue("Must be of this length".equals(validation.getMessage()));
}
Also used : Validation(io.atlasmap.v2.Validation) Test(org.junit.Test)

Example 4 with Length

use of io.atlasmap.v2.Length 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 5 with Length

use of io.atlasmap.v2.Length 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)

Aggregations

Actions (io.atlasmap.v2.Actions)3 Camelize (io.atlasmap.v2.Camelize)3 Capitalize (io.atlasmap.v2.Capitalize)3 Length (io.atlasmap.v2.Length)3 Lowercase (io.atlasmap.v2.Lowercase)3 SeparateByDash (io.atlasmap.v2.SeparateByDash)3 SeparateByUnderscore (io.atlasmap.v2.SeparateByUnderscore)3 Trim (io.atlasmap.v2.Trim)3 TrimLeft (io.atlasmap.v2.TrimLeft)3 TrimRight (io.atlasmap.v2.TrimRight)3 Uppercase (io.atlasmap.v2.Uppercase)3 AtlasFieldActionInfo (io.atlasmap.spi.AtlasFieldActionInfo)1 Properties (io.atlasmap.v2.Properties)1 Property (io.atlasmap.v2.Property)1 SubStringAfter (io.atlasmap.v2.SubStringAfter)1 Validation (io.atlasmap.v2.Validation)1 Method (java.lang.reflect.Method)1 Parameter (java.lang.reflect.Parameter)1 Test (org.junit.Test)1