From 60500d13648a1d58e8121392a819baaeea1b849e Mon Sep 17 00:00:00 2001 From: Robert Csakany Date: Thu, 1 Oct 2020 00:22:03 +0200 Subject: [PATCH] JNG-1659 DAO reverted back and Payload transient map keys are added. --- .../java/hu/blackbelt/judo/dao/api/DAO.java | 64 ------------------- .../blackbelt/judo/dao/api/PayloadImpl.java | 26 ++++---- .../judo/dao/api/PayloadImplTest.java | 9 +++ 3 files changed, 24 insertions(+), 75 deletions(-) diff --git a/src/main/java/hu/blackbelt/judo/dao/api/DAO.java b/src/main/java/hu/blackbelt/judo/dao/api/DAO.java index b12591e..eb7742e 100644 --- a/src/main/java/hu/blackbelt/judo/dao/api/DAO.java +++ b/src/main/java/hu/blackbelt/judo/dao/api/DAO.java @@ -85,19 +85,6 @@ public interface DAO { */ Payload create(EClass clazz, Payload payload); - /** - * Create a new instance of a given mapped transfer object type. - *

- * This operation can be used by JCL (create), exposed graphs (ExposedGraph#create) and custom Java sources. Mapped - * transfer object must have a filter to restrict which kind of instances can be created by exposed services. - * - * @param clazz mapped transfer object type - * @param payload instance to create - * @param newIds output parameter that new IDs will be added to - * @return created instance - */ - Payload create(EClass clazz, Payload payload, Collection newIds); - /** * Update a mapped transfer object. *

@@ -109,18 +96,6 @@ public interface DAO { */ Payload update(EClass clazz, Payload payload); - /** - * Update a mapped transfer object. - *

- * This operation can be used by JCL (update) and custom Java sources. - * - * @param clazz mapped transfer object type - * @param payload instance to update - * @param newIds output parameter that new IDs will be added to - * @return updated instance - */ - Payload update(EClass clazz, Payload payload, Collection newIds); - /** * Delete a mapped transfer object. *

@@ -210,19 +185,6 @@ public interface DAO { */ Payload updateReferencedInstancesOf(EClass clazz, EReference reference, Payload payload); - /** - * Update a mapped transfer object of a given reference (static navigation). - *

- * This operation can be used by exposed graphs (ExposedGraph#update). - * - * @param clazz mapped transfer object type - * @param reference static navigation - * @param payload instance to update - * @param newIds output parameter that new IDs will be added to - * @return updated instance - */ - Payload updateReferencedInstancesOf(EClass clazz, EReference reference, Payload payload, Collection newIds); - /** * Delete a mapped transfer object of a given reference (static navigation). *

@@ -321,19 +283,6 @@ public interface DAO { */ Payload createNavigationInstanceAt(ID id, EReference reference, Payload payload); - /** - * Create a mapped transfer object of a given reference from a given mapped transfer object. - *

- * This operation can be used by bound operations (TransferObjectRelation#create). - * - * @param id mapped transfer object ID in which the new instance will be created - * @param reference transfer object relation that the new instance will be linked to - * @param payload instance to create - * @param newIds output parameter that new IDs will be added to - * @return created instance - */ - Payload createNavigationInstanceAt(ID id, EReference reference, Payload payload, Collection newIds); - /** * Update a mapped transfer object of a given reference from a given mapped transfer object. *

@@ -346,19 +295,6 @@ public interface DAO { */ Payload updateNavigationInstanceAt(ID id, EReference reference, Payload payload); - /** - * Update a mapped transfer object of a given reference from a given mapped transfer object. - *

- * This operation can be used by bound operations (TransferObjectRelation#update). - * - * @param id mapped transfer object ID in which the instance to update can be found - * @param reference transfer object relation that the instance to update is linked in (pre condition) - * @param payload instance to update - * @param newIds output parameter that new IDs will be added to - * @return updated instance - */ - Payload updateNavigationInstanceAt(ID id, EReference reference, Payload payload, Collection newIds); - /** * Delete a mapped transfer object of a given reference from a given mapped transfer object. *

diff --git a/src/main/java/hu/blackbelt/judo/dao/api/PayloadImpl.java b/src/main/java/hu/blackbelt/judo/dao/api/PayloadImpl.java index a5a92ee..d729cd3 100644 --- a/src/main/java/hu/blackbelt/judo/dao/api/PayloadImpl.java +++ b/src/main/java/hu/blackbelt/judo/dao/api/PayloadImpl.java @@ -1,10 +1,5 @@ package hu.blackbelt.judo.dao.api; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSortedMap; -import com.google.common.collect.ImmutableSortedSet; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.TypeAdapter; @@ -14,7 +9,6 @@ import java.io.IOException; import java.time.ZonedDateTime; import java.util.Collection; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -41,6 +35,7 @@ public ZonedDateTime read(JsonReader in) throws IOException { .enableComplexMapKeySerialization() .setPrettyPrinting() .create(); + public static final String TRANSIENT_PREFIX = "__$"; Map internal; @@ -131,12 +126,21 @@ public boolean equals(Object obj) { if (!(obj instanceof Map)) { return false; } - Map right = (Map) obj; + Map right = new TreeMap((Map) obj); + Map left = new TreeMap(internal); - if (!(right instanceof TreeMap)) { - right = new TreeMap(right); - } - return internal.equals(right); + // Remove hidden fields + ((Set) right.keySet().stream() + .filter(k -> k.toString().startsWith(TRANSIENT_PREFIX)) + .collect(Collectors.toSet())) + .forEach(k -> right.remove(k)); + + ((Set) left.keySet().stream() + .filter(k -> k.toString().startsWith(TRANSIENT_PREFIX)) + .collect(Collectors.toSet())) + .forEach(k -> left.remove(k)); + + return left.equals(right); } @Override diff --git a/src/test/java/hu/blackbelt/judo/dao/api/PayloadImplTest.java b/src/test/java/hu/blackbelt/judo/dao/api/PayloadImplTest.java index 1794348..216cad3 100644 --- a/src/test/java/hu/blackbelt/judo/dao/api/PayloadImplTest.java +++ b/src/test/java/hu/blackbelt/judo/dao/api/PayloadImplTest.java @@ -56,4 +56,13 @@ public void testPayloadStatic() { } + @Test + public void testEquls() { + Payload payload = Payload.map("k1", null, "k2", "string"); + assertThat(Payload.map("k2", "string", "k1", null), equalTo(Payload.map("k1", null, "k2", "string"))); + assertThat(Payload.map("k2", "string", "k1", null, "__$created", true), equalTo(Payload.map("k1", null, "k2", "string"))); + + } + + } \ No newline at end of file