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.ldap.sdk.unboundidds.controls.
043            AssuredReplicationServerResultCode;
044import com.unboundid.util.NotMutable;
045import com.unboundid.util.NotNull;
046import com.unboundid.util.Nullable;
047import com.unboundid.util.ThreadSafety;
048import com.unboundid.util.ThreadSafetyLevel;
049import com.unboundid.util.json.JSONObject;
050
051
052
053/**
054 * This class provides a data structure that contains information about a
055 * server result from an assurance completed access log message.
056 * <BR>
057 * <BLOCKQUOTE>
058 *   <B>NOTE:</B>  This class, and other classes within the
059 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
060 *   supported for use against Ping Identity, UnboundID, and
061 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
062 *   for proprietary functionality or for external specifications that are not
063 *   considered stable or mature enough to be guaranteed to work in an
064 *   interoperable way with other types of LDAP servers.
065 * </BLOCKQUOTE>
066 */
067@NotMutable()
068@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
069public final class JSONAssuredReplicationServerResult
070       implements Serializable
071{
072  /**
073   * The serial version UID for this serializable class.
074   */
075  private static final long serialVersionUID = 7810704048456207340L;
076
077
078
079  // The result code for this result.
080  @Nullable private final AssuredReplicationServerResultCode resultCode;
081
082  // The JSON object containing an encoded representation of this server result.
083  @NotNull private final JSONObject serverResultObject;
084
085  // The replica ID for this result.
086  @Nullable private final Long replicaID;
087
088  // The replication server ID for this result.
089  @Nullable private final Long replicationServerID;
090
091
092
093  /**
094   * Creates a new JSON assured replication server result that is decoded from
095   * the provided JSON object.
096   *
097   * @param  serverResultObject  The JSON object containing an encoded
098   *                             representation of this server result.
099   */
100  public JSONAssuredReplicationServerResult(
101              @NotNull final JSONObject serverResultObject)
102  {
103    this.serverResultObject = serverResultObject;
104
105    replicaID = serverResultObject.getFieldAsLong(JSONFormattedAccessLogFields.
106         SERVER_ASSURANCE_RESULTS_REPLICA_ID.getFieldName());
107    replicationServerID = serverResultObject.getFieldAsLong(
108         JSONFormattedAccessLogFields.
109              SERVER_ASSURANCE_RESULTS_REPLICATION_SERVER_ID.getFieldName());
110
111    final String resultCodeName = serverResultObject.getFieldAsString(
112         JSONFormattedAccessLogFields.SERVER_ASSURANCE_RESULTS_RESULT_CODE.
113              getFieldName());
114    if (resultCodeName == null)
115    {
116      resultCode = null;
117    }
118    else
119    {
120      resultCode = AssuredReplicationServerResultCode.forName(resultCodeName);
121    }
122  }
123
124
125
126  /**
127   * Retrieves the JSON object containing an encoded representation of this
128   * assured replication server result.
129   *
130   * @return  The JSON object containing an encoded representation of this
131   *          certificate.
132   */
133  @NotNull()
134  public JSONObject getServerResultObject()
135  {
136    return serverResultObject;
137  }
138
139
140
141  /**
142   * Retrieves the result code for this server result.
143   *
144   * @return  The result code for this server result.
145   */
146  @Nullable()
147  public AssuredReplicationServerResultCode getResultCode()
148  {
149    return resultCode;
150  }
151
152
153
154  /**
155   * Retrieves the replication server ID for this server result.
156   *
157   * @return  The replication server ID for this server result.
158   */
159  @Nullable()
160  public Long getReplicationServerID()
161  {
162    return replicationServerID;
163  }
164
165
166
167  /**
168   * Retrieves the replica ID for this server result.
169   *
170   * @return  The replica ID for this server result.
171   */
172  @Nullable()
173  public Long getReplicaID()
174  {
175    return replicaID;
176  }
177
178
179
180  /**
181   * Retrieves a string representation of this JSON assured replication server
182   * result.
183   *
184   * @return  A string representation of this JSON assured replication server
185   *          result.
186   */
187  @Override()
188  @NotNull()
189  public String toString()
190  {
191    return serverResultObject.toSingleLineString();
192  }
193}