Class EntryWriter
EntryWriter is used in two ways: either to create a new entry in the directory, or to modify an existing entry.
When creating a new entry, EntryWriter can derive values from an existing entry.
Callers may add, modify or delete values from the Entry that they
are creating with EntryWriter. When the modifications are complete,
then by calling apply(DirectorySession, CommonArgs)
, EntryWriter
will perform the appropriate series of operations on the Directory to write
the new Entry.
// Given a directory entry "cn=nick,o=isode" with // the following attributes: // cn=nick // sn=hudson // objectClass=inetorgperson, person, mboxgroup // description="Old description" // mboxGroupMember="notWantedMember, superMember" // then the following set of operations DN oldDN = new DN("cn=nick,o=isode"); Selection sel = new Selection(SelectionType.ALL_USER_AND_OPER_ATTRIBUTES); Indication ind = ds.read(oldDN, sel, null); Entry oldEntry = ind.getEntry(0); DN newDN = new DN("cn=harry,o=isode"); EntryWriter ew = new EntryWriter(oldEntry, newDN); // ensure that objectClass contains mboxGroup ew.add(AttributeTypes.objectClass, "mboxGroup"); // force description to be "New description" ew.set(AttributeTypes.description, "New description"); // ensure that mboxGroupMember maultivalued attribute has "wantedMember" value ew.add(AttributeTypes.mboxGroupMember,"wantedMember"); // ensure that mboxGroupMember maultivalued attribute has no "notWantedMember" value ew.delete(AttributeTypes.mboxGroupMember,"notWantedMember"); ew.apply(ds, null); // will result in the "cn=nick,o=isode" entry being renamed/relocated to // "cn=harry,o=isode" with the following attributes: // cn=harry // sn=hudson // objectclass=inetorgperson, person, mboxgroup // description="New description" // mboxGroupMember=wantedMember, superMember
- Since:
- 14.5
- Author:
- mst
-
Constructor Summary
ConstructorsConstructorDescriptionEntryWriter
(DN newDn) Constructs a new EntryWriter supposed to create new EntryEntryWriter
(Entry entry) Constructs a new EntryWriter allowing modify existing entry.EntryWriter
(Entry oldEntry, DN newDn) Constructs a new EntryWriter.EntryWriter
(Entry oldEntry, DN newDn, boolean relocate) Constructs a new EntryWriter. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add values from given attribute.void
add
(AttributeType at, String val) Modify attribute by adding string value.void
add
(AttributeType at, String[] vals) Modify attribute by adding string values.Values that already exist, will be ignored.void
add
(AttributeType at, Collection<String> vals) Modify attribute by adding string values.Values that already exist, will be ignored.void
addBer
(AttributeType at, byte[] val) Modify attribute by adding BER value.If the value already exists, it will be ignored.void
addBer
(AttributeType at, Collection<byte[]> vals) Modify attribute by adding BER values.Values that already exist, will be ignored.void
addBin
(AttributeType at, byte[] val) Modify attribute by adding binary value.If the value already exists, it will be ignored.void
addBin
(AttributeType at, Collection<byte[]> vals) Modify attribute by adding binary values.Values that already exist, will be ignored.apply
(DirectorySession ds, CommonArgs ca) Apply changes to the directory.void
Delete the attribute and the values specified in the attribute value field of the attribute.void
delete
(AttributeType attrType) Delete the attribute and all its values from the entry if it exists.void
delete
(AttributeType at, String val) Modify attribute by deleting string value.void
delete
(AttributeType at, String[] vals) Modify attribute by deleting string values.The values that exist in the existing entry will be removed and others would be ignoredvoid
delete
(AttributeType at, Collection<String> vals) Modify attribute by deleting string values.void
deleteBer
(AttributeType at, byte[] val) Modify attribute by deleting BER value.The value will be deleted on apply if it exists in the existing entry else no action would be takenvoid
deleteBer
(AttributeType at, Collection<byte[]> vals) Modify attribute by deleting BER values.void
deleteBin
(AttributeType at, byte[] val) Modify attribute by deleting binary value.void
deleteBin
(AttributeType at, Collection<byte[]> vals) Modify attribute by deleting binary values.boolean
Determines if there are any changes pending to be committed to the directory for an existing entry.boolean
Determine if the changes have already been appliedboolean
hasChanges
(AttributeType... attributeTypes) Determines if there are any changes pending to be committed to the directory for the given list of attribute types in an existing entry.void
Set values from given attribute.void
set
(AttributeType at, Boolean val) Modify attribute by setting boolean value.void
set
(AttributeType at, String val) Modify attribute by setting string value to an attribute with string syntax.void
set
(AttributeType at, String[] vals) Modify attribute by setting string values.After the apply operation the attribute type will have the values specified and existing values be removedvoid
set
(AttributeType at, Collection<String> vals) Modify attribute by setting string values.After the apply operation the attribute type will have the values specified and existing values be removedvoid
setBer
(AttributeType at, byte[] val) Modify attribute by setting BER value.void
setBer
(AttributeType at, Collection<byte[]> vals) Modify attribute by setting BER values.void
setBin
(AttributeType at, byte[] val) Modify attribute by setting binary value.void
setBin
(AttributeType at, Collection<byte[]> vals) Modify attribute by setting binary values.toString()
Return user friendly report of planned entry modifications which will be performed byapply(DirectorySession, CommonArgs)
method
-
Constructor Details
-
EntryWriter
Constructs a new EntryWriter.- if oldEntry is not null, then all of the attribute values
from oldEntry will be set in the EntryWriter object, and
the result of calling
apply(DirectorySession, CommonArgs)
is that oldEntry will be renamed/relocated to newDn and modified to gain specified values - if oldEntry has the same DN as newDN, then the
result of calling
apply(DirectorySession, CommonArgs)
is that oldEntry will be modified.
- If oldEntry is null then new Entry at newDN will be created
- If oldEntry RDN is different from newDn RDN - it will be renamed
- If oldEntry parent DN is different from newDn parent DN and relocation is allowed then it will be relocated in DIT
- Parameters:
oldEntry
- old entry (may benull
if an entry is to be created)
newDn
- new DN; If the parent dn is different from old entry's dn, it will be relocated only if relocate flag is true, else just the RDN will be renamed (null
allowed but not when oldEntry is
null
)relocate
- allow to relocate entry (for false only RDN will be changed)
- if oldEntry is not null, then all of the attribute values
from oldEntry will be set in the EntryWriter object, and
the result of calling
-
EntryWriter
Constructs a new EntryWriter.- if oldEntry is not null, then all of the attribute values
from oldEntry will be set in the EntryWriter object, and
the result of calling
apply(DirectorySession, CommonArgs)
is that oldEntry will be renamed/relocated to newDn and modified to gain specified values - if oldEntry has the same DN as newDN, then the
result of calling
apply(DirectorySession, CommonArgs)
is that oldEntry will be modified.
- If oldEntry is null then new Entry at newDN will be created
- If oldEntry RDN is different from newDn RDN - it will be renamed
- If oldEntry parent DN is different from newDn parent DN and relocation is allowed then it will be relocated in DIT
- Parameters:
oldEntry
- old entry (may benull
if an entry is to be created)
newDn
- new DN; If the parent dn is different from old entry's dn, it will be relocated only (null
allowed but not when oldEntry is
null
)
- if oldEntry is not null, then all of the attribute values
from oldEntry will be set in the EntryWriter object, and
the result of calling
-
EntryWriter
Constructs a new EntryWriter supposed to create new Entry- Parameters:
newDn
- new entry DN (notnull
)- Throws:
NullPointerException
- if newDn isnull
- Since:
- 15.0
-
EntryWriter
Constructs a new EntryWriter allowing modify existing entry.- Parameters:
entry
- existing entry (notnull
)- Throws:
NullPointerException
- if entry isnull
-
-
Method Details
-
set
Modify attribute by setting string value to an attribute with string syntax. After the apply operation the attribute type will have the values specified and existing values be removed- Parameters:
at
- attribute type (not null)val
- value to set; if null or an empty String (""), the attribute will be deleted- Throws:
BadValueException
- if value is not a valid LDAP-encoded value for attribute.
-
set
Modify attribute by setting boolean value. After the apply operation the attribute type will have the values specified and existing values be removed- Parameters:
at
- attribute type (not null)val
- value to set, if null the attribute would be deleted- Throws:
BadValueException
- if attribute type is not of type boolean .NullPointerException
- if attribute type is null
-
setBer
Modify attribute by setting BER value. After the apply operation the attribute type will have the values specified and existing values be removed- Parameters:
at
- attribute type (not null)val
- value to set , if null or empty the attribute would be deleted- Throws:
BadValueException
- BadValueException if val is not a valid value for the specified attribute type- Since:
- 14.6
- See Also:
-
setBin
Modify attribute by setting binary value. After the apply operation the attribute type will have the values specified and existing values be removed- Parameters:
at
- attribute type (not null)val
- value to set,if null or empty the attribute would be deleted- Throws:
BadValueException
- BadValueException if val is not a valid value for the specified attribute type- Since:
- 14.6
- See Also:
-
add
Modify attribute by adding string value. If the value already exists, it will be ignored.For a single valued attribute in the EntryWriter object, this function could be called multiple times. The first time it would add the attribute if it didn't exist in its copy yet; the subsequent times it would update its copy of the attribute value.
- Parameters:
at
- attribute type (not null)val
- value to set; if null or an empty String (""), no modification will be performed.- Throws:
BadValueException
- if value is not a valid LDAP-encoded value for attribute.
-
addBin
Modify attribute by adding binary value.If the value already exists, it will be ignored.For a single valued attribute in the EntryWriter object, this function could be called multiple times. The first time it would add the attribute if it didn't exist in its copy yet; the subsequent times it would update its copy of the attribute value.
- Parameters:
at
- attribute type (not null)val
- value to set (if null or empty - no modification will be performed)- Throws:
BadValueException
- BadValueException if val is not a valid value for the specified attribute type- Since:
- 14.6
- See Also:
-
addBer
Modify attribute by adding BER value.If the value already exists, it will be ignored.For a single valued attribute in the EntryWriter object, this function could be called multiple times. The first time it would add the attribute if it didn't exist in its copy yet; the subsequent times it would update its copy of the attribute value.
- Parameters:
at
- attribute type (not null)val
- value to set (if null or empty - then no modification will be performed)- Throws:
BadValueException
- BadValueException if val is not a valid value for the specified attribute type- Since:
- 14.6
- See Also:
-
delete
Modify attribute by deleting string value. The value will be deleted on apply if it exists in the existing entry else no action would be taken- Parameters:
at
- attribute type (not null)val
- value to delete; if null or an empty String (""), then no modification will be performed- Throws:
BadValueException
- if value is not a valid LDAP-encoded value for attribute.
-
deleteBin
Modify attribute by deleting binary value. The value will be deleted on apply if it exists in the existing entry else no action would be taken- Parameters:
at
- attribute type (not null)val
- value to set (if null or empty - then no modification will be performed)- Throws:
BadValueException
- BadValueException if val is not a valid value for the specified attribute type- Since:
- 14.6
- See Also:
-
deleteBer
Modify attribute by deleting BER value.The value will be deleted on apply if it exists in the existing entry else no action would be taken- Parameters:
at
- attribute type (not null)val
- value to set (if null or empty - then no modification will be performed)- Throws:
BadValueException
- BadValueException if val is not a valid value for the specified attribute type- Since:
- 14.6
- See Also:
-
set
Modify attribute by setting string values.After the apply operation the attribute type will have the values specified and existing values be removed- Parameters:
at
- attribute type (not null)vals
- values to set. If vals is null or an empty Collection, the attribute will be deleted from the entry. Any empty Strings ("") in vals are ignored.- Throws:
BadValueException
- if values are not a valid LDAP-encoded value for attribute or if this method is being called for single-valued attributes. .
-
set
Modify attribute by setting string values.After the apply operation the attribute type will have the values specified and existing values be removed- Parameters:
at
- attribute type (not null)vals
- values to set (if null or null, the attribute will be deleted from the entry)- Throws:
BadValueException
- if values are not a valid LDAP-encoded value for attribute or if this method is being called for single-valued attributes. .
-
add
Modify attribute by adding string values.Values that already exist, will be ignored.- Parameters:
at
- attribute type (not null)vals
- values to set. If vals is null or an empty Collection, then no modification will be performed). Any empty Strings ("") inside vals are ignored.- Throws:
BadValueException
- if values are not a valid LDAP-encoded value for attribute or if this method is being called for single-valued attributes.
-
add
Modify attribute by adding string values.Values that already exist, will be ignored.- Parameters:
at
- attribute type (not null)vals
- values to set (may be null or empty - then no modification will be performed)- Throws:
BadValueException
- if values are not a valid LDAP-encoded value for attribute.
-
delete
Modify attribute by deleting string values. The values that exist in the existing entry will be removed and others would be ignored- Parameters:
at
- attribute type (not null)vals
- values to set. If vals is null, or an empty Collection, then no modification will be performed. Any empty Strings ("") inside vals are ignored.- Throws:
BadValueException
- if values are not a valid LDAP-encoded value for attribute or if this method is being called for single-valued attributes.
-
delete
Modify attribute by deleting string values.The values that exist in the existing entry will be removed and others would be ignored- Parameters:
at
- attribute type (not null)vals
- values to set (if null or empty - then no modification will be performed)- Throws:
BadValueException
- if values are not a valid LDAP-encoded value for attribute.
-
setBin
Modify attribute by setting binary values. After the apply operation the attribute type will have the value specified.- Parameters:
at
- attribute type (not null)vals
- values to set (if null or empty - the attribute will be deleted)- Throws:
BadValueException
- BadValueException if val is not a valid value for the specified attribute type or if this method is being called for single-valued attributes.- Since:
- 14.6
- See Also:
-
setBer
Modify attribute by setting BER values. After the apply operation the attribute type will have the values specified and existing values be removed- Parameters:
at
- attribute type (not null)vals
- values to set (if null or empty - then the attribute would be deleted)- Throws:
BadValueException
- BadValueException if val is not a valid value for the specified attribute type or if this method is being called for single-valued attributes.- Since:
- 14.6
- See Also:
-
addBin
Modify attribute by adding binary values.Values that already exist, will be ignored.- Parameters:
at
- attribute type (not null)vals
- values to set (if null or empty - then no modification will be performed)- Throws:
BadValueException
- BadValueException if val is not a valid value for the specified attribute typeor if this method is being called for single-valued attributes.- Since:
- 14.6
- See Also:
-
addBer
Modify attribute by adding BER values.Values that already exist, will be ignored.- Parameters:
at
- attribute type (not null)vals
- values to set (if null or empty - then no modification will be performed)- Throws:
BadValueException
- BadValueException if val is not a valid value for the specified attribute type or if this method is being called for single-valued attributes.- Since:
- 14.6
- See Also:
-
deleteBin
Modify attribute by deleting binary values. On apply only the value will be deleted if it exists and no action would be taken if it does not exist- Parameters:
at
- attribute type (not null)vals
- values to set (if null or empty - then no modification will be performed)- Throws:
BadValueException
- BadValueException if val is not a valid value for the specified attribute type or if this method is being called for single-valued attributes.- Since:
- 14.6
- See Also:
-
deleteBer
Modify attribute by deleting BER values. On apply the values that exist in the existing entry would be deleted while no action would be taken for the ones that don't exist.- Parameters:
at
- attribute type (not null)vals
- values to set (if null or empty - then no modification will be performed)- Throws:
BadValueException
- BadValueException if val is not a valid value for the specified attribute type or if this method is being called for single-valued attributes.- Since:
- 14.6
- See Also:
-
set
Set values from given attribute. After the apply operation the attribute type will have the values specified and existing values be removed- Parameters:
attr
- attribute (should not be null)
-
add
Add values from given attribute. Values that already exist, will be ignored.For a single valued attribute in the EntryWriter object, this function could be called multiple times. The first time it would add the attribute if it didn't exist in its copy yet; the subsequent times it would update its copy of the attribute value.
- Parameters:
attr
- attribute (should not be null)
-
delete
Delete the attribute and all its values from the entry if it exists.- Parameters:
attrType
- attribute type- Since:
- 15.0
-
delete
Delete the attribute and the values specified in the attribute value field of the attribute. If it is empty then all values would be deleted on apply- Parameters:
attr
- attribute
-
hasBeenApplied
public boolean hasBeenApplied()Determine if the changes have already been applied- Returns:
- true if the changes have been applied and false otherwise
-
apply
Apply changes to the directory. If directory session is not specified then it just simulates operation allowing to get report of performed directory operations.For real directory operation (when ds!=null) this method can be called only once as for Entry modification it would have no effect for next calls and impossible for renaming operation. So make sure that this methods gets called with non-null directory sessions only when changes have not been applied by using the method
hasBeenApplied()
For ds==null no operation will be performed on directory but whole process will be simulated in order to generate operations report only (This functionality is used by
toString()
method- Parameters:
ds
- directory session (may be null - for getting report only)ca
- common arguments (may be null)- Returns:
- operation report
- Throws:
DSAPIException
- See Also:
-
toString
Return user friendly report of planned entry modifications which will be performed byapply(DirectorySession, CommonArgs)
method -
entryHasChanges
public boolean entryHasChanges()Determines if there are any changes pending to be committed to the directory for an existing entry.This method should only be used when the object of this class has been created to modify an existing entry. This must not be invoked when the object of this class has been created with a null entry,for example,for creating or renaming or relocation operations.
If you know the attribute types that could have been modified in the entry, it would be more efficient to invoke the method
hasChanges(AttributeType...)
.- Returns:
- TRUE if there are changes to any attributes in the entry, FALSE if there are no changes or if the class had been invoked with null old entry
- Since:
- 15.0
-
hasChanges
Determines if there are any changes pending to be committed to the directory for the given list of attribute types in an existing entry.This must not be invoked for create entry or rename entry or relocate operations.
This method will look for changes in each given attribute type one by one and return TRUE as soon as it finds a change.
If no attribute type is given, it will return FALSE.
- Parameters:
attributeTypes
- list of attribute types for which pending changes need to be determined, must not be null- Returns:
- TRUE if there are pending changes in any attribute type in the given list, FALSE if there are no changes in any or if the class had been invoked with null old entry
- Since:
- 15.0
-