use of com.day.cq.wcm.api.components.ComponentManager in project acs-aem-commons by Adobe-Consulting-Services.
the class SharedComponentPropertiesBindingsValuesProviderTest method setUp.
@Before
public void setUp() throws Exception {
resource = mock(Resource.class);
pageRootProvider = mock(PageRootProvider.class);
page = mock(Page.class);
bindings = new SimpleBindings();
component = mock(Component.class);
sharedPropsResource = mock(Resource.class);
globalPropsResource = mock(Resource.class);
resourceResolver = mock(ResourceResolver.class);
componentManager = mock(ComponentManager.class);
String globalPropsPath = SITE_ROOT + "/jcr:content/" + SharedComponentProperties.NN_GLOBAL_COMPONENT_PROPERTIES;
String sharedPropsPath = SITE_ROOT + "/jcr:content/" + SharedComponentProperties.NN_SHARED_COMPONENT_PROPERTIES + "/" + RESOURCE_TYPE;
bindings.put("resource", resource);
when(resource.getResourceResolver()).thenReturn(resourceResolver);
when(resourceResolver.getResource(sharedPropsPath)).thenReturn(sharedPropsResource);
when(resourceResolver.getResource(globalPropsPath)).thenReturn(globalPropsResource);
when(resourceResolver.adaptTo(ComponentManager.class)).thenReturn(componentManager);
when(componentManager.getComponentOfResource(resource)).thenReturn(component);
when(page.getPath()).thenReturn(SITE_ROOT);
when(pageRootProvider.getRootPage(resource)).thenReturn(page);
when(component.getResourceType()).thenReturn(RESOURCE_TYPE);
when(sharedPropsResource.getName()).thenReturn("Shared Properties Resource");
when(globalPropsResource.getName()).thenReturn("Global Properties Resource");
sharedProps = new ValueMapDecorator(new HashMap<String, Object>());
globalProps = new ValueMapDecorator(new HashMap<String, Object>());
sharedProps.put("shared", "value");
globalProps.put("global", "value");
when(globalPropsResource.getValueMap()).thenReturn(globalProps);
when(sharedPropsResource.getValueMap()).thenReturn(sharedProps);
}
use of com.day.cq.wcm.api.components.ComponentManager in project acs-aem-commons by Adobe-Consulting-Services.
the class SharedComponentPropertiesPageInfoProvider method updateSharedComponentsMap.
/**
* Traverse the entire set of components in the /apps directory and create a map of all component types
* that have shared/global config dialogs.
*
* This is used by the JS libs in the authoring interface to determine if a component should show the
* options for editing shared/global configs.
*/
private void updateSharedComponentsMap() {
ResourceResolver resourceResolver = null;
try {
log.debug("Calculating map of components with shared properties dialogs");
Map<String, Object> authInfo = Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, (Object) SERVICE_NAME);
resourceResolver = resourceResolverFactory.getServiceResourceResolver(authInfo);
resourceResolver.refresh();
ComponentManager componentManager = resourceResolver.adaptTo(ComponentManager.class);
Map<String, List<Boolean>> localComponentsWithSharedProperties = new HashMap<>();
for (Component component : componentManager.getComponents()) {
if (component.getPath().startsWith("/apps")) {
boolean hasSharedDialogForTouch = componentHasTouchDialog(component, "dialogshared");
boolean hasGlobalDialogForTouch = componentHasTouchDialog(component, "dialogglobal");
boolean hasSharedDialogForClassic = componentHasClassicDialog(component, "dialog_shared");
boolean hasGlobalDialogForClassic = componentHasClassicDialog(component, "dialog_global");
if (hasSharedDialogForTouch || hasGlobalDialogForTouch || hasSharedDialogForClassic || hasGlobalDialogForClassic) {
localComponentsWithSharedProperties.put(component.getResourceType(), Arrays.asList(hasSharedDialogForTouch, hasGlobalDialogForTouch, hasSharedDialogForClassic, hasGlobalDialogForClassic));
}
}
}
componentsWithSharedProperties = Collections.unmodifiableMap(localComponentsWithSharedProperties);
log.debug("Calculated map of components with shared properties dialogs: {}", componentsWithSharedProperties);
} catch (org.apache.sling.api.resource.LoginException e) {
log.error("Unable to log into service user to determine list of components with shared properties dialogs", e);
} catch (RepositoryException e) {
log.error("Unexpected error attempting to determine list of components with shared properties dialogs", e);
} finally {
if (resourceResolver != null) {
resourceResolver.close();
}
}
}
use of com.day.cq.wcm.api.components.ComponentManager in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServlet method getContentPolicy.
/**
* Returns the content policy bound to the given component.
*
* @param imageResource the resource identifying the accessed image component
* @return the content policy. May be {@code nulll} in case no content policy can be found.
*/
private ContentPolicy getContentPolicy(@NotNull Resource imageResource) {
ResourceResolver resourceResolver = imageResource.getResourceResolver();
ContentPolicyManager policyManager = resourceResolver.adaptTo(ContentPolicyManager.class);
if (policyManager != null) {
ComponentManager componentManager = resourceResolver.adaptTo(ComponentManager.class);
if (componentManager != null) {
com.day.cq.wcm.api.components.Component component = componentManager.getComponentOfResource(imageResource);
if (component != null && component.getProperties() != null) {
String delegatingResourceType = component.getProperties().get(AbstractImageDelegatingModel.IMAGE_DELEGATE, String.class);
if (StringUtils.isNotEmpty(delegatingResourceType)) {
imageResource = new CoreResourceWrapper(imageResource, delegatingResourceType);
}
}
}
return policyManager.getPolicy(imageResource);
} else {
LOGGER.warn("Could not get policy manager from resource resolver!");
}
return null;
}
use of com.day.cq.wcm.api.components.ComponentManager in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AbstractContainerImpl method getChildren.
/**
* Return (and cache) the list of children resources that are components
*
* @return List of all children resources that are components.
*/
@NotNull
protected List<Resource> getChildren() {
if (childComponents == null) {
Resource effectiveResource = this.getEffectiveResource();
childComponents = Optional.ofNullable(request.getResourceResolver().adaptTo(ComponentManager.class)).map(componentManager -> StreamSupport.stream(effectiveResource.getChildren().spliterator(), false).filter(res -> Objects.nonNull(componentManager.getComponentOfResource(res)))).orElseGet(Stream::empty).collect(Collectors.toList());
}
return childComponents;
}
use of com.day.cq.wcm.api.components.ComponentManager in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class Editor method readChildren.
private void readChildren() {
items = new ArrayList<>();
String containerPath = request.getRequestPathInfo().getSuffix();
if (StringUtils.isNotEmpty(containerPath)) {
ResourceResolver resolver = request.getResourceResolver();
container = resolver.getResource(containerPath);
if (container != null) {
ComponentManager componentManager = request.getResourceResolver().adaptTo(ComponentManager.class);
if (componentManager != null) {
for (Resource resource : container.getChildren()) {
if (resource != null) {
Component component = componentManager.getComponentOfResource(resource);
if (component != null) {
items.add(new Item(request, resource));
}
}
}
}
}
}
}
Aggregations