@Override protected EntityAndPendingNotifications<BE, MetadataPack> wireUpNewEntity(BE entity, MetadataPack.Blueprint blueprint, CanonicalPath parentPath, BE parent, Transaction<BE> tx) { Set<Notification<?, ?>> newRels = new HashSet<>(); blueprint.getMembers().forEach((p) -> { try { BE member = tx.find(p); BE rel = tx.relate(entity, member, incorporates.name(), null); Relationship r = tx.convert(rel, Relationship.class); newRels.add(new Notification<>(r, r, created())); } catch (ElementNotFoundException e) { throw new EntityNotFoundException(p.getSegment().getElementType().getSimpleName(), Query.filters(Query.to(p))); } }); MetadataPack entityObject = tx.convert(entity, MetadataPack.class); return new EntityAndPendingNotifications<>(entity, entityObject, newRels); }
public static <BE> EntityAndPendingNotifications<BE, Relationship> createAssociation(Transaction<BE> tx, BE source, String relationship, BE target, Map<String, Object> properties) { if (tx.hasRelationship(source, target, relationship)) { throw new RelationAlreadyExistsException(relationship, Query.filters(Query.to(tx.extractCanonicalPath (source)))); } RelationshipRules.checkCreate(tx, source, Relationships.Direction.outgoing, relationship, target); BE relationshipObject = tx.relate(source, target, relationship, properties); Relationship ret = tx.convert(relationshipObject, Relationship.class); return new EntityAndPendingNotifications<>(relationshipObject, ret, new Notification<>(ret, ret, created())); }