Search in sources :

Example 1 with FeedCategory

use of com.thinkbiganalytics.feedmgr.rest.model.FeedCategory in project kylo by Teradata.

the class FileObjectPersistence method getCategoriesFromFile.

public Collection<FeedCategory> getCategoriesFromFile() {
    ObjectMapper mapper = new ObjectMapper();
    File file = new File(filePath + "/" + FEED_CATEGORIES_FILENAME);
    Collection<FeedCategory> categories = null;
    if (file.exists()) {
        try {
            categories = mapper.readValue(file, new TypeReference<List<FeedCategory>>() {
            });
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    return categories;
}
Also used : FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with FeedCategory

use of com.thinkbiganalytics.feedmgr.rest.model.FeedCategory 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 3 with FeedCategory

use of com.thinkbiganalytics.feedmgr.rest.model.FeedCategory 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 4 with FeedCategory

use of com.thinkbiganalytics.feedmgr.rest.model.FeedCategory 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 5 with FeedCategory

use of com.thinkbiganalytics.feedmgr.rest.model.FeedCategory in project kylo by Teradata.

the class InMemoryFeedManagerCategoryService method deleteCategory.

@Override
public boolean deleteCategory(String categoryId) throws InvalidOperationException {
    FeedCategory category = categories.get(categoryId);
    if (category != null) {
        // dont allow if category has feeds on it
        if (category.getRelatedFeeds() > 0) {
            throw new InvalidOperationException("Unable to delete Category " + category.getName() + ".  This category has " + category.getRelatedFeeds() + " feeds associated to it.");
        } else {
            categories.remove(categoryId);
            FileObjectPersistence.getInstance().writeCategoriesToFile(categories.values());
            return true;
        }
    }
    return false;
}
Also used : FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory) InvalidOperationException(com.thinkbiganalytics.feedmgr.InvalidOperationException)

Aggregations

FeedCategory (com.thinkbiganalytics.feedmgr.rest.model.FeedCategory)32 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)18 ImportTemplate (com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate)8 Category (com.thinkbiganalytics.metadata.api.category.Category)8 ArrayList (java.util.ArrayList)7 FeedSummary (com.thinkbiganalytics.feedmgr.rest.model.FeedSummary)5 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)5 Test (org.junit.Test)5 RegisteredTemplate (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)4 IOException (java.io.IOException)4 PropertyExpressionResolver (com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver)3 NifiFeed (com.thinkbiganalytics.feedmgr.rest.model.NifiFeed)3 UploadProgressMessage (com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage)3 HadoopSecurityGroup (com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Sets (com.google.common.collect.Sets)2 DefaultTableSchema (com.thinkbiganalytics.discovery.model.DefaultTableSchema)2 DefaultTag (com.thinkbiganalytics.discovery.model.DefaultTag)2 MetadataFieldAnnotationFieldNameResolver (com.thinkbiganalytics.feedmgr.MetadataFieldAnnotationFieldNameResolver)2 ImportComponent (com.thinkbiganalytics.feedmgr.rest.ImportComponent)2