@Test public void testRootCategory() { Resource root = provider.getResource(resolveContext, CATALOG_ROOT_PATH, null, null); assertNotNull(root); ValueMap valueMap = root.adaptTo(ValueMap.class); assertEquals(MockGraphqlDataServiceConfiguration.ROOT_CATEGORY_ID, valueMap.get(CIF_ID)); assertEquals(RootCategoryResource.RESOURCE_TYPE, valueMap.get(PROPERTY_RESOURCE_TYPE)); assertEquals(RootCategoryResource.RESOURCE_TYPE, root.getResourceType()); assertEquals(CATEGORY, valueMap.get(PN_COMMERCE_TYPE)); assertEquals(MockGraphqlDataServiceConfiguration.ROOT_CATEGORY_ID, valueMap.get("./" + CIF_ID)); assertNull(root.adaptTo(Product.class)); Node rootNode = mock(Node.class); when(rootResource.adaptTo(Node.class)).thenReturn(rootNode); assertEquals(rootNode, root.adaptTo(Node.class)); RootCategoryResource rootCategoryResource = (RootCategoryResource) root; assertEquals(rootNode, rootCategoryResource.adaptToNode(new StackTraceElement[0])); StackTraceElement[] stackTrace = { new StackTraceElement("AClass", "aMethod", "aFile", 1), new StackTraceElement("AClass", "aMethod", "aFile", 1), new StackTraceElement("AClass", "aMethod", "aFile", 1), new StackTraceElement("AClass", "aMethod", "aFile", 1) }; assertEquals(rootNode, rootCategoryResource.adaptToNode(stackTrace)); String callerClass = "com.day.cq.dam.core.impl.servlet.FolderThumbnailServlet"; String callerMethod = "getPreviewGenerator"; stackTrace[2] = new StackTraceElement(callerClass, callerMethod, "", 0); assertNull(rootCategoryResource.adaptToNode(stackTrace)); }
@Override public Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext resourceContext, Resource parent) { LOGGER.debug("getResource called for " + path); if (path.equals(root)) { Resource resource = ctx.getParentResourceProvider().getResource( (ResolveContext) ctx.getParentResolveContext(), path, resourceContext, parent); if (resource == null) { return null; } else { return new RootCategoryResource(resource, rootCategoryId); } } if (path.contains(JcrConstants.JCR_CONTENT) || path.endsWith(".jpg") || path.contains("assets") || path.contains("thumbnail") || path.contains("rep:policy")) { return null; } ResourceResolver resolver = ctx.getResourceResolver(); CategoryResource category = resourceMapper.resolveCategory(resolver, path); if (category != null) { return category; } else { Resource resource; if (path.endsWith("/image")) { resource = resourceMapper.resolveProductImage(resolver, path); } else { resource = resourceMapper.resolveProduct(resolver, path); } return resource; } }
GraphqlResourceProvider extends ResourceProvider<Object> { @Override public Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext resourceContext, Resource parent) { LOGGER.debug("getResource called for " + path); if (path.equals(root)) { Resource resource = ctx.getParentResourceProvider().getResource( (ResolveContext) ctx.getParentResolveContext(), path, resourceContext, parent); if (resource == null) { return null; } else { return new RootCategoryResource(resource, rootCategoryId); } } if (path.contains(JcrConstants.JCR_CONTENT) || path.endsWith(".jpg") || path.contains("assets") || path.contains("thumbnail") || path.contains("rep:policy")) { return null; } ResourceResolver resolver = ctx.getResourceResolver(); CategoryResource category = resourceMapper.resolveCategory(resolver, path); if (category != null) { return category; } else { Resource resource; if (path.endsWith("/image")) { resource = resourceMapper.resolveProductImage(resolver, path); } else { resource = resourceMapper.resolveProduct(resolver, path); } return resource; } } }
GraphqlResourceProvider extends ResourceProvider<Object> { @Override public Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext resourceContext, Resource parent) { LOGGER.debug("getResource called for " + path); if (path.equals(root)) { Resource resource = ctx.getParentResourceProvider().getResource( (ResolveContext) ctx.getParentResolveContext(), path, resourceContext, parent); if (resource == null) { return null; } else { return new RootCategoryResource(resource, rootCategoryId); } } if (path.contains(JcrConstants.JCR_CONTENT) || path.endsWith(".jpg") || path.contains("assets") || path.contains("thumbnail") || path.contains("rep:policy")) { return null; } ResourceResolver resolver = ctx.getResourceResolver(); CategoryResource category = resourceMapper.resolveCategory(resolver, path); if (category != null) { return category; } else { Resource resource; if (path.endsWith("/image")) { resource = resourceMapper.resolveProductImage(resolver, path); } else { resource = resourceMapper.resolveProduct(resolver, path); } return resource; } } GraphqlResourceProvider(String root, GraphqlDataService graphqlDataService, Map<String, String> properties); }
GraphqlResourceProvider extends ResourceProvider<Object> { @Override public Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext resourceContext, Resource parent) { LOGGER.debug("getResource called for " + path); if (path.equals(root)) { Resource resource = ctx.getParentResourceProvider().getResource( (ResolveContext) ctx.getParentResolveContext(), path, resourceContext, parent); if (resource == null) { return null; } else { return new RootCategoryResource(resource, rootCategoryId); } } if (path.contains(JcrConstants.JCR_CONTENT) || path.endsWith(".jpg") || path.contains("assets") || path.contains("thumbnail") || path.contains("rep:policy")) { return null; } ResourceResolver resolver = ctx.getResourceResolver(); CategoryResource category = resourceMapper.resolveCategory(resolver, path); if (category != null) { return category; } else { Resource resource; if (path.endsWith("/image")) { resource = resourceMapper.resolveProductImage(resolver, path); } else { resource = resourceMapper.resolveProduct(resolver, path); } return resource; } } GraphqlResourceProvider(String root, GraphqlDataService graphqlDataService, Map<String, String> properties); @Override Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext resourceContext, Resource parent); @Override Iterator<Resource> listChildren(ResolveContext<Object> ctx, Resource parent); @Override GraphqlQueryLanguageProvider getQueryLanguageProvider(); }
GraphqlResourceProvider extends ResourceProvider<Object> { @Override public Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext resourceContext, Resource parent) { LOGGER.debug("getResource called for " + path); if (path.equals(root)) { Resource resource = ctx.getParentResourceProvider().getResource( (ResolveContext) ctx.getParentResolveContext(), path, resourceContext, parent); if (resource == null) { return null; } else { return new RootCategoryResource(resource, rootCategoryId); } } if (path.contains(JcrConstants.JCR_CONTENT) || path.endsWith(".jpg") || path.contains("assets") || path.contains("thumbnail") || path.contains("rep:policy")) { return null; } ResourceResolver resolver = ctx.getResourceResolver(); CategoryResource category = resourceMapper.resolveCategory(resolver, path); if (category != null) { return category; } else { Resource resource; if (path.endsWith("/image")) { resource = resourceMapper.resolveProductImage(resolver, path); } else { resource = resourceMapper.resolveProduct(resolver, path); } return resource; } } GraphqlResourceProvider(String root, GraphqlDataService graphqlDataService, Map<String, String> properties); @Override Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext resourceContext, Resource parent); @Override Iterator<Resource> listChildren(ResolveContext<Object> ctx, Resource parent); @Override GraphqlQueryLanguageProvider getQueryLanguageProvider();  }