This is an automated email from the ASF dual-hosted git repository.
sergehuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/unomi.git
The following commit(s) were added to refs/heads/master by this push:
new 289eca9b5 UNOMI-1049 Embed json-patch in the services bundle and stop
deploying Guava 16 (#957)
289eca9b5 is described below
commit 289eca9b5e43535cbd8a3194c9f750632e6fce94
Author: Serge Huber <[email protected]>
AuthorDate: Thu Nov 12 21:37:00 2026 +0100
UNOMI-1049 Embed json-patch in the services bundle and stop deploying Guava
16 (#957)
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
kar/src/main/feature/feature.xml | 5 -
pom.xml | 4 +-
services/pom.xml | 33 +++++-
.../impl/patches/PatchServiceImplTest.java | 124 +++++++++++++++++++++
4 files changed, 158 insertions(+), 8 deletions(-)
diff --git a/kar/src/main/feature/feature.xml b/kar/src/main/feature/feature.xml
index 832ce089d..ce51c43f7 100644
--- a/kar/src/main/feature/feature.xml
+++ b/kar/src/main/feature/feature.xml
@@ -52,11 +52,6 @@
<bundle>mvn:com.fasterxml.jackson.datatype/jackson-datatype-jsr310/${jackson.version}</bundle>
<bundle>mvn:com.fasterxml.jackson.module/jackson-module-jaxb-annotations/${jackson.version}</bundle>
- <bundle>mvn:com.github.java-json-tools/btf/${btf.version}</bundle>
-
<bundle>mvn:com.github.java-json-tools/msg-simple/${msg-simple.version}</bundle>
-
<bundle>mvn:com.github.java-json-tools/jackson-coreutils/${jackson-coreutils.version}</bundle>
-
<bundle>mvn:com.github.java-json-tools/json-patch/${json-patch.version}</bundle>
- <bundle>mvn:com.google.guava/guava/${guava.version}</bundle>
<bundle>mvn:org.json/json/${org-json.version}</bundle>
<bundle>mvn:joda-time/joda-time/${joda-time.version}</bundle>
<bundle>mvn:jakarta.annotation/jakarta.annotation-api/${jakarta-annotation-api.version}</bundle>
diff --git a/pom.xml b/pom.xml
index d8a4fe24c..5d24f41cd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -88,9 +88,9 @@
<ipaddress.version>5.6.2</ipaddress.version>
<btf.version>1.3</btf.version>
<msg-simple.version>1.2</msg-simple.version>
- <json-patch.version>1.10</json-patch.version> <!-- Starting version
1.11 OSGI Export Package is wrong causing wiring problems -->
+ <json-patch.version>1.13</json-patch.version> <!-- Embedded in the
services bundle: 1.11+ jars export no OSGi packages -->
<jackson.version>2.18.10</jackson.version>
- <jackson-coreutils.version>1.10</jackson-coreutils.version> <!--
Starting version 1.11 OSGI Export Package is wrong causing wiring problems -->
+ <jackson-coreutils.version>2.0</jackson-coreutils.version>
<guava.version>16.0.1</guava.version>
<guava.version>16.0.1</guava.version>
<org-json.version>20250517</org-json.version>
diff --git a/services/pom.xml b/services/pom.xml
index c0c5740cf..1d2b8415e 100644
--- a/services/pom.xml
+++ b/services/pom.xml
@@ -111,10 +111,40 @@
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
+ <!-- JSON Patch is embedded (its 1.11+ jars export no OSGi packages).
Jackson stays shared. -->
<dependency>
<groupId>com.github.java-json-tools</groupId>
<artifactId>json-patch</artifactId>
- <scope>provided</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>com.github.java-json-tools</groupId>
+ <artifactId>jackson-coreutils</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>com.github.java-json-tools</groupId>
+ <artifactId>msg-simple</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>com.github.java-json-tools</groupId>
+ <artifactId>btf</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
@@ -231,6 +261,7 @@
sun.misc;resolution:=optional,
com.sun.management;resolution:=optional,
org.osgi.service.event*;resolution:=optional,
+ javax.annotation;resolution:=optional,
*
</Import-Package>
</instructions>
diff --git
a/services/src/test/java/org/apache/unomi/services/impl/patches/PatchServiceImplTest.java
b/services/src/test/java/org/apache/unomi/services/impl/patches/PatchServiceImplTest.java
new file mode 100644
index 000000000..e755c4f32
--- /dev/null
+++
b/services/src/test/java/org/apache/unomi/services/impl/patches/PatchServiceImplTest.java
@@ -0,0 +1,124 @@
+/*
+ * 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.unomi.services.impl.patches;
+
+import org.apache.unomi.api.Item;
+import org.apache.unomi.api.Metadata;
+import org.apache.unomi.api.Patch;
+import org.apache.unomi.api.goals.Goal;
+import org.apache.unomi.api.services.cache.CacheableTypeConfig;
+import org.apache.unomi.persistence.spi.PersistenceService;
+import org.apache.unomi.services.TestHelper;
+import org.apache.unomi.services.common.security.ExecutionContextManagerImpl;
+import org.apache.unomi.services.impl.InMemoryPersistenceServiceImpl;
+import org.apache.unomi.services.impl.TestConditionEvaluators;
+import org.apache.unomi.services.impl.cache.MultiTypeCacheServiceImpl;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Exercises the embedded json-patch library through {@link PatchServiceImpl},
with Unomi's
+ * Jackson configuration.
+ */
+class PatchServiceImplTest {
+
+ private static final String TENANT = "test-tenant";
+ private static final String GOAL_ID = "patchedGoal";
+
+ private ExecutionContextManagerImpl executionContextManager;
+ private PersistenceService persistenceService;
+ private MultiTypeCacheServiceImpl cacheService;
+ private PatchServiceImpl patchService;
+
+ @BeforeEach
+ void setUp() {
+ executionContextManager =
TestHelper.createExecutionContextManager(TestHelper.createSecurityService());
+ persistenceService = new
InMemoryPersistenceServiceImpl(executionContextManager,
TestConditionEvaluators.createDispatcher());
+ cacheService = new MultiTypeCacheServiceImpl();
+ cacheService.registerType(CacheableTypeConfig.builder(Goal.class,
Goal.ITEM_TYPE, "goals").withIdExtractor(Goal::getItemId).build());
+
+ patchService = new PatchServiceImpl();
+ patchService.setPersistenceService(persistenceService);
+ patchService.setCacheService(cacheService);
+ patchService.setContextManager(executionContextManager);
+
+ Goal goal = new Goal(new Metadata(null, GOAL_ID, "Old name", "Old
description"));
+ executionContextManager.executeAsTenant(TENANT, () -> {
+ persistenceService.save(goal);
+ cacheService.put(Goal.ITEM_TYPE, GOAL_ID, TENANT, goal);
+ });
+ }
+
+ @Test
+ void appliesJsonPatchOperations() {
+ Patch patch = patch("patch-ok",
+ op("test", "/metadata/name", "Old name"),
+ op("replace", "/metadata/name", "New name"),
+ op("remove", "/metadata/description", null));
+
+ Item result = executionContextManager.executeAsTenant(TENANT, () ->
patchService.patch(patch));
+
+ assertEquals("New name", ((Goal) result).getMetadata().getName());
+ Goal stored = load(GOAL_ID, Goal.class);
+ assertEquals("New name", stored.getMetadata().getName());
+ assertEquals(null, stored.getMetadata().getDescription());
+ }
+
+ @Test
+ void failedPatchLeavesItemUnchanged() {
+ Patch patch = patch("patch-failing-test",
+ op("test", "/metadata/name", "Not the current name"),
+ op("replace", "/metadata/name", "New name"));
+
+ executionContextManager.executeAsTenant(TENANT, () ->
patchService.patch(patch));
+
+ assertEquals("Old name", load(GOAL_ID,
Goal.class).getMetadata().getName());
+ assertNotNull(load("patch-failing-test",
Patch.class).getLastApplication());
+ }
+
+ private <T extends Item> T load(String id, Class<T> type) {
+ return executionContextManager.executeAsTenant(TENANT, () ->
persistenceService.load(id, type));
+ }
+
+ @SafeVarargs
+ private static Patch patch(String id, Map<String, Object>... operations) {
+ Patch patch = new Patch();
+ patch.setItemId(id);
+ patch.setPatchedItemId(GOAL_ID);
+ patch.setPatchedItemType("goal");
+ patch.setOperation("patch");
+ patch.setData(Arrays.asList(operations));
+ return patch;
+ }
+
+ private static Map<String, Object> op(String op, String path, Object
value) {
+ Map<String, Object> operation = new LinkedHashMap<>();
+ operation.put("op", op);
+ operation.put("path", path);
+ if (value != null) {
+ operation.put("value", value);
+ }
+ return operation;
+ }
+}