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