Example usage for org.springframework.util StringUtils collectionToCommaDelimitedString

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

Introduction

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

Prototype

public static String collectionToCommaDelimitedString(@Nullable Collection<?> coll) 

Source Link

Document

Convert a Collection into a delimited String (e.g., CSV).

Usage

From source file:org.synyx.hera.si.PluginRegistryAwareMessageHandler.java

private List<Object> invokePlugins(Collection<? extends Plugin<?>> plugins, Message<?> message) {
    List<Object> results = new ArrayList<Object>();
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("Invoking plugin(s) %s with message %s",
                StringUtils.collectionToCommaDelimitedString(plugins), message));
    }/*  w  ww.  j av a  2  s.  c om*/

    for (Plugin<?> plugin : plugins) {

        Object[] invocationArguments = getInvocationArguments(message);
        Class<?>[] types = getTypes(invocationArguments);

        Method businessMethod = ReflectionUtils.findMethod(pluginType, serviceMethodName, types);

        if (businessMethod == null) {
            throw new MessageHandlingException(message,
                    String.format("Did not find a method %s on %s taking the following parameters %s",
                            serviceMethodName, pluginType.getName(), Arrays.toString(types)));
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug(String.format("Invoke plugin method %s using arguments %s", businessMethod,
                    Arrays.toString(invocationArguments)));
        }

        Object result = ReflectionUtils.invokeMethod(businessMethod, plugin, invocationArguments);

        if (!businessMethod.getReturnType().equals(void.class)) {
            results.add(result);
        }
    }

    return results;
}

From source file:com.appglu.impl.SyncTemplate.java

/**
 * {@inheritDoc}//from   w ww.  jav  a  2s  .co m
 */
public List<TableVersion> versionsForTables(List<String> tables) throws AppGluRestClientException {
    try {
        String tablesParameter = StringUtils.collectionToCommaDelimitedString(tables);
        TableVersionBody response = this.restOperations.getForObject(VERSIONS_FOR_TABLES_URL,
                TableVersionBody.class, tablesParameter);
        return response.getTables();
    } catch (RestClientException e) {
        throw new AppGluRestClientException(e.getMessage(), e);
    }
}

From source file:com.devnexus.ting.model.Presentation.java

public void convertPresentationTagsToText() {
    final List<String> tagAsString = new ArrayList<>();
    for (PresentationTag presentationTag : this.presentationTags) {
        tagAsString.add(presentationTag.getName());
    }/*from   ww w  . j a  v a 2 s  .co  m*/
    this.tagsAsText = StringUtils.collectionToCommaDelimitedString(tagAsString);
}

From source file:jails.http.HttpHeaders.java

/**
 * Set the set of allowed {@link HttpMethod HTTP methods}, as specified by the {@code Allow} header.
 * @param allowedMethods the allowed methods
 *//*from  w w w  . ja v  a  2  s .c o m*/
public void setAllow(Set<HttpMethod> allowedMethods) {
    set(ALLOW, StringUtils.collectionToCommaDelimitedString(allowedMethods));
}

From source file:eu.trentorise.smartcampus.permissionprovider.manager.ResourceManager.java

/**
 * Save resource parameter. Check the uniqueness of the parameter value across all the
 * parameters with the same resource parameter definition ID. Instantiate 
 * all the derived resources. //  w  w w  .j  av a 2 s  .  c  om
 * @param rp
 */
public void storeResourceParameter(ResourceParameter rp, String serviceId) {
    validateResourceParameterData(rp);
    ResourceParameter rpold = rp.getId() == null ? null : resourceParameterRepository.findOne(rp.getId());
    // check uniqueness
    String clientId = rp.getClientId();
    if (rpold != null && !clientId.equals(clientId)) {
        throw new IllegalArgumentException("A parameter already used by another app");
    } else if (rpold == null) {
        ServiceDescriptor sd = serviceRepository.findOne(serviceId);
        if (sd == null) {
            throw new IllegalArgumentException("Unknown service: " + serviceId);
        } else {
            Service s = Utils.toServiceObject(sd);
            boolean found = false;
            for (ResourceDeclaration rd : s.getResource()) {
                if (rd.getId().equals(rp.getParameter())) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                throw new IllegalArgumentException(
                        "Unknown parameter '" + rp.getParameter() + "' for service: " + serviceId);
            }
            rp.setService(sd);
        }

        resourceParameterRepository.save(rp);
        // derived resources
        Map<String, ResourceMapping> mappings = findResourceURIs(rp);
        // store new resources entailed by the resource parameter
        if (mappings != null) {
            Set<String> newSet = new HashSet<String>();
            Set<String> newScopes = new HashSet<String>();
            for (String uri : mappings.keySet()) {
                ResourceMapping resourceMapping = mappings.get(uri);

                Resource r = prepareResource(clientId, rp, uri, resourceMapping, rp.getVisibility());
                r.setService(sd);
                resourceRepository.save(r);
                newSet.add(r.getResourceId().toString());
                newScopes.add(r.getResourceUri());
            }
            // add automatically the resources entailed by own resource parameters to the client resourceIds
            ClientDetailsEntity cd = clientDetailsRepository.findByClientId(clientId);
            Set<String> oldSet = cd.getResourceIds();
            if (oldSet != null)
                newSet.addAll(oldSet);
            cd.setResourceIds(StringUtils.collectionToCommaDelimitedString(newSet));
            // add automatically the resources entailed by own resource parameters to the client scope
            oldSet = cd.getScope();
            if (oldSet != null)
                newScopes.addAll(oldSet);
            cd.setScope(StringUtils.collectionToCommaDelimitedString(newScopes));
            clientDetailsRepository.save(cd);
        }
    } else {
        throw new IllegalArgumentException("A parameter already exists");
    }
}

