From 14099ca50e1ea525c6fe86aff8c12bd02199176c Mon Sep 17 00:00:00 2001 From: Doris Lam Date: Thu, 6 Oct 2022 12:47:46 -0700 Subject: [PATCH 1/6] add delete field with elements post --- .../org/openmbee/mms/core/objects/ElementsRequest.java | 10 ++++++++++ .../openmbee/mms/crud/services/DefaultNodeService.java | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/core/src/main/java/org/openmbee/mms/core/objects/ElementsRequest.java b/core/src/main/java/org/openmbee/mms/core/objects/ElementsRequest.java index 1450473b7..9b26dd8fa 100644 --- a/core/src/main/java/org/openmbee/mms/core/objects/ElementsRequest.java +++ b/core/src/main/java/org/openmbee/mms/core/objects/ElementsRequest.java @@ -10,6 +10,8 @@ public class ElementsRequest extends BaseRequest { @Schema(required = true) private List elements; + private List deletes; + public List getElements() { return elements; } @@ -17,4 +19,12 @@ public List getElements() { public void setElements(List elements) { this.elements = elements; } + + public List getDeletes() { + return deletes; + } + + public void setDeletes(List deletes) { + this.deletes = deletes; + } } diff --git a/crud/src/main/java/org/openmbee/mms/crud/services/DefaultNodeService.java b/crud/src/main/java/org/openmbee/mms/crud/services/DefaultNodeService.java index 59b860992..1533b9003 100644 --- a/crud/src/main/java/org/openmbee/mms/crud/services/DefaultNodeService.java +++ b/crud/src/main/java/org/openmbee/mms/crud/services/DefaultNodeService.java @@ -194,6 +194,15 @@ public ElementsCommitResponse createOrUpdate(String projectId, String refId, Ele .processPostJson(req.getElements(), overwriteJson, createCommit(user, refId, projectId, req, commitId), this); + if (req.getDeletes() != null && !req.getDeletes().isEmpty()) { + NodeChangeInfo delete = nodeDeleteHelper.processDeleteJson(req.getDeletes(), createCommit(user, refId, projectId, req, info.getCommitJson().getCommitId()), this); + info.getCommitJson().getDeleted().addAll(delete.getCommitJson().getDeleted()); + info.getDeletedMap().putAll(delete.getDeletedMap()); + info.getToSaveNodeMap().putAll(delete.getToSaveNodeMap()); + info.getOldDocIds().addAll(delete.getOldDocIds()); + info.getRejected().putAll(delete.getRejected()); + } + commitChanges(info); ElementsCommitResponse response = new ElementsCommitResponse(); From 1fc0082379a33f1f29d1790a8b3833aa5827d024 Mon Sep 17 00:00:00 2001 From: Doris Lam Date: Mon, 17 Oct 2022 17:59:39 -0700 Subject: [PATCH 2/6] prevent overwrite option on element update to unlink artifacts --- .../mms/artifacts/pubsub/ArtifactsElementsHookSubscriber.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/artifacts/src/main/java/org/openmbee/mms/artifacts/pubsub/ArtifactsElementsHookSubscriber.java b/artifacts/src/main/java/org/openmbee/mms/artifacts/pubsub/ArtifactsElementsHookSubscriber.java index a606360ac..56756bdf1 100644 --- a/artifacts/src/main/java/org/openmbee/mms/artifacts/pubsub/ArtifactsElementsHookSubscriber.java +++ b/artifacts/src/main/java/org/openmbee/mms/artifacts/pubsub/ArtifactsElementsHookSubscriber.java @@ -20,7 +20,8 @@ public void acceptHook(Object payload) { } ElementUpdateHook elementUpdateHook = (ElementUpdateHook) payload; - if(elementUpdateHook.getElements() != null) { + if(elementUpdateHook.getElements() != null && + elementUpdateHook.getParams().getOrDefault("overwrite", "false").equals("false")) { //Ignore any artifact changes coming in outside of the Artifacts Controller elementUpdateHook.getElements().parallelStream().forEach(v -> { v.remove(ArtifactJson.ARTIFACTS); From 90e76ba9b94820008a2c4c53475499d794c253a7 Mon Sep 17 00:00:00 2001 From: Doris Lam Date: Fri, 21 Oct 2022 16:39:23 -0700 Subject: [PATCH 3/6] preserve _artifacts even when overwriting --- .../mms/crud/services/NodePostHelper.java | 4 ++ example/artifacts.postman_collection.json | 53 ++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/crud/src/main/java/org/openmbee/mms/crud/services/NodePostHelper.java b/crud/src/main/java/org/openmbee/mms/crud/services/NodePostHelper.java index e5cf967c5..34f9a3112 100644 --- a/crud/src/main/java/org/openmbee/mms/crud/services/NodePostHelper.java +++ b/crud/src/main/java/org/openmbee/mms/crud/services/NodePostHelper.java @@ -91,6 +91,10 @@ public NodeChangeInfo processPostJson(List elements, boolean overwr } } else { updated = true; + String ARTIFACTS = "_artifacts"; + if (indexElement.containsKey(ARTIFACTS) && !element.containsKey(ARTIFACTS)) { + element.put(ARTIFACTS, indexElement.get(ARTIFACTS)); + } element.setCreated(indexElement.getCreated()); element.setCreator(indexElement.getCreator()); } diff --git a/example/artifacts.postman_collection.json b/example/artifacts.postman_collection.json index f6300eb4d..3e7027937 100644 --- a/example/artifacts.postman_collection.json +++ b/example/artifacts.postman_collection.json @@ -670,13 +670,64 @@ }, "response": [] }, + { + "name": "overwriting element json without _artifacts won't remove it", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"element artifact persists\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.elements[0]._artifacts.length).to.eql(1);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n\t\"elements\": [\n\t\t{\n\t\t\t\"id\": \"x\",\n\t\t\t\"name\": \"overwrite x\"\n\t\t\t \n\t\t}\n\t]\n}" + }, + "url": { + "raw": "{{host}}/projects/arta/refs/master/elements?overwrite=true", + "host": [ + "{{host}}" + ], + "path": [ + "projects", + "arta", + "refs", + "master", + "elements" + ], + "query": [ + { + "key": "overwrite", + "value": "true" + } + ] + } + }, + "response": [] + }, { "name": "create other user", "event": [ { "listen": "test", "script": { - "id": "3e68a393-9a9f-4759-b8ec-a7e51917ee62", "exec": [ "pm.test(\"Status code is 200\", function () {", " pm.response.to.have.status(200);", From 8e5ac78e82f6f81cfbbd06ecd7d37a7a2fe3c979 Mon Sep 17 00:00:00 2001 From: Doris Lam Date: Fri, 21 Oct 2022 16:40:34 -0700 Subject: [PATCH 4/6] Revert "prevent overwrite option on element update to unlink artifacts" This reverts commit 1fc0082379a33f1f29d1790a8b3833aa5827d024. --- .../mms/artifacts/pubsub/ArtifactsElementsHookSubscriber.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/artifacts/src/main/java/org/openmbee/mms/artifacts/pubsub/ArtifactsElementsHookSubscriber.java b/artifacts/src/main/java/org/openmbee/mms/artifacts/pubsub/ArtifactsElementsHookSubscriber.java index 56756bdf1..a606360ac 100644 --- a/artifacts/src/main/java/org/openmbee/mms/artifacts/pubsub/ArtifactsElementsHookSubscriber.java +++ b/artifacts/src/main/java/org/openmbee/mms/artifacts/pubsub/ArtifactsElementsHookSubscriber.java @@ -20,8 +20,7 @@ public void acceptHook(Object payload) { } ElementUpdateHook elementUpdateHook = (ElementUpdateHook) payload; - if(elementUpdateHook.getElements() != null && - elementUpdateHook.getParams().getOrDefault("overwrite", "false").equals("false")) { + if(elementUpdateHook.getElements() != null) { //Ignore any artifact changes coming in outside of the Artifacts Controller elementUpdateHook.getElements().parallelStream().forEach(v -> { v.remove(ArtifactJson.ARTIFACTS); From 42526087f4129a460384e758beb82194af1edd5f Mon Sep 17 00:00:00 2001 From: Doris Lam Date: Fri, 21 Oct 2022 17:15:18 -0700 Subject: [PATCH 5/6] add tests for delete with update --- .../core/objects/ElementsCommitResponse.java | 13 + .../mms/crud/services/DefaultNodeService.java | 3 +- example/crud.postman_collection.json | 231 ++++++++++++++++++ 3 files changed, 246 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/openmbee/mms/core/objects/ElementsCommitResponse.java b/core/src/main/java/org/openmbee/mms/core/objects/ElementsCommitResponse.java index 4a0a42732..ab3d365e7 100644 --- a/core/src/main/java/org/openmbee/mms/core/objects/ElementsCommitResponse.java +++ b/core/src/main/java/org/openmbee/mms/core/objects/ElementsCommitResponse.java @@ -1,12 +1,16 @@ package org.openmbee.mms.core.objects; import io.swagger.v3.oas.annotations.media.Schema; +import org.openmbee.mms.json.ElementJson; + +import java.util.List; public class ElementsCommitResponse extends ElementsResponse { @Schema(nullable = true) private String commitId; + private List deleted; public String getCommitId() { return commitId; } @@ -14,4 +18,13 @@ public String getCommitId() { public void setCommitId(String commitId) { this.commitId = commitId; } + + public List getDeleted() { + return deleted; + } + + public ElementsResponse setDeleted(List deleted) { + this.deleted = deleted; + return this; + } } diff --git a/crud/src/main/java/org/openmbee/mms/crud/services/DefaultNodeService.java b/crud/src/main/java/org/openmbee/mms/crud/services/DefaultNodeService.java index 1533b9003..564cc6f71 100644 --- a/crud/src/main/java/org/openmbee/mms/crud/services/DefaultNodeService.java +++ b/crud/src/main/java/org/openmbee/mms/crud/services/DefaultNodeService.java @@ -208,7 +208,8 @@ public ElementsCommitResponse createOrUpdate(String projectId, String refId, Ele ElementsCommitResponse response = new ElementsCommitResponse(); response.getElements().addAll(info.getUpdatedMap().values()); response.setRejected(new ArrayList<>(info.getRejected().values())); - if(!info.getUpdatedMap().isEmpty()) { + response.setDeleted(new ArrayList<>(info.getDeletedMap().values())); + if(!info.getUpdatedMap().isEmpty() || !info.getDeletedMap().isEmpty()) { response.setCommitId(info.getCommitJson().getId()); } return response; diff --git a/example/crud.postman_collection.json b/example/crud.postman_collection.json index e51faf156..0fa48976b 100644 --- a/example/crud.postman_collection.json +++ b/example/crud.postman_collection.json @@ -3563,6 +3563,237 @@ } }, "response": [] + }, + { + "name": "create project zz", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n\t\"projects\": [\n\t\t{\n\t\t\t\"id\": \"zz\", \n\t\t\t\"name\": \"zz\",\n\t\t\t\"orgId\": \"a\",\n\t\t\t\"schema\": \"default\"\n\t\t}\n\t]\n}" + }, + "url": { + "raw": "{{host}}/projects", + "host": [ + "{{host}}" + ], + "path": [ + "projects" + ] + } + }, + "response": [] + }, + { + "name": "add elements to project zz", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n\t\"elements\": [\n\t\t{\n\t\t\t\"id\": \"x\",\n\t\t\t\"name\": \"x\"\n\t\t}, {\n\t\t\t\"id\": \"y\", \n\t\t\t\"name\": \"y\"\n\t\t}, {\n\t\t\t\"id\": \"z\",\n\t\t\t\"name\": \"z\"\n\t\t}\n\t]\n}" + }, + "url": { + "raw": "{{host}}/projects/zz/refs/master/elements", + "host": [ + "{{host}}" + ], + "path": [ + "projects", + "zz", + "refs", + "master", + "elements" + ] + } + }, + "response": [] + }, + { + "name": "update and delete elements in same commit", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"response has elements\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.elements.length).to.eql(2);", + " pm.expect(jsonData.deleted.length).to.eql(1);", + "});", + "", + "pm.environment.set(\"hybridCommit\", pm.response.json().commitId);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n\t\"elements\": [\n\t\t{\n\t\t\t\"id\": \"x\",\n\t\t\t\"name\": \"xx\"\n\t\t}, {\n\t\t\t\"id\": \"y\", \n\t\t\t\"name\": \"yy\"\n\t\t}\n\t],\n \"deletes\": [{\"id\": \"z\"}]\n}" + }, + "url": { + "raw": "{{host}}/projects/zz/refs/master/elements", + "host": [ + "{{host}}" + ], + "path": [ + "projects", + "zz", + "refs", + "master", + "elements" + ] + } + }, + "response": [] + }, + { + "name": "get deleted element", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 410\", function () {", + " pm.response.to.have.status(410);", + "});" + ], + "type": "text/javascript" + } + } + ], + "protocolProfileBehavior": { + "disableBodyPruning": true + }, + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n\t\"elements\": [\n\t\t{\n\t\t\t\"id\": \"x\",\n\t\t\t\"name\": \"xx\"\n\t\t}, {\n\t\t\t\"id\": \"y\", \n\t\t\t\"name\": \"yy\"\n\t\t}\n\t],\n \"deletes\": [{\"id\": \"z\"}]\n}" + }, + "url": { + "raw": "{{host}}/projects/zz/refs/master/elements/z", + "host": [ + "{{host}}" + ], + "path": [ + "projects", + "zz", + "refs", + "master", + "elements", + "z" + ] + } + }, + "response": [] + }, + { + "name": "get commit object", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"commit has right data\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.commits[0].updated.length).to.eql(2);", + " pm.expect(jsonData.commits[0].deleted.length).to.eql(1);", + "", + "});", + "", + "" + ], + "type": "text/javascript" + } + } + ], + "protocolProfileBehavior": { + "disableBodyPruning": true + }, + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n\t\"elements\": [\n\t\t{\n\t\t\t\"id\": \"x\",\n\t\t\t\"name\": \"xx\"\n\t\t}, {\n\t\t\t\"id\": \"y\", \n\t\t\t\"name\": \"yy\"\n\t\t}\n\t],\n \"deletes\": [{\"id\": \"z\"}]\n}" + }, + "url": { + "raw": "{{host}}/projects/zz/commits/{{hybridCommit}}", + "host": [ + "{{host}}" + ], + "path": [ + "projects", + "zz", + "commits", + "{{hybridCommit}}" + ] + } + }, + "response": [] } ], "auth": { From 2e09754d8b27da90eea744e597a5aea04ea1bd58 Mon Sep 17 00:00:00 2001 From: Jason Han Date: Mon, 24 Oct 2022 11:13:00 -0700 Subject: [PATCH 6/6] Bump version for release --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 6fcfb3d8f..08d176e97 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=4.0.12 +version=4.0.13 group=org.openmbee.mms springBootVersion=2.6.7