Java Code Examples for io.micronaut.core.util.StringUtils#isEmpty()

The following examples show how to use io.micronaut.core.util.StringUtils#isEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProjectionMethodExpression.java    From micronaut-data with Apache License 2.0 6 votes vote down vote up
@Override
protected ProjectionMethodExpression initProjection(@NonNull MethodMatchContext matchContext, String remaining) {
    if (StringUtils.isEmpty(remaining)) {
        this.expectedType = matchContext.getRootEntity().getType();
        return this;
    } else {
        this.property = NameUtils.decapitalize(remaining);
        SourcePersistentProperty pp = matchContext.getRootEntity().getPropertyByName(property);
        if (pp == null || pp.getType() == null) {
            matchContext.fail("Cannot project on non-existent property " + property);
            return null;
        }
        this.expectedType = pp.getType();
        return this;
    }
}
 
Example 2
Source File: ProjectionMethodExpression.java    From micronaut-data with Apache License 2.0 6 votes vote down vote up
@Override
protected ProjectionMethodExpression initProjection(@NonNull MethodMatchContext matchContext, String remaining) {
    if (StringUtils.isEmpty(remaining)) {
        matchContext.fail(getClass().getSimpleName() + " projection requires a property name");
        return null;
    } else {

        this.property = NameUtils.decapitalize(remaining);
        this.persistentProperty = (SourcePersistentProperty) matchContext.getRootEntity().getPropertyByPath(property).orElse(null);
        if (persistentProperty == null || persistentProperty.getType() == null) {
            matchContext.fail("Cannot project on non-existent property " + property);
            return null;
        }
        this.expectedType = resolveExpectedType(matchContext, persistentProperty.getType());
        return this;
    }
}
 
Example 3
Source File: GraphQLWsMessageHandler.java    From micronaut-graphql with Apache License 2.0 6 votes vote down vote up
private Publisher<GraphQLWsResponse> startOperation(GraphQLWsRequest request, WebSocketSession session) {
    if (request.getId() == null) {
        LOG.warn("GraphQL operation id is required with type start");
        return Flowable.just(new GraphQLWsResponse(GQL_ERROR));
    }

    if (state.operationExists(request, session)) {
        LOG.info("Already subscribed to operation {} in session {}", request.getId(), session.getId());
        return Flowable.empty();
    }

    GraphQLRequestBody payload = request.getPayload();
    if (payload == null || StringUtils.isEmpty(payload.getQuery())) {
        LOG.info("Payload was null or query empty for operation {} in session {}", request.getId(),
                 session.getId());
        return Flowable.just(new GraphQLWsResponse(GQL_ERROR, request.getId()));
    }

    return executeRequest(request.getId(), payload, session);
}
 
Example 4
Source File: AbstractMicronautLambdaRuntime.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
private URL lookupRuntimeApiEndpoint() throws MalformedURLException {
    final String runtimeApiEndpoint = getEnv(ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_RUNTIME_API);
    if (StringUtils.isEmpty(runtimeApiEndpoint)) {
        throw new IllegalStateException("Missing " + ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_RUNTIME_API + " environment variable. Custom runtime can only be run within AWS Lambda environment.");
    }
    return new URL("http://" + runtimeApiEndpoint);
}
 
Example 5
Source File: GrpcChannelScope.java    From micronaut-grpc with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T get(
        BeanResolutionContext resolutionContext,
        BeanDefinition<T> beanDefinition,
        BeanIdentifier identifier,
        Provider<T> provider) {
    BeanResolutionContext.Segment segment = resolutionContext.getPath().currentSegment().orElseThrow(() ->
            new IllegalStateException("@GrpcChannel used in invalid location")
    );
    Argument argument = segment.getArgument();
    String value = argument.getAnnotationMetadata().getValue(GrpcChannel.class, String.class).orElse(null);
    if (StringUtils.isEmpty(value)) {
        throw new DependencyInjectionException(resolutionContext, argument, "No value specified to @GrpcChannel annotation");
    }
    if (!Channel.class.isAssignableFrom(argument.getType())) {
        throw new DependencyInjectionException(resolutionContext, argument, "@GrpcChannel used on type that is not a Channel");
    }

    if ("grpc-server".equalsIgnoreCase(value)) {
        return (T) applicationContext.getBean(ManagedChannel.class, Qualifiers.byName("grpc-server"));
    }

    if (!(provider instanceof ParametrizedProvider)) {
        throw new DependencyInjectionException(resolutionContext, argument, "GrpcChannelScope called with invalid bean provider");
    }
    value = applicationContext.resolveRequiredPlaceholders(value);
    String finalValue = value;
    return (T) channels.computeIfAbsent(new ChannelKey(identifier, value), channelKey ->
            (ManagedChannel) ((ParametrizedProvider<T>) provider).get(finalValue)
    );
}
 
