Search in sources :

Example 1 with CategoryNotFoundException

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;
}
Also used : HadoopSecurityGroup(com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup) JcrHadoopSecurityGroup(com.thinkbiganalytics.metadata.modeshape.security.JcrHadoopSecurityGroup) Category(com.thinkbiganalytics.metadata.api.category.Category) FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory) CategoryNotFoundException(com.thinkbiganalytics.metadata.api.category.CategoryNotFoundException) ArrayList(java.util.ArrayList) JcrHadoopSecurityGroup(com.thinkbiganalytics.metadata.modeshape.security.JcrHadoopSecurityGroup) DateTime(org.joda.time.DateTime) Nonnull(javax.annotation.Nonnull)

Example 2 with CategoryNotFoundException

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;
}
Also used : SecurityRole(com.thinkbiganalytics.security.role.SecurityRole) JcrAllowedActions(com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions) Node(javax.jcr.Node) CategoryNotFoundException(com.thinkbiganalytics.metadata.api.category.CategoryNotFoundException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) JcrCategory(com.thinkbiganalytics.metadata.modeshape.category.JcrCategory)

Aggregations

CategoryNotFoundException (com.thinkbiganalytics.metadata.api.category.CategoryNotFoundException)2 FeedCategory (com.thinkbiganalytics.feedmgr.rest.model.FeedCategory)1 Category (com.thinkbiganalytics.metadata.api.category.Category)1 HadoopSecurityGroup (com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup)1 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)1 JcrCategory (com.thinkbiganalytics.metadata.modeshape.category.JcrCategory)1 JcrHadoopSecurityGroup (com.thinkbiganalytics.metadata.modeshape.security.JcrHadoopSecurityGroup)1 JcrAllowedActions (com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions)1 SecurityRole (com.thinkbiganalytics.security.role.SecurityRole)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 DateTime (org.joda.time.DateTime)1