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:com.phoenixnap.oss.ramlapisync.plugin.SpringMvcEndpointGeneratorMojo.java

@SuppressWarnings("unchecked")
private Rule<JCodeModel, JDefinedClass, ApiResourceMetadata> loadRule() {
    Rule<JCodeModel, JDefinedClass, ApiResourceMetadata> ruleInstance = new Spring4ControllerStubRule();
    try {/*from w w w  . j a v  a  2  s  . co m*/
        ruleInstance = (Rule<JCodeModel, JDefinedClass, ApiResourceMetadata>) getClassRealm().loadClass(rule)
                .newInstance();
        this.getLog().debug(StringUtils.collectionToCommaDelimitedString(ruleConfiguration.keySet()));
        this.getLog().debug(StringUtils.collectionToCommaDelimitedString(ruleConfiguration.values()));

        if (ruleInstance instanceof ConfigurableRule<?, ?, ?> && !CollectionUtils.isEmpty(ruleConfiguration)) {
            this.getLog().debug("SETTING CONFIG");
            ((ConfigurableRule<?, ?, ?>) ruleInstance).applyConfiguration(ruleConfiguration);
        }
    } catch (Exception e) {
        getLog().error("Could not instantiate Rule " + this.rule
                + ". The default Rule will be used for code generation.", e);
    }
    return ruleInstance;
}

From source file:io.spring.initializr.web.ui.UiController.java

private static Map<String, Object> mapDependency(DependencyItem item) {
    Map<String, Object> result = new HashMap<>();
    Dependency d = item.dependency;//  w  w  w . ja  va  2 s  .  c o  m
    result.put("id", d.getId());
    result.put("name", d.getName());
    result.put("group", item.group);
    if (d.getDescription() != null) {
        result.put("description", d.getDescription());
    }
    if (d.getWeight() > 0) {
        result.put("weight", d.getWeight());
    }
    if (!CollectionUtils.isEmpty(d.getKeywords()) || !CollectionUtils.isEmpty(d.getAliases())) {
        List<String> all = new ArrayList<>(d.getKeywords());
        all.addAll(d.getAliases());
        result.put("keywords", StringUtils.collectionToCommaDelimitedString(all));
    }
    return result;
}

From source file:it.smartcommunitylab.aac.apikey.APIKeyManager.java

/**
 * Update key scopes. //from ww  w .  j av a  2s. c  o  m
 * @param key
 * @param data
 * @return
 * @throws #{@link EntityNotFoundException} if the key does not exists
 */
public APIKey updateKeyScopes(String key, Set<String> scopes) throws EntityNotFoundException {
    APIKeyEntity entity = keyRepo.findOne(key);
    if (entity != null) {
        if (scopes != null) {
            ClientDetailsEntity client = clientRepo.findByClientId(entity.getClientId());
            Set<String> targetScopes = new HashSet<>(scopes);
            targetScopes.retainAll(client.getScope());
            entity.setScope(StringUtils.collectionToCommaDelimitedString(targetScopes));
        }

        keyRepo.save(entity);
        APIKey result = new APIKey(entity);
        log.debug("Update API Key data " + key);
        keyCache.put(key, result);
        return result;
    }
    throw new EntityNotFoundException(key);
}

From source file:it.smartcommunitylab.aac.apikey.APIKeyManager.java

/**
 * Create a new key for the specified client app
 * @param clientId//from   w w  w.  ja v  a 2s  .co  m
 * @param validity
 * @param data
 * @return
 * @throws #{@link EntityNotFoundException} if the specified client does not exist 
 */
public APIKey createKey(String clientId, Long validity, Map<String, Object> data, Set<String> scopes)
        throws EntityNotFoundException {
    ClientDetailsEntity client = clientRepo.findByClientId(clientId);
    if (client == null)
        throw new EntityNotFoundException("Client not found: " + clientId);

    APIKeyEntity entity = new APIKeyEntity();
    entity.setAdditionalInformation(APIKey.toDataString(data));
    entity.setValidity(validity);
    entity.setClientId(clientId);
    entity.setApiKey(UUID.randomUUID().toString());
    entity.setIssuedTime(System.currentTimeMillis());
    entity.setUserId(client.getDeveloperId());
    entity.setUsername(userManager.getUserInternalName(client.getDeveloperId()));
    entity.setRoles(APIKey.toRolesString(userManager.getUserRoles(client.getDeveloperId())));
    if (scopes != null && !scopes.isEmpty()) {
        Set<String> targetScopes = new HashSet<>(scopes);
        targetScopes.retainAll(client.getScope());
        entity.setScope(StringUtils.collectionToCommaDelimitedString(targetScopes));
    }
    keyRepo.save(entity);
    log.debug("Saved API Key  " + entity.getApiKey());

    APIKey result = new APIKey(entity);
    keyCache.put(result.getApiKey(), result);
    return result;
}

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

@RequestMapping(value = "/admin/approvals/{clientId}", method = RequestMethod.POST)
public @ResponseBody Response approve(@PathVariable String clientId) throws Exception {
    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);//ww  w  . j a va  2 s . c o m
            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();
}

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

/**
 * Save permissions requested by the app.
 * @param permissions//from w  ww .ja v a2s .c om
 * @param clientId
 * @param serviceId
 * @return {@link Response} entity containing the processed app {@link Permissions} descriptor
 * @throws Exception 
 */
@RequestMapping(value = "/dev/permissions/{clientId}/{serviceId:.*}", method = RequestMethod.PUT)
public @ResponseBody Response savePermissions(@RequestBody Permissions permissions,
        @PathVariable String clientId, @PathVariable String serviceId) throws Exception {
    Response response = new Response();
    // check that the client is owned by the current user
    userManager.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));

    return response;

}

