use of com.thinkbiganalytics.metadata.api.feed.reindex.HistoryReindexingStatus 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 inputId = feedMetadata.getId() != null ? feedProvider.resolveId(feedMetadata.getId()) : null;
Feed domain = inputId != null ? feedProvider.findById(inputId) : null;
FeedCategory restCategoryModel = feedMetadata.getCategory();
Category category = restCategoryModel != null ? categoryProvider.findById(categoryProvider.resolveId(restCategoryModel.getId())) : null;
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());
inputId = domain.getId();
Feed.State state = Feed.State.valueOf(feedMetadata.getState());
domain.setState(state);
// reassign the domain data back to the ui model....
feedMetadata.setFeedId(inputId.toString());
feedMetadata.setState(state.name());
}
final Feed.ID domainId = inputId;
// Check if the category is changing
if (category != null && !category.getId().equals(domain.getCategory().getId())) {
domain = feedProvider.moveFeed(domain, category);
}
// Check if the feed system name is changing
if (!domain.getSystemName().equals(feedMetadata.getSystemFeedName())) {
domain = feedProvider.changeSystemName(domain, feedMetadata.getSystemFeedName());
// Make sure the table schema name matches the system name.
if (feedMetadata.getTable() != null && feedMetadata.getTable().getTableSchema() != null) {
feedMetadata.getTable().getTableSchema().setName(feedMetadata.getSystemFeedName());
}
}
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.feed.reindex.HistoryReindexingStatus in project kylo by Teradata.
the class FeedData method createHistoryReindexingStatus.
private HistoryReindexingStatus createHistoryReindexingStatus(Node historyReindexingNode) {
HistoryReindexingState historyReindexingState = HistoryReindexingState.valueOf(JcrPropertyUtil.getString(historyReindexingNode, REINDEXING_STATUS));
DateTime lastModifiedTimestamp = JcrPropertyUtil.getProperty(historyReindexingNode, "jcr:lastModified");
return new HistoryReindexingStatus(historyReindexingState, lastModifiedTimestamp);
}
Aggregations