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

The following examples show how to use io.micronaut.core.util.StringUtils#isNotEmpty() . 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: SourcePersistentEntity.java    From micronaut-data with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public SourcePersistentProperty getPropertyByName(String name) {
    if (StringUtils.isNotEmpty(name)) {
        final PropertyElement prop = beanProperties.get(name);
        if (prop != null) {
            if (prop.hasStereotype(Relation.class)) {
                if (isEmbedded(prop)) {
                    return new SourceEmbedded(this, prop, entityResolver);
                } else {
                    return new SourceAssociation(this, prop, entityResolver);
                }
            } else {
                return new SourcePersistentProperty(this, prop);
            }
        }
    }
    return null;
}
 
Example 2
Source File: BeanAnnotationMapper.java    From micronaut-spring with Apache License 2.0 6 votes vote down vote up
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    List<AnnotationValue<?>> newAnnotations = new ArrayList<>(3);
    final AnnotationValueBuilder<Bean> beanAnn = AnnotationValue.builder(Bean.class);

    final Optional<String> destroyMethod = annotation.get("destroyMethod", String.class);
    destroyMethod.ifPresent(s -> beanAnn.member("preDestroy", s));
    newAnnotations.add(beanAnn.build());
    newAnnotations.add(AnnotationValue.builder(DefaultScope.class)
            .value(Singleton.class)
            .build());
    final String beanName = annotation.getValue(String.class).orElse(annotation.get("name", String.class).orElse(null));

    if (StringUtils.isNotEmpty(beanName)) {
        newAnnotations.add(AnnotationValue.builder(Named.class).value(beanName).build());
    }

    return newAnnotations;
}
 
Example 3
Source File: PgClientFactory.java    From micronaut-sql with Apache License 2.0 5 votes vote down vote up
/**
 * Create a connection pool to the database configured with the {@link PgClientConfiguration }.
 * @param vertx The Vertx instance.
 * @return A pool of connections.
 */
private PgPool createClient(Vertx vertx) {
    PgClientConfiguration configuration = this.connectionConfiguration;
    String connectionUri = configuration.getUri();
    if (StringUtils.isNotEmpty(connectionUri)) {
        return PgPool.pool(vertx, connectionUri, configuration.poolOptions);
    } else {
        return PgPool.pool(vertx, configuration.connectOptions, configuration.poolOptions);
    }
}
 
Example 4
Source File: KafkaConsumerProcessor.java    From micronaut-kafka with Apache License 2.0 5 votes vote down vote up
@Override
public void pause(@Nonnull String id) {
    if (StringUtils.isNotEmpty(id) && consumers.containsKey(id)) {
        paused.add(id);
    } else {
        throw new IllegalArgumentException("No consumer found for ID: " + id);
    }
}
 
Example 5
Source File: AbstractSqlLikeQueryBuilder.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
private String buildAdditionalWhereString(PersistentEntity entity, AnnotationMetadata annotationMetadata) {
    final String whereStr = resolveWhereForAnnotationMetadata(annotationMetadata);
    if (StringUtils.isNotEmpty(whereStr)) {
        return whereStr;
    } else {
        return resolveWhereForAnnotationMetadata(entity.getAnnotationMetadata());
    }
}
 
Example 6
Source File: AbstractKafkaStreamsConfiguration.java    From micronaut-kafka with Apache License 2.0 5 votes vote down vote up
/**
 * Shared initialization.
 *
 * @param applicationConfiguration The application config
 * @param environment The env
 * @param config The config to be initialized
 */
protected void init(ApplicationConfiguration applicationConfiguration, Environment environment, Properties config) {
    // set the default application id
    String applicationName = applicationConfiguration.getName().orElse(Environment.DEFAULT_NAME);
    config.putIfAbsent(StreamsConfig.APPLICATION_ID_CONFIG, applicationName);

    if (environment.getActiveNames().contains(Environment.TEST)) {
        String tmpDir = System.getProperty("java.io.tmpdir");
        if (StringUtils.isNotEmpty(tmpDir)) {
            if (new File(tmpDir, applicationName).mkdirs()) {
                config.putIfAbsent(StreamsConfig.STATE_DIR_CONFIG, tmpDir);
            }
        }
    }
}
 
