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:nl.minbzk.dwr.zoeken.enricher.uploader.SolrResultUploader.java

/**
 * Get the Solr server based on the job.
 * /*from  ww  w  .j  ava2  s .  c  om*/
 * @param databaseName
 * @param types
 * @return SolrServer
 * @throws MalformedURLException
 */
private SolrServer getInstance(final String databaseName, final List<GeneratorType> types)
        throws MalformedURLException {
    if (solrServers.containsKey(databaseName))
        return solrServers.get(databaseName);

    SolrServer instance = null;

    for (GeneratorType type : types)
        switch (type) {
        case Solr:
            instance = new HttpSolrServer(solrBaseUri + databaseName + "/");

            break;
        case SolrCloud:
            instance = new CloudSolrServer(solrCloudUri);

            ((CloudSolrServer) instance).setDefaultCollection(databaseName);

            break;
        default:
            continue;
        }

    if (instance == null)
        throw new IllegalArgumentException(String.format("Unknown generator type(s) '%s'",
                StringUtils.collectionToCommaDelimitedString(types)));

    solrServers.put(databaseName, instance);

    return instance;
}

From source file:org.jasig.ssp.util.importer.job.tasklet.BatchInitializer.java

private void removeInvalidFiles()
        throws UnsupportedEncodingException, IOException, PartialUploadGuardException {
    TableColumnMetaDataRepository repo = metadataRepository.getRepository().getColumnMetadataRepository();
    Boolean missingKeysFound = false;
    String exceptionMessage = "";
    String EOL = System.getProperty("line.separator");
    List<String> tableNames = new ArrayList<String>();
    for (Resource resource : resources) {
        String fileName = resource.getFilename();
        String[] tableName = fileName.split("\\.");

        BufferedReader reader = bufferedReaderFactory.create(resource, encoding);
        String[] headers = StringUtils.tokenizeToStringArray(reader.readLine(), ",");
        TableReference tableReference = new TableReference(tableName[0]);
        tableNames.add(EOL + tableName[0]);
        TableMetadata tableMetadato = repo.getTableMetadata(tableReference);
        Map<String, String> tableMap = new HashMap<String, String>();
        for (String header : headers)
            tableMap.put(header, header);

        if (!tableMetadato.hasKeys(tableMap)) {
            missingKeysFound = true;/*  ww w .ja  v  a  2 s  .  com*/
            List<String> missingKeys = tableMetadato.missingKeys(tableMap);
            exceptionMessage = exceptionMessage + "Table: " + tableName[0]
                    + " can not be processed. Missing headers: "
                    + StringUtils.collectionToCommaDelimitedString(missingKeys) + EOL;
        }
    }

    if (missingKeysFound) {
        exceptionMessage = exceptionMessage + "All Tables Not Processed: "
                + StringUtils.collectionToCommaDelimitedString(tableNames) + EOL;
        throw new PartialUploadGuardException(exceptionMessage);
    }
}

From source file:org.cloudfoundry.tools.compiler.CloudFoundryJavaCompiler.java

/**
 * Adapt any tasks options for use with the eclipse batch compiler.
 * /*from   w  w w  .  j a v a 2  s. com*/
 * @param options the source options (never null)
 * @param classes the class (never null)
 * @return a set of options that can be applied to the {@link EclipseBatchCompiler}
 */
private String[] getArgumentsForBatchCompiler(List<String> options, List<String> classes) {
    ArrayList<String> arguments = new ArrayList<String>();
    arguments.addAll(options);
    if (!classes.isEmpty()) {
        arguments.add("-classNames");
        arguments.add(StringUtils.collectionToCommaDelimitedString(classes));
    }
    return arguments.toArray(new String[arguments.size()]);
}

From source file:com.reactivetechnologies.platform.rest.dll.JarModuleLoader.java

private void loadDynamicLibrary(File f) {
    log.info("[JAR Loader] Trying to load classes from: " + f.getName());
    try {/*from  ww w.j  a va2  s  .c  om*/
        Set<String> packages = jarLoader.addJar(f);
        log.info("[JAR Loader] Trying to map JAX RS services from loaded jar");
        server.mapServiceRoute(StringUtils.collectionToCommaDelimitedString(packages));
        log.info("[JAR Loader] Dynamic library loaded succesfully");
    } catch (Exception e) {
        log.error("[JAR Loader] Unable to load classes from jar", e);
    }
}

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

