Search in sources :

Example 56 with PathVariable

use of org.springframework.web.bind.annotation.PathVariable in project powerauth-restful-integration by lime-company.

the class PowerAuthAnnotationInterceptor method expandResourceId.

/**
 * The method substitutes placeholders (marked via "${placeholder}") in resourceID attribute value by
 * the actual parameters of the handler method. The implementation takes into account all method parameters
 * that are annotated via @RequestParam or @PathVariable annotations and extracts values from the request
 * parameter map.<br>
 * <br>
 * <b>
 *     Note: In case both @RequestParam and @PathVariable with the same name exist, the value of @RequestParam
 *     takes precedence. This is because @RequestParam usually maps to the HTTP GET query parameter that cannot
 *     be easily changed in existing API, while @PathVariable is just a URL placeholder that can be renamed in
 *     the code with no impact on functionality.
 * </b>
 *
 * @param resourceId Resource ID with possible placeholders.
 * @param request HttpServletRequest for the current execution.
 * @param handlerMethod Handler method that is responsible for the request processing.
 * @return Resource ID with substituted placeholders.
 */
@SuppressWarnings("unchecked")
private String expandResourceId(String resourceId, HttpServletRequest request, HandlerMethod handlerMethod) {
    // Get method parameters that could be replaced in the context of resource ID
    final Map<String, String> parameters = new TreeMap<>();
    final MethodParameter[] methodParameters = handlerMethod.getMethodParameters();
    for (MethodParameter mp : methodParameters) {
        // Handle parameters annotated by @RequestParam annotation.
        // These are stored in the servlet request parameter map.
        // Note: @RequestParam must be processed before @PathVariable since
        // in API, it cannot be renamed (the path variable is just
        // a placeholder and can have arbitrary name).
        final RequestParam requestParam = mp.getParameterAnnotation(RequestParam.class);
        if (requestParam != null) {
            final String name = requestParam.name();
            final String value = request.getParameter(name);
            if (value != null) {
                // do not check "&& !parameters.containsKey(name)" because in the case of
                // a name conflict, we want @RequestParam to overwrite @PathVariable value
                parameters.put(name, value);
            }
        } else {
            // Handle parameters annotated by @PathVariable annotation.
            // These are stored by Spring in the servlet request attributes map, under a special
            // URI_TEMPLATE_VARIABLES_ATTRIBUTE key that contains Map<String, String> with path
            // variable mapping.
            final PathVariable pathVariable = mp.getParameterAnnotation(PathVariable.class);
            if (pathVariable != null) {
                final String name = pathVariable.name();
                final Map<String, String> pathVariableMap = (Map<String, String>) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
                if (pathVariableMap != null && !parameters.containsKey(name)) {
                    // prevent overwriting value that is already assigned
                    final String value = pathVariableMap.get(name);
                    if (value != null) {
                        parameters.put(name, value);
                    }
                }
            }
        }
    }
    // Substitute the placeholders
    final StringSubstitutor sub = new StringSubstitutor(parameters);
    return sub.replace(resourceId);
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) StringSubstitutor(org.apache.commons.text.StringSubstitutor) TreeMap(java.util.TreeMap) MethodParameter(org.springframework.core.MethodParameter) Map(java.util.Map) TreeMap(java.util.TreeMap) PathVariable(org.springframework.web.bind.annotation.PathVariable)

Example 57 with PathVariable

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

the class CacheController method listIndexes.

