Search in sources :

Example 21 with DataSource

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));
}
Also used : Resource(org.apache.sling.api.resource.Resource) DataSource(com.adobe.granite.ui.components.ds.DataSource) Test(org.junit.jupiter.api.Test)

Example 22 with DataSource

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());
}
Also used : Resource(org.apache.sling.api.resource.Resource) DataSource(com.adobe.granite.ui.components.ds.DataSource) Test(org.junit.jupiter.api.Test)

Example 23 with DataSource

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);
}
Also used : HashMap(java.util.HashMap) DataSourceOption(com.adobe.acs.commons.wcm.datasources.DataSourceOption) SimpleDataSource(com.adobe.granite.ui.components.ds.SimpleDataSource) ValueMapResource(com.adobe.granite.ui.components.ds.ValueMapResource) Resource(org.apache.sling.api.resource.Resource) ArrayList(java.util.ArrayList) ValueMapResource(com.adobe.granite.ui.components.ds.ValueMapResource) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator) ResourceMetadata(org.apache.sling.api.resource.ResourceMetadata) ValueMap(org.apache.sling.api.resource.ValueMap) HashMap(java.util.HashMap) Map(java.util.Map) EmptyDataSource(com.adobe.granite.ui.components.ds.EmptyDataSource) SimpleDataSource(com.adobe.granite.ui.components.ds.SimpleDataSource) DataSource(com.adobe.granite.ui.components.ds.DataSource)

Example 24 with 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());
}
Also used : JSONObject(org.apache.sling.commons.json.JSONObject) ValueMap(org.apache.sling.api.resource.ValueMap) JSONArray(org.apache.sling.commons.json.JSONArray) ValueMapResource(com.adobe.granite.ui.components.ds.ValueMapResource) Resource(org.apache.sling.api.resource.Resource) EmptyDataSource(com.adobe.granite.ui.components.ds.EmptyDataSource) SimpleDataSource(com.adobe.granite.ui.components.ds.SimpleDataSource) DataSource(com.adobe.granite.ui.components.ds.DataSource)

Example 25 with 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);
    }
}
Also used : ServletException(javax.servlet.ServletException) SimpleDataSource(com.adobe.granite.ui.components.ds.SimpleDataSource) WorkflowSession(com.adobe.granite.workflow.WorkflowSession) WorkflowException(com.adobe.granite.workflow.WorkflowException) Resource(org.apache.sling.api.resource.Resource) ArrayList(java.util.ArrayList) WorkflowModel(com.adobe.granite.workflow.model.WorkflowModel) SimpleDataSource(com.adobe.granite.ui.components.ds.SimpleDataSource) DataSource(com.adobe.granite.ui.components.ds.DataSource)

Aggregations

DataSource (com.adobe.granite.ui.components.ds.DataSource)48 Test (org.junit.jupiter.api.Test)37 Resource (org.apache.sling.api.resource.Resource)14 SimpleDataSource (com.adobe.granite.ui.components.ds.SimpleDataSource)10 ValueMap (org.apache.sling.api.resource.ValueMap)6 EmptyDataSource (com.adobe.granite.ui.components.ds.EmptyDataSource)5 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)5 LinkedList (java.util.LinkedList)3 ValueMapResource (com.adobe.granite.ui.components.ds.ValueMapResource)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 DataSourceOption (com.adobe.acs.commons.wcm.datasources.DataSourceOption)1 ContentFragment (com.adobe.cq.dam.cfm.ContentFragment)1 CoreComponentTestContext (com.adobe.cq.wcm.core.components.context.CoreComponentTestContext)1 TextValueDataResourceSource (com.adobe.cq.wcm.core.components.internal.servlets.TextValueDataResourceSource)1 EmbeddableDescription (com.adobe.cq.wcm.core.components.internal.servlets.embed.EmbeddablesDataSourceServlet.EmbeddableDescription)1 MockStyle (com.adobe.cq.wcm.core.components.testing.MockStyle)1 Config (com.adobe.granite.ui.components.Config)1 Value (com.adobe.granite.ui.components.Value)1