Search in sources :

Example 16 with PathVariable

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

the class AssociationController method addMultiSnps.

@RequestMapping(value = "/studies/{studyId}/associations/add_multi", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST)
public String addMultiSnps(@ModelAttribute("form") @Valid SnpAssociationStandardMultiForm snpAssociationStandardMultiForm, BindingResult bindingResult, @PathVariable Long studyId, Model model, @RequestParam(required = true) String measurementType, HttpServletRequest request) throws EnsemblMappingException {
    Study study = studyRepository.findOne(studyId);
    model.addAttribute("study", study);
    model.addAttribute("measurementType", measurementType);
    // Binding vs Validator issue. File: messages.properties
    if (bindingResult.hasErrors()) {
        model.addAttribute("form", snpAssociationStandardMultiForm);
        return "add_multi_snp_association";
    }
    // Check for errors in form that would prevent saving an association
    List<AssociationValidationView> rowErrors = associationOperationsService.checkSnpAssociationFormErrors(snpAssociationStandardMultiForm, measurementType);
    if (!rowErrors.isEmpty()) {
        model.addAttribute("errors", rowErrors);
        model.addAttribute("form", snpAssociationStandardMultiForm);
        model.addAttribute("criticalErrorsFound", true);
        return "add_multi_snp_association";
    } else {
        // Create an association object from details in returned form
        Association newAssociation = singleSnpMultiSnpAssociationService.createAssociation(snpAssociationStandardMultiForm);
        // Save and validate form
        String eRelease = ensemblRestTemplateService.getRelease();
        Collection<AssociationValidationView> errors = associationOperationsService.saveAssociationCreatedFromForm(study, newAssociation, currentUserDetailsService.getUserFromRequest(request), eRelease);
        // Determine if we have any errors rather than warnings
        long errorCount = errors.stream().filter(validationError -> !validationError.getWarning()).count();
        if (errorCount > 0) {
            model.addAttribute("errors", errors);
            model.addAttribute("form", snpAssociationStandardMultiForm);
            model.addAttribute("criticalErrorsFound", true);
            return "add_multi_snp_association";
        } else {
            return "redirect:/associations/" + newAssociation.getId();
        }
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) CheckMappingService(uk.ac.ebi.spot.goci.curation.service.CheckMappingService) LoggerFactory(org.slf4j.LoggerFactory) SnpAssociationInteractionForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationInteractionForm) Autowired(org.springframework.beans.factory.annotation.Autowired) Valid(javax.validation.Valid) AssociationOperationsService(uk.ac.ebi.spot.goci.curation.service.AssociationOperationsService) PreDestroy(javax.annotation.PreDestroy) Model(org.springframework.ui.Model) Future(java.util.concurrent.Future) AssociationDeletionService(uk.ac.ebi.spot.goci.curation.service.AssociationDeletionService) uk.ac.ebi.spot.goci.model(uk.ac.ebi.spot.goci.model) StudyRepository(uk.ac.ebi.spot.goci.repository.StudyRepository) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) EnsemblRestTemplateService(uk.ac.ebi.spot.goci.service.EnsemblRestTemplateService) DateFormat(java.text.DateFormat) RedirectAttributes(org.springframework.web.servlet.mvc.support.RedirectAttributes) HttpSession(javax.servlet.http.HttpSession) MediaType(org.springframework.http.MediaType) EventsViewService(uk.ac.ebi.spot.goci.curation.service.EventsViewService) PageRequest(org.springframework.data.domain.PageRequest) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Page(org.springframework.data.domain.Page) SnpFormColumn(uk.ac.ebi.spot.goci.curation.model.SnpFormColumn) AssociationUploadErrorView(uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView) FileNotFoundException(java.io.FileNotFoundException) Executors(java.util.concurrent.Executors) SingleSnpMultiSnpAssociationService(uk.ac.ebi.spot.goci.curation.service.SingleSnpMultiSnpAssociationService) SnpAssociationTableViewService(uk.ac.ebi.spot.goci.curation.service.SnpAssociationTableViewService) LastViewedAssociation(uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation) SnpInteractionAssociationService(uk.ac.ebi.spot.goci.curation.service.SnpInteractionAssociationService) InitBinder(org.springframework.web.bind.annotation.InitBinder) CurrentUserDetailsService(uk.ac.ebi.spot.goci.curation.service.CurrentUserDetailsService) FileUploadException(uk.ac.ebi.spot.goci.curation.exception.FileUploadException) Async(org.springframework.scheduling.annotation.Async) java.util(java.util) SnpAssociationTableView(uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) SimpleDateFormat(java.text.SimpleDateFormat) BindingResult(org.springframework.validation.BindingResult) Callable(java.util.concurrent.Callable) Controller(org.springframework.stereotype.Controller) SnpAssociationStandardMultiForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm) EfoTraitRepository(uk.ac.ebi.spot.goci.repository.EfoTraitRepository) AssociationService(uk.ac.ebi.spot.goci.service.AssociationService) Value(org.springframework.beans.factory.annotation.Value) AssociationValidationReportService(uk.ac.ebi.spot.goci.curation.service.AssociationValidationReportService) HttpServletRequest(javax.servlet.http.HttpServletRequest) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ExecutorService(java.util.concurrent.ExecutorService) DataIntegrityException(uk.ac.ebi.spot.goci.curation.exception.DataIntegrityException) Logger(org.slf4j.Logger) AssociationUploadService(uk.ac.ebi.spot.goci.curation.service.AssociationUploadService) AssociationRepository(uk.ac.ebi.spot.goci.repository.AssociationRepository) HttpServletResponse(javax.servlet.http.HttpServletResponse) SnpAssociationForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationForm) EnsemblMappingException(uk.ac.ebi.spot.goci.exception.EnsemblMappingException) SheetProcessingException(uk.ac.ebi.spot.goci.exception.SheetProcessingException) IOException(java.io.IOException) CheckEfoTermAssignmentService(uk.ac.ebi.spot.goci.curation.service.CheckEfoTermAssignmentService) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) StudyAssociationBatchDeletionEventService(uk.ac.ebi.spot.goci.curation.service.StudyAssociationBatchDeletionEventService) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) MapCatalogService(uk.ac.ebi.spot.goci.service.MapCatalogService) SnpFormRow(uk.ac.ebi.spot.goci.curation.model.SnpFormRow) WebDataBinder(org.springframework.web.bind.WebDataBinder) MultipartFile(org.springframework.web.multipart.MultipartFile) AssociationDownloadService(uk.ac.ebi.spot.goci.curation.service.AssociationDownloadService) AssociationValidationView(uk.ac.ebi.spot.goci.curation.model.AssociationValidationView) MappingDetails(uk.ac.ebi.spot.goci.curation.model.MappingDetails) LastViewedAssociation(uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation) AssociationValidationView(uk.ac.ebi.spot.goci.curation.model.AssociationValidationView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with PathVariable

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

the class AssociationController method editAssociation.

// Edit existing association
// We tried to remap if the snp or genes changed.
// TODO : implement something for SNP:SNP iteration. Actually we remap.
@RequestMapping(value = "/associations/{associationId}", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST)
public // TODO COULD REFACTOR TO JUST USE SUPERCLASS AS METHOD PARAMETER
String editAssociation(@ModelAttribute SnpAssociationStandardMultiForm snpAssociationStandardMultiForm, @ModelAttribute SnpAssociationInteractionForm snpAssociationInteractionForm, @PathVariable Long associationId, @RequestParam(value = "associationtype", required = true) String associationType, Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) throws EnsemblMappingException {
    // Establish study and association we are editing
    Collection<String> previousAuthorReportedGenes = new HashSet<>();
    Collection<String> authorReportedGenes = new HashSet<>();
    Collection<String> previousSnps = new HashSet<>();
    Collection<String> snps = new HashSet<>();
    String isToRemapping = "yes";
    Association associationToEdit = associationRepository.findOne(associationId);
    Long studyId = associationToEdit.getStudy().getId();
    Study study = studyRepository.findOne(studyId);
    model.addAttribute("study", study);
    AssociationReport oldAssociationReport = associationToEdit.getAssociationReport();
    previousAuthorReportedGenes = associationOperationsService.getGenesIds(associationToEdit.getLoci());
    previousSnps = associationOperationsService.getSpnsName(associationToEdit.getSnps());
    // Determine if association is an OR or BETA type
    String measurementType = associationOperationsService.determineIfAssociationIsOrType(associationToEdit);
    model.addAttribute("measurementType", measurementType);
    // Validate returned form depending on association type
    List<AssociationValidationView> criticalErrors = new ArrayList<>();
    if (associationType.equalsIgnoreCase("interaction")) {
        criticalErrors = associationOperationsService.checkSnpAssociationInteractionFormErrorsForView(snpAssociationInteractionForm, measurementType);
    } else {
        criticalErrors = associationOperationsService.checkSnpAssociationFormErrors(snpAssociationStandardMultiForm, measurementType);
    }
    // If errors found then return the edit form with all information entered by curator preserved
    if (!criticalErrors.isEmpty()) {
        // Get mapping details
        model.addAttribute("mappingDetails", associationOperationsService.createMappingDetails(associationToEdit));
        // Return any association errors
        model.addAttribute("errors", criticalErrors);
        model.addAttribute("criticalErrorsFound", true);
        if (associationType.equalsIgnoreCase("interaction")) {
            model.addAttribute("form", snpAssociationInteractionForm);
            return "edit_snp_interaction_association";
        } else {
            model.addAttribute("form", snpAssociationStandardMultiForm);
            // Determine view
            if (associationToEdit.getMultiSnpHaplotype()) {
                return "edit_multi_snp_association";
            } else {
                return "edit_standard_snp_association";
            }
        }
    } else {
        // Create association
        Association editedAssociation;
        // Request parameter determines how to process form and also which form to process
        if (associationType.equalsIgnoreCase("interaction")) {
            editedAssociation = snpInteractionAssociationService.createAssociation(snpAssociationInteractionForm);
        } else {
            editedAssociation = singleSnpMultiSnpAssociationService.createAssociation(snpAssociationStandardMultiForm);
            // New snps to compare with the previousSnps.
            Collection<SnpFormRow> newSnpsList = snpAssociationStandardMultiForm.getSnpFormRows();
            if (newSnpsList != null && !newSnpsList.isEmpty()) {
                for (SnpFormRow snp : newSnpsList) {
                    snps.add(snp.getSnp());
                }
            }
        }
        authorReportedGenes = associationOperationsService.getGenesIds(editedAssociation.getLoci());
        if (oldAssociationReport != null) {
            if ((previousAuthorReportedGenes.size() == authorReportedGenes.size()) && (snps.size() == snps.size())) {
                // check the values
                if ((authorReportedGenes.equals(previousAuthorReportedGenes)) && (snps.equals(previousSnps))) {
                    editedAssociation.setLastMappingDate(associationToEdit.getLastMappingDate());
                    editedAssociation.setLastMappingPerformedBy(associationToEdit.getLastMappingPerformedBy());
                    editedAssociation.setAssociationReport(oldAssociationReport);
                    isToRemapping = "no";
                }
            }
        }
        if ((oldAssociationReport != null) && (isToRemapping.compareTo("yes") == 0)) {
            associationOperationsService.deleteAssocationReport(associationToEdit.getAssociationReport().getId());
        }
        // Save and validate form
        String eRelease = ensemblRestTemplateService.getRelease();
        Collection<AssociationValidationView> errors = associationOperationsService.saveEditedAssociationFromForm(study, editedAssociation, associationId, currentUserDetailsService.getUserFromRequest(request), eRelease);
        // Determine if we have any errors rather than warnings
        long errorCount = errors.stream().filter(validationError -> !validationError.getWarning()).count();
        if (errorCount > 0) {
            // Get mapping details for association we're editing
            model.addAttribute("mappingDetails", associationOperationsService.createMappingDetails(associationToEdit));
            model.addAttribute("errors", errors);
            model.addAttribute("criticalErrorsFound", true);
            if (associationType.equalsIgnoreCase("interaction")) {
                model.addAttribute("form", snpAssociationInteractionForm);
                return "edit_snp_interaction_association";
            } else {
                model.addAttribute("form", snpAssociationStandardMultiForm);
                // Determine view
                if (associationToEdit.getMultiSnpHaplotype()) {
                    return "edit_multi_snp_association";
                } else {
                    return "edit_standard_snp_association";
                }
            }
        } else {
            redirectAttributes.addFlashAttribute("isToRemapping", isToRemapping);
            return "redirect:/associations/" + associationId;
        }
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) CheckMappingService(uk.ac.ebi.spot.goci.curation.service.CheckMappingService) LoggerFactory(org.slf4j.LoggerFactory) SnpAssociationInteractionForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationInteractionForm) Autowired(org.springframework.beans.factory.annotation.Autowired) Valid(javax.validation.Valid) AssociationOperationsService(uk.ac.ebi.spot.goci.curation.service.AssociationOperationsService) PreDestroy(javax.annotation.PreDestroy) Model(org.springframework.ui.Model) Future(java.util.concurrent.Future) AssociationDeletionService(uk.ac.ebi.spot.goci.curation.service.AssociationDeletionService) uk.ac.ebi.spot.goci.model(uk.ac.ebi.spot.goci.model) StudyRepository(uk.ac.ebi.spot.goci.repository.StudyRepository) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) EnsemblRestTemplateService(uk.ac.ebi.spot.goci.service.EnsemblRestTemplateService) DateFormat(java.text.DateFormat) RedirectAttributes(org.springframework.web.servlet.mvc.support.RedirectAttributes) HttpSession(javax.servlet.http.HttpSession) MediaType(org.springframework.http.MediaType) EventsViewService(uk.ac.ebi.spot.goci.curation.service.EventsViewService) PageRequest(org.springframework.data.domain.PageRequest) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Page(org.springframework.data.domain.Page) SnpFormColumn(uk.ac.ebi.spot.goci.curation.model.SnpFormColumn) AssociationUploadErrorView(uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView) FileNotFoundException(java.io.FileNotFoundException) Executors(java.util.concurrent.Executors) SingleSnpMultiSnpAssociationService(uk.ac.ebi.spot.goci.curation.service.SingleSnpMultiSnpAssociationService) SnpAssociationTableViewService(uk.ac.ebi.spot.goci.curation.service.SnpAssociationTableViewService) LastViewedAssociation(uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation) SnpInteractionAssociationService(uk.ac.ebi.spot.goci.curation.service.SnpInteractionAssociationService) InitBinder(org.springframework.web.bind.annotation.InitBinder) CurrentUserDetailsService(uk.ac.ebi.spot.goci.curation.service.CurrentUserDetailsService) FileUploadException(uk.ac.ebi.spot.goci.curation.exception.FileUploadException) Async(org.springframework.scheduling.annotation.Async) java.util(java.util) SnpAssociationTableView(uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) SimpleDateFormat(java.text.SimpleDateFormat) BindingResult(org.springframework.validation.BindingResult) Callable(java.util.concurrent.Callable) Controller(org.springframework.stereotype.Controller) SnpAssociationStandardMultiForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm) EfoTraitRepository(uk.ac.ebi.spot.goci.repository.EfoTraitRepository) AssociationService(uk.ac.ebi.spot.goci.service.AssociationService) Value(org.springframework.beans.factory.annotation.Value) AssociationValidationReportService(uk.ac.ebi.spot.goci.curation.service.AssociationValidationReportService) HttpServletRequest(javax.servlet.http.HttpServletRequest) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ExecutorService(java.util.concurrent.ExecutorService) DataIntegrityException(uk.ac.ebi.spot.goci.curation.exception.DataIntegrityException) Logger(org.slf4j.Logger) AssociationUploadService(uk.ac.ebi.spot.goci.curation.service.AssociationUploadService) AssociationRepository(uk.ac.ebi.spot.goci.repository.AssociationRepository) HttpServletResponse(javax.servlet.http.HttpServletResponse) SnpAssociationForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationForm) EnsemblMappingException(uk.ac.ebi.spot.goci.exception.EnsemblMappingException) SheetProcessingException(uk.ac.ebi.spot.goci.exception.SheetProcessingException) IOException(java.io.IOException) CheckEfoTermAssignmentService(uk.ac.ebi.spot.goci.curation.service.CheckEfoTermAssignmentService) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) StudyAssociationBatchDeletionEventService(uk.ac.ebi.spot.goci.curation.service.StudyAssociationBatchDeletionEventService) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) MapCatalogService(uk.ac.ebi.spot.goci.service.MapCatalogService) SnpFormRow(uk.ac.ebi.spot.goci.curation.model.SnpFormRow) WebDataBinder(org.springframework.web.bind.WebDataBinder) MultipartFile(org.springframework.web.multipart.MultipartFile) AssociationDownloadService(uk.ac.ebi.spot.goci.curation.service.AssociationDownloadService) AssociationValidationView(uk.ac.ebi.spot.goci.curation.model.AssociationValidationView) MappingDetails(uk.ac.ebi.spot.goci.curation.model.MappingDetails) AssociationValidationView(uk.ac.ebi.spot.goci.curation.model.AssociationValidationView) LastViewedAssociation(uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation) SnpFormRow(uk.ac.ebi.spot.goci.curation.model.SnpFormRow) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with PathVariable

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

