Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.*;

import java.util.stream.Collectors;

import org.openmbee.mms.core.config.ContextHolder;
import org.openmbee.mms.core.objects.Rejection;
import org.openmbee.mms.core.services.NodeGetInfo;
import org.openmbee.mms.core.exceptions.BadRequestException;
Expand Down Expand Up @@ -100,14 +102,15 @@ private NodeGetInfo processCommit(NodeGetInfo info, String commitId, NodeService
}
Instant modified = Instant.from(formatter.parse(indexElement.getModified()));
Instant created = Instant.from(formatter.parse(indexElement.getCreated()));

indexElement.setRefId(ContextHolder.getContext().getBranchId());
if (commitId.equals(indexElement.getCommitId())) { //exact match
info.getActiveElementMap().put(nodeId, indexElement);
} else if (created.isAfter(time)) { // element created after commit
rejectNotFound(info, nodeId);
} else if (modified.isAfter(time)) { // latest element is after commit
Optional<ElementJson> tryExact = nodeIndex.getByCommitId(commitId, nodeId);
if (tryExact.isPresent()) {
tryExact.get().setRefId(ContextHolder.getContext().getBranchId());
info.getActiveElementMap().put(nodeId, tryExact.get());
continue; // found exact match at commit
}
Expand All @@ -118,6 +121,7 @@ private NodeGetInfo processCommit(NodeGetInfo info, String commitId, NodeService
formatter.format(time), refCommitIds);
if (e.isPresent()) { // found version of element at commit time
//TODO determine if element was deleted at the time?
e.get().setRefId(ContextHolder.getContext().getBranchId());
info.getActiveElementMap().put(nodeId, e.get());
} else {
rejectNotFound(info, nodeId); // element not found at commit time
Expand Down Expand Up @@ -150,7 +154,12 @@ public List<ElementJson> processGetAll() {
for (Node node : existingNodes) {
indexIds.add(node.getDocId());
}
return nodeIndex.findAllById(indexIds);
List<ElementJson> els = nodeIndex.findAllById(indexIds);
String ref = ContextHolder.getContext().getBranchId();
for (ElementJson el: els) {
el.setRefId(ref);
}
return els;
}

public List<ElementJson> processGetAll(String commitId, NodeService service) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Set;
import java.util.UUID;

import org.openmbee.mms.core.config.ContextHolder;
import org.openmbee.mms.core.objects.Rejection;
import org.openmbee.mms.core.services.NodeChangeInfo;
import org.openmbee.mms.core.services.NodeGetInfo;
Expand Down Expand Up @@ -90,6 +91,11 @@ public NodeChangeInfo initInfoFromNodes(List<Node> existingNodes, CommitJson cmj
}
// bulk read existing elements in elastic
List<ElementJson> existingElements = nodeIndex.findAllById(indexIds);
// set the _refId of the element json to be the ref it's 'found/requested' in,
String ref = ContextHolder.getContext().getBranchId();
for (ElementJson e: existingElements) {
e.setRefId(ref);
}
Map<String, ElementJson> existingElementMap = convertJsonToMap(existingElements);

Instant now = Instant.now();
Expand Down
39 changes: 39 additions & 0 deletions example/crud.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,7 @@
" var jsonData = pm.response.json();",
" jsonData.elements.forEach(function(e) {",
" pm.expect(e._inRefIds).to.include('refa');",
" pm.expect(e._refId).to.equal('refa');",
" })",
"});"
],
Expand All @@ -1100,6 +1101,44 @@
},
"response": []
},
{
"name": "check response element _refId matches request",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"return element in new ref have right _refId\", function () {",
" var jsonData = pm.response.json();",
" jsonData.elements.forEach(function(e) {",
" pm.expect(e._refId).to.equal('refa');",
" })",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{host}}/projects/aa/refs/refa/elements/x",
"host": [
"{{host}}"
],
"path": [
"projects",
"aa",
"refs",
"refa",
"elements",
"x"
]
}
},
"response": []
},
{
"name": "update x and y on refa",
"event": [
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.13
version=4.0.14
group=org.openmbee.mms

springBootVersion=2.6.7
Expand Down