001/* 002 * Copyright 2011-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2011-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.extensions; 037 038 039 040import java.util.ArrayList; 041import java.util.Collection; 042import java.util.Collections; 043import java.util.Iterator; 044import java.util.List; 045 046import com.unboundid.asn1.ASN1Boolean; 047import com.unboundid.asn1.ASN1Element; 048import com.unboundid.asn1.ASN1OctetString; 049import com.unboundid.asn1.ASN1Sequence; 050import com.unboundid.ldap.sdk.LDAPException; 051import com.unboundid.ldap.sdk.ResultCode; 052import com.unboundid.util.Debug; 053import com.unboundid.util.NotMutable; 054import com.unboundid.util.StaticUtils; 055import com.unboundid.util.ThreadSafety; 056import com.unboundid.util.ThreadSafetyLevel; 057import com.unboundid.util.Validator; 058 059import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*; 060 061 062 063/** 064 * This class provides an implementation of a get changelog batch change 065 * selection criteria value that indicates that the server should not return 066 * changes which target only the specified attributes. This can be useful for 067 * ignoring changes to attributes which are changed frequently but not of 068 * interest to the client. Note that changes returned may include changes to 069 * these attributes, but only if the change targets other attributes that should 070 * not be ignored. 071 * <BR> 072 * <BLOCKQUOTE> 073 * <B>NOTE:</B> This class, and other classes within the 074 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 075 * supported for use against Ping Identity, UnboundID, and 076 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 077 * for proprietary functionality or for external specifications that are not 078 * considered stable or mature enough to be guaranteed to work in an 079 * interoperable way with other types of LDAP servers. 080 * </BLOCKQUOTE> 081 */ 082@NotMutable() 083@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 084public final class IgnoreAttributesChangeSelectionCriteria 085 extends ChangelogBatchChangeSelectionCriteria 086{ 087 /** 088 * The inner BER type that should be used for encoded elements that represent 089 * an ignore attributes get changelog batch selection criteria value. 090 */ 091 static final byte TYPE_SELECTION_CRITERIA_IGNORE_ATTRIBUTES = (byte) 0xA3; 092 093 094 095 // Indicates whether to automatically consider all operational attributes in 096 // the ignore list. 097 private final boolean ignoreOperationalAttributes; 098 099 // The names of the attributes to ignore. 100 private final List<String> attributeNames; 101 102 103 104 /** 105 * Creates a new ignore attributes change selection criteria value with the 106 * provided information. 107 * 108 * @param ignoreOperationalAttributes Indicates whether to automatically 109 * include all operational attributes in 110 * the set of attributes to ignore. 111 * @param attributeNames The names of the attributes to ignore. 112 * It may be {@code null} or empty only 113 * if 114 * {@code ignoreOperationalAttributes} 115 * is {@code true} and no user attributes 116 * changes should be ignored. 117 */ 118 public IgnoreAttributesChangeSelectionCriteria( 119 final boolean ignoreOperationalAttributes, 120 final String... attributeNames) 121 { 122 this(ignoreOperationalAttributes, StaticUtils.toList(attributeNames)); 123 } 124 125 126 127 /** 128 * Creates a new ignore attributes change selection criteria value with the 129 * provided information. 130 * 131 * @param ignoreOperationalAttributes Indicates whether to automatically 132 * include all operational attributes in 133 * the set of attributes to ignore. 134 * @param attributeNames The names of the attributes to ignore. 135 * It may be {@code null} or empty only 136 * if 137 * {@code ignoreOperationalAttributes} 138 * is {@code true} and no user attributes 139 * changes should be ignored. 140 */ 141 public IgnoreAttributesChangeSelectionCriteria( 142 final boolean ignoreOperationalAttributes, 143 final Collection<String> attributeNames) 144 { 145 if ((attributeNames == null) || attributeNames.isEmpty()) 146 { 147 Validator.ensureTrue(ignoreOperationalAttributes); 148 this.attributeNames = Collections.emptyList(); 149 } 150 else 151 { 152 this.attributeNames = 153 Collections.unmodifiableList(new ArrayList<>(attributeNames)); 154 } 155 156 this.ignoreOperationalAttributes = ignoreOperationalAttributes; 157 } 158 159 160 161 /** 162 * Decodes the provided ASN.1 element, which is the inner element of a 163 * changelog batch change selection criteria element, as an all attributes 164 * change selection criteria value. 165 * 166 * @param innerElement The inner element of a changelog batch change 167 * selection criteria element to be decoded. 168 * 169 * @return The decoded all attributes change selection criteria value. 170 * 171 * @throws LDAPException If a problem is encountered while trying to decode 172 * the provided element as the inner element of an all 173 * attributes change selection criteria value. 174 */ 175 static IgnoreAttributesChangeSelectionCriteria decodeInnerElement( 176 final ASN1Element innerElement) 177 throws LDAPException 178 { 179 try 180 { 181 final ASN1Element[] elements = 182 ASN1Sequence.decodeAsSequence(innerElement).elements(); 183 final ASN1Element[] attrElements = 184 ASN1Sequence.decodeAsSequence(elements[0]).elements(); 185 final ArrayList<String> attrNames = new ArrayList<>(attrElements.length); 186 for (final ASN1Element e : attrElements) 187 { 188 attrNames.add(ASN1OctetString.decodeAsOctetString(e).stringValue()); 189 } 190 191 return new IgnoreAttributesChangeSelectionCriteria( 192 ASN1Boolean.decodeAsBoolean(elements[1]).booleanValue(), 193 attrNames); 194 } 195 catch (final Exception e) 196 { 197 Debug.debugException(e); 198 throw new LDAPException(ResultCode.DECODING_ERROR, 199 ERR_IGNORE_ATTRS_CHANGE_SELECTION_CRITERIA_DECODE_ERROR.get( 200 StaticUtils.getExceptionMessage(e)), 201 e); 202 } 203 } 204 205 206 207 /** 208 * Indicates whether to automatically include all operational attributes in 209 * the set of attributes to ignore. 210 * 211 * @return {@code true} if all operational attributes should automatically be 212 * included in the set of attributes to ignore, or {@code false} if 213 * only those operational attributes which are explicitly named 214 * should be ignored. 215 */ 216 public boolean ignoreOperationalAttributes() 217 { 218 return ignoreOperationalAttributes; 219 } 220 221 222 223 /** 224 * Retrieves the names of the target attributes for changes that should be 225 * retrieved. 226 * 227 * @return The names of the target attributes for changes that should be 228 * retrieved. 229 */ 230 public List<String> getAttributeNames() 231 { 232 return attributeNames; 233 } 234 235 236 237 /** 238 * {@inheritDoc} 239 */ 240 @Override() 241 public ASN1Element encodeInnerElement() 242 { 243 final ArrayList<ASN1Element> attrNameElements = 244 new ArrayList<>(attributeNames.size()); 245 for (final String s : attributeNames) 246 { 247 attrNameElements.add(new ASN1OctetString(s)); 248 } 249 250 return new ASN1Sequence(TYPE_SELECTION_CRITERIA_IGNORE_ATTRIBUTES, 251 new ASN1Sequence(attrNameElements), 252 new ASN1Boolean(ignoreOperationalAttributes)); 253 } 254 255 256 257 /** 258 * {@inheritDoc} 259 */ 260 @Override() 261 public void toString(final StringBuilder buffer) 262 { 263 buffer.append("IgnoreAttributesChangeSelectionCriteria(attributeNames={"); 264 265 final Iterator<String> iterator = attributeNames.iterator(); 266 while (iterator.hasNext()) 267 { 268 buffer.append(iterator.next()); 269 if (iterator.hasNext()) 270 { 271 buffer.append(','); 272 } 273 } 274 275 buffer.append("}, ignoreOperationalAttributes="); 276 buffer.append(ignoreOperationalAttributes); 277 buffer.append(')'); 278 } 279}