Search in sources :

Example 26 with PathVariable

use of org.springframework.web.bind.annotation.PathVariable in project zhcet-web by zhcet-amu.

the class RealTimeStatusController method realTimeSse.

@GetMapping("/management/task/sse/{id}")
public SseEmitter realTimeSse(@PathVariable String id) {
    SseEmitter emitter = new SseEmitter(TIMEOUT);
    RealTimeStatus status = realTimeStatusService.get(id);
    Consumer<RealTimeStatus> consumer = statusChange -> {
        try {
            emitter.send(statusChange);
        } catch (IOException e) {
            log.error("Error sending event", e);
            emitter.complete();
        }
    };
    Runnable completeListener = emitter::complete;
    Runnable onComplete = () -> {
        status.removeChangeListener(consumer);
        status.removeStopListener(completeListener);
    };
    status.addChangeListener(consumer);
    status.onStop(completeListener);
    emitter.onCompletion(onComplete);
    emitter.onTimeout(onComplete);
    consumer.accept(status);
    if (status.isInvalid() || status.isFailed() || status.isFinished())
        emitter.complete();
    return emitter;
}
Also used : Consumer(java.util.function.Consumer) PathVariable(org.springframework.web.bind.annotation.PathVariable) Slf4j(lombok.extern.slf4j.Slf4j) GetMapping(org.springframework.web.bind.annotation.GetMapping) IOException(java.io.IOException) RestController(org.springframework.web.bind.annotation.RestController) SseEmitter(org.springframework.web.servlet.mvc.method.annotation.SseEmitter) SseEmitter(org.springframework.web.servlet.mvc.method.annotation.SseEmitter) IOException(java.io.IOException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 27 with PathVariable

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

the class BaseSubmissionController method createSubmission.

@ApiOperation("Create and send submission.")
@PostMapping("/api/v1/analysis-management/{analysisId}/submissions")
public JsonResult<List<DTO>> createSubmission(Principal principal, @RequestBody @Validated CreateSubmissionsDTO createSubmissionsDTO, @PathVariable("analysisId") Long analysisId) throws PermissionDeniedException, NotExistException, IOException, NoExecutableFileException, ValidationException {
    final JsonResult<List<DTO>> result;
    if (principal == null) {
        throw new PermissionDeniedException();
    }
    IUser user = userService.getByUsername(principal.getName());
    if (user == null) {
        throw new PermissionDeniedException();
    }
    Analysis analysis = analysisService.getById(analysisId);
    final List<Submission> submissions = AnalysisHelper.createSubmission(submissionService, createSubmissionsDTO.getDataSources(), user, analysis);
    final List<DTO> submissionDTOs = submissions.stream().map(s -> conversionService.convert(s, getSubmissionDTOClass())).collect(Collectors.toList());
    result = new JsonResult<>(NO_ERROR);
    result.setResult(submissionDTOs);
    return result;
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) AnalysisHelper(com.odysseusinc.arachne.portal.util.AnalysisHelper) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) PutMapping(org.springframework.web.bind.annotation.PutMapping) Analysis(com.odysseusinc.arachne.portal.model.Analysis) ResultFileSearch(com.odysseusinc.arachne.portal.model.search.ResultFileSearch) SubmissionFile(com.odysseusinc.arachne.portal.model.SubmissionFile) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) Path(java.nio.file.Path) SubmissionStatusHistoryElement(com.odysseusinc.arachne.portal.model.SubmissionStatusHistoryElement) ToPdfConverter(com.odysseusinc.arachne.portal.service.ToPdfConverter) BaseSubmissionService(com.odysseusinc.arachne.portal.service.submission.BaseSubmissionService) PostMapping(org.springframework.web.bind.annotation.PostMapping) BaseAnalysisService(com.odysseusinc.arachne.portal.service.analysis.BaseAnalysisService) ContentStorageService(com.odysseusinc.arachne.storage.service.ContentStorageService) ResultFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.ResultFileDTO) HttpUtils(com.odysseusinc.arachne.portal.util.HttpUtils) MediaType(org.springframework.http.MediaType) ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) IUser(com.odysseusinc.arachne.portal.model.IUser) FileDTO(com.odysseusinc.arachne.portal.api.v1.dto.FileDTO) IOUtils(org.apache.commons.io.IOUtils) Principal(java.security.Principal) BaseSubmissionDTO(com.odysseusinc.arachne.portal.api.v1.dto.BaseSubmissionDTO) SubmissionStatus(com.odysseusinc.arachne.portal.model.SubmissionStatus) FilenameUtils(org.apache.commons.io.FilenameUtils) java.util(java.util) FileDtoContentHandler(com.odysseusinc.arachne.portal.api.v1.dto.converters.FileDtoContentHandler) ZipInputStream(java.util.zip.ZipInputStream) StringUtils.getFilename(org.springframework.util.StringUtils.getFilename) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Submission(com.odysseusinc.arachne.portal.model.Submission) ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) RequestBody(org.springframework.web.bind.annotation.RequestBody) NoExecutableFileException(com.odysseusinc.arachne.portal.exception.NoExecutableFileException) ApproveDTO(com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO) ZipUtil(com.odysseusinc.arachne.portal.util.ZipUtil) Files(com.google.common.io.Files) ObjectUtils(org.apache.commons.lang3.ObjectUtils) SubmissionStatusHistoryElementDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionStatusHistoryElementDTO) NO_ERROR(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.NO_ERROR) GetMapping(org.springframework.web.bind.annotation.GetMapping) UploadFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO) BaseController(com.odysseusinc.arachne.portal.api.v1.controller.BaseController) Validated(org.springframework.validation.annotation.Validated) Logger(org.slf4j.Logger) HttpServletResponse(javax.servlet.http.HttpServletResponse) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) CommonAnalysisExecutionStatusDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisExecutionStatusDTO) CreateSubmissionsDTO(com.odysseusinc.arachne.portal.api.v1.dto.CreateSubmissionsDTO) SubmissionFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionFileDTO) File(java.io.File) PermissionDeniedException(com.odysseusinc.arachne.portal.exception.PermissionDeniedException) ContentStorageHelper(com.odysseusinc.arachne.portal.util.ContentStorageHelper) HttpStatus(org.springframework.http.HttpStatus) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) MultipartFile(org.springframework.web.multipart.MultipartFile) SubmissionDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionDTO) BaseSubmissionAndAnalysisTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.BaseSubmissionAndAnalysisTypeDTO) SubmissionInsightService(com.odysseusinc.arachne.portal.service.submission.SubmissionInsightService) Submission(com.odysseusinc.arachne.portal.model.Submission) Analysis(com.odysseusinc.arachne.portal.model.Analysis) IUser(com.odysseusinc.arachne.portal.model.IUser) PermissionDeniedException(com.odysseusinc.arachne.portal.exception.PermissionDeniedException) ResultFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.ResultFileDTO) FileDTO(com.odysseusinc.arachne.portal.api.v1.dto.FileDTO) BaseSubmissionDTO(com.odysseusinc.arachne.portal.api.v1.dto.BaseSubmissionDTO) ApproveDTO(com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO) SubmissionStatusHistoryElementDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionStatusHistoryElementDTO) UploadFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO) CommonAnalysisExecutionStatusDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisExecutionStatusDTO) CreateSubmissionsDTO(com.odysseusinc.arachne.portal.api.v1.dto.CreateSubmissionsDTO) SubmissionFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionFileDTO) SubmissionDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionDTO) BaseSubmissionAndAnalysisTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.BaseSubmissionAndAnalysisTypeDTO) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 28 with PathVariable

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

