Search in sources :

Example 6 with PathVariable

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);
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) MoreStatus(org.zalando.problem.MoreStatus) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) LoggerFactory(org.slf4j.LoggerFactory) NotFoundException(org.zalando.nakadi.exceptions.NotFoundException) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) NakadiException(org.zalando.nakadi.exceptions.NakadiException) Cursor(org.zalando.nakadi.view.Cursor) MyNakadiRuntimeException1(org.zalando.nakadi.exceptions.runtime.MyNakadiRuntimeException1) Responses.create(org.zalando.problem.spring.web.advice.Responses.create) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException) InvalidCursorOperation(org.zalando.nakadi.exceptions.runtime.InvalidCursorOperation) NativeWebRequest(org.springframework.web.context.request.NativeWebRequest) Lists(com.google.common.collect.Lists) NakadiCursorLag(org.zalando.nakadi.domain.NakadiCursorLag) ServiceUnavailableException(org.zalando.nakadi.exceptions.ServiceUnavailableException) Problem(org.zalando.problem.Problem) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) TimelineService(org.zalando.nakadi.service.timeline.TimelineService) Nullable(javax.annotation.Nullable) EventType(org.zalando.nakadi.domain.EventType) Logger(org.slf4j.Logger) NOT_FOUND(javax.ws.rs.core.Response.Status.NOT_FOUND) PartitionStatistics(org.zalando.nakadi.domain.PartitionStatistics) ResponseEntity.ok(org.springframework.http.ResponseEntity.ok) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Responses(org.zalando.problem.spring.web.advice.Responses) InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) AuthorizationValidator(org.zalando.nakadi.service.AuthorizationValidator) List(java.util.List) CursorLag(org.zalando.nakadi.view.CursorLag) EventTypePartitionView(org.zalando.nakadi.view.EventTypePartitionView) Response(javax.ws.rs.core.Response) Timeline(org.zalando.nakadi.domain.Timeline) EventTypeRepository(org.zalando.nakadi.repository.EventTypeRepository) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) Collections(java.util.Collections) CursorConverter(org.zalando.nakadi.service.CursorConverter) CursorOperationsService(org.zalando.nakadi.service.CursorOperationsService) Timeline(org.zalando.nakadi.domain.Timeline) EventType(org.zalando.nakadi.domain.EventType) PartitionStatistics(org.zalando.nakadi.domain.PartitionStatistics) EventTypePartitionView(org.zalando.nakadi.view.EventTypePartitionView) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException) NakadiException(org.zalando.nakadi.exceptions.NakadiException) InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with PathVariable

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);
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) ControllerLinkBuilder.methodOn(org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn) Controller(org.springframework.stereotype.Controller) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) Scope(org.springframework.context.annotation.Scope) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) ArrayList(java.util.ArrayList) ProjectService(ca.corefacility.bioinformatics.irida.service.ProjectService) HashSet(java.util.HashSet) RequestBody(org.springframework.web.bind.annotation.RequestBody) ControllerLinkBuilder.linkTo(org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo) Model(org.springframework.ui.Model) Locale(java.util.Locale) Map(java.util.Map) RESTSampleSequenceFilesController(ca.corefacility.bioinformatics.irida.web.controller.api.samples.RESTSampleSequenceFilesController) MessageSource(org.springframework.context.MessageSource) SequencingObjectService(ca.corefacility.bioinformatics.irida.service.SequencingObjectService) ImmutableMap(com.google.common.collect.ImmutableMap) RESTProjectSamplesController(ca.corefacility.bioinformatics.irida.web.controller.api.projects.RESTProjectSamplesController) Collection(java.util.Collection) MediaType(org.springframework.http.MediaType) Set(java.util.Set) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Collectors(java.util.stream.Collectors) Project(ca.corefacility.bioinformatics.irida.model.project.Project) List(java.util.List) Principal(java.security.Principal) UserService(ca.corefacility.bioinformatics.irida.service.user.UserService) SampleService(ca.corefacility.bioinformatics.irida.service.sample.SampleService) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with PathVariable

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;
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RootResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource) LoggerFactory(org.slf4j.LoggerFactory) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) ControllerLinkBuilder.methodOn(org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn) Controller(org.springframework.stereotype.Controller) RequestPart(org.springframework.web.bind.annotation.RequestPart) RESTAnalysisSubmissionController(ca.corefacility.bioinformatics.irida.web.controller.api.RESTAnalysisSubmissionController) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) ModelMap(org.springframework.ui.ModelMap) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) ControllerLinkBuilder.linkTo(org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo) HttpHeaders(com.google.common.net.HttpHeaders) Objects(com.google.common.base.Objects) Path(java.nio.file.Path) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) BiMap(com.google.common.collect.BiMap) Link(org.springframework.hateoas.Link) Logger(org.slf4j.Logger) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) SequencingObjectService(ca.corefacility.bioinformatics.irida.service.SequencingObjectService) Files(java.nio.file.Files) RESTProjectSamplesController(ca.corefacility.bioinformatics.irida.web.controller.api.projects.RESTProjectSamplesController) Collection(java.util.Collection) MediaType(org.springframework.http.MediaType) HttpServletResponse(javax.servlet.http.HttpServletResponse) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) IOException(java.io.IOException) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SequencingRunService(ca.corefacility.bioinformatics.irida.service.SequencingRunService) RESTGenericController(ca.corefacility.bioinformatics.irida.web.controller.api.RESTGenericController) HttpStatus(org.springframework.http.HttpStatus) SequenceFileResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.sequencefile.SequenceFileResource) Optional(java.util.Optional) MultipartFile(org.springframework.web.multipart.MultipartFile) SampleService(ca.corefacility.bioinformatics.irida.service.sample.SampleService) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisService(ca.corefacility.bioinformatics.irida.service.AnalysisService) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with PathVariable

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);
}
Also used : DataType(com.revolsys.datatype.DataType) Map(java.util.Map) HashMap(java.util.HashMap) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) PathVariable(org.springframework.web.bind.annotation.PathVariable)

