Search in sources :

Example 31 with PathVariable

use of org.springframework.web.bind.annotation.PathVariable in project vorto by eclipse.

the class CommentController method getCommentsforModelId.

@RequestMapping(method = RequestMethod.GET, value = "/{modelId:.+}", produces = "application/json")
@PreAuthorize("hasAuthority('model_viewer')")
public List<Comment> getCommentsforModelId(@ApiParam(value = "modelId", required = true) @PathVariable String modelId) {
    final ModelId modelID = ModelId.fromPrettyFormat(modelId);
    Optional<String> maybeWorkspaceId = namespaceService.resolveWorkspaceIdForNamespace(modelID.getNamespace());
    if (!maybeWorkspaceId.isPresent()) {
        LOGGER.error(String.format("Namespace [%s] does not exist.", modelID.getNamespace()));
        return Collections.emptyList();
    }
    return commentService.getCommentsforModelId(modelID).stream().map(comment -> ModelDtoFactory.createDto(comment, UserContext.user(SecurityContextHolder.getContext().getAuthentication().getName(), maybeWorkspaceId.get()))).collect(Collectors.toList());
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) DoesNotExistException(org.eclipse.vorto.repository.services.exceptions.DoesNotExistException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Valid(javax.validation.Valid) RequestBody(org.springframework.web.bind.annotation.RequestBody) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) Logger(org.slf4j.Logger) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) ICommentService(org.eclipse.vorto.repository.comment.ICommentService) ModelDtoFactory(org.eclipse.vorto.repository.web.core.ModelDtoFactory) Collectors(java.util.stream.Collectors) ModelId(org.eclipse.vorto.model.ModelId) RestController(org.springframework.web.bind.annotation.RestController) NamespaceService(org.eclipse.vorto.repository.services.NamespaceService) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) Comment(org.eclipse.vorto.repository.domain.Comment) Collections(java.util.Collections) UserContext(org.eclipse.vorto.repository.core.impl.UserContext) ModelId(org.eclipse.vorto.model.ModelId) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 32 with PathVariable

use of org.springframework.web.bind.annotation.PathVariable in project data-prep by Talend.

the class DataSetAPI method getPreparation.

/**
 * Return the list of preparation using a dataset
 *
 * @param id the wanted dataset.
 * @return the list of preparation using the dataset
 */
