001    /*
002     * Copyright 2011-2012 UnboundID Corp.
003     *
004     * This program is free software; you can redistribute it and/or modify
005     * it under the terms of the GNU General Public License (GPLv2 only)
006     * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
007     * as published by the Free Software Foundation.
008     *
009     * This program is distributed in the hope that it will be useful,
010     * but WITHOUT ANY WARRANTY; without even the implied warranty of
011     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012     * GNU General Public License for more details.
013     *
014     * You should have received a copy of the GNU General Public License
015     * along with this program; if not, see <http://www.gnu.org/licenses>.
016     */
017    
018    package com.unboundid.scim.wink;
019    
020    import com.unboundid.scim.schema.ResourceDescriptor;
021    import com.unboundid.scim.sdk.SCIMBackend;
022    
023    import javax.servlet.ServletContext;
024    import javax.ws.rs.GET;
025    import javax.ws.rs.Produces;
026    import javax.ws.rs.QueryParam;
027    import javax.ws.rs.core.Context;
028    import javax.ws.rs.core.HttpHeaders;
029    import javax.ws.rs.core.MediaType;
030    import javax.ws.rs.core.Response;
031    import javax.ws.rs.core.SecurityContext;
032    import javax.ws.rs.core.UriInfo;
033    
034    import static com.unboundid.scim.sdk.SCIMConstants.QUERY_PARAMETER_FILTER;
035    import static com.unboundid.scim.sdk.SCIMConstants.QUERY_PARAMETER_PAGE_SIZE;
036    import static com.unboundid.scim.sdk.SCIMConstants.
037        QUERY_PARAMETER_PAGE_START_INDEX;
038    import static com.unboundid.scim.sdk.SCIMConstants.QUERY_PARAMETER_SORT_BY;
039    import static com.unboundid.scim.sdk.SCIMConstants.QUERY_PARAMETER_SORT_ORDER;
040    
041    
042    
043    /**
044     * This class is a Wink dynamic resource implementation for query operations
045     * on a SCIM resource where the client requests XML response format in the URL
046     * by appending ".xml" on to the endpoint.
047     */
048    public class XMLQueryResource extends AbstractSCIMResource
049    {
050      /**
051       * Create a new SCIM wink resource for XML query operations on a
052       * SCIM endpoint.
053       *
054       * @param resourceDescriptor   The ResourceDescriptor associated with this
055       *                             resource.
056       * @param resourceStats       The ResourceStats instance to use.
057       * @param backend             The SCIMBackend to use to process requests.
058       */
059      public XMLQueryResource(final ResourceDescriptor resourceDescriptor,
060                              final ResourceStats resourceStats,
061                              final SCIMBackend backend)
062      {
063        super(resourceDescriptor.getEndpoint() + ".xml",
064            resourceDescriptor, resourceStats, backend);
065      }
066    
067    
068    
069      /**
070       * Implement the GET operation producing XML format.
071       *
072       * @param servletContext   The servlet context of the current request.
073       * @param securityContext  The security context of the current request.
074       * @param headers          The request headers.
075       * @param uriInfo          The URI info for the request.
076       * @param filterString     The filter query parameter, or {@code null}.
077       * @param sortBy           The sortBy query parameter, or {@code null}.
078       * @param sortOrder        The sortOrder query parameter, or {@code null}.
079       * @param pageStartIndex   The startIndex query parameter, or {@code null}.
080       * @param pageSize         The count query parameter, or {@code null}.
081       *
082       * @return  The response to the request.
083       */
084      @GET
085      @Produces(MediaType.APPLICATION_XML)
086      public Response doXmlGet(@Context final ServletContext servletContext,
087                               @Context final SecurityContext securityContext,
088                               @Context final HttpHeaders headers,
089                               @Context final UriInfo uriInfo,
090                               @QueryParam(QUERY_PARAMETER_FILTER)
091                               final String filterString,
092                               @QueryParam(QUERY_PARAMETER_SORT_BY)
093                               final String sortBy,
094                               @QueryParam(QUERY_PARAMETER_SORT_ORDER)
095                               final String sortOrder,
096                               @QueryParam(QUERY_PARAMETER_PAGE_START_INDEX)
097                               final String pageStartIndex,
098                               @QueryParam(QUERY_PARAMETER_PAGE_SIZE)
099                               final String pageSize)
100      {
101        final RequestContext requestContext =
102            new RequestContext(servletContext, securityContext, headers, uriInfo,
103                               MediaType.APPLICATION_XML_TYPE,
104                               MediaType.APPLICATION_XML_TYPE);
105    
106        return getUsers(requestContext, filterString, sortBy, sortOrder,
107                        pageStartIndex, pageSize);
108      }
109    
110    
111    
112    }