@RequestMapping("{cacheId}")
public List<CacheIndex> listIndexes(@PathVariable int cacheId) {
    CacheEntry cache = cacheService.findCache(cacheId);
    if (cache == null) {
        throw new NotFoundException();
    }
    List<IndexEntry> indexes = cacheService.findIndexesForCache(cache);
    return indexes.stream().map(entry -> new CacheIndex(entry.getIndexId(), entry.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) CacheIndex(net.runelite.http.api.cache.CacheIndex) NotFoundException(net.runelite.http.service.util.exception.NotFoundException) IndexEntry(net.runelite.http.service.cache.beans.IndexEntry) CacheEntry(net.runelite.http.service.cache.beans.CacheEntry) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 58 with PathVariable

use of org.springframework.web.bind.annotation.PathVariable in project metasfresh-webui-api by metasfresh.

the class ProcessRestController method getParameterDropdown.

@RequestMapping(value = "/{processId}/{pinstanceId}/field/{parameterName}/dropdown", method = RequestMethod.GET)
public JSONLookupValuesList getParameterDropdown(// 
@PathVariable("processId") final String processIdStr, // 
@PathVariable("pinstanceId") final String pinstanceIdStr, // 
@PathVariable("parameterName") final String parameterName) {
    userSession.assertLoggedIn();
    final ProcessId processId = ProcessId.fromJson(processIdStr);
    final DocumentId pinstanceId = DocumentId.of(pinstanceIdStr);
    final IProcessInstancesRepository instancesRepository = getRepository(processId);
    return instancesRepository.forProcessInstanceReadonly(pinstanceId, processInstance -> processInstance.getParameterLookupValues(parameterName)).transform(JSONLookupValuesList::ofLookupValuesList);
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) WebRequest(org.springframework.web.context.request.WebRequest) Env(org.compiere.util.Env) Autowired(org.springframework.beans.factory.annotation.Autowired) DocumentCollection(de.metas.ui.web.window.model.DocumentCollection) OpenReportAction(de.metas.ui.web.process.ProcessInstanceResult.OpenReportAction) ReasonSupplier(de.metas.ui.web.window.model.IDocumentChangesCollector.ReasonSupplier) IView(de.metas.ui.web.view.IView) ProcessDescriptor(de.metas.ui.web.process.descriptor.ProcessDescriptor) Util(org.compiere.util.Util) HttpHeaders(org.springframework.http.HttpHeaders) NonNull(lombok.NonNull) Collection(java.util.Collection) MediaType(org.springframework.http.MediaType) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) RestController(org.springframework.web.bind.annotation.RestController) JSONLookupValuesList(de.metas.ui.web.window.datatypes.json.JSONLookupValuesList) UserSession(de.metas.ui.web.session.UserSession) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) List(java.util.List) Stream(java.util.stream.Stream) IDocumentChangesCollector(de.metas.ui.web.window.model.IDocumentChangesCollector) JSONDocument(de.metas.ui.web.window.datatypes.json.JSONDocument) JSONProcessLayout(de.metas.ui.web.process.json.JSONProcessLayout) IViewsRepository(de.metas.ui.web.view.IViewsRepository) LogManager(de.metas.logging.LogManager) JSONProcessInstanceResult(de.metas.ui.web.process.json.JSONProcessInstanceResult) JSONOptions(de.metas.ui.web.window.datatypes.json.JSONOptions) WebConfig(de.metas.ui.web.config.WebConfig) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) Execution(de.metas.ui.web.window.controller.Execution) JSONDocumentChangedEvent(de.metas.ui.web.window.datatypes.json.JSONDocumentChangedEvent) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) NullDocumentChangesCollector(de.metas.ui.web.window.model.NullDocumentChangesCollector) RequestBody(org.springframework.web.bind.annotation.RequestBody) JSONCreateProcessInstanceRequest(de.metas.ui.web.process.json.JSONCreateProcessInstanceRequest) JSONProcessInstance(de.metas.ui.web.process.json.JSONProcessInstance) Api(io.swagger.annotations.Api) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) ViewRowIdsSelection(de.metas.ui.web.view.ViewRowIdsSelection) Logger(org.slf4j.Logger) ETagResponseEntityBuilder(de.metas.ui.web.cache.ETagResponseEntityBuilder) ApplicationContext(org.springframework.context.ApplicationContext) WebuiRelatedProcessDescriptor(de.metas.ui.web.process.descriptor.WebuiRelatedProcessDescriptor) HttpStatus(org.springframework.http.HttpStatus) Check(org.adempiere.util.Check) ResponseEntity(org.springframework.http.ResponseEntity) ViewId(de.metas.ui.web.view.ViewId) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) JSONLookupValuesList(de.metas.ui.web.window.datatypes.json.JSONLookupValuesList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 59 with PathVariable

use of org.springframework.web.bind.annotation.PathVariable in project metasfresh-webui-api by metasfresh.

the class ASIRestController method getAttributeTypeahead.

@GetMapping("/{asiDocId}/field/{attributeName}/typeahead")
public JSONLookupValuesList getAttributeTypeahead(// 
@PathVariable("asiDocId") final String asiDocIdStr, // 
@PathVariable("attributeName") final String attributeName, // 
@RequestParam(name = "query", required = true) final String query) {
    userSession.assertLoggedIn();
    final DocumentId asiDocId = DocumentId.of(asiDocIdStr);
    return asiRepo.forASIDocumentReadonly(asiDocId, asiDoc -> asiDoc.getFieldLookupValuesForQuery(attributeName, query)).transform(JSONLookupValuesList::ofLookupValuesList);
}
Also used : JSONOptions(de.metas.ui.web.window.datatypes.json.JSONOptions) PathVariable(org.springframework.web.bind.annotation.PathVariable) PostMapping(org.springframework.web.bind.annotation.PostMapping) RequestParam(org.springframework.web.bind.annotation.RequestParam) WebConfig(de.metas.ui.web.config.WebConfig) Execution(de.metas.ui.web.window.controller.Execution) JSONDocumentChangedEvent(de.metas.ui.web.window.datatypes.json.JSONDocumentChangedEvent) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) JSONCreateASIRequest(de.metas.ui.web.pattribute.json.JSONCreateASIRequest) RestController(org.springframework.web.bind.annotation.RestController) JSONLookupValuesList(de.metas.ui.web.window.datatypes.json.JSONLookupValuesList) PatchMapping(org.springframework.web.bind.annotation.PatchMapping) RequestBody(org.springframework.web.bind.annotation.RequestBody) UserSession(de.metas.ui.web.session.UserSession) List(java.util.List) IDocumentChangesCollector(de.metas.ui.web.window.model.IDocumentChangesCollector) GetMapping(org.springframework.web.bind.annotation.GetMapping) JSONASILayout(de.metas.ui.web.pattribute.json.JSONASILayout) Api(io.swagger.annotations.Api) JSONDocument(de.metas.ui.web.window.datatypes.json.JSONDocument) JSONLookupValue(de.metas.ui.web.window.datatypes.json.JSONLookupValue) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) JSONLookupValuesList(de.metas.ui.web.window.datatypes.json.JSONLookupValuesList) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 60 with PathVariable