/**
 * Convert DB object to the simplified client representation
 * @param e/*from  ww w .  j  a v a2s  . c  om*/
 * @return
 */
public ClientAppBasic convertToClientApp(ClientDetailsEntity e) {
    ClientAppBasic res = new ClientAppBasic();
    res.setClientId(e.getClientId());
    res.setClientSecret(e.getClientSecret());
    res.setClientSecretMobile(e.getClientSecretMobile());
    res.setGrantedTypes(e.getAuthorizedGrantTypes());

    // approval status
    res.setIdentityProviderApproval(new HashMap<String, Boolean>());
    // request status
    res.setIdentityProviders(new HashMap<String, Boolean>());
    for (String key : attributesAdapter.getAuthorityUrls().keySet()) {
        res.getIdentityProviders().put(key, false);
    }

    ClientAppInfo info = ClientAppInfo.convert(e.getAdditionalInformation());
    if (info != null) {
        res.setName(info.getName());
        res.setNativeAppsAccess(info.isNativeAppsAccess());
        if (info.getIdentityProviders() != null) {
            for (String key : info.getIdentityProviders().keySet()) {
                switch (info.getIdentityProviders().get(key)) {
                case ClientAppInfo.APPROVED:
                    res.getIdentityProviderApproval().put(key, true);
                    res.getIdentityProviders().put(key, true);
                    break;
                case ClientAppInfo.REJECTED:
                    res.getIdentityProviderApproval().put(key, false);
                    res.getIdentityProviders().put(key, true);
                    break;
                case ClientAppInfo.REQUESTED:
                    res.getIdentityProviders().put(key, true);
                    break;
                default:
                    break;
                }
            }
        }
    }
    // access server-side corresponds to the 'authorization grant' flow.
    res.setServerSideAccess(e.getAuthorizedGrantTypes().contains(GT_AUTHORIZATION_CODE));
    // browser access corresponds to the 'implicit' flow.
    res.setBrowserAccess(e.getAuthorizedGrantTypes().contains(GT_IMPLICIT));

    res.setRedirectUris(StringUtils.collectionToCommaDelimitedString(e.getRegisteredRedirectUri()));
    return res;
}

From source file:eu.trentorise.smartcampus.permissionprovider.manager.ResourceAdapter.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. //from   w w w.  j  av  a 2s.c  o m
 * @param rp
 */
public void storeResourceParameter(ResourceParameter rp) {
    ResourceParameterKey pk = new ResourceParameterKey();
    pk.resourceId = rp.getResourceId();
    pk.value = rp.getValue();

    ResourceParameter rpold = resourceParameterRepository.findOne(pk);
    // 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) {
        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());
                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:eu.trentorise.smartcampus.permissionprovider.manager.ClientDetailsManager.java

/**
 * Convert DB object to the simplified client representation
 * @param e//  w ww.ja  va2s . c o m
 * @return
 */
private ClientAppBasic convertToClientApp(ClientDetailsEntity e) {
    ClientAppBasic res = new ClientAppBasic();
    res.setClientId(e.getClientId());
    res.setClientSecret(e.getClientSecret());
    res.setClientSecretMobile(e.getClientSecretMobile());
    res.setGrantedTypes(e.getAuthorizedGrantTypes());

    // approval status
    res.setIdentityProviderApproval(new HashMap<String, Boolean>());
    // request status
    res.setIdentityProviders(new HashMap<String, Boolean>());
    for (String key : attributesAdapter.getAuthorityUrls().keySet()) {
        res.getIdentityProviders().put(key, false);
    }

    ClientAppInfo info = ClientAppInfo.convert(e.getAdditionalInformation());
    if (info != null) {
        res.setName(info.getName());
        res.setNativeAppsAccess(info.isNativeAppsAccess());
        res.setNativeAppSignatures(info.getNativeAppSignatures());
        if (info.getIdentityProviders() != null) {
            for (String key : info.getIdentityProviders().keySet()) {
                switch (info.getIdentityProviders().get(key)) {
                case ClientAppInfo.APPROVED:
                    res.getIdentityProviderApproval().put(key, true);
                    res.getIdentityProviders().put(key, true);
                    break;
                case ClientAppInfo.REJECTED:
                    res.getIdentityProviderApproval().put(key, false);
                    res.getIdentityProviders().put(key, true);
                    break;
                case ClientAppInfo.REQUESTED:
                    res.getIdentityProviders().put(key, true);
                    break;
                default:
                    break;
                }
            }
        }
    }
    // access server-side corresponds to the 'authorization grant' flow.
    res.setServerSideAccess(e.getAuthorizedGrantTypes().contains(GT_AUTHORIZATION_CODE));
    // browser access corresponds to the 'implicit' flow.
    res.setBrowserAccess(e.getAuthorizedGrantTypes().contains(GT_IMPLICIT));

    res.setRedirectUris(StringUtils.collectionToCommaDelimitedString(e.getRegisteredRedirectUri()));
    return res;
}

