use of org.talend.dataprep.security.PublicAPI in project data-prep by Talend.
the class UpgradeAPI method check.
@RequestMapping(value = "/api/upgrade/check", method = GET)
@ApiOperation(value = "Checks if a newer versions are available and returns them as JSON.", produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
@PublicAPI
public Stream<UpgradeServerVersion> check() {
// defensive programming
if (StringUtils.isBlank(upgradeVersionLocation)) {
return Stream.empty();
}
try {
// Get current version
final Version parsedCurrentVersion = fromInternal(service.version());
// POST to URL that serves a JSON Version object
LOGGER.debug("Contacting upgrade server @ '{}'", upgradeVersionLocation);
List<UpgradeServerVersion> versions = fetchServerUpgradeVersions(service.version());
LOGGER.debug("{} available version(s) returned by update server: {}", versions.size(), toString(versions));
// Compare current version with available and filter new versions
return versions.stream().filter(v -> Version.valueOf(v.getVersion()).greaterThan(parsedCurrentVersion));
} catch (Exception e) {
LOGGER.error("Unable to check for new version (message: {}).", e.getMessage());
LOGGER.debug("Exception occurred during new version check. ", e);
return Stream.empty();
}
}
use of org.talend.dataprep.security.PublicAPI in project data-prep by Talend.
the class VersionServiceAPI method allVersions.
/**
* Returns all the versions of the different services (api, dataset, preparation and transformation) and the global
* application version.
*
* @return an array of service versions
*/
@RequestMapping(value = "/api/version", method = GET)
@ApiOperation(value = "Get the version of all services (including underlying low level services)", produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
@PublicAPI
public BuildDetails allVersions() {
List<Version> versions = new ArrayList<>();
for (VersionsSupplier versionsSupplier : versionsSuppliers) {
versions.addAll(versionsSupplier.getVersions());
}
CollectionUtils.filter(versions, PredicateUtils.notNullPredicate());
return new BuildDetails(applicationVersion, versions.toArray(new Version[versions.size()]));
}
use of org.talend.dataprep.security.PublicAPI in project data-prep by Talend.
the class DataSetService method getImportParameters.
@RequestMapping(value = "/datasets/imports/{import}/parameters", method = GET, produces = APPLICATION_JSON_VALUE)
@ApiOperation(value = "Get the import parameters", notes = "This list can be used by user to change dataset encoding.")
@Timed
@PublicAPI
public // ComponentProperties
Object getImportParameters(@PathVariable("import") final String importType) {
DataSetLocation matchingDatasetLocation = locationsService.findLocation(importType);
Object parametersToReturn;
if (matchingDatasetLocation == null) {
parametersToReturn = emptyList();
} else {
if (matchingDatasetLocation.isSchemaOriented()) {
parametersToReturn = matchingDatasetLocation.getParametersAsSchema(getLocale());
} else {
parametersToReturn = matchingDatasetLocation.getParameters(getLocale());
}
}
return parametersToReturn;
}
use of org.talend.dataprep.security.PublicAPI in project data-prep by Talend.
the class DataSetService method getDataSetColumnSemanticCategories.
/**
* Return the semantic types for a given dataset / column.
*
* @param datasetId the datasetId id.
* @param columnId the column id.
* @return the semantic types for a given dataset / column.
*/
@RequestMapping(value = "/datasets/{datasetId}/columns/{columnId}/types", method = GET)
@ApiOperation(value = "list the types of the wanted column", notes = "This list can be used by user to change the column type.")
@Timed
@PublicAPI
public List<SemanticDomain> getDataSetColumnSemanticCategories(@ApiParam(value = "The dataset id") @PathVariable String datasetId, @ApiParam(value = "The column id") @PathVariable String columnId) {
LOG.debug("listing semantic categories for dataset #{} column #{}", datasetId, columnId);
final DataSetMetadata metadata = dataSetMetadataRepository.get(datasetId);
if (metadata == null) {
throw new TDPException(DataSetErrorCodes.DATASET_DOES_NOT_EXIST, ExceptionContext.withBuilder().put("id", datasetId).build());
} else {
try (final Stream<DataSetRow> records = contentStore.stream(metadata)) {
final ColumnMetadata columnMetadata = metadata.getRowMetadata().getById(columnId);
final Analyzer<Analyzers.Result> analyzer = analyzerService.build(columnMetadata, SEMANTIC);
analyzer.init();
records.map(r -> r.get(columnId)).forEach(analyzer::analyze);
analyzer.end();
final List<Analyzers.Result> analyzerResult = analyzer.getResult();
final StatisticsAdapter statisticsAdapter = new StatisticsAdapter(40);
statisticsAdapter.adapt(singletonList(columnMetadata), analyzerResult);
LOG.debug("found {} for dataset #{}, column #{}", columnMetadata.getSemanticDomains(), datasetId, columnId);
return columnMetadata.getSemanticDomains();
}
}
}
use of org.talend.dataprep.security.PublicAPI in project data-prep by Talend.
the class TransformationService method getPreparationColumnSemanticCategories.
/**
* Return the semantic types for a given preparation / column.
*
* @param preparationId the preparation id.
* @param columnId the column id.
* @param stepId the step id (optional, if not specified, it's 'head')
* @return the semantic types for a given preparation / column.
*/
@RequestMapping(value = "/preparations/{preparationId}/columns/{columnId}/types", method = GET)
@ApiOperation(value = "list the types of the wanted column", notes = "This list can be used by user to change the column type.")
@Timed
@PublicAPI
public List<SemanticDomain> getPreparationColumnSemanticCategories(@ApiParam(value = "The preparation id") @PathVariable String preparationId, @ApiParam(value = "The column id") @PathVariable String columnId, @ApiParam(value = "The preparation version") @RequestParam(defaultValue = "head") String stepId) {
LOG.debug("listing preparation semantic categories for preparation #{} column #{}@{}", preparationId, columnId, stepId);
// get the preparation
final Preparation preparation = getPreparation(preparationId);
// get the step (in case of 'head', the real step id must be found)
final String version = //
StringUtils.equals("head", stepId) ? preparation.getSteps().get(preparation.getSteps().size() - 1).getId() : stepId;
/*
* OK, this one is a bit tricky so pay attention.
*
* To be able to get the semantic types, the analyzer service needs to run on the result of the preparation.
*
* The result must be found in the cache, so if the preparation is not cached, the preparation is run so that
* it gets cached.
*
* Then, the analyzer service just gets the data from the cache. That's it.
*/
// generate the cache keys for both metadata & content
final ContentCacheKey metadataKey = cacheKeyGenerator.metadataBuilder().preparationId(preparationId).stepId(version).sourceType(HEAD).build();
final ContentCacheKey contentKey = cacheKeyGenerator.contentBuilder().datasetId(preparation.getDataSetId()).preparationId(preparationId).stepId(//
version).format(JSON).sourceType(//
HEAD).build();
// if the preparation is not cached, let's compute it to have some cache
if (!contentCache.has(metadataKey) || !contentCache.has(contentKey)) {
addPreparationInCache(preparation, stepId);
}
// run the analyzer service on the cached content
try (final InputStream metadataCache = contentCache.get(metadataKey);
final InputStream contentCache = this.contentCache.get(contentKey)) {
final DataSetMetadata metadata = mapper.readerFor(DataSetMetadata.class).readValue(metadataCache);
final List<SemanticDomain> semanticDomains = getSemanticDomains(metadata, columnId, contentCache);
LOG.debug("found {} for preparation #{}, column #{}", semanticDomains, preparationId, columnId);
return semanticDomains;
} catch (IOException e) {
throw new TDPException(UNEXPECTED_EXCEPTION, e);
}
}
Aggregations