diff --git a/cit-esi-api/src/main/java/br/com/centralit/esi/api/runtime/RuntimeEnvironmentImpl.java b/cit-esi-api/src/main/java/br/com/centralit/esi/api/runtime/RuntimeEnvironmentImpl.java index b384850..5453680 100644 --- a/cit-esi-api/src/main/java/br/com/centralit/esi/api/runtime/RuntimeEnvironmentImpl.java +++ b/cit-esi-api/src/main/java/br/com/centralit/esi/api/runtime/RuntimeEnvironmentImpl.java @@ -309,7 +309,9 @@ public class RuntimeEnvironmentImpl implements RuntimeEnvironment { ,false) .setInputMap(inputMap); - this.initialize(input, flowVersion, objects); + MapObjects map = ConvertUtilsESI.cloneMap(inputMap); + + this.initialize(input, flowVersion, map); } @Override diff --git a/cit-esi-api/src/main/java/br/com/centralit/esi/api/util/ConvertUtilsESI.java b/cit-esi-api/src/main/java/br/com/centralit/esi/api/util/ConvertUtilsESI.java index 467c544..6bed4bc 100644 --- a/cit-esi-api/src/main/java/br/com/centralit/esi/api/util/ConvertUtilsESI.java +++ b/cit-esi-api/src/main/java/br/com/centralit/esi/api/util/ConvertUtilsESI.java @@ -30,6 +30,7 @@ import br.com.centralit.esi.api.business.rule.BusinessRule; import br.com.centralit.esi.api.design.model.FlowVariable; import br.com.centralit.esi.api.design.model.FlowVersion; import br.com.centralit.esi.api.enumerated.JavaClassEnum; +import br.com.centralit.esi.api.execution.map.MapObjects; import br.com.centralit.esi.exception.EsiBusinessException; import br.com.centralit.esi.exception.EsiExecutionException; import br.com.centralit.framework.esi.enumerated.VariableTypeEnum; @@ -701,4 +702,18 @@ public class ConvertUtilsESI { } } + public static MapObjects cloneMap(HashMap inputMap) { + if (inputMap != null) { + MapObjects map = new MapObjects(); + for (String key : inputMap.keySet()) { + Object obj = inputMap.get(key); + if (obj != null) { + map.put(key, obj); + } + } + return map; + }else{ + return null; + } + } } diff --git a/cit-esi-api/src/main/java/br/com/centralit/esi/api/util/ParseUtilsESI.java b/cit-esi-api/src/main/java/br/com/centralit/esi/api/util/ParseUtilsESI.java index 936f875..a744f80 100644 --- a/cit-esi-api/src/main/java/br/com/centralit/esi/api/util/ParseUtilsESI.java +++ b/cit-esi-api/src/main/java/br/com/centralit/esi/api/util/ParseUtilsESI.java @@ -7,6 +7,11 @@ import java.util.HashMap; import org.apache.commons.lang.text.StrSubstitutor; import org.json.JSONObject; +import br.com.centralit.esi.api.design.model.ScriptCode; +import br.com.centralit.esi.api.enumerated.ScriptEngineTypeEnum; +import br.com.centralit.esi.api.execution.component.ExecuteScript; +import br.com.centralit.esi.api.runtime.RuntimeEnvironment; +import br.com.centralit.esi.api.runtime.RuntimeEnvironmentImpl; import br.com.centralit.framework.util.UtilDate; public class ParseUtilsESI { @@ -28,6 +33,7 @@ public class ParseUtilsESI { private static String parseProperties(String str, HashMap map) { String resolvedString = str; + for (String key : map.keySet()) { String searchProperty = "${"+key+"."; int startPos = resolvedString.indexOf(searchProperty); @@ -41,7 +47,13 @@ public class ParseUtilsESI { Object obj = map.get(key); int i = 1; while (obj != null && i < properties.length) { - obj = parseProperty(obj, properties[i]); + String[] values = properties[i].split("\\|"); + obj = parseProperty(obj, values[0]); + if (values.length > 1) { + obj = applyScript(values[1], obj, map); + arg = arg.replace("|", "\\|"); + } + i++; } if (obj != null) { @@ -99,4 +111,19 @@ public class ParseUtilsESI { return null; } + + private static Object applyScript(String method, Object value, HashMap map) { + String parmName = "arg_"+method; + String script = method+"("+parmName+");"; + ScriptCode scriptCode = new ScriptCode(ScriptEngineTypeEnum.RHINO, script); + + HashMap input = new HashMap(); + input.put(parmName, value); + + RuntimeEnvironment runtimeEnvironment = new RuntimeEnvironmentImpl(null, input); + + Object result = ExecuteScript.execute(runtimeEnvironment, method, scriptCode); + + return result; + } } diff --git a/cit-esi-web/src/main/java/br/com/centralit/listener/StartupListenerEsi.java b/cit-esi-web/src/main/java/br/com/centralit/listener/StartupListenerEsi.java index 9a23868..6d2c2ae 100644 --- a/cit-esi-web/src/main/java/br/com/centralit/listener/StartupListenerEsi.java +++ b/cit-esi-web/src/main/java/br/com/centralit/listener/StartupListenerEsi.java @@ -832,8 +832,9 @@ public class StartupListenerEsi extends UtilStartup implements ApplicationListen str.append(uuid+".importPackage(Packages.org.json);\n"); str.append(uuid+".importPackage(Packages.br.com.centralit.esi.api.enumerated);\n"); str.append(uuid+".importPackage(Packages.br.com.centralit.framework.esi.environment);\n"); - str.append(uuid+".importPackage(Packages.br.com.centralit.framework.esi.enumerated);\n\n"); - + str.append(uuid+".importPackage(Packages.br.com.centralit.framework.esi.enumerated);\n"); + str.append(uuid+".importPackage(Packages.java.text);\n\n"); + str.append("var JSONArray = "+uuid+".JSONArray;\n"); str.append("var JSONObject = "+uuid+".JSONObject;\n"); str.append("var UtilDate = "+uuid+".UtilDate;\n"); @@ -843,12 +844,26 @@ public class StartupListenerEsi extends UtilStartup implements ApplicationListen str.append("var Boolean = "+uuid+".Boolean;\n"); str.append("var Double = "+uuid+".Double;\n"); str.append("var Calendar = "+uuid+".Calendar;\n"); - str.append("var GregorianCalendar = "+uuid+".GregorianCalendar;\n\n"); - str.append("var parameterService = runtimeEnvironment.getObject(\"parameterService\");\n\n"); - str.append("var EnvironmentVariable = importNames.EnvironmentVariable;\n\n"); - str.append("var VariableTypeEnum = importNames.VariableTypeEnum;\n"); - str.append("var HashMap = importNames.HashMap;\n"); - str.append("var StringBuilder = importNames.StringBuilder;\n\n"); + str.append("var GregorianCalendar = "+uuid+".GregorianCalendar;\n"); + str.append("var EnvironmentVariable = "+uuid+".EnvironmentVariable;\n\n"); + str.append("var VariableTypeEnum = "+uuid+".VariableTypeEnum;\n"); + str.append("var HashMap = "+uuid+".HashMap;\n"); + str.append("var StringBuilder = "+uuid+".StringBuilder;\n\n"); + + str.append("var numberFormat = "+uuid+".NumberFormat.getInstance(new importNames.Locale(\"pt\", \"BR\"));\n"); + str.append("numberFormat.setMaximumFractionDigits(2);\n"); + str.append("numberFormat.setMinimumFractionDigits(2);\n\n"); + + str.append("formatMoney = function(obj) {\n"); + str.append(" var value = parseFloat(obj);\n"); + str.append(" return numberFormat.format(value);\n"); + str.append("};\n\n"); + + str.append("formatBoolean = function(obj) {\n"); + str.append(" var value = \"\"+obj;\n"); + str.append(" return value == '1' || value == 'true' || value == 'y' || value == 'yes' ? 'sim' : 'não';\n"); + str.append("};\n\n"); + str.append("addOrUpdateObject = function(name, value) {\n"); str.append(" runtimeEnvironment.addOrUpdateObject(name, value);\n"); diff --git a/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/CssController.js b/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/CssController.js index c9ab60f..15a369b 100644 --- a/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/CssController.js +++ b/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/CssController.js @@ -68,6 +68,7 @@ citApp.controller('CssController', ["$scope", "appService", "CssRepository", "$f if ($scope.css.id) { $scope.uploader.url += '&id=' + $scope.css.id; } + $scope.uploader.url = encodeURI($scope.uploader.url); $scope.uploader.queue[0].url = $scope.uploader.url; $scope.uploader.uploadAll(); diff --git a/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/FileController.js b/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/FileController.js index 1bbe0b3..8d7c67a 100644 --- a/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/FileController.js +++ b/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/FileController.js @@ -69,6 +69,7 @@ citApp.controller('FileController', ["$scope", "appService", "FileRepository", " if ($scope.file.id) { $scope.uploader.url += '&id=' + $scope.file.id; } + $scope.uploader.url = encodeURI($scope.uploader.url); $scope.uploader.queue[0].url = $scope.uploader.url; $scope.uploader.uploadAll(); diff --git a/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ImageController.js b/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ImageController.js index a593354..1fc785d 100644 --- a/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ImageController.js +++ b/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ImageController.js @@ -67,6 +67,7 @@ citApp.controller('ImageController', ["$scope", "appService", "ImageRepository", if ($scope.image.id) { $scope.uploader.url += '&id=' + $scope.image.id; } + $scope.uploader.url = encodeURI($scope.uploader.url); $scope.uploader.queue[0].url = $scope.uploader.url; $scope.uploader.uploadAll(); diff --git a/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/JavaScriptController.js b/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/JavaScriptController.js index 66e7179..f5f17ad 100644 --- a/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/JavaScriptController.js +++ b/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/JavaScriptController.js @@ -68,6 +68,7 @@ citApp.controller('JavaScriptController', ["$scope", "appService", "JavaScriptRe if ($scope.javaScript.id) { $scope.uploader.url += '&id=' + $scope.javaScript.id; } + $scope.uploader.url = encodeURI($scope.uploader.url); $scope.uploader.queue[0].url = $scope.uploader.url; $scope.uploader.uploadAll(); diff --git a/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/PageController.js b/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/PageController.js index 4b324aa..4ce7e1f 100644 --- a/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/PageController.js +++ b/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/PageController.js @@ -69,6 +69,7 @@ citApp.controller('PageController', ["$scope", "appService", "PageRepository", " if ($scope.page.id) { $scope.uploader.url += '&id=' + $scope.page.id; } + $scope.uploader.url = encodeURI($scope.uploader.url); $scope.uploader.queue[0].url = $scope.uploader.url; $scope.uploader.uploadAll(); diff --git a/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ReportFileController.js b/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ReportFileController.js index e90c2af..d90760e 100644 --- a/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ReportFileController.js +++ b/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ReportFileController.js @@ -73,6 +73,7 @@ citApp.controller('ReportFileController', ["$scope", "appService", "ReportReposi if ($scope.report.id) { $scope.uploader.url += '&id=' + $scope.report.id; } + $scope.uploader.url = encodeURI($scope.uploader.url); $scope.uploader.queue[0].url = $scope.uploader.url; $scope.uploader.uploadAll(); -- libgit2 0.21.2