the class UmaFindPolicyForResourceSetEndpointController method getPolicyForResourceSet.

/**
 * Gets policy for resource set.
 *
 * @param resourceId the resource id
 * @param policyId   the policy id
 * @param request    the request
 * @param response   the response
 * @return the policy for resource set
 */
@GetMapping(value = '/' + OAuth20Constants.BASE_OAUTH20_URL + "/{resourceId}/" + OAuth20Constants.UMA_POLICY_URL + "/{policyId}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity getPolicyForResourceSet(@PathVariable(value = "resourceId") final long resourceId, @PathVariable(value = "policyId") final long policyId, final HttpServletRequest request, final HttpServletResponse response) {
    try {
        val profileResult = getAuthenticatedProfile(request, response, OAuth20Constants.UMA_PROTECTION_SCOPE);
        val resourceSetResult = getUmaConfigurationContext().getUmaResourceSetRepository().getById(resourceId);
        if (resourceSetResult.isEmpty()) {
            val model = buildResponseEntityErrorModel(HttpStatus.NOT_FOUND, "Requested resource-set cannot be found");
            return new ResponseEntity(model, model, HttpStatus.BAD_REQUEST);
        }
        val resourceSet = resourceSetResult.get();
        resourceSet.validate(profileResult);
        val policyResult = resourceSet.getPolicies().stream().filter(p -> p.getId() == policyId).findFirst();
        if (policyResult.isPresent()) {
            val model = CollectionUtils.wrap("entity", policyResult.get(), "code", HttpStatus.FOUND);
            return new ResponseEntity(model, HttpStatus.OK);
        }
        val model = CollectionUtils.wrap("code", HttpStatus.NOT_FOUND);
        return new ResponseEntity(model, HttpStatus.OK);
    } catch (final Exception e) {
        LoggingUtils.error(LOGGER, e);
    }
    return new ResponseEntity("Unable to locate resource-set.", HttpStatus.BAD_REQUEST);
}
Also used : lombok.val(lombok.val) PathVariable(org.springframework.web.bind.annotation.PathVariable) OAuth20Constants(org.apereo.cas.support.oauth.OAuth20Constants) UmaConfigurationContext(org.apereo.cas.uma.UmaConfigurationContext) MediaType(org.springframework.http.MediaType) lombok.val(lombok.val) HttpServletResponse(javax.servlet.http.HttpServletResponse) Controller(org.springframework.stereotype.Controller) HttpStatus(org.springframework.http.HttpStatus) LoggingUtils(org.apereo.cas.util.LoggingUtils) Slf4j(lombok.extern.slf4j.Slf4j) HttpServletRequest(javax.servlet.http.HttpServletRequest) CollectionUtils(org.apereo.cas.util.CollectionUtils) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseEntity(org.springframework.http.ResponseEntity) BaseUmaEndpointController(org.apereo.cas.uma.web.controllers.BaseUmaEndpointController) ResponseEntity(org.springframework.http.ResponseEntity) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 19 with PathVariable

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