@RequestMapping(value = "/api/datasets/{id}/preparations", method = GET, produces = APPLICATION_JSON_VALUE)
@ApiOperation(value = "Get the list of preparation using a dataset by the dataset id.", produces = APPLICATION_JSON_VALUE, notes = "Get the list of preparation using a dataset by the dataset id.")
@Timed
public List<DatasetDetailsDTO.Preparation> getPreparation(@ApiParam(value = "Id of the data set to get") @PathVariable(value = "id") String id) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Requesting preparations using dataset #{} (pool: {})...", id, getConnectionStats());
    }
    try {
        DatasetDetailsDTO details = datasetClient.getDataSetDetails(id);
        // Add the related preparations list to the given dataset metadata.
        final PreparationSearchByDataSetId getPreparations = getCommand(PreparationSearchByDataSetId.class, details.getId());
        List<DatasetDetailsDTO.Preparation> preps = new ArrayList<>();
        // 
        toStream(PreparationDTO.class, mapper, getPreparations).filter(p -> p.getSteps() != null).forEach(p -> preps.add(new DatasetDetailsDTO.Preparation(p.getId(), p.getName(), (long) p.getSteps().size(), p.getLastModificationDate())));
        return preps;
    } finally {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Request preparations using dataset #{} (pool: {}) done.", id, getConnectionStats());
        }
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) UpdateDataSet(org.talend.dataprep.api.service.command.dataset.UpdateDataSet) StringUtils.containsIgnoreCase(org.apache.commons.lang3.StringUtils.containsIgnoreCase) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiParam(io.swagger.annotations.ApiParam) SetFavorite(org.talend.dataprep.api.service.command.dataset.SetFavorite) DatasetDetailsDTO(org.talend.dataprep.api.dataset.DatasetDetailsDTO) CommandHelper.toStream(org.talend.dataprep.command.CommandHelper.toStream) DatasetDTO(org.talend.dataprep.api.dataset.DatasetDTO) TEXT_PLAIN_VALUE(org.springframework.http.MediaType.TEXT_PLAIN_VALUE) CommandHelper.toStreaming(org.talend.dataprep.command.CommandHelper.toStreaming) SemanticDomain(org.talend.dataprep.api.dataset.statistics.SemanticDomain) ApiOperation(io.swagger.annotations.ApiOperation) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) DataSet(org.talend.dataprep.api.dataset.DataSet) CertificationState(org.talend.dataprep.dataset.adapter.Dataset.CertificationState) Order(org.talend.dataprep.util.SortAndOrderHelper.Order) MediaType(org.springframework.http.MediaType) UpdateColumn(org.talend.dataprep.api.service.command.dataset.UpdateColumn) PublicAPI(org.talend.dataprep.security.PublicAPI) StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) DataSetPreview(org.talend.dataprep.api.service.command.dataset.DataSetPreview) List(java.util.List) HystrixCommand(com.netflix.hystrix.HystrixCommand) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) Stream(java.util.stream.Stream) GetDataSetColumnTypes(org.talend.dataprep.api.service.command.dataset.GetDataSetColumnTypes) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) PreparationList(org.talend.dataprep.api.service.command.preparation.PreparationList) CopyDataSet(org.talend.dataprep.api.service.command.dataset.CopyDataSet) GenericCommand(org.talend.dataprep.command.GenericCommand) SuggestLookupActions(org.talend.dataprep.api.service.command.transformation.SuggestLookupActions) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Callable(java.util.concurrent.Callable) CreateOrUpdateDataSet(org.talend.dataprep.api.service.command.dataset.CreateOrUpdateDataSet) SortAndOrderHelper(org.talend.dataprep.util.SortAndOrderHelper) GET(org.springframework.web.bind.annotation.RequestMethod.GET) PreparationSearchByDataSetId(org.talend.dataprep.api.service.command.preparation.PreparationSearchByDataSetId) DatasetClient(org.talend.dataprep.dataset.adapter.DatasetClient) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) CONTENT_TYPE(org.springframework.http.HttpHeaders.CONTENT_TYPE) Charset(java.nio.charset.Charset) CompatibleDataSetList(org.talend.dataprep.api.service.command.dataset.CompatibleDataSetList) POST(org.springframework.web.bind.annotation.RequestMethod.POST) DataSetGetImportParameters(org.talend.dataprep.api.service.command.dataset.DataSetGetImportParameters) DELETE(org.springframework.web.bind.annotation.RequestMethod.DELETE) CreateDataSet(org.talend.dataprep.api.service.command.dataset.CreateDataSet) Sort(org.talend.dataprep.util.SortAndOrderHelper.Sort) APPLICATION_JSON_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_VALUE) StringsHelper(org.talend.dataprep.util.StringsHelper) ActionForm(org.talend.dataprep.api.action.ActionForm) PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) DataSetDelete(org.talend.dataprep.api.service.command.dataset.DataSetDelete) CERTIFIED(org.talend.dataprep.dataset.adapter.Dataset.CertificationState.CERTIFIED) ResponseEntity(org.springframework.http.ResponseEntity) CommandHelper(org.talend.dataprep.command.CommandHelper) EncodingSupport(org.talend.dataprep.configuration.EncodingSupport) Timed(org.talend.dataprep.metrics.Timed) InputStream(java.io.InputStream) DatasetDetailsDTO(org.talend.dataprep.api.dataset.DatasetDetailsDTO) ArrayList(java.util.ArrayList) PreparationSearchByDataSetId(org.talend.dataprep.api.service.command.preparation.PreparationSearchByDataSetId) Timed(org.talend.dataprep.metrics.Timed) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with PathVariable

use of org.springframework.web.bind.annotation.PathVariable in project data-prep by Talend.

the class PreparationAPI method addPreparationAction.

