final GraphObject sourceNode = typedIdResource.getEntity();
if (sourceNode != null && propertyKey != null && propertyKey instanceof RelationProperty) {
final RelationProperty relationProperty = (RelationProperty) propertyKey;
final Class sourceNodeType = sourceNode.getClass();
NodeInterface newNode = null;
if (propertyKey.isReadOnly()) {
logger.log(Level.INFO, "Read-only property on {0}: {1}", new Object[]{sourceNodeType, typeResource.getRawType()});
return null;
}
// fetch notion
final Notion notion = relationProperty.getNotion();
final PropertyKey primaryPropertyKey = notion.getPrimaryPropertyKey();
// apply notion if the property set contains the ID property as the only element
if (primaryPropertyKey != null && propertySet.containsKey(primaryPropertyKey.jsonName()) && propertySet.size() == 1) {
/*
* FIXME: is this needed at all??
*
// the notion that is defined for this relationship can deserialize
// objects with a single key (uuid for example), and the POSTed
// property set contains value(s) for this key, so we only need
// to create relationships
final Object keySource = propertySet.get(primaryPropertyKey.jsonName());
if (keySource != null) {
if (keySource instanceof Collection) {
sourceNode.setProperty(propertyKey, notion.getCollectionAdapterForSetter(securityContext).adapt(keySource));
} else {
sourceNode.setProperty(propertyKey, notion.getAdapterForSetter(securityContext).adapt(keySource));
}
/*
GraphObject otherNode = null;
if (keySource instanceof Collection) {
final Collection collection = (Collection) keySource;
for (final Object key : collection) {
otherNode = deserializationStrategy.adapt(key);
if (otherNode != null && otherNode instanceof AbstractNode) {
relationshipProperty.createRelationship(securityContext, sourceNode, (AbstractNode)otherNode);
} else {
logger.log(Level.WARNING, "Relationship end node has invalid type {0}", otherNode.getClass().getName());
}
}
} else {
// create a single relationship
otherNode = deserializationStrategy.adapt(keySource);
if (otherNode != null && otherNode instanceof AbstractNode) {
relationshipProperty.createRelationship(securityContext, sourceNode, (AbstractNode)otherNode);
} else {
logger.log(Level.WARNING, "Relationship end node has invalid type {0}", otherNode.getClass().getName());
}
}
return otherNode;
} else {
logger.log(Level.INFO, "Key {0} not found in {1}", new Object[] { primaryPropertyKey.jsonName(), propertySet.toString() });
}
*/
} else {
// the notion can not deserialize objects with a single key, or the POSTed propertySet did not contain a key to deserialize,
// so we create a new node from the POSTed properties and link the source node to it. (this is the "old" implementation)
newNode = typeResource.createNode(propertySet);
if (newNode != null) {
relationProperty.addSingleElement(securityContext, sourceNode, newNode);
}
}
if (newNode != null) {