Commit 24fec1d5d2e08a37512777f6c2a02aaaad69a21b
1 parent
6e12f555
Exists in
master
Criação de funcionalidade para formatação de objetos no RHINO
Showing
10 changed files
with
75 additions
and
10 deletions
Show diff stats
cit-esi-api/src/main/java/br/com/centralit/esi/api/runtime/RuntimeEnvironmentImpl.java
... | ... | @@ -309,7 +309,9 @@ public class RuntimeEnvironmentImpl implements RuntimeEnvironment { |
309 | 309 | ,false) |
310 | 310 | .setInputMap(inputMap); |
311 | 311 | |
312 | - this.initialize(input, flowVersion, objects); | |
312 | + MapObjects map = ConvertUtilsESI.cloneMap(inputMap); | |
313 | + | |
314 | + this.initialize(input, flowVersion, map); | |
313 | 315 | } |
314 | 316 | |
315 | 317 | @Override | ... | ... |
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; |
30 | 30 | import br.com.centralit.esi.api.design.model.FlowVariable; |
31 | 31 | import br.com.centralit.esi.api.design.model.FlowVersion; |
32 | 32 | import br.com.centralit.esi.api.enumerated.JavaClassEnum; |
33 | +import br.com.centralit.esi.api.execution.map.MapObjects; | |
33 | 34 | import br.com.centralit.esi.exception.EsiBusinessException; |
34 | 35 | import br.com.centralit.esi.exception.EsiExecutionException; |
35 | 36 | import br.com.centralit.framework.esi.enumerated.VariableTypeEnum; |
... | ... | @@ -701,4 +702,18 @@ public class ConvertUtilsESI { |
701 | 702 | } |
702 | 703 | } |
703 | 704 | |
705 | + public static MapObjects cloneMap(HashMap<String, Object> inputMap) { | |
706 | + if (inputMap != null) { | |
707 | + MapObjects map = new MapObjects(); | |
708 | + for (String key : inputMap.keySet()) { | |
709 | + Object obj = inputMap.get(key); | |
710 | + if (obj != null) { | |
711 | + map.put(key, obj); | |
712 | + } | |
713 | + } | |
714 | + return map; | |
715 | + }else{ | |
716 | + return null; | |
717 | + } | |
718 | + } | |
704 | 719 | } | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/util/ParseUtilsESI.java
... | ... | @@ -7,6 +7,11 @@ import java.util.HashMap; |
7 | 7 | import org.apache.commons.lang.text.StrSubstitutor; |
8 | 8 | import org.json.JSONObject; |
9 | 9 | |
10 | +import br.com.centralit.esi.api.design.model.ScriptCode; | |
11 | +import br.com.centralit.esi.api.enumerated.ScriptEngineTypeEnum; | |
12 | +import br.com.centralit.esi.api.execution.component.ExecuteScript; | |
13 | +import br.com.centralit.esi.api.runtime.RuntimeEnvironment; | |
14 | +import br.com.centralit.esi.api.runtime.RuntimeEnvironmentImpl; | |
10 | 15 | import br.com.centralit.framework.util.UtilDate; |
11 | 16 | |
12 | 17 | public class ParseUtilsESI { |
... | ... | @@ -28,6 +33,7 @@ public class ParseUtilsESI { |
28 | 33 | |
29 | 34 | private static String parseProperties(String str, HashMap<String, Object> map) { |
30 | 35 | String resolvedString = str; |
36 | + | |
31 | 37 | for (String key : map.keySet()) { |
32 | 38 | String searchProperty = "${"+key+"."; |
33 | 39 | int startPos = resolvedString.indexOf(searchProperty); |
... | ... | @@ -41,7 +47,13 @@ public class ParseUtilsESI { |
41 | 47 | Object obj = map.get(key); |
42 | 48 | int i = 1; |
43 | 49 | while (obj != null && i < properties.length) { |
44 | - obj = parseProperty(obj, properties[i]); | |
50 | + String[] values = properties[i].split("\\|"); | |
51 | + obj = parseProperty(obj, values[0]); | |
52 | + if (values.length > 1) { | |
53 | + obj = applyScript(values[1], obj, map); | |
54 | + arg = arg.replace("|", "\\|"); | |
55 | + } | |
56 | + | |
45 | 57 | i++; |
46 | 58 | } |
47 | 59 | if (obj != null) { |
... | ... | @@ -99,4 +111,19 @@ public class ParseUtilsESI { |
99 | 111 | return null; |
100 | 112 | } |
101 | 113 | |
114 | + | |
115 | + private static Object applyScript(String method, Object value, HashMap<String, Object> map) { | |
116 | + String parmName = "arg_"+method; | |
117 | + String script = method+"("+parmName+");"; | |
118 | + ScriptCode scriptCode = new ScriptCode(ScriptEngineTypeEnum.RHINO, script); | |
119 | + | |
120 | + HashMap<String, Object> input = new HashMap<String, Object>(); | |
121 | + input.put(parmName, value); | |
122 | + | |
123 | + RuntimeEnvironment runtimeEnvironment = new RuntimeEnvironmentImpl(null, input); | |
124 | + | |
125 | + Object result = ExecuteScript.execute(runtimeEnvironment, method, scriptCode); | |
126 | + | |
127 | + return result; | |
128 | + } | |
102 | 129 | } | ... | ... |
cit-esi-web/src/main/java/br/com/centralit/listener/StartupListenerEsi.java
... | ... | @@ -832,8 +832,9 @@ public class StartupListenerEsi extends UtilStartup implements ApplicationListen |
832 | 832 | str.append(uuid+".importPackage(Packages.org.json);\n"); |
833 | 833 | str.append(uuid+".importPackage(Packages.br.com.centralit.esi.api.enumerated);\n"); |
834 | 834 | str.append(uuid+".importPackage(Packages.br.com.centralit.framework.esi.environment);\n"); |
835 | - str.append(uuid+".importPackage(Packages.br.com.centralit.framework.esi.enumerated);\n\n"); | |
836 | - | |
835 | + str.append(uuid+".importPackage(Packages.br.com.centralit.framework.esi.enumerated);\n"); | |
836 | + str.append(uuid+".importPackage(Packages.java.text);\n\n"); | |
837 | + | |
837 | 838 | str.append("var JSONArray = "+uuid+".JSONArray;\n"); |
838 | 839 | str.append("var JSONObject = "+uuid+".JSONObject;\n"); |
839 | 840 | str.append("var UtilDate = "+uuid+".UtilDate;\n"); |
... | ... | @@ -843,12 +844,26 @@ public class StartupListenerEsi extends UtilStartup implements ApplicationListen |
843 | 844 | str.append("var Boolean = "+uuid+".Boolean;\n"); |
844 | 845 | str.append("var Double = "+uuid+".Double;\n"); |
845 | 846 | str.append("var Calendar = "+uuid+".Calendar;\n"); |
846 | - str.append("var GregorianCalendar = "+uuid+".GregorianCalendar;\n\n"); | |
847 | - str.append("var parameterService = runtimeEnvironment.getObject(\"parameterService\");\n\n"); | |
848 | - str.append("var EnvironmentVariable = importNames.EnvironmentVariable;\n\n"); | |
849 | - str.append("var VariableTypeEnum = importNames.VariableTypeEnum;\n"); | |
850 | - str.append("var HashMap = importNames.HashMap;\n"); | |
851 | - str.append("var StringBuilder = importNames.StringBuilder;\n\n"); | |
847 | + str.append("var GregorianCalendar = "+uuid+".GregorianCalendar;\n"); | |
848 | + str.append("var EnvironmentVariable = "+uuid+".EnvironmentVariable;\n\n"); | |
849 | + str.append("var VariableTypeEnum = "+uuid+".VariableTypeEnum;\n"); | |
850 | + str.append("var HashMap = "+uuid+".HashMap;\n"); | |
851 | + str.append("var StringBuilder = "+uuid+".StringBuilder;\n\n"); | |
852 | + | |
853 | + str.append("var numberFormat = "+uuid+".NumberFormat.getInstance(new importNames.Locale(\"pt\", \"BR\"));\n"); | |
854 | + str.append("numberFormat.setMaximumFractionDigits(2);\n"); | |
855 | + str.append("numberFormat.setMinimumFractionDigits(2);\n\n"); | |
856 | + | |
857 | + str.append("formatMoney = function(obj) {\n"); | |
858 | + str.append(" var value = parseFloat(obj);\n"); | |
859 | + str.append(" return numberFormat.format(value);\n"); | |
860 | + str.append("};\n\n"); | |
861 | + | |
862 | + str.append("formatBoolean = function(obj) {\n"); | |
863 | + str.append(" var value = \"\"+obj;\n"); | |
864 | + str.append(" return value == '1' || value == 'true' || value == 'y' || value == 'yes' ? 'sim' : 'não';\n"); | |
865 | + str.append("};\n\n"); | |
866 | + | |
852 | 867 | |
853 | 868 | str.append("addOrUpdateObject = function(name, value) {\n"); |
854 | 869 | str.append(" runtimeEnvironment.addOrUpdateObject(name, value);\n"); | ... | ... |
cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/CssController.js
... | ... | @@ -68,6 +68,7 @@ citApp.controller('CssController', ["$scope", "appService", "CssRepository", "$f |
68 | 68 | if ($scope.css.id) { |
69 | 69 | $scope.uploader.url += '&id=' + $scope.css.id; |
70 | 70 | } |
71 | + $scope.uploader.url = encodeURI($scope.uploader.url); | |
71 | 72 | |
72 | 73 | $scope.uploader.queue[0].url = $scope.uploader.url; |
73 | 74 | $scope.uploader.uploadAll(); | ... | ... |
cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/FileController.js
... | ... | @@ -69,6 +69,7 @@ citApp.controller('FileController', ["$scope", "appService", "FileRepository", " |
69 | 69 | if ($scope.file.id) { |
70 | 70 | $scope.uploader.url += '&id=' + $scope.file.id; |
71 | 71 | } |
72 | + $scope.uploader.url = encodeURI($scope.uploader.url); | |
72 | 73 | |
73 | 74 | $scope.uploader.queue[0].url = $scope.uploader.url; |
74 | 75 | $scope.uploader.uploadAll(); | ... | ... |
cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ImageController.js
... | ... | @@ -67,6 +67,7 @@ citApp.controller('ImageController', ["$scope", "appService", "ImageRepository", |
67 | 67 | if ($scope.image.id) { |
68 | 68 | $scope.uploader.url += '&id=' + $scope.image.id; |
69 | 69 | } |
70 | + $scope.uploader.url = encodeURI($scope.uploader.url); | |
70 | 71 | |
71 | 72 | $scope.uploader.queue[0].url = $scope.uploader.url; |
72 | 73 | $scope.uploader.uploadAll(); | ... | ... |
cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/JavaScriptController.js
... | ... | @@ -68,6 +68,7 @@ citApp.controller('JavaScriptController', ["$scope", "appService", "JavaScriptRe |
68 | 68 | if ($scope.javaScript.id) { |
69 | 69 | $scope.uploader.url += '&id=' + $scope.javaScript.id; |
70 | 70 | } |
71 | + $scope.uploader.url = encodeURI($scope.uploader.url); | |
71 | 72 | |
72 | 73 | $scope.uploader.queue[0].url = $scope.uploader.url; |
73 | 74 | $scope.uploader.uploadAll(); | ... | ... |
cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/PageController.js
... | ... | @@ -69,6 +69,7 @@ citApp.controller('PageController', ["$scope", "appService", "PageRepository", " |
69 | 69 | if ($scope.page.id) { |
70 | 70 | $scope.uploader.url += '&id=' + $scope.page.id; |
71 | 71 | } |
72 | + $scope.uploader.url = encodeURI($scope.uploader.url); | |
72 | 73 | |
73 | 74 | $scope.uploader.queue[0].url = $scope.uploader.url; |
74 | 75 | $scope.uploader.uploadAll(); | ... | ... |
cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ReportFileController.js
... | ... | @@ -73,6 +73,7 @@ citApp.controller('ReportFileController', ["$scope", "appService", "ReportReposi |
73 | 73 | if ($scope.report.id) { |
74 | 74 | $scope.uploader.url += '&id=' + $scope.report.id; |
75 | 75 | } |
76 | + $scope.uploader.url = encodeURI($scope.uploader.url); | |
76 | 77 | |
77 | 78 | $scope.uploader.queue[0].url = $scope.uploader.url; |
78 | 79 | $scope.uploader.uploadAll(); | ... | ... |