// TODO: this API should take a list of AppendStep.
@RequestMapping(value = "/api/preparations/{id}/actions", method = POST, produces = APPLICATION_JSON_VALUE)
@ApiOperation(value = "Adds an action at the end of preparation.", notes = "Does not return any value, client may expect successful operation based on HTTP status code.")
@Timed
public void addPreparationAction(@ApiParam(name = "id", value = "Preparation id.") @PathVariable(value = "id") final String preparationId, @ApiParam("Action to add at end of the preparation.") @RequestBody final AppendStep actionsContainer) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Adding action to preparation (pool: {} )...", getConnectionStats());
    }
    // This trick is to keep the API taking and unrolling ONE AppendStep until the codefreeze but this must not stay
    // that way
    List<AppendStep> stepsToAppend = actionsContainer.getActions().stream().map(a -> {
        AppendStep s = new AppendStep();
        s.setActions(singletonList(a));
        return s;
    }).collect(toList());
    getCommand(PreparationAddAction.class, preparationId, stepsToAppend).execute();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Added action to preparation (pool: {} )...", getConnectionStats());
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) PreparationListItemDTO(org.talend.dataprep.api.preparation.PreparationListItemDTO) RequestParam(org.springframework.web.bind.annotation.RequestParam) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiParam(io.swagger.annotations.ApiParam) CommandHelper.toStream(org.talend.dataprep.command.CommandHelper.toStream) StringUtils(org.apache.commons.lang3.StringUtils) TEXT_PLAIN_VALUE(org.springframework.http.MediaType.TEXT_PLAIN_VALUE) Collections.singletonList(java.util.Collections.singletonList) PreparationDelete(org.talend.dataprep.api.service.command.preparation.PreparationDelete) PreparationLock(org.talend.dataprep.api.service.command.preparation.PreparationLock) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) AppendStep(org.talend.dataprep.api.preparation.AppendStep) PreviewDiff(org.talend.dataprep.api.service.command.preparation.PreviewDiff) DataprepBundle.message(org.talend.dataprep.i18n.DataprepBundle.message) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) PreparationDeleteAction(org.talend.dataprep.api.service.command.preparation.PreparationDeleteAction) PreparationSummaryGet(org.talend.dataprep.command.preparation.PreparationSummaryGet) INVALID_HEAD_STEP_USING_DELETED_DATASET(org.talend.dataprep.exception.error.APIErrorCodes.INVALID_HEAD_STEP_USING_DELETED_DATASET) CachePreparationEviction(org.talend.dataprep.api.service.command.preparation.CachePreparationEviction) PreparationDetailsGet(org.talend.dataprep.command.preparation.PreparationDetailsGet) ExportParameters(org.talend.dataprep.api.export.ExportParameters) PreparationUpdate(org.talend.dataprep.command.preparation.PreparationUpdate) Order(org.talend.dataprep.util.SortAndOrderHelper.Order) PublicAPI(org.talend.dataprep.security.PublicAPI) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) DiffMetadata(org.talend.dataprep.api.service.command.preparation.DiffMetadata) PreviewDiffParameters(org.talend.dataprep.api.service.api.PreviewDiffParameters) FindStep(org.talend.dataprep.api.service.command.preparation.FindStep) RestController(org.springframework.web.bind.annotation.RestController) PREPARATION_STEP_DOES_NOT_EXIST(org.talend.dataprep.exception.error.PreparationErrorCodes.PREPARATION_STEP_DOES_NOT_EXIST) APIErrorCodes(org.talend.dataprep.exception.error.APIErrorCodes) List(java.util.List) PreviewAdd(org.talend.dataprep.api.service.command.preparation.PreviewAdd) HystrixCommand(com.netflix.hystrix.HystrixCommand) Stream(java.util.stream.Stream) PreparationGetMetadata(org.talend.dataprep.api.service.command.preparation.PreparationGetMetadata) PreparationGetContent(org.talend.dataprep.api.service.command.preparation.PreparationGetContent) PreparationList(org.talend.dataprep.api.service.command.preparation.PreparationList) PreparationMoveHead(org.talend.dataprep.api.service.command.preparation.PreparationMoveHead) GenericCommand(org.talend.dataprep.command.GenericCommand) TDPException(org.talend.dataprep.exception.TDPException) InjectorUtil(org.talend.dataprep.util.InjectorUtil) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) GET(org.springframework.web.bind.annotation.RequestMethod.GET) DatasetClient(org.talend.dataprep.dataset.adapter.DatasetClient) ArrayList(java.util.ArrayList) RequestBody(org.springframework.web.bind.annotation.RequestBody) PreviewUpdateParameters(org.talend.dataprep.api.service.api.PreviewUpdateParameters) POST(org.springframework.web.bind.annotation.RequestMethod.POST) Action(org.talend.dataprep.api.preparation.Action) PreviewAddParameters(org.talend.dataprep.api.service.api.PreviewAddParameters) PreparationCreate(org.talend.dataprep.api.service.command.preparation.PreparationCreate) Preparation(org.talend.dataprep.api.preparation.Preparation) PreparationUnlock(org.talend.dataprep.api.service.command.preparation.PreparationUnlock) PreparationDetailsDTO(org.talend.dataprep.api.preparation.PreparationDetailsDTO) DELETE(org.springframework.web.bind.annotation.RequestMethod.DELETE) PreviewUpdate(org.talend.dataprep.api.service.command.preparation.PreviewUpdate) ActionRegistry(org.talend.dataprep.transformation.pipeline.ActionRegistry) GetPreparationColumnTypes(org.talend.dataprep.api.service.command.transformation.GetPreparationColumnTypes) HttpResponseContext(org.talend.dataprep.http.HttpResponseContext) PreparationCopyStepsFrom(org.talend.dataprep.api.service.command.preparation.PreparationCopyStepsFrom) Sort(org.talend.dataprep.util.SortAndOrderHelper.Sort) PreparationCopy(org.talend.dataprep.api.service.command.preparation.PreparationCopy) Step(org.talend.dataprep.api.preparation.Step) APPLICATION_JSON_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_VALUE) PreparationAddAction(org.talend.dataprep.api.PreparationAddAction) PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) PreparationReorderStep(org.talend.dataprep.api.service.command.preparation.PreparationReorderStep) PreparationMove(org.talend.dataprep.api.service.command.preparation.PreparationMove) Collectors.toList(java.util.stream.Collectors.toList) Lookup(org.talend.dataprep.transformation.actions.datablending.Lookup) PreparationGetActions(org.talend.dataprep.command.preparation.PreparationGetActions) ResponseEntity(org.springframework.http.ResponseEntity) CommandHelper(org.talend.dataprep.command.CommandHelper) PreparationUpdateAction(org.talend.dataprep.api.service.command.preparation.PreparationUpdateAction) Timed(org.talend.dataprep.metrics.Timed) InputStream(java.io.InputStream) PreparationAddAction(org.talend.dataprep.api.PreparationAddAction) AppendStep(org.talend.dataprep.api.preparation.AppendStep) Timed(org.talend.dataprep.metrics.Timed) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 34 with PathVariable

