001/* 002 * Copyright 2019 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2019 Ping Identity Corporation 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021package com.unboundid.ldap.sdk.transformations; 022 023 024 025import java.io.Serializable; 026import java.util.Collection; 027import java.util.Collections; 028import java.util.EnumSet; 029import java.util.Set; 030 031import com.unboundid.ldap.sdk.ChangeType; 032import com.unboundid.ldif.LDIFChangeRecord; 033import com.unboundid.util.NotMutable; 034import com.unboundid.util.StaticUtils; 035import com.unboundid.util.ThreadSafety; 036import com.unboundid.util.ThreadSafetyLevel; 037 038 039 040/** 041 * This class provides an LDIF change record transformation that can exclude 042 * change records that can exclude LDIF change records that match any of a 043 * provided set of change types. It will not have any effect on LDIF records 044 * that do not contain a change type (which must be entries). 045 */ 046@NotMutable() 047@ThreadSafety(level = ThreadSafetyLevel.COMPLETELY_THREADSAFE) 048public final class ExcludeChangeTypeTransformation 049 implements LDIFChangeRecordTransformation, Serializable 050{ 051 /** 052 * The serial version UID for this serializable class. 053 */ 054 private static final long serialVersionUID = -6927917616913251572L; 055 056 057 058 // The set of change types for records to be excluded. 059 private final Set<ChangeType> excludedChangeTypes; 060 061 062 063 /** 064 * Creates a new exclude change type transformation that will exclude change 065 * records with any of the provided change types. 066 * 067 * @param changeTypes The set of change types to exclude. 068 */ 069 public ExcludeChangeTypeTransformation(final ChangeType... changeTypes) 070 { 071 this(StaticUtils.toList(changeTypes)); 072 } 073 074 075 076 /** 077 * Creates a new exclude change type transformation that will exclude change 078 * records with any of the provided change types. 079 * 080 * @param changeTypes The set of change types to exclude. 081 */ 082 public ExcludeChangeTypeTransformation( 083 final Collection<ChangeType> changeTypes) 084 { 085 if (changeTypes == null) 086 { 087 excludedChangeTypes = Collections.emptySet(); 088 } 089 else 090 { 091 final EnumSet<ChangeType> ctSet = EnumSet.noneOf(ChangeType.class); 092 ctSet.addAll(changeTypes); 093 excludedChangeTypes = Collections.unmodifiableSet(ctSet); 094 } 095 } 096 097 098 099 /** 100 * {@inheritDoc} 101 */ 102 @Override() 103 public LDIFChangeRecord transformChangeRecord( 104 final LDIFChangeRecord changeRecord) 105 { 106 if (excludedChangeTypes.contains(changeRecord.getChangeType())) 107 { 108 return null; 109 } 110 else 111 { 112 return changeRecord; 113 } 114 } 115 116 117 118 /** 119 * {@inheritDoc} 120 */ 121 @Override() 122 public LDIFChangeRecord translate(final LDIFChangeRecord original, 123 final long firstLineNumber) 124 { 125 if (excludedChangeTypes.contains(original.getChangeType())) 126 { 127 return null; 128 } 129 else 130 { 131 return original; 132 } 133 } 134 135 136 137 /** 138 * {@inheritDoc} 139 */ 140 @Override() 141 public LDIFChangeRecord translateChangeRecordToWrite( 142 final LDIFChangeRecord original) 143 { 144 if (excludedChangeTypes.contains(original.getChangeType())) 145 { 146 return null; 147 } 148 else 149 { 150 return original; 151 } 152 } 153}