the class BaseDataNodeController method getDataSourcesForDataNode.

@ApiOperation("List datasources for the specified data node")
@GetMapping(value = "/api/v1/data-nodes/{dataNodeId}/data-sources")
public List<DataSourceDTO> getDataSourcesForDataNode(@PathVariable("dataNodeId") Long dataNodeId) {
    DataNode dataNode = baseDataNodeService.getById(dataNodeId);
    List<DataSource> dataSources = dataNode.getDataSources().stream().filter(ds -> Boolean.TRUE.equals(ds.getPublished())).collect(Collectors.toList());
    return converterUtils.convertList(dataSources, DataSourceDTO.class);
}
Also used : OrganizationService(com.odysseusinc.arachne.portal.service.OrganizationService) PathVariable(org.springframework.web.bind.annotation.PathVariable) CommonDataNodeDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonDataNodeDTO) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) BaseUserService(com.odysseusinc.arachne.portal.service.BaseUserService) Organization(com.odysseusinc.arachne.portal.model.Organization) DataSourceDTO(com.odysseusinc.arachne.portal.api.v1.dto.DataSourceDTO) ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) Valid(javax.validation.Valid) RequestBody(org.springframework.web.bind.annotation.RequestBody) Strings(com.google.common.base.Strings) ApiOperation(io.swagger.annotations.ApiOperation) SolrServerException(org.apache.solr.client.solrj.SolrServerException) DataSource(com.odysseusinc.arachne.portal.model.DataSource) IDataSource(com.odysseusinc.arachne.portal.model.IDataSource) BaseDataSourceService(com.odysseusinc.arachne.portal.service.BaseDataSourceService) ArachneConverterUtils(com.odysseusinc.arachne.portal.util.ArachneConverterUtils) GetMapping(org.springframework.web.bind.annotation.GetMapping) CommonDataNodeCreationResponseDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonDataNodeCreationResponseDTO) ConstraintViolation(javax.validation.ConstraintViolation) BindException(org.springframework.validation.BindException) BaseAnalysisService(com.odysseusinc.arachne.portal.service.analysis.BaseAnalysisService) Logger(org.slf4j.Logger) DataNodeDTO(com.odysseusinc.arachne.portal.api.v1.dto.DataNodeDTO) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) FieldError(org.springframework.validation.FieldError) CommonDataNodeRegisterDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonDataNodeRegisterDTO) Set(java.util.Set) Validator(javax.validation.Validator) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) IOException(java.io.IOException) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) BaseDataNodeService(com.odysseusinc.arachne.portal.service.BaseDataNodeService) Collectors(java.util.stream.Collectors) PermissionDeniedException(com.odysseusinc.arachne.portal.exception.PermissionDeniedException) IUser(com.odysseusinc.arachne.portal.model.IUser) Objects(java.util.Objects) List(java.util.List) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) Principal(java.security.Principal) ConstraintViolationException(javax.validation.ConstraintViolationException) DataNode(com.odysseusinc.arachne.portal.model.DataNode) StudyDataSourceService(com.odysseusinc.arachne.portal.service.StudyDataSourceService) CommonDataSourceDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonDataSourceDTO) FieldException(com.odysseusinc.arachne.portal.exception.FieldException) DataNode(com.odysseusinc.arachne.portal.model.DataNode) DataSource(com.odysseusinc.arachne.portal.model.DataSource) IDataSource(com.odysseusinc.arachne.portal.model.IDataSource) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 29 with PathVariable

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

