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.util.Set;
041
042import com.unboundid.ldap.sdk.unboundidds.logs.AccessLogMessageType;
043import com.unboundid.ldap.sdk.unboundidds.logs.AccessLogOperationType;
044import com.unboundid.ldap.sdk.unboundidds.logs.LogException;
045import com.unboundid.ldap.sdk.unboundidds.logs.v2.
046            IntermediateResponseAccessLogMessage;
047import com.unboundid.util.NotMutable;
048import com.unboundid.util.NotNull;
049import com.unboundid.util.Nullable;
050import com.unboundid.util.ThreadSafety;
051import com.unboundid.util.ThreadSafetyLevel;
052import com.unboundid.util.json.JSONObject;
053
054import static com.unboundid.ldap.sdk.unboundidds.logs.v2.json.JSONLogMessages.*;
055
056
057
058/**
059 * This class provides a data structure that holds information about a
060 * JSON-formatted operation request access log message.
061 * <BR>
062 * <BLOCKQUOTE>
063 *   <B>NOTE:</B>  This class, and other classes within the
064 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
065 *   supported for use against Ping Identity, UnboundID, and
066 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
067 *   for proprietary functionality or for external specifications that are not
068 *   considered stable or mature enough to be guaranteed to work in an
069 *   interoperable way with other types of LDAP servers.
070 * </BLOCKQUOTE>
071 */
072@NotMutable()
073@ThreadSafety(level=ThreadSafetyLevel.INTERFACE_THREADSAFE)
074public final class JSONIntermediateResponseAccessLogMessage
075       extends JSONRequestAccessLogMessage
076       implements IntermediateResponseAccessLogMessage
077{
078  /**
079   * The serial version UID for this serializable class.
080   */
081  private static final long serialVersionUID = -8154114903633681042L;
082
083
084
085  // The operation type for this log message.
086  @NotNull private final AccessLogOperationType operationType;
087
088  // The set of response control OIDs for this log message.
089  @NotNull private final Set<String> responseControlOIDs;
090
091  // The intermediate response name for this log message.
092  @Nullable private final String intermediateResponseName;
093
094  // The intermediate response OID for this log message.
095  @Nullable private final String oid;
096
097  // A string representation of the intermediate response value for this log
098  // message.
099  @Nullable private final String valueString;
100
101
102
103  /**
104   * Creates a new JSON intermediate response access log message from the
105   * provided JSON object.
106   *
107   * @param  jsonObject  The JSON object that contains an encoded representation
108   *                     of this log message.  It must not be {@code null}.
109   *
110   * @throws  LogException  If the provided JSON object cannot be parsed as a
111   *                        valid log message.
112   */
113  public JSONIntermediateResponseAccessLogMessage(
114              @NotNull final JSONObject jsonObject)
115         throws LogException
116  {
117    super(jsonObject);
118
119    oid = getString(JSONFormattedAccessLogFields.INTERMEDIATE_RESPONSE_OID);
120    intermediateResponseName = getString(
121         JSONFormattedAccessLogFields.INTERMEDIATE_RESPONSE_NAME);
122    valueString = getString(
123         JSONFormattedAccessLogFields.INTERMEDIATE_RESPONSE_VALUE);
124    responseControlOIDs = getStringSet(
125         JSONFormattedAccessLogFields.RESPONSE_CONTROL_OIDS);
126
127    final String operationTypeName = getString(
128         JSONFormattedAccessLogFields.OPERATION_TYPE);
129    if (operationTypeName == null)
130    {
131      final String jsonObjectString = jsonObject.toSingleLineString();
132      throw new LogException(jsonObjectString,
133           ERR_INTERMEDIATE_RESPONSE_CANNOT_IDENTIFY_OPERATION_TYPE.get(
134                jsonObjectString));
135    }
136    else
137    {
138      operationType = AccessLogOperationType.forName(operationTypeName);
139      if (operationType == null)
140      {
141        final String jsonObjectString = jsonObject.toSingleLineString();
142        throw new LogException(jsonObjectString,
143             ERR_INTERMEDIATE_RESPONSE_CANNOT_IDENTIFY_OPERATION_TYPE.get(
144                  jsonObjectString));
145      }
146    }
147  }
148
149
150
151  /**
152   * {@inheritDoc}
153   */
154  @Override()
155  @NotNull()
156  public AccessLogMessageType getMessageType()
157  {
158    return AccessLogMessageType.INTERMEDIATE_RESPONSE;
159  }
160
161
162
163  /**
164   * {@inheritDoc}
165   */
166  @Override()
167  @NotNull()
168  public AccessLogOperationType getOperationType()
169  {
170    return operationType;
171  }
172
173
174
175  /**
176   * {@inheritDoc}
177   */
178  @Override()
179  @Nullable()
180  public String getOID()
181  {
182    return oid;
183  }
184
185
186
187  /**
188   * {@inheritDoc}
189   */
190  @Override()
191  @Nullable()
192  public String getResponseName()
193  {
194    return intermediateResponseName;
195  }
196
197
198
199  /**
200   * {@inheritDoc}
201   */
202  @Override()
203  @Nullable()
204  public String getValueString()
205  {
206    return valueString;
207  }
208
209
210
211  /**
212   * {@inheritDoc}
213   */
214  @Override()
215  @NotNull()
216  public Set<String> getResponseControlOIDs()
217  {
218    return responseControlOIDs;
219  }
220}