001/*
002 * Copyright 2007-2022 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2007-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) 2007-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.extensions;
037
038
039
040import com.unboundid.asn1.ASN1OctetString;
041import com.unboundid.ldap.sdk.Control;
042import com.unboundid.ldap.sdk.ExtendedResult;
043import com.unboundid.ldap.sdk.ResultCode;
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;
049
050import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*;
051
052
053
054/**
055 * This class implements a data structure for storing the information from an
056 * extended result for the start batched transaction extended request.  It is
057 * able to decode a generic extended result to extract the transaction ID that
058 * it contains, if the operation was successful.
059 * <BR>
060 * <BLOCKQUOTE>
061 *   <B>NOTE:</B>  This class, and other classes within the
062 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
063 *   supported for use against Ping Identity, UnboundID, and
064 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
065 *   for proprietary functionality or for external specifications that are not
066 *   considered stable or mature enough to be guaranteed to work in an
067 *   interoperable way with other types of LDAP servers.
068 * </BLOCKQUOTE>
069 * <BR>
070 * See the documentation for the {@link StartBatchedTransactionExtendedRequest}
071 * class for an example that demonstrates the use of batched transactions.
072 */
073@NotMutable()
074@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
075public final class StartBatchedTransactionExtendedResult
076       extends ExtendedResult
077{
078  /**
079   * The serial version UID for this serializable class.
080   */
081  private static final long serialVersionUID = 7661263203064470371L;
082
083
084
085  // The transaction ID returned by the server.
086  @Nullable private final ASN1OctetString transactionID;
087
088
089
090  /**
091   * Creates a new start batched transaction extended result from the provided
092   * extended result.
093   *
094   * @param  extendedResult  The extended result to be decoded as a start
095   *                         batched transaction extended result.  It must not
096   *                         be {@code null}.
097   */
098  public StartBatchedTransactionExtendedResult(
099              @NotNull final ExtendedResult extendedResult)
100  {
101    super(extendedResult);
102
103    transactionID = extendedResult.getValue();
104  }
105
106
107
108  /**
109   * Creates a new start batched transaction extended result with the provided
110   * information.
111   *
112   * @param  messageID          The message ID for the LDAP message that is
113   *                            associated with this LDAP result.
114   * @param  resultCode         The result code from the response.
115   * @param  diagnosticMessage  The diagnostic message from the response, if
116   *                            available.
117   * @param  matchedDN          The matched DN from the response, if available.
118   * @param  referralURLs       The set of referral URLs from the response, if
119   *                            available.
120   * @param  transactionID      The transaction ID for this response, if
121   *                            available.
122   * @param  responseControls   The set of controls from the response, if
123   *                            available.
124   */
125  public StartBatchedTransactionExtendedResult(final int messageID,
126              @NotNull final ResultCode resultCode,
127              @Nullable final String diagnosticMessage,
128              @Nullable final String matchedDN,
129              @Nullable final String[] referralURLs,
130              @Nullable final ASN1OctetString transactionID,
131              @Nullable final Control[] responseControls)
132  {
133    super(messageID, resultCode, diagnosticMessage, matchedDN, referralURLs,
134          null, transactionID, responseControls);
135
136    this.transactionID = transactionID;
137  }
138
139
140
141  /**
142   * Retrieves the transaction ID for this start batched transaction extended
143   * result, if available.
144   *
145   * @return  The transaction ID for this start batched transaction extended
146   *          result, or {@code null} if none was provided.
147   */
148  @Nullable()
149  public ASN1OctetString getTransactionID()
150  {
151    return transactionID;
152  }
153
154
155
156  /**
157   * {@inheritDoc}
158   */
159  @Override()
160  @NotNull()
161  public String getExtendedResultName()
162  {
163    return INFO_EXTENDED_RESULT_NAME_START_BATCHED_TXN.get();
164  }
165
166
167
168  /**
169   * Appends a string representation of this extended result to the provided
170   * buffer.
171   *
172   * @param  buffer  The buffer to which a string representation of this
173   *                 extended result will be appended.
174   */
175  @Override()
176  public void toString(@NotNull final StringBuilder buffer)
177  {
178    buffer.append("StartBatchedTransactionExtendedResult(resultCode=");
179    buffer.append(getResultCode());
180
181    final int messageID = getMessageID();
182    if (messageID >= 0)
183    {
184      buffer.append(", messageID=");
185      buffer.append(messageID);
186    }
187
188    if (transactionID != null)
189    {
190      buffer.append(", transactionID='");
191      buffer.append(transactionID.stringValue());
192      buffer.append('\'');
193    }
194
195    final String diagnosticMessage = getDiagnosticMessage();
196    if (diagnosticMessage != null)
197    {
198      buffer.append(", diagnosticMessage='");
199      buffer.append(diagnosticMessage);
200      buffer.append('\'');
201    }
202
203    final String matchedDN = getMatchedDN();
204    if (matchedDN != null)
205    {
206      buffer.append(", matchedDN='");
207      buffer.append(matchedDN);
208      buffer.append('\'');
209    }
210
211    final String[] referralURLs = getReferralURLs();
212    if (referralURLs.length > 0)
213    {
214      buffer.append(", referralURLs={");
215      for (int i=0; i < referralURLs.length; i++)
216      {
217        if (i > 0)
218        {
219          buffer.append(", ");
220        }
221
222        buffer.append('\'');
223        buffer.append(referralURLs[i]);
224        buffer.append('\'');
225      }
226      buffer.append('}');
227    }
228
229    final Control[] responseControls = getResponseControls();
230    if (responseControls.length > 0)
231    {
232      buffer.append(", responseControls={");
233      for (int i=0; i < responseControls.length; i++)
234      {
235        if (i > 0)
236        {
237          buffer.append(", ");
238        }
239
240        buffer.append(responseControls[i]);
241      }
242      buffer.append('}');
243    }
244
245    buffer.append(')');
246  }
247}