use of org.springframework.web.bind.annotation.PathVariable in project nakadi by zalando.
the class PartitionsController method listPartitions.
@RequestMapping(value = "/event-types/{name}/partitions", method = RequestMethod.GET)
public ResponseEntity<?> listPartitions(@PathVariable("name") final String eventTypeName, final NativeWebRequest request) {
LOG.trace("Get partitions endpoint for event-type '{}' is called", eventTypeName);
try {
final EventType eventType = eventTypeRepository.findByName(eventTypeName);
authorizationValidator.authorizeStreamRead(eventType);
final List<Timeline> timelines = timelineService.getActiveTimelinesOrdered(eventTypeName);
final List<PartitionStatistics> firstStats = timelineService.getTopicRepository(timelines.get(0)).loadTopicStatistics(Collections.singletonList(timelines.get(0)));
final List<PartitionStatistics> lastStats;
if (timelines.size() == 1) {
lastStats = firstStats;
} else {
lastStats = timelineService.getTopicRepository(timelines.get(timelines.size() - 1)).loadTopicStatistics(Collections.singletonList(timelines.get(timelines.size() - 1)));
}
final List<EventTypePartitionView> result = firstStats.stream().map(first -> {
final PartitionStatistics last = lastStats.stream().filter(l -> l.getPartition().equals(first.getPartition())).findAny().get();
return new EventTypePartitionView(eventTypeName, first.getPartition(), cursorConverter.convert(first.getFirst()).getOffset(), cursorConverter.convert(last.getLast()).getOffset());
}).collect(Collectors.toList());
return ok().body(result);
} catch (final NoSuchEventTypeException e) {
return create(Problem.valueOf(NOT_FOUND, "topic not found"), request);
} catch (final NakadiException e) {
LOG.error("Could not list partitions. Respond with SERVICE_UNAVAILABLE.", e);
return create(e.asProblem(), request);
}
}
use of org.springframework.web.bind.annotation.PathVariable in project irida by phac-nml.
the class CartController method addProject.
/**
* Add an entire {@link Project} to the cart
*
* @param projectId
* The ID of the {@link Project}
* @return a map stating success
*/
@RequestMapping(value = "/project/{projectId}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, Object> addProject(@PathVariable Long projectId) {
Project project = projectService.read(projectId);
List<Join<Project, Sample>> samplesForProject = sampleService.getSamplesForProject(project);
Set<Sample> samples = samplesForProject.stream().map((j) -> {
return j.getObject();
}).collect(Collectors.toSet());
getSelectedSamplesForProject(project).addAll(samples);
return ImmutableMap.of("success", true);
}
use of org.springframework.web.bind.annotation.PathVariable in project irida by phac-nml.
the class RESTSampleSequenceFilesController method readSequenceFileForSequencingObject.
/**
* Read a single {@link SequenceFile} for a given {@link Sample} and
* {@link SequencingObject}
*
* @param sampleId
* ID of the {@link Sample}
* @param objectType
* type of {@link SequencingObject}
* @param objectId
* id of the {@link SequencingObject}
* @param fileId
* ID of the {@link SequenceFile} to read
* @return a {@link SequenceFile}
*/
@RequestMapping(value = "/api/samples/{sampleId}/{objectType}/{objectId}/files/{fileId}", method = RequestMethod.GET)
public ModelMap readSequenceFileForSequencingObject(@PathVariable Long sampleId, @PathVariable String objectType, @PathVariable Long objectId, @PathVariable Long fileId) {
ModelMap modelMap = new ModelMap();
Sample sample = sampleService.read(sampleId);
SequencingObject readSequenceFilePairForSample = sequencingObjectService.readSequencingObjectForSample(sample, objectId);
Optional<SequenceFile> findFirst = readSequenceFilePairForSample.getFiles().stream().filter(f -> f.getId().equals(fileId)).findFirst();
if (!findFirst.isPresent()) {
throw new EntityNotFoundException("File with id " + fileId + " is not associated with this sequencing object");
}
SequenceFile file = findFirst.get();
file.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).getSampleSequenceFiles(sampleId)).withRel(REL_SAMPLE_SEQUENCE_FILES));
file.add(linkTo(methodOn(RESTProjectSamplesController.class).getSample(sampleId)).withRel(REL_SAMPLE));
file.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).readSequencingObject(sampleId, objectType, objectId)).withRel(REL_SEQ_OBJECT));
file.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).readQCForSequenceFile(sampleId, objectType, objectId, fileId)).withRel(REL_SEQ_QC));
file.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).readSequenceFileForSequencingObject(sampleId, objectType, objectId, fileId)).withSelfRel());
modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, file);
return modelMap;
}
use of org.springframework.web.bind.annotation.PathVariable in project com.revolsys.open by revolsys.
the class WebMethodHandler method pathVariable.
@SuppressWarnings("unchecked")
public static WebParameterHandler pathVariable(final WebAnnotationMethodHandlerAdapter adapter, final Parameter parameter, final Annotation annotation) {
final Class<?> parameterClass = parameter.getType();
final DataType dataType = DataTypes.getDataType(parameterClass);
final PathVariable pathVariable = (PathVariable) annotation;
final String name = getName(parameter, pathVariable.value());
return //
WebParameterHandler.function(//
name, (request, response) -> {
final Map<String, String> uriTemplateVariables = (Map<String, String>) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
if (uriTemplateVariables == null) {
return null;
} else {
return uriTemplateVariables.get(name);
}
}, //
dataType, //
true, //
null);
}
use of org.springframework.web.bind.annotation.PathVariable in project runelite by runelite.
the class CacheController method listArchives.
@RequestMapping("{cacheId}/{indexId}")
public List<CacheArchive> listArchives(@PathVariable int cacheId, @PathVariable int indexId) {
CacheEntry cache = cacheService.findCache(cacheId);
if (cache == null) {
throw new NotFoundException();
}
IndexEntry indexEntry = cacheService.findIndexForCache(cache, indexId);
if (indexEntry == null) {
throw new NotFoundException();
}
List<ArchiveEntry> archives = cacheService.findArchivesForIndex(indexEntry);
return archives.stream().map(archive -> new CacheArchive(archive.getArchiveId(), archive.getNameHash(), archive.getRevision())).collect(Collectors.toList());
}
Aggregations