use of com.thinkbiganalytics.metadata.api.category.CategoryNotFoundException in project kylo by Teradata.
the class CategoryModelTransform method feedCategoryToDomain.
/**
* Transforms the specified Feed Manager category to a Metadata category.
*
* @param feedCategory the Feed Manager category
* @param userFields the user-defined fields
* @return the Metadata category
*/
@Nonnull
private Category feedCategoryToDomain(@Nonnull final FeedCategory feedCategory, @Nonnull final Set<UserFieldDescriptor> userFields) {
Category.ID domainId = feedCategory.getId() != null ? categoryProvider.resolveId(feedCategory.getId()) : null;
Category category = null;
if (domainId != null) {
category = categoryProvider.findById(domainId);
}
if (category == null) {
category = categoryProvider.ensureCategory(feedCategory.getSystemName());
}
if (category == null) {
throw new CategoryNotFoundException("Unable to find Category ", domainId);
}
domainId = category.getId();
feedCategory.setId(domainId.toString());
category.setDisplayName(feedCategory.getName());
category.setSystemName(feedCategory.getSystemName());
category.setDescription(feedCategory.getDescription());
category.setIcon(feedCategory.getIcon());
category.setIconColor(feedCategory.getIconColor());
category.setAllowIndexing(feedCategory.isAllowIndexing());
category.setCreatedTime(new DateTime(feedCategory.getCreateDate()));
category.setModifiedTime(new DateTime(feedCategory.getUpdateDate()));
// Transforms the Feed Manager user-defined properties to domain user-defined properties
if (feedCategory.getUserProperties() != null) {
category.setUserProperties(UserPropertyTransform.toMetadataProperties(feedCategory.getUserProperties()), userFields);
}
// Set the hadoop security groups
final List<HadoopSecurityGroup> securityGroups = new ArrayList<>();
if (feedCategory.getSecurityGroups() != null) {
for (com.thinkbiganalytics.feedmgr.rest.model.HadoopSecurityGroup securityGroup : feedCategory.getSecurityGroups()) {
JcrHadoopSecurityGroup hadoopSecurityGroup = (JcrHadoopSecurityGroup) hadoopSecurityGroupProvider.ensureSecurityGroup(securityGroup.getName());
hadoopSecurityGroup.setGroupId(securityGroup.getId());
hadoopSecurityGroup.setDescription(securityGroup.getDescription());
securityGroups.add(hadoopSecurityGroup);
}
}
category.setSecurityGroups(securityGroups);
return category;
}
use of com.thinkbiganalytics.metadata.api.category.CategoryNotFoundException in project kylo by Teradata.
the class JcrFeedProvider method ensureFeed.
/**
* Ensure the Feed, but the Category must exist!
*/
@Override
public Feed ensureFeed(String categorySystemName, String feedSystemName) {
JcrCategory category = null;
try {
String categoryPath = EntityUtil.pathForCategory(categorySystemName);
Node categoryNode = getSession().getNode(categoryPath);
if (categoryNode != null) {
category = JcrUtil.createJcrObject(categoryNode, JcrCategory.class);
} else {
category = (JcrCategory) categoryProvider.findBySystemName(categorySystemName);
}
} catch (RepositoryException e) {
throw new CategoryNotFoundException("Unable to find Category for " + categorySystemName, null);
}
String feedParentPath = category.getFeedParentPath();
boolean newFeed = !hasEntityNode(feedParentPath, feedSystemName);
Node feedNode = findOrCreateEntityNode(feedParentPath, feedSystemName, getJcrEntityClass());
JcrFeed feed = new JcrFeed(feedNode, category, this.opsAccessProvider);
feed.setSystemName(feedSystemName);
if (newFeed) {
if (this.accessController.isEntityAccessControlled()) {
List<SecurityRole> roles = this.roleProvider.getEntityRoles(SecurityRole.FEED);
this.actionsProvider.getAvailableActions(AllowedActions.FEED).ifPresent(actions -> feed.enableAccessControl((JcrAllowedActions) actions, JcrMetadataAccess.getActiveUser(), roles));
} else {
this.actionsProvider.getAvailableActions(AllowedActions.FEED).ifPresent(actions -> feed.disableAccessControl((JcrAllowedActions) actions, JcrMetadataAccess.getActiveUser()));
}
addPostFeedChangeAction(feed, ChangeType.CREATE);
}
return feed;
}
Aggregations