[ofbiz-framework] branch trunk updated: Fixed: Use non string parameters on a update-area failed when comme from a JWToken (OFBIZ-12749)

2023-02-10 Thread jleroux
This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
 new 3c0cec35a5 Fixed: Use non string parameters on a update-area failed 
when comme from a JWToken (OFBIZ-12749)
3c0cec35a5 is described below

commit 3c0cec35a563cc17ec7a6cbc0e4945dc9914edd1
Author: Jacques Le Roux 
AuthorDate: Fri Feb 10 10:37:46 2023 +0100

Fixed: Use non string parameters on a update-area failed when comme from a 
JWToken (OFBIZ-12749)

Adds missing ASL2 header
---
 .../apache/ofbiz/widget/model/ModelFormTest.java| 21 -
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git 
a/framework/widget/src/test/java/org/apache/ofbiz/widget/model/ModelFormTest.java
 
b/framework/widget/src/test/java/org/apache/ofbiz/widget/model/ModelFormTest.java
index 87c08cc392..f02490d877 100644
--- 
a/framework/widget/src/test/java/org/apache/ofbiz/widget/model/ModelFormTest.java
+++ 
b/framework/widget/src/test/java/org/apache/ofbiz/widget/model/ModelFormTest.java
@@ -1,12 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.ofbiz.widget.model;
 
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.any;
 
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+
 import org.apache.ofbiz.base.conversion.ConversionException;
 import org.apache.ofbiz.base.conversion.JSONConverters;
 import org.apache.ofbiz.base.util.UtilMisc;



[ofbiz-framework] branch trunk updated: Fixed: Use non string parameters on a update-area failed when comme from a JWToken (OFBIZ-12749)

2023-01-27 Thread nmalin
This is an automated email from the ASF dual-hosted git repository.

nmalin pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
 new aaee98002e Fixed: Use non string parameters on a update-area failed 
when comme from a JWToken (OFBIZ-12749)
aaee98002e is described below

commit aaee98002e34b68da214a16d35ffc4372979b18d
Author: Nicolas Malin 
AuthorDate: Fri Jan 27 17:27:03 2023 +0100

Fixed: Use non string parameters on a update-area failed when comme from a 
JWToken (OFBIZ-12749)

When define a update-area with some parameters as List or Map the 
conversion failed due to a bad management of this case when the creation come 
from a JWToken.










The link generate for the callback contains the variable myField with the 
class name and not serialized List "['myCase']"
---
 .../ofbiz/widget/model/CommonWidgetModels.java | 22 +++
 .../org/apache/ofbiz/widget/model/ModelForm.java   |  4 +-
 .../apache/ofbiz/widget/model/ModelFormTest.java   | 75 ++
 3 files changed, 99 insertions(+), 2 deletions(-)

diff --git 
a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/CommonWidgetModels.java
 
b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/CommonWidgetModels.java
index 258d6a9e59..9992ec14cb 100644
--- 
a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/CommonWidgetModels.java
+++ 
b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/CommonWidgetModels.java
@@ -31,6 +31,8 @@ import java.util.Map;
 import java.util.TimeZone;
 
 import org.apache.ofbiz.base.util.Debug;
+import org.apache.ofbiz.base.util.GeneralException;
+import org.apache.ofbiz.base.util.ObjectType;
 import org.apache.ofbiz.base.util.UtilCodec;
 import org.apache.ofbiz.base.util.UtilDateTime;
 import org.apache.ofbiz.base.util.UtilGenerics;
@@ -774,4 +776,24 @@ public final class CommonWidgetModels {
 return null;
 }
 }
+
+/**
+ * Object dedicate to the creation of parameter object
+ */
+public static class ParameterFactory {
+
+/**
+ * For an entry map return a parameter after convert correctly the 
value
+ * @param entry
+ * @return
+ */
+public static Parameter create(Map.Entry entry) {
+try {
+return new CommonWidgetModels.Parameter(entry.getKey(),
+(String) 
ObjectType.simpleTypeOrObjectConvert(entry.getValue(), "String", null, null), 
false);
+} catch (GeneralException e) {
+throw new RuntimeException(e);
+}
+}
+}
 }
diff --git 
a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java 
b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java
index a7d1cdf19a..c214862cd7 100644
--- 
a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java
+++ 
b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java
@@ -2505,7 +2505,7 @@ public abstract class ModelForm extends ModelWidget {
 }
 
 /**
- * Retrieva Jwt from context, validate it and generate UpdateArea 
Object
+ * Retrieve a Jwt from context, validate it and generate UpdateArea 
Object
  * @return UpdateArea object
  */
 public static ModelForm.UpdateArea fromJwtToken(Map 
context) {
@@ -2541,7 +2541,7 @@ public abstract class ModelForm extends ModelWidget {
 parameters != null
 ? parameters.entrySet()
 .stream()
-.map(entry -> new 
CommonWidgetModels.Parameter(entry.getKey(), (String) entry.getValue(), false))
+.map(entry -> 
CommonWidgetModels.ParameterFactory.create(entry))
 .collect(Collectors.toList())
 : new ArrayList<>());
 }
diff --git 
a/framework/widget/src/test/java/org/apache/ofbiz/widget/model/ModelFormTest.java
 
b/framework/widget/src/test/java/org/apache/ofbiz/widget/model/ModelFormTest.java
new file mode 100644
index 00..f3d6aef2c3
--- /dev/null
+++ 
b/framework/widget/src/test/java/org/apache/ofbiz/widget/model/ModelFormTest.java
@@ -0,0 +1,75 @@
+package org.apache.ofbiz.widget.model;
+
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.any;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.ofbiz.base.conversion.ConversionException;
+import org.apache.ofbiz.base.conversion.JSONConverters;
+import org.apache.ofbiz.base.util.UtilMisc;
+import org.apache.ofbiz.entity.Delegator;
+import org.apache.ofbiz.entity.GenericEntityException;
+import