Example usage for org.apache.commons.collections4 CollectionUtils isNotEmpty

List of usage examples for org.apache.commons.collections4 CollectionUtils isNotEmpty

Introduction

In this page you can find the example usage for org.apache.commons.collections4 CollectionUtils isNotEmpty.

Prototype

public static boolean isNotEmpty(final Collection<?> coll) 

Source Link

Document

Null-safe check if the specified collection is not empty.

Usage

From source file:cop.maven.plugins.RamlMojo.java

@NotNull
@Override/*from  ww w . j  a va  2 s.  c o m*/
protected Set<String> getClasspathElements() {
    Set<String> elements = new LinkedHashSet<>();
    List<Resource> resources = (List<Resource>) project.getResources();

    if (CollectionUtils.isNotEmpty(resources))
        elements.addAll(resources.stream().map(FileSet::getDirectory).collect(Collectors.toList()));

    elements.addAll(classpathElements);

    return elements;
}

From source file:com.jkoolcloud.tnt4j.streams.filters.AbstractActivityFilter.java

/**
 * Performs filter initialization: resolves expression variables.
 *///from   ww  w . ja v  a2  s . c om
@Override
protected void initFilter() {
    exprVars = new HashSet<>();
    placeHoldersMap = new HashMap<>();
    Utils.resolveExpressionVariables(exprVars, getExpression());

    String expString = super.getExpression();
    if (CollectionUtils.isNotEmpty(exprVars)) {
        String varPlh;
        int idx = 0;
        for (String eVar : exprVars) {
            varPlh = "$TNT4J_ST_FLTR_PLH" + (idx++); // NON-NLS
            expString = expString.replace(eVar, varPlh);
            placeHoldersMap.put(eVar, varPlh);
        }
    }

    ppExpression = expString;
}

From source file:com.jkoolcloud.tnt4j.streams.filters.XPathActivityExpressionFilter.java

@Override
public boolean doFilter(ActivityInfo activityInfo) throws FilterException {
    if (activityInfo == null) {
        return false;
    }/*  w ww  .  ja  v a  2 s  . co m*/

    Map<String, Object> valuesMap = new HashMap<>();

    if (CollectionUtils.isNotEmpty(exprVars)) {
        Object fValue;
        String fieldName;
        for (String eVar : exprVars) {
            fieldName = eVar.substring(2, eVar.length() - 1);
            fValue = activityInfo.getFieldValue(fieldName);
            fieldName = placeHoldersMap.get(eVar);
            valuesMap.put(StringUtils.isEmpty(fieldName) ? eVar : fieldName, fValue);
        }
    }

    XPath xPath = StreamsXMLUtils.getStreamsXPath();
    xPath.setXPathVariableResolver(new XPathActivityExpressionFilter.StreamsVariableResolver(valuesMap));

    try {
        boolean match = "true".equals(xPath.evaluate(getExpression(), (Object) null)); // NON-NLS

        boolean filteredOut = isFilteredOut(getHandleType(), match);
        activityInfo.setFiltered(filteredOut);

        return filteredOut;
    } catch (Exception exc) {
        throw new FilterException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ExpressionFilter.filtering.failed", filterExpression), exc);
    }
}

From source file:com.mirth.connect.server.api.servlets.ChannelServlet.java

@Override
@DontCheckAuthorized/*from  w  ww .  j  av a2 s.  c o m*/
public List<Channel> getChannels(Set<String> channelIds, boolean pollingOnly) {
    if (CollectionUtils.isNotEmpty(channelIds)) {
        parameterMap.put("channelIds", channelIds);
    }
    if (!isUserAuthorized()) {
        return new ArrayList<Channel>();
    }

    List<Channel> channels;
    if (CollectionUtils.isEmpty(channelIds)) {
        channels = redactChannels(channelController.getChannels(null));
    } else {
        channels = channelController.getChannels(redactChannelIds(channelIds));
    }

    if (pollingOnly) {
        retainPollingChannels(channels);
    }

    return channels;
}

From source file:com.baifendian.swordfish.dao.AdHocDao.java

/**
 * ?//from   w  ww .  j a v  a2s  .  c o  m
 *
 * @param execId
 * @param execSqls
 */
