001/* 002 * Copyright 2009-2022 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2009-2022 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-2022 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 super(REPLICATION_REPAIR_REQUEST_OID, true, null); 112 } 113 114 115 116 /** 117 * Creates a new replication repair request control which is decoded from 118 * the provided generic control. 119 * 120 * @param control The generic control to be decoded as a replication repair 121 * request control. 122 * 123 * @throws LDAPException If the provided control cannot be decoded as a 124 * replication repair request control. 125 */ 126 public ReplicationRepairRequestControl(@NotNull final Control control) 127 throws LDAPException 128 { 129 super(control); 130 131 if (control.hasValue()) 132 { 133 throw new LDAPException(ResultCode.DECODING_ERROR, 134 ERR_REPLICATION_REPAIR_REQUEST_HAS_VALUE.get()); 135 } 136 } 137 138 139 140 /** 141 * {@inheritDoc} 142 */ 143 @Override() 144 @NotNull() 145 public String getControlName() 146 { 147 return INFO_CONTROL_NAME_REPLICATION_REPAIR_REQUEST.get(); 148 } 149 150 151 152 /** 153 * Retrieves a representation of this replication repair request control as a 154 * JSON object. The JSON object uses the following fields (note that since 155 * this control does not have a value, neither the {@code value-base64} nor 156 * {@code value-json} fields may be present): 157 * <UL> 158 * <LI> 159 * {@code oid} -- A mandatory string field whose value is the object 160 * identifier for this control. For the replication repair request 161 * control, the OID is "1.3.6.1.4.1.30221.1.5.2". 162 * </LI> 163 * <LI> 164 * {@code control-name} -- An optional string field whose value is a 165 * human-readable name for this control. This field is only intended for 166 * descriptive purposes, and when decoding a control, the {@code oid} 167 * field should be used to identify the type of control. 168 * </LI> 169 * <LI> 170 * {@code criticality} -- A mandatory Boolean field used to indicate 171 * whether this control is considered critical. 172 * </LI> 173 * </UL> 174 * 175 * @return A JSON object that contains a representation of this control. 176 */ 177 @Override() 178 @NotNull() 179 public JSONObject toJSONControl() 180 { 181 return new JSONObject( 182 new JSONField(JSONControlDecodeHelper.JSON_FIELD_OID, 183 REPLICATION_REPAIR_REQUEST_OID), 184 new JSONField(JSONControlDecodeHelper.JSON_FIELD_CONTROL_NAME, 185 INFO_CONTROL_NAME_REPLICATION_REPAIR_REQUEST.get()), 186 new JSONField(JSONControlDecodeHelper.JSON_FIELD_CRITICALITY, 187 isCritical())); 188 } 189 190 191 192 /** 193 * Attempts to decode the provided object as a JSON representation of a 194 * replication repair request control. 195 * 196 * @param controlObject The JSON object to be decoded. It must not be 197 * {@code null}. 198 * @param strict Indicates whether to use strict mode when decoding 199 * the provided JSON object. If this is {@code true}, 200 * then this method will throw an exception if the 201 * provided JSON object contains any unrecognized 202 * fields. If this is {@code false}, then unrecognized 203 * fields will be ignored. 204 * 205 * @return The replication repair request control that was decoded from 206 * the provided JSON object. 207 * 208 * @throws LDAPException If the provided JSON object cannot be parsed as a 209 * valid replication repair request control. 210 */ 211 @NotNull() 212 public static ReplicationRepairRequestControl decodeJSONControl( 213 @NotNull final JSONObject controlObject, 214 final boolean strict) 215 throws LDAPException 216 { 217 final JSONControlDecodeHelper jsonControl = new JSONControlDecodeHelper( 218 controlObject, strict, false, false); 219 220 return new ReplicationRepairRequestControl(); 221 } 222 223 224 225 /** 226 * {@inheritDoc} 227 */ 228 @Override() 229 public void toString(@NotNull final StringBuilder buffer) 230 { 231 buffer.append("ReplicationRepairRequestControl()"); 232 } 233}