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:net.cpollet.jixture.asserts.JixtureAssert.java

public JixtureAssert containsExactly(List<Fixture> fixtures) {
    List<String> errors = new ArrayList<String>(2);

    try {/* w  w w  .ja  v a 2 s .  c  o m*/
        containsAtLeast(fixtures);
    } catch (AssertionError assertionError) {
        errors.add(assertionError.getMessage());
    }

    try {
        containsAtMost(fixtures);
    } catch (AssertionError assertionError) {
        errors.add(assertionError.getMessage());
    }

    if (0 < errors.size()) {
        throw new AssertionError(StringUtils.collectionToCommaDelimitedString(errors));
    }

    return this;
}

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

@RequestMapping(value = "/admin/approvals/{clientId}", method = RequestMethod.POST)
public @ResponseBody Response approve(@PathVariable String clientId) {
    try {//  ww  w.j  av  a  2  s . c o m
        ClientDetailsEntity e = clientDetailsRepository.findByClientId(clientId);
        ClientAppInfo info = ClientAppInfo.convert(e.getAdditionalInformation());
        if (!info.getResourceApprovals().isEmpty()) {
            Set<String> idSet = new HashSet<String>();
            if (e.getResourceIds() != null)
                idSet.addAll(e.getResourceIds());
            Set<String> uriSet = new HashSet<String>();
            if (e.getScope() != null)
                uriSet.addAll(e.getScope());
            for (String rId : info.getResourceApprovals().keySet()) {
                Resource resource = resourceRepository.findOne(Long.parseLong(rId));
                idSet.add(rId);
                uriSet.add(resource.getResourceUri());
            }
            e.setResourceIds(StringUtils.collectionToCommaDelimitedString(idSet));
            e.setScope(StringUtils.collectionToCommaDelimitedString(uriSet));
            info.setResourceApprovals(Collections.<String, Boolean>emptyMap());
            e.setAdditionalInformation(info.toJson());
            clientDetailsRepository.save(e);
        }
        return getApprovals();
    } catch (Exception e) {
        Response result = new Response();
        result.setResponseCode(RESPONSE.ERROR);
        result.setErrorMessage(e.getMessage());
        return result;
    }
}

From source file:org.cloudfoundry.identity.uaa.config.YamlProcessor.java

private void assignProperties(Properties properties, Map<String, Object> input, String path) {
    for (Entry<String, Object> entry : input.entrySet()) {
        String key = entry.getKey();
        if (StringUtils.hasText(path)) {
            if (key.startsWith("[")) {
                key = path + key;//  ww  w.  java 2 s.com
            } else {
                key = path + "." + key;
            }
        }
        Object value = entry.getValue();
        if (value instanceof String) {
            properties.put(key, value);
        } else if (value instanceof Map) {
            // Need a compound key
            @SuppressWarnings("unchecked")
            Map<String, Object> map = (Map<String, Object>) value;
            assignProperties(properties, map, key);
        } else if (value instanceof Collection) {
            // Need a compound key
            @SuppressWarnings("unchecked")
            Collection<Object> collection = (Collection<Object>) value;
            properties.put(key, StringUtils.collectionToCommaDelimitedString(collection));
            int count = 0;
            for (Object object : collection) {
                assignProperties(properties, Collections.singletonMap("[" + (count++) + "]", object), key);
            }
        } else {
            properties.put(key, value == null ? "" : value);
        }
    }
}

From source file:org.apigw.monitoring.jms.messagelistener.MonitoringMessageListener.java

private ResourceEvent parseJSONToResourceEvent(String message) throws JsonParseException, IOException {
    log.debug("Parsing json message to ResourceEvent");
    log.debug("Json message is: " + message);
    ResourceEvent event = new ResourceEvent();

    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> mapObject = mapper.readValue(message, new TypeReference<Map<String, Object>>() {
    });/*from   w w w. ja va  2 s .c o  m*/

    if (mapObject.get("timestamp") != null) {
        event.setTimestamp(new Date((Long) mapObject.get("timestamp")));
    }
    if (mapObject.get("correlationId") != null) {
        event.setCorrelationId((String) mapObject.get("correlationId"));
    }
    if (mapObject.get("eventType") != null) {
        event.setEventType(ResourceEventType.valueOf((String) mapObject.get("eventType")));
    }
    if (mapObject.get("state") != null) {
        event.setRequestState(RequestState.valueOf((String) mapObject.get("state")));
    }
    if (mapObject.get("message") != null) {
        event.setMessage((String) mapObject.get("message"));
    }
    if (mapObject.get("endpoint") != null) {
        event.setEndpoint((String) mapObject.get("endpoint"));
    }
    if (mapObject.get("resource") != null) {
        event.setResource((String) mapObject.get("resource"));
    }
    if (mapObject.get("ip") != null) {
        event.setIp((String) mapObject.get("ip"));
    }
    if (mapObject.get("httpStatus") != null) {
        event.setHttpStatus(Integer.valueOf((Integer) mapObject.get("httpStatus")));
    }
    if (mapObject.get("request") != null) {
        event.setRequest((String) mapObject.get("request"));
    }
    if (mapObject.get("method") != null) {
        event.setMethod((String) mapObject.get("method"));
    }
    if (mapObject.get("logicalAddress") != null) {
        event.setLogicalAddress((String) mapObject.get("logicalAddress"));
    }
    if (mapObject.get("client") != null) {
        event.setClient((String) mapObject.get("client"));
    }
    if (mapObject.get("user") != null) {
        event.setUser((String) mapObject.get("user"));
    }
    if (mapObject.get("scopes") != null) {
        List<String> scopes = (List<String>) mapObject.get("scopes");
        event.setScopes(StringUtils.collectionToCommaDelimitedString(scopes));
    }

    return event;
}

