use of com.adobe.granite.ui.components.ds.DataSource in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ModelDataSourceServlet method doGet.
@Override
protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) throws ServletException, IOException {
DataSource dataSource = EmptyDataSource.instance();
ResourceResolver resourceResolver = request.getResourceResolver();
QueryBuilder queryBuilder = resourceResolver.adaptTo(QueryBuilder.class);
if (queryBuilder != null) {
Map<String, String> parameterMap = new HashMap<>();
parameterMap.put("path", "/conf");
parameterMap.put("type", NT_TEMPLATE);
parameterMap.put("p.limit", "-1");
parameterMap.put("1_property", JcrConstants.JCR_CONTENT + "/model/" + ResourceResolver.PROPERTY_RESOURCE_TYPE);
parameterMap.put("1_property.value", "wcm/scaffolding/components/scaffolding");
PredicateGroup predicateGroup = PredicateGroup.create(parameterMap);
Session session = resourceResolver.adaptTo(Session.class);
Query query = queryBuilder.createQuery(predicateGroup, session);
SearchResult searchResult = query.getResult();
// Query builder has a leaking resource resolver, so the following work around is required.
ResourceResolver leakingResourceResolver = null;
try {
// Iterate over the hits if you need special information
List<Resource> resources = new LinkedList<>();
for (Iterator<Resource> resourceIterator = searchResult.getResources(); resourceIterator.hasNext(); ) {
Resource resource = resourceIterator.next();
if (leakingResourceResolver == null) {
// Get a reference to query builder's leaking resource resolver
leakingResourceResolver = resource.getResourceResolver();
}
ValueMap modelValueMap = resource.getValueMap();
String modelTitle = modelValueMap.get(JcrConstants.JCR_CONTENT + "/" + JcrConstants.JCR_TITLE, resource.getName());
String modelPath = resource.getPath();
Resource syntheticResource = createResource(resourceResolver, modelTitle, modelPath);
resources.add(syntheticResource);
}
dataSource = new SimpleDataSource(resources.iterator());
} finally {
if (leakingResourceResolver != null) {
// Always close the leaking query builder resource resolver.
leakingResourceResolver.close();
}
}
}
request.setAttribute(DataSource.class.getName(), dataSource);
}
use of com.adobe.granite.ui.components.ds.DataSource in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ModelElementsDataSourceServlet method doGet.
@Override
protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) {
// First try to get the model path from request parameters
// otherwise determine model path from component resource.
RequestParameter modelPathRequestParameter = request.getRequestParameter(PARAMETER_AND_PN_MODEL_PATH);
boolean isOrderBy = request.getResource().isResourceType(RESOURCE_TYPE_ORDER_BY_V1);
String modelPath;
if (modelPathRequestParameter != null) {
modelPath = modelPathRequestParameter.getString();
} else {
Config config = getConfig(request);
ValueMap componentValueMap = getComponentValueMap(config, request);
// get model path from component resource
modelPath = componentValueMap != null ? componentValueMap.get(ContentFragmentList.PN_MODEL_PATH, String.class) : null;
}
DataSource dataSource = EmptyDataSource.instance();
if (modelPath != null) {
ResourceResolver resourceResolver = request.getResourceResolver();
String pathToCFModelElements = String.format("%s/%s/model/cq:dialog/content/items", modelPath, JcrConstants.JCR_CONTENT);
Resource cfModelElementRoot = resourceResolver.getResource(pathToCFModelElements);
if (cfModelElementRoot != null) {
Iterator<Resource> resourceIterator = cfModelElementRoot.listChildren();
List<Resource> resourceList = new LinkedList<>();
if (isOrderBy) {
resourceList.add(createResource(resourceResolver, "Created", JcrConstants.JCR_CREATED));
resourceList.add(createResource(resourceResolver, "Last Modified", JcrConstants.JCR_CONTENT + "/" + JcrConstants.JCR_LASTMODIFIED));
}
while (resourceIterator.hasNext()) {
Resource elementResource = resourceIterator.next();
ValueMap valueMap = elementResource.getValueMap();
String valueValue = valueMap.get("name", "");
String textValue = valueMap.get("fieldLabel", valueValue);
if (isOrderBy && StringUtils.isNotEmpty(valueValue)) {
valueValue = "jcr:content/data/master/" + valueValue;
}
String metaType = valueMap.get("metaType", StringUtils.EMPTY);
if (!isOrderBy || StringUtils.startsWith(metaType, "text-")) {
Resource syntheticResource = createResource(resourceResolver, textValue, valueValue);
resourceList.add(syntheticResource);
}
}
dataSource = new SimpleDataSource(resourceList.iterator());
}
}
request.setAttribute(DataSource.class.getName(), dataSource);
}
use of com.adobe.granite.ui.components.ds.DataSource in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class WorkflowModelDataSourceServlet method doGet.
@Override
protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) throws ServletException, IOException {
try {
WorkflowSession workflowSession = request.getResourceResolver().adaptTo(WorkflowSession.class);
ArrayList<Resource> resources = new ArrayList<>();
if (workflowSession != null) {
WorkflowModel[] models = workflowSession.getModels();
for (WorkflowModel model : models) {
resources.add(new WorkflowModelResource(model, request.getResourceResolver()));
}
}
SimpleDataSource dataSource = new SimpleDataSource(resources.iterator());
request.setAttribute(DataSource.class.getName(), dataSource);
} catch (WorkflowException e) {
throw new ServletException(e);
}
}
use of com.adobe.granite.ui.components.ds.DataSource in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class OptionsImpl method populateOptionItems.
/* ------------------------ Internal stuff -------------------------------------------- */
private void populateOptionItems() {
this.optionItems = new ArrayList<>();
Source source = Source.getSource(sourceString);
if (source == null) {
populateOptionItemsFromLocal();
} else {
switch(source) {
case DATASOURCE:
populateOptionItemsFromDatasource();
break;
case LIST:
populateOptionItemsFromList();
break;
default:
populateOptionItemsFromLocal();
}
}
}
use of com.adobe.granite.ui.components.ds.DataSource in project APM by Cognifide.
the class ChildrenDatasourceServlet method doGet.
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) {
Iterator<Resource> iterator = Optional.ofNullable(request.getResource()).flatMap(parent -> Optional.ofNullable(parent.getChild("items"))).map(items -> items.listChildren()).orElse(Collections.emptyIterator());
DataSource dataSource = new SimpleDataSource(iterator);
request.setAttribute(DataSource.class.getName(), dataSource);
}
Aggregations