From source file:it.smartcommunitylab.aac.manager.ClientDetailsManager.java

/**
 * Convert DB object to the simplified client representation
 * @param e/*  w  w w.  ja v  a 2s  .  c  o  m*/
 * @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());
    res.setUserName(e.getDeveloperId().toString());
    // 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);
    }

    res.setName(e.getName());
    res.setDisplayName(res.getName());
    res.setScope(Joiner.on(",").join(e.getScope()));
    res.setParameters(e.getParameters());
    res.setMobileAppSchema(e.getMobileAppSchema());

    ClientAppInfo info = ClientAppInfo.convert(e.getAdditionalInformation());
    if (info != null) {
        res.setDisplayName(info.getDisplayName());
        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;
                }
            }
        }
        res.setProviderConfigurations(info.getProviderConfigurations());
    }

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

From source file:it.smartcommunitylab.aac.manager.ClientDetailsManager.java

/**
 * Fill in the DB object with the properties of {@link ClientAppBasic} instance. In case of problem, return null.
 * @param client/*  www.j a  va 2  s  .  c o m*/
 * @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.setDisplayName(data.getDisplayName());
        if (StringUtils.hasText(data.getMobileAppSchema())) {
            client.setMobileAppSchema(data.getMobileAppSchema());
        } else {
            client.setMobileAppSchema(generateSchema(client.getClientId()));
        }
        Set<String> types = data.getGrantedTypes();
        client.setAuthorizedGrantTypes(StringUtils.collectionToCommaDelimitedString(types));
        if (info.getIdentityProviders() == null) {
            info.setIdentityProviders(new HashMap<String, Integer>());
        }

        if (data.getIdentityProviders() != null) {
            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);
                }
                if (data.getProviderConfigurations() != null
                        && data.getProviderConfigurations().containsKey(key)) {
                    if (info.getProviderConfigurations() == null)
                        info.setProviderConfigurations(new HashMap<>());
                    info.getProviderConfigurations().put(key, data.getProviderConfigurations().get(key));
                }
            }
        }

        client.setAdditionalInformation(info.toJson());
        client.setRedirectUri(Utils.normalizeValues(data.getRedirectUris()));

        if (data.getScope() != null) {
            client.setScope(data.getScope());

            String resourcesId = "";
            for (String resource : client.getScope()) {
                it.smartcommunitylab.aac.model.Resource r = resourceRepository.findByResourceUri(resource);
                if (r != null) {
                    resourcesId += "," + r.getResourceId();
                }
            }
            resourcesId = resourcesId.replaceFirst(",", "");
            client.setResourceIds(resourcesId);
        }

        client.setParameters(data.getParameters());
    } catch (Exception e) {
        log.error("failed to convert an object: " + e.getMessage(), e);
        return null;
    }
    return client;
}

From source file:org.alfresco.repo.forms.processor.node.PropertyFieldProcessor.java

@Override
public Object getValue(QName name, ContentModelItemData<?> data) {
    Serializable value = data.getPropertyValue(name);
    if (value == null) {
        return getDefaultValue(name, data);
    }//from   www .j  av a 2  s  . com

    if (value instanceof Collection<?>) {
        // temporarily add repeating field data as a comma
        // separated list, this will be changed to using
        // a separate field for each value once we have full
        // UI support in place.
        Collection<?> values = (Collection<?>) value;

        // if the non empty collection is a List of Date objects 
        // we need to convert each date to a ISO8601 format 
        if (value instanceof List<?> && !values.isEmpty()) {
            List<?> list = (List<?>) values;
            if (list.get(0) instanceof Date) {
                List<String> isoDates = new ArrayList<String>(list.size());
                for (Object date : list) {
                    isoDates.add(ISO8601DateFormat.format((Date) date));
                }

                // return the ISO formatted dates as a comma delimited string 
                return StringUtils.collectionToCommaDelimitedString(isoDates);
            }
        }

        // return everything else using toString()
        return StringUtils.collectionToCommaDelimitedString(values);
    } else if (value instanceof ContentData) {
        // for content properties retrieve the info URL rather than the
        // the object value itself
        ContentData contentData = (ContentData) value;
        return contentData.getInfoUrl();
    } else if (value instanceof NodeRef) {
        return ((NodeRef) value).toString();
    }

    return value;
}

From source file:org.cloudfoundry.identity.uaa.integration.UaaTestAccounts.java

public ClientDetails getClientDetails(String prefix, BaseClientDetails defaults) {
    String clientId = environment.getProperty(prefix + ".id", defaults.getClientId());
    String clientSecret = environment.getProperty(prefix + ".secret", defaults.getClientSecret());
    String resourceIds = environment.getProperty(prefix + ".resource-ids",
            StringUtils.collectionToCommaDelimitedString(defaults.getResourceIds()));
    String scopes = environment.getProperty(prefix + ".scope",
            StringUtils.collectionToCommaDelimitedString(defaults.getScope()));
    String grantTypes = environment.getProperty(prefix + ".authorized-grant-types",
            StringUtils.collectionToCommaDelimitedString(defaults.getAuthorizedGrantTypes()));
    String authorities = environment.getProperty(prefix + ".authorities",
            StringUtils.collectionToCommaDelimitedString(defaults.getAuthorities()));
    String redirectUris = environment.getProperty(prefix + ".redirect-uri",
            StringUtils.collectionToCommaDelimitedString(defaults.getRegisteredRedirectUri()));
    BaseClientDetails result = new BaseClientDetails(resourceIds, scopes, grantTypes, authorities,
            redirectUris);//  w  w w . j  a va2  s  . com
    result.setClientId(clientId);
    result.setClientSecret(clientSecret);
    return result;
}