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 @@ -45,8 +45,14 @@ public RefsResponse getAllRefs(
if (!permissionService.isProjectPublic(projectId)) {
List<RefJson> filtered = new ArrayList<>();
for (RefJson ref: res.getRefs()) {
if (mss.hasBranchPrivilege(auth, projectId, ref.getId(), Privileges.BRANCH_READ.name(), false)) {
filtered.add(ref);
try {
if (mss.hasBranchPrivilege(auth, projectId, ref.getId(),
Privileges.BRANCH_READ.name(), false)) {
filtered.add(ref);
}
} catch (MMSException e) {
logger.warn("error in getting branch permissions: projectId=" +
projectId + ", refId=" + ref.getId(), e);
}
}
res.setRefs(filtered);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public NodeChangeInfo processDeleteJson(List<ElementJson> elements, CommitJson c
info.addRejection(nodeId, new Rejection(indexElement, 304, "Already deleted"));
continue;
}
if (indexElement == null) {
logger.warn("node db and index mismatch on element delete: nodeId: " + nodeId +
", docId not found: " + info.getExistingNodeMap().get(nodeId).getDocId());
indexElement = Map.of("id", nodeId);
}
ElementJson request = info.getReqElementMap().get(nodeId);
request.putAll(indexElement);
processElementDeleted(request, node, info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ private NodeGetInfo processLatest(NodeGetInfo info, NodeService service) {
}
ElementJson indexElement = info.getExistingElementMap().get(nodeId);
if (info.getExistingNodeMap().get(nodeId).isDeleted()) {
rejectDeleted(info, nodeId, indexElement);
rejectDeleted(info, nodeId, indexElement == null ? new ElementJson().setId(nodeId) : indexElement);
continue;
}
if (indexElement == null) {
logger.warn("node db and index mismatch on element get: nodeId: " + nodeId +
", docId not found: " + info.getExistingNodeMap().get(nodeId).getDocId());
rejectNotFound(info, nodeId);
continue;
}
if (service != null) {
Expand Down Expand Up @@ -75,6 +81,23 @@ private NodeGetInfo processCommit(NodeGetInfo info, String commitId, NodeService
continue;
}
ElementJson indexElement = info.getExistingElementMap().get(nodeId);
if (indexElement == null) {
Node n = info.getExistingNodeMap().get(nodeId);
logger.warn("node db and index mismatch on element commit get: nodeId: " + nodeId +
", docId not found: " + n.getDocId());
Optional<Commit> last = commitRepository.findByCommitId(n.getLastCommit());
Optional<Commit> first = commitRepository.findByCommitId(n.getInitialCommit());
if (!last.isPresent() || !first.isPresent()) {
rejectNotFound(info, nodeId);
continue;
}
indexElement = new ElementJson().setId(nodeId).setDocId(n.getDocId());
indexElement.setModified(formatter.format(last.get().getTimestamp()));
indexElement.setModifier(last.get().getCreator());
indexElement.setCommitId(last.get().getCommitId());
indexElement.setCreator(first.get().getCreator());
indexElement.setCreated(formatter.format(first.get().getTimestamp()));
}
Instant modified = Instant.from(formatter.parse(indexElement.getModified()));
Instant created = Instant.from(formatter.parse(indexElement.getCreated()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import java.util.List;
import java.util.Map;

import java.util.Optional;
import java.util.UUID;
import org.openmbee.mms.core.config.Formats;
import org.openmbee.mms.core.objects.Rejection;
import org.openmbee.mms.core.services.NodeChangeInfo;
import org.openmbee.mms.core.services.NodeService;
import org.openmbee.mms.data.domains.scoped.Commit;
import org.openmbee.mms.json.BaseJson;
import org.openmbee.mms.json.CommitJson;
import org.openmbee.mms.json.ElementJson;
Expand All @@ -34,7 +36,7 @@ public boolean diffUpdateJson(BaseJson element, Map<String, Object> existing,

String jsonModified = element.getModified();
Object existingModified = existing.get(BaseJson.MODIFIED);
if (jsonModified != null && !jsonModified.isEmpty()) {
if (jsonModified != null && !jsonModified.isEmpty() && existingModified != null) {
try {
Date jsonModDate = Formats.SDF.parse(jsonModified);
Date existingModDate = Formats.SDF.parse(existingModified.toString());
Expand Down Expand Up @@ -72,8 +74,14 @@ public NodeChangeInfo processPostJson(List<ElementJson> elements, boolean overwr
added = true;
} else if (indexElement == null) {
logger.warn("node db and index mismatch on element update: nodeId: " + n.getNodeId() + ", docId not found: " + n.getDocId());
info.addRejection(element.getId(), new Rejection(element, 500, "Update failed: previous element not found"));
continue;
//info.addRejection(element.getId(), new Rejection(element, 500, "Update failed: previous element not found"));
//continue;
indexElement = new ElementJson().setId(n.getNodeId()).setDocId(n.getDocId());
Optional<Commit> init = commitRepository.findByCommitId(n.getInitialCommit());
if (init.isPresent()) {
indexElement.setCreator(init.get().getCreator());
indexElement.setCreated(formatter.format(init.get().getTimestamp()));
}
}

if (!added) {
Expand Down