respondWithNotFound(response);
return;
}
ElementMutation<Vertex> entityVertexMutation = entityVertex.prepareMutation();
VisibilityJson visibilityJson = getLumifyVisibility(entityVertex, workspaceId);
LumifyVisibility lumifyVisibility = visibilityTranslator.toVisibility(visibilityJson);
Map<String, Object> metadata = new HashMap<String, Object>();
LumifyProperties.VISIBILITY_JSON.setMetadata(metadata, visibilityJson);
String title = String.format("Image of %s", LumifyProperties.TITLE.getPropertyValue(entityVertex));
ElementBuilder<Vertex> artifactVertexBuilder = convertToArtifact(file, title, visibilityJson, metadata, lumifyVisibility, authorizations);
Vertex artifactVertex = artifactVertexBuilder.save(authorizations);
this.graph.flush();
auditRepository.auditVertexElementMutation(AuditAction.UPDATE, artifactVertexBuilder, artifactVertex, "", user, lumifyVisibility.getVisibility());
entityVertexMutation.setProperty(LumifyProperties.ENTITY_IMAGE_VERTEX_ID.getPropertyName(), artifactVertex.getId(), metadata, lumifyVisibility.getVisibility());
auditRepository.auditVertexElementMutation(AuditAction.UPDATE, entityVertexMutation, entityVertex, "", user, lumifyVisibility.getVisibility());
entityVertex = entityVertexMutation.save(authorizations);
graph.flush();
List<Edge> existingEdges = toList(entityVertex.getEdges(artifactVertex, Direction.BOTH, entityHasImageIri, authorizations));
if (existingEdges.size() == 0) {
EdgeBuilder edgeBuilder = graph.prepareEdge(entityVertex, artifactVertex, entityHasImageIri, lumifyVisibility.getVisibility());
LumifyProperties.VISIBILITY_JSON.setProperty(edgeBuilder, visibilityJson, lumifyVisibility.getVisibility());
Edge edge = edgeBuilder.save(authorizations);
auditRepository.auditRelationship(AuditAction.CREATE, entityVertex, artifactVertex, edge, "", "", user, lumifyVisibility.getVisibility());
}
this.workspaceRepository.updateEntityOnWorkspace(workspace, artifactVertex.getId(), false, null, user);
this.workspaceRepository.updateEntityOnWorkspace(workspace, entityVertex.getId(), false, null, user);
graph.flush();
workQueueRepository.pushGraphPropertyQueue(artifactVertex, null, LumifyProperties.RAW.getPropertyName(), workspaceId, visibilityJson.getSource());
respondWithClientApiObject(response, ClientApiConverter.toClientApi(entityVertex, workspaceId, authorizations));
}