Search in sources :

Example 11 with Category

use of com.thinkbiganalytics.metadata.api.category.Category 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 12 with Category

use of com.thinkbiganalytics.metadata.api.category.Category in project kylo by Teradata.

the class DefaultFeedManagerCategoryService method checkCategoryPermission.

@Override
public boolean checkCategoryPermission(final String id, final Action action, final Action... more) {
    if (accessController.isEntityAccessControlled()) {
        return metadataAccess.read(() -> {
            final Category.ID domainId = categoryProvider.resolveId(id);
            final Category domainCategory = categoryProvider.findById(domainId);
            if (domainCategory != null) {
                domainCategory.getAllowedActions().checkPermission(action, more);
                return true;
            } else {
                return false;
            }
        });
    } else {
        return true;
    }
}
Also used : Category(com.thinkbiganalytics.metadata.api.category.Category) FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory)

Example 13 with Category

use of com.thinkbiganalytics.metadata.api.category.Category in project kylo by Teradata.

the class DefaultFeedManagerCategoryService method getCategoryById.

@Override
public FeedCategory getCategoryById(final String id) {
    return metadataAccess.read(() -> {
        this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_CATEGORIES);
        final Category.ID domainId = categoryProvider.resolveId(id);
        final Category domainCategory = categoryProvider.findById(domainId);
        return categoryModelTransform.domainToFeedCategory(domainCategory, true);
    });
}
Also used : Category(com.thinkbiganalytics.metadata.api.category.Category) FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory)

Example 14 with Category

use of com.thinkbiganalytics.metadata.api.category.Category in project kylo by Teradata.

the class DefaultFeedManagerCategoryService method saveCategory.

@Override
public void saveCategory(final FeedCategory feedCategory) {
    boolean isNew = feedCategory.getId() == null;
    // Perform the rest of the updates as the current user.
    Category.ID updateId = metadataAccess.commit(() -> {
        this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.EDIT_CATEGORIES);
        if (feedCategory.getId() != null) {
            final Category.ID domainId = feedCategory.getId() != null ? categoryProvider.resolveId(feedCategory.getId()) : null;
            final FeedCategory oldCategory = getCategoryById(feedCategory.getId());
            if (oldCategory != null && !oldCategory.getSystemName().equalsIgnoreCase(feedCategory.getSystemName())) {
                // system names have changed, only regenerate the system name if there are no related feeds
                if (oldCategory.getRelatedFeeds() == 0) {
                    categoryProvider.renameSystemName(domainId, feedCategory.getSystemName());
                }
            }
        }
        // Update the domain entity
        final Category domainCategory = categoryProvider.update(categoryModelTransform.feedCategoryToDomain(feedCategory));
        // Repopulate identifier
        feedCategory.setId(domainCategory.getId().toString());
        // TODO only do this when modifying the access control
        if (domainCategory.getAllowedActions().hasPermission(CategoryAccessControl.CHANGE_PERMS)) {
            feedCategory.toRoleMembershipChangeList().stream().forEach(roleMembershipChange -> securityService.changeCategoryRoleMemberships(feedCategory.getId(), roleMembershipChange));
            feedCategory.toFeedRoleMembershipChangeList().stream().forEach(roleMembershipChange -> securityService.changeCategoryFeedRoleMemberships(feedCategory.getId(), roleMembershipChange));
        }
        // Update user-defined fields
        final Set<UserFieldDescriptor> userFields = (feedCategory.getUserFields() != null) ? UserPropertyTransform.toUserFieldDescriptors(feedCategory.getUserFields()) : Collections.emptySet();
        categoryProvider.setFeedUserFields(domainCategory.getId(), userFields);
        return domainCategory.getId();
    });
    notifyCategoryChange(updateId, feedCategory.getSystemName(), isNew ? MetadataChange.ChangeType.CREATE : MetadataChange.ChangeType.UPDATE);
}
Also used : Category(com.thinkbiganalytics.metadata.api.category.Category) FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory) FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory) UserFieldDescriptor(com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor)

Example 15 with Category

use of com.thinkbiganalytics.metadata.api.category.Category in project kylo by Teradata.

the class DefaultFeedManagerCategoryService method deleteCategory.

@Override
public boolean deleteCategory(final String categoryId) throws InvalidOperationException {
    this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.EDIT_CATEGORIES);
    SimpleCategory simpleCategory = metadataAccess.read(() -> {
        Category.ID id = categoryProvider.resolveId(categoryId);
        final Category category = categoryProvider.findById(id);
        if (category != null) {
            if (accessController.isEntityAccessControlled()) {
                // this check should throw a runtime exception
                category.getAllowedActions().checkPermission(CategoryAccessControl.DELETE);
            }
            return new SimpleCategory(id, category.getSystemName());
        } else {
            // unable to read the category
            return null;
        }
    });
    if (simpleCategory != null) {
        metadataAccess.commit(() -> {
            categoryProvider.deleteById(simpleCategory.getCategoryId());
        }, MetadataAccess.SERVICE);
        notifyCategoryChange(simpleCategory.getCategoryId(), simpleCategory.getCategoryName(), MetadataChange.ChangeType.DELETE);
        return true;
    } else {
        return false;
    }
}
Also used : Category(com.thinkbiganalytics.metadata.api.category.Category) FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory)

Aggregations

Category (com.thinkbiganalytics.metadata.api.category.Category)28 FeedCategory (com.thinkbiganalytics.feedmgr.rest.model.FeedCategory)12 Feed (com.thinkbiganalytics.metadata.api.feed.Feed)10 FeedManagerTemplate (com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate)7 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)6 JcrCategory (com.thinkbiganalytics.metadata.modeshape.category.JcrCategory)6 RegisteredTemplate (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)5 UserFieldDescriptor (com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor)5 HadoopSecurityGroup (com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup)5 ArrayList (java.util.ArrayList)5 Collections (java.util.Collections)5 List (java.util.List)5 Optional (java.util.Optional)5 Set (java.util.Set)5 Nonnull (javax.annotation.Nonnull)5 CategoryProvider (com.thinkbiganalytics.metadata.api.category.CategoryProvider)4 DatasourceProvider (com.thinkbiganalytics.metadata.api.datasource.DatasourceProvider)4 FeedAccessControl (com.thinkbiganalytics.metadata.api.feed.security.FeedAccessControl)4 AccessController (com.thinkbiganalytics.security.AccessController)4 FeedNameUtil (com.thinkbiganalytics.support.FeedNameUtil)4