use of org.springframework.web.bind.annotation.PathVariable in project data-prep by Talend.

the class DataSetService method preview.

/**
 * Returns preview of the the data set content for given id (first 100 rows). Service might return
 * {@link org.apache.http.HttpStatus#SC_ACCEPTED} if the data set exists but analysis is not yet fully
 * completed so content is not yet ready to be served.
 *
 * @param metadata If <code>true</code>, includes data set metadata information.
 * @param sheetName the sheet name to preview
 * @param dataSetId A data set id.
 */
@RequestMapping(value = "/datasets/{id}/preview", method = RequestMethod.GET)
@ApiOperation(value = "Get a data preview set by id", notes = "Get a data set preview content based on provided id. Not valid or non existing data set id returns empty content. Data set not in drat status will return a redirect 301")
@Timed
@ResponseBody
public DataSet preview(@RequestParam(defaultValue = "true") @ApiParam(name = "metadata", value = "Include metadata information in the response") boolean metadata, @RequestParam(defaultValue = "") @ApiParam(name = "sheetName", value = "Sheet name to preview") String sheetName, @PathVariable(value = "id") @ApiParam(name = "id", value = "Id of the requested data set") String dataSetId) {
    DataSetMetadata dataSetMetadata = dataSetMetadataRepository.get(dataSetId);
    if (dataSetMetadata == null) {
        HttpResponseContext.status(HttpStatus.NO_CONTENT);
        // No data set, returns empty content.
        return DataSet.empty();
    }
    if (!dataSetMetadata.isDraft()) {
        // Moved to get data set content operation
        HttpResponseContext.status(HttpStatus.MOVED_PERMANENTLY);
        HttpResponseContext.header("Location", "/datasets/" + dataSetId + "/content");
        // dataset not anymore a draft so preview doesn't make sense.
        return DataSet.empty();
    }
    if (StringUtils.isNotEmpty(sheetName)) {
        dataSetMetadata.setSheetName(sheetName);
    }
    // take care of previous data without schema parser result
    if (dataSetMetadata.getSchemaParserResult() != null) {
        // sheet not yet set correctly so use the first one
        if (StringUtils.isEmpty(dataSetMetadata.getSheetName())) {
            String theSheetName = dataSetMetadata.getSchemaParserResult().getSheetContents().get(0).getName();
            LOG.debug("preview for dataSetMetadata: {} with sheetName: {}", dataSetId, theSheetName);
            dataSetMetadata.setSheetName(theSheetName);
        }
        String theSheetName = dataSetMetadata.getSheetName();
        Optional<Schema.SheetContent> sheetContentFound = dataSetMetadata.getSchemaParserResult().getSheetContents().stream().filter(// 
        sheetContent -> theSheetName.equals(sheetContent.getName())).findFirst();
        if (!sheetContentFound.isPresent()) {
            HttpResponseContext.status(HttpStatus.NO_CONTENT);
            // No sheet found, returns empty content.
            return DataSet.empty();
        }
        List<ColumnMetadata> columnMetadatas = sheetContentFound.get().getColumnMetadatas();
        if (dataSetMetadata.getRowMetadata() == null) {
            dataSetMetadata.setRowMetadata(new RowMetadata(emptyList()));
        }
        dataSetMetadata.getRowMetadata().setColumns(columnMetadatas);
    } else {
        LOG.warn("dataset#{} has draft status but any SchemaParserResult", dataSetId);
    }
    // Build the result
    DataSet dataSet = new DataSet();
    if (metadata) {
        dataSet.setMetadata(conversionService.convert(dataSetMetadata, UserDataSetMetadata.class));
    }
    dataSet.setRecords(contentStore.stream(dataSetMetadata).limit(100));
    return dataSet;
}
Also used : VolumeMetered(org.talend.dataprep.metrics.VolumeMetered) RequestParam(org.springframework.web.bind.annotation.RequestParam) ImportBuilder(org.talend.dataprep.api.dataset.Import.ImportBuilder) FormatFamilyFactory(org.talend.dataprep.schema.FormatFamilyFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiParam(io.swagger.annotations.ApiParam) StringUtils(org.apache.commons.lang3.StringUtils) TEXT_PLAIN_VALUE(org.springframework.http.MediaType.TEXT_PLAIN_VALUE) SortAndOrderHelper.getDataSetMetadataComparator(org.talend.dataprep.util.SortAndOrderHelper.getDataSetMetadataComparator) Collections.singletonList(java.util.Collections.singletonList) SemanticDomain(org.talend.dataprep.api.dataset.statistics.SemanticDomain) BeanConversionService(org.talend.dataprep.conversions.BeanConversionService) PipedInputStream(java.io.PipedInputStream) DistributedLock(org.talend.dataprep.lock.DistributedLock) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) DataprepBundle.message(org.talend.dataprep.i18n.DataprepBundle.message) UserData(org.talend.dataprep.api.user.UserData) TaskExecutor(org.springframework.core.task.TaskExecutor) MAX_STORAGE_MAY_BE_EXCEEDED(org.talend.dataprep.exception.error.DataSetErrorCodes.MAX_STORAGE_MAY_BE_EXCEEDED) DataSet(org.talend.dataprep.api.dataset.DataSet) LocalStoreLocation(org.talend.dataprep.api.dataset.location.LocalStoreLocation) FormatFamily(org.talend.dataprep.schema.FormatFamily) Resource(javax.annotation.Resource) Set(java.util.Set) DatasetUpdatedEvent(org.talend.dataprep.dataset.event.DatasetUpdatedEvent) RestController(org.springframework.web.bind.annotation.RestController) IOUtils(org.apache.commons.io.IOUtils) QuotaService(org.talend.dataprep.dataset.store.QuotaService) SecurityProxy(org.talend.dataprep.security.SecurityProxy) Stream(java.util.stream.Stream) StreamSupport.stream(java.util.stream.StreamSupport.stream) FlagNames(org.talend.dataprep.api.dataset.row.FlagNames) UNEXPECTED_CONTENT(org.talend.dataprep.exception.error.CommonErrorCodes.UNEXPECTED_CONTENT) Analyzers(org.talend.dataquality.common.inference.Analyzers) DatasetImportedEvent(org.talend.dataprep.dataset.event.DatasetImportedEvent) DataSetLocatorService(org.talend.dataprep.api.dataset.location.locator.DataSetLocatorService) Callable(java.util.concurrent.Callable) Schema(org.talend.dataprep.schema.Schema) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) RequestBody(org.springframework.web.bind.annotation.RequestBody) DataSetLocationService(org.talend.dataprep.api.dataset.location.DataSetLocationService) AnalyzerService(org.talend.dataprep.quality.AnalyzerService) UserDataRepository(org.talend.dataprep.user.store.UserDataRepository) Markers(org.talend.dataprep.log.Markers) Api(io.swagger.annotations.Api) DraftValidator(org.talend.dataprep.schema.DraftValidator) HttpResponseContext(org.talend.dataprep.http.HttpResponseContext) Sort(org.talend.dataprep.util.SortAndOrderHelper.Sort) IOException(java.io.IOException) PipedOutputStream(java.io.PipedOutputStream) FormatAnalysis(org.talend.dataprep.dataset.service.analysis.synchronous.FormatAnalysis) ContentAnalysis(org.talend.dataprep.dataset.service.analysis.synchronous.ContentAnalysis) SchemaAnalysis(org.talend.dataprep.dataset.service.analysis.synchronous.SchemaAnalysis) HttpStatus(org.springframework.http.HttpStatus) FilterService(org.talend.dataprep.api.filter.FilterService) Marker(org.slf4j.Marker) NullOutputStream(org.apache.commons.io.output.NullOutputStream) StatisticsAdapter(org.talend.dataprep.dataset.StatisticsAdapter) Timed(org.talend.dataprep.metrics.Timed) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) PathVariable(org.springframework.web.bind.annotation.PathVariable) DataSetMetadataBuilder(org.talend.dataprep.dataset.DataSetMetadataBuilder) DataSetErrorCodes(org.talend.dataprep.exception.error.DataSetErrorCodes) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) DatasetDTO(org.talend.dataprep.api.dataset.DatasetDTO) SEMANTIC(org.talend.dataprep.quality.AnalyzerService.Analysis.SEMANTIC) ApiOperation(io.swagger.annotations.ApiOperation) UNABLE_TO_CREATE_OR_UPDATE_DATASET(org.talend.dataprep.exception.error.DataSetErrorCodes.UNABLE_TO_CREATE_OR_UPDATE_DATASET) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) StrictlyBoundedInputStream(org.talend.dataprep.dataset.store.content.StrictlyBoundedInputStream) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) UNSUPPORTED_CONTENT(org.talend.dataprep.exception.error.DataSetErrorCodes.UNSUPPORTED_CONTENT) TimeToLive(org.talend.dataprep.cache.ContentCache.TimeToLive) Order(org.talend.dataprep.util.SortAndOrderHelper.Order) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) PublicAPI(org.talend.dataprep.security.PublicAPI) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ContentCache(org.talend.dataprep.cache.ContentCache) INVALID_DATASET_NAME(org.talend.dataprep.exception.error.DataSetErrorCodes.INVALID_DATASET_NAME) List(java.util.List) Optional(java.util.Optional) Analyzer(org.talend.dataquality.common.inference.Analyzer) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) Pattern(java.util.regex.Pattern) Security(org.talend.dataprep.security.Security) Spliterator(java.util.Spliterator) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ComponentProperties(org.talend.dataprep.parameters.jsonschema.ComponentProperties) TDPException(org.talend.dataprep.exception.TDPException) JsonErrorCodeDescription(org.talend.dataprep.exception.json.JsonErrorCodeDescription) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) UNABLE_CREATE_DATASET(org.talend.dataprep.exception.error.DataSetErrorCodes.UNABLE_CREATE_DATASET) HashMap(java.util.HashMap) GET(org.springframework.web.bind.annotation.RequestMethod.GET) HashSet(java.util.HashSet) Import(org.talend.dataprep.api.dataset.Import) ExceptionContext.build(org.talend.daikon.exception.ExceptionContext.build) ExceptionContext(org.talend.daikon.exception.ExceptionContext) UpdateColumnParameters(org.talend.dataprep.dataset.service.api.UpdateColumnParameters) VersionService(org.talend.dataprep.api.service.info.VersionService) POST(org.springframework.web.bind.annotation.RequestMethod.POST) OutputStream(java.io.OutputStream) DataSetLocation(org.talend.dataprep.api.dataset.DataSetLocation) Logger(org.slf4j.Logger) LocaleContextHolder.getLocale(org.springframework.context.i18n.LocaleContextHolder.getLocale) UpdateDataSetCacheKey(org.talend.dataprep.dataset.service.cache.UpdateDataSetCacheKey) DataSetContentLimit(org.talend.dataprep.dataset.store.content.DataSetContentLimit) APPLICATION_JSON_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_VALUE) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Certification(org.talend.dataprep.api.dataset.DataSetGovernance.Certification) Comparator(java.util.Comparator) InputStream(java.io.InputStream) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) DataSet(org.talend.dataprep.api.dataset.DataSet) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Timed(org.talend.dataprep.metrics.Timed) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 35 with PathVariable

