Skip to content

Commit

Permalink
Merge pull request #1726 from arunans23/fixdm
Browse files Browse the repository at this point in the history
Simplify datamapper map function name
  • Loading branch information
chanikag authored Jul 15, 2024
2 parents 3b0009c + c927181 commit b05ca37
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static org.wso2.carbon.mediator.datamapper.engine.utils.DataMapperEngineConstants.DEFAULT_ENGINE_NAME;
import static org.wso2.carbon.mediator.datamapper.engine.utils.DataMapperEngineConstants.ENCODE_CHAR_HYPHEN;
import static org.wso2.carbon.mediator.datamapper.engine.utils.DataMapperEngineConstants.HYPHEN;
import static org.wso2.carbon.mediator.datamapper.engine.utils.DataMapperEngineConstants.INPUT_VARIABLE_IDENTIFIER;
import static org.wso2.carbon.mediator.datamapper.engine.utils.DataMapperEngineConstants.NASHORN_ENGINE_NAME;
import static org.wso2.carbon.mediator.datamapper.engine.utils.DataMapperEngineConstants.PROPERTIES_OBJECT_NAME;

Expand All @@ -50,7 +51,6 @@
public class ScriptExecutor implements Executor {

public static final String PROPERTIES_IDENTIFIER = "properties";
public static final String INPUT_VARIABLE_IDENTIFIER = "inputVariables";
public static final String OPENJDK_NASHORN_CLASSNAME = "org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory";
private static final Log log = LogFactory.getLog(ScriptExecutor.class);
private ScriptEngine scriptEngine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import static org.wso2.carbon.mediator.datamapper.engine.utils.DataMapperEngineConstants.JS_STRINGIFY;
import static org.wso2.carbon.mediator.datamapper.engine.utils.DataMapperEngineConstants.HYPHEN;
import static org.wso2.carbon.mediator.datamapper.engine.utils.DataMapperEngineConstants.ENCODE_CHAR_HYPHEN;
import static org.wso2.carbon.mediator.datamapper.engine.utils.DataMapperEngineConstants.MAP_FUNCTION;
import static org.wso2.carbon.mediator.datamapper.engine.utils.DataMapperEngineConstants.MAP_FUNCTION_NAME;

public class MappingResource {

Expand Down Expand Up @@ -147,6 +149,10 @@ private JSFunction createFunction(InputStream mappingConfig, String outputType)
propertiesList.add(match.group(2) + "['" + match.group(3) + "']");
}

if (jsFunctionBody.contains(MAP_FUNCTION_NAME)) {
fnName = MAP_FUNCTION;
}

if (fnName != null) {
return new JSFunction(fnName, jsFunctionBody);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public class DataMapperEngineConstants {
public static final String BRACKET_CLOSE = ")";
public static final String FUNCTION_NAME_CONST_1 = "map_S_";
public static final String FUNCTION_NAME_CONST_2 = "_S_";
public static final String INPUT_VARIABLE_IDENTIFIER = "inputVariables";
public static final String MAP_FUNCTION_NAME = "mapFunction";
public static final String MAP_FUNCTION = "mapFunction(JSON.parse(" + INPUT_VARIABLE_IDENTIFIER + ")";
public static final String NAME_SEPERATOR = "_Separat0r_";
public static final String ENCODE_CHAR_HYPHEN = "_EnC0DeCHaRHyPh3n_";
public static final String HYPHEN = "-";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
import static org.wso2.carbon.mediator.datamapper.config.xml.DataMapperMediatorConstants.SYNAPSE_CONTEXT;
import static org.wso2.carbon.mediator.datamapper.config.xml.DataMapperMediatorConstants.TRANSPORT_CONTEXT;
import static org.wso2.carbon.mediator.datamapper.config.xml.DataMapperMediatorConstants.TRANSPORT_HEADERS;
import static org.wso2.carbon.mediator.datamapper.engine.utils.DataMapperEngineConstants.INPUT_VARIABLE_IDENTIFIER;
import static org.wso2.carbon.mediator.datamapper.engine.utils.DataMapperEngineConstants.ORG_APACHE_SYNAPSE_DATAMAPPER_EXECUTOR_POOL_SIZE;
import static org.wso2.carbon.mediator.datamapper.engine.core.executors.ScriptExecutor.INPUT_VARIABLE_IDENTIFIER;
import static org.wso2.carbon.mediator.datamapper.engine.utils.DataMapperEngineConstants.ENCODE_CHAR_HYPHEN;
import static org.wso2.carbon.mediator.datamapper.engine.utils.DataMapperEngineConstants.HYPHEN;
import static org.wso2.carbon.mediator.datamapper.engine.utils.DataMapperEngineConstants.PROPERTIES_OBJECT_NAME;
Expand Down

0 comments on commit b05ca37

Please sign in to comment.