From source file:com.googlecode.janrain4j.api.engage.EngagePartnerServiceImplTest.java

@Test
public void testSetProviderPermissions() throws Exception {
    // build provider permissions
    Collection<String> providerPermissions = new ArrayList<String>();
    for (int i = 1; i < 5; i++) {
        providerPermissions.add("PROVIDER_PERMISSION_" + i);
    }//from ww w . j av a 2  s. c  o  m

    params.put(API_KEY_PARAM, apiKey);
    params.put(PROVIDER_PARAM, providerName);
    params.put(PERMISSIONS_PARAM, StringUtils.collectionToCommaDelimitedString(providerPermissions));
    params.put(PARTNER_KEY_PARAM, partnerApiKey);
    params.put(FORMAT_PARAM, JSON);

    // api url
    url = API_PARTNER_URI + SET_PROVIDER_PERMISSIONS_METHOD;

    when(httpClient.post(url, params)).thenReturn(httpResponse);
    when(httpResponse.getContent()).thenReturn(okResponse);

    // call service
    service.setProviderPermissions(apiKey, providerName, providerPermissions);

    verify(httpClient).post(url, params);
}

From source file:org.elasticsoftware.elasticactors.spring.AnnotationConfigWebApplicationContext.java

/**
 * Register a {@link org.springframework.beans.factory.config.BeanDefinition} for
 * any classes specified by {@link #register(Class...)} and scan any packages
 * specified by {@link #scan(String...)}.
 * <p>For any values specified by {@link #setConfigLocation(String)} or
 * {@link #setConfigLocations(String[])}, attempt first to load each location as a
 * class, registering a {@code BeanDefinition} if class loading is successful,
 * and if class loading fails (i.e. a {@code ClassNotFoundException} is raised),
 * assume the value is a package and attempt to scan it for annotated classes.
 * <p>Enables the default set of annotation configuration post processors, such that
 * {@code @Autowired}, {@code @Required}, and associated annotations can be used.
 * <p>Configuration class bean definitions are registered with generated bean
 * definition names unless the {@code value} attribute is provided to the stereotype
 * annotation./*from  w w w .  j a va2s .co m*/
 * @see #register(Class...)
 * @see #scan(String...)
 * @see #setConfigLocation(String)
 * @see #setConfigLocations(String[])
 * @see AnnotatedBeanDefinitionReader
 * @see ClassPathBeanDefinitionScanner
 */
@Override
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) {
    AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(beanFactory);
    reader.setEnvironment(this.getEnvironment());

    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(beanFactory);
    scanner.setEnvironment(this.getEnvironment());

    BeanNameGenerator beanNameGenerator = getBeanNameGenerator();
    ScopeMetadataResolver scopeMetadataResolver = getScopeMetadataResolver();
    if (beanNameGenerator != null) {
        reader.setBeanNameGenerator(beanNameGenerator);
        scanner.setBeanNameGenerator(beanNameGenerator);
        beanFactory.registerSingleton(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR,
                beanNameGenerator);
    }
    if (scopeMetadataResolver != null) {
        reader.setScopeMetadataResolver(scopeMetadataResolver);
        scanner.setScopeMetadataResolver(scopeMetadataResolver);
    }

    if (!this.annotatedClasses.isEmpty()) {
        if (logger.isInfoEnabled()) {
            logger.info("Registering annotated classes: ["
                    + StringUtils.collectionToCommaDelimitedString(this.annotatedClasses) + "]");
        }
        reader.register(this.annotatedClasses.toArray(new Class<?>[this.annotatedClasses.size()]));
    }

    if (!this.basePackages.isEmpty()) {
        if (logger.isInfoEnabled()) {
            logger.info("Scanning base packages: ["
                    + StringUtils.collectionToCommaDelimitedString(this.basePackages) + "]");
        }
        for (TypeFilter typeFilter : includeFilters) {
            scanner.addIncludeFilter(typeFilter);
        }
        scanner.scan(this.basePackages.toArray(new String[this.basePackages.size()]));
    }

    String[] configLocations = getConfigLocations();
    if (configLocations != null) {
        for (String configLocation : configLocations) {
            try {
                Class<?> clazz = getClassLoader().loadClass(configLocation);
                if (logger.isInfoEnabled()) {
                    logger.info("Successfully resolved class for [" + configLocation + "]");
                }
                reader.register(clazz);
            } catch (ClassNotFoundException ex) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Could not load class for config location [" + configLocation
                            + "] - trying package scan. " + ex);
                }
                int count = scanner.scan(configLocation);
                if (logger.isInfoEnabled()) {
                    if (count == 0) {
                        logger.info("No annotated classes found for specified class/package [" + configLocation
                                + "]");
                    } else {
                        logger.info(
                                "Found " + count + " annotated classes in package [" + configLocation + "]");
                    }
                }
            }
        }
    }
}