the class VariableController method variable.

@GetMapping("/variable/{id:.+}")
public ModelAndView variable(@PathVariable String id) {
    Map<String, Object> params = newParameters();
    DatasetVariable.IdResolver resolver = DatasetVariable.IdResolver.from(id);
    String datasetId = resolver.getDatasetId();
    String variableName = resolver.getName();
    switch(resolver.getType()) {
        case Collected:
            if (!collectedDatasetService.isPublished(datasetId))
                throw NoSuchDatasetException.withId(datasetId);
            break;
        case Dataschema:
        case Harmonized:
            if (!harmonizedDatasetService.isPublished(datasetId))
                throw NoSuchDatasetException.withId(datasetId);
            break;
    }
    DatasetVariable variable = resolver.getType().equals(DatasetVariable.Type.Harmonized) ? getHarmonizedDatasetVariable(resolver.getDatasetId(), id, variableName) : getDatasetVariable(id, variableName);
    params.put("variable", variable);
    params.put("type", resolver.getType().toString());
    addStudyTableParameters(params, variable);
    Map<String, Taxonomy> taxonomies = taxonomyService.getVariableTaxonomies().stream().collect(Collectors.toMap(TaxonomyEntity::getName, e -> e));
    // annotations are attributes described by some taxonomies
    List<Annotation> annotations = variable.hasAttributes() ? variable.getAttributes().asAttributeList().stream().filter(attr -> attr.hasNamespace() && taxonomies.containsKey(attr.getNamespace()) && taxonomies.get(attr.getNamespace()).hasVocabulary(attr.getName())).map(attr -> new Annotation(attr, taxonomies.get(attr.getNamespace()))).collect(Collectors.toList()) : Lists.newArrayList();
    List<Annotation> harmoAnnotations = annotations.stream().filter(annot -> annot.getTaxonomyName().equals("Mlstr_harmo")).collect(Collectors.toList());
    annotations = annotations.stream().filter(annot -> !annot.getTaxonomyName().equals("Mlstr_harmo")).collect(Collectors.toList());
    StringBuilder query = new StringBuilder();
    for (Annotation annot : annotations) {
        String expr = "in(" + annot.getTaxonomyName() + "." + annot.getVocabularyName() + "," + annot.getTermName() + ")";
        if (query.length() == 0)
            query = new StringBuilder(expr);
        else
            query = new StringBuilder("and(" + query + "," + expr + ")");
    }
    params.put("annotations", annotations);
    params.put("harmoAnnotations", new HarmonizationAnnotations(harmoAnnotations));
    params.put("query", "variable(" + query.toString() + ")");
    params.put("showDatasetContingencyLink", showDatasetContingencyLink());
    return new ModelAndView("variable", params);
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) LoggerFactory(org.slf4j.LoggerFactory) HarmonizationStudyTable(org.obiba.mica.core.domain.HarmonizationStudyTable) Controller(org.springframework.stereotype.Controller) NoSuchVariableException(org.obiba.magma.NoSuchVariableException) Indexer(org.obiba.mica.spi.search.Indexer) Inject(javax.inject.Inject) Lists(com.google.common.collect.Lists) Map(java.util.Map) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) GetMapping(org.springframework.web.bind.annotation.GetMapping) NoSuchDatasetException(org.obiba.mica.dataset.NoSuchDatasetException) TaxonomyEntity(org.obiba.opal.core.domain.taxonomy.TaxonomyEntity) NoSuchElementException(java.util.NoSuchElementException) Logger(org.slf4j.Logger) Searcher(org.obiba.mica.spi.search.Searcher) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) BaseStudy(org.obiba.mica.study.domain.BaseStudy) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Population(org.obiba.mica.study.domain.Population) CollectedDatasetService(org.obiba.mica.dataset.service.CollectedDatasetService) StudyService(org.obiba.mica.study.service.StudyService) IOException(java.io.IOException) DataCollectionEvent(org.obiba.mica.study.domain.DataCollectionEvent) Collectors(java.util.stream.Collectors) HarmonizedDatasetService(org.obiba.mica.dataset.service.HarmonizedDatasetService) NoSuchStudyException(org.obiba.mica.study.NoSuchStudyException) HarmonizationAnnotations(org.obiba.mica.web.controller.domain.HarmonizationAnnotations) PublishedStudyService(org.obiba.mica.study.service.PublishedStudyService) ModelAndView(org.springframework.web.servlet.ModelAndView) List(java.util.List) Study(org.obiba.mica.study.domain.Study) Annotation(org.obiba.mica.web.controller.domain.Annotation) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) TaxonomyService(org.obiba.mica.micaConfig.service.TaxonomyService) Optional(java.util.Optional) StudyTable(org.obiba.mica.core.domain.StudyTable) InputStream(java.io.InputStream) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) ModelAndView(org.springframework.web.servlet.ModelAndView) HarmonizationAnnotations(org.obiba.mica.web.controller.domain.HarmonizationAnnotations) Annotation(org.obiba.mica.web.controller.domain.Annotation) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 30 with PathVariable