Example 7
Source File: MySQLClientFactory.java    From micronaut-sql with Apache License 2.0 5 votes vote down vote up
/**
 * Create a connection pool to the database configured with the
 * {@link MySQLClientConfiguration}.
 * @return A pool of connections.
 */
private MySQLPool createClient() {
    MySQLClientConfiguration configuration = this.connectionConfiguration;
    String connectionUri = configuration.getUri();
    if (StringUtils.isNotEmpty(connectionUri)) {
        return MySQLPool.pool(connectionUri, configuration.poolOptions);
    } else {
        return MySQLPool.pool(configuration.connectOptions, configuration.poolOptions);
    }
}
 
Example 8
Source File: JdbcDatabaseManager.java    From micronaut-sql with Apache License 2.0 5 votes vote down vote up
/**
 * Searches defined database where the URL prefix matches one of the prefixes defined in a {@link JdbcDatabase}.
 * The prefix is determined by:
 * <p>
 * jdbc:<prefix>:...
 *
 * @param jdbcUrl The connection URL
 * @return An optional {@link JdbcDatabase}
 */
@SuppressWarnings("MagicNumber")
public static Optional<JdbcDatabase> findDatabase(String jdbcUrl) {
    if (StringUtils.isNotEmpty(jdbcUrl)) {
        if (!jdbcUrl.startsWith("jdbc")) {
            throw new IllegalArgumentException("Invalid JDBC URL [" + jdbcUrl + "]. JDBC URLs must start with 'jdbc'.");
        }
        String partialUrl = jdbcUrl.substring(5);
        String prefix = partialUrl.substring(0, partialUrl.indexOf(':')).toLowerCase();

        return databases.stream().filter(db -> db.containsPrefix(prefix)).findFirst();
    }
    return Optional.empty();
}
 
Example 9
Source File: PgClientFactory.java    From micronaut-sql with Apache License 2.0 5 votes vote down vote up
/**
 * Create a connection pool to the database configured with the
 * {@link PgClientConfiguration}.
 * @return A pool of connections.
 */
private PgPool createClient() {
    PgClientConfiguration configuration = this.connectionConfiguration;
    String connectionUri = configuration.getUri();
    if (StringUtils.isNotEmpty(connectionUri)) {
        return PgPool.pool(connectionUri, configuration.poolOptions);
    } else {
        return PgPool.pool(configuration.connectOptions, configuration.poolOptions);
    }
}
 
Example 10
Source File: WebBindAnnotationMapper.java    From micronaut-spring with Apache License 2.0 5 votes vote down vote up
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    List<AnnotationValue<?>> mappedAnnotations = new ArrayList<>();

    final String name = annotation.getValue(String.class).orElseGet(() -> annotation.get("name", String.class).orElse(null));
    final String defaultValue = annotation.get("defaultValue", String.class).orElse(null);
    final boolean required = annotation.get("required", boolean.class).orElse(true);

    final AnnotationValueBuilder<?> builder = AnnotationValue.builder(annotationType());
    final AnnotationValueBuilder<Bindable> bindableBuilder = AnnotationValue.builder(Bindable.class);
    if (StringUtils.isNotEmpty(name)) {
        builder.value(name);
        bindableBuilder.value(name);
    }
    if (StringUtils.isNotEmpty(defaultValue)) {
        builder.member("defaultValue", name);
        bindableBuilder.member("defaultValue", defaultValue);
    }

    mappedAnnotations.add(builder.build());
    mappedAnnotations.add(bindableBuilder.build());
    if (!required) {
        mappedAnnotations.add(AnnotationValue.builder(Nullable.class).build());
    }

    return mappedAnnotations;
}
 
Example 11
Source File: DeleteByMethod.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean hasQueryAnnotation(@NonNull MethodElement methodElement) {
    final String str = methodElement.stringValue(Query.class).orElse(null);
    if (StringUtils.isNotEmpty(str)) {
        return str.trim().toLowerCase(Locale.ENGLISH).startsWith("delete");
    }
    return false;
}
 
Example 12
Source File: MicronautAwsProxyResponse.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public String get(CharSequence name) {
    if (StringUtils.isNotEmpty(name)) {
        return multiValueHeaders.getFirst(name.toString());
    }
    return null;
}
 
Example 13
Source File: MicronautAwsProxyRequest.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public String get(CharSequence name) {
    if (StringUtils.isNotEmpty(name)) {
        return multiValueHeaders.getFirst(name.toString());
    }
    return null;
}
 
