Search in sources :

Example 1 with ExportFeed

use of com.thinkbiganalytics.metadata.api.feed.export.ExportFeed in project kylo by Teradata.

the class DefaultFeedExporter method exportFeed.

/**
 * Export a feed as a zip file
 *
 * @param feedId the id {@link Feed#getId()} of the feed to export
 * @return object containing the zip file with data about the feed.
 */
@Override
public ExportFeed exportFeed(String feedId) throws IOException {
    this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.EXPORT_FEEDS);
    this.metadataService.checkFeedPermission(feedId, FeedAccessControl.EXPORT);
    // Prepare feed metadata
    final FeedMetadata feed = metadataService.getFeedById(feedId);
    if (feed == null) {
        // feed will not be found when user is allowed to export feeds but has no entity access to feed with feed id
        throw new NotFoundException("Feed not found for id " + feedId);
    }
    final List<Datasource> userDatasources = Optional.ofNullable(feed.getDataTransformation()).map(FeedDataTransformation::getDatasourceIds).map(datasourceIds -> metadataAccess.read(() -> datasourceIds.stream().map(datasourceProvider::resolve).map(datasourceProvider::getDatasource).map(domain -> datasourceTransform.toDatasource(domain, DatasourceModelTransform.Level.FULL)).map(datasource -> {
        // Clear sensitive fields
        datasource.getDestinationForFeeds().clear();
        datasource.getSourceForFeeds().clear();
        return datasource;
    }).collect(Collectors.toList()))).orElse(null);
    if (userDatasources != null && !userDatasources.isEmpty()) {
        this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_DATASOURCES);
        feed.setUserDatasources(userDatasources);
    }
    // Add feed json to template zip file
    final ExportTemplate exportTemplate = templateExporter.exportTemplateForFeedExport(feed.getTemplateId());
    final String feedJson = ObjectMapperSerializer.serialize(feed);
    final byte[] zipFile = ZipFileUtil.addToZip(exportTemplate.getFile(), feedJson, ImportFeed.FEED_JSON_FILE);
    return new ExportFeed(feed.getSystemFeedName() + ".feed.zip", zipFile);
}
Also used : Datasource(com.thinkbiganalytics.metadata.rest.model.data.Datasource) FeedDataTransformation(com.thinkbiganalytics.feedmgr.rest.model.FeedDataTransformation) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) ExportFeed(com.thinkbiganalytics.metadata.api.feed.export.ExportFeed) DatasourceModelTransform(com.thinkbiganalytics.feedmgr.service.datasource.DatasourceModelTransform) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) DefaultTemplateExporter(com.thinkbiganalytics.feedmgr.service.template.exporting.DefaultTemplateExporter) Inject(javax.inject.Inject) ObjectMapperSerializer(com.thinkbiganalytics.json.ObjectMapperSerializer) FeedAccessControl(com.thinkbiganalytics.metadata.api.feed.security.FeedAccessControl) AccessController(com.thinkbiganalytics.security.AccessController) FeedServicesAccessControl(com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) MetadataService(com.thinkbiganalytics.feedmgr.service.MetadataService) Datasource(com.thinkbiganalytics.metadata.rest.model.data.Datasource) TemplateExporter(com.thinkbiganalytics.metadata.api.template.export.TemplateExporter) IOException(java.io.IOException) FeedExporter(com.thinkbiganalytics.metadata.api.feed.export.FeedExporter) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) ZipFileUtil(com.thinkbiganalytics.feedmgr.support.ZipFileUtil) ExportTemplate(com.thinkbiganalytics.metadata.api.template.export.ExportTemplate) List(java.util.List) ImportFeed(com.thinkbiganalytics.feedmgr.service.feed.importing.model.ImportFeed) Optional(java.util.Optional) DatasourceProvider(com.thinkbiganalytics.metadata.api.datasource.DatasourceProvider) ExportFeed(com.thinkbiganalytics.metadata.api.feed.export.ExportFeed) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) FeedDataTransformation(com.thinkbiganalytics.feedmgr.rest.model.FeedDataTransformation) NotFoundException(javax.ws.rs.NotFoundException) ExportTemplate(com.thinkbiganalytics.metadata.api.template.export.ExportTemplate)

Aggregations

FeedDataTransformation (com.thinkbiganalytics.feedmgr.rest.model.FeedDataTransformation)1 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)1 FeedServicesAccessControl (com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl)1 MetadataService (com.thinkbiganalytics.feedmgr.service.MetadataService)1 DatasourceModelTransform (com.thinkbiganalytics.feedmgr.service.datasource.DatasourceModelTransform)1 ImportFeed (com.thinkbiganalytics.feedmgr.service.feed.importing.model.ImportFeed)1 DefaultTemplateExporter (com.thinkbiganalytics.feedmgr.service.template.exporting.DefaultTemplateExporter)1 ZipFileUtil (com.thinkbiganalytics.feedmgr.support.ZipFileUtil)1 ObjectMapperSerializer (com.thinkbiganalytics.json.ObjectMapperSerializer)1 MetadataAccess (com.thinkbiganalytics.metadata.api.MetadataAccess)1 DatasourceProvider (com.thinkbiganalytics.metadata.api.datasource.DatasourceProvider)1 Feed (com.thinkbiganalytics.metadata.api.feed.Feed)1 ExportFeed (com.thinkbiganalytics.metadata.api.feed.export.ExportFeed)1 FeedExporter (com.thinkbiganalytics.metadata.api.feed.export.FeedExporter)1 FeedAccessControl (com.thinkbiganalytics.metadata.api.feed.security.FeedAccessControl)1 ExportTemplate (com.thinkbiganalytics.metadata.api.template.export.ExportTemplate)1 TemplateExporter (com.thinkbiganalytics.metadata.api.template.export.TemplateExporter)1 Datasource (com.thinkbiganalytics.metadata.rest.model.data.Datasource)1 AccessController (com.thinkbiganalytics.security.AccessController)1 IOException (java.io.IOException)1