User user,
Authorizations authorizations) {
VisibilityJson visibilityJson = new VisibilityJson();
visibilityJson.setSource(visibilitySource);
visibilityJson.addWorkspace(workspaceId);
LumifyVisibility lumifyVisibility = visibilityTranslator.toVisibility(visibilityJson);
Property oldProperty = element.getProperty(propertyKey, propertyName, lumifyVisibility.getVisibility());
Map<String, Object> propertyMetadata;
if (oldProperty != null) {
propertyMetadata = oldProperty.getMetadata();
if (oldProperty.getName().equals(propertyName) && oldProperty.getKey().equals(propertyKey)) {
element.removeProperty(propertyKey, propertyName, authorizations);
graph.flush();
}
} else {
propertyMetadata = new HashMap<String, Object>();
}
mergeMetadata(propertyMetadata, metadata);
ExistingElementMutation<T> elementMutation = element.prepareMutation();
visibilityJson = updateVisibilitySourceAndAddWorkspaceId(visibilityJson, visibilitySource, workspaceId);
LumifyProperties.VISIBILITY_JSON.setMetadata(propertyMetadata, visibilityJson);
LumifyProperties.MODIFIED_DATE.setMetadata(propertyMetadata, new Date());
LumifyProperties.MODIFIED_BY.setMetadata(propertyMetadata, user.getUserId());
LumifyProperties.CONFIDENCE.setMetadata(propertyMetadata, SET_PROPERTY_CONFIDENCE);
lumifyVisibility = visibilityTranslator.toVisibility(visibilityJson);
if (justificationText != null) {
PropertyJustificationMetadata propertyJustificationMetadata = new PropertyJustificationMetadata(justificationText);
if (propertyMetadata.containsKey(PropertySourceMetadata.PROPERTY_SOURCE_METADATA)) {
propertyMetadata.remove(PropertySourceMetadata.PROPERTY_SOURCE_METADATA);
}
propertyMetadata.put(PropertyJustificationMetadata.PROPERTY_JUSTIFICATION, propertyJustificationMetadata);
} else if (sourceObject.length() > 0) {
PropertySourceMetadata sourceMetadata = createPropertySourceMetadata(sourceObject);
if (propertyMetadata.containsKey(PropertyJustificationMetadata.PROPERTY_JUSTIFICATION)) {
propertyMetadata.remove(PropertyJustificationMetadata.PROPERTY_JUSTIFICATION);
}
propertyMetadata.put(PropertySourceMetadata.PROPERTY_SOURCE_METADATA, sourceMetadata);
}
elementMutation.addPropertyValue(propertyKey, propertyName, value, propertyMetadata, lumifyVisibility.getVisibility());
return new VisibilityAndElementMutation<T>(lumifyVisibility, elementMutation);
}