use of com.thinkbiganalytics.metadata.api.catalog.DataSourceProvider in project kylo by Teradata.
the class SparkShellProxyController method resolveDatasources.
/**
* Retrieves all details of the specified data sources.
*/
@Nonnull
private List<Datasource> resolveDatasources(@Nonnull final List<Datasource> sources) {
// Verify access to data sources
accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_DATASOURCES);
final List<com.thinkbiganalytics.metadata.api.datasource.Datasource.ID> datasourceIds = metadata.read(() -> sources.stream().map(com.thinkbiganalytics.metadata.datasource.Datasource::getId).map(datasourceProvider::resolve).map(id -> {
final com.thinkbiganalytics.metadata.api.datasource.Datasource datasource = datasourceProvider.getDatasource(id);
if (datasource != null) {
return datasource.getId();
} else {
throw new BadRequestException("No datasource exists with the given ID: " + id);
}
}).collect(Collectors.toList()));
// Retrieve admin-level details
return metadata.read(() -> datasourceIds.stream().map(datasourceProvider::getDatasource).map(datasource -> {
if (datasource instanceof com.thinkbiganalytics.metadata.api.datasource.UserDatasource) {
return (com.thinkbiganalytics.metadata.datasource.Datasource) datasourceTransform.toDatasource(datasource, DatasourceModelTransform.Level.ADMIN);
} else {
throw new BadRequestException("Not a supported datasource: " + datasource.getClass().getSimpleName() + " " + datasource.getId());
}
}).map(datasource -> {
if (datasource instanceof com.thinkbiganalytics.metadata.datasource.JdbcDatasource) {
return new JdbcDatasource((com.thinkbiganalytics.metadata.datasource.JdbcDatasource) datasource);
} else {
throw new BadRequestException("Not a supported datasource: " + datasource.getClass().getSimpleName());
}
}).collect(Collectors.toList()), MetadataAccess.SERVICE);
}
Aggregations