Example usage for org.apache.commons.collections CollectionUtils addAll

List of usage examples for org.apache.commons.collections CollectionUtils addAll

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils addAll.

Prototype

public static void addAll(Collection collection, Object[] elements) 

Source Link

Document

Adds all elements in the array to the given collection.

Usage

From source file:org.ow2.bonita.persistence.db.DbSessionImpl.java

@Override
public Set<IncomingEventInstance> getIncomingEvents() {
    final Set<IncomingEventInstance> result = new HashSet<IncomingEventInstance>();
    final Query query = getSession().getNamedQuery("getIncomingEvents");
    CollectionUtils.addAll(result, query.iterate());
    return result;
}

From source file:org.ow2.bonita.persistence.db.DbSessionImpl.java

@Override
public Set<IncomingEventInstance> getActivityIncomingEvents(final ActivityInstanceUUID activityUUID) {
    final Set<IncomingEventInstance> result = new HashSet<IncomingEventInstance>();
    final Query query = getSession().getNamedQuery("getActivityIncomingEvents");
    query.setString("activityUUID", activityUUID.getValue());

    CollectionUtils.addAll(result, query.iterate());
    return result;
}

From source file:org.ow2.bonita.persistence.db.DbSessionImpl.java

@Override
public Set<EventCouple> getEventsCouples() {
    final Query query = getSession().getNamedQuery("getEventsCouples");

    query.setLong("current", System.currentTimeMillis());
    query.setResultTransformer(Transformers.aliasToBean(EventCouple.class));

    final Set<EventCouple> result = new HashSet<EventCouple>();
    CollectionUtils.addAll(result, query.iterate());
    return result;
}

From source file:org.pentaho.repo.controller.RepositoryBrowserController.java

public LinkedList<String> getRecentSearches() {
    LinkedList<String> recentSearches = new LinkedList<String>();
    try {/*  ww w.  j  av a 2s .com*/
        PropsUI props = PropsUI.getInstance();
        String jsonValue = props.getRecentSearches();
        if (jsonValue != null) {
            JSONParser jsonParser = new JSONParser();
            JSONObject jsonObject = (JSONObject) jsonParser.parse(jsonValue);

            String login = "file_repository_no_login";
            if (Spoon.getInstance().rep.getUserInfo() != null) {
                login = Spoon.getInstance().rep.getUserInfo().getLogin();
            }
            JSONArray jsonArray = (JSONArray) jsonObject.get(login);
            CollectionUtils.addAll(recentSearches, jsonArray.toArray());
        }
    } catch (Exception e) {
        // Log error in console
    }
    return recentSearches;
}

From source file:org.pentaho.repo.controller.RepositoryBrowserController.java

public LinkedList<String> storeRecentSearch(String recentSearch) {
    LinkedList<String> recentSearches = getRecentSearches();
    try {//ww w  . j  a  va 2s.com
        if (recentSearch == null || recentSearches.contains(recentSearch)) {
            return recentSearches;
        }
        recentSearches.push(recentSearch);
        if (recentSearches.size() > 5) {
            recentSearches.pollLast();
        }

        JSONArray jsonArray = new JSONArray();
        CollectionUtils.addAll(jsonArray, recentSearches.toArray());

        PropsUI props = PropsUI.getInstance();
        String jsonValue = props.getRecentSearches();
        JSONParser jsonParser = new JSONParser();
        JSONObject jsonObject = jsonValue != null ? (JSONObject) jsonParser.parse(jsonValue) : new JSONObject();

        String login = "file_repository_no_login";
        if (Spoon.getInstance().rep.getUserInfo() != null) {
            login = Spoon.getInstance().rep.getUserInfo().getLogin();
        }

        jsonObject.put(login, jsonArray);
        props.setRecentSearches(jsonObject.toJSONString());
    } catch (Exception e) {
        // Log error in console
    }

    return recentSearches;
}

From source file:org.projectforge.web.admin.AdminPage.java

