Search in sources :

Example 1 with FeedDataTransformation

use of com.thinkbiganalytics.feedmgr.rest.model.FeedDataTransformation 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)

Example 2 with FeedDataTransformation

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

the class ImportUtil method replaceDatasource.

/**
 * Replaces the specified data source id with a new data source id.
 *
 * @param metadata the feed metadata
 * @param oldDatasourceId the id of the data source to be replaced
 * @param newDatasourceId the id of the new data source
 */
@SuppressWarnings("unchecked")
public static void replaceDatasource(@Nonnull final FeedMetadata metadata, @Nonnull final String oldDatasourceId, @Nonnull final String newDatasourceId) {
    // Update data transformation
    final FeedDataTransformation transformation = metadata.getDataTransformation();
    if (transformation != null) {
        // Update chart view model
        Optional.of(transformation.getChartViewModel()).map(model -> (List<Map<String, Object>>) model.get("nodes")).ifPresent(nodes -> nodes.forEach(node -> {
            final String nodeDatasourceId = (String) node.get("datasourceId");
            if (nodeDatasourceId != null && oldDatasourceId.equals(nodeDatasourceId)) {
                node.put("datasourceId", newDatasourceId);
            }
        }));
        // Update data source id list
        transformation.getDatasourceIds().replaceAll(id -> oldDatasourceId.equals(id) ? newDatasourceId : id);
        // Update transform script
        final String updatedDataTransformScript = transformation.getDataTransformScript().replace(oldDatasourceId, newDatasourceId);
        transformation.setDataTransformScript(updatedDataTransformScript);
    }
    // Update processor properties
    metadata.getProperties().forEach(property -> {
        final String value = property.getValue();
        if (value != null && !value.isEmpty()) {
            property.setValue(value.replace(oldDatasourceId, newDatasourceId));
        }
    });
}
Also used : FeedDataTransformation(com.thinkbiganalytics.feedmgr.rest.model.FeedDataTransformation) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) StringUtils(org.apache.commons.lang3.StringUtils) ImportOptions(com.thinkbiganalytics.feedmgr.rest.model.ImportOptions) HashSet(java.util.HashSet) ObjectMapperSerializer(com.thinkbiganalytics.json.ObjectMapperSerializer) ByteArrayInputStream(java.io.ByteArrayInputStream) ImportProperty(com.thinkbiganalytics.feedmgr.rest.model.ImportProperty) Map(java.util.Map) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ImportType(com.thinkbiganalytics.feedmgr.rest.ImportType) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) ZipEntry(java.util.zip.ZipEntry) Nonnull(javax.annotation.Nonnull) RemoteProcessGroupInputPort(com.thinkbiganalytics.feedmgr.rest.model.RemoteProcessGroupInputPort) ImportTemplate(com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) FeedNameUtil(com.thinkbiganalytics.support.FeedNameUtil) StringWriter(java.io.StringWriter) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ZipFileUtil(com.thinkbiganalytics.feedmgr.support.ZipFileUtil) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) ImportFeed(com.thinkbiganalytics.feedmgr.service.feed.importing.model.ImportFeed) Optional(java.util.Optional) ImportComponent(com.thinkbiganalytics.feedmgr.rest.ImportComponent) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup) InputStream(java.io.InputStream) FeedDataTransformation(com.thinkbiganalytics.feedmgr.rest.model.FeedDataTransformation) List(java.util.List)

Aggregations

FeedDataTransformation (com.thinkbiganalytics.feedmgr.rest.model.FeedDataTransformation)2 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)2 ImportFeed (com.thinkbiganalytics.feedmgr.service.feed.importing.model.ImportFeed)2 ZipFileUtil (com.thinkbiganalytics.feedmgr.support.ZipFileUtil)2 ObjectMapperSerializer (com.thinkbiganalytics.json.ObjectMapperSerializer)2 IOException (java.io.IOException)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ImportComponent (com.thinkbiganalytics.feedmgr.rest.ImportComponent)1 ImportType (com.thinkbiganalytics.feedmgr.rest.ImportType)1 ImportComponentOption (com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption)1 ImportOptions (com.thinkbiganalytics.feedmgr.rest.model.ImportOptions)1 ImportProperty (com.thinkbiganalytics.feedmgr.rest.model.ImportProperty)1 RegisteredTemplate (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)1 RemoteProcessGroupInputPort (com.thinkbiganalytics.feedmgr.rest.model.RemoteProcessGroupInputPort)1 ReusableTemplateConnectionInfo (com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo)1 FeedServicesAccessControl (com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl)1 MetadataService (com.thinkbiganalytics.feedmgr.service.MetadataService)1