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();
}
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);
});
}
Aggregations