From source file:com.devnexus.ting.model.CfpSubmission.java

public String getSpeakerLocation() {
    final Set<String> speakerLocations = new HashSet<String>();

    for (CfpSubmissionSpeaker speaker : this.cfpSubmissionSpeakers) {
        speakerLocations.add(speaker.getLocation());
    }/*www .  j av a 2s  .  c o  m*/

    return StringUtils.collectionToCommaDelimitedString(speakerLocations);
}

From source file:eu.trentorise.smartcampus.permissionprovider.manager.ClientDetailsAdapter.java

/**
 * Fill in the DB object with the properties of {@link ClientAppBasic} instance. In case of problem, return null.
 * @param client//  ww w  .j a v  a2s  .com
 * @param data
 * @return
 * @throws Exception 
 */
public ClientDetailsEntity convertFromClientApp(ClientDetailsEntity client, ClientAppBasic data) {
    try {
        ClientAppInfo info = null;
        if (client.getAdditionalInformation() == null) {
            info = new ClientAppInfo();
        } else {
            info = ClientAppInfo.convert(client.getAdditionalInformation());
        }
        info.setName(data.getName());
        info.setNativeAppsAccess(data.isNativeAppsAccess());
        Set<String> types = new HashSet<String>(client.getAuthorizedGrantTypes());
        if (data.isBrowserAccess()) {
            types.add(GT_IMPLICIT);
        } else {
            types.remove(GT_IMPLICIT);
        }
        if (data.isServerSideAccess() || data.isNativeAppsAccess()) {
            types.add(GT_AUTHORIZATION_CODE);
            types.add(GT_REFRESH_TOKEN);
        } else {
            types.remove(GT_AUTHORIZATION_CODE);
            types.remove(GT_REFRESH_TOKEN);
        }
        client.setAuthorizedGrantTypes(StringUtils.collectionToCommaDelimitedString(types));
        if (info.getIdentityProviders() == null) {
            info.setIdentityProviders(new HashMap<String, Integer>());
        }

        for (String key : attributesAdapter.getAuthorityUrls().keySet()) {
            if (data.getIdentityProviders().get(key)) {
                Integer value = info.getIdentityProviders().get(key);
                AuthorityMapping a = attributesAdapter.getAuthority(key);
                if (value == null || value == ClientAppInfo.UNKNOWN) {
                    info.getIdentityProviders().put(key,
                            a.isPublic() ? ClientAppInfo.APPROVED : ClientAppInfo.REQUESTED);
                }
            } else {
                info.getIdentityProviders().remove(key);
            }
        }

        client.setAdditionalInformation(info.toJson());
        client.setRedirectUri(data.getRedirectUris());
    } catch (Exception e) {
        log.error("failed to convert an object: " + e.getMessage(), e);
        return null;
    }
    return client;
}

From source file:com.devnexus.ting.model.CfpSubmission.java

public String getSpeakerCompany() {
    final Set<String> speakerCompanies = new HashSet<String>();

    for (CfpSubmissionSpeaker speaker : this.cfpSubmissionSpeakers) {
        speakerCompanies.add(speaker.getCompany());
    }/*from w ww . j  a v  a  2  s.  co  m*/

    return StringUtils.collectionToCommaDelimitedString(speakerCompanies);
}

From source file:eu.trentorise.smartcampus.permissionprovider.manager.ClientDetailsManager.java

/**
 * Fill in the DB object with the properties of {@link ClientAppBasic} instance. In case of problem, return null.
 * @param client//from   w  w w  . ja  va2s .c  om
 * @param data
 * @return
 * @throws Exception 
 */
public ClientDetailsEntity convertFromClientApp(ClientDetailsEntity client, ClientAppBasic data) {
    try {
        ClientAppInfo info = null;
        if (client.getAdditionalInformation() == null) {
            info = new ClientAppInfo();
        } else {
            info = ClientAppInfo.convert(client.getAdditionalInformation());
        }
        info.setName(data.getName());
        info.setNativeAppsAccess(data.isNativeAppsAccess());
        info.setNativeAppSignatures(Utils.normalizeValues(data.getNativeAppSignatures()));
        Set<String> types = new HashSet<String>(client.getAuthorizedGrantTypes());
        if (data.isBrowserAccess()) {
            types.add(GT_IMPLICIT);
        } else {
            types.remove(GT_IMPLICIT);
        }
        if (data.isServerSideAccess() || data.isNativeAppsAccess()) {
            types.add(GT_AUTHORIZATION_CODE);
            types.add(GT_REFRESH_TOKEN);
        } else {
            types.remove(GT_AUTHORIZATION_CODE);
            types.remove(GT_REFRESH_TOKEN);
        }
        client.setAuthorizedGrantTypes(StringUtils.collectionToCommaDelimitedString(types));
        if (info.getIdentityProviders() == null) {
            info.setIdentityProviders(new HashMap<String, Integer>());
        }

        for (String key : attributesAdapter.getAuthorityUrls().keySet()) {
            if (data.getIdentityProviders().get(key)) {
                Integer value = info.getIdentityProviders().get(key);
                AuthorityMapping a = attributesAdapter.getAuthority(key);
                if (value == null || value == ClientAppInfo.UNKNOWN) {
                    info.getIdentityProviders().put(key,
                            a.isPublic() ? ClientAppInfo.APPROVED : ClientAppInfo.REQUESTED);
                }
            } else {
                info.getIdentityProviders().remove(key);
            }
        }

        client.setAdditionalInformation(info.toJson());
        client.setRedirectUri(Utils.normalizeValues(data.getRedirectUris()));
    } catch (Exception e) {
        log.error("failed to convert an object: " + e.getMessage(), e);
        return null;
    }
    return client;
}