use of org.springframework.web.bind.annotation.PathVariable in project alf.io by alfio-event.

the class MolliePaymentWebhookController method receivePaymentConfirmation.

@SuppressWarnings("MVCPathVariableInspection")
@PostMapping(WEBHOOK_URL_TEMPLATE)
public ResponseEntity<String> receivePaymentConfirmation(HttpServletRequest request, @PathVariable("reservationId") String reservationId) {
    return Optional.ofNullable(StringUtils.trimToNull(request.getParameter("id"))).flatMap(id -> purchaseContextManager.findByReservationId(reservationId).map(purchaseContext -> {
        var content = "id=" + id;
        var result = ticketReservationManager.processTransactionWebhook(content, null, PaymentProxy.MOLLIE, Map.of(ADDITIONAL_INFO_PURCHASE_CONTEXT_TYPE, purchaseContext.getType().getUrlComponent(), ADDITIONAL_INFO_PURCHASE_IDENTIFIER, purchaseContext.getPublicIdentifier(), ADDITIONAL_INFO_RESERVATION_ID, reservationId), new PaymentContext(purchaseContext, reservationId));
        if (result.isSuccessful()) {
            return ResponseEntity.ok("OK");
        } else if (result.isError()) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result.getReason());
        }
        return ResponseEntity.ok(result.getReason());
    })).orElseGet(() -> ResponseEntity.badRequest().body("NOK"));
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) PostMapping(org.springframework.web.bind.annotation.PostMapping) MollieWebhookPaymentManager(alfio.manager.payment.MollieWebhookPaymentManager) PaymentProxy(alfio.model.transaction.PaymentProxy) StringUtils(org.apache.commons.lang3.StringUtils) RestController(org.springframework.web.bind.annotation.RestController) HttpStatus(org.springframework.http.HttpStatus) PurchaseContextManager(alfio.manager.PurchaseContextManager) TicketReservationManager(alfio.manager.TicketReservationManager) HttpServletRequest(javax.servlet.http.HttpServletRequest) PaymentContext(alfio.model.transaction.PaymentContext) Map(java.util.Map) Log4j2(lombok.extern.log4j.Log4j2) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) AllArgsConstructor(lombok.AllArgsConstructor) PaymentContext(alfio.model.transaction.PaymentContext) PostMapping(org.springframework.web.bind.annotation.PostMapping)

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