Skip to content

Commit

Permalink
JNG-1659 DAO reverted back and Payload transient map keys are added.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertcsakany committed Sep 30, 2020
1 parent 03192d3 commit 60500d1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 75 deletions.
64 changes: 0 additions & 64 deletions src/main/java/hu/blackbelt/judo/dao/api/DAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,6 @@ public interface DAO<ID> {
*/
Payload create(EClass clazz, Payload payload);

/**
* Create a new instance of a given mapped transfer object type.
* <p>
* 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<ID> newIds);

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

/**
* Update a mapped transfer object.
* <p>
* 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<ID> newIds);

/**
* Delete a mapped transfer object.
* <p>
Expand Down Expand Up @@ -210,19 +185,6 @@ public interface DAO<ID> {
*/
Payload updateReferencedInstancesOf(EClass clazz, EReference reference, Payload payload);

/**
* Update a mapped transfer object of a given reference (static navigation).
* <p>
* 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<ID> newIds);

/**
* Delete a mapped transfer object of a given reference (static navigation).
* <p>
Expand Down Expand Up @@ -321,19 +283,6 @@ public interface DAO<ID> {
*/
Payload createNavigationInstanceAt(ID id, EReference reference, Payload payload);

/**
* Create a mapped transfer object of a given reference from a given mapped transfer object.
* <p>
* 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<ID> newIds);

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

/**
* Update a mapped transfer object of a given reference from a given mapped transfer object.
* <p>
* 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<ID> newIds);

/**
* Delete a mapped transfer object of a given reference from a given mapped transfer object.
* <p>
Expand Down
26 changes: 15 additions & 11 deletions src/main/java/hu/blackbelt/judo/dao/api/PayloadImpl.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -41,6 +35,7 @@ public ZonedDateTime read(JsonReader in) throws IOException {
.enableComplexMapKeySerialization()
.setPrettyPrinting()
.create();
public static final String TRANSIENT_PREFIX = "__$";

Map<String, Object> internal;

Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/hu/blackbelt/judo/dao/api/PayloadImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")));

}


}

0 comments on commit 60500d1

Please sign in to comment.