Example 10 with PathVariable

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());
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) TextureProvider(net.runelite.cache.definitions.providers.TextureProvider) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Cache(net.runelite.http.api.cache.Cache) SpriteDefinition(net.runelite.cache.definitions.SpriteDefinition) SpriteLoader(net.runelite.cache.definitions.loaders.SpriteLoader) IndexEntry(net.runelite.http.service.cache.beans.IndexEntry) ImageIO(javax.imageio.ImageIO) CacheEntry(net.runelite.http.service.cache.beans.CacheEntry) ItemLoader(net.runelite.cache.definitions.loaders.ItemLoader) FSFile(net.runelite.cache.fs.FSFile) IndexType(net.runelite.cache.IndexType) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) TextureDefinition(net.runelite.cache.definitions.TextureDefinition) TextureLoader(net.runelite.cache.definitions.loaders.TextureLoader) NpcLoader(net.runelite.cache.definitions.loaders.NpcLoader) BufferedImage(java.awt.image.BufferedImage) ArchiveEntry(net.runelite.http.service.cache.beans.ArchiveEntry) Container(net.runelite.cache.fs.Container) IOException(java.io.IOException) ObjectLoader(net.runelite.cache.definitions.loaders.ObjectLoader) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) SpriteProvider(net.runelite.cache.definitions.providers.SpriteProvider) CacheIndex(net.runelite.http.api.cache.CacheIndex) CacheArchive(net.runelite.http.api.cache.CacheArchive) ConfigType(net.runelite.cache.ConfigType) ItemProvider(net.runelite.cache.definitions.providers.ItemProvider) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) ItemDefinition(net.runelite.cache.definitions.ItemDefinition) ItemSpriteFactory(net.runelite.cache.item.ItemSpriteFactory) NotFoundException(net.runelite.http.service.util.exception.NotFoundException) NpcDefinition(net.runelite.cache.definitions.NpcDefinition) ResponseEntity(org.springframework.http.ResponseEntity) ModelLoader(net.runelite.cache.definitions.loaders.ModelLoader) ModelProvider(net.runelite.cache.definitions.providers.ModelProvider) ModelDefinition(net.runelite.cache.definitions.ModelDefinition) CacheArchive(net.runelite.http.api.cache.CacheArchive) NotFoundException(net.runelite.http.service.util.exception.NotFoundException) IndexEntry(net.runelite.http.service.cache.beans.IndexEntry) ArchiveEntry(net.runelite.http.service.cache.beans.ArchiveEntry) CacheEntry(net.runelite.http.service.cache.beans.CacheEntry) 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