Example usage for org.springframework.util StringUtils collectionToDelimitedString

List of usage examples for org.springframework.util StringUtils collectionToDelimitedString

Introduction

In this page you can find the example usage for org.springframework.util StringUtils collectionToDelimitedString.

Prototype

public static String collectionToDelimitedString(@Nullable Collection<?> coll, String delim) 

Source Link

Document

Convert a Collection into a delimited String (e.g.

Usage

From source file:edu.jhuapl.openessence.datasource.jdbc.JdbcOeDataSource.java

protected boolean addOrderByClauses(final StringBuilder query, final Collection<OrderByFilter> sorters)
        throws OeDataSourceException {

    boolean addedSorters = false;

    if (!CollectionUtils.isEmpty(sorters)) {
        query.append(" ORDER BY ");
        addedSorters = true;/*from  w ww  .  j ava  2 s .c om*/

        final List<String> orderBySql = new ArrayList<String>();
        for (final OrderByFilter sorter : sorters) {
            String sqlSnippet = "";
            //added to check for an alias on sort
            DimensionBean bean = this.getBean(sorter.getFilterId());
            if (bean != null && bean.getSqlColAlias() != null && !"".equals(bean.getSqlColAlias())) {
                sqlSnippet = sorter.getSqlSnippet(bean.getSqlColAlias());
            } else {
                sqlSnippet = sorter.getSqlSnippet(this);
            }
            if (sqlSnippet != null) {
                orderBySql.add(sqlSnippet);
            } else {
                throw new OeDataSourceException("You cannot use this dimension '" + sorter.getFilterId()
                        + "' to sort until you properly configure its sql column name. Please adjust your groovy definition file.");
            }
        }
        query.append(StringUtils.collectionToDelimitedString(orderBySql, ", "));
    }

    return addedSorters;

}

From source file:edu.jhuapl.openessence.datasource.jdbc.JdbcOeDataSource.java

protected void addGroupByClauses(final StringBuilder query, final LinkedHashMap<String, String> columns)
        throws OeDataSourceException {

    query.append(" GROUP BY ");

    final List<String> groupBySql = new ArrayList<String>();
    for (final String column : columns.keySet()) {
        String sqlSnippet = "";
        //added to check for an alias on sort
        DimensionBean bean = this.getBean(column);
        if (bean != null && bean.getSqlColAlias() != null && !"".equals(bean.getSqlColAlias())) {
            sqlSnippet = bean.getSqlColAlias();
        } else {/*  w w w. ja va  2s .co m*/
            sqlSnippet = columns.get(column);
        }
        if (sqlSnippet != null) {
            groupBySql.add(sqlSnippet);
        } else {
            throw new OeDataSourceException("You cannot use this dimension '" + column
                    + "' in groupby until you properly configure its sql column name. Please adjust your groovy definition file.");
        }
    }
    //query.append(StringUtils.collectionToDelimitedString(columns.values(), ","));
    query.append(StringUtils.collectionToDelimitedString(groupBySql, ", "));
}

From source file:it.smartcommunitylab.aac.controller.TokenIntrospectionController.java

@ApiOperation(value = "Get token metadata")
@RequestMapping(method = RequestMethod.POST, value = "/token_introspection")
public ResponseEntity<AACTokenIntrospection> getTokenInfo(@RequestParam String token) {
    AACTokenIntrospection result = new AACTokenIntrospection();

    try {/* w  w  w . ja va  2 s . c  o  m*/
        OAuth2Authentication auth = resourceServerTokenServices.loadAuthentication(token);

        OAuth2AccessToken storedToken = tokenStore.getAccessToken(auth);

        String clientId = auth.getOAuth2Request().getClientId();

        String userName = null;
        String userId = null;
        boolean applicationToken = false;

        if (auth.getPrincipal() instanceof User) {
            User principal = (User) auth.getPrincipal();
            userId = principal.getUsername();
        } else {
            ClientDetailsEntity client = clientDetailsRepository.findByClientId(clientId);
            applicationToken = true;
            userId = "" + client.getDeveloperId();
        }
        userName = userManager.getUserInternalName(Long.parseLong(userId));
        String localName = userName.substring(0, userName.lastIndexOf('@'));
        String tenant = userName.substring(userName.lastIndexOf('@') + 1);

        result.setUsername(localName);
        result.setClient_id(clientId);
        result.setScope(StringUtils.collectionToDelimitedString(auth.getOAuth2Request().getScope(), " "));
        result.setExp((int) (storedToken.getExpiration().getTime() / 1000));
        result.setIat(result.getExp() - storedToken.getExpiresIn());
        result.setIss(issuer);
        result.setNbf(result.getIat());
        result.setSub(userId);
        result.setAud(clientId);
        // jti is not supported in this form

        // only bearer tokens supported
        result.setToken_type(OAuth2AccessToken.BEARER_TYPE);
        result.setActive(true);

        result.setAac_user_id(userId);
        result.setAac_grantType(auth.getOAuth2Request().getGrantType());
        result.setAac_applicationToken(applicationToken);
        result.setAac_am_tenant(tenant);
    } catch (Exception e) {
        logger.error("Error getting info for token: " + e.getMessage());
        result = new AACTokenIntrospection();
        result.setActive(false);
    }
    return ResponseEntity.ok(result);
}

From source file:net.yasion.common.core.bean.wrapper.impl.ExtendedBeanWrapperImpl.java

/**
 * Parse the given property name into the corresponding property name tokens.
 * /*from   ww  w. j av a2 s.  c o m*/
 * @param propertyName
 *            the property name to parse
 * @return representation of the parsed property tokens
 */
private PropertyTokenHolder getPropertyNameTokens(String propertyName) {
    PropertyTokenHolder tokens = new PropertyTokenHolder();
    String actualName = null;
    List<String> keys = new ArrayList<String>(2);
    int searchIndex = 0;
    while (searchIndex != -1) {
        int keyStart = propertyName.indexOf(PROPERTY_KEY_PREFIX, searchIndex);
        searchIndex = -1;
        if (keyStart != -1) {
            int keyEnd = propertyName.indexOf(PROPERTY_KEY_SUFFIX, keyStart + PROPERTY_KEY_PREFIX.length());
            if (keyEnd != -1) {
                if (actualName == null) {
                    actualName = propertyName.substring(0, keyStart);
                }
                String key = propertyName.substring(keyStart + PROPERTY_KEY_PREFIX.length(), keyEnd);
                if ((key.startsWith("'") && key.endsWith("'"))
                        || (key.startsWith("\"") && key.endsWith("\""))) {
                    key = key.substring(1, key.length() - 1);
                }
                keys.add(key);
                searchIndex = keyEnd + PROPERTY_KEY_SUFFIX.length();
            }
        }
    }
    tokens.actualName = (actualName != null ? actualName : propertyName);
    tokens.canonicalName = tokens.actualName;
    if (!keys.isEmpty()) {
        tokens.canonicalName += PROPERTY_KEY_PREFIX
                + StringUtils.collectionToDelimitedString(keys, PROPERTY_KEY_SUFFIX + PROPERTY_KEY_PREFIX)
                + PROPERTY_KEY_SUFFIX;
        tokens.keys = StringUtils.toStringArray(keys);
    }
    return tokens;
}

From source file:org.apache.syncope.client.console.commons.PreferenceManager.java

public void set(final Request request, final Response response, final Map<String, List<String>> prefs) {
    Map<String, String> current = new HashMap<>();

    String prefString = cookieUtils.load(PREFMAN_KEY);
    if (prefString != null) {
        current.putAll(getPrefs(new String(Base64.decodeBase64(prefString.getBytes()))));
    }/*from ww w.  j a va 2s  .co  m*/

    // after retrieved previous setting in order to overwrite the key ...
    for (Map.Entry<String, List<String>> entry : prefs.entrySet()) {
        current.put(entry.getKey(), StringUtils.collectionToDelimitedString(entry.getValue(), ";"));
    }

    try {
        cookieUtils.save(PREFMAN_KEY, new String(Base64.encodeBase64(setPrefs(current).getBytes())));
    } catch (IOException e) {
        LOG.error("Could not save {} info: {}", getClass().getSimpleName(), current, e);
    }
}

From source file:org.apache.syncope.client.console.commons.PreferenceManager.java

public void setList(final Request request, final Response response, final String key,
        final List<String> values) {
    set(request, response, key, StringUtils.collectionToDelimitedString(values, ";"));
}

From source file:org.apache.syncope.console.commons.PreferenceManager.java

public void set(final Request request, final Response response, final Map<String, List<String>> prefs) {
    String prefString = cookieUtils.load(PREFMAN_KEY);

    final Map<String, String> current = new HashMap<String, String>();
    if (prefString != null) {
        current.putAll(getPrefs(new String(Base64.decodeBase64(prefString.getBytes()))));
    }/*from  ww  w  .  jav a  2s  .  co m*/

    // after retrieved previous setting in order to overwrite the key ...
    for (Entry<String, List<String>> entry : prefs.entrySet()) {
        current.put(entry.getKey(), StringUtils.collectionToDelimitedString(entry.getValue(), ";"));
    }

    try {
        cookieUtils.save(PREFMAN_KEY, new String(Base64.encodeBase64(setPrefs(current).getBytes())));
    } catch (IOException e) {
        LOG.error("Could not save {} info: {}", getClass().getSimpleName(), current, e);
    }
}

From source file:org.nextframework.controller.ExtendedBeanWrapper.java

private PropertyTokenHolder getPropertyNameTokens(String propertyName) {
    PropertyTokenHolder tokens = new PropertyTokenHolder();
    String actualName = null;//ww  w  . ja  v a  2  s .  c  om
    List<Object> keys = new ArrayList<Object>(2);
    int searchIndex = 0;
    while (searchIndex != -1) {
        int keyStart = propertyName.indexOf(PROPERTY_KEY_PREFIX, searchIndex);
        searchIndex = -1;
        if (keyStart != -1) {
            int keyEnd = propertyName.indexOf(PROPERTY_KEY_SUFFIX, keyStart + PROPERTY_KEY_PREFIX.length());
            if (keyEnd != -1) {
                if (actualName == null) {
                    actualName = propertyName.substring(0, keyStart);
                }
                String key = propertyName.substring(keyStart + PROPERTY_KEY_PREFIX.length(), keyEnd);
                if (key.startsWith("'") && key.endsWith("'")) {
                    key = key.substring(1, key.length() - 1);
                } else if (key.startsWith("\"") && key.endsWith("\"")) {
                    key = key.substring(1, key.length() - 1);
                }
                keys.add(key);
                searchIndex = keyEnd + PROPERTY_KEY_SUFFIX.length();
            }
        }
    }
    tokens.actualName = (actualName != null ? actualName : propertyName);
    tokens.canonicalName = tokens.actualName;
    if (!keys.isEmpty()) {
        tokens.canonicalName += PROPERTY_KEY_PREFIX
                + StringUtils.collectionToDelimitedString(keys, PROPERTY_KEY_SUFFIX + PROPERTY_KEY_PREFIX)
                + PROPERTY_KEY_SUFFIX;
        tokens.keys = (String[]) keys.toArray(new String[keys.size()]);
    }
    return tokens;
}

From source file:org.openmrs.PersonName.java

/**
 * Convenience method to get all the names of this PersonName and concatonating them together
 * with spaces in between. If any part of {@link #getPrefix()}, {@link #getGivenName()},
 * {@link #getMiddleName()}, etc are null, they are not included in the returned name
 *
 * @return all of the parts of this {@link PersonName} joined with spaces
 * @should not put spaces around an empty middle name
 *//*from   ww  w.  j  av  a  2  s. c o m*/
public String getFullName() {
    List<String> temp = new ArrayList<String>();
    if (StringUtils.hasText(getPrefix())) {
        temp.add(getPrefix());
    }
    if (StringUtils.hasText(getGivenName())) {
        temp.add(getGivenName());
    }
    if (StringUtils.hasText(getMiddleName())) {
        temp.add(getMiddleName());
    }
    if (OpenmrsConstants.PERSON_NAME_FORMAT_LONG.equals(PersonName.getFormat())) {

        if (StringUtils.hasText(getFamilyNamePrefix())) {
            temp.add(getFamilyNamePrefix());
        }
        if (StringUtils.hasText(getFamilyName())) {
            temp.add(getFamilyName());
        }
        if (StringUtils.hasText(getFamilyName2())) {
            temp.add(getFamilyName2());
        }
        if (StringUtils.hasText(getFamilyNameSuffix())) {
            temp.add(getFamilyNameSuffix());
        }
        if (StringUtils.hasText(getDegree())) {
            temp.add(getDegree());
        }
    } else {

        if (StringUtils.hasText(getFamilyName())) {
            temp.add(getFamilyName());
        }
    }

    String nameString = StringUtils.collectionToDelimitedString(temp, " ");

    return nameString.trim();
}

From source file:org.opennms.netmgt.dao.support.PropertiesGraphDao.java

/** {@inheritDoc} */
@Override//  www .j  av a2  s  .c om
public PrefabGraph[] getPrefabGraphsForResource(final OnmsResource resource) {
    if (resource == null) {
        LOG.warn("returning empty graph list for resource because it is null");
        return new PrefabGraph[0];
    }
    Set<OnmsAttribute> attributes = new LinkedHashSet<>(resource.getAttributes());
    // Check if there are no attributes
    if (attributes.size() == 0) {
        LOG.debug("returning empty graph list for resource {} because its attribute list is empty", resource);
        return new PrefabGraph[0];
    }

    Set<String> availableRrdAttributes = new LinkedHashSet<>(resource.getRrdGraphAttributes().keySet());
    Set<String> availableStringAttributes = new LinkedHashSet<>(
            resource.getStringPropertyAttributes().keySet());
    Set<String> availableExternalAttributes = new LinkedHashSet<>(
            resource.getExternalValueAttributes().keySet());

    // Check if there are no RRD attributes
    if (availableRrdAttributes.size() == 0) {
        LOG.debug("returning empty graph list for resource {} because it has no RRD attributes", resource);
        return new PrefabGraph[0];
    }

    String resourceType = resource.getResourceType().getName();

    Map<String, PrefabGraph> returnList = new LinkedHashMap<String, PrefabGraph>();
    for (PrefabGraph query : getAllPrefabGraphs()) {
        if (resourceType != null && !query.hasMatchingType(resourceType)) {
            LOG.debug("skipping {} because its types \"{}\" does not match resourceType \"{}\"",
                    query.getName(), StringUtils.arrayToDelimitedString(query.getTypes(), ", "), resourceType);
            continue;
        }

        if (!verifyAttributesExist(query, "RRD", Arrays.asList(query.getColumns()), availableRrdAttributes)) {
            continue;
        }
        if (!verifyAttributesExist(query, "string property", Arrays.asList(query.getPropertiesValues()),
                availableStringAttributes)) {
            continue;
        }
        if (!verifyAttributesExist(query, "external value", Arrays.asList(query.getExternalValues()),
                availableExternalAttributes)) {
            continue;
        }

        LOG.debug("adding {} to query list", query.getName());

        returnList.put(query.getName(), query);
    }

    if (LOG.isDebugEnabled()) {
        ArrayList<String> nameList = new ArrayList<String>(returnList.size());
        for (PrefabGraph graph : returnList.values()) {
            nameList.add(graph.getName());
        }
        LOG.debug("found {} prefabricated graphs for resource {}: {}", nameList.size(), resource,
                StringUtils.collectionToDelimitedString(nameList, ", "));
    }

    final Set<String> suppressReports = new HashSet<String>();
    for (final Entry<String, PrefabGraph> entry : returnList.entrySet()) {
        suppressReports.addAll(Arrays.asList(entry.getValue().getSuppress()));
    }

    suppressReports.retainAll(returnList.keySet());
    if (suppressReports.size() > 0) {
        LOG.debug("suppressing {} prefabricated graphs for resource {}: {}", suppressReports.size(), resource,
                StringUtils.collectionToDelimitedString(suppressReports, ", "));
    }

    for (final String suppressReport : suppressReports) {
        returnList.remove(suppressReport);
    }

    return returnList.values().toArray(new PrefabGraph[returnList.size()]);
}