Search in sources :

Example 1 with Result

use of com.adobe.acs.commons.quickly.results.Result in project acs-aem-commons by Adobe-Consulting-Services.

the class QuicklyEngineImpl method getJSONResults.

private JSONObject getJSONResults(Command cmd, SlingHttpServletRequest request, final Collection<Result> results) throws JSONException {
    final JSONObject json = new JSONObject();
    json.put(KEY_RESULTS, new JSONArray());
    final ValueMap requestConfig = new ValueMapDecorator(new HashMap<String, Object>());
    // Collect all items collected from OSGi Properties
    requestConfig.putAll(this.config);
    // Add Request specific configurations
    requestConfig.put(AuthoringUIMode.class.getName(), authoringUIModeService.getAuthoringUIMode(request));
    for (final Result result : results) {
        final JSONObject tmp = resultBuilder.toJSON(cmd, result, requestConfig);
        if (tmp != null) {
            json.accumulate(KEY_RESULTS, tmp);
        }
    }
    return json;
}
Also used : JSONObject(org.apache.sling.commons.json.JSONObject) ValueMap(org.apache.sling.api.resource.ValueMap) JSONArray(org.apache.sling.commons.json.JSONArray) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator) JSONObject(org.apache.sling.commons.json.JSONObject) AuthoringUIMode(com.day.cq.wcm.api.AuthoringUIMode) Result(com.adobe.acs.commons.quickly.results.Result)

Example 2 with Result

use of com.adobe.acs.commons.quickly.results.Result in project acs-aem-commons by Adobe-Consulting-Services.

the class LastModifiedOperationImpl method withoutParams.

@Override
protected List<Result> withoutParams(final SlingHttpServletRequest request, final SlingHttpServletResponse response, final Command cmd) {
    final List<Result> results = new ArrayList<Result>();
    final Result infoResult = new Result.Builder("lastmod [ userId ] [ 1s | 2m | 3h | 4d | 5w | 6M | 7y ]").description("Returns the last modified Pages. Defaults to: me 1d").build();
    results.add(infoResult);
    // Default to "lastmod me 1d"
    results.addAll(this.withParams(request, response, cmd));
    return results;
}
Also used : QueryBuilder(com.day.cq.search.QueryBuilder) ArrayList(java.util.ArrayList) SearchResult(com.day.cq.search.result.SearchResult) Result(com.adobe.acs.commons.quickly.results.Result)

Example 3 with Result

use of com.adobe.acs.commons.quickly.results.Result in project acs-aem-commons by Adobe-Consulting-Services.

the class DuckDuckGoDocsOperationImpl method withoutParams.

@Override
protected List<Result> withoutParams(final SlingHttpServletRequest request, final SlingHttpServletResponse response, final Command cmd) {
    final List<Result> results = new ArrayList<Result>();
    final Result result = new Result.Builder("docs.adobe.com").description("http://docs.adobe.com").action(new Action.Builder().uri("http://docs.adobe.com").target(Action.Target.BLANK).build()).build();
    results.add(result);
    return results;
}
Also used : Action(com.adobe.acs.commons.quickly.results.Action) ArrayList(java.util.ArrayList) Result(com.adobe.acs.commons.quickly.results.Result)

Example 4 with Result

use of com.adobe.acs.commons.quickly.results.Result in project acs-aem-commons by Adobe-Consulting-Services.

the class DuckDuckGoDocsOperationImpl method withParams.

@Override
protected List<Result> withParams(final SlingHttpServletRequest request, final SlingHttpServletResponse response, final Command cmd) {
    final List<Result> results = new ArrayList<Result>();
    final Map<String, String> params = new HashMap<String, String>();
    params.put("q", "site:docs.adobe.com/docs/en/" + productName + "/" + aemVersion + " AND " + cmd.getParam());
    final Result result = new Result.Builder("Search AEM documentation").description("Search for: " + cmd.getParam()).action(new Action.Builder().uri("https://duckduckgo.com").target(Action.Target.BLANK).params(params).build()).build();
    results.add(result);
    return results;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Result(com.adobe.acs.commons.quickly.results.Result)

Example 5 with Result

use of com.adobe.acs.commons.quickly.results.Result in project acs-aem-commons by Adobe-Consulting-Services.

the class LastModifiedOperationImpl method withParams.

@Override
protected List<Result> withParams(final SlingHttpServletRequest request, final SlingHttpServletResponse response, final Command cmd) {
    final long start = System.currentTimeMillis();
    final List<Result> results = new ArrayList<Result>();
    final ResourceResolver resourceResolver = request.getResourceResolver();
    final PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
    final List<Resource> pages = this.getLastModifiedPages(resourceResolver, cmd);
    log.debug("LastModified pages -- [ {} ] results", pages.size());
    for (final Resource resource : pages) {
        final Page page = pageManager.getContainingPage(resource);
        if (page == null) {
            continue;
        }
        final String title = TextUtil.getFirstNonEmpty(page.getTitle(), page.getPageTitle(), page.getNavigationTitle(), page.getName());
        final String description = page.getPath() + " by " + page.getLastModifiedBy() + " at " + DATE_FORMAT.format(page.getLastModified().getTime());
        results.add(new Result.Builder(title).path(page.getPath()).description(description).resultType(OpenResultSerializerImpl.TYPE).build());
    }
    log.debug("Lastmod - Execution time: {} ms", System.currentTimeMillis() - start);
    return results;
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) ArrayList(java.util.ArrayList) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page) SearchResult(com.day.cq.search.result.SearchResult) Result(com.adobe.acs.commons.quickly.results.Result)

Aggregations

Result (com.adobe.acs.commons.quickly.results.Result)5 ArrayList (java.util.ArrayList)4 SearchResult (com.day.cq.search.result.SearchResult)2 Action (com.adobe.acs.commons.quickly.results.Action)1 QueryBuilder (com.day.cq.search.QueryBuilder)1 AuthoringUIMode (com.day.cq.wcm.api.AuthoringUIMode)1 Page (com.day.cq.wcm.api.Page)1 PageManager (com.day.cq.wcm.api.PageManager)1 HashMap (java.util.HashMap)1 Resource (org.apache.sling.api.resource.Resource)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 ValueMap (org.apache.sling.api.resource.ValueMap)1 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)1 JSONArray (org.apache.sling.commons.json.JSONArray)1 JSONObject (org.apache.sling.commons.json.JSONObject)1