use of com.day.cq.wcm.api.Page in project acs-aem-commons by Adobe-Consulting-Services.
the class AemObjectInjector method getCurrentDesign.
/**
* Get the current design.
*
* @param adaptable a SlingHttpServletRequest
* @return the current Design if the adaptable was a SlingHttpServletRequest, the default Design otherwise
*/
private Design getCurrentDesign(Object adaptable) {
Page currentPage = getCurrentPage(adaptable);
Designer designer = getDesigner(adaptable);
if (currentPage != null && designer != null) {
return designer.getDesign(currentPage);
}
return null;
}
use of com.day.cq.wcm.api.Page in project acs-aem-commons by Adobe-Consulting-Services.
the class WorkflowPackageManagerImpl method create.
/**
* {@inheritDoc}
*/
public final Page create(final ResourceResolver resourceResolver, String bucketSegment, final String name, final String... paths) throws WCMException, RepositoryException {
final Session session = resourceResolver.adaptTo(Session.class);
final PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
String bucketPath = "/etc/workflow/packages";
if (StringUtils.isNotBlank(bucketSegment)) {
bucketPath += "/" + bucketSegment;
}
final Node shardNode = JcrUtils.getOrCreateByPath(bucketPath, NT_SLING_FOLDER, NT_SLING_FOLDER, session, false);
final Page page = pageManager.create(shardNode.getPath(), JcrUtil.createValidName(name), WORKFLOW_PACKAGE_TEMPLATE, name, false);
final Resource contentResource = page.getContentResource();
Node node = JcrUtil.createPath(contentResource.getPath() + "/" + NN_VLT_DEFINITION, NT_VLT_DEFINITION, session);
node = JcrUtil.createPath(node.getPath() + "/filter", JcrConstants.NT_UNSTRUCTURED, session);
JcrUtil.setProperty(node, SLING_RESOURCE_TYPE, FILTER_RESOURCE_TYPE);
int i = 0;
Node resourceNode = null;
for (final String path : paths) {
if (path != null) {
resourceNode = JcrUtil.createPath(node.getPath() + "/resource_" + i++, JcrConstants.NT_UNSTRUCTURED, session);
JcrUtil.setProperty(resourceNode, "root", path);
JcrUtil.setProperty(resourceNode, "rules", this.getIncludeRules(path));
JcrUtil.setProperty(resourceNode, SLING_RESOURCE_TYPE, FILTER_RESOURCE_RESOURCE_TYPE);
}
}
session.save();
return page;
}
use of com.day.cq.wcm.api.Page in project acs-aem-commons by Adobe-Consulting-Services.
the class TwitterFeedUpdaterImpl method updateTwitterFeedComponents.
@Override
@SuppressWarnings("squid:S3776")
public void updateTwitterFeedComponents(ResourceResolver resourceResolver) {
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
List<Resource> twitterResources = findTwitterResources(resourceResolver);
for (Resource twitterResource : twitterResources) {
Page page = pageManager.getContainingPage(twitterResource);
if (page != null) {
Twitter client = page.adaptTo(Twitter.class);
if (client != null) {
try {
ValueMap properties = twitterResource.getValueMap();
String username = properties.get("username", String.class);
if (!StringUtils.isEmpty(username)) {
log.info("Loading Twitter timeline for user {} for component {}.", username, twitterResource.getPath());
List<Status> statuses = client.getUserTimeline(username);
if (statuses != null) {
List<String> tweetsList = new ArrayList<>(statuses.size());
List<String> jsonList = new ArrayList<>(statuses.size());
for (Status status : statuses) {
tweetsList.add(processTweet(status));
jsonList.add(DataObjectFactory.getRawJSON(status));
}
if (!tweetsList.isEmpty()) {
ModifiableValueMap map = twitterResource.adaptTo(ModifiableValueMap.class);
map.put("tweets", tweetsList.toArray(new String[tweetsList.size()]));
map.put("tweetsJson", jsonList.toArray(new String[jsonList.size()]));
twitterResource.getResourceResolver().commit();
handleReplication(twitterResource);
}
}
}
} catch (PersistenceException e) {
log.error("Exception while updating twitter feed on resource:" + twitterResource.getPath(), e);
} catch (ReplicationException e) {
log.error("Exception while replicating twitter feed on resource:" + twitterResource.getPath(), e);
} catch (TwitterException e) {
log.error("Exception while loading twitter feed on resource:" + twitterResource.getPath(), e);
}
} else {
log.warn("Twitter component found on {}, but page cannot be adapted to Twitter API. Check Cloud SErvice configuration", page.getPath());
}
}
}
}
use of com.day.cq.wcm.api.Page in project acs-aem-commons by Adobe-Consulting-Services.
the class TwitterAdapterFactoryTest method setupPage.
private Page setupPage(ValueMap configData) {
com.day.cq.wcm.webservicesupport.Configuration config = setupConfiguration(configData);
String[] configPath = new String[] { "configpath " };
Page page = mock(Page.class);
Resource contentResource = mock(Resource.class);
when(page.getContentResource()).thenReturn(contentResource);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
when(contentResource.getResourceResolver()).thenReturn(resourceResolver);
ConfigurationManager configurationManager = mock(ConfigurationManager.class);
when(resourceResolver.adaptTo(ConfigurationManager.class)).thenReturn(configurationManager);
when(contentResource.getValueMap()).thenReturn(new ValueMapDecorator(Collections.singletonMap(ConfigurationConstants.PN_CONFIGURATIONS, configPath)));
when(configurationManager.getConfiguration("twitterconnect", configPath)).thenReturn(config);
return page;
}
use of com.day.cq.wcm.api.Page 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);
}
Aggregations