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