use of com.thinkbiganalytics.metadata.api.category.Category in project kylo by Teradata.
the class FeedModelTransform method domainToFeedMetadata.
/**
* Transforms the specified Metadata feed to a Feed Manager feed.
*
* @param domain the Metadata feed
* @param userFieldMap cache map from category to user-defined fields, or {@code null}
* @return the Feed Manager feed
*/
@Nonnull
private FeedMetadata domainToFeedMetadata(@Nonnull final Feed domain, @Nullable final Map<Category, Set<UserFieldDescriptor>> userFieldMap) {
FeedMetadata feed = deserializeFeedMetadata(domain, false);
feed.setId(domain.getId().toString());
feed.setFeedId(domain.getId().toString());
feed.setFeedName(domain.getDisplayName());
feed.setSystemFeedName(domain.getName());
feed.setDescription(domain.getDescription());
feed.setAllowIndexing(domain.isAllowIndexing());
feed.setHistoryReindexingStatus(domain.getCurrentHistoryReindexingStatus().getHistoryReindexingState().toString());
feed.setOwner(domain.getOwner() != null ? new User(domain.getOwner().getName()) : null);
if (domain.getCreatedTime() != null) {
feed.setCreateDate(domain.getCreatedTime().toDate());
}
if (domain.getModifiedTime() != null) {
feed.setUpdateDate(domain.getModifiedTime().toDate());
}
FeedManagerTemplate template = domain.getTemplate();
if (template != null) {
RegisteredTemplate registeredTemplate = templateModelTransform.DOMAIN_TO_REGISTERED_TEMPLATE.apply(template);
feed.setRegisteredTemplate(registeredTemplate);
feed.setTemplateId(registeredTemplate.getId());
feed.setTemplateName(registeredTemplate.getTemplateName());
}
Category category = domain.getCategory();
if (category != null) {
feed.setCategory(categoryModelTransform.domainToFeedCategorySimple(category));
}
feed.setState(domain.getState() != null ? domain.getState().name() : null);
feed.setVersionName(domain.getVersionName() != null ? domain.getVersionName() : null);
// Set user-defined properties
final Set<UserFieldDescriptor> userFields;
if (userFieldMap == null) {
userFields = getUserFields(category);
} else if (userFieldMap.containsKey(category)) {
userFields = userFieldMap.get(category);
} else {
userFields = getUserFields(category);
userFieldMap.put(category, userFields);
}
@SuppressWarnings("unchecked") final Set<UserProperty> userProperties = UserPropertyTransform.toUserProperties(domain.getUserProperties(), userFields);
feed.setUserProperties(userProperties);
// Convert JCR securitygroup to DTO
List<com.thinkbiganalytics.feedmgr.rest.model.HadoopSecurityGroup> restSecurityGroups = new ArrayList<>();
if (domain.getSecurityGroups() != null && domain.getSecurityGroups().size() > 0) {
for (Object group : domain.getSecurityGroups()) {
HadoopSecurityGroup hadoopSecurityGroup = (HadoopSecurityGroup) group;
com.thinkbiganalytics.feedmgr.rest.model.HadoopSecurityGroup restSecurityGroup = new com.thinkbiganalytics.feedmgr.rest.model.HadoopSecurityGroup();
restSecurityGroup.setDescription(hadoopSecurityGroup.getDescription());
restSecurityGroup.setId(hadoopSecurityGroup.getGroupId());
restSecurityGroup.setName(hadoopSecurityGroup.getName());
restSecurityGroups.add(restSecurityGroup);
}
}
feed.setSecurityGroups(restSecurityGroups);
feed.setTags(domain.getTags().stream().map(name -> new DefaultTag(name)).collect(Collectors.toList()));
if (domain.getUsedByFeeds() != null) {
final List<FeedSummary> usedByFeeds = domain.getUsedByFeeds().stream().map(this::domainToFeedSummary).collect(Collectors.toList());
feed.setUsedByFeeds(usedByFeeds);
}
// add in access control items
securityTransform.applyAccessControl(domain, feed);
return feed;
}
use of com.thinkbiganalytics.metadata.api.category.Category in project kylo by Teradata.
the class FeedModelTransform method feedToDomain.
/**
* Transforms the specified Feed Manager feed to a Metadata feed.
*
* @param feedMetadata the Feed Manager feed
* @return the Metadata feed
*/
@Nonnull
public Feed feedToDomain(@Nonnull final FeedMetadata feedMetadata) {
// resolve the id
Feed.ID domainId = feedMetadata.getId() != null ? feedProvider.resolveId(feedMetadata.getId()) : null;
Feed domain = domainId != null ? feedProvider.findById(domainId) : null;
FeedCategory restCategoryModel = feedMetadata.getCategory();
Category category = null;
if (restCategoryModel != null && (domain == null || domain.getCategory() == null)) {
category = categoryProvider.findById(categoryProvider.resolveId(restCategoryModel.getId()));
}
if (domain == null) {
// ensure the Category exists
if (category == null) {
final String categoryId = (restCategoryModel != null) ? restCategoryModel.getId() : "(null)";
throw new RuntimeException("Category cannot be found while creating feed " + feedMetadata.getSystemFeedName() + ". Category Id is " + categoryId);
}
domain = feedProvider.ensureFeed(category.getId(), feedMetadata.getSystemFeedName());
domainId = domain.getId();
Feed.State state = Feed.State.valueOf(feedMetadata.getState());
domain.setState(state);
// reassign the domain data back to the ui model....
feedMetadata.setFeedId(domainId.toString());
feedMetadata.setState(state.name());
}
domain.setDisplayName(feedMetadata.getFeedName());
if (feedMetadata.getDescription() == null) {
feedMetadata.setDescription("");
}
domain.setDescription(feedMetadata.getDescription());
domain.setAllowIndexing(feedMetadata.isAllowIndexing());
if (StringUtils.isNotBlank(feedMetadata.getHistoryReindexingStatus())) {
domain.updateHistoryReindexingStatus(new HistoryReindexingStatus(com.thinkbiganalytics.metadata.api.feed.reindex.HistoryReindexingState.valueOf(feedMetadata.getHistoryReindexingStatus())));
}
feedMetadata.setId(domain.getId().toString());
if (StringUtils.isNotBlank(feedMetadata.getState())) {
Feed.State state = Feed.State.valueOf(feedMetadata.getState().toUpperCase());
domain.setState(state);
}
domain.setNifiProcessGroupId(feedMetadata.getNifiProcessGroupId());
// clear out the state as that
RegisteredTemplate template = feedMetadata.getRegisteredTemplate();
prepareForSave(feedMetadata);
feedMetadata.setRegisteredTemplate(template);
if (domain.getTemplate() == null) {
FeedManagerTemplate.ID templateId = templateProvider.resolveId(feedMetadata.getTemplateId());
FeedManagerTemplate domainTemplate = templateProvider.findById(templateId);
domain.setTemplate(domainTemplate);
}
// Set user-defined properties
if (feedMetadata.getUserProperties() != null) {
final Set<UserFieldDescriptor> userFields = getUserFields(category);
domain.setUserProperties(UserPropertyTransform.toMetadataProperties(feedMetadata.getUserProperties()), userFields);
}
// Set the hadoop security groups
final List<HadoopSecurityGroup> securityGroups = new ArrayList<>();
if (feedMetadata.getSecurityGroups() != null) {
for (com.thinkbiganalytics.feedmgr.rest.model.HadoopSecurityGroup securityGroup : feedMetadata.getSecurityGroups()) {
JcrHadoopSecurityGroup hadoopSecurityGroup = (JcrHadoopSecurityGroup) hadoopSecurityGroupProvider.ensureSecurityGroup(securityGroup.getName());
hadoopSecurityGroup.setGroupId(securityGroup.getId());
hadoopSecurityGroup.setDescription(securityGroup.getDescription());
securityGroups.add(hadoopSecurityGroup);
}
}
domain.setSecurityGroups(securityGroups);
domain.setVersionName(domain.getVersionName());
if (feedMetadata.getTags() != null) {
domain.setTags(feedMetadata.getTags().stream().map(Tag::getName).collect(Collectors.toSet()));
}
// Create a new feed metadata stripped of any excess data that does
// not need to be serialized and stored in the feed domain entity.
FeedMetadata stripped = stripMetadata(feedMetadata);
domain.setJson(ObjectMapperSerializer.serialize(stripped));
return domain;
}
use of com.thinkbiganalytics.metadata.api.category.Category in project kylo by Teradata.
the class FeedImporter method validateEntityAccess.
private boolean validateEntityAccess(FeedMetadata existingFeed, String feedCategory) {
FeedMetadata importingFeed = importFeed.getFeedToImport();
if (existingFeed != null) {
FeedMetadata userAccessFeed = metadataAccess.read(() -> {
return metadataService.getFeedByName(feedCategory, importingFeed.getSystemFeedName());
});
if (userAccessFeed == null || !userAccessFeed.hasAction(FeedAccessControl.EDIT_DETAILS.getSystemName())) {
// error
importFeed.setValid(false);
if (importFeed.getTemplate() == null) {
ImportTemplate importTemplate = new ImportTemplate(importFeed.getFileName());
importFeed.setTemplate(importTemplate);
}
String msg = "Access Denied. You do not have access to edit this feed.";
importFeed.getImportOptions().addErrorMessage(ImportComponent.FEED_DATA, msg);
importFeed.addErrorMessage(existingFeed, msg);
importFeed.setValid(false);
return false;
} else {
return true;
}
} else {
// ensure the user can create under the category
Category category = metadataAccess.read(() -> {
return categoryProvider.findBySystemName(feedCategory);
}, MetadataAccess.SERVICE);
if (category == null) {
// ensure the user has functional access to create categories
boolean hasPermission = accessController.hasPermission(AccessController.SERVICES, FeedServicesAccessControl.EDIT_CATEGORIES);
if (!hasPermission) {
String msg = "Access Denied. The category for this feed," + feedCategory + ", doesn't exist and you do not have access to create a new category.";
importFeed.getImportOptions().addErrorMessage(ImportComponent.FEED_DATA, msg);
importFeed.addErrorMessage(existingFeed, msg);
importFeed.setValid(false);
return false;
}
return true;
} else {
// if the feed is new ensure the user has write access to create feeds
return metadataAccess.read(() -> {
// Query for Category and ensure the user has access to create feeds on that category
Category domainCategory = categoryProvider.findBySystemName(feedCategory);
if (domainCategory == null || (!domainCategory.getAllowedActions().hasPermission(CategoryAccessControl.CREATE_FEED))) {
String msg = "Access Denied. You do not have access to create feeds under the category " + feedCategory + ". Attempt made to create feed " + FeedNameUtil.fullName(feedCategory, importingFeed.getSystemFeedName()) + ".";
importFeed.getImportOptions().addErrorMessage(ImportComponent.FEED_DATA, msg);
importFeed.addErrorMessage(existingFeed, msg);
importFeed.setValid(false);
return false;
}
/*
TemplateAccessControl.CREATE_FEED permission is not being used right now.
Uncomment this code once/if we should be checking it
// Query for Template and ensure the user has access to create feeds
final RegisteredTemplate domainTemplate = registeredTemplateService.findRegisteredTemplate(
new RegisteredTemplateRequest.Builder().templateName(importingFeed.getTemplateName()).isFeedEdit(true).build());
if (domainTemplate != null && !registeredTemplateService.hasTemplatePermission(domainTemplate.getId(), TemplateAccessControl.CREATE_FEED)) {
final String msg = "Access Denied. You do not have access to create feeds using the template " + importingFeed.getTemplateName()
+ ". Attempt made to create feed " + FeedNameUtil.fullName(feedCategory, importingFeed.getSystemFeedName()) + ".";
feed.getImportOptions().addErrorMessage(ImportComponent.FEED_DATA, msg);
feed.addErrorMessage(existingFeed, msg);
feed.setValid(false);
return false;
}
*/
return true;
});
}
}
}
use of com.thinkbiganalytics.metadata.api.category.Category in project kylo by Teradata.
the class FeedImporter method validate.
public ImportFeed validate() {
UploadProgressMessage feedImportStatusMessage = uploadProgressService.addUploadStatus(importFeedOptions.getUploadKey(), "Validating Feed import.");
try {
init();
// read the JSON into the Feed object
FeedMetadata metadata = importFeed.getFeedToImport();
// validate the incoming category exists
validateFeedCategory();
// verify if we should overwrite the feed if it already exists
String feedCategory = StringUtils.isNotBlank(importFeedOptions.getCategorySystemName()) ? importFeedOptions.getCategorySystemName() : metadata.getSystemCategoryName();
// query for this feed.
// first read in the feed as a service account
FeedMetadata existingFeed = metadataAccess.read(() -> {
return metadataService.getFeedByName(feedCategory, metadata.getSystemFeedName());
}, MetadataAccess.SERVICE);
if (!validateOverwriteExistingFeed(existingFeed)) {
// exit
return importFeed;
}
if (accessController.isEntityAccessControlled()) {
if (!validateEntityAccess(existingFeed, feedCategory)) {
return importFeed;
}
}
// sensitive properties
if (!validateSensitiveProperties()) {
return importFeed;
}
// Valid data sources
if (!validateUserDatasources()) {
return importFeed;
}
// UploadProgressMessage statusMessage = uploadProgressService.addUploadStatus(options.getUploadKey(),"Validating the template data");
TemplateImporter templateImporter = templateImporterFactory.apply(importFeed.getFileName(), file, importFeedOptions);
ImportTemplate importTemplate = templateImporter.validate();
// need to set the importOptions back to the feed options
// find importOptions for the Template and add them back to the set of options
// importFeed.getImportOptions().updateOptions(importTemplate.getImportOptions().getImportComponentOptions());
importFeed.setTemplate(importTemplate);
// statusMessage.update("Validated the template data",importTemplate.isValid());
if (!importTemplate.isValid()) {
importFeed.setValid(false);
List<String> errorMessages = importTemplate.getTemplateResults().getAllErrors().stream().map(nifiError -> nifiError.getMessage()).collect(Collectors.toList());
if (!errorMessages.isEmpty()) {
for (String msg : errorMessages) {
importFeed.addErrorMessage(metadata, msg);
}
}
}
// statusMessage = uploadProgressService.addUploadStatus(options.getUploadKey(),"Validation complete: the feed is "+(importFeed.isValid() ? "valid" : "invalid"),true,importFeed.isValid());
} catch (Exception e) {
feedImportStatusMessage.update("Validation error. Feed import error: " + e.getMessage(), false);
throw new UnsupportedOperationException("Error importing template " + fileName + ". " + e.getMessage());
}
feedImportStatusMessage.update("Validated Feed import.", importFeed.isValid());
return this.importFeed;
}
use of com.thinkbiganalytics.metadata.api.category.Category in project kylo by Teradata.
the class DefaultSecurityService method accessCategory.
private Optional<Category> accessCategory(String id) {
this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_CATEGORIES);
Category.ID catId = categoryProvider.resolveId(id);
Category category = categoryProvider.findById(catId);
return Optional.ofNullable(category);
}
Aggregations