use of org.springframework.web.bind.annotation.PathVariable in project thingsboard by thingsboard.

the class DeviceApiController method claimDevice.

@ApiOperation(value = "Save claiming information (claimDevice)", notes = "Saves the information required for user to claim the device. " + "See more info about claiming in the corresponding 'Claiming devices' platform documentation." + "\n Example of the request payload: " + MARKDOWN_CODE_BLOCK_START + "{\"secretKey\":\"value\", \"durationMs\":60000}" + MARKDOWN_CODE_BLOCK_END + "Note: both 'secretKey' and 'durationMs' is optional parameters. " + "In case the secretKey is not specified, the empty string as a default value is used. In case the durationMs is not specified, the system parameter device.claim.duration is used.\n\n" + REQUIRE_ACCESS_TOKEN, produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/{deviceToken}/claim", method = RequestMethod.POST)
public DeferredResult<ResponseEntity> claimDevice(@ApiParam(value = ACCESS_TOKEN_PARAM_DESCRIPTION, required = true, defaultValue = "YOUR_DEVICE_ACCESS_TOKEN") @PathVariable("deviceToken") String deviceToken, @RequestBody(required = false) String json) {
    DeferredResult<ResponseEntity> responseWriter = new DeferredResult<>();
    transportContext.getTransportService().process(DeviceTransportType.DEFAULT, ValidateDeviceTokenRequestMsg.newBuilder().setToken(deviceToken).build(), new DeviceAuthCallback(transportContext, responseWriter, sessionInfo -> {
        TransportService transportService = transportContext.getTransportService();
        DeviceId deviceId = new DeviceId(new UUID(sessionInfo.getDeviceIdMSB(), sessionInfo.getDeviceIdLSB()));
        transportService.process(sessionInfo, JsonConverter.convertToClaimDeviceProto(deviceId, json), new HttpOkCallback(responseWriter));
    }));
    return responseWriter;
}
Also used : JsonObject(com.google.gson.JsonObject) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) Arrays(java.util.Arrays) RpcStatus(org.thingsboard.server.common.data.rpc.RpcStatus) RequiredArgsConstructor(lombok.RequiredArgsConstructor) ApiParam(io.swagger.annotations.ApiParam) Autowired(org.springframework.beans.factory.annotation.Autowired) ByteArrayResource(org.springframework.core.io.ByteArrayResource) ApiOperation(io.swagger.annotations.ApiOperation) SubscribeToAttributeUpdatesMsg(org.thingsboard.server.gen.transport.TransportProtos.SubscribeToAttributeUpdatesMsg) DeviceTransportType(org.thingsboard.server.common.data.DeviceTransportType) JsonConverter(org.thingsboard.server.common.transport.adaptor.JsonConverter) GetAttributeResponseMsg(org.thingsboard.server.gen.transport.TransportProtos.GetAttributeResponseMsg) DeviceId(org.thingsboard.server.common.data.id.DeviceId) HttpHeaders(org.springframework.http.HttpHeaders) MediaType(org.springframework.http.MediaType) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) UUID(java.util.UUID) TransportService(org.thingsboard.server.common.transport.TransportService) RestController(org.springframework.web.bind.annotation.RestController) ToServerRpcResponseMsg(org.thingsboard.server.gen.transport.TransportProtos.ToServerRpcResponseMsg) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SubscribeToRPCMsg(org.thingsboard.server.gen.transport.TransportProtos.SubscribeToRPCMsg) TbTransportService(org.thingsboard.server.common.data.TbTransportService) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) GetAttributeRequestMsg(org.thingsboard.server.gen.transport.TransportProtos.GetAttributeRequestMsg) ProvisionDeviceResponseMsg(org.thingsboard.server.gen.transport.TransportProtos.ProvisionDeviceResponseMsg) ValidateDeviceCredentialsResponse(org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse) SessionInfoCreator(org.thingsboard.server.common.transport.auth.SessionInfoCreator) AttributeUpdateNotificationMsg(org.thingsboard.server.gen.transport.TransportProtos.AttributeUpdateNotificationMsg) ToDeviceRpcRequestMsg(org.thingsboard.server.gen.transport.TransportProtos.ToDeviceRpcRequestMsg) ToDeviceRpcResponseMsg(org.thingsboard.server.gen.transport.TransportProtos.ToDeviceRpcResponseMsg) ToServerRpcRequestMsg(org.thingsboard.server.gen.transport.TransportProtos.ToServerRpcRequestMsg) TransportServiceCallback(org.thingsboard.server.common.transport.TransportServiceCallback) DeferredResult(org.springframework.web.context.request.async.DeferredResult) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) JsonParser(com.google.gson.JsonParser) RequestBody(org.springframework.web.bind.annotation.RequestBody) SessionMsgListener(org.thingsboard.server.common.transport.SessionMsgListener) ConditionalOnExpression(org.springframework.boot.autoconfigure.condition.ConditionalOnExpression) HttpServletRequest(javax.servlet.http.HttpServletRequest) SessionCloseNotificationProto(org.thingsboard.server.gen.transport.TransportProtos.SessionCloseNotificationProto) ValidateDeviceTokenRequestMsg(org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceTokenRequestMsg) DataConstants(org.thingsboard.server.common.data.DataConstants) TransportContext(org.thingsboard.server.common.transport.TransportContext) SessionInfoProto(org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto) OtaPackageType(org.thingsboard.server.common.data.ota.OtaPackageType) Consumer(java.util.function.Consumer) HttpStatus(org.springframework.http.HttpStatus) ResponseEntity(org.springframework.http.ResponseEntity) StringUtils(org.springframework.util.StringUtils) ResponseEntity(org.springframework.http.ResponseEntity) TransportService(org.thingsboard.server.common.transport.TransportService) TbTransportService(org.thingsboard.server.common.data.TbTransportService) DeviceId(org.thingsboard.server.common.data.id.DeviceId) UUID(java.util.UUID) DeferredResult(org.springframework.web.context.request.async.DeferredResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

PathVariable (org.springframework.web.bind.annotation.PathVariable)83 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)65 List (java.util.List)61 RequestParam (org.springframework.web.bind.annotation.RequestParam)54 Collectors (java.util.stream.Collectors)50 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)48 RestController (org.springframework.web.bind.annotation.RestController)44 Autowired (org.springframework.beans.factory.annotation.Autowired)43 RequestBody (org.springframework.web.bind.annotation.RequestBody)42 MediaType (org.springframework.http.MediaType)40 ApiOperation (io.swagger.annotations.ApiOperation)37 HttpStatus (org.springframework.http.HttpStatus)33 IOException (java.io.IOException)32 Set (java.util.Set)29 ApiParam (io.swagger.annotations.ApiParam)27 HttpServletResponse (javax.servlet.http.HttpServletResponse)27 Map (java.util.Map)26 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)26 ResponseEntity (org.springframework.http.ResponseEntity)25 GetMapping (org.springframework.web.bind.annotation.GetMapping)24