public class ListingRequestUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
AFTER
Only items after the specified value in the sort order should be returned.
|
static java.lang.String |
CLASS_VERSION
Class version string
|
static java.lang.String |
DEFAULT_DISPLAY_NAME_PROPERTY
The DEFAULT_DISPLAY_NAME_PROPERTY property.
|
static int |
DEFAULT_LIMIT
The DEFAULT_LIMIT property.
|
static int |
DEFAULT_OFFSET
The DEFAULT_OFFSET property.
|
static java.lang.String |
DEFAULT_SORT_PROPERTY
The DEFAULT_SORT_PROPERTY property.
|
static java.lang.String |
DOUBLE_QUOTES
The Constant DOUBLE_QUOTES.
|
static java.lang.String |
EXPANDED
The EXPANDED property.
|
static java.lang.String |
GET_FOR_UPDATE |
static java.lang.String |
INCLUDES
The Constant INCLUDES.
|
static java.lang.String |
INVALID_PARAM_VALUE
The INVALID_PARAM_VALUE property.
|
static java.lang.String |
INVALID_SORT_PROPERTY
The INVALID_SORT_PROPERTY property.
|
static java.lang.String |
ITEMS
The ITEMS property.
|
static java.lang.String |
LIMIT
The LIMIT property.
|
static java.lang.String |
LISTING_KEY_SORT_ORDER_ASC
The LISTING_KEY_SORT_ORDER_ASC property.
|
static java.lang.String |
LISTING_KEY_SORT_ORDER_DESC
The LISTING_KEY_SORT_ORDER_DESC property.
|
static int |
MAX_LIMIT
The MAX_LIMIT property.
|
static java.lang.String |
NULL_SORT_DIRECTIVE
The NULL_SORT_DIRECTIVE property.
|
static java.lang.String |
OFFSET
The OFFSET property.
|
static java.lang.String |
ORDERBY
The ORDERBY property.
|
static java.lang.String |
QUERY
The specified RQL query.
|
static java.lang.String |
REPOSITORY_ID
The REPOSITORY_ID property.
|
static java.lang.String |
RESTRICTED_SORT_PROPERTY
The RESTRICTED_SORT_PROPERTY property.
|
static java.lang.String |
SORT
The SORT property.
|
static int |
SORT_DEFAULT_ORDER
The SORT_DEFAULT_ORDER property.
|
static java.lang.String |
SORT_ORDER
The SORT_ORDER property.
|
static java.lang.String |
SORT_PROPERTY
The SORT_PROPERTY property.
|
static java.lang.String |
TOTAL
The TOTAL property.
|
static java.lang.String |
TOTAL_RESULTS |
Constructor and Description |
---|
ListingRequestUtils() |
Modifier and Type | Method and Description |
---|---|
static ListingResponse<RepositoryItem> |
buildListingResponseFromCollection(ListingRequest pListingRequest,
RepositoryItem pParentItem,
java.lang.String pPropertyName,
RepositoryView pChildRepositoryView,
int pSortingLimit)
Fetch the items based on item property defined in parent item.
|
static ListingResponse<RepositoryItem> |
buildListingResponseFromCollection(ListingRequest pListingRequest,
RepositoryItem pParentItem,
java.lang.String pPropertyName,
RepositoryView pChildRepositoryView,
int pSortingLimit,
java.lang.String pCollectionQuery)
Fetch the items based on item property defined in parent item.
|
static ListingResponse<RepositoryItem> |
buildListingResponseFromQuery(ListingRequest pListingRequest,
RepositoryView pItemView)
Utility method to execute a base query for given listing request and item view.
|
static ListingResponse<RepositoryItem> |
buildListingResponseFromQuery(ListingRequest pListingRequest,
RepositoryView pItemView,
Query pQuery)
Utility method to execute a query for given listing request and item view.
|
static ListingResponse<RepositoryItem> |
buildListingResponseFromQuery(java.util.Map<java.lang.String,java.util.List<java.lang.String>> pQueryParams,
RepositoryItemDescriptor pItemDesc,
java.lang.String pDefaultSortProperty,
int pDefaultLimit)
Utility method to execute a query for given query params and an item descriptor.
|
static Query |
buildRefByQuery(RepositoryItem pItem,
java.lang.String pPropertyName)
Builds a referenced by query to get the child items
of a parent referenced in the specified property.
|
static SortDirectives |
createDefaultSortDirectives()
Create default sort directives.
|
static SortDirectives |
createDefaultSortDirectives(java.lang.String pDefaultSortProperty)
Create default sort directives.
|
protected static java.lang.String |
getFirst(java.util.Map<java.lang.String,java.util.List<java.lang.String>> pMap,
java.lang.String pKey)
Utility method to handle getting the first item from multivalued map values.
|
static ListingRequest |
queryParamsToListingRequest(java.util.Map<java.lang.String,java.util.List<java.lang.String>> pQueryParams)
Create a ListingRequest from query params.
|
static ListingRequest |
queryParamsToListingRequest(java.util.Map<java.lang.String,java.util.List<java.lang.String>> pQueryParams,
java.lang.String pDefaultSortProperty)
Create a listing request using the query params and sort property passed in.
|
static ListingRequest |
queryParamsToListingRequest(java.util.Map<java.lang.String,java.util.List<java.lang.String>> pQueryParams,
java.lang.String pDefaultSortProperty,
boolean pCreateDefaultSortDirectives)
Create a ListingRequest from query params.
|
static ListingRequest |
queryParamsToListingRequest(java.util.Map<java.lang.String,java.util.List<java.lang.String>> pQueryParams,
java.lang.String pDefaultSortProperty,
boolean pCreateDefaultSortDirectives,
int pDefaultLimit)
Create a ListingRequest from query params.
|
static int |
stringToSortOrder(java.lang.String pJsonString)
Turns the given string into an int representing a sort order in a sort
directive
|
static java.util.Map<java.lang.String,java.lang.Object> |
toJsonMap(ListingResponse listingResults,
boolean pUseLimit)
Converts a
ListingResponse into a map for easy representation
in json. |
static void |
validateDirective(SortDirective pDirective,
RepositoryItemDescriptor itemDesc)
Validates the given directive, ensuring that it is not null, not a
restricted property like repositoryId, does not refer to an invalid
itemtype property
|
static void |
validateSortDirectives(SortDirectives sortDirectives,
RepositoryItemDescriptor itemDesc)
Validates the given sort directives, making sure that each directive refers
to a valid property
|
public static final java.lang.String CLASS_VERSION
public static final java.lang.String SORT
public static final java.lang.String ORDERBY
public static final java.lang.String OFFSET
public static final java.lang.String LIMIT
public static final java.lang.String TOTAL
public static final java.lang.String EXPANDED
public static final java.lang.String AFTER
public static final java.lang.String QUERY
public static final java.lang.String GET_FOR_UPDATE
public static final java.lang.String TOTAL_RESULTS
public static final java.lang.String ITEMS
public static final java.lang.String SORT_ORDER
public static final java.lang.String SORT_PROPERTY
public static final java.lang.String LISTING_KEY_SORT_ORDER_ASC
public static final java.lang.String LISTING_KEY_SORT_ORDER_DESC
public static int DEFAULT_OFFSET
public static int DEFAULT_LIMIT
public static int MAX_LIMIT
public static final int SORT_DEFAULT_ORDER
public static final java.lang.String DEFAULT_DISPLAY_NAME_PROPERTY
public static final java.lang.String DEFAULT_SORT_PROPERTY
public static final java.lang.String NULL_SORT_DIRECTIVE
public static final java.lang.String RESTRICTED_SORT_PROPERTY
public static final java.lang.String INVALID_SORT_PROPERTY
public static final java.lang.String REPOSITORY_ID
public static final java.lang.String INVALID_PARAM_VALUE
public static final java.lang.String INCLUDES
public static final java.lang.String DOUBLE_QUOTES
public static SortDirectives createDefaultSortDirectives()
public static SortDirectives createDefaultSortDirectives(java.lang.String pDefaultSortProperty)
pDefaultSortProperty
- the default sort property.protected static java.lang.String getFirst(java.util.Map<java.lang.String,java.util.List<java.lang.String>> pMap, java.lang.String pKey)
pMap
- multivalued map of stringpKey
- string keypublic static ListingRequest queryParamsToListingRequest(java.util.Map<java.lang.String,java.util.List<java.lang.String>> pQueryParams) throws javax.servlet.ServletException
pQueryParams
- map of params for sort, offset and limit.javax.servlet.ServletException
- should a error happen during processing.public static ListingRequest queryParamsToListingRequest(java.util.Map<java.lang.String,java.util.List<java.lang.String>> pQueryParams, java.lang.String pDefaultSortProperty) throws javax.servlet.ServletException
pQueryParams
- the query params.pDefaultSortProperty
- the default sort property.javax.servlet.ServletException
- should an error happen processing the params.public static ListingRequest queryParamsToListingRequest(java.util.Map<java.lang.String,java.util.List<java.lang.String>> pQueryParams, java.lang.String pDefaultSortProperty, boolean pCreateDefaultSortDirectives) throws javax.servlet.ServletException
pQueryParams
- map of params for sort, offset and limit.pDefaultSortProperty
- the name of the property to use for sorting if no other sorting
params are passed in.pCreateDefaultSortDirectives
- specifies whether to use the pDefaultSortProperty if no sorting
params are passed in pQueryParams.javax.servlet.ServletException
- should an error happen processing the params.public static ListingRequest queryParamsToListingRequest(java.util.Map<java.lang.String,java.util.List<java.lang.String>> pQueryParams, java.lang.String pDefaultSortProperty, boolean pCreateDefaultSortDirectives, int pDefaultLimit) throws javax.servlet.ServletException
pQueryParams
- map of params for sort, offset and limit.pDefaultSortProperty
- the name of the property to use for sorting if no other sorting
params are passed in.pCreateDefaultSortDirectives
- specifies whether to use the pDefaultSortProperty if no sorting
params are passed in pQueryParams.pCreateDefaultSortDirectives
- specifies whether to use the pDefaultSortProperty if no sorting
params are passed in pQueryParams.javax.servlet.ServletException
- should an error happen processing the params.public static java.util.Map<java.lang.String,java.lang.Object> toJsonMap(ListingResponse listingResults, boolean pUseLimit)
ListingResponse
into a map for easy representation
in json.listingResults
- the response to convert.pUseLimit
- indicates whether a max limit should be used in listing results.public static int stringToSortOrder(java.lang.String pJsonString)
pJsonString
- the string to parseSORT_DEFAULT_ORDER
if the string value is invalidpublic static void validateDirective(SortDirective pDirective, RepositoryItemDescriptor itemDesc) throws RepositoryException, javax.servlet.ServletException
pDirective
- the directive to validateitemDesc
- Repository item descriptor to check the property againstRepositoryException
- if error occurs interacting with repository.javax.servlet.ServletException
- if property specified for the sort is restricted or invalid.public static void validateSortDirectives(SortDirectives sortDirectives, RepositoryItemDescriptor itemDesc) throws RepositoryException, javax.servlet.ServletException
sortDirectives
- the directives to validateitemDesc
- Repository item descriptor to check the property againstRepositoryException
- if error occurs interacting with repository.javax.servlet.ServletException
- if property specified for the sort is restricted or invalid.public static ListingResponse<RepositoryItem> buildListingResponseFromQuery(java.util.Map<java.lang.String,java.util.List<java.lang.String>> pQueryParams, RepositoryItemDescriptor pItemDesc, java.lang.String pDefaultSortProperty, int pDefaultLimit) throws javax.servlet.ServletException
pQueryParams
- Map of request query params to use to constrain the item querypItemDesc
- Item descriptor to execute item query againstpDefaultSortProperty
- The name of the item property to use for sorting if no query param specifies one.javax.servlet.ServletException
- for any issues building or executing the query.public static ListingResponse<RepositoryItem> buildListingResponseFromQuery(ListingRequest pListingRequest, RepositoryView pItemView, Query pQuery) throws javax.servlet.ServletException
pListingRequest
- Listing requestpItemView
- Repository view for items to be returnedpQuery
- the query to executejavax.servlet.ServletException
- for issues building or executing the querypublic static ListingResponse<RepositoryItem> buildListingResponseFromQuery(ListingRequest pListingRequest, RepositoryView pItemView) throws javax.servlet.ServletException
The base query will create a query from a particular id based on the 'after' param if set, also from/to a particular index based on the 'offset' and 'limit' param if set. Plus it will take into account any 'orderBy'/'sort' directives. Or else execute a query based on the 'q' param.
Otherwise it returns all of the item view items
pListingRequest
- Listing request with querypItemView
- Repository view for items to be returnedjavax.servlet.ServletException
- for issues building or executing the querypublic static ListingResponse<RepositoryItem> buildListingResponseFromCollection(ListingRequest pListingRequest, RepositoryItem pParentItem, java.lang.String pPropertyName, RepositoryView pChildRepositoryView, int pSortingLimit) throws javax.servlet.ServletException
pListingRequest
- the listing requestpParentItem
- the parent itempPropertyName
- the property namepChildRepositoryView
- the child repository viewjavax.servlet.ServletException
- the servlet exceptionpublic static ListingResponse<RepositoryItem> buildListingResponseFromCollection(ListingRequest pListingRequest, RepositoryItem pParentItem, java.lang.String pPropertyName, RepositoryView pChildRepositoryView, int pSortingLimit, java.lang.String pCollectionQuery) throws javax.servlet.ServletException
If any sorting is defined in the request this collection will be sorted. If sorting and the collection is larger than the collection sorting limit, the sort will be performed by retrieves items based on generated rql query. If an collection query has not been specified then a referenced by query is built based on the parent item. The child property must be defined to generate the rql query. If it is not defined then an error message is thrown.
pListingRequest
- the listing requestpParentItem
- the parent itempPropertyName
- the property namepChildRepositoryView
- the child repository viewpSortingLimit
- the collection sorting limitpCollectionQuery
- the collection queryjavax.servlet.ServletException
- the servlet exceptionpublic static Query buildRefByQuery(RepositoryItem pItem, java.lang.String pPropertyName) throws RepositoryException
pItem
- the parent repository itempPropertyName
- the child property nameRepositoryException
- issues building query