Skip to content

Commit

Permalink
Merge pull request #218 from Open-MBEE/release/4.0.13
Browse files Browse the repository at this point in the history
Release/4.0.13
  • Loading branch information
HuiJun authored Oct 24, 2022
2 parents 2722f1b + 2e09754 commit df54e9a
Show file tree
Hide file tree
Showing 7 changed files with 322 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
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<ElementJson> deleted;
public String getCommitId() {
return commitId;
}

public void setCommitId(String commitId) {
this.commitId = commitId;
}

public List<ElementJson> getDeleted() {
return deleted;
}

public ElementsResponse setDeleted(List<ElementJson> deleted) {
this.deleted = deleted;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ public class ElementsRequest extends BaseRequest {
@Schema(required = true)
private List<ElementJson> elements;

private List<ElementJson> deletes;

public List<ElementJson> getElements() {
return elements;
}

public void setElements(List<ElementJson> elements) {
this.elements = elements;
}

public List<ElementJson> getDeletes() {
return deletes;
}

public void setDeletes(List<ElementJson> deletes) {
this.deletes = deletes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,22 @@ 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();
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public NodeChangeInfo processPostJson(List<ElementJson> 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());
}
Expand Down
53 changes: 52 additions & 1 deletion example/artifacts.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -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);",
Expand Down
231 changes: 231 additions & 0 deletions example/crud.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=4.0.12
version=4.0.13
group=org.openmbee.mms

springBootVersion=2.6.7
Expand Down

0 comments on commit df54e9a

Please sign in to comment.