@Override protected EntityAndPendingNotifications<BE, Feed> wireUpNewEntity(BE entity, Feed.Blueprint blueprint, CanonicalPath parentPath, BE parent, Transaction<BE> transaction) { return new EntityAndPendingNotifications<>(entity, new Feed(blueprint.getName(), parentPath.extend(Feed.SEGMENT_TYPE, transaction.extractId(entity)).get(), null, null, null, blueprint.getProperties()), emptyList()); }
@Override public String generate(Inventory inventory, Feed proposedFeed) throws EntityAlreadyExistsException { try { if (!Feed.Blueprint.shouldAutogenerateId(proposedFeed)) { inventory.inspect(proposedFeed).entity(); } if (fallback == null || !Feed.Blueprint.shouldAutogenerateId(proposedFeed)) { throw new FeedAlreadyRegisteredException(proposedFeed); } else { return fallback.generate(inventory, proposedFeed); } } catch (EntityNotFoundException e) { // the happy path return proposedFeed.getId(); } } }
@Override public B visitFeed(Feed feed, Void parameter) { return (B) fillCommon(feed, Feed.Blueprint.builder()).build(); }
@Override public Element visitFeed(Feed.Blueprint feed, Void parameter) { return common(path, feed.getName(), feed.getProperties(), Feed.class); }
@Override public Blueprint build() { return new Blueprint(id, name, properties, outgoing, incoming); } }
@Override protected String getProposedId(Transaction<BE> tx, Feed.Blueprint blueprint) { BE tenant = tx.querySingle(context.sourcePath.extend().filter() .with(type(Tenant.class)).get()); if (tenant == null) { throw new EntityNotFoundException(Tenant.class, Query.filters(context.sourcePath)); } CanonicalPath feedPath = tx.extractCanonicalPath(tenant) .extend(Feed.SEGMENT_TYPE, blueprint.getId()).get(); return context.configuration.getFeedIdStrategy().generate(context.inventory.keepTransaction(tx), new Feed(feedPath, null, null, null)); }
@Override public Blueprint build() { return new Blueprint(id, name, properties, outgoing, incoming); } }