protected void checkI18nProperties() {
    log.info("Administration: check i18n properties.");
    checkAccess();/* www .  j av a  2 s .  c  o m*/
    final StringBuffer buf = new StringBuffer();
    final Properties props = new Properties();
    final Properties props_en = new Properties();
    final Properties props_de = new Properties();
    final Properties propsFound = new Properties();
    final ClassLoader cLoader = this.getClass().getClassLoader();
    try {
        load(props, "");
        load(props_en, "_en");
        load(props_de, "_de");
        final InputStream is = cLoader.getResourceAsStream(WebConstants.FILE_I18N_KEYS);
        propsFound.load(is);
    } catch (final IOException ex) {
        log.error("Could not load i18n properties: " + ex.getMessage(), ex);
        throw new RuntimeException(ex);
    }
    buf.append("Checking the differences between the " + PFUserContext.BUNDLE_NAME
            + " properties (default and _de)\n\n");
    buf.append("Found " + props.size() + " entries in default property file (en).\n\n");
    buf.append("Missing in _de:\n");
    buf.append("---------------\n");
    List<String> keys = new ArrayList<String>();
    for (final Object key : props.keySet()) {
        if (props_de.containsKey(key) == false) {
            keys.add(String.valueOf(key));
        }
    }
    Collections.sort(keys);
    for (final String key : keys) {
        buf.append(key + "=" + props.getProperty(key) + "\n");
    }
    buf.append("\n\nOnly in _de (not in _en):\n");
    buf.append("-------------------------\n");
    keys = new ArrayList<String>();
    for (final Object key : props_de.keySet()) {
        if (props.containsKey(key) == false) {
            keys.add(String.valueOf(key));
        }
    }
    Collections.sort(keys);
    for (final String key : keys) {
        buf.append(key + "=" + props_de.getProperty(key) + "\n");
    }
    if (WebConfiguration.isDevelopmentMode() == true) {
        buf.append("\n\nMaybe not defined but used (found in java, jsp or Wicket's html code):\n");
        buf.append("----------------------------------------------------------------------\n");
        keys = new ArrayList<String>();
        for (final Object key : propsFound.keySet()) {
            if (props.containsKey(key) == false && props_de.containsKey(key) == false
                    && props.containsKey(key) == false) {
                keys.add(String.valueOf(key) + "=" + propsFound.getProperty((String) key));
            }
        }
        Collections.sort(keys);
        for (final String key : keys) {
            buf.append(key + "\n");
        }
        buf.append(
                "\n\nExperimental (in progress): Maybe unused (not found in java, jsp or Wicket's html code):\n");
        buf.append(
                "----------------------------------------------------------------------------------------\n");
        final Set<String> all = new TreeSet<String>();
        CollectionUtils.addAll(all, props.keys());
        CollectionUtils.addAll(all, props_en.keys());
        CollectionUtils.addAll(all, props_de.keys());
        keys = new ArrayList<String>();
        for (final String key : all) {
            if (propsFound.containsKey(key) == false) {
                keys.add(String.valueOf(key));
            }
        }
        Collections.sort(keys);
        for (final String key : keys) {
            String value = props_de.getProperty(key);
            if (value == null) {
                value = props_en.getProperty(key);
            }
            if (value == null) {
                value = props.getProperty(key);
            }
            buf.append(key + "=" + value + "\n");
        }
    }
    final String result = buf.toString();
    final String filename = "projectforge_i18n_check" + DateHelper.getDateAsFilenameSuffix(new Date()) + ".txt";
    DownloadUtils.setDownloadTarget(result.getBytes(), filename);
}

From source file:org.robotframework.javalib.util.ArrayUtil.java

public static <T> T[] add(T[] original, T... newElements) {
    List<T> results = new ArrayList<T>(original.length + newElements.length);
    CollectionUtils.addAll(results, original);
    CollectionUtils.addAll(results, newElements);
    return results.toArray(original);
}

From source file:org.robotframework.jvmconnector.xmlrpc.CloseableLibraryDecorator.java

public String[] getKeywordNames() {
    List<String> newKeywordNames = new ArrayList<String>();
    CollectionUtils.addAll(newKeywordNames, library.getKeywordNames());
    newKeywordNames.add(KEYWORD_CLOSE_APPLICATION);
    return newKeywordNames.toArray(new String[0]);
}

From source file:org.robotframework.swing.keyword.list.ListKeywords.java

private List<String> intoList(final String listItemIdentifier, String[] additionalItemIdentifiers) {
    final List<String> itemIdentifiers = new ArrayList<String>() {
        {/*from w  ww.j  av a  2  s  . c o  m*/
            add(listItemIdentifier);
        }
    };
    CollectionUtils.addAll(itemIdentifiers, additionalItemIdentifiers);
    return itemIdentifiers;
}

From source file:org.sakaiproject.nakamura.search.solr.SolrResultSetFactory.java

/**
 * Process a query string to search using Solr.
 *
 * @param request//w ww  .  jav  a 2 s  .  c om
 * @param query
 * @param asAnon
 * @param rs
 * @return
 * @throws SolrSearchException
 */
