Search in sources :

Example 1 with Value

use of org.springframework.beans.factory.annotation.Value in project goci by EBISPOT.

the class AssociationController method validateUnapproved.

/**
     -     * Run mapping pipeline on all SNPs in a study
     -     *
     -     * @param studyId            Study ID in database
     -     * @param redirectAttributes attributes for a redirect scenario
     -     */
@RequestMapping(value = "/studies/{studyId}/associations/validate_unapproved", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
public String validateUnapproved(@PathVariable Long studyId, RedirectAttributes redirectAttributes, Model model, HttpServletRequest request) throws //                                         @RequestParam(required = false) Long associationId)
EnsemblMappingException {
    Study study = studyRepository.findOne(studyId);
    // For the study get all associations
    Collection<Association> studyAssociations = associationRepository.findByStudyId(studyId);
    for (Association associationToValidate : studyAssociations) {
        if (!associationToValidate.getSnpApproved()) {
            String measurementType = associationOperationsService.determineIfAssociationIsOrType(associationToValidate);
            List<AssociationValidationView> criticalErrors = new ArrayList<>();
            if (associationToValidate.getSnpInteraction()) {
                criticalErrors = associationOperationsService.checkSnpAssociationInteractionFormErrors((SnpAssociationInteractionForm) associationOperationsService.generateForm(associationToValidate), measurementType);
            } else {
                criticalErrors = associationOperationsService.checkSnpAssociationFormErrors((SnpAssociationStandardMultiForm) associationOperationsService.generateForm(associationToValidate), measurementType);
            }
            //if an association has critical errors, go straight to that association
            if (!criticalErrors.isEmpty()) {
                model.addAttribute("study", study);
                model.addAttribute("measurementType", measurementType);
                // Get mapping details
                model.addAttribute("mappingDetails", associationOperationsService.createMappingDetails(associationToValidate));
                // Return any association errors
                model.addAttribute("errors", criticalErrors);
                model.addAttribute("criticalErrorsFound", true);
                if (associationToValidate.getSnpInteraction()) {
                    model.addAttribute("form", associationOperationsService.generateForm(associationToValidate));
                    return "redirect:/associations/" + associationToValidate.getId();
                // return "edit_snp_interaction_association";
                } else {
                    model.addAttribute("form", associationOperationsService.generateForm(associationToValidate));
                    // Determine view
                    if (associationToValidate.getMultiSnpHaplotype()) {
                        return "redirect:/associations/" + associationToValidate.getId();
                    // return "edit_multi_snp_association";
                    } else {
                        //                             return "edit_standard_snp_association";
                        return "redirect:/associations/" + associationToValidate.getId();
                    }
                }
            } else //     if there are no criticial errors, save the validation and go to the next association
            {
                // Save and validate form
                String eRelease = ensemblRestTemplateService.getRelease();
                Collection<AssociationValidationView> errors = associationOperationsService.validateAndSaveAssociation(study, associationToValidate, currentUserDetailsService.getUserFromRequest(request), eRelease);
                // Determine if we have any errors rather than warnings
                long errorCount = errors.stream().filter(validationError -> !validationError.getWarning()).count();
                //if there are errors rather than warnings, go straight to the page to edit
                if (errorCount > 0) {
                    model.addAttribute("study", study);
                    model.addAttribute("measurementType", measurementType);
                    // Get mapping details for association we're editing
                    model.addAttribute("mappingDetails", associationOperationsService.createMappingDetails(associationToValidate));
                    model.addAttribute("errors", errors);
                    model.addAttribute("criticalErrorsFound", true);
                    if (associationToValidate.getSnpInteraction()) {
                        model.addAttribute("form", associationOperationsService.generateForm(associationToValidate));
                        //                              return "edit_snp_interaction_association";
                        return "redirect:/associations/" + associationToValidate.getId();
                    } else {
                        model.addAttribute("form", associationOperationsService.generateForm(associationToValidate));
                        // Determine view
                        if (associationToValidate.getMultiSnpHaplotype()) {
                            //                                  return "edit_multi_snp_association";
                            return "redirect:/associations/" + associationToValidate.getId();
                        } else {
                            //                                  return "edit_standard_snp_association";
                            return "redirect:/associations/" + associationToValidate.getId();
                        }
                    }
                }
            }
        }
    }
    String message = "Mapping complete, please check for any errors displayed in the 'Errors' column";
    redirectAttributes.addFlashAttribute("mappingComplete", message);
    return "redirect:/studies/" + studyId + "/associations";
}
Also used : FileUploadException(uk.ac.ebi.spot.goci.curation.exception.FileUploadException) java.util(java.util) SnpAssociationTableView(uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView) LoggerFactory(org.slf4j.LoggerFactory) SnpAssociationInteractionForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationInteractionForm) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleDateFormat(java.text.SimpleDateFormat) BindingResult(org.springframework.validation.BindingResult) Controller(org.springframework.stereotype.Controller) SnpAssociationStandardMultiForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm) EfoTraitRepository(uk.ac.ebi.spot.goci.repository.EfoTraitRepository) Value(org.springframework.beans.factory.annotation.Value) Valid(javax.validation.Valid) Model(org.springframework.ui.Model) uk.ac.ebi.spot.goci.curation.service(uk.ac.ebi.spot.goci.curation.service) HttpServletRequest(javax.servlet.http.HttpServletRequest) uk.ac.ebi.spot.goci.model(uk.ac.ebi.spot.goci.model) Qualifier(org.springframework.beans.factory.annotation.Qualifier) StudyRepository(uk.ac.ebi.spot.goci.repository.StudyRepository) 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) DataIntegrityException(uk.ac.ebi.spot.goci.curation.exception.DataIntegrityException) Logger(org.slf4j.Logger) AssociationRepository(uk.ac.ebi.spot.goci.repository.AssociationRepository) MediaType(org.springframework.http.MediaType) 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) SnpFormColumn(uk.ac.ebi.spot.goci.curation.model.SnpFormColumn) AssociationUploadErrorView(uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView) FileNotFoundException(java.io.FileNotFoundException) MapCatalogService(uk.ac.ebi.spot.goci.service.MapCatalogService) GetRequest(com.mashape.unirest.request.GetRequest) SnpFormRow(uk.ac.ebi.spot.goci.curation.model.SnpFormRow) WebDataBinder(org.springframework.web.bind.WebDataBinder) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) LastViewedAssociation(uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation) MultipartFile(org.springframework.web.multipart.MultipartFile) 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) SnpAssociationStandardMultiForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm) AssociationValidationView(uk.ac.ebi.spot.goci.curation.model.AssociationValidationView) SnpAssociationInteractionForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationInteractionForm)

