All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adobe.cq.social.scf.QueryRequestInfo Maven / Gradle / Ivy

/*************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * __________________
 *
 *  Copyright 2013 Adobe Systems Incorporated
 *  All Rights Reserved.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Adobe Systems Incorporated and its suppliers,
 * if any.  The intellectual and technical concepts contained
 * herein are proprietary to Adobe Systems Incorporated and its
 * suppliers and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Adobe Systems Incorporated.
 **************************************************************************/
package com.adobe.cq.social.scf;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.adobe.cq.social.scf.core.BaseQueryRequestInfo;
import com.adobe.cq.social.scf.core.CollectionSortedOrder;

/**
 * The QueryRequestInfo maintains information such as pagination, query predicates of a client request.
 * @author thuynh
 */
public interface QueryRequestInfo {

    public static String GET = "GET";
    public static List SCF_SELECTORS = Arrays.asList(new String[]{"topic", "entry", "idea", "event", "asset",
        "translate"});

    public interface QueryRequestInfoFactory {
        QueryRequestInfo create();

        QueryRequestInfo create(QueryRequestInfo copyFrom);
    }

    QueryRequestInfoFactory DEFAULT_QUERY_INFO_FACTORY = new QueryRequestInfoFactory() {
        @Override
        public QueryRequestInfo create() {
            return new BaseQueryRequestInfo(false, Collections.emptyMap(),
                CollectionPagination.DEFAULT_PAGINATION, false);
        }

        @Override
        public QueryRequestInfo create(final QueryRequestInfo copyFrom) {
            if (copyFrom != null) {
                final QueryRequestInfo newQueryInfo =
                    new BaseQueryRequestInfo(copyFrom.isQuery(), new HashMap(
                        copyFrom.getPredicates()), new CollectionPagination(copyFrom.getPagination()),
                        copyFrom.isTranslationRequest());
                if (copyFrom.getSortBy() != null) {
                    newQueryInfo.setSortBy(new ArrayList(copyFrom.getSortBy()));
                }
                newQueryInfo.setSortOrder(copyFrom.getSortOrder());
                final List> sortFields = copyFrom.getSortFields();
                newQueryInfo.setSortRequest(copyFrom.isSortRequest());
                if (sortFields != null && !sortFields.isEmpty()) {
                    newQueryInfo.setSortFields(sortFields);
                }
                return newQueryInfo;
            } else {
                return create();
            }
        }
    };

    /**
     * Is the request a query request
     * @return boolean
     */
    boolean isQuery();

    /**
     * Is the request a translate request
     * @return boolean
     */
    boolean isTranslationRequest();

    /**
     * Is the request a sort request
     * @return boolean
     */
    boolean isSortRequest();

    /**
     * Sets the property that identifies if the QueryRequest is a sort request.
     * @param isSortRequest the new sort request
     */
    void setSortRequest(boolean isSortRequest);

    /**
     * Set the translation request
     * @param isTranslationRequest request value
     */
    void setTranslationRequest(boolean isTranslationRequest);

    /**
     * Get the query predicates.
     * @return null if the request is not a query request, otherwise, the method returns a map of the query predicates
     */
    Map getPredicates();

    /**
     * Get the request paging specification
     * @return CollectionPagination
     */
    CollectionPagination getPagination();

    /**
     * Set the pagination
     * @param pagination the pagination setting.
     */
    void setPagination(final CollectionPagination pagination);

    /**
     * @param sortBy list of indexes to use to sort the list by
     */
    void setSortBy(final List sortBy);

    /**
     * @return List - the list of index names requested to sort the list by
     */
    List getSortBy();

    /**
     * Gets the sort fields. Its a ordered list. For a sort field [{"subject", true},{"added", false}] like this would
     * sort UGC based on subject in ascending order and then by create date
     * @return the sort fields
     */
    List> getSortFields();

    /**
     * Sets the sort fields.
     * @param sortFields the sort fields
     */
    void setSortFields(final List> sortFields);

    /**
     * Gets the query params.
     * @return the query params
     */
    String getQueryString();

    /**
     * @param order for the list
     */
    @Deprecated
    void setSortOrder(final CollectionSortedOrder order);

    /**
     * @return the requested order to sort the list by
     */
    @Deprecated
    CollectionSortedOrder getSortOrder();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy