List of usage examples for org.apache.commons.collections4 CollectionUtils isNotEmpty
public static boolean isNotEmpty(final Collection<?> coll)
From source file:org.blocks4j.feature.toggle.proxy.Feature.java
private boolean isFeatureOnFeatureList() { return CollectionUtils.isNotEmpty(this.config.getEnabledFeatures()) && this.config.getEnabledFeatures().contains(this.featureName); }
From source file:org.blocks4j.reconf.client.check.ObserverThread.java
@Override public void run() { while (true) { try {/* www . j a v a 2s.c o m*/ TimeUnit.MINUTES.sleep(1); LoggerHolder.getLog().debug(msg.format("start", getName())); List<ObservableThread> threads = new ArrayList<ObservableThread>(toWatch); List<ObservableThread> toRemove = new ArrayList<ObservableThread>(); List<ObservableThread> toAdd = new ArrayList<ObservableThread>(); for (ObservableThread thread : threads) { if (System.currentTimeMillis() - thread.getLastExecution() > (1.5F * thread.getReloadTimeUnit().toMillis(thread.getReloadRate()))) { LoggerHolder.getLog().error(msg.format("not.running", getName(), thread.getName())); toRemove.add(thread); toAdd.add((ObservableThread) thread.clone()); } } for (ObservableThread rem : toRemove) { toWatch.remove(rem); rem.stopIt(); if (CollectionUtils.isNotEmpty(rem.getChildren())) { for (ObservableThread child : rem.getChildren()) { toWatch.remove(child); } } } for (ObservableThread add : toAdd) { LoggerHolder.getLog().info(msg.format("thread.starting", getName(), add.getName())); toWatch.add(add); add.start(); LoggerHolder.getLog().info(msg.format("thread.running", getName(), add.getName())); } } catch (Throwable t) { LoggerHolder.getLog().error(msg.format("error", getName(), ExceptionUtils.getStackTrace(t))); } } }
From source file:org.broadleafcommerce.common.resource.service.ResourceBundlingServiceImpl.java
@Override public String resolveBundleResourceName(String requestedBundleName, String mappingPrefix, List<String> files) { ResourceHttpRequestHandler resourceRequestHandler = findResourceHttpRequestHandler(requestedBundleName); if (resourceRequestHandler != null && CollectionUtils.isNotEmpty(files)) { ResourceResolverChain resolverChain = new BroadleafDefaultResourceResolverChain( resourceRequestHandler.getResourceResolvers()); List<Resource> locations = resourceRequestHandler.getLocations(); StringBuilder combinedPathString = new StringBuilder(); List<String> filePaths = new ArrayList<String>(); for (String file : files) { String resourcePath = resolverChain.resolveUrlPath(file, locations); if (resourcePath == null) { // can't find the exact name specified in the bundle, try it with the mappingPrefix resourcePath = resolverChain.resolveUrlPath(mappingPrefix + file, locations); }// w w w.j av a 2 s . c o m if (resourcePath != null) { filePaths.add(resourcePath); combinedPathString.append(resourcePath); } else { LOG.warn(new StringBuilder().append("Could not resolve resource path specified in bundle as [") .append(file).append("] or as [").append(mappingPrefix + file) .append("]. Skipping file.").toString()); } } int version = Math.abs(combinedPathString.toString().hashCode()); String versionedBundleName = mappingPrefix + addVersion(requestedBundleName, "-" + String.valueOf(version)); createBundleIfNeeded(versionedBundleName, filePaths, resolverChain, locations); return versionedBundleName; } else { if (LOG.isWarnEnabled()) { LOG.warn(""); } return null; } }
From source file:org.broadleafcommerce.core.search.domain.FieldEntity.java
public List<String> getAllLookupTypes() { if (CollectionUtils.isNotEmpty(getAdditionalLookupTypes())) { List<String> result = new ArrayList<>(getAdditionalLookupTypes()); result.add(getType());/*from ww w. j a v a 2 s. c om*/ return Collections.unmodifiableList(result); } else { return Arrays.asList(getType()); } }
From source file:org.broadleafcommerce.core.web.api.wrapper.BaseWrapper.java
/** * Used method, to be used by Wrappers that implement the WrapperAdditionalFields interface. * Transfers the additional fields from the wrapper into the domain object * @param model//from w w w. j a v a2 s . c o m * @param me */ public void transferAdditionalFieldsFromWrapper(WrapperAdditionalFields from, AdditionalFields to) { Map<String, String> destination = new HashMap<String, String>(); if (CollectionUtils.isNotEmpty(from.getAdditionalFields())) { for (MapElementWrapper elem : from.getAdditionalFields()) { destination.put(elem.key, elem.value); } } to.setAdditionalFields(destination); }
From source file:org.codice.ddf.commands.solr.SolrCommands.java
protected static boolean collectionExists(SolrClient client, String collection) throws IOException, SolrServerException { CollectionAdminResponse response = new CollectionAdminRequest.List().process(client); if (response.getResponse() == null) { return false; }//from w w w . j a v a 2 s .c o m List<String> existingCollections = (List<String>) response.getResponse().get("collections"); if (CollectionUtils.isNotEmpty(existingCollections)) { return existingCollections.contains(collection); } return false; }
From source file:org.codice.ddf.opensearch.endpoint.OpenSearchEndpoint.java
/** * Executes the OpenSearchQuery and formulates the response * * @param format - of the results in the response * @param query - the query to execute/*from w w w. j av a 2s . c o m*/ * @param ui -the ui information to use to format the results * @return the response on the query */ private Response executeQuery(String format, OpenSearchQuery query, UriInfo ui, Map<String, Serializable> properties) { Response response = null; String queryFormat = format; MultivaluedMap<String, String> queryParams = ui.getQueryParameters(); List<String> subscriptionList = queryParams.get(Constants.SUBSCRIPTION_KEY); LOGGER.trace("Attempting to execute query: {}", query); try { Map<String, Serializable> arguments = new HashMap<>(); String organization = framework.getOrganization(); String url = ui.getRequestUri().toString(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("organization: {}", organization); LOGGER.trace("url: {}", url); } arguments.put("organization", organization); arguments.put("url", url); // if subscription is specified, add to arguments as well as update // interval if (CollectionUtils.isNotEmpty(subscriptionList)) { String subscription = subscriptionList.get(0); LOGGER.trace("Subscription: {}", subscription); arguments.put(Constants.SUBSCRIPTION_KEY, subscription); List<String> intervalList = queryParams.get(UPDATE_QUERY_INTERVAL); if (CollectionUtils.isNotEmpty(intervalList)) { arguments.put(UPDATE_QUERY_INTERVAL, intervalList.get(0)); } } if (StringUtils.isEmpty(queryFormat)) { queryFormat = DEFAULT_FORMAT; } if (query.getFilter() != null) { QueryRequest queryRequest = new QueryRequestImpl(query, query.isEnterprise(), query.getSiteIds(), properties); QueryResponse queryResponse; LOGGER.trace("Sending query"); queryResponse = framework.query(queryRequest); // pass in the format for the transform BinaryContent content = framework.transform(queryResponse, queryFormat, arguments); response = Response.ok(content.getInputStream(), content.getMimeTypeValue()).build(); } else { // No query was specified QueryRequest queryRequest = new QueryRequestImpl(query, query.isEnterprise(), query.getSiteIds(), null); // Create a dummy QueryResponse with zero results QueryResponseImpl queryResponseQueue = new QueryResponseImpl(queryRequest, new ArrayList<>(), 0); // pass in the format for the transform BinaryContent content = framework.transform(queryResponseQueue, queryFormat, arguments); if (null != content) { response = Response.ok(content.getInputStream(), content.getMimeTypeValue()).build(); } } } catch (UnsupportedQueryException ce) { LOGGER.debug("Unsupported query", ce); response = Response.status(Response.Status.BAD_REQUEST) .entity(wrapStringInPreformattedTags("Unsupported query")).build(); } catch (CatalogTransformerException e) { LOGGER.debug("Error transforming response", e); response = Response.serverError().entity(wrapStringInPreformattedTags("Error transforming response")) .build(); } catch (FederationException e) { LOGGER.debug("Error executing query", e); response = Response.serverError().entity(wrapStringInPreformattedTags("Error executing query")).build(); } catch (SourceUnavailableException e) { LOGGER.debug("Error executing query because the underlying source was unavailable.", e); response = Response.serverError().entity(wrapStringInPreformattedTags( "Error executing query because the underlying source was unavailable.")).build(); } catch (RuntimeException e) { // Account for any runtime exceptions and send back a server error // this prevents full stacktraces returning to the client // this allows for a graceful server error to be returned LOGGER.debug("RuntimeException on executing query", e); response = Response.serverError() .entity(wrapStringInPreformattedTags("RuntimeException on executing query")).build(); } return response; }
From source file:org.codice.ddf.opensearch.endpoint.query.OpenSearchQuery.java
public void addTypeFilter(String type, String versions) { Filter filter;/* w w w .j a v a 2 s .co m*/ Filter typeFilter; if (type.contains("*")) { typeFilter = FILTER_FACTORY.like(FILTER_FACTORY.property(Metacard.CONTENT_TYPE), type); } else { typeFilter = FILTER_FACTORY.equals(FILTER_FACTORY.property(Metacard.CONTENT_TYPE), FILTER_FACTORY.literal(type)); } if (StringUtils.isNotEmpty(versions)) { LOGGER.trace("Received versions from client."); List<Filter> typeVersionPairsFilters = new ArrayList<>(); for (String version : VERSION_PATTERN.split(versions)) { Filter versionFilter; if (version.contains("*")) { versionFilter = FILTER_FACTORY.like(FILTER_FACTORY.property(Metacard.CONTENT_TYPE_VERSION), version); } else { versionFilter = FILTER_FACTORY.equals(FILTER_FACTORY.property(Metacard.CONTENT_TYPE_VERSION), FILTER_FACTORY.literal(version)); } typeVersionPairsFilters.add(FILTER_FACTORY.and(typeFilter, versionFilter)); } if (CollectionUtils.isNotEmpty(typeVersionPairsFilters)) { filter = FILTER_FACTORY.or(typeVersionPairsFilters); } else { filter = typeFilter; } } else { filter = typeFilter; } if (filter != null) { LOGGER.trace("Adding type filter"); filters.add(filter); } }
From source file:org.codice.ddf.opensearch.source.OpenSearchSource.java
@Nullable protected InputTransformer lookupTransformerReference(String namespaceUri) throws InvalidSyntaxException { LOGGER.trace("Looking up Input Transformer by schema : {}", namespaceUri); Bundle bundle = getBundle();//from ww w . j av a 2s . com if (bundle != null) { BundleContext bundleContext = bundle.getBundleContext(); Collection<ServiceReference<InputTransformer>> transformerReferences = bundleContext .getServiceReferences(InputTransformer.class, "(schema=" + namespaceUri + ")"); if (CollectionUtils.isNotEmpty(transformerReferences)) { ServiceReference<InputTransformer> transformer = transformerReferences.iterator().next(); LOGGER.trace("Found Input Transformer {} by schema {}", transformer.getBundle().getSymbolicName(), namespaceUri); return bundleContext.getService(transformer); } LOGGER.trace("Failed to find Input Transformer by schema : {}", namespaceUri); } return null; }
From source file:org.codice.ddf.opensearch.source.OpenSearchSource.java
private List<Metacard> processAdditionalForeignMarkups(Element element, String id) throws UnsupportedQueryException { List<Metacard> metacards = new ArrayList<>(); if (CollectionUtils.isNotEmpty(markUpSet) && markUpSet.contains(element.getName())) { XMLOutputter xmlOutputter = new XMLOutputter(); Metacard metacard = parseContent(xmlOutputter.outputString(element), id); if (metacard != null) { metacards.add(metacard);/*from w w w.ja va2s. c o m*/ } } return metacards; }