Workspace workspace = workspaceRepository.findById(workspaceId, user);
Authorizations authorizations = getAuthorizations(request, user);
VisibilityJson visibilityJson = GraphUtil.updateVisibilitySourceAndAddWorkspaceId(null, visibilitySource, workspaceId);
LumifyVisibility visibility = this.visibilityTranslator.toVisibility(visibilityJson);
if (!graph.isVisibilityValid(visibility.getVisibility(), authorizations)) {
LOGGER.warn("%s is not a valid visibility for %s user", visibilitySource, user.getDisplayName());
respondWithBadRequest(response, "visibilitySource", getString(request, "visibility.invalid"));
chain.next(request, response);
return;
}
String id = resolvedVertexId == null ? graph.getIdGenerator().nextId() : resolvedVertexId;
Concept concept = ontologyRepository.getConceptByIRI(conceptId);
final Vertex artifactVertex = graph.getVertex(artifactId, authorizations);
LumifyVisibility lumifyVisibility = visibilityTranslator.toVisibility(visibilityJson);
Map<String, Object> metadata = new HashMap<String, Object>();
LumifyProperties.VISIBILITY_JSON.setMetadata(metadata, visibilityJson);
ElementMutation<Vertex> vertexMutation;
Vertex vertex;
if (resolvedVertexId != null) {
vertex = graph.getVertex(id, authorizations);
vertexMutation = vertex.prepareMutation();
} else {
vertexMutation = graph.prepareVertex(id, lumifyVisibility.getVisibility());
GraphUtil.addJustificationToMutation(vertexMutation, justificationText, sourceInfo, lumifyVisibility);
LumifyProperties.CONCEPT_TYPE.setProperty(vertexMutation, conceptId, metadata, lumifyVisibility.getVisibility());
LumifyProperties.TITLE.addPropertyValue(vertexMutation, MULTI_VALUE_KEY, title, metadata, lumifyVisibility.getVisibility());
vertex = vertexMutation.save(authorizations);
auditRepository.auditVertexElementMutation(AuditAction.UPDATE, vertexMutation, vertex, "", user, lumifyVisibility.getVisibility());
LumifyProperties.VISIBILITY_JSON.setProperty(vertexMutation, visibilityJson, metadata, lumifyVisibility.getVisibility());
this.graph.flush();
workspaceRepository.updateEntityOnWorkspace(workspace, vertex.getId(), false, null, user);
}
// TODO: a better way to check if the same edge exists instead of looking it up every time?
Edge edge = graph.addEdge(artifactVertex, vertex, this.artifactHasEntityIri, lumifyVisibility.getVisibility(), authorizations);
LumifyProperties.VISIBILITY_JSON.setProperty(edge, visibilityJson, metadata, lumifyVisibility.getVisibility(), authorizations);
auditRepository.auditRelationship(AuditAction.CREATE, artifactVertex, vertex, edge, "", "", user, lumifyVisibility.getVisibility());
new TermMentionBuilder()
.sourceVertex(artifactVertex)
.propertyKey(propertyKey)
.start(mentionStart)