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