001/* 002 * Copyright 2019-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2019-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) 2019-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.transformations; 037 038 039 040import java.io.Serializable; 041import java.util.Collection; 042import java.util.Collections; 043import java.util.EnumSet; 044import java.util.Set; 045 046import com.unboundid.ldap.sdk.ChangeType; 047import com.unboundid.ldif.LDIFChangeRecord; 048import com.unboundid.util.NotMutable; 049import com.unboundid.util.StaticUtils; 050import com.unboundid.util.ThreadSafety; 051import com.unboundid.util.ThreadSafetyLevel; 052 053 054 055/** 056 * This class provides an LDIF change record transformation that can exclude 057 * change records that can exclude LDIF change records that match any of a 058 * provided set of change types. It will not have any effect on LDIF records 059 * that do not contain a change type (which must be entries). 060 */ 061@NotMutable() 062@ThreadSafety(level = ThreadSafetyLevel.COMPLETELY_THREADSAFE) 063public final class ExcludeChangeTypeTransformation 064 implements LDIFChangeRecordTransformation, Serializable 065{ 066 /** 067 * The serial version UID for this serializable class. 068 */ 069 private static final long serialVersionUID = -6927917616913251572L; 070 071 072 073 // The set of change types for records to be excluded. 074 private final Set<ChangeType> excludedChangeTypes; 075 076 077 078 /** 079 * Creates a new exclude change type transformation that will exclude change 080 * records with any of the provided change types. 081 * 082 * @param changeTypes The set of change types to exclude. 083 */ 084 public ExcludeChangeTypeTransformation(final ChangeType... changeTypes) 085 { 086 this(StaticUtils.toList(changeTypes)); 087 } 088 089 090 091 /** 092 * Creates a new exclude change type transformation that will exclude change 093 * records with any of the provided change types. 094 * 095 * @param changeTypes The set of change types to exclude. 096 */ 097 public ExcludeChangeTypeTransformation( 098 final Collection<ChangeType> changeTypes) 099 { 100 if (changeTypes == null) 101 { 102 excludedChangeTypes = Collections.emptySet(); 103 } 104 else 105 { 106 final EnumSet<ChangeType> ctSet = EnumSet.noneOf(ChangeType.class); 107 ctSet.addAll(changeTypes); 108 excludedChangeTypes = Collections.unmodifiableSet(ctSet); 109 } 110 } 111 112 113 114 /** 115 * {@inheritDoc} 116 */ 117 @Override() 118 public LDIFChangeRecord transformChangeRecord( 119 final LDIFChangeRecord changeRecord) 120 { 121 if (excludedChangeTypes.contains(changeRecord.getChangeType())) 122 { 123 return null; 124 } 125 else 126 { 127 return changeRecord; 128 } 129 } 130 131 132 133 /** 134 * {@inheritDoc} 135 */ 136 @Override() 137 public LDIFChangeRecord translate(final LDIFChangeRecord original, 138 final long firstLineNumber) 139 { 140 if (excludedChangeTypes.contains(original.getChangeType())) 141 { 142 return null; 143 } 144 else 145 { 146 return original; 147 } 148 } 149 150 151 152 /** 153 * {@inheritDoc} 154 */ 155 @Override() 156 public LDIFChangeRecord translateChangeRecordToWrite( 157 final LDIFChangeRecord original) 158 { 159 if (excludedChangeTypes.contains(original.getChangeType())) 160 { 161 return null; 162 } 163 else 164 { 165 return original; 166 } 167 } 168}