View Javadoc
1   /*
2    * The contents of this file are subject to the terms of the Common Development and
3    * Distribution License (the License). You may not use this file except in compliance with the
4    * License.
5    *
6    * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7    * specific language governing permission and limitations under the License.
8    *
9    * When distributing Covered Software, include this CDDL Header Notice in each file and include
10   * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11   * Header, with the fields enclosed by brackets [] replaced by your own identifying
12   * information: "Portions copyright [year] [name of copyright owner]".
13   *
14   * Copyright 2015-2016 ForgeRock AS.
15   */
16  
17  package org.forgerock.api.annotations;
18  
19  import java.lang.annotation.ElementType;
20  import java.lang.annotation.Retention;
21  import java.lang.annotation.RetentionPolicy;
22  import java.lang.annotation.Target;
23  
24  import org.forgerock.api.enums.CountPolicy;
25  import org.forgerock.api.enums.PagingMode;
26  import org.forgerock.api.enums.QueryType;
27  
28  /**
29   * Indicates an CREST query method on an annotated POJO. This annotation can only be used on
30   * collection resource request handlers.
31   * <p>
32   * The annotated method's return type must be:
33   * <ul>
34   *     <li>A {@code Promise<QueryResponse, ? extends ResourceException>} promise.</li>
35   * </ul>
36   * The method must take the following parameters:
37   * <ul>
38   *     <li>A {@code org.forgerock.json.resource.QueryResourceHandler} for the results of the query.</li>
39   *     <li>A {@code org.forgerock.json.resource.QueryRequest} for the request.</li>
40   * </ul>
41   * The method may also take the following parameters:
42   * <ul>
43   *     <li>A {@link org.forgerock.services.context.Context} to be given the context.</li>
44   * </ul>
45   * @see RequestHandler
46   * @see SingletonProvider
47   * @see CollectionProvider
48   */
49  @Retention(RetentionPolicy.RUNTIME)
50  @Target(ElementType.METHOD)
51  public @interface Query {
52      /** Describe the standard operation details of this action. */
53      Operation operationDescription();
54      /** The type of query this method supports. */
55      QueryType type();
56      /** The paging modes that can be used with this query. */
57      PagingMode[] pagingModes() default {};
58      /**
59       * The count policies that can be used with this query.
60       * If the array is empty, this means that the query does not support any form of count policy,
61       * and no value for count policy should be specified
62       */
63      CountPolicy[] countPolicies() default {};
64      /**
65       * The query ID - required only when {@code type} is {@code ID}. If not supplied but required, the name of the
66       * annotated method is used.
67       */
68      String id() default "";
69      /** The set of fields that can be used in a query filter. Required only when the {@code type} is {@code FILTER}. */
70      String[] queryableFields() default {};
71      /** The keys that can be used to sort the results of the query. */
72      String[] sortKeys() default {};
73  }