the class UmaDeletePolicyForResourceSetEndpointController method deletePoliciesForResourceSet.

/**
 * Delete policy for resource set.
 *
 * @param resourceId the resource id
 * @param policyId   the policy id
 * @param request    the request
 * @param response   the response
 * @return the policy for resource set
 */
@DeleteMapping(value = '/' + OAuth20Constants.BASE_OAUTH20_URL + "/{resourceId}/" + OAuth20Constants.UMA_POLICY_URL + "/{policyId}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity deletePoliciesForResourceSet(@PathVariable(value = "resourceId") final long resourceId, @PathVariable(value = "policyId") final long policyId, final HttpServletRequest request, final HttpServletResponse response) {
    try {
        val profileResult = getAuthenticatedProfile(request, response, OAuth20Constants.UMA_PROTECTION_SCOPE);
        val resourceSetResult = getUmaConfigurationContext().getUmaResourceSetRepository().getById(resourceId);
        if (resourceSetResult.isEmpty()) {
            val model = buildResponseEntityErrorModel(HttpStatus.NOT_FOUND, "Requested resource-set cannot be found");
            return new ResponseEntity(model, model, HttpStatus.BAD_REQUEST);
        }
        val resourceSet = resourceSetResult.get();
        resourceSet.validate(profileResult);
        val policies = resourceSet.getPolicies().stream().filter(p -> p.getId() != policyId).collect(Collectors.toSet());
        resourceSet.setPolicies(new HashSet<>(policies));
        val saved = getUmaConfigurationContext().getUmaResourceSetRepository().save(resourceSet);
        val model = CollectionUtils.wrap("entity", saved, "code", HttpStatus.OK);
        return new ResponseEntity(model, HttpStatus.OK);
    } catch (final Exception e) {
        LoggingUtils.error(LOGGER, e);
    }
    return new ResponseEntity("Unable to locate resource-set.", HttpStatus.BAD_REQUEST);
}
Also used : lombok.val(lombok.val) PathVariable(org.springframework.web.bind.annotation.PathVariable) OAuth20Constants(org.apereo.cas.support.oauth.OAuth20Constants) UmaConfigurationContext(org.apereo.cas.uma.UmaConfigurationContext) MediaType(org.springframework.http.MediaType) lombok.val(lombok.val) HttpServletResponse(javax.servlet.http.HttpServletResponse) Controller(org.springframework.stereotype.Controller) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) HttpStatus(org.springframework.http.HttpStatus) LoggingUtils(org.apereo.cas.util.LoggingUtils) Slf4j(lombok.extern.slf4j.Slf4j) HttpServletRequest(javax.servlet.http.HttpServletRequest) CollectionUtils(org.apereo.cas.util.CollectionUtils) ResponseEntity(org.springframework.http.ResponseEntity) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) BaseUmaEndpointController(org.apereo.cas.uma.web.controllers.BaseUmaEndpointController) ResponseEntity(org.springframework.http.ResponseEntity) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Example 20 with PathVariable

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