@Transactional(value = "TransactionManager")
public void initAdHocResult(int execId, List<String> execSqls) {
    if (CollectionUtils.isNotEmpty(execSqls)) {
        adHocResultMapper.delete(execId);

        int index = 0;

        for (String stm : execSqls) {
            AdHocResult adHocResult = new AdHocResult();
            adHocResult.setExecId(execId);
            adHocResult.setStm(stm);
            adHocResult.setIndex(index);
            adHocResult.setStatus(FlowStatus.INIT);
            adHocResult.setCreateTime(new Date());

            ++index;

            adHocResultMapper.insert(adHocResult);
        }
    }
}

From source file:de.alpharogroup.user.rest.BaseAuthenticationsRestResource.java

/**
 * {@inheritDoc}//from ww w . j a  va 2  s  . c  o  m
 */
@Override
public Response authenticate(final String username, final String password) {
    final AuthenticationResult<User, AuthenticationErrors> result = baseAuthenticationService
            .authenticate(username, password);
    if (CollectionUtils.isNotEmpty(result.getValidationErrors())) {
        return Response.status(Response.Status.UNAUTHORIZED).header("Access-Control-Allow-Origin", "*")// allow cors...
                .build();
    }
    final String authenticationToken = baseAuthenticationService.newAuthenticationToken(username);
    final AuthToken authToken = AuthToken.builder().value(authenticationToken).build();
    // Set the auth token in the response
    return Response.ok(authToken.getValue()).header("Access-Control-Allow-Origin", "*")// allow
            // cors...
            .build();
}

From source file:co.runrightfast.vertx.orientdb.ODatabaseDocumentTxHealthCheck.java

@Override
protected Result check() throws Exception {
    try (final ODatabaseDocumentTx db = oDatabaseDocumentTxSupplier.get()) {
        final JsonObjectBuilder msgBuilder = Json.createObjectBuilder().add("db", getDatabaseInfo(db));
        if (CollectionUtils.isNotEmpty(documentObjects)) {
            final JsonObjectBuilder counts = Json.createObjectBuilder();
            documentObjects.stream().forEach(documentObject -> browseClass(db, documentObject, counts));
            msgBuilder.add("counts", counts);
        }// www.  j  a  v  a  2 s  .  c o m

        final JsonObject msg = msgBuilder.build();
        if (isHealthy(msg)) {
            return HealthCheck.Result.healthy(msg.toString());
        }
        return HealthCheck.Result.unhealthy(msg.toString());
    } catch (final Exception e) {
        final JsonObjectBuilder msg = Json.createObjectBuilder().add("db",
                Json.createObjectBuilder().add("name", databaseName).build());
        return HealthCheck.Result
                .unhealthy(new ODatabaseDocumentTxHealthCheckException(msg.build().toString(), e));
    }
}

From source file:com.mirth.connect.model.MetaData.java

public List<ApiProvider> getApiProviders(Version version) {
    List<ApiProvider> list = new ArrayList<ApiProvider>();

    if (CollectionUtils.isNotEmpty(apiProviders)) {
        for (ApiProvider provider : apiProviders) {
            boolean valid = true;
            Version minVersion = Version.fromString(provider.getMinVersion());
            Version maxVersion = Version.fromString(provider.getMaxVersion());

            if (minVersion != null && minVersion.ordinal() > version.ordinal()) {
                valid = false;/*from   www  .java2s.  co m*/
            }
            if (maxVersion != null && maxVersion.ordinal() < version.ordinal()) {
                valid = false;
            }

            if (valid) {
                list.add(provider);
            }
        }
    }

    return list;
}

From source file:io.github.swagger2markup.internal.utils.ParameterAdapter.java

/**
 * Retrieves the type of a parameter, or otherwise null
 *
 * @param definitionDocumentResolver the defintion document resolver
 * @return the type of the parameter, or otherwise null
 *///  ww  w  .j a  va  2s  .  c  o m