Example 2 with Value

use of org.springframework.beans.factory.annotation.Value in project apollo by ctripcorp.

the class SpringValueProcessor method processMethod.

@Override
protected void processMethod(Object bean, String beanName, Method method) {
    // register @Value on method
    Value value = method.getAnnotation(Value.class);
    if (value == null) {
        return;
    }
    // skip Configuration bean methods
    if (method.getAnnotation(Bean.class) != null) {
        return;
    }
    if (method.getParameterTypes().length != 1) {
        logger.error("Ignore @Value setter {}.{}, expecting 1 parameter, actual {} parameters", bean.getClass().getName(), method.getName(), method.getParameterTypes().length);
        return;
    }
    Set<String> keys = placeholderHelper.extractPlaceholderKeys(value.value());
    if (keys.isEmpty()) {
        return;
    }
    for (String key : keys) {
        SpringValue springValue = new SpringValue(key, value.value(), bean, beanName, method, false);
        springValueRegistry.register(key, springValue);
        logger.debug("Monitoring {}", springValue);
    }
}
Also used : SpringValue(com.ctrip.framework.apollo.spring.property.SpringValue) Value(org.springframework.beans.factory.annotation.Value) SpringValue(com.ctrip.framework.apollo.spring.property.SpringValue) Bean(org.springframework.context.annotation.Bean)

Example 3 with Value

use of org.springframework.beans.factory.annotation.Value in project apollo by ctripcorp.

the class SpringValueProcessor method processField.

@Override
protected void processField(Object bean, String beanName, Field field) {
    // register @Value on field
    Value value = field.getAnnotation(Value.class);
    if (value == null) {
        return;
    }
    Set<String> keys = placeholderHelper.extractPlaceholderKeys(value.value());
    if (keys.isEmpty()) {
        return;
    }
    for (String key : keys) {
        SpringValue springValue = new SpringValue(key, value.value(), bean, beanName, field, false);
        springValueRegistry.register(key, springValue);
        logger.debug("Monitoring {}", springValue);
    }
}
Also used : SpringValue(com.ctrip.framework.apollo.spring.property.SpringValue) Value(org.springframework.beans.factory.annotation.Value) SpringValue(com.ctrip.framework.apollo.spring.property.SpringValue)

Example 4 with Value

use of org.springframework.beans.factory.annotation.Value in project vorto by eclipse.

the class ModelRepositoryController method getModelContentByModelAndMappingId.

