use of org.talend.dataprep.metrics.Timed in project data-prep by Talend.
the class FolderAPI method renameFolder.
@RequestMapping(value = "/api/folders/{id}/name", method = PUT)
@ApiOperation(value = "Rename a Folder")
@Timed
public void renameFolder(@PathVariable final String id, @RequestBody final String newName) {
if (StringUtils.isEmpty(id) || StringUtils.isEmpty(newName)) {
throw new TDPException(APIErrorCodes.UNABLE_TO_RENAME_FOLDER);
}
try {
final HystrixCommand<Void> renameFolder = getCommand(RenameFolder.class, id, newName);
renameFolder.execute();
} catch (Exception e) {
throw new TDPException(APIErrorCodes.UNABLE_TO_RENAME_FOLDER, e);
}
}
use of org.talend.dataprep.metrics.Timed in project data-prep by Talend.
the class PreparationAPI method createPreparation.
// @formatter:off
@RequestMapping(value = "/api/preparations", method = POST, produces = TEXT_PLAIN_VALUE)
@ApiOperation(value = "Create a new preparation for preparation content in body.", notes = "Returns the created preparation id.")
@Timed
public String createPreparation(@ApiParam(name = "folder", value = "Where to store the preparation.") @RequestParam(value = "folder") String folder, @ApiParam(name = "body", value = "The original preparation. You may set all values, service will override values you can't write to.") @RequestBody Preparation preparation) {
if (LOG.isDebugEnabled()) {
LOG.debug("Creating a preparation in {} (pool: {} )...", folder, getConnectionStats());
}
DataSetGetMetadata dataSetMetadata = getCommand(DataSetGetMetadata.class, preparation.getDataSetId());
DataSetMetadata execute = dataSetMetadata.execute();
preparation.setRowMetadata(execute.getRowMetadata());
PreparationCreate preparationCreate = getCommand(PreparationCreate.class, preparation, folder);
final String preparationId = preparationCreate.execute();
LOG.info("New Preparation #{}, name: {}, created in folder {}", preparationId, preparation.getName(), folder);
return preparationId;
}
use of org.talend.dataprep.metrics.Timed in project data-prep by Talend.
the class PreparationAPI method updatePreparation.
@RequestMapping(value = "/api/preparations/{id}", method = PUT, consumes = APPLICATION_JSON_VALUE, produces = TEXT_PLAIN_VALUE)
@ApiOperation(value = "Update a preparation with content in body.", notes = "Returns the updated preparation id.")
@Timed
public String updatePreparation(@ApiParam(name = "id", value = "The id of the preparation to update.") @PathVariable("id") String id, @ApiParam(name = "body", value = "The updated preparation. Null values are ignored during update. You may set all values, service will override values you can't write to.") @RequestBody Preparation preparation) {
if (LOG.isDebugEnabled()) {
LOG.debug("Updating preparation (pool: {} )...", getConnectionStats());
}
PreparationUpdate preparationUpdate = getCommand(PreparationUpdate.class, id, preparation);
final String preparationId = preparationUpdate.execute();
if (LOG.isDebugEnabled()) {
LOG.debug("Updated preparation (pool: {} )...", getConnectionStats());
}
return preparationId;
}
use of org.talend.dataprep.metrics.Timed in project data-prep by Talend.
the class DataSetService method get.
/**
* Returns the <b>full</b> data set content for given id.
*
* @param metadata If <code>true</code>, includes data set metadata information.
* @param dataSetId A data set id.
* @return The full data set.
*/
@RequestMapping(value = "/datasets/{id}/content", method = RequestMethod.GET)
@ApiOperation(value = "Get a data set by id", notes = "Get a data set content based on provided id. Id should be a UUID returned by the list operation. Not valid or non existing data set id returns empty content.")
@Timed
@ResponseBody
public Callable<DataSet> get(@RequestParam(defaultValue = "true") @ApiParam(name = "metadata", value = "Include metadata information in the response") boolean metadata, @RequestParam(defaultValue = "false") @ApiParam(name = "includeInternalContent", value = "Include internal content in the response") boolean includeInternalContent, @ApiParam(value = "Filter for retrieved content.") @RequestParam(value = "filter", defaultValue = "") String filter, @PathVariable(value = "id") @ApiParam(name = "id", value = "Id of the requested data set") String dataSetId) {
return () -> {
final Marker marker = Markers.dataset(dataSetId);
LOG.debug(marker, "Get data set #{}", dataSetId);
try {
DataSetMetadata dataSetMetadata = dataSetMetadataRepository.get(dataSetId);
assertDataSetMetadata(dataSetMetadata, dataSetId);
// Build the result
DataSet dataSet = new DataSet();
if (metadata) {
dataSet.setMetadata(conversionService.convert(dataSetMetadata, UserDataSetMetadata.class));
}
// Disable line limit
Stream<DataSetRow> stream = contentStore.stream(dataSetMetadata, -1);
if (!includeInternalContent) {
LOG.debug("Skip internal content when serving data set #{} content.", dataSetId);
stream = stream.map(r -> {
final Map<String, Object> values = r.values();
final Map<String, Object> filteredValues = new HashMap<>(values);
values.forEach((k, v) -> {
if (k != null && k.startsWith(FlagNames.INTERNAL_PROPERTY_PREFIX)) {
// Removes technical
// properties
// from returned
// values.
filteredValues.remove(k);
}
});
// Include TDP_ID anyway
filteredValues.put(FlagNames.TDP_ID, r.getTdpId());
return new DataSetRow(r.getRowMetadata(), filteredValues);
});
}
// Filter content
stream = stream.filter(filterService.build(URLDecoder.decode(filter, "UTF-8"), dataSetMetadata.getRowMetadata()));
dataSet.setRecords(stream);
return dataSet;
} finally {
LOG.debug(marker, "Get done.");
}
};
}
use of org.talend.dataprep.metrics.Timed 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();
}
}
}
Aggregations