Search in sources :

Example 51 with Action

use of com.opensymphony.xwork2.Action in project atlasmap by atlasmap.

the class DefaultAtlasFieldActionService method processActions.

@Override
public Field processActions(AtlasInternalSession session, Field field) throws AtlasException {
    ArrayList<Action> actions = field.getActions();
    if (actions == null || actions.isEmpty()) {
        return field;
    }
    Field tmpSourceField = field;
    FieldType currentType = determineFieldType(field);
    for (Action action : actions) {
        ActionProcessor processor = findActionProcessor(action, currentType);
        if (processor == null) {
            AtlasUtil.addAudit(session, field, String.format("Couldn't find metadata for a FieldAction '%s', please make sure it's in the classpath, and also have a service declaration under META-INF/services. Ignoring...", action.getDisplayName()), AuditStatus.WARN, null);
            continue;
        }
        ActionDetail detail = processor.getActionDetail();
        if (detail == null) {
            AtlasUtil.addAudit(session, field, String.format("Couldn't find metadata for a FieldAction '%s', ignoring...", action.getDisplayName()), AuditStatus.WARN, null);
            continue;
        }
        tmpSourceField = processAction(action, processor, currentType, tmpSourceField);
        currentType = determineFieldType(tmpSourceField);
    }
    return tmpSourceField;
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) CustomAction(io.atlasmap.v2.CustomAction) AtlasFieldAction(io.atlasmap.spi.AtlasFieldAction) Action(io.atlasmap.v2.Action) ActionDetail(io.atlasmap.v2.ActionDetail) ActionProcessor(io.atlasmap.spi.ActionProcessor) AtlasActionProcessor(io.atlasmap.spi.AtlasActionProcessor) FieldType(io.atlasmap.v2.FieldType)

Example 52 with Action

use of com.opensymphony.xwork2.Action in project atlasmap by atlasmap.

the class DefaultAtlasFieldActionService method buildAndProcessAction.

/**
 * Instantiate the field action impl class from {@link ActionProcessor} and processes it.
 * @param actionProcessor action processor
 * @param actionParameters action parameters
 * @param field field
 * @return processed field
 */
public Field buildAndProcessAction(ActionProcessor actionProcessor, Map<String, Object> actionParameters, Field field) {
    FieldType valueType = determineFieldType(field);
    try {
        Action action = actionProcessor.getActionClass().getDeclaredConstructor().newInstance();
        for (Map.Entry<String, Object> property : actionParameters.entrySet()) {
            String setter = "set" + property.getKey().substring(0, 1).toUpperCase() + property.getKey().substring(1);
            action.getClass().getMethod(setter, property.getValue().getClass()).invoke(action, property.getValue());
        }
        return processAction(action, actionProcessor, valueType, field);
    } catch (Exception e) {
        throw new IllegalArgumentException(String.format("The action '%s' cannot be processed", actionProcessor.getActionDetail().getName()), e);
    }
}
Also used : CustomAction(io.atlasmap.v2.CustomAction) AtlasFieldAction(io.atlasmap.spi.AtlasFieldAction) Action(io.atlasmap.v2.Action) Map(java.util.Map) AtlasConversionException(io.atlasmap.api.AtlasConversionException) AtlasException(io.atlasmap.api.AtlasException) FieldType(io.atlasmap.v2.FieldType)

Example 53 with Action

use of com.opensymphony.xwork2.Action in project atlasmap by atlasmap.

the class MappingFieldPairValidator method getActionOutputFieldType.

private FieldType getActionOutputFieldType(List<Validation> validations, String mappingId, Field f) {
    if (f.getActions() == null || f.getActions().size() == 0) {
        return null;
    }
    Action lastAction = f.getActions().get(f.getActions().size() - 1);
    ActionDetail detail = null;
    try {
        detail = service.getFieldActionService().findActionDetail(lastAction, f.getFieldType());
    } catch (AtlasException e) {
        if (LOG.isDebugEnabled()) {
            LOG.error("ActionDetail not found", e);
        }
    }
    if (detail == null) {
        Validation validation = new Validation();
        validation.setScope(ValidationScope.MAPPING);
        validation.setId(mappingId);
        validation.setMessage(String.format("Couldn't find a metadata for transformation '%s'", lastAction.getDisplayName()));
        validation.setStatus(ValidationStatus.ERROR);
        validations.add(validation);
        return null;
    }
    return detail.getTargetType();
}
Also used : Validation(io.atlasmap.v2.Validation) Action(io.atlasmap.v2.Action) ActionDetail(io.atlasmap.v2.ActionDetail) AtlasException(io.atlasmap.api.AtlasException)

Example 54 with Action

use of com.opensymphony.xwork2.Action 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 ArrayList<Action>());
        m.getOutputField().get(0).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";
    Json.mapper().writeValue(new File(tmpFile), atlasMapping);
    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 : Action(io.atlasmap.v2.Action) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) 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)

Example 55 with Action

use of com.opensymphony.xwork2.Action in project atlasmap by atlasmap.

the class DefaultAtlasPreviewContextTest method testProcessPreviewSourceFieldAction.

@Test
public void testProcessPreviewSourceFieldAction() throws AtlasException {
    Mapping m = new Mapping();
    m.setMappingType(MappingType.MAP);
    Field source = new SimpleField();
    source.setFieldType(FieldType.STRING);
    source.setValue("abc");
    ArrayList<Action> actions = new ArrayList<Action>();
    actions.add(new Uppercase());
    source.setActions(actions);
    Field target = new SimpleField();
    target.setFieldType(FieldType.STRING);
    m.getInputField().add(source);
    m.getOutputField().add(target);
    previewContext.processPreview(m);
    target = m.getOutputField().get(0);
    assertEquals("ABC", target.getValue());
}
Also used : SimpleField(io.atlasmap.v2.SimpleField) ConstantField(io.atlasmap.v2.ConstantField) Field(io.atlasmap.v2.Field) Action(io.atlasmap.v2.Action) Uppercase(io.atlasmap.v2.Uppercase) ArrayList(java.util.ArrayList) Mapping(io.atlasmap.v2.Mapping) SimpleField(io.atlasmap.v2.SimpleField) Test(org.junit.jupiter.api.Test)

Aggregations

ActionSupport (com.opensymphony.xwork2.ActionSupport)61 List (java.util.List)40 Action (io.atlasmap.v2.Action)35 ArrayList (java.util.ArrayList)23 Test (org.junit.jupiter.api.Test)16 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)14 SimpleField (io.atlasmap.v2.SimpleField)13 Field (io.atlasmap.v2.Field)12 Mapping (io.atlasmap.v2.Mapping)11 ActionContext (com.opensymphony.xwork2.ActionContext)9 AtlasMapping (io.atlasmap.v2.AtlasMapping)9 Collections (java.util.Collections)9 HashMap (java.util.HashMap)9 SettableApiFuture (com.google.api.core.SettableApiFuture)8 ServiceOptions (com.google.cloud.ServiceOptions)8 DlpServiceClient (com.google.cloud.dlp.v2.DlpServiceClient)8 Subscriber (com.google.cloud.pubsub.v1.Subscriber)8 Action (com.google.privacy.dlp.v2.Action)8 BigQueryTable (com.google.privacy.dlp.v2.BigQueryTable)8 CreateDlpJobRequest (com.google.privacy.dlp.v2.CreateDlpJobRequest)8