Search in sources :

Example 1 with JcrFeedTemplate

use of com.thinkbiganalytics.metadata.modeshape.template.JcrFeedTemplate in project kylo by Teradata.

the class EnsureTemplateFeedRelationshipsUpgradeAction method ensureFeedTemplateFeedRelationships.

private void ensureFeedTemplateFeedRelationships() {
    // ensure the templates have the feed relationships
    List<Feed> feeds = feedProvider.findAll();
    if (feeds != null) {
        feeds.stream().forEach(feed -> {
            FeedManagerTemplate template = feed.getTemplate();
            if (template != null) {
                // ensure the template has feeds.
                List<Feed> templateFeeds = null;
                try {
                    templateFeeds = template.getFeeds();
                } catch (MetadataRepositoryException e) {
                    // templateFeeds are weak references.
                    // if the template feeds return itemNotExists we need to reset it
                    Throwable rootCause = ExceptionUtils.getRootCause(e);
                    if (rootCause != null && rootCause instanceof ItemNotFoundException) {
                        // reset the reference collection.  It will be rebuilt in the subsequent call
                        JcrPropertyUtil.removeAllFromSetProperty(((JcrFeedTemplate) template).getNode(), JcrFeedTemplate.FEEDS);
                    }
                }
                if (templateFeeds == null || !templateFeeds.contains(feed)) {
                    log.info("Updating relationship temlate: {} -> feed: {}", template.getName(), feed.getName());
                    template.addFeed(feed);
                    feedManagerTemplateProvider.update(template);
                }
            }
        });
    }
    feedProvider.populateInverseFeedDependencies();
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) JcrFeedTemplate(com.thinkbiganalytics.metadata.modeshape.template.JcrFeedTemplate) FeedManagerTemplate(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) JcrFeed(com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 2 with JcrFeedTemplate

use of com.thinkbiganalytics.metadata.modeshape.template.JcrFeedTemplate in project kylo by Teradata.

the class FeedWeakReferenceUpgradeAction method upgradeTo.

@Override
public void upgradeTo(final KyloVersion targetVersion) {
    log.info("Updating template feed references: {}", targetVersion);
    this.templateProvider.findAll().stream().map(JcrFeedTemplate.class::cast).map(JcrFeedTemplate::getNode).forEach(templateNode -> {
        Set<Node> feedNodes = JcrPropertyUtil.getSetProperty(templateNode, JcrFeedTemplate.FEEDS);
        JcrPropertyUtil.removeAllFromSetProperty(templateNode, JcrFeedTemplate.FEEDS);
        feedNodes.forEach(feedNode -> JcrPropertyUtil.addToSetProperty(templateNode, JcrFeedTemplate.FEEDS, feedNode, true));
    });
    this.feedProvider.findAll().stream().map(JcrFeed.class::cast).map(JcrFeed::getFeedDetails).filter(Optional::isPresent).map(Optional::get).map(FeedDetails::getNode).forEach(detailsNode -> {
        Node templateNode = JcrPropertyUtil.getProperty(detailsNode, FeedDetails.TEMPLATE);
        JcrPropertyUtil.setProperty(detailsNode, FeedDetails.TEMPLATE, null);
        JcrPropertyUtil.setWeakReferenceProperty(detailsNode, FeedDetails.TEMPLATE, templateNode);
    });
}
Also used : JcrFeedTemplate(com.thinkbiganalytics.metadata.modeshape.template.JcrFeedTemplate) JcrFeed(com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed) Optional(java.util.Optional) Node(javax.jcr.Node)

Aggregations

JcrFeed (com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed)2 JcrFeedTemplate (com.thinkbiganalytics.metadata.modeshape.template.JcrFeedTemplate)2 Feed (com.thinkbiganalytics.metadata.api.feed.Feed)1 FeedManagerTemplate (com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate)1 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)1 Optional (java.util.Optional)1 ItemNotFoundException (javax.jcr.ItemNotFoundException)1 Node (javax.jcr.Node)1