Search in sources :

Example 11 with Value

use of org.springframework.beans.factory.annotation.Value in project hub-docker-inspector by blackducksoftware.

the class Config method init.

@PostConstruct
public void init() throws IllegalArgumentException, IllegalAccessException {
    final Object configObject = this;
    publicOptions = new ArrayList<>();
    allKeys = new ArrayList<>();
    optionsByKey = new HashMap<>();
    optionsByFieldName = new HashMap<>();
    for (final Field field : configObject.getClass().getDeclaredFields()) {
        final Annotation[] declaredAnnotations = field.getDeclaredAnnotations();
        if (declaredAnnotations.length > 0) {
            for (final Annotation annotation : declaredAnnotations) {
                if (annotation.annotationType().getName().equals(ValueDescription.class.getName())) {
                    logger.debug(String.format("ValueDescription annotated config object field: %s", field.getName()));
                    final String propMappingString = field.getAnnotation(Value.class).value();
                    final String propName = SpringValueUtils.springKeyFromValueAnnotation(propMappingString);
                    final Object fieldValueObject = field.get(configObject);
                    if (fieldValueObject == null) {
                        logger.warn(String.format("propName %s field is null", propName));
                        continue;
                    }
                    final String value = fieldValueObject.toString();
                    logger.trace(String.format("adding prop key %s [value: %s]", propName, value));
                    allKeys.add(propName);
                    final ValueDescription valueDescription = field.getAnnotation(ValueDescription.class);
                    final DockerInspectorOption opt = new DockerInspectorOption(propName, field.getName(), value, valueDescription.description(), field.getType(), valueDescription.defaultValue(), valueDescription.group(), valueDescription.deprecated());
                    optionsByKey.put(propName, opt);
                    logger.trace(String.format("adding field name %s to optionsByFieldName", field.getName()));
                    optionsByFieldName.put(field.getName(), opt);
                    if (!Config.GROUP_PRIVATE.equals(valueDescription.group())) {
                        publicOptions.add(opt);
                    } else {
                        logger.debug(String.format("private prop: propName: %s, fieldName: %s, group: %s, description: %s", propName, field.getName(), valueDescription.group(), valueDescription.description()));
                    }
                }
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) ValueDescription(com.blackducksoftware.integration.hub.docker.dockerinspector.help.ValueDescription) Value(org.springframework.beans.factory.annotation.Value) Annotation(java.lang.annotation.Annotation) PostConstruct(javax.annotation.PostConstruct)

Example 12 with Value

use of org.springframework.beans.factory.annotation.Value in project nextprot-api by calipho-sib.

the class PepXServiceImpl method computePeptideUnicityStatus.

/**
 * Computes a unicity value for each peptide: UNIQUE, PSEUDO_UNIQUE, NON_UNIQUE
 * based on the response returned by pepx (a list of peptide - isoform matches)
 * by using the PeptideUnicityService
 * @param entries
 * @param withVariants
 * @return a map with key = peptide sequence, value = unicity value
 */
private Map<String, PeptideUnicity> computePeptideUnicityStatus(List<Entry> entries, boolean withVariants) {
    Map<String, Set<String>> pepIsoSetMap = new HashMap<>();
    entries.forEach(e -> {
        e.getAnnotationsByCategory(AnnotationCategory.PEPX_VIRTUAL_ANNOTATION).stream().filter(a -> a.getVariant() == null || withVariants).forEach(a -> {
            String pep = a.getCvTermName();
            if (!pepIsoSetMap.containsKey(pep))
                pepIsoSetMap.put(pep, new TreeSet<String>());
            a.getTargetingIsoformsMap().values().forEach(i -> {
                pepIsoSetMap.get(pep).add(i.getIsoformAccession());
            });
        });
    });
    Map<String, PeptideUnicity> pepUnicityMap = new HashMap<>();
    pepIsoSetMap.entrySet().forEach(e -> {
        String pep = e.getKey();
        PeptideUnicity pu = peptideUnicityService.getPeptideUnicityFromMappingIsoforms(e.getValue());
        pepUnicityMap.put(pep, pu);
    });
    return pepUnicityMap;
}
Also used : java.util(java.util) PepXResponse(org.nextprot.api.web.domain.PepXResponse) PepXEntryMatch(org.nextprot.api.web.domain.PepXResponse.PepXEntryMatch) URL(java.net.URL) Annotation(org.nextprot.api.core.domain.annotation.Annotation) NextProtException(org.nextprot.api.commons.exception.NextProtException) Autowired(org.springframework.beans.factory.annotation.Autowired) PeptideUnicity(org.nextprot.api.core.domain.PeptideUnicity) EntryBuilderService(org.nextprot.api.core.service.EntryBuilderService) Value(org.springframework.beans.factory.annotation.Value) AnnotationIsoformSpecificity(org.nextprot.api.core.domain.annotation.AnnotationIsoformSpecificity) AnnotationCategory(org.nextprot.api.commons.constants.AnnotationCategory) EntryConfig(org.nextprot.api.core.service.fluent.EntryConfig) Service(org.springframework.stereotype.Service) URLConnection(java.net.URLConnection) IsoformUtils(org.nextprot.api.core.utils.IsoformUtils) AnnotationVariant(org.nextprot.api.core.domain.annotation.AnnotationVariant) AnnotationProperty(org.nextprot.api.core.domain.annotation.AnnotationProperty) PepXIsoformMatch(org.nextprot.api.web.domain.PepXResponse.PepXIsoformMatch) PeptideUnicityService(org.nextprot.api.core.service.PeptideUnicityService) Entry(org.nextprot.api.core.domain.Entry) PeptideUtils(org.nextprot.api.core.utils.PeptideUtils) IOException(java.io.IOException) PropertyApiModel(org.nextprot.api.commons.constants.PropertyApiModel) InputStreamReader(java.io.InputStreamReader) AnnotationUtils(org.nextprot.api.core.service.annotation.AnnotationUtils) PepXService(org.nextprot.api.web.service.PepXService) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) PepxUtils(org.nextprot.api.web.domain.PepxUtils) BufferedReader(java.io.BufferedReader) Isoform(org.nextprot.api.core.domain.Isoform) PeptideUnicity(org.nextprot.api.core.domain.PeptideUnicity)

Example 13 with Value

use of org.springframework.beans.factory.annotation.Value in project nextprot-api by calipho-sib.

the class InstrumentationAspect method addArgumentsParameters.

private static StringBuilder addArgumentsParameters(StringBuilder sb, Object[] arguments, Annotation[][] annotations) {
    for (int i = 0; i < arguments.length; i++) {
        Annotation[] annots = annotations[i];
        Value v = null;
        for (Annotation a : annots) {
            if (a.annotationType().equals(Value.class)) {
                v = (Value) a;
                break;
            }
        }
        if (v == null) {
            sb.append("arg" + (i + 1));
        } else {
            sb.append(v.value());
        }
        sb.append("=");
        Object argument = arguments[i];
        if (argument == null) {
            sb.append("null");
        } else if (argument instanceof KeyValueRepresentation) {
            sb.append(((KeyValueRepresentation) argument).toKeyValueString());
        } else if (argument instanceof Collection) {
            sb.append(((Collection<?>) argument).size());
        } else if (argument instanceof String || argument instanceof Long || argument instanceof Short || argument instanceof Integer) {
            sb.append(argument);
        } else {
            sb.append("representation-unknown");
        }
        sb.append(";");
    }
    return sb;
}
Also used : Value(org.springframework.beans.factory.annotation.Value) AtomicLong(java.util.concurrent.atomic.AtomicLong) Collection(java.util.Collection) KeyValueRepresentation(org.nextprot.api.commons.utils.KeyValueRepresentation) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Annotation(java.lang.annotation.Annotation)

Example 14 with Value

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

the class CsarFileRepository method setRootPath.

@Required
@Value("${directories.alien}/${directories.csar_repository}")
public void setRootPath(String path) {
    this.rootPath = Paths.get(path).toAbsolutePath();
    if (!Files.isDirectory(rootPath)) {
        try {
            Files.createDirectories(rootPath);
            log.info("Alien Repository folder set to " + rootPath.toAbsolutePath());
        } catch (IOException e) {
            throw new CSARDirectoryCreationFailureException("Error while trying to create the CSAR repository <" + rootPath.toString() + ">. " + e.getMessage(), e);
        }
    } else {
        log.info("Alien Repository folder already created! " + rootPath.toAbsolutePath());
    }
}
Also used : CSARDirectoryCreationFailureException(alien4cloud.component.repository.exception.CSARDirectoryCreationFailureException) IOException(java.io.IOException) Required(org.springframework.beans.factory.annotation.Required) Value(org.springframework.beans.factory.annotation.Value)

Example 15 with Value

use of org.springframework.beans.factory.annotation.Value in project spring-security by spring-projects.

the class OAuth2ResourceServerSpecTests method getWhenUsingCustomAuthenticationManagerInLambdaThenUsesItAccordingly.

@Test
public void getWhenUsingCustomAuthenticationManagerInLambdaThenUsesItAccordingly() {
    this.spring.register(CustomAuthenticationManagerInLambdaConfig.class).autowire();
    ReactiveAuthenticationManager authenticationManager = this.spring.getContext().getBean(ReactiveAuthenticationManager.class);
    given(authenticationManager.authenticate(any(Authentication.class))).willReturn(Mono.error(new OAuth2AuthenticationException(new OAuth2Error("mock-failure"))));
    // @formatter:off
    this.client.get().headers((headers) -> headers.setBearerAuth(this.messageReadToken)).exchange().expectStatus().isUnauthorized().expectHeader().value(HttpHeaders.WWW_AUTHENTICATE, startsWith("Bearer error=\"mock-failure\""));
// @formatter:on
}
Also used : JwtAuthenticationConverter(org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) RSAPublicKey(java.security.interfaces.RSAPublicKey) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BDDMockito.given(org.mockito.BDDMockito.given) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec) MockWebServer(okhttp3.mockwebserver.MockWebServer) ReactiveAuthenticationManager(org.springframework.security.authentication.ReactiveAuthenticationManager) BigInteger(java.math.BigInteger) ReactiveAuthenticationManagerResolver(org.springframework.security.authentication.ReactiveAuthenticationManagerResolver) Jwt(org.springframework.security.oauth2.jwt.Jwt) HttpHeaders(org.apache.http.HttpHeaders) ReactiveJwtDecoder(org.springframework.security.oauth2.jwt.ReactiveJwtDecoder) PostMapping(org.springframework.web.bind.annotation.PostMapping) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MediaType(org.springframework.http.MediaType) OAuth2AuthenticationException(org.springframework.security.oauth2.core.OAuth2AuthenticationException) TestJwts(org.springframework.security.oauth2.jwt.TestJwts) PreDestroy(jakarta.annotation.PreDestroy) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) KeyFactory(java.security.KeyFactory) Test(org.junit.jupiter.api.Test) Base64(java.util.Base64) Stream(java.util.stream.Stream) AbstractAuthenticationToken(org.springframework.security.authentication.AbstractAuthenticationToken) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Optional(java.util.Optional) MockResponse(okhttp3.mockwebserver.MockResponse) Authentication(org.springframework.security.core.Authentication) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ReactiveJwtAuthenticationConverterAdapter(org.springframework.security.oauth2.server.resource.authentication.ReactiveJwtAuthenticationConverterAdapter) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) ReactiveJwtAuthenticationConverter(org.springframework.security.oauth2.server.resource.authentication.ReactiveJwtAuthenticationConverter) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) DispatcherHandler(org.springframework.web.reactive.DispatcherHandler) ServerWebExchange(org.springframework.web.server.ServerWebExchange) Value(org.springframework.beans.factory.annotation.Value) ServerAuthenticationConverter(org.springframework.security.web.server.authentication.ServerAuthenticationConverter) WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) EnableWebFlux(org.springframework.web.reactive.config.EnableWebFlux) Dispatcher(okhttp3.mockwebserver.Dispatcher) BeanCreationException(org.springframework.beans.factory.BeanCreationException) EnableWebFluxSecurity(org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) GetMapping(org.springframework.web.bind.annotation.GetMapping) NoUniqueBeanDefinitionException(org.springframework.beans.factory.NoUniqueBeanDefinitionException) Converter(org.springframework.core.convert.converter.Converter) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) ApplicationContext(org.springframework.context.ApplicationContext) Mockito.verify(org.mockito.Mockito.verify) HttpStatus(org.springframework.http.HttpStatus) SecurityWebFilterChain(org.springframework.security.web.server.SecurityWebFilterChain) HttpStatusServerEntryPoint(org.springframework.security.web.server.authentication.HttpStatusServerEntryPoint) SpringTestContext(org.springframework.security.config.test.SpringTestContext) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) HttpStatusServerAccessDeniedHandler(org.springframework.security.web.server.authorization.HttpStatusServerAccessDeniedHandler) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) SpringTestContextExtension(org.springframework.security.config.test.SpringTestContextExtension) OAuth2Error(org.springframework.security.oauth2.core.OAuth2Error) Bean(org.springframework.context.annotation.Bean) BearerTokenAuthenticationToken(org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ReactiveAuthenticationManager(org.springframework.security.authentication.ReactiveAuthenticationManager) Authentication(org.springframework.security.core.Authentication) OAuth2Error(org.springframework.security.oauth2.core.OAuth2Error) OAuth2AuthenticationException(org.springframework.security.oauth2.core.OAuth2AuthenticationException) Test(org.junit.jupiter.api.Test)

Aggregations

Value (org.springframework.beans.factory.annotation.Value)71 Autowired (org.springframework.beans.factory.annotation.Autowired)33 IOException (java.io.IOException)29 Collectors (java.util.stream.Collectors)29 List (java.util.List)24 Logger (org.slf4j.Logger)23 LoggerFactory (org.slf4j.LoggerFactory)23 PathVariable (org.springframework.web.bind.annotation.PathVariable)20 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)20 ArrayList (java.util.ArrayList)18 RequestParam (org.springframework.web.bind.annotation.RequestParam)18 Map (java.util.Map)17 Optional (java.util.Optional)17 HttpServletResponse (javax.servlet.http.HttpServletResponse)16 RestController (org.springframework.web.bind.annotation.RestController)16 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)15 Stream (java.util.stream.Stream)14 HttpStatus (org.springframework.http.HttpStatus)14 ApiOperation (io.swagger.annotations.ApiOperation)13 ApiParam (io.swagger.annotations.ApiParam)12