Java Code Examples for org.springframework.web.util.UriTemplate#match()

The following examples show how to use org.springframework.web.util.UriTemplate#match() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RestScriptsController.java    From engine with GNU General Public License v3.0 6 votes vote down vote up
protected String parseScriptUrlForVariables(SiteContext siteContext, String scriptUrl,
                                            Map<String, Object> variables) {
    ContentStoreService storeService = siteContext.getStoreService();
    if (!storeService.exists(siteContext.getContext(), scriptUrl) && urlTemplateScanner != null) {
        List<UriTemplate> urlTemplates = urlTemplateScanner.scan(siteContext);
        if (CollectionUtils.isNotEmpty(urlTemplates)) {
            for (UriTemplate template : urlTemplates) {
                if (template.matches(scriptUrl)) {
                    Map<String, String> pathVars = template.match(scriptUrl);
                    String actualScriptUrl = template.toString();

                    variables.put(GroovyScriptUtils.VARIABLE_PATH_VARS, pathVars);

                    return actualScriptUrl;
                }
            }
        }
    }

    return scriptUrl;
}
 
Example 2
Source File: RestResourceHelper.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
private Map<String, String> getMatchList(final UriInfo uriInfo, final ResourceTemplate template) {
    final UriTemplate uriTemplate = new UriTemplate(template.getTemplate());
    String path = uriInfo.getRequestUri().getPath();
    if (path.endsWith("/")) {
        path = path.substring(0, (path.length() - 1));
    }
    return uriTemplate.match(path);
}
 
Example 3
Source File: FacilityUtil.java    From moserp with Apache License 2.0 4 votes vote down vote up
public String getFacilityIdFromUri(String facilityUri) {
    UriTemplate uriTemplate = new UriTemplate("/facilities/{facilityId}");
    Map<String, String> variables = uriTemplate.match(facilityUri);
    String facilityId = variables.get("facilityId");
    return facilityId;
}
 
Example 4
Source File: BaseWebInventoryTest.java    From moserp with Apache License 2.0 4 votes vote down vote up
public String getProductIdFromUri(String productURI) {
    UriTemplate uriTemplate = new UriTemplate("/products/{productId}");
    Map<String, String> variables = uriTemplate.match(productURI);
    return variables.get("productId");
}
 
Example 5
Source File: ProductUtil.java    From moserp with Apache License 2.0 4 votes vote down vote up
public String getProductIdFromUri(String productURI) {
    UriTemplate uriTemplate = new UriTemplate("/products/{productId}");
    Map<String, String> variables = uriTemplate.match(productURI);
    return variables.get("productId");
}
 
Example 6
Source File: URITranslator.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
public String translate(String requestPath) {
    final UriTemplate uriTemplate = new UriTemplate(pattern);
    Map<String, String> matchList = uriTemplate.match(requestPath);
    if (matchList.isEmpty() || ignorePatternList(requestPath)) {
        return requestPath;
    }

    List<String> translatedIdList = new ArrayList<String>();
    if (useProvidedId) {
        String[] ids = matchList.get("id").split(",");
        translatedIdList.addAll(Arrays.asList(ids));
    } else {

        NeutralQuery neutralQuery = new NeutralQuery();
        neutralQuery.addCriteria(new NeutralCriteria(referenceKey, "in", Arrays.asList(matchList.get("id"))));
        neutralQuery.setOffset(0);
        neutralQuery.setLimit(0);
        Iterable<Entity> entities = repository.findAll(parentEntity, neutralQuery);

        for (Entity entity : entities) {
            if (key.equals("_id")) {
                translatedIdList.add(entity.getEntityId());
            } else if (entity.getBody().containsKey(key)) {
                Object value = entity.getBody().get(key);
                if (value instanceof String) {
                    translatedIdList.add((String) value);
                } else if (value instanceof List<?>) {
                    for (String id : (List<String>) value) {
                        translatedIdList.add(id);
                    }
                }
            }
        }
        if (translatedIdList.isEmpty()) {
            LOG.warn("Failed upversioning rewrite {} -> {} due not being able to find intermediate entities", requestPath, this.transformTo);
            throw new URITranslationException("Upversioning rewrite failed.  No target entities found.");
        }
    }

    return buildTranslatedPath(translatedIdList);
}