From source file:org.cloudfoundry.identity.uaa.login.ClientInfoAuthenticationFilter.java

protected List<GrantedAuthority> getAuthorities(Collection<String> authorities) {
    return AuthorityUtils
            .commaSeparatedStringToAuthorityList(StringUtils.collectionToCommaDelimitedString(authorities));
}

From source file:eu.trentorise.smartcampus.permissionprovider.controller.PermissionController.java

/**
 * Save permissions requested by the app.
 * @param permissions//from w w  w  .  j  av  a2s .c  o  m
 * @param clientId
 * @param serviceId
 * @return {@link Response} entity containing the processed app {@link Permissions} descriptor
 */
@RequestMapping(value = "/dev/permissions/{clientId}/{serviceId:.*}", method = RequestMethod.PUT)
public @ResponseBody Response savePermissions(@RequestBody Permissions permissions,
        @PathVariable String clientId, @PathVariable String serviceId) {
    Response response = new Response();
    response.setResponseCode(RESPONSE.OK);
    try {
        // check that the client is owned by the current user
        checkClientIdOwnership(clientId);
        ClientDetailsEntity clientDetails = clientDetailsRepository.findByClientId(clientId);
        ClientAppInfo info = ClientAppInfo.convert(clientDetails.getAdditionalInformation());

        if (info.getResourceApprovals() == null)
            info.setResourceApprovals(new HashMap<String, Boolean>());
        Collection<String> resourceIds = new HashSet<String>(clientDetails.getResourceIds());
        Collection<String> scopes = new HashSet<String>(clientDetails.getScope());
        for (String r : permissions.getSelectedResources().keySet()) {
            Resource resource = resourceRepository.findOne(Long.parseLong(r));
            // if not checked, remove from permissions and from pending requests
            if (!permissions.getSelectedResources().get(r)) {
                info.getResourceApprovals().remove(r);
                resourceIds.remove(r);
                scopes.remove(resource.getResourceUri());
                // if checked but requires approval, check whether
                // - is the resource of the same client, so add automatically   
                // - already approved (i.e., included in client resourceIds)
                // - already requested (i.e., included in additional info approval requests map)   
            } else if (!clientId.equals(resource.getClientId()) && resource.isApprovalRequired()) {
                if (!resourceIds.contains(r) && !info.getResourceApprovals().containsKey(r)) {
                    info.getResourceApprovals().put(r, true);
                }
                // if approval is not required, include directly in client resource ids   
            } else {
                resourceIds.add(r);
                scopes.add(resource.getResourceUri());
            }
        }
        clientDetails.setResourceIds(StringUtils.collectionToCommaDelimitedString(resourceIds));
        clientDetails.setScope(StringUtils.collectionToCommaDelimitedString(scopes));
        clientDetails.setAdditionalInformation(info.toJson());
        clientDetailsRepository.save(clientDetails);
        response.setData(buildPermissions(clientDetails, serviceId));
    } catch (Exception e) {
        logger.error("Failure saving permissions model: " + e.getMessage(), e);
        response.setErrorMessage(e.getMessage());
        response.setResponseCode(RESPONSE.ERROR);
    }

    return response;

}

From source file:org.kmnet.com.fw.web.logging.TraceLoggingInterceptor.java

/**
 * convert parameter names of the method into a String value<br>
 * <br>// w  w  w .j  a  va2 s .c o m
 * @param handlerMethod Target methods of interceptor
 * @return String parameter string
 */
protected static String buildMethodParams(HandlerMethod handlerMethod) {
    MethodParameter[] params = handlerMethod.getMethodParameters();
    List<String> lst = new ArrayList<String>(params.length);
    for (MethodParameter p : params) {
        lst.add(p.getParameterType().getSimpleName());
    }
    return StringUtils.collectionToCommaDelimitedString(lst);
}