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());
}
}
}
}
}
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()));
}
}
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);
}
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;
}
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;
}
Aggregations