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.sdk;
019
020import com.unboundid.scim.schema.ResourceDescriptor;
021
022import javax.servlet.http.HttpServletRequest;
023import javax.ws.rs.core.EntityTag;
024import java.net.URI;
025
026
027
028/**
029 * This class represents a SCIM Get Resource request to retrieve all or
030 * selected attributes from a single resource.
031 */
032public final class GetResourceRequest extends ResourceReturningRequest
033{
034  /**
035   * The requested resource ID.
036   */
037  private final String resourceID;
038
039
040
041  /**
042   * Create a new SCIM Get Resource request from the provided information.
043   *
044   * @param baseURL              The base URL for the SCIM service.
045   * @param authenticatedUserID  The authenticated user name or {@code null} if
046   *                             the request is not authenticated.
047   * @param resourceDescriptor   The ResourceDescriptor associated with this
048   *                             request.
049   * @param resourceID           The requested resource ID.
050   * @param attributes           The set of requested attributes.
051   */
052  public GetResourceRequest(final URI baseURL,
053                            final String authenticatedUserID,
054                            final ResourceDescriptor resourceDescriptor,
055                            final String resourceID,
056                            final SCIMQueryAttributes attributes)
057  {
058    super(baseURL, authenticatedUserID, resourceDescriptor, attributes);
059    this.resourceID          = resourceID;
060  }
061
062
063
064  /**
065   * Create a new SCIM Get Resource request from the provided information.
066   *
067   * @param baseURL              The base URL for the SCIM service.
068   * @param authenticatedUserID  The authenticated user name or {@code null} if
069   *                             the request is not authenticated.
070   * @param resourceDescriptor   The ResourceDescriptor associated with this
071   *                             request.
072   * @param resourceID           The requested resource ID.
073   * @param attributes           The set of requested attributes.
074   * @param httpServletRequest   The HTTP servlet request associated with this
075   *                             request or {@code null} if this request is not
076   *                             initiated by a servlet.
077   */
078  public GetResourceRequest(final URI baseURL,
079                            final String authenticatedUserID,
080                            final ResourceDescriptor resourceDescriptor,
081                            final String resourceID,
082                            final SCIMQueryAttributes attributes,
083                            final HttpServletRequest httpServletRequest)
084  {
085    super(baseURL, authenticatedUserID, resourceDescriptor, attributes,
086          httpServletRequest);
087    this.resourceID          = resourceID;
088  }
089
090
091
092  /**
093   * Get the requested resource ID.
094   *
095   * @return  The requested resource ID.
096   */
097  public String getResourceID()
098  {
099    return resourceID;
100  }
101
102
103
104  /**
105   * {@inheritDoc}
106   */
107  @Override
108  protected void evaluateIfNoneMatch(final EntityTag eTag,
109                                     final String headerValue)
110      throws SCIMException
111  {
112    try
113    {
114      super.evaluateIfNoneMatch(eTag, headerValue);
115    }
116    catch (PreconditionFailedException e)
117    {
118      throw new NotModifiedException(e.getMessage(), e.getVersion(), null);
119    }
120  }
121}