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.data.ServiceProviderConfig;
021    
022    import javax.ws.rs.GET;
023    import javax.ws.rs.Path;
024    import javax.ws.rs.Produces;
025    import javax.ws.rs.core.MediaType;
026    import javax.ws.rs.core.Response;
027    
028    import static com.unboundid.scim.sdk.SCIMConstants.
029        RESOURCE_ENDPOINT_SERVICE_PROVIDER_CONFIG;
030    
031    
032    
033    /**
034     * This class is a JAX-RS resource for the SCIM Service Provider Configuration.
035     */
036    @Path(RESOURCE_ENDPOINT_SERVICE_PROVIDER_CONFIG)
037    public class ServiceProviderConfigResource extends AbstractStaticResource
038    {
039      private final SCIMApplication application;
040      private final ResourceStats resourceStats;
041    
042      /**
043       * Create a new JAX-RS resource.
044       *
045       * @param application    The SCIM JAX-RS application associated with this
046       *                       resource.
047       * @param resourceStats  The ResourceStats instance to use.
048       */
049      public ServiceProviderConfigResource(final SCIMApplication application,
050                                           final ResourceStats resourceStats) {
051        this.application = application;
052        this.resourceStats = resourceStats;
053      }
054    
055      /**
056       * Implement the GET operation to fetch the configuration in JSON format.
057       *
058       * @return  The response to the request.
059       */
060      @GET
061      @Produces(MediaType.APPLICATION_JSON)
062      public Response doJsonGet()
063      {
064        final ServiceProviderConfig config = application.getServiceProviderConfig();
065        Response.ResponseBuilder builder = Response.ok();
066    
067        setResponseEntity(builder, MediaType.APPLICATION_JSON_TYPE, config);
068        resourceStats.incrementStat(ResourceStats.GET_RESPONSE_JSON);
069        resourceStats.incrementStat(ResourceStats.GET_OK);
070        return builder.build();
071      }
072    
073    
074    
075      /**
076       * Implement the GET operation to fetch the configuration in XML format.
077       *
078       * @return  The response to the request.
079       */
080      @GET
081      @Produces(MediaType.APPLICATION_XML)
082      public Response doXmlGet()
083      {
084        final ServiceProviderConfig config = application.getServiceProviderConfig();
085        Response.ResponseBuilder builder = Response.ok();
086    
087        setResponseEntity(builder, MediaType.APPLICATION_XML_TYPE, config);
088        resourceStats.incrementStat(ResourceStats.GET_RESPONSE_XML);
089        resourceStats.incrementStat(ResourceStats.GET_OK);
090        return builder.build();
091      }
092    }