Example 6
Source File: KafkaMetricMeterTypeBuilder.java    From micronaut-kafka with Apache License 2.0 5 votes vote down vote up
/**
 * Build and register a typed meter.
 *
 * @return Optional type of {@link Meter}
 */
public Optional<Meter> build() {
    if (!isValid()) {
        return Optional.empty();
    }

    if (StringUtils.isEmpty(name)) {
        name = kafkaMetric.metricName().name();
    }

    KafkaMetricMeterType kafkaMetricMeterType = kafkaMetricMeterTypeRegistry.lookup(this.name);

    if (kafkaMetricMeterType.getMeterType() == MeterType.GAUGE && this.kafkaMetric.metricValue() instanceof Double) {
        return Optional.of(Gauge.builder(getMetricName(), () -> (Double) kafkaMetric.metricValue())
                .tags(tagFunction.apply(kafkaMetric.metricName()))
                .description(kafkaMetricMeterType.getDescription())
                .baseUnit(kafkaMetricMeterType.getBaseUnit())
                .register(meterRegistry));
    } else if (kafkaMetricMeterType.getMeterType() == MeterType.FUNCTION_COUNTER && this.kafkaMetric.metricValue() instanceof Double) {
        return Optional.of(FunctionCounter.builder(getMetricName(), kafkaMetric, value -> (Double) value.metricValue())
                .tags(tagFunction.apply(kafkaMetric.metricName()))
                .description(kafkaMetricMeterType.getDescription())
                .baseUnit(kafkaMetricMeterType.getBaseUnit())
                .register(meterRegistry));
    } else if (kafkaMetricMeterType.getMeterType() == MeterType.TIME_GAUGE && this.kafkaMetric.metricValue() instanceof Double) {
        return Optional.of(TimeGauge.builder(getMetricName(), kafkaMetric, kafkaMetricMeterType.getTimeUnit(), value -> (Double) value.metricValue())
                .tags(tagFunction.apply(kafkaMetric.metricName()))
                .description(kafkaMetricMeterType.getDescription())
                .register(meterRegistry));
    }

    return Optional.empty();
}
 
Example 7
Source File: GrpcChannelScope.java    From micronaut-grpc with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T get(
        BeanResolutionContext resolutionContext,
        BeanDefinition<T> beanDefinition,
        BeanIdentifier identifier,
        Provider<T> provider) {
    BeanResolutionContext.Segment segment = resolutionContext.getPath().currentSegment().orElseThrow(() ->
            new IllegalStateException("@GrpcChannel used in invalid location")
    );
    Argument argument = segment.getArgument();
    String value = argument.getAnnotationMetadata().getValue(GrpcChannel.class, String.class).orElse(null);
    if (StringUtils.isEmpty(value)) {
        throw new DependencyInjectionException(resolutionContext, argument, "No value specified to @GrpcChannel annotation");
    }
    if (!Channel.class.isAssignableFrom(argument.getType())) {
        throw new DependencyInjectionException(resolutionContext, argument, "@GrpcChannel used on type that is not a Channel");
    }

    if ("grpc-server".equalsIgnoreCase(value)) {
        return (T) applicationContext.getBean(ManagedChannel.class, Qualifiers.byName("grpc-server"));
    }

    if (!(provider instanceof ParametrizedProvider)) {
        throw new DependencyInjectionException(resolutionContext, argument, "GrpcChannelScope called with invalid bean provider");
    }
    value = applicationContext.resolveRequiredPlaceholders(value);
    String finalValue = value;
    return (T) channels.computeIfAbsent(new ChannelKey(identifier, value), channelKey ->
            (ManagedChannel) ((ParametrizedProvider<T>) provider).get(finalValue)
    );
}
 
Example 8
Source File: TransactionInterceptor.java    From micronaut-spring with Apache License 2.0 5 votes vote down vote up
@Override
public final Object intercept(MethodInvocationContext<Object, Object> context) {
    if (context.hasStereotype(Transactional.class)) {
        String transactionManagerName = context.stringValue(Transactional.class).orElse(null);
        if (StringUtils.isEmpty(transactionManagerName)) {
            transactionManagerName = null;
        }
        PlatformTransactionManager transactionManager = resolveTransactionManager(transactionManagerName);

        String finalTransactionManagerName = transactionManagerName;
        TransactionAttribute transactionDefinition = resolveTransactionAttribute(
            context.getExecutableMethod(),
            context,
            finalTransactionManagerName
        );

        final TransactionInfo transactionInfo = createTransactionIfNecessary(
                transactionManager,
                transactionDefinition,
                context.getDeclaringType().getName() + "." + context.getMethodName());
        Object retVal;
        try {
            retVal = context.proceed();
        } catch (Throwable ex) {
            completeTransactionAfterThrowing(transactionInfo, ex);
            throw ex;
        } finally {
            cleanupTransactionInfo(transactionInfo);
        }
        commitTransactionAfterReturning(transactionInfo);
        return retVal;
    } else {
        return context.proceed();
    }
}