From source file:com.impetus.ankush.common.framework.ClusterPreValidator.java

/**
 * Method to check process lists./*w  w w.j  ava  2s .  c  o m*/
 * 
 * @param username
 * @param hostname
 * @param authUsingPassword
 * @param authInfo
 * @return
 */
private Status checkProcessList(String username, String hostname, boolean authUsingPassword, String authInfo) {
    String processList = "";
    String message = null;
    try {
        processList = SSHUtils.getCommandOutput("jps", hostname, username, authInfo, authUsingPassword);
    } catch (Exception e) {
        message = e.getMessage();
        logger.error(message, e);
    }

    List<String> processes = null;
    if ((processList == null) || processList.isEmpty()) {
        processes = new ArrayList<String>();
    } else {
        processes = new ArrayList<String>(Arrays.asList(processList.split("\n")));
    }

    List<String> processLists = new ArrayList<String>();
    for (String process : processes) {
        if (!(process.contains("Jps") || process.contains(AgentDeployer.ANKUSH_SERVER_PROCSS_NAME))) {
            String[] processArray = process.split("\\ ");
            if (processArray.length == 2) {
                processLists.add(process.split("\\ ")[1]);
            }
        }
    }

    if (processLists.isEmpty()) {
        return new Status("JPS process list", OK);
    } else {
        message = StringUtils.collectionToCommaDelimitedString(processLists) + " already running";
        return new Status("JPS process list", message, WARNING);
    }
}

From source file:org.apigw.monitoring.jms.messagelistener.MonitoringMessageListener.java

private AuthEvent parseJSONToAuthEvent(String message) throws JsonParseException, IOException {
    log.debug("Parsing json message to AuthEvent");
    log.debug("Json message is: " + message);
    AuthEvent event = new AuthEvent();
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> mapObject = mapper.readValue(message, new TypeReference<Map<String, Object>>() {
    });// w ww. j a v  a2s.c om

    if (mapObject.get("timestamp") != null) {
        event.setTimestamp(new Date((Long) mapObject.get("timestamp")));
    }
    if (mapObject.get("eventType") != null) {
        event.setEventType(AuthEventType.getEnum((String) mapObject.get("eventType")));
    }
    if (mapObject.get("state") != null) {
        event.setRequestState(RequestState.valueOf((String) mapObject.get("state")));
    }
    if (mapObject.get("message") != null) {
        event.setMessage((String) mapObject.get("message"));
    }
    if (mapObject.get("user") != null) {
        event.setUser((String) mapObject.get("user"));
    }
    if (mapObject.get("code") != null) {
        event.setCode((String) mapObject.get("code"));
    }
    if (mapObject.get("client") != null) {
        event.setClient((String) mapObject.get("client"));
    }
    if (mapObject.get("id") != null) {
        event.setRequestId((String) mapObject.get("id"));
    }
    if (mapObject.get("token") != null) {
        event.setToken((String) mapObject.get("token"));
    }
    if (mapObject.get("scope") != null) {
        List<String> scopes = (List<String>) mapObject.get("scope");
        event.setScope(StringUtils.collectionToCommaDelimitedString(scopes));
    }

    return event;
}

From source file:org.eclipse.gemini.blueprint.test.AbstractOnTheFlyBundleCreatorTests.java

private void addImportPackage(Manifest manifest) {
    String[] rawImports = determineImports();

    boolean trace = logger.isTraceEnabled();

    if (trace)//  ww w.  j  av a2  s.c  o m
        logger.trace("Discovered raw imports " + ObjectUtils.nullSafeToString(rawImports));

    Collection specialImportsOut = eliminateSpecialPackages(rawImports);
    Collection imports = eliminatePackagesAvailableInTheJar(specialImportsOut);

    if (trace)
        logger.trace("Filtered imports are " + imports);

    manifest.getMainAttributes().putValue(Constants.IMPORT_PACKAGE,
            StringUtils.collectionToCommaDelimitedString(imports));
}