@SuppressWarnings("rawtypes")
public SolrSearchResultSet processQuery(SlingHttpServletRequest request, Query query, boolean asAnon)
        throws SolrSearchException {
    try {
        // Add reader restrictions to solr fq (filter query) parameter,
        // to prevent "reader restrictions" from affecting the solr score
        // of a document.
        Map<String, Object> originalQueryOptions = query.getOptions();
        Map<String, Object> queryOptions = Maps.newHashMap();
        Object filterQuery = null;

        if (originalQueryOptions != null) {
            // copy from originalQueryOptions in case its backed by a ImmutableMap,
            // which prevents saving of filter query changes.
            queryOptions.putAll(originalQueryOptions);
            if (queryOptions.get(CommonParams.FQ) != null) {
                filterQuery = queryOptions.get(CommonParams.FQ);
            }
        }

        Set<String> filterQueries = Sets.newHashSet();
        // add any existing filter queries to the set
        if (filterQuery != null) {
            if (filterQuery instanceof Object[]) {
                CollectionUtils.addAll(filterQueries, (Object[]) filterQuery);
            } else if (filterQuery instanceof Iterable) {
                CollectionUtils.addAll(filterQueries, ((Iterable) filterQuery).iterator());
            } else {
                filterQueries.add(String.valueOf(filterQuery));
            }
        }

        // apply readers restrictions.
        if (asAnon) {
            filterQueries.add("readers:" + User.ANON_USER);
        } else {
            Session session = StorageClientUtils
                    .adaptToSession(request.getResourceResolver().adaptTo(javax.jcr.Session.class));
            if (!User.ADMIN_USER.equals(session.getUserId())) {
                AuthorizableManager am = session.getAuthorizableManager();
                Authorizable user = am.findAuthorizable(session.getUserId());
                Set<String> readers = Sets.newHashSet();
                for (Iterator<Group> gi = user.memberOf(am); gi.hasNext();) {
                    readers.add(SearchUtil.escapeString(gi.next().getId(), Query.SOLR));
                }
                readers.add(SearchUtil.escapeString(session.getUserId(), Query.SOLR));
                filterQueries.add("readers:(" + StringUtils.join(readers, " OR ") + ")");
            }
        }

        // filter out 'excluded' items. these are indexed because we do need to search for
        // some things on the server that the UI doesn't want (e.g. collection groups)
        filterQueries.add("-exclude:true");

        // filter out deleted items
        List<String> deletedPaths = deletedPathsService.getDeletedPaths();
        if (!deletedPaths.isEmpty()) {
            // these are escaped as they are collected
            filterQueries.add("-path:(" + StringUtils.join(deletedPaths, " OR ") + ")");
        }
        // save filterQuery changes
        queryOptions.put(CommonParams.FQ, filterQueries);

        SolrQuery solrQuery = buildQuery(request, query.getQueryString(), queryOptions);

        SolrServer solrServer = solrSearchService.getServer();
        if (LOGGER.isDebugEnabled()) {
            try {
                LOGGER.debug("Performing Query {} ", URLDecoder.decode(solrQuery.toString(), "UTF-8"));
            } catch (UnsupportedEncodingException e) {
            }
        }
        long tquery = System.currentTimeMillis();
        QueryResponse response = solrServer.query(solrQuery, queryMethod);
        tquery = System.currentTimeMillis() - tquery;
        try {
            if (tquery > verySlowQueryThreshold) {
                SLOW_QUERY_LOGGER.error("Very slow solr query {} ms {} ", tquery,
                        URLDecoder.decode(solrQuery.toString(), "UTF-8"));
                TelemetryCounter.incrementValue("search", "VERYSLOW", request.getResource().getPath());
            } else if (tquery > slowQueryThreshold) {
                SLOW_QUERY_LOGGER.warn("Slow solr query {} ms {} ", tquery,
                        URLDecoder.decode(solrQuery.toString(), "UTF-8"));
                TelemetryCounter.incrementValue("search", "SLOW", request.getResource().getPath());
            }
        } catch (UnsupportedEncodingException e) {
        }
        SolrSearchResultSetImpl rs = new SolrSearchResultSetImpl(response);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Got {} hits in {} ms", rs.getSize(), response.getElapsedTime());
        }
        return rs;
    } catch (StorageClientException e) {
        throw new SolrSearchException(500, e.getMessage());
    } catch (AccessDeniedException e) {
        throw new SolrSearchException(500, e.getMessage());
    } catch (SolrServerException e) {
        throw new SolrSearchException(500, e.getMessage());
    }
}