001/*
002 * Copyright 2022-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2022-2024 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2022-2024 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk.unboundidds.logs.v2.json;
037
038
039
040import java.io.Serializable;
041
042import com.unboundid.util.NotMutable;
043import com.unboundid.util.NotNull;
044import com.unboundid.util.Nullable;
045import com.unboundid.util.ThreadSafety;
046import com.unboundid.util.ThreadSafetyLevel;
047import com.unboundid.util.json.JSONObject;
048
049import static com.unboundid.ldap.sdk.unboundidds.logs.v2.json.
050                   JSONFormattedAccessLogFields.*;
051
052
053
054/**
055 * This class provides a data structure that contains information about an
056 * JSON-formatted operation purpose request control.
057 * <BR>
058 * <BLOCKQUOTE>
059 *   <B>NOTE:</B>  This class, and other classes within the
060 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
061 *   supported for use against Ping Identity, UnboundID, and
062 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
063 *   for proprietary functionality or for external specifications that are not
064 *   considered stable or mature enough to be guaranteed to work in an
065 *   interoperable way with other types of LDAP servers.
066 * </BLOCKQUOTE>
067 */
068@NotMutable()
069@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
070public final class JSONOperationPurposeRequestControl
071       implements Serializable
072{
073  /**
074   * The serial version UID for this serializable class.
075   */
076  private static final long serialVersionUID = 7062571568593641747L;
077
078
079
080  // The JSON object with an encoded representation of this control.
081  @NotNull private final JSONObject controlObject;
082
083  // The application name from the control.
084  @Nullable private final String applicationName;
085
086  // The application version from the control.
087  @Nullable private final String applicationVersion;
088
089  // The code location from the control.
090  @Nullable private final String codeLocation;
091
092  // The request purpose from the control.
093  @Nullable private final String requestPurpose;
094
095
096
097  /**
098   * Creates a new JSON operation purpose request control that is decoded from
099   * the provided JSON object.
100   *
101   * @param  controlObject  The JSON object containing an encoded representation
102   *                        of this operation purpose request control.
103   */
104  public JSONOperationPurposeRequestControl(
105              @NotNull final JSONObject controlObject)
106  {
107    this.controlObject = controlObject;
108
109    applicationName = controlObject.getFieldAsString(
110         OPERATION_PURPOSE_APPLICATION_NAME.getFieldName());
111    applicationVersion = controlObject.getFieldAsString(
112         OPERATION_PURPOSE_APPLICATION_VERSION.getFieldName());
113    codeLocation = controlObject.getFieldAsString(
114         OPERATION_PURPOSE_CODE_LOCATION.getFieldName());
115    requestPurpose = controlObject.getFieldAsString(
116         OPERATION_PURPOSE_REQUEST_PURPOSE.getFieldName());
117  }
118
119
120
121  /**
122   * Retrieves a JSON object containing an encoded representation of this
123   * operation purpose request control.
124   *
125   * @return  A JSON object containing an encoded representation of this
126   *          operation purpose request control.
127   */
128  @NotNull()
129  public JSONObject getControlObject()
130  {
131    return controlObject;
132  }
133
134
135
136  /**
137   * Retrieves the name of the application that generated this control.
138   *
139   * @return  The name of the application that generated this control, or
140   *          {@code null} if it was not included in the log message.
141   */
142  @Nullable()
143  public String getApplicationName()
144  {
145    return applicationName;
146  }
147
148
149
150  /**
151   * Retrieves the version of the application that generated this control.
152   *
153   * @return  The version of the application that generated this control, or
154   *          {@code null} if it was not included in the log message.
155   */
156  @Nullable()
157  public String getApplicationVersion()
158  {
159    return applicationVersion;
160  }
161
162
163
164  /**
165   * Retrieves a description of the location in the application code where the
166   * control was generated.
167   *
168   * @return  A description of the location in the application code where the
169   *          control was generated, or {@code null} if it was not included in
170   *          the log message.
171   */
172  @Nullable()
173  public String getCodeLocation()
174  {
175    return codeLocation;
176  }
177
178
179
180  /**
181   * Retrieves the request purpose from the control.
182   *
183   * @return  The request purpose from the control, or {@code null} if it was
184   *          not included in the log message.
185   */
186  @Nullable()
187  public String getRequestPurpose()
188  {
189    return requestPurpose;
190  }
191
192
193
194  /**
195   * Retrieves a string representation of this operation purpose request
196   * control.
197   *
198   * @return  A string representation of this operation purpose request control.
199   */
200  @NotNull()
201  public String toString()
202  {
203    return controlObject.toSingleLineString();
204  }
205}