Search in sources :

Example 61 with RequestParam

use of org.springframework.web.bind.annotation.RequestParam in project ArachneCentralAPI by OHDSI.

the class BaseAnalysisController method list.

@ApiOperation("List analyses.")
@RequestMapping(value = "/api/v1/analysis-management/analyses", method = GET)
public JsonResult<List<D>> list(Principal principal, @RequestParam("study-id") Long studyId) throws PermissionDeniedException, NotExistException {
    JsonResult<List<D>> result;
    IUser user = userService.getByUsername(principal.getName());
    if (user == null) {
        result = new JsonResult<>(PERMISSION_DENIED);
        return result;
    }
    Iterable<T> analyses = analysisService.list(user, studyId);
    result = new JsonResult<>(NO_ERROR);
    List<D> analysisDTOs = StreamSupport.stream(analyses.spliterator(), false).map(analysis -> conversionService.convert(analysis, getAnalysisDTOClass())).collect(Collectors.toList());
    result.setResult(analysisDTOs);
    return result;
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) Arrays(java.util.Arrays) UploadFilesDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFilesDTO) Valid(javax.validation.Valid) CommentUtils.getRecentCommentables(com.odysseusinc.arachne.portal.util.CommentUtils.getRecentCommentables) AnalysisLockDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisLockDTO) Analysis(com.odysseusinc.arachne.portal.model.Analysis) Commentable(com.odysseusinc.arachne.portal.api.v1.dto.Commentable) Sort(org.springframework.data.domain.Sort) ImportedFile(com.odysseusinc.arachne.portal.util.ImportedFile) Resource(org.springframework.core.io.Resource) MessagingUtils(com.odysseusinc.arachne.portal.service.messaging.MessagingUtils) FieldError(org.springframework.validation.FieldError) Set(java.util.Set) AnalysisFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisFileDTO) Page(org.springframework.data.domain.Page) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) IUser(com.odysseusinc.arachne.portal.model.IUser) IOUtils(org.apache.commons.io.IOUtils) SimpMessagingTemplate(org.springframework.messaging.simp.SimpMessagingTemplate) Stream(java.util.stream.Stream) AnalysisFilesSavingService(com.odysseusinc.arachne.portal.service.analysis.AnalysisFilesSavingService) VALIDATION_ERROR(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.VALIDATION_ERROR) DataReference(com.odysseusinc.arachne.portal.model.DataReference) BindingResult(org.springframework.validation.BindingResult) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) RequestBody(org.springframework.web.bind.annotation.RequestBody) SubmissionInsightDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionInsightDTO) NO_ERROR(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.NO_ERROR) StreamSupport(java.util.stream.StreamSupport) CommonEntityRequestDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestDTO) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) IOException(java.io.IOException) HttpUtils.putFileContentToResponse(com.odysseusinc.arachne.portal.util.HttpUtils.putFileContentToResponse) SubmissionInsightUpdateDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionInsightUpdateDTO) DataReferenceDTO(com.odysseusinc.arachne.portal.api.v1.dto.DataReferenceDTO) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) UpdateNotificationDTO(com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO) AnalysisUpdateDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisUpdateDTO) PathVariable(org.springframework.web.bind.annotation.PathVariable) AnalysisUnlockRequestDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisUnlockRequestDTO) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) LoggerFactory(org.slf4j.LoggerFactory) ValidationRuntimeException(com.odysseusinc.arachne.portal.exception.ValidationRuntimeException) ApiOperation(io.swagger.annotations.ApiOperation) PutMapping(org.springframework.web.bind.annotation.PutMapping) AnalysisUnlockRequest(com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest) PERMISSION_DENIED(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.PERMISSION_DENIED) ToPdfConverter(com.odysseusinc.arachne.portal.service.ToPdfConverter) BaseSubmissionService(com.odysseusinc.arachne.portal.service.submission.BaseSubmissionService) BaseAnalysisService(com.odysseusinc.arachne.portal.service.analysis.BaseAnalysisService) AnalysisDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisDTO) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) CommonAnalysisType(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType) UUID(java.util.UUID) ShortBaseAnalysisDTO(com.odysseusinc.arachne.portal.api.v1.dto.ShortBaseAnalysisDTO) JMSException(javax.jms.JMSException) Collectors(java.util.stream.Collectors) FileDTO(com.odysseusinc.arachne.portal.api.v1.dto.FileDTO) List(java.util.List) Principal(java.security.Principal) DataReferenceService(com.odysseusinc.arachne.portal.service.DataReferenceService) AnalysisCreateDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisCreateDTO) AnalysisUnlockRequestStatus(com.odysseusinc.arachne.portal.model.AnalysisUnlockRequestStatus) SubmissionGroupDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionGroupDTO) NotUniqueException(com.odysseusinc.arachne.portal.exception.NotUniqueException) FileDtoContentHandler(com.odysseusinc.arachne.portal.api.v1.dto.converters.FileDtoContentHandler) ClassPathResource(org.springframework.core.io.ClassPathResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ObjectMessage(javax.jms.ObjectMessage) GET(org.springframework.web.bind.annotation.RequestMethod.GET) Submission(com.odysseusinc.arachne.portal.model.Submission) SubmissionGroupSearch(com.odysseusinc.arachne.portal.model.search.SubmissionGroupSearch) ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) HeraclesAnalysisService(com.odysseusinc.arachne.portal.service.analysis.heracles.HeraclesAnalysisService) JmsTemplate(org.springframework.jms.core.JmsTemplate) ProducerConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate) SubmissionInsight(com.odysseusinc.arachne.portal.model.SubmissionInsight) POST(org.springframework.web.bind.annotation.RequestMethod.POST) UploadFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO) DestinationResolver(org.springframework.jms.support.destination.DestinationResolver) ServiceNotAvailableException(com.odysseusinc.arachne.portal.exception.ServiceNotAvailableException) CommentTopic(com.odysseusinc.arachne.portal.model.CommentTopic) Logger(org.slf4j.Logger) DELETE(org.springframework.web.bind.annotation.RequestMethod.DELETE) CommonFilenameUtils(com.odysseusinc.arachne.commons.utils.CommonFilenameUtils) HttpServletResponse(javax.servlet.http.HttpServletResponse) BaseDataNodeService(com.odysseusinc.arachne.portal.service.BaseDataNodeService) PermissionDeniedException(com.odysseusinc.arachne.portal.exception.PermissionDeniedException) OptionDTO(com.odysseusinc.arachne.commons.api.v1.dto.OptionDTO) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) HeraclesAnalysisKind(com.odysseusinc.arachne.portal.service.analysis.heracles.HeraclesAnalysisKind) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) DataNode(com.odysseusinc.arachne.portal.model.DataNode) MultipartFile(org.springframework.web.multipart.MultipartFile) ImportService(com.odysseusinc.arachne.portal.service.ImportService) NotEmptyException(com.odysseusinc.arachne.portal.exception.NotEmptyException) SubmissionInsightService(com.odysseusinc.arachne.portal.service.submission.SubmissionInsightService) Collections(java.util.Collections) StringUtils(org.springframework.util.StringUtils) InputStream(java.io.InputStream) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) GET(org.springframework.web.bind.annotation.RequestMethod.GET) POST(org.springframework.web.bind.annotation.RequestMethod.POST) PERMISSION_DENIED(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.PERMISSION_DENIED) UUID(java.util.UUID) IUser(com.odysseusinc.arachne.portal.model.IUser) ArrayList(java.util.ArrayList) List(java.util.List) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 62 with RequestParam

use of org.springframework.web.bind.annotation.RequestParam 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)

Aggregations

RequestParam (org.springframework.web.bind.annotation.RequestParam)62 List (java.util.List)46 PathVariable (org.springframework.web.bind.annotation.PathVariable)42 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)42 Collectors (java.util.stream.Collectors)37 HttpServletRequest (javax.servlet.http.HttpServletRequest)34 HttpServletResponse (javax.servlet.http.HttpServletResponse)34 IOException (java.io.IOException)32 Autowired (org.springframework.beans.factory.annotation.Autowired)32 Map (java.util.Map)28 Controller (org.springframework.stereotype.Controller)28 GetMapping (org.springframework.web.bind.annotation.GetMapping)27 HttpStatus (org.springframework.http.HttpStatus)25 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)25 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)23 MediaType (org.springframework.http.MediaType)22 Model (org.springframework.ui.Model)20 StringUtils (org.apache.commons.lang3.StringUtils)19 Set (java.util.Set)18 Logger (org.slf4j.Logger)18