public Type getType(Map<String, Model> definitions, DocumentResolver definitionDocumentResolver) {
    Validate.notNull(parameter, "parameter must not be null!");
    Type type = null;

    if (parameter instanceof BodyParameter) {
        BodyParameter bodyParameter = (BodyParameter) parameter;
        Model model = bodyParameter.getSchema();

        if (model != null) {
            type = ModelUtils.getType(model, definitions, definitionDocumentResolver);
        } else {
            type = new BasicType("string", null);
        }

    } else if (parameter instanceof AbstractSerializableParameter) {
        AbstractSerializableParameter serializableParameter = (AbstractSerializableParameter) parameter;
        @SuppressWarnings("unchecked")
        List<String> enums = serializableParameter.getEnum();

        if (CollectionUtils.isNotEmpty(enums)) {
            type = new EnumType(null, enums);
        } else {
            type = new BasicType(serializableParameter.getType(), null, serializableParameter.getFormat());
        }
        if (serializableParameter.getType().equals("array")) {
            String collectionFormat = serializableParameter.getCollectionFormat();

            type = new ArrayType(null,
                    new PropertyAdapter(serializableParameter.getItems()).getType(definitionDocumentResolver),
                    collectionFormat);
        }
    } else if (parameter instanceof RefParameter) {
        String refName = ((RefParameter) parameter).getSimpleRef();

        type = new RefType(definitionDocumentResolver.apply(refName),
                new ObjectType(refName, null /* FIXME, not used for now */));
    }
    return type;
}

From source file:com.mirth.connect.plugins.httpauth.oauth2.OAuth2Authenticator.java

@Override
public AuthenticationResult authenticate(RequestInfo request) throws Exception {
    OAuth2HttpAuthProperties properties = getReplacedProperties(request);

    CloseableHttpClient client = null;//from   ww  w .  j  ava  2s .  co  m
    CloseableHttpResponse response = null;

    try {
        // Create and configure the client and context 
        RegistryBuilder<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
                .<ConnectionSocketFactory>create()
                .register("http", PlainConnectionSocketFactory.getSocketFactory());
        ConnectorPluginProperties pluginProperties = null;
        if (CollectionUtils.isNotEmpty(properties.getConnectorPluginProperties())) {
            pluginProperties = properties.getConnectorPluginProperties().iterator().next();
        }
        provider.getHttpConfiguration().configureSocketFactoryRegistry(pluginProperties, socketFactoryRegistry);
        BasicHttpClientConnectionManager httpClientConnectionManager = new BasicHttpClientConnectionManager(
                socketFactoryRegistry.build());
        httpClientConnectionManager.setSocketConfig(SocketConfig.custom().setSoTimeout(SOCKET_TIMEOUT).build());
        HttpClientBuilder clientBuilder = HttpClients.custom()
                .setConnectionManager(httpClientConnectionManager);
        HttpUtil.configureClientBuilder(clientBuilder);
        client = clientBuilder.build();

        HttpClientContext context = HttpClientContext.create();
        RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(SOCKET_TIMEOUT)
                .setSocketTimeout(SOCKET_TIMEOUT).setStaleConnectionCheckEnabled(true).build();
        context.setRequestConfig(requestConfig);

        URIBuilder uriBuilder = new URIBuilder(properties.getVerificationURL());

        // Add query parameters
        if (properties.getTokenLocation() == TokenLocation.QUERY) {
            List<String> paramList = request.getQueryParameters().get(properties.getLocationKey());
            if (CollectionUtils.isNotEmpty(paramList)) {
                for (String value : paramList) {
                    uriBuilder.addParameter(properties.getLocationKey(), value);
                }
            }
        }

        // Build the final URI and create a GET request
        HttpGet httpGet = new HttpGet(uriBuilder.build());

        // Add headers
        if (properties.getTokenLocation() == TokenLocation.HEADER) {
            List<String> headerList = request.getHeaders().get(properties.getLocationKey());
            if (CollectionUtils.isNotEmpty(headerList)) {
                for (String value : headerList) {
                    httpGet.addHeader(properties.getLocationKey(), value);
                }
            }
        }

        // Execute the request
        response = client.execute(httpGet, context);

        // Determine authentication from the status code 
        if (response.getStatusLine().getStatusCode() < 400) {
            return AuthenticationResult.Success();
        } else {
            return AuthenticationResult.Failure();
        }
    } finally {
        HttpClientUtils.closeQuietly(response);
        HttpClientUtils.closeQuietly(client);
    }
}