use of com.adobe.granite.ui.components.ds.DataSource in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class WorkflowModelDataSourceServletTest method testDataSource.
@Test
public void testDataSource() throws Exception {
context.currentResource("/apps/workflowdatasource");
WorkflowModelDataSourceServlet dataSourceServlet = new WorkflowModelDataSourceServlet();
dataSourceServlet.doGet(context.request(), context.response());
DataSource dataSource = (DataSource) context.request().getAttribute(DataSource.class.getName());
assertNotNull(dataSource);
Resource resource = dataSource.iterator().next();
assertEquals("Workflow Title", resource.getValueMap().get("text", String.class));
assertEquals("test/workflow", resource.getValueMap().get("value", String.class));
}
use of com.adobe.granite.ui.components.ds.DataSource in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class FormActionTypeSettingsDataSourceServletTest method testDataSource.
@Test
public void testDataSource() throws Exception {
context.currentResource("/apps/actiontypesettingsdatasource");
FormActionTypeSettingsDataSourceServlet dataSourceServlet = new FormActionTypeSettingsDataSourceServlet();
dataSourceServlet.doGet(context.request(), context.response());
DataSource dataSource = (DataSource) context.request().getAttribute(DataSource.class.getName());
assertNotNull(dataSource);
Resource resource = dataSource.iterator().next();
assertEquals(resource.getPath(), context.currentResource("/apps/form/action/cq:dialog").getPath());
}
use of com.adobe.granite.ui.components.ds.DataSource in project acs-aem-commons by Adobe-Consulting-Services.
the class DataSourceBuilderImpl method addDataSource.
@Override
public void addDataSource(final SlingHttpServletRequest slingRequest, final List<DataSourceOption> options) {
final ArrayList<Resource> resourceList = new ArrayList<Resource>();
DataSource dataSource = null;
for (final DataSourceOption option : options) {
final Map map = new HashMap();
map.put(TEXT, option.getText());
map.put(VALUE, option.getValue());
resourceList.add(new ValueMapResource(slingRequest.getResourceResolver(), new ResourceMetadata(), "", new ValueMapDecorator(map)));
}
if (resourceList.size() > 0) {
dataSource = new SimpleDataSource(resourceList.iterator());
} else {
dataSource = EmptyDataSource.instance();
}
slingRequest.setAttribute(DataSource.class.getName(), dataSource);
}
use of com.adobe.granite.ui.components.ds.DataSource in project acs-aem-commons by Adobe-Consulting-Services.
the class DataSourceBuilderImpl method writeDataSourceOptions.
@Override
public void writeDataSourceOptions(final SlingHttpServletRequest slingRequest, final SlingHttpServletResponse slingResponse) throws JSONException, IOException {
final DataSource datasource = (DataSource) slingRequest.getAttribute(DataSource.class.getName());
final JSONArray jsonArray = new JSONArray();
if (datasource != null) {
final Iterator<Resource> iterator = datasource.iterator();
if (iterator != null) {
while (iterator.hasNext()) {
final Resource dataResource = iterator.next();
if (dataResource != null) {
final ValueMap dataProps = dataResource.adaptTo(ValueMap.class);
if (dataProps != null) {
final JSONObject json = new JSONObject();
json.put(TEXT, dataProps.get(TEXT, ""));
json.put(VALUE, dataProps.get(VALUE, ""));
jsonArray.put(json);
}
}
}
}
}
slingResponse.setContentType("application/json; charset=UTF-8");
slingResponse.setCharacterEncoding("UTF-8");
slingResponse.getWriter().write(jsonArray.toString());
}
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);
}
}
Aggregations