the class DuoSecurityAdminApiEndpoint method getUser.

/**
 * Fetch duo user account from admin api.
 *
 * @param username   the username
 * @param providerId the provider id
 * @return the map
 */
@GetMapping(path = "/{username}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Fetch Duo Security user account from Duo Admin API", parameters = { @Parameter(name = "username", required = true, in = ParameterIn.PATH), @Parameter(name = "providerId") })
public Map<String, DuoSecurityUserAccount> getUser(@PathVariable("username") final String username, @RequestParam(required = false) final String providerId) {
    val results = new LinkedHashMap<String, DuoSecurityUserAccount>();
    val providers = applicationContext.getBeansOfType(DuoSecurityMultifactorAuthenticationProvider.class).values();
    providers.stream().filter(Objects::nonNull).map(DuoSecurityMultifactorAuthenticationProvider.class::cast).filter(provider -> StringUtils.isBlank(providerId) || provider.matches(providerId)).filter(provider -> provider.getDuoAuthenticationService().getAdminApiService().isPresent()).forEach(Unchecked.consumer(p -> {
        val duoService = p.getDuoAuthenticationService().getAdminApiService().get();
        duoService.getDuoSecurityUserAccount(username).ifPresent(user -> results.put(p.getId(), user));
    }));
    return results;
}
Also used : lombok.val(lombok.val) DuoSecurityMultifactorAuthenticationProvider(org.apereo.cas.adaptors.duo.authn.DuoSecurityMultifactorAuthenticationProvider) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) PathVariable(org.springframework.web.bind.annotation.PathVariable) PostMapping(org.springframework.web.bind.annotation.PostMapping) RequestParam(org.springframework.web.bind.annotation.RequestParam) Unchecked(org.jooq.lambda.Unchecked) MediaType(org.springframework.http.MediaType) lombok.val(lombok.val) StringUtils(org.apache.commons.lang3.StringUtils) ApplicationContext(org.springframework.context.ApplicationContext) DuoSecurityMultifactorAuthenticationProvider(org.apereo.cas.adaptors.duo.authn.DuoSecurityMultifactorAuthenticationProvider) ParameterIn(io.swagger.v3.oas.annotations.enums.ParameterIn) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) Parameter(io.swagger.v3.oas.annotations.Parameter) RestControllerEndpoint(org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint) LinkedHashMap(java.util.LinkedHashMap) Objects(java.util.Objects) Operation(io.swagger.v3.oas.annotations.Operation) List(java.util.List) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) DuoSecurityUserAccount(org.apereo.cas.adaptors.duo.DuoSecurityUserAccount) Objects(java.util.Objects) LinkedHashMap(java.util.LinkedHashMap) GetMapping(org.springframework.web.bind.annotation.GetMapping) Operation(io.swagger.v3.oas.annotations.Operation)

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