Example 14
Source File: DataConfiguration.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
/**
 * @param pageParameterName Sets the default page parameter name
 */
public void setPageParameterName(String pageParameterName) {
    if (StringUtils.isNotEmpty(sizeParameterName)) {
        this.pageParameterName = pageParameterName;
    }
}
 
Example 15
Source File: DataConfiguration.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
/**
 * @param sortParameterName The default sort parameter name
 */
public void setSortParameterName(String sortParameterName) {
    if (StringUtils.isNotEmpty(sortParameterName)) {
        this.sortParameterName = sortParameterName;
    }
}
 
Example 16
Source File: DataConfiguration.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
/**
 * @param sortDelimiter The delimiter to use to calculate sort order. Defaults to {@code ,}.
 */
public void setSortDelimiter(String sortDelimiter) {
    if (StringUtils.isNotEmpty(sortDelimiter)) {
        this.sortDelimiter = Pattern.compile(Pattern.quote(sortDelimiter));
    }
}
 
Example 17
Source File: KafkaMetricMeterTypeBuilder.java    From micronaut-kafka with Apache License 2.0 4 votes vote down vote up
private boolean isValid() {
    return tagFunction != null &&
            meterRegistry != null &&
            kafkaMetric != null &&
            StringUtils.isNotEmpty(prefix);
}
 
Example 18
Source File: RepositoryTypeElementVisitor.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
@Override
public void visitClass(ClassElement element, VisitorContext context) {
    String interfaceName = element.getName();
    if (failing) {
        return;
    }
    if (visitedRepositories.contains(interfaceName)) {
        // prevent duplicate visits
        currentRepository = null;
        currentClass = null;
        return;
    }
    this.currentClass = element;

    if (element.hasDeclaredStereotype(Repository.class)) {
        visitedRepositories.add(interfaceName);
        currentRepository = element;
        queryEncoder = QueryBuilder.newQueryBuilder(element.getAnnotationMetadata());
        this.dataTypes = MappedEntityVisitor.getConfiguredDataTypes(currentRepository);
        AnnotationMetadata annotationMetadata = element.getAnnotationMetadata();
        List<AnnotationValue<TypeRole>> roleArray = annotationMetadata
                .findAnnotation(RepositoryConfiguration.class)
                .map(av -> av.getAnnotations("typeRoles", TypeRole.class))
                .orElse(Collections.emptyList());
        for (AnnotationValue<TypeRole> parameterRole : roleArray) {
            String role = parameterRole.stringValue("role").orElse(null);
            AnnotationClassValue cv = parameterRole.get("type", AnnotationClassValue.class).orElse(null);
            if (StringUtils.isNotEmpty(role) && cv != null) {
                context.getClassElement(cv.getName()).ifPresent(ce ->
                        typeRoles.put(ce.getName(), role)
                );
            }
        }
        if (element.isAssignable(SPRING_REPO)) {
            context.getClassElement("org.springframework.data.domain.Pageable").ifPresent(ce ->
                    typeRoles.put(ce.getName(), TypeRole.PAGEABLE)
            );
            context.getClassElement("org.springframework.data.domain.Page").ifPresent(ce ->
                    typeRoles.put(ce.getName(), TypeRole.PAGE)
            );
            context.getClassElement("org.springframework.data.domain.Slice").ifPresent(ce ->
                    typeRoles.put(ce.getName(), TypeRole.SLICE)
            );
            context.getClassElement("org.springframework.data.domain.Sort").ifPresent(ce ->
                    typeRoles.put(ce.getName(), TypeRole.SORT)
            );
        }
        if (queryEncoder == null) {
            context.fail("QueryEncoder not present on annotation processor path", element);
            failing = true;
        }
    }

}
 
Example 19
Source File: AgentRef.java    From micronaut-microservices-poc with Apache License 2.0 4 votes vote down vote up
public static AgentRef of(String login) {
    if (StringUtils.isNotEmpty(login))
        return new AgentRef(login);

    return null;
}
 
Example 20
Source File: DataConfiguration.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
/**
 * @param sizeParameterName The default size parameter name
 */
public void setSizeParameterName(String sizeParameterName) {
    if (StringUtils.isNotEmpty(sizeParameterName)) {
        this.sizeParameterName = sizeParameterName;
    }
}