List of usage examples for org.springframework.web.util UriTemplate getVariableNames
public List<String> getVariableNames()
From source file:tv.arte.resteventapi.core.presentation.decoration.RestEventApiControllerLinkBuilder.java
public static String linkTo(Class<?> controller, Method method, Map<String, ?> parameters, ConversionService conversionService) { Assert.notNull(controller, "Controller type must not be null!"); Assert.notNull(method, "Method must not be null!"); RestEventApiControllerLinkBuilder linkBuilder = new RestEventApiControllerLinkBuilder(getBuilder()); if (parameters == null) { parameters = new HashMap<String, Object>(1); }/*from w ww . ja v a 2 s .c o m*/ UriTemplate template = new UriTemplate(DISCOVERER.getMapping(controller, method)); URI uri = template.expand(parameters); linkBuilder = linkBuilder.slash(uri); List<String> templateVariables = template.getVariableNames(); for (Entry<String, ?> paramEnt : parameters.entrySet()) { if (!templateVariables.contains(paramEnt.getKey())) { String queryParamName = paramEnt.getKey(); Object queryParamValue = null; if (paramEnt.getValue() != null) { queryParamValue = conversionService.convert(paramEnt.getValue(), String.class); } if (queryParamValue != null) { linkBuilder.uriBuilder.queryParam(queryParamName, queryParamValue); } } } return linkBuilder.uriBuilder.build().toUriString(); }
From source file:eu.trentorise.smartcampus.permissionprovider.manager.ResourceAdapter.java
/** * @param rm//from ww w. j a v a 2s . com * @return true if the mapping definition is parametric to the service resource parameters */ private boolean isParametric(ResourceMapping rm) { UriTemplate template = new UriTemplate(rm.getUri()); return template.getVariableNames() != null && template.getVariableNames().size() > 0; }
From source file:eu.trentorise.smartcampus.permissionprovider.manager.ResourceAdapter.java
/** * Find all the resource uris derived from the specified resource parameter and its parent parameters. * @param rpdb/*from w w w . jav a 2 s. c om*/ * @return map with URIs as the keys and mapping definitions as values. */ private Map<String, ResourceMapping> findResourceURIs(ResourceParameter rpdb) { Map<String, ResourceMapping> res = new HashMap<String, ResourceMapping>(); Map<String, String> params = new HashMap<String, String>(); params.put(rpdb.getResourceId(), rpdb.getValue()); // the service where parameter is defined Service service = serviceMap.get(rpdb.getServiceId()); if (service == null) { throw new IllegalArgumentException("Service " + rpdb.getServiceId() + " is not found."); } // all the service resource mappings List<ResourceMapping> list = flatServiceMappings.get(service.getId()); if (list != null) { for (ResourceMapping rm : list) { UriTemplate template = new UriTemplate(rm.getUri()); // if the extracted parameters contain all the template parameters, the mapping is updated if (template.getVariableNames() != null) { if (new HashSet<String>(template.getVariableNames()).equals(params.keySet())) { URI uri = template.expand(params); res.put(uri.toString(), rm); } } } } return res; }
From source file:eu.trentorise.smartcampus.permissionprovider.manager.ResourceManager.java
/** * Find all the resource uris derived from the specified resource parameter and its parent parameters. * @param rpdb/*w w w. jav a 2 s . c o m*/ * @return map with URIs as the keys and mapping definitions as values. */ private Map<String, ResourceMapping> findResourceURIs(ResourceParameter rpdb) { Map<String, ResourceMapping> res = new HashMap<String, ResourceMapping>(); Map<String, String> params = new HashMap<String, String>(); params.put(rpdb.getParameter(), rpdb.getValue()); // the service where parameter is defined ServiceDescriptor sd = rpdb.getService(); if (sd == null) { throw new IllegalArgumentException("ServiceDescriptor is not found."); } Service s = Utils.toServiceObject(sd); // all the service resource mappings List<ResourceMapping> list = s.getResourceMapping(); if (list != null) { for (ResourceMapping rm : list) { UriTemplate template = new UriTemplate(rm.getUri()); // if the extracted parameters contain all the template parameters, the mapping is updated if (template.getVariableNames() != null) { if (new HashSet<String>(template.getVariableNames()).equals(params.keySet())) { URI uri = template.expand(params); res.put(uri.toString(), rm); } } } } return res; }