001/*
002 * Copyright 2007-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2007-2020 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) 2015-2020 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.asn1.ASN1OctetString;
041import com.unboundid.ldap.sdk.Control;
042import com.unboundid.ldap.sdk.LDAPException;
043import com.unboundid.ldap.sdk.ResultCode;
044import com.unboundid.ldap.sdk.controls.AssertionRequestControl;
045import com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl;
046import com.unboundid.ldap.sdk.controls.PostReadRequestControl;
047import com.unboundid.ldap.sdk.controls.PreReadRequestControl;
048import com.unboundid.ldap.sdk.controls.ProxiedAuthorizationV1RequestControl;
049import com.unboundid.ldap.sdk.controls.ProxiedAuthorizationV2RequestControl;
050import com.unboundid.ldap.sdk.controls.SubtreeDeleteRequestControl;
051import com.unboundid.ldap.sdk.unboundidds.extensions.
052            StartBatchedTransactionExtendedRequest;
053import com.unboundid.util.NotMutable;
054import com.unboundid.util.ThreadSafety;
055import com.unboundid.util.ThreadSafetyLevel;
056
057import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*;
058
059
060
061/**
062 * This class provides an implementation of the batched transaction
063 * specification request control, which may be used to indicate that the
064 * associated add, delete, modify, modify DN, or password modify operation is
065 * part of a batched transaction.  The transaction should be created with the
066 * start batched transaction extended operation, which will obtain a transaction
067 * ID, and the transaction may be committed or aborted using the end batched
068 * transaction extended operation.
069 * <BR>
070 * <BLOCKQUOTE>
071 *   <B>NOTE:</B>  This class, and other classes within the
072 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
073 *   supported for use against Ping Identity, UnboundID, and
074 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
075 *   for proprietary functionality or for external specifications that are not
076 *   considered stable or mature enough to be guaranteed to work in an
077 *   interoperable way with other types of LDAP servers.
078 * </BLOCKQUOTE>
079 * <BR>
080 * Note that directory servers may limit the set of controls that are available
081 * for use in requests that are part of a transaction.  RFC 5805 section 4
082 * indicates that the following controls may be used in conjunction with the
083 * transaction specification request control:  {@link AssertionRequestControl},
084 * {@link ManageDsaITRequestControl}, {@link PreReadRequestControl}, and
085 * {@link PostReadRequestControl}.  The
086 * {@link ProxiedAuthorizationV1RequestControl} and
087 * {@link ProxiedAuthorizationV2RequestControl} controls cannot be included in
088 * requests that are part of a transaction, but you can include them in the
089 * {@link StartBatchedTransactionExtendedRequest} to indicate that all
090 * operations within the transaction should be processed with the specified
091 * authorization identity.
092 * <BR><BR>
093 * The Ping Identity, UnboundID, and Nokia/Alcatel-Lucent 8661 server products
094 * support the following additional UnboundID-specific controls in conjunction
095 * with operations included in a transaction:
096 * {@link AccountUsableRequestControl}, {@link HardDeleteRequestControl},
097 * {@link IntermediateClientRequestControl},
098 * {@link PasswordPolicyRequestControl},
099 * {@link ReplicationRepairRequestControl}, {@link SoftDeleteRequestControl},
100 * {@link SoftDeletedEntryAccessRequestControl},
101 * {@link SubtreeDeleteRequestControl}, and {@link UndeleteRequestControl}.
102 * <BR><BR>
103 * See the documentation for the {@link StartBatchedTransactionExtendedRequest}
104 * class for an example of processing a batched transaction.
105 */
106@NotMutable()
107@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
108public final class BatchedTransactionSpecificationRequestControl
109       extends Control
110{
111  /**
112   * The OID (1.3.6.1.4.1.30221.2.5.1) for the batched transaction specification
113   * request control.
114   */
115  public static final String BATCHED_TRANSACTION_SPECIFICATION_REQUEST_OID =
116       "1.3.6.1.4.1.30221.2.5.1";
117
118
119
120  /**
121   * The serial version UID for this serializable class.
122   */
123  private static final long serialVersionUID = -6817702055586260189L;
124
125
126
127  // The transaction ID for the associated transaction.
128  private final ASN1OctetString transactionID;
129
130
131
132  /**
133   * Creates a new batched transaction specification request control with the
134   * provided transaction ID.
135   *
136   * @param  transactionID  The transaction ID for the associated transaction,
137   *                        as obtained from the start batched transaction
138   *                        extended operation.  It must not be {@code null}.
139   */
140  public BatchedTransactionSpecificationRequestControl(
141              final ASN1OctetString transactionID)
142  {
143    super(BATCHED_TRANSACTION_SPECIFICATION_REQUEST_OID, true,
144         new ASN1OctetString(transactionID.getValue()));
145
146    this.transactionID = transactionID;
147  }
148
149
150
151  /**
152   * Creates a new batched transaction specification request control which is
153   * decoded from the provided generic control.
154   *
155   * @param  control  The generic control to be decoded as a batched transaction
156   *                  specification request control.
157   *
158   * @throws  LDAPException  If the provided control cannot be decoded as a
159   *                         batched transaction specification request control.
160   */
161  public BatchedTransactionSpecificationRequestControl(final Control control)
162         throws LDAPException
163  {
164    super(control);
165
166    transactionID = control.getValue();
167    if (transactionID == null)
168    {
169      throw new LDAPException(ResultCode.DECODING_ERROR,
170                              ERR_TXN_REQUEST_CONTROL_NO_VALUE.get());
171    }
172  }
173
174
175
176  /**
177   * Retrieves the transaction ID for the associated transaction.
178   *
179   * @return  The transaction ID for the associated transaction.
180   */
181  public ASN1OctetString getTransactionID()
182  {
183    return transactionID;
184  }
185
186
187
188  /**
189   * {@inheritDoc}
190   */
191  @Override()
192  public String getControlName()
193  {
194    return INFO_CONTROL_NAME_BATCHED_TXN_REQUEST.get();
195  }
196
197
198
199  /**
200   * {@inheritDoc}
201   */
202  @Override()
203  public void toString(final StringBuilder buffer)
204  {
205    buffer.append("BatchedTransactionSpecificationRequestControl(" +
206                  "transactionID='");
207    buffer.append(transactionID.stringValue());
208    buffer.append("')");
209  }
210}