@ApiOperation(value = "Returns the model content including target platform specific attributes for the given model- and mapping modelID")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Wrong input"), @ApiResponse(code = 404, message = "Model not found") })
@RequestMapping(value = "/content/{modelId:.+}/mapping/{mappingId:.+}", method = RequestMethod.GET)
public AbstractModel getModelContentByModelAndMappingId(@ApiParam(value = "The model ID (prettyFormat)", required = true) @PathVariable final String modelId, @ApiParam(value = "The mapping Model ID (prettyFormat)", required = true) @PathVariable final String mappingId) {
    ModelInfo vortoModelInfo = modelRepository.getById(ModelId.fromPrettyFormat(modelId));
    ModelInfo mappingModelInfo = modelRepository.getById(ModelId.fromPrettyFormat(mappingId));
    if (vortoModelInfo == null) {
        throw new ModelNotFoundException("Could not find vorto model with ID: " + modelId);
    } else if (mappingModelInfo == null) {
        throw new ModelNotFoundException("Could not find mapping with ID: " + mappingId);
    }
    byte[] mappingContentZip = createZipWithAllDependencies(mappingModelInfo.getId(), ContentType.DSL);
    IModelWorkspace workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(new ByteArrayInputStream(mappingContentZip))).read();
    MappingModel mappingModel = (MappingModel) workspace.get().stream().filter(p -> p instanceof MappingModel).findFirst().get();
    byte[] modelContent = createZipWithAllDependencies(vortoModelInfo.getId(), ContentType.DSL);
    workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(new ByteArrayInputStream(modelContent))).read();
    return ModelDtoFactory.createResource(workspace.get().stream().filter(p -> p.getName().equals(vortoModelInfo.getId().getName())).findFirst().get(), Optional.of(mappingModel));
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URLDecoder(java.net.URLDecoder) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ApiParam(io.swagger.annotations.ApiParam) ApiResponses(io.swagger.annotations.ApiResponses) ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) Value(org.springframework.beans.factory.annotation.Value) Logger(org.apache.log4j.Logger) ApiOperation(io.swagger.annotations.ApiOperation) AbstractRepositoryController(org.eclipse.vorto.repository.web.AbstractRepositoryController) ByteArrayInputStream(java.io.ByteArrayInputStream) AbstractModel(org.eclipse.vorto.repository.api.AbstractModel) Api(io.swagger.annotations.Api) ZipEntry(java.util.zip.ZipEntry) ModelId(org.eclipse.vorto.repository.api.ModelId) UploadTooLargeException(org.eclipse.vorto.repository.web.core.exceptions.UploadTooLargeException) ContentType(org.eclipse.vorto.repository.core.IModelRepository.ContentType) HttpServletResponse(javax.servlet.http.HttpServletResponse) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) ModelNotFoundException(org.eclipse.vorto.repository.api.exception.ModelNotFoundException) IModelWorkspace(org.eclipse.vorto.server.commons.reader.IModelWorkspace) Objects(java.util.Objects) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) ApiResponse(io.swagger.annotations.ApiResponse) Optional(java.util.Optional) MultipartFile(org.springframework.web.multipart.MultipartFile) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ModelNotFoundException(org.eclipse.vorto.repository.api.exception.ModelNotFoundException) IModelWorkspace(org.eclipse.vorto.server.commons.reader.IModelWorkspace) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Value

use of org.springframework.beans.factory.annotation.Value in project microservices by pwillhan.

the class PersonPhotoRestController method setUserHome.

@Value("${user.home}")
void setUserHome(String home) {
    this.root = new File(home, "Desktop/images");
    Assert.isTrue(this.root.exists() || this.root.mkdirs(), "The path '" + this.root.getAbsolutePath() + "' must exist.");
}
Also used : File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) Value(org.springframework.beans.factory.annotation.Value)

Aggregations

Value (org.springframework.beans.factory.annotation.Value)64 Autowired (org.springframework.beans.factory.annotation.Autowired)27 IOException (java.io.IOException)26 Collectors (java.util.stream.Collectors)22 Logger (org.slf4j.Logger)21 LoggerFactory (org.slf4j.LoggerFactory)21 List (java.util.List)19 HttpServletResponse (javax.servlet.http.HttpServletResponse)15 ArrayList (java.util.ArrayList)14 PathVariable (org.springframework.web.bind.annotation.PathVariable)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 RequestParam (org.springframework.web.bind.annotation.RequestParam)14 AnnotationVisitor (com.navercorp.pinpoint.common.server.config.AnnotationVisitor)13 LoggingEvent (com.navercorp.pinpoint.common.server.config.LoggingEvent)13 Optional (java.util.Optional)13 Map (java.util.Map)12 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)12 java.util (java.util)11 Set (java.util.Set)11 Stream (java.util.stream.Stream)11