use of org.springframework.web.bind.annotation.PathVariable in project metasfresh-webui-api by metasfresh.

the class ASIRestController method getAttributeDropdown.

@GetMapping("/{asiDocId}/field/{attributeName}/dropdown")
public JSONLookupValuesList getAttributeDropdown(// 
@PathVariable("asiDocId") final String asiDocIdStr, // 
@PathVariable("attributeName") final String attributeName) {
    userSession.assertLoggedIn();
    final DocumentId asiDocId = DocumentId.of(asiDocIdStr);
    return asiRepo.forASIDocumentReadonly(asiDocId, asiDoc -> asiDoc.getFieldLookupValues(attributeName)).transform(JSONLookupValuesList::ofLookupValuesList);
}
Also used : JSONOptions(de.metas.ui.web.window.datatypes.json.JSONOptions) PathVariable(org.springframework.web.bind.annotation.PathVariable) PostMapping(org.springframework.web.bind.annotation.PostMapping) RequestParam(org.springframework.web.bind.annotation.RequestParam) WebConfig(de.metas.ui.web.config.WebConfig) Execution(de.metas.ui.web.window.controller.Execution) JSONDocumentChangedEvent(de.metas.ui.web.window.datatypes.json.JSONDocumentChangedEvent) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) JSONCreateASIRequest(de.metas.ui.web.pattribute.json.JSONCreateASIRequest) RestController(org.springframework.web.bind.annotation.RestController) JSONLookupValuesList(de.metas.ui.web.window.datatypes.json.JSONLookupValuesList) PatchMapping(org.springframework.web.bind.annotation.PatchMapping) RequestBody(org.springframework.web.bind.annotation.RequestBody) UserSession(de.metas.ui.web.session.UserSession) List(java.util.List) IDocumentChangesCollector(de.metas.ui.web.window.model.IDocumentChangesCollector) GetMapping(org.springframework.web.bind.annotation.GetMapping) JSONASILayout(de.metas.ui.web.pattribute.json.JSONASILayout) Api(io.swagger.annotations.Api) JSONDocument(de.metas.ui.web.window.datatypes.json.JSONDocument) JSONLookupValue(de.metas.ui.web.window.datatypes.json.JSONLookupValue) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) JSONLookupValuesList(de.metas.ui.web.window.datatypes.json.JSONLookupValuesList) GetMapping(org.springframework.web.bind.annotation.GetMapping)

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