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