Search in sources :

Example 1 with Reference

use of com.day.cq.wcm.api.reference.Reference in project acs-aem-commons by Adobe-Consulting-Services.

the class PagesReferenceProvider method findReferences.

@Override
public List<Reference> findReferences(Resource resource) {
    List<Reference> references = new ArrayList<Reference>();
    ResourceResolver resolver = resource.getResourceResolver();
    PageManager pageManager = resolver.adaptTo(PageManager.class);
    Set<Page> pages = new HashSet<Page>();
    search(resource, pages, pageManager);
    for (Page page : pages) {
        Resource contentResource = page.getContentResource();
        if (contentResource != null && !contentResource.getPath().equals(resource.getPath())) {
            references.add(getReference(page));
        }
    }
    return references;
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) Reference(com.day.cq.wcm.api.reference.Reference) ArrayList(java.util.ArrayList) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page) HashSet(java.util.HashSet)

Example 2 with Reference

use of com.day.cq.wcm.api.reference.Reference in project acs-aem-commons by Adobe-Consulting-Services.

the class DesignReferenceProvider method findReferences.

@Override
public List<Reference> findReferences(Resource resource) {
    ResourceResolver resourceResolver = resource.getResourceResolver();
    PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
    Designer designer = resourceResolver.adaptTo(Designer.class);
    Page page = pageManager.getContainingPage(resource);
    if (page == null) {
        return Collections.emptyList();
    }
    Design design = designer.getDesign(page);
    if (design == null) {
        return Collections.emptyList();
    }
    return Collections.singletonList(new Reference(TYPE_DESIGN_PAGE, String.format("%s (Design)", design.getId()), design.getContentResource(), getLastModified(design)));
}
Also used : Design(com.day.cq.wcm.api.designer.Design) Designer(com.day.cq.wcm.api.designer.Designer) PageManager(com.day.cq.wcm.api.PageManager) Reference(com.day.cq.wcm.api.reference.Reference) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Page(com.day.cq.wcm.api.Page)

Example 3 with Reference

use of com.day.cq.wcm.api.reference.Reference in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class CaConfigReferenceProviderTest method testDisabled.

@Test
void testDisabled() {
    Resource resource = context.resourceResolver().getResource(TEST_CA_COMPONENT);
    CaConfigReferenceProvider referenceProvider = context.registerInjectActivateService(new CaConfigReferenceProvider(), "enabled", false);
    List<Reference> references = referenceProvider.findReferences(resource);
    assertTrue(references.isEmpty());
}
Also used : Reference(com.day.cq.wcm.api.reference.Reference) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.jupiter.api.Test)

Example 4 with Reference

use of com.day.cq.wcm.api.reference.Reference in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class CaConfigReferenceProviderTest method testNoReferences.

@Test
void testNoReferences() {
    Resource resource = context.resourceResolver().getResource(TEST_NO_CA_COMPONENT);
    assertNotNull(resource);
    List<Reference> references = caConfigReferenceProvider.findReferences(resource);
    assertEquals(0, references.size());
}
Also used : Reference(com.day.cq.wcm.api.reference.Reference) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.jupiter.api.Test)

Example 5 with Reference

use of com.day.cq.wcm.api.reference.Reference in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class CaConfigReferenceProviderTest method testFindReferences.

@Test
void testFindReferences() {
    Resource resource = context.resourceResolver().getResource(TEST_CA_COMPONENT);
    assertNotNull(resource);
    List<Reference> references = caConfigReferenceProvider.findReferences(resource);
    assertEquals(2, references.size());
    Reference reference = getReference(references, HtmlPageItemsConfig.class);
    assertNotNull(reference);
    Resource expectedReferenceRes = context.resourceResolver().getResource(SLING_CONFIGS_ROOT + "/" + HtmlPageItemsConfig.class.getName());
    assertEquals("caconfig", reference.getType());
    if (expectedReferenceRes != null) {
        assertEquals(expectedReferenceRes.getPath(), reference.getResource().getPath());
    }
    assertEquals(1602683813696L, reference.getLastModified());
    reference = getReference(references, DataLayerConfig.class);
    assertNotNull(reference);
    assertEquals(1623074213696L, reference.getLastModified());
}
Also used : Reference(com.day.cq.wcm.api.reference.Reference) Resource(org.apache.sling.api.resource.Resource) DataLayerConfig(com.adobe.cq.wcm.core.components.internal.DataLayerConfig) Test(org.junit.jupiter.api.Test)

Aggregations

Reference (com.day.cq.wcm.api.reference.Reference)6 Resource (org.apache.sling.api.resource.Resource)4 Page (com.day.cq.wcm.api.Page)3 PageManager (com.day.cq.wcm.api.PageManager)3 Test (org.junit.jupiter.api.Test)3 ArrayList (java.util.ArrayList)2 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)2 DataLayerConfig (com.adobe.cq.wcm.core.components.internal.DataLayerConfig)1 Design (com.day.cq.wcm.api.designer.Design)1 Designer (com.day.cq.wcm.api.designer.Designer)1 HashSet (java.util.HashSet)1