001/*
002 * Copyright 2009-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2009-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) 2009-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.controls;
037
038
039
040import com.unboundid.ldap.sdk.Control;
041import com.unboundid.ldap.sdk.JSONControlDecodeHelper;
042import com.unboundid.ldap.sdk.LDAPException;
043import com.unboundid.ldap.sdk.ResultCode;
044import com.unboundid.util.NotMutable;
045import com.unboundid.util.NotNull;
046import com.unboundid.util.ThreadSafety;
047import com.unboundid.util.ThreadSafetyLevel;
048import com.unboundid.util.json.JSONField;
049import com.unboundid.util.json.JSONObject;
050
051import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*;
052
053
054
055/**
056 * This class provides an implementation of a control which may be used to
057 * process an add, delete, modify, or modify DN operation in the Directory
058 * Server which will not be replicated to other servers.  This control is
059 * primarily intended for use in manually resolving replication conflicts.
060 * <BR>
061 * <BLOCKQUOTE>
062 *   <B>NOTE:</B>  This class, and other classes within the
063 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
064 *   supported for use against Ping Identity, UnboundID, and
065 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
066 *   for proprietary functionality or for external specifications that are not
067 *   considered stable or mature enough to be guaranteed to work in an
068 *   interoperable way with other types of LDAP servers.
069 * </BLOCKQUOTE>
070 * <BR>
071 * This request control has an OID of 1.3.6.1.4.1.30221.1.5.2 and a criticality
072 * of true.  It does not have a value.
073 * <BR><BR>
074 * <H2>Example</H2>
075 * The following example demonstrates the use of the replication repair request
076 * control:
077 * <PRE>
078 * ModifyRequest modifyRequest = new ModifyRequest("dc=example,dc=com",
079 *      new Modification(ModificationType.REPLACE, "attrName", "attrValue"));
080 * modifyRequest.addControl(new ReplicationRepairRequestControl());
081 * LDAPResult modifyResult = connection.modify(modifyRequest);
082 * </PRE>
083 */
084@NotMutable()
085@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
086public final class ReplicationRepairRequestControl
087       extends Control
088{
089  /**
090   * The OID (1.3.6.1.4.1.30221.1.5.2) for the replication repair request
091   * control.
092   */
093  @NotNull public static final String REPLICATION_REPAIR_REQUEST_OID =
094       "1.3.6.1.4.1.30221.1.5.2";
095
096
097
098  /**
099   * The serial version UID for this serializable class.
100   */
101  private static final long serialVersionUID = 8036161025439278805L;
102
103
104
105  /**
106   * Creates a new replication repair request control.  It will be marked
107   * critical.
108   */
109  public ReplicationRepairRequestControl()
110  {
111    this(true);
112  }
113
114
115
116  /**
117   * Creates a new replication repair request control with the specified
118   * criticality.
119   *
120   * @param  isCritical  Indicates whether the control should be marked
121   *                     critical.
122   */
123  public ReplicationRepairRequestControl(final boolean isCritical)
124  {
125    super(REPLICATION_REPAIR_REQUEST_OID, isCritical, null);
126  }
127
128
129
130  /**
131   * Creates a new replication repair request control which is decoded from
132   * the provided generic control.
133   *
134   * @param  control  The generic control to be decoded as a replication repair
135   *                  request control.
136   *
137   * @throws  LDAPException  If the provided control cannot be decoded as a
138   *                         replication repair request control.
139   */
140  public ReplicationRepairRequestControl(@NotNull final Control control)
141         throws LDAPException
142  {
143    super(control);
144
145    if (control.hasValue())
146    {
147      throw new LDAPException(ResultCode.DECODING_ERROR,
148                              ERR_REPLICATION_REPAIR_REQUEST_HAS_VALUE.get());
149    }
150  }
151
152
153
154  /**
155   * {@inheritDoc}
156   */
157  @Override()
158  @NotNull()
159  public String getControlName()
160  {
161    return INFO_CONTROL_NAME_REPLICATION_REPAIR_REQUEST.get();
162  }
163
164
165
166  /**
167   * Retrieves a representation of this replication repair request control as a
168   * JSON object.  The JSON object uses the following fields (note that since
169   * this control does not have a value, neither the {@code value-base64} nor
170   * {@code value-json} fields may be present):
171   * <UL>
172   *   <LI>
173   *     {@code oid} -- A mandatory string field whose value is the object
174   *     identifier for this control.  For the replication repair request
175   *     control, the OID is "1.3.6.1.4.1.30221.1.5.2".
176   *   </LI>
177   *   <LI>
178   *     {@code control-name} -- An optional string field whose value is a
179   *     human-readable name for this control.  This field is only intended for
180   *     descriptive purposes, and when decoding a control, the {@code oid}
181   *     field should be used to identify the type of control.
182   *   </LI>
183   *   <LI>
184   *     {@code criticality} -- A mandatory Boolean field used to indicate
185   *     whether this control is considered critical.
186   *   </LI>
187   * </UL>
188   *
189   * @return  A JSON object that contains a representation of this control.
190   */
191  @Override()
192  @NotNull()
193  public JSONObject toJSONControl()
194  {
195    return new JSONObject(
196         new JSONField(JSONControlDecodeHelper.JSON_FIELD_OID,
197              REPLICATION_REPAIR_REQUEST_OID),
198         new JSONField(JSONControlDecodeHelper.JSON_FIELD_CONTROL_NAME,
199              INFO_CONTROL_NAME_REPLICATION_REPAIR_REQUEST.get()),
200         new JSONField(JSONControlDecodeHelper.JSON_FIELD_CRITICALITY,
201              isCritical()));
202  }
203
204
205
206  /**
207   * Attempts to decode the provided object as a JSON representation of a
208   * replication repair request control.
209   *
210   * @param  controlObject  The JSON object to be decoded.  It must not be
211   *                        {@code null}.
212   * @param  strict         Indicates whether to use strict mode when decoding
213   *                        the provided JSON object.  If this is {@code true},
214   *                        then this method will throw an exception if the
215   *                        provided JSON object contains any unrecognized
216   *                        fields.  If this is {@code false}, then unrecognized
217   *                        fields will be ignored.
218   *
219   * @return  The replication repair request control that was decoded from
220   *          the provided JSON object.
221   *
222   * @throws  LDAPException  If the provided JSON object cannot be parsed as a
223   *                         valid replication repair request control.
224   */
225  @NotNull()
226  public static ReplicationRepairRequestControl decodeJSONControl(
227              @NotNull final JSONObject controlObject,
228              final boolean strict)
229         throws LDAPException
230  {
231    final JSONControlDecodeHelper jsonControl = new JSONControlDecodeHelper(
232         controlObject, strict, false, false);
233
234    return new ReplicationRepairRequestControl();
235  }
236
237
238
239  /**
240   * {@inheritDoc}
241   */
242  @Override()
243  public void toString(@NotNull final StringBuilder buffer)
244  {
245    buffer.append("ReplicationRepairRequestControl()");
246  }
247}