You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by "fjtirado (via GitHub)" <gi...@apache.org> on 2024/02/16 15:56:12 UTC

[PR] [Fix_#1989] Considering '.' in variable name when merging variables [incubator-kie-kogito-apps]

fjtirado opened a new pull request, #1991:
URL: https://github.com/apache/incubator-kie-kogito-apps/pull/1991

   Fixes https://github.com/apache/incubator-kie-kogito-apps/issues/1989


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org


Re: [PR] [Fix_#1989] Considering '.' in variable name when merging variables [incubator-kie-kogito-apps]

Posted by "fjtirado (via GitHub)" <gi...@apache.org>.
fjtirado commented on code in PR #1991:
URL: https://github.com/apache/incubator-kie-kogito-apps/pull/1991#discussion_r1492743730


##########
data-index/data-index-common/src/main/java/org/kie/kogito/index/json/JsonUtils.java:
##########
@@ -50,4 +54,20 @@ public static ObjectMapper configure(ObjectMapper objectMapper) {
         objectMapper.registerModule(module);
         return objectMapper;
     }
+
+    public static ObjectNode mergeVariable(String variableName, Object variableValue, ObjectNode variables) {
+        return (ObjectNode) MergeUtils.merge(getObjectNode(variableName, variableValue), variables);
+    }
+
+    private static ObjectNode getObjectNode(String variableName, Object variableValue) {

Review Comment:
   yes, you are right



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org


Re: [PR] [Fix_#1989] Considering '.' in variable name when merging variables [incubator-kie-kogito-apps]

Posted by "wmedvede (via GitHub)" <gi...@apache.org>.
wmedvede commented on code in PR #1991:
URL: https://github.com/apache/incubator-kie-kogito-apps/pull/1991#discussion_r1492712548


##########
data-index/data-index-common/src/test/java/org/kie/kogito/index/json/JsonUtilsTest.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.kie.kogito.index.json;
+
+import org.junit.jupiter.api.Test;
+import org.kie.kogito.jackson.utils.ObjectMapperFactory;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class JsonUtilsTest {
+
+    @Test
+    void testMergeWithDot() {
+        ObjectNode expected = ObjectMapperFactory.get().createObjectNode().set("Javier", ObjectMapperFactory.get().createObjectNode().put("ito", "manolo"));
+        assertThat(JsonUtils.mergeVariable("Javier.ito", "manolo", null)).isEqualTo(expected);
+    }
+
+    @Test
+    void testSimpleMerge() {
+        ObjectNode expected = ObjectMapperFactory.get().createObjectNode().put("Javierito", "manolo");
+        assertThat(JsonUtils.mergeVariable("Javierito", "manolo", null)).isEqualTo(expected);
+    }
+
+    @Test
+    void testComplexMergeWithDot() {
+        ObjectNode expected = ObjectMapperFactory.get().createObjectNode().set("Javier", ObjectMapperFactory.get().createObjectNode().put("ito", "manolo").put("ato", "pepe"));

Review Comment:
   your call, but I believe using more standard names, "bob", "alice", "user1", "user2" are more follow-able.



##########
data-index/data-index-common/src/main/java/org/kie/kogito/index/json/JsonUtils.java:
##########
@@ -50,4 +54,20 @@ public static ObjectMapper configure(ObjectMapper objectMapper) {
         objectMapper.registerModule(module);
         return objectMapper;
     }
+
+    public static ObjectNode mergeVariable(String variableName, Object variableValue, ObjectNode variables) {
+        return (ObjectNode) MergeUtils.merge(getObjectNode(variableName, variableValue), variables);
+    }
+
+    private static ObjectNode getObjectNode(String variableName, Object variableValue) {

Review Comment:
   Sorry for being picky, but i believe this method name with "get" is a bit confusing, Id prefer a name like createVariableNode, or something similar.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org


Re: [PR] [Fix_#1989] Considering '.' in variable name when merging variables [incubator-kie-kogito-apps]

Posted by "fjtirado (via GitHub)" <gi...@apache.org>.
fjtirado commented on code in PR #1991:
URL: https://github.com/apache/incubator-kie-kogito-apps/pull/1991#discussion_r1492765671


##########
data-index/data-index-common/src/test/java/org/kie/kogito/index/json/JsonUtilsTest.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.kie.kogito.index.json;
+
+import org.junit.jupiter.api.Test;
+import org.kie.kogito.jackson.utils.ObjectMapperFactory;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class JsonUtilsTest {
+
+    @Test
+    void testMergeWithDot() {
+        ObjectNode expected = ObjectMapperFactory.get().createObjectNode().set("Javier", ObjectMapperFactory.get().createObjectNode().put("ito", "manolo"));
+        assertThat(JsonUtils.mergeVariable("Javier.ito", "manolo", null)).isEqualTo(expected);
+    }
+
+    @Test
+    void testSimpleMerge() {
+        ObjectNode expected = ObjectMapperFactory.get().createObjectNode().put("Javierito", "manolo");
+        assertThat(JsonUtils.mergeVariable("Javierito", "manolo", null)).isEqualTo(expected);
+    }
+
+    @Test
+    void testComplexMergeWithDot() {
+        ObjectNode expected = ObjectMapperFactory.get().createObjectNode().set("Javier", ObjectMapperFactory.get().createObjectNode().put("ito", "manolo").put("ato", "pepe"));

Review Comment:
   I have to stick with Manolo and Pepe for patriotic reasons ;)
   Changing Javier.ito to key.user1 ;)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org