org.apache.sling.api.request.RequestPathInfo Java Examples
The following examples show how to use
org.apache.sling.api.request.RequestPathInfo.
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: GraphqlProductViewHandlerTest.java From commerce-cif-connector with Apache License 2.0 | 7 votes |
@Before public void setUp() { servletRequest = Mockito.mock(SlingHttpServletRequest.class); resourceResolver = Mockito.mock(ResourceResolver.class); Mockito.when(servletRequest.getResourceResolver()).thenReturn(resourceResolver); tagManager = Mockito.mock(TagManager.class); Mockito.when(resourceResolver.adaptTo(TagManager.class)).thenReturn(tagManager); commerceBasePathsService = Mockito.mock(CommerceBasePathsService.class); Mockito.when(resourceResolver.adaptTo(CommerceBasePathsService.class)).thenReturn(commerceBasePathsService); Mockito.when(commerceBasePathsService.getProductsBasePath()).thenReturn("/var/commerce/products"); requestPathInfo = Mockito.mock(RequestPathInfo.class); Mockito.when(servletRequest.getRequestPathInfo()).thenReturn(requestPathInfo); Mockito.when(requestPathInfo.getSuffix()).thenReturn("/var/commerce/products"); omniSearchHandler = Mockito.mock(OmniSearchHandler.class); searchResult = Mockito.mock(SearchResult.class); viewHandler = new GraphqlProductViewHandler(); viewHandler.omniSearchHandler = omniSearchHandler; Mockito.when(omniSearchHandler.getResults(resourceResolver, null, 0, 0)).thenReturn(searchResult); }
Example #2
Source File: UrlBuilder.java From sling-org-apache-sling-dynamic-include with Apache License 2.0 | 6 votes |
public static String buildUrl(String includeSelector, String resourceType, boolean synthetic, Configuration config, RequestPathInfo pathInfo) { final StringBuilder builder = new StringBuilder(); final String resourcePath = pathInfo.getResourcePath(); builder.append(resourcePath); String currentSelectorString = StringUtils.defaultString(pathInfo.getSelectorString()); if (pathInfo.getSelectorString() != null) { builder.append('.').append(currentSelectorString); } if (includeSelectorNotAlreadyPresent(pathInfo.getSelectors(), includeSelector)) { builder.append('.').append(includeSelector); } builder.append('.').append(pathInfo.getExtension()); if (synthetic) { builder.append('/').append(resourceType); if (config.hasExtensionSet()) { builder.append('.').append(config.getExtension()); } } else { if (config.isAppendSuffix()) { builder.append(StringUtils.defaultString(pathInfo.getSuffix())); } } return builder.toString(); }
Example #3
Source File: FieldInitializerTest.java From commerce-cif-connector with Apache License 2.0 | 5 votes |
@Before public void setUp() { SlingScriptHelper sling = mock(SlingScriptHelper.class); bindings.put(SlingBindings.SLING, sling); ExpressionResolver expressionResolver = mock(ExpressionResolver.class); when(expressionResolver.resolve(anyString(), any(), any(), (SlingHttpServletRequest) any())).thenAnswer( invocationOnMock -> invocationOnMock.getArguments()[0]); when(sling.getService(ExpressionResolver.class)).thenReturn(expressionResolver); CommerceBasePathsService pathService = mock(CommerceBasePathsService.class); when(pathService.getProductsBasePath()).thenReturn(PRODUCTS_BASE_PATH); when(sling.getService(CommerceBasePathsService.class)).thenReturn(pathService); doAnswer(invocationOnMock -> { includedResourceSample = (Resource) invocationOnMock.getArguments()[0]; return null; }).when(sling).include(any(Resource.class)); request = mock(SlingHttpServletRequest.class); when(request.getRequestURI()).thenReturn("some_request_uri"); bindings.put(SlingBindings.REQUEST, request); requestPathInfo = mock(RequestPathInfo.class); when(request.getRequestPathInfo()).thenReturn(requestPathInfo); valueMap = new ModifiableValueMapDecorator(new HashMap<>()); bindings.put(WCMBindingsConstants.NAME_PROPERTIES, valueMap); ResourceResolver resourceResolver = mock(ResourceResolver.class); when(request.getResourceResolver()).thenReturn(resourceResolver); PageManager pageManager = mock(PageManager.class); when(resourceResolver.adaptTo(PageManager.class)).thenReturn(pageManager); Page page = mock(Page.class); when(pageManager.getContainingPage(anyString())).thenReturn(page); contentResource = mock(Resource.class); contentResourceProperties = new ModifiableValueMapDecorator(new HashMap<>()); when(contentResource.getValueMap()).thenReturn(contentResourceProperties); when(page.getContentResource()).thenReturn(contentResource); }
Example #4
Source File: ConstructorTest.java From sling-org-apache-sling-models-impl with Apache License 2.0 | 5 votes |
@Test public void testViaInjectionModel() throws Exception { Resource suffixResource = mock(Resource.class); when(suffixResource.getPath()).thenReturn("/the/suffix"); RequestPathInfo requestPathInfo = mock(RequestPathInfo.class); when(requestPathInfo.getSuffixResource()).thenReturn(suffixResource); when(request.getRequestPathInfo()).thenReturn(requestPathInfo); ViaRequestSuffixModel model = factory.getAdapter(request, ViaRequestSuffixModel.class); assertThat(model, Matchers.notNullValue()); assertThat(model.getSuffix(), Matchers.is("/the/suffix")); }
Example #5
Source File: GraphqlProductViewHandler.java From commerce-cif-connector with Apache License 2.0 | 4 votes |
@Override protected ViewQuery createQuery(SlingHttpServletRequest request, Session session, String queryString) throws RepositoryException { queryString = preserveWildcards(queryString); PredicateGroup gqlPredicateGroup = PredicateConverter.createPredicatesFromGQL(queryString); ResourceResolver resolver = request.getResourceResolver(); tagManager = resolver.adaptTo(TagManager.class); Set<String> predicateSet = customizePredicateGroup(gqlPredicateGroup); // set default start path RequestPathInfo pathInfo = request.getRequestPathInfo(); CommerceBasePathsService cbps = resolver.adaptTo(CommerceBasePathsService.class); String defaultStartPath = cbps.getProductsBasePath(); String startPath = (pathInfo.getSuffix() != null && pathInfo.getSuffix().startsWith(defaultStartPath)) ? pathInfo.getSuffix() : defaultStartPath; if (!predicateSet.contains(PathPredicateEvaluator.PATH)) { gqlPredicateGroup.add(new Predicate(PathPredicateEvaluator.PATH).set(PathPredicateEvaluator.PATH, startPath)); } String refererHeader = request.getHeader(REFERER_HEADER); if (StringUtils.isNotBlank(refererHeader) && refererHeader.contains(PAGE_EDITOR_PATH + "/")) { int p = refererHeader.lastIndexOf(PAGE_EDITOR_PATH); String pagePath = refererHeader.substring(p + PAGE_EDITOR_PATH.length()); if (pagePath.endsWith(".html")) { pagePath = pagePath.substring(0, pagePath.length() - ".html".length()); } CatalogSearchSupport catalogSearch = new CatalogSearchSupport(resolver); String catalogPath = catalogSearch.findCatalogPath(pagePath); String rootCategoryId = catalogSearch.findCategoryId(catalogPath); if (rootCategoryId != null) { gqlPredicateGroup.add(new Predicate(CATEGORY_ID_PARAMETER).set(CATEGORY_ID_PARAMETER, rootCategoryId)); gqlPredicateGroup.add(new Predicate(CATEGORY_PATH_PARAMETER).set(CATEGORY_PATH_PARAMETER, catalogPath)); } } else { LOGGER.warn("The path of the edited page cannot be determined"); } // append node type constraint to match product data index /etc/commerce/oak:index/commerce gqlPredicateGroup.add(new Predicate(TypePredicateEvaluator.TYPE).set(TypePredicateEvaluator.TYPE, NT_UNSTRUCTURED)); // append limit constraint if (gqlPredicateGroup.get(Predicate.PARAM_LIMIT) == null) { String limit = request.getParameter(LIMIT); if ((limit != null) && (!limit.equals(""))) { int offset = Integer.parseInt(StringUtils.substringBefore(limit, "..")); int total = Integer.parseInt(StringUtils.substringAfter(limit, "..")); gqlPredicateGroup.set(Predicate.PARAM_LIMIT, Long.toString(total - offset)); gqlPredicateGroup.set(Predicate.PARAM_OFFSET, Long.toString(offset)); } else { gqlPredicateGroup.set(Predicate.PARAM_LIMIT, Long.toString(DEFAULT_LIMIT)); } } // add product property constraint addProductConstraint(gqlPredicateGroup); // append order constraint if (!predicateSet.contains(Predicate.ORDER_BY)) { gqlPredicateGroup.add(new Predicate(Predicate.ORDER_BY) .set(Predicate.ORDER_BY, "@" + JCR_LASTMODIFIED) .set(Predicate.PARAM_SORT, Predicate.SORT_DESCENDING)); } return new GQLViewQuery(resolver, omniSearchHandler, xssAPI, gqlPredicateGroup); }