You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2016/06/15 12:30:01 UTC
svn commit: r1748572 [16/23] - in
/directory/apacheds/branches/apacheds-value: ./
benchmarks/installers-maven-plugin/
benchmarks/installers-maven-plugin/.settings/
benchmarks/installers-maven-plugin/target/
benchmarks/installers-maven-plugin/target/cla...
Modified: directory/apacheds/branches/apacheds-value/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-value/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java?rev=1748572&r1=1748571&r2=1748572&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-value/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java (original)
+++ directory/apacheds/branches/apacheds-value/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java Wed Jun 15 12:29:57 2016
@@ -22,6 +22,7 @@ package org.apache.directory.server.core
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -34,12 +35,10 @@ import org.apache.directory.api.ldap.mod
import org.apache.directory.api.ldap.model.cursor.EmptyCursor;
import org.apache.directory.api.ldap.model.cursor.SingletonCursor;
import org.apache.directory.api.ldap.model.entry.Attribute;
-import org.apache.directory.api.ldap.model.entry.BinaryValue;
import org.apache.directory.api.ldap.model.entry.DefaultAttribute;
import org.apache.directory.api.ldap.model.entry.DefaultModification;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.entry.Modification;
-import org.apache.directory.api.ldap.model.entry.StringValue;
import org.apache.directory.api.ldap.model.entry.Value;
import org.apache.directory.api.ldap.model.exception.LdapAttributeInUseException;
import org.apache.directory.api.ldap.model.exception.LdapException;
@@ -82,7 +81,9 @@ import org.apache.directory.server.core.
import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
import org.apache.directory.server.core.api.interceptor.context.CompareOperationContext;
import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.ModDnAva;
import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.MoveAndRenameOperationContext;
import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext;
import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
import org.apache.directory.server.core.api.partition.PartitionNexus;
@@ -114,17 +115,11 @@ public class SchemaInterceptor extends B
private TopFilter topFilter;
- private List<EntryFilter> filters = new ArrayList<EntryFilter>();
-
- /** A normalized form for the SubschemaSubentry Dn */
- private String subschemaSubentryDnNorm;
+ private List<EntryFilter> filters = new ArrayList<>();
/** The SubschemaSubentry Dn */
private Dn subschemaSubentryDn;
- /** The normalized name for the schema modification attributes */
- private Dn schemaModificationAttributesDn;
-
/** The schema manager */
private SchemaSubentryManager schemaSubEntryManager;
@@ -159,6 +154,7 @@ public class SchemaInterceptor extends B
* @param directoryService the directory service core
* @throws Exception if there are problems during initialization
*/
+ @Override
public void init( DirectoryService directoryService ) throws LdapException
{
if ( IS_DEBUG )
@@ -175,12 +171,8 @@ public class SchemaInterceptor extends B
schemaBaseDn = dnFactory.create( SchemaConstants.OU_SCHEMA );
// stuff for dealing with subentries (garbage for now)
- Value<?> subschemaSubentry = nexus.getRootDseValue( directoryService.getAtProvider().getSubschemaSubentry() );
- subschemaSubentryDn = dnFactory.create( subschemaSubentry.getString() );
- subschemaSubentryDnNorm = subschemaSubentryDn.getNormName();
-
- schemaModificationAttributesDn = dnFactory.create(
- SchemaConstants.SCHEMA_MODIFICATIONS_DN );
+ Value subschemaSubentry = nexus.getRootDseValue( directoryService.getAtProvider().getSubschemaSubentry() );
+ subschemaSubentryDn = dnFactory.create( subschemaSubentry.getValue() );
computeSuperiors();
@@ -206,9 +198,9 @@ public class SchemaInterceptor extends B
{
List<ObjectClass> parents = superiors.get( objectClass.getOid() );
- List<AttributeType> mustList = new ArrayList<AttributeType>();
- List<AttributeType> allowedList = new ArrayList<AttributeType>();
- Set<String> mustSeen = new HashSet<String>();
+ List<AttributeType> mustList = new ArrayList<>();
+ List<AttributeType> allowedList = new ArrayList<>();
+ Set<String> mustSeen = new HashSet<>();
allMust.put( objectClass.getOid(), mustList );
allowed.put( objectClass.getOid(), allowedList );
@@ -217,7 +209,7 @@ public class SchemaInterceptor extends B
{
List<AttributeType> mustParent = parent.getMustAttributeTypes();
- if ( ( mustParent != null ) && ( mustParent.size() != 0 ) )
+ if ( ( mustParent != null ) && !mustParent.isEmpty() )
{
for ( AttributeType attributeType : mustParent )
{
@@ -250,8 +242,8 @@ public class SchemaInterceptor extends B
{
List<ObjectClass> parents = superiors.get( objectClass.getOid() );
- List<AttributeType> mayList = new ArrayList<AttributeType>();
- Set<String> maySeen = new HashSet<String>();
+ List<AttributeType> mayList = new ArrayList<>();
+ Set<String> maySeen = new HashSet<>();
List<AttributeType> allowedList = allowed.get( objectClass.getOid() );
allMay.put( objectClass.getOid(), mayList );
@@ -260,7 +252,7 @@ public class SchemaInterceptor extends B
{
List<AttributeType> mustParent = parent.getMustAttributeTypes();
- if ( ( mustParent != null ) && ( mustParent.size() != 0 ) )
+ if ( ( mustParent != null ) && !mustParent.isEmpty() )
{
for ( AttributeType attributeType : mustParent )
{
@@ -296,7 +288,7 @@ public class SchemaInterceptor extends B
List<ObjectClass> parents = objectClass.getSuperiors();
// Loop on all the objectClass superiors
- if ( ( parents != null ) && ( parents.size() != 0 ) )
+ if ( ( parents != null ) && !parents.isEmpty() )
{
for ( ObjectClass parent : parents )
{
@@ -327,13 +319,13 @@ public class SchemaInterceptor extends B
*/
private void computeSuperior( ObjectClass objectClass ) throws LdapException
{
- List<ObjectClass> ocSuperiors = new ArrayList<ObjectClass>();
+ List<ObjectClass> ocSuperiors = new ArrayList<>();
superiors.put( objectClass.getOid(), ocSuperiors );
computeOCSuperiors( objectClass, ocSuperiors, new HashSet<String>() );
- Set<String> atSeen = new HashSet<String>();
+ Set<String> atSeen = new HashSet<>();
computeMustAttributes( objectClass, atSeen );
computeMayAttributes( objectClass, atSeen );
@@ -348,10 +340,10 @@ public class SchemaInterceptor extends B
private void computeSuperiors() throws LdapException
{
Iterator<ObjectClass> objectClasses = schemaManager.getObjectClassRegistry().iterator();
- superiors = new ConcurrentHashMap<String, List<ObjectClass>>();
- allMust = new ConcurrentHashMap<String, List<AttributeType>>();
- allMay = new ConcurrentHashMap<String, List<AttributeType>>();
- allowed = new ConcurrentHashMap<String, List<AttributeType>>();
+ superiors = new ConcurrentHashMap<>();
+ allMust = new ConcurrentHashMap<>();
+ allMay = new ConcurrentHashMap<>();
+ allowed = new ConcurrentHashMap<>();
while ( objectClasses.hasNext() )
{
@@ -361,15 +353,15 @@ public class SchemaInterceptor extends B
}
- private Value<?> convert( AttributeType attributeType, Value<?> value ) throws LdapException
+ private Value convert( AttributeType attributeType, Value value ) throws LdapException
{
if ( attributeType.getSyntax().isHumanReadable() )
{
- if ( value instanceof BinaryValue )
+ if ( !value.isHumanReadable() )
{
try
{
- return new StringValue( attributeType, new String( ( ( BinaryValue ) value ).getBytes(), "UTF-8" ) );
+ return new Value( attributeType, new String( value.getBytes(), "UTF-8" ) );
}
catch ( UnsupportedEncodingException uee )
{
@@ -381,10 +373,7 @@ public class SchemaInterceptor extends B
}
else
{
- if ( value instanceof StringValue )
- {
- return new BinaryValue( attributeType, ( ( StringValue ) value ).getBytes() );
- }
+ return new Value( attributeType, value.getBytes() );
}
return null;
@@ -415,10 +404,10 @@ public class SchemaInterceptor extends B
{
if ( filter instanceof EqualityNode )
{
- EqualityNode node = ( ( EqualityNode ) filter );
- Value<?> value = node.getValue();
+ EqualityNode node = ( EqualityNode ) filter;
+ Value value = node.getValue();
- Value<?> newValue = convert( node.getAttributeType(), value );
+ Value newValue = convert( node.getAttributeType(), value );
if ( newValue != null )
{
@@ -427,10 +416,10 @@ public class SchemaInterceptor extends B
}
else if ( filter instanceof GreaterEqNode )
{
- GreaterEqNode node = ( ( GreaterEqNode ) filter );
- Value<?> value = node.getValue();
+ GreaterEqNode node = ( GreaterEqNode ) filter;
+ Value value = node.getValue();
- Value<?> newValue = convert( node.getAttributeType(), value );
+ Value newValue = convert( node.getAttributeType(), value );
if ( newValue != null )
{
@@ -440,10 +429,10 @@ public class SchemaInterceptor extends B
}
else if ( filter instanceof LessEqNode )
{
- LessEqNode node = ( ( LessEqNode ) filter );
- Value<?> value = node.getValue();
+ LessEqNode node = ( LessEqNode ) filter;
+ Value value = node.getValue();
- Value<?> newValue = convert( node.getAttributeType(), value );
+ Value newValue = convert( node.getAttributeType(), value );
if ( newValue != null )
{
@@ -452,16 +441,16 @@ public class SchemaInterceptor extends B
}
else if ( filter instanceof ExtensibleNode )
{
- ExtensibleNode node = ( ( ExtensibleNode ) filter );
+ ExtensibleNode node = ( ExtensibleNode ) filter;
// Todo : add the needed checks here
}
else if ( filter instanceof ApproximateNode )
{
- ApproximateNode node = ( ( ApproximateNode ) filter );
- Value<?> value = node.getValue();
+ ApproximateNode node = ( ApproximateNode ) filter;
+ Value value = node.getValue();
- Value<?> newValue = convert( node.getAttributeType(), value );
+ Value newValue = convert( node.getAttributeType(), value );
if ( newValue != null )
{
@@ -505,15 +494,15 @@ public class SchemaInterceptor extends B
private boolean getObjectClasses( Attribute objectClasses, List<ObjectClass> result ) throws LdapException
{
- Set<String> ocSeen = new HashSet<String>();
+ Set<String> ocSeen = new HashSet<>();
// We must select all the ObjectClasses, except 'top',
// but including all the inherited ObjectClasses
boolean hasExtensibleObject = false;
- for ( Value<?> objectClass : objectClasses )
+ for ( Value objectClass : objectClasses )
{
- String objectClassName = objectClass.getString();
+ String objectClassName = objectClass.getValue();
if ( SchemaConstants.TOP_OC.equals( objectClassName ) )
{
@@ -544,18 +533,18 @@ public class SchemaInterceptor extends B
private Set<String> getAllMust( Attribute objectClasses ) throws LdapException
{
- Set<String> must = new HashSet<String>();
+ Set<String> must = new HashSet<>();
// Loop on all objectclasses
- for ( Value<?> value : objectClasses )
+ for ( Value value : objectClasses )
{
- String ocName = value.getString();
+ String ocName = value.getValue();
ObjectClass oc = schemaManager.lookupObjectClassRegistry( ocName );
List<AttributeType> types = oc.getMustAttributeTypes();
// For each objectClass, loop on all MUST attributeTypes, if any
- if ( ( types != null ) && ( types.size() > 0 ) )
+ if ( ( types != null ) && !types.isEmpty() )
{
for ( AttributeType type : types )
{
@@ -570,32 +559,32 @@ public class SchemaInterceptor extends B
private Set<String> getAllAllowed( Attribute objectClasses, Set<String> must ) throws LdapException
{
- Set<String> allowed = new HashSet<String>( must );
+ Set<String> allAllowed = new HashSet<>( must );
// Add the 'ObjectClass' attribute ID
- allowed.add( SchemaConstants.OBJECT_CLASS_AT_OID );
+ allAllowed.add( SchemaConstants.OBJECT_CLASS_AT_OID );
// Loop on all objectclasses
- for ( Value<?> objectClass : objectClasses )
+ for ( Value objectClass : objectClasses )
{
- String ocName = objectClass.getString();
+ String ocName = objectClass.getValue();
ObjectClass oc = schemaManager.lookupObjectClassRegistry( ocName );
List<AttributeType> types = oc.getMayAttributeTypes();
// For each objectClass, loop on all MAY attributeTypes, if any
- if ( ( types != null ) && ( types.size() > 0 ) )
+ if ( ( types != null ) && !types.isEmpty() )
{
for ( AttributeType type : types )
{
String oid = type.getOid();
- allowed.add( oid );
+ allAllowed.add( oid );
}
}
}
- return allowed;
+ return allAllowed;
}
@@ -610,17 +599,17 @@ public class SchemaInterceptor extends B
*/
private void alterObjectClasses( Attribute objectClassAttr ) throws LdapException
{
- Set<String> objectClasses = new HashSet<String>();
- Set<String> objectClassesUP = new HashSet<String>();
+ Set<String> objectClasses = new HashSet<>();
+ Set<String> objectClassesUP = new HashSet<>();
// Init the objectClass list with 'top'
objectClasses.add( SchemaConstants.TOP_OC );
objectClassesUP.add( SchemaConstants.TOP_OC );
// Construct the new list of ObjectClasses
- for ( Value<?> ocValue : objectClassAttr )
+ for ( Value ocValue : objectClassAttr )
{
- String ocName = ocValue.getString();
+ String ocName = ocValue.getValue();
if ( !ocName.equalsIgnoreCase( SchemaConstants.TOP_OC ) )
{
@@ -670,7 +659,7 @@ public class SchemaInterceptor extends B
// Create the new Attribute
Attribute newAttribute = new DefaultAttribute( attribute.getUpId(), attributeType );
- for ( Value<?> value : attribute )
+ for ( Value value : attribute )
{
newAttribute.add( value );
}
@@ -713,7 +702,7 @@ public class SchemaInterceptor extends B
// If not, we have to create the entry
if ( currentAttribute != null )
{
- for ( Value<?> value : attribute )
+ for ( Value value : attribute )
{
// At this point, we know that the attribute's syntax is correct
// We just have to check that the current attribute does not
@@ -770,7 +759,7 @@ public class SchemaInterceptor extends B
currentAttribute = tempEntry.get( attributeType );
// Now remove all the values
- for ( Value<?> value : attribute )
+ for ( Value value : attribute )
{
// We can only remove existing values.
if ( currentAttribute.contains( value ) )
@@ -869,10 +858,10 @@ public class SchemaInterceptor extends B
return;
}
- if ( ( !attributeType.equals( directoryService.getAtProvider().getModifiersName() )
- && ( !attributeType.equals( directoryService.getAtProvider().getModifyTimestamp() ) )
- && ( !attributeType.equals( directoryService.getAtProvider().getEntryCSN() ) )
- && ( !PWD_POLICY_STATE_ATTRIBUTE_TYPES.contains( attributeType ) ) ) )
+ if ( !attributeType.equals( directoryService.getAtProvider().getModifiersName() )
+ && !attributeType.equals( directoryService.getAtProvider().getModifyTimestamp() )
+ && !attributeType.equals( directoryService.getAtProvider().getEntryCSN() )
+ && !PWD_POLICY_STATE_ATTRIBUTE_TYPES.contains( attributeType ) )
{
String msg = I18n.err( I18n.ERR_52, attributeType );
LOG.error( msg );
@@ -889,6 +878,7 @@ public class SchemaInterceptor extends B
/**
* {@inheritDoc}
*/
+ @Override
public boolean accept( SearchOperationContext operationContext, Entry entry ) throws LdapException
{
ServerEntryUtils.filterContents( schemaManager, operationContext, entry );
@@ -900,6 +890,7 @@ public class SchemaInterceptor extends B
/**
* {@inheritDoc}
*/
+ @Override
public String toString( String tabs )
{
return tabs + "TopFilter";
@@ -917,7 +908,6 @@ public class SchemaInterceptor extends B
// ---------------------------------------------------------------
// First, make sure all attributes are valid schema defined attributes
// ---------------------------------------------------------------
-
for ( Attribute attribute : entry.getAttributes() )
{
AttributeType attributeType = attribute.getAttributeType();
@@ -945,13 +935,13 @@ public class SchemaInterceptor extends B
objectClassAttr = new DefaultAttribute( directoryService.getAtProvider().getObjectClass() );
}
- List<ObjectClass> ocs = new ArrayList<ObjectClass>();
+ List<ObjectClass> ocs = new ArrayList<>();
alterObjectClasses( objectClassAttr );
// Now we can process the MUST and MAY attributes
Set<String> must = getAllMust( objectClassAttr );
- Set<String> allowed = getAllAllowed( objectClassAttr, must );
+ Set<String> allAllowed = getAllAllowed( objectClassAttr, must );
boolean hasExtensibleObject = getObjectClasses( objectClassAttr, ocs );
@@ -964,11 +954,11 @@ public class SchemaInterceptor extends B
if ( !hasExtensibleObject )
{
- assertAllAttributesAllowed( dn, entry, allowed );
+ assertAllAttributesAllowed( dn, entry, allAllowed );
}
// Check the attributes values and transform them to String if necessary
- assertHumanReadable( entry );
+ entry = assertHumanReadable( entry );
// Now check the syntaxes
assertSyntaxes( entry );
@@ -994,11 +984,11 @@ public class SchemaInterceptor extends B
// First check that the inheritence scheme is correct.
// 1) If the ocType is ABSTRACT, it should not have any other SUP not ABSTRACT
- for ( Value<?> sup : supOC )
+ for ( Value sup : supOC )
{
try
{
- String supName = sup.getString();
+ String supName = sup.getValue();
ObjectClass superior = schemaManager.lookupObjectClassRegistry( supName );
@@ -1049,6 +1039,7 @@ public class SchemaInterceptor extends B
/**
* {@inheritDoc}
*/
+ @Override
public void add( AddOperationContext addContext ) throws LdapException
{
Dn name = addContext.getDn();
@@ -1114,6 +1105,7 @@ public class SchemaInterceptor extends B
/**
* {@inheritDoc}
*/
+ @Override
public boolean compare( CompareOperationContext compareContext ) throws LdapException
{
if ( IS_DEBUG )
@@ -1128,15 +1120,14 @@ public class SchemaInterceptor extends B
throw new LdapInvalidAttributeTypeException( I18n.err( I18n.ERR_266, compareContext.getOid() ) );
}
- boolean result = next( compareContext );
-
- return result;
+ return next( compareContext );
}
/**
* {@inheritDoc}
*/
+ @Override
public Entry lookup( LookupOperationContext lookupContext ) throws LdapException
{
Entry entry = next( lookupContext );
@@ -1152,6 +1143,7 @@ public class SchemaInterceptor extends B
/**
* {@inheritDoc}
*/
+ @Override
public void modify( ModifyOperationContext modifyContext ) throws LdapException
{
// A modification on a simple entry will be done in three steps :
@@ -1178,7 +1170,7 @@ public class SchemaInterceptor extends B
// We can get rid of the modifiersName and modifyTimestamp, they are useless.
List<Modification> mods = modifyContext.getModItems();
- List<Modification> cleanMods = new ArrayList<Modification>();
+ List<Modification> cleanMods = new ArrayList<>();
for ( Modification mod : mods )
{
@@ -1206,10 +1198,197 @@ public class SchemaInterceptor extends B
next( modifyContext );
}
+
+ private Map<String, List<ModDnAva>> processRdn( Rdn oldRdn, Rdn newRdn, boolean deleteOldRdn )
+ {
+ Map<String, List<ModDnAva>> listAvas = new HashMap<>();
+
+ // Check that the new RDN will not break the entry when added
+ for ( Ava ava : newRdn )
+ {
+ // Three possibilities :
+ // - This is a new AT (not present in the entry) : ModDnType.Add
+ // - The AT is already present in the previous RDN, and in the entry : ModDnType.Modify
+ // - The AT is already present in the entry, but not in the previous RDN : ModDnType.Add
+ boolean found = false;
+
+ for ( Ava oldAva : oldRdn )
+ {
+ if ( oldAva.getAttributeType().equals( ava.getAttributeType() ) )
+ {
+ // Same At, check the value
+ if ( !oldAva.getValue().equals( ava.getValue() ) )
+ {
+ List<ModDnAva> modDnAvas = listAvas.get( ava.getAttributeType().getOid() );
+
+ if ( modDnAvas == null )
+ {
+ modDnAvas = new ArrayList<>();
+ listAvas.put( ava.getAttributeType().getOid(), modDnAvas );
+ }
+
+ modDnAvas.add( new ModDnAva( ModDnAva.ModDnType.UPDATE_ADD, ava ) );
+ found = true;
+ break;
+ }
+ }
+ }
+
+ if ( !found )
+ {
+ List<ModDnAva> modDnAvas = listAvas.get( ava.getAttributeType().getOid() );
+
+ if ( modDnAvas == null )
+ {
+ modDnAvas = new ArrayList<>();
+ listAvas.put( ava.getAttributeType().getOid(), modDnAvas );
+ }
+
+ modDnAvas.add( new ModDnAva( ModDnAva.ModDnType.ADD, ava ) );
+ }
+ }
+
+ // Now process the oldRdn avas,if the deleteOldRdn flag is set to True
+ if ( deleteOldRdn )
+ {
+ for ( Ava oldAva : oldRdn )
+ {
+ boolean found = false;
+
+ for ( Ava newAva : newRdn )
+ {
+ if ( newAva.getAttributeType().equals( oldAva.getAttributeType() ) )
+ {
+ // Same At, check the value
+ if ( !newAva.getValue().equals( oldAva.getValue() ) )
+ {
+ List<ModDnAva> modDnAvas = listAvas.get( oldAva.getAttributeType().getOid() );
+
+ if ( modDnAvas == null )
+ {
+ modDnAvas = new ArrayList<>();
+ listAvas.put( oldAva.getAttributeType().getOid(), modDnAvas );
+ }
+
+ modDnAvas.add( new ModDnAva( ModDnAva.ModDnType.UPDATE_DELETE, oldAva ) );
+ found = true;
+ break;
+ }
+ }
+ }
+
+ if ( !found )
+ {
+ List<ModDnAva> modDnAvas = listAvas.get( oldAva.getAttributeType().getOid() );
+
+ if ( modDnAvas == null )
+ {
+ modDnAvas = new ArrayList<>();
+ listAvas.put( oldAva.getAttributeType().getOid(), modDnAvas );
+ }
+
+ modDnAvas.add( new ModDnAva( ModDnAva.ModDnType.DELETE, oldAva ) );
+ }
+ }
+ }
+
+ return listAvas;
+ }
+
+
+ private void applyRdn( MoveAndRenameOperationContext moveAndRenameContext, Map<String, List<ModDnAva>> modifiedAvas ) throws LdapException
+ {
+ Entry modifiedEntry = moveAndRenameContext.getModifiedEntry();
+ List<ModDnAva> removedSVs = null;
+
+ for ( List<ModDnAva> modDnAvas : modifiedAvas.values() )
+ {
+ for ( ModDnAva modDnAva : modDnAvas )
+ {
+ Ava ava = modDnAva.getAva();
+
+ switch ( modDnAva.getType() )
+ {
+ case ADD :
+ case UPDATE_ADD :
+ // Check that the AT is not SV, otherwise we have to delete the old value
+ if ( ava.getAttributeType().isSingleValued() )
+ {
+ Attribute svAttribute = modifiedEntry.get( ava.getAttributeType() );
+ modifiedEntry.removeAttributes( ava.getAttributeType() );
+
+ if ( removedSVs == null )
+ {
+ removedSVs = new ArrayList<>();
+ }
+
+ modDnAvas.add( new ModDnAva( ModDnAva.ModDnType.UPDATE_DELETE, ava ) );
+ removedSVs.add( new ModDnAva( ModDnAva.ModDnType.UPDATE_DELETE, new Ava( schemaManager, svAttribute.getId(), svAttribute.getString() ) ) );
+ }
+
+ modifiedEntry.add( ava.getAttributeType(), ava.getValue() );
+ break;
+
+ case DELETE :
+ case UPDATE_DELETE :
+ modifiedEntry.remove( ava.getAttributeType(), ava.getValue() );
+ break;
+
+ default :
+ break;
+ }
+ }
+ }
+
+ // Add the SV attributes that has to be removed to the list of ModDnAva
+ if ( removedSVs != null )
+ {
+ for ( ModDnAva modDnAva : removedSVs )
+ {
+ String oid = modDnAva.getAva().getAttributeType().getOid();
+ List<ModDnAva> modDnAvas = modifiedAvas.get( oid );
+
+ modDnAvas.add( modDnAva );
+ }
+ }
+
+ moveAndRenameContext.setModifiedAvas( modifiedAvas );
+ moveAndRenameContext.setModifiedEntry( modifiedEntry );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException
+ {
+ // We will compute the modified entry, and check that its still valid :
+ // - the new RDn's AVAs must be compatible with the existing ObjectClasses (except if the Extensible ObjectClass is present)
+ // - The removal of the old RDN (if requested) must not left the entry invalid
+ // - if the new RDN has SV AT, then we should remove the old RDN's AVA if it's using the same AT
+ Entry entry = moveAndRenameContext.getOriginalEntry();
+ Dn entryDn = entry.getDn();
+ Rdn oldRdn = entryDn.getRdn();
+ Rdn newRdn = moveAndRenameContext.getNewRdn();
+
+ // First get the list of impacted AVAs
+ Map<String, List<ModDnAva>> modifiedAvas = processRdn( oldRdn, newRdn, moveAndRenameContext.getDeleteOldRdn() );
+
+ // Check if they will left the entry in a correct state
+ applyRdn( moveAndRenameContext, modifiedAvas );
+
+ // Check the modified entry now
+ check( moveAndRenameContext.getNewDn(), moveAndRenameContext.getModifiedEntry() );
+
+ next( moveAndRenameContext );
+ }
+
/**
* {@inheritDoc}
*/
+ @Override
public void rename( RenameOperationContext renameContext ) throws LdapException
{
Dn oldDn = renameContext.getDn();
@@ -1267,6 +1446,7 @@ public class SchemaInterceptor extends B
/**
* {@inheritDoc}
*/
+ @Override
public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException
{
Dn base = searchContext.getDn();
@@ -1275,10 +1455,8 @@ public class SchemaInterceptor extends B
// We also have to check the H/R flag for the filter attributes
checkFilter( filter );
- String baseNormForm = ( base.isSchemaAware() ? base.getNormName() : base.getNormName() );
-
// Deal with the normal case : searching for a normal value (not subSchemaSubEntry)
- if ( !subschemaSubentryDnNorm.equals( baseNormForm ) )
+ if ( !subschemaSubentryDn.equals( base ) )
{
EntryFilteringCursor cursor = next( searchContext );
@@ -1309,9 +1487,9 @@ public class SchemaInterceptor extends B
SimpleNode node = ( SimpleNode ) filter;
String objectClass;
- objectClass = node.getValue().getString();
+ objectClass = node.getValue().getValue();
- String objectClassOid = null;
+ String objectClassOid;
if ( schemaManager.getObjectClassRegistry().contains( objectClass ) )
{
@@ -1329,7 +1507,6 @@ public class SchemaInterceptor extends B
&& ( objectClassOid.equals( SchemaConstants.TOP_OC_OID ) || objectClassOid
.equals( SchemaConstants.SUBSCHEMA_OC_OID ) ) && ( node instanceof EqualityNode ) )
{
- // call.setBypass( true );
Entry serverEntry = SchemaService.getSubschemaEntry( directoryService,
searchContext );
serverEntry.setDn( base );
@@ -1347,9 +1524,8 @@ public class SchemaInterceptor extends B
Entry serverEntry = SchemaService.getSubschemaEntry( directoryService,
searchContext );
serverEntry.setDn( base );
- EntryFilteringCursor cursor = new EntryFilteringCursorImpl(
+ return new EntryFilteringCursorImpl(
new SingletonCursor<Entry>( serverEntry ), searchContext, schemaManager );
- return cursor;
}
}
@@ -1369,7 +1545,7 @@ public class SchemaInterceptor extends B
Rdn rdn = dn.getRdn( size - 2 );
- return rdn.getNormValue();
+ return rdn.getValue();
}
@@ -1382,15 +1558,7 @@ public class SchemaInterceptor extends B
*/
private void assertAllAttributesAllowed( Dn dn, Entry entry, Set<String> allowed ) throws LdapException
{
- // Never check the attributes if the extensibleObject objectClass is
- // declared for this entry
- Attribute objectClass = entry.get( directoryService.getAtProvider().getObjectClass() );
-
- if ( objectClass.contains( SchemaConstants.EXTENSIBLE_OBJECT_OC ) )
- {
- return;
- }
-
+ // Loop on all the attributes
for ( Attribute attribute : entry )
{
String attrOid = attribute.getAttributeType().getOid();
@@ -1442,7 +1610,7 @@ public class SchemaInterceptor extends B
must.remove( attribute.getAttributeType().getOid() );
}
- if ( must.size() != 0 )
+ if ( !must.isEmpty() )
{
// include AT names for better error reporting
StringBuilder sb = new StringBuilder();
@@ -1475,7 +1643,7 @@ public class SchemaInterceptor extends B
*/
private void assertObjectClasses( Dn dn, List<ObjectClass> ocs ) throws LdapException
{
- Set<ObjectClass> structuralObjectClasses = new HashSet<ObjectClass>();
+ Set<ObjectClass> structuralObjectClasses = new HashSet<>();
/*
* Since the number of ocs present in an entry is small it's not
@@ -1514,7 +1682,7 @@ public class SchemaInterceptor extends B
/// objectClasses. If there is more than one then we have a problem.
// --------------------------------------------------------------------
- Set<ObjectClass> remaining = new HashSet<ObjectClass>( structuralObjectClasses.size() );
+ Set<ObjectClass> remaining = new HashSet<>( structuralObjectClasses.size() );
remaining.addAll( structuralObjectClasses );
for ( ObjectClass oc : structuralObjectClasses )
@@ -1560,7 +1728,7 @@ public class SchemaInterceptor extends B
}
// Then loop on all values
- for ( Value<?> value : attribute )
+ for ( Value value : attribute )
{
if ( value.isSchemaAware() )
{
@@ -1570,7 +1738,7 @@ public class SchemaInterceptor extends B
if ( !syntaxChecker.isValidSyntax( value.getValue() ) )
{
- String message = I18n.err( I18n.ERR_280, value.getString(), attribute.getUpId() );
+ String message = I18n.err( I18n.ERR_280, value.getValue(), attribute.getUpId() );
LOG.info( message );
throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
}
@@ -1605,13 +1773,13 @@ public class SchemaInterceptor extends B
boolean isModified = false;
// Loop on each values
- for ( Value<?> value : attribute )
+ for ( Value value : attribute )
{
- if ( value instanceof StringValue )
+ if ( value.isHumanReadable() )
{
continue;
}
- else if ( value instanceof BinaryValue )
+ else
{
// we have a byte[] value. It should be a String UTF-8 encoded
// Let's transform it
@@ -1627,10 +1795,6 @@ public class SchemaInterceptor extends B
throw new LdapException( I18n.err( I18n.ERR_281 ) );
}
}
- else
- {
- throw new LdapException( I18n.err( I18n.ERR_282 ) );
- }
}
return isModified;
@@ -1647,36 +1811,21 @@ public class SchemaInterceptor extends B
boolean isModified = false;
// Loop on each values
- for ( Value<?> value : attribute )
+ for ( Value value : attribute )
{
- if ( value instanceof BinaryValue )
+ if ( !value.isHumanReadable() )
{
continue;
}
- else if ( value instanceof StringValue )
+ else
{
// We have a String value. It should be a byte[]
// Let's transform it
- try
- {
- byte[] valBytes = value.getString().getBytes( "UTF-8" );
+ byte[] valBytes = value.getBytes();
- attribute.remove( value );
- attribute.add( valBytes );
- isModified = true;
- }
- catch ( UnsupportedEncodingException uee )
- {
- String message = I18n.err( I18n.ERR_63 );
- LOG.error( message );
- throw new LdapException( message );
- }
- }
- else
- {
- String message = I18n.err( I18n.ERR_64 );
- LOG.error( message );
- throw new LdapException( message );
+ attribute.remove( value );
+ attribute.add( valBytes );
+ isModified = true;
}
}
@@ -1689,15 +1838,15 @@ public class SchemaInterceptor extends B
* to valid String if they are stored as byte[], and that non Human Readable attributes
* stored as String can be transformed to byte[]
*/
- private void assertHumanReadable( Entry entry ) throws LdapException
+ private Entry assertHumanReadable( Entry entry ) throws LdapException
{
- boolean isModified = false;
-
Entry clonedEntry = null;
// Loops on all attributes
for ( Attribute attribute : entry )
{
+ boolean isModified;
+
AttributeType attributeType = attribute.getAttributeType();
// If the attributeType is H-R, check all of its values
@@ -1721,14 +1870,16 @@ public class SchemaInterceptor extends B
// Switch the attributes
clonedEntry.put( attribute );
-
- isModified = false;
}
}
if ( clonedEntry != null )
{
- entry = clonedEntry;
+ return clonedEntry;
+ }
+ else
+ {
+ return entry;
}
}
}
Modified: directory/apacheds/branches/apacheds-value/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaLdifToPartitionExtractor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-value/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaLdifToPartitionExtractor.java?rev=1748572&r1=1748571&r2=1748572&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-value/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaLdifToPartitionExtractor.java (original)
+++ directory/apacheds/branches/apacheds-value/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaLdifToPartitionExtractor.java Wed Jun 15 12:29:57 2016
@@ -38,7 +38,6 @@ import org.apache.directory.api.ldap.mod
import org.apache.directory.api.ldap.model.entry.DefaultEntry;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.exception.LdapException;
-import org.apache.directory.api.ldap.model.ldif.LdapLdifException;
import org.apache.directory.api.ldap.model.ldif.LdifEntry;
import org.apache.directory.api.ldap.model.ldif.LdifReader;
import org.apache.directory.api.ldap.model.name.Dn;
@@ -60,10 +59,6 @@ import org.slf4j.LoggerFactory;
*/
public class SchemaLdifToPartitionExtractor implements SchemaLdifExtractor
{
-
- /** The base path. */
- private static final String BASE_PATH = "";
-
/** The logger. */
private static final Logger LOG = LoggerFactory.getLogger( SchemaLdifToPartitionExtractor.class );
@@ -114,6 +109,7 @@ public class SchemaLdifToPartitionExtrac
*
* @return true if schema has already been added to the schema partition
*/
+ @Override
public boolean isExtracted()
{
return extracted;
@@ -123,12 +119,13 @@ public class SchemaLdifToPartitionExtrac
/**
* {@inheritDoc}
*/
+ @Override
public void extractOrCopy( boolean overwrite ) throws IOException
{
Map<String, Boolean> resources = ResourceMap.getResources( EXTRACT_PATTERN );
// must sort the map to ensure parent entries are added before children
- resources = new TreeMap<String, Boolean>( resources );
+ resources = new TreeMap<>( resources );
if ( !extracted || overwrite )
{
@@ -153,6 +150,7 @@ public class SchemaLdifToPartitionExtrac
/**
* {@inheritDoc}
*/
+ @Override
public void extractOrCopy() throws IOException
{
extractOrCopy( false );
@@ -245,16 +243,13 @@ public class SchemaLdifToPartitionExtrac
ldifReader.close();
}
- // inject the entry
- Entry entry = new DefaultEntry( schemaManager, ldifEntry.getEntry() );
- AddOperationContext addContext = new AddOperationContext( null, entry );
- partition.add( addContext );
- }
- catch ( LdapLdifException ne )
- {
- String msg = I18n.err( I18n.ERR_08004, source, ne.getLocalizedMessage() );
- LOG.error( msg );
- throw new InvalidObjectException( msg );
+ // inject the entry if any
+ if ( ldifEntry != null )
+ {
+ Entry entry = new DefaultEntry( schemaManager, ldifEntry.getEntry() );
+ AddOperationContext addContext = new AddOperationContext( null, entry );
+ partition.add( addContext );
+ }
}
catch ( LdapException ne )
{
Modified: directory/apacheds/branches/apacheds-value/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-value/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryManager.java?rev=1748572&r1=1748571&r2=1748572&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-value/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryManager.java (original)
+++ directory/apacheds/branches/apacheds-value/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryManager.java Wed Jun 15 12:29:57 2016
@@ -79,7 +79,7 @@ public class SchemaSubentryManager
private static final int DIT_CONTENT_RULE_INDEX = 9;
private static final int NAME_FORM_INDEX = 10;
- private static final Set<String> VALID_OU_VALUES = new HashSet<String>();
+ private static final Set<String> VALID_OU_VALUES = new HashSet<>();
/** The schemaManager */
private final SchemaManager schemaManager;
@@ -93,7 +93,7 @@ public class SchemaSubentryManager
* Maps the OID of a subschemaSubentry operational attribute to the index of
* the handler in the schemaObjectHandlers array.
*/
- private final Map<String, Integer> opAttr2handlerIndex = new HashMap<String, Integer>( 11 );
+ private final Map<String, Integer> opAttr2handlerIndex = new HashMap<>( 11 );
private static final String CASCADING_ERROR =
"Cascading has not yet been implemented: standard operation is in effect.";
@@ -102,7 +102,7 @@ public class SchemaSubentryManager
VALID_OU_VALUES.add( Strings.toLowerCaseAscii( SchemaConstants.NORMALIZERS_AT ) );
VALID_OU_VALUES.add( Strings.toLowerCaseAscii( SchemaConstants.COMPARATORS_AT ) );
VALID_OU_VALUES.add( Strings.toLowerCaseAscii( SchemaConstants.SYNTAX_CHECKERS_AT ) );
- VALID_OU_VALUES.add( Strings.toLowerCaseAscii( "syntaxes" ) );
+ VALID_OU_VALUES.add( Strings.toLowerCaseAscii( SchemaConstants.SYNTAXES ) );
VALID_OU_VALUES.add( Strings.toLowerCaseAscii( SchemaConstants.MATCHING_RULES_AT ) );
VALID_OU_VALUES.add( Strings.toLowerCaseAscii( SchemaConstants.MATCHING_RULE_USE_AT ) );
VALID_OU_VALUES.add( Strings.toLowerCaseAscii( SchemaConstants.ATTRIBUTE_TYPES_AT ) );
@@ -303,7 +303,7 @@ public class SchemaSubentryManager
switch ( index )
{
- case ( COMPARATOR_INDEX ):
+ case COMPARATOR_INDEX :
LdapComparatorDescription[] comparatorDescriptions = parsers.parseComparators( mods );
for ( LdapComparatorDescription comparatorDescription : comparatorDescriptions )
@@ -313,7 +313,7 @@ public class SchemaSubentryManager
break;
- case ( NORMALIZER_INDEX ):
+ case NORMALIZER_INDEX :
NormalizerDescription[] normalizerDescriptions = parsers.parseNormalizers( mods );
for ( NormalizerDescription normalizerDescription : normalizerDescriptions )
@@ -323,7 +323,7 @@ public class SchemaSubentryManager
break;
- case ( SYNTAX_CHECKER_INDEX ):
+ case SYNTAX_CHECKER_INDEX :
SyntaxCheckerDescription[] syntaxCheckerDescriptions = parsers.parseSyntaxCheckers( mods );
for ( SyntaxCheckerDescription syntaxCheckerDescription : syntaxCheckerDescriptions )
@@ -333,7 +333,7 @@ public class SchemaSubentryManager
break;
- case ( SYNTAX_INDEX ):
+ case SYNTAX_INDEX :
LdapSyntax[] syntaxes = parsers.parseLdapSyntaxes( mods );
for ( LdapSyntax syntax : syntaxes )
@@ -343,7 +343,7 @@ public class SchemaSubentryManager
break;
- case ( MATCHING_RULE_INDEX ):
+ case MATCHING_RULE_INDEX :
MatchingRule[] mrs = parsers.parseMatchingRules( mods );
for ( MatchingRule mr : mrs )
@@ -353,7 +353,7 @@ public class SchemaSubentryManager
break;
- case ( ATTRIBUTE_TYPE_INDEX ):
+ case ATTRIBUTE_TYPE_INDEX :
AttributeType[] ats = parsers.parseAttributeTypes( mods );
for ( AttributeType at : ats )
@@ -363,7 +363,7 @@ public class SchemaSubentryManager
break;
- case ( OBJECT_CLASS_INDEX ):
+ case OBJECT_CLASS_INDEX :
ObjectClass[] ocs = parsers.parseObjectClasses( mods );
for ( ObjectClass oc : ocs )
@@ -373,7 +373,7 @@ public class SchemaSubentryManager
break;
- case ( MATCHING_RULE_USE_INDEX ):
+ case MATCHING_RULE_USE_INDEX :
MatchingRuleUse[] mrus = parsers.parseMatchingRuleUses( mods );
for ( MatchingRuleUse mru : mrus )
@@ -383,7 +383,7 @@ public class SchemaSubentryManager
break;
- case ( DIT_STRUCTURE_RULE_INDEX ):
+ case DIT_STRUCTURE_RULE_INDEX :
DitStructureRule[] dsrs = parsers.parseDitStructureRules( mods );
for ( DitStructureRule dsr : dsrs )
@@ -393,7 +393,7 @@ public class SchemaSubentryManager
break;
- case ( DIT_CONTENT_RULE_INDEX ):
+ case DIT_CONTENT_RULE_INDEX :
DitContentRule[] dcrs = parsers.parseDitContentRules( mods );
for ( DitContentRule dcr : dcrs )
@@ -403,7 +403,7 @@ public class SchemaSubentryManager
break;
- case ( NAME_FORM_INDEX ):
+ case NAME_FORM_INDEX :
NameForm[] nfs = parsers.parseNameForms( mods );
for ( NameForm nf : nfs )
@@ -442,7 +442,7 @@ public class SchemaSubentryManager
switch ( index )
{
- case ( COMPARATOR_INDEX ):
+ case COMPARATOR_INDEX :
LdapComparatorDescription[] comparatorDescriptions = parsers.parseComparators( mods );
for ( LdapComparatorDescription comparatorDescription : comparatorDescriptions )
@@ -452,7 +452,7 @@ public class SchemaSubentryManager
break;
- case ( NORMALIZER_INDEX ):
+ case NORMALIZER_INDEX :
NormalizerDescription[] normalizerDescriptions = parsers.parseNormalizers( mods );
for ( NormalizerDescription normalizerDescription : normalizerDescriptions )
@@ -462,7 +462,7 @@ public class SchemaSubentryManager
break;
- case ( SYNTAX_CHECKER_INDEX ):
+ case SYNTAX_CHECKER_INDEX :
SyntaxCheckerDescription[] syntaxCheckerDescriptions = parsers.parseSyntaxCheckers( mods );
for ( SyntaxCheckerDescription syntaxCheckerDescription : syntaxCheckerDescriptions )
@@ -472,7 +472,7 @@ public class SchemaSubentryManager
break;
- case ( SYNTAX_INDEX ):
+ case SYNTAX_INDEX :
LdapSyntax[] syntaxes = parsers.parseLdapSyntaxes( mods );
for ( LdapSyntax syntax : syntaxes )
@@ -482,7 +482,7 @@ public class SchemaSubentryManager
break;
- case ( MATCHING_RULE_INDEX ):
+ case MATCHING_RULE_INDEX :
MatchingRule[] mrs = parsers.parseMatchingRules( mods );
for ( MatchingRule mr : mrs )
@@ -492,7 +492,7 @@ public class SchemaSubentryManager
break;
- case ( ATTRIBUTE_TYPE_INDEX ):
+ case ATTRIBUTE_TYPE_INDEX :
AttributeType[] ats = parsers.parseAttributeTypes( mods );
for ( AttributeType at : ats )
@@ -502,7 +502,7 @@ public class SchemaSubentryManager
break;
- case ( OBJECT_CLASS_INDEX ):
+ case OBJECT_CLASS_INDEX :
ObjectClass[] ocs = parsers.parseObjectClasses( mods );
for ( ObjectClass oc : ocs )
@@ -512,7 +512,7 @@ public class SchemaSubentryManager
break;
- case ( MATCHING_RULE_USE_INDEX ):
+ case MATCHING_RULE_USE_INDEX :
MatchingRuleUse[] mrus = parsers.parseMatchingRuleUses( mods );
for ( MatchingRuleUse mru : mrus )
@@ -522,7 +522,7 @@ public class SchemaSubentryManager
break;
- case ( DIT_STRUCTURE_RULE_INDEX ):
+ case DIT_STRUCTURE_RULE_INDEX :
DitStructureRule[] dsrs = parsers.parseDitStructureRules( mods );
for ( DitStructureRule dsr : dsrs )
@@ -532,7 +532,7 @@ public class SchemaSubentryManager
break;
- case ( DIT_CONTENT_RULE_INDEX ):
+ case DIT_CONTENT_RULE_INDEX :
DitContentRule[] dcrs = parsers.parseDitContentRules( mods );
for ( DitContentRule dcr : dcrs )
@@ -542,7 +542,7 @@ public class SchemaSubentryManager
break;
- case ( NAME_FORM_INDEX ):
+ case NAME_FORM_INDEX :
NameForm[] nfs = parsers.parseNameForms( mods );
for ( NameForm nf : nfs )
Modified: directory/apacheds/branches/apacheds-value/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-value/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java?rev=1748572&r1=1748571&r2=1748572&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-value/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java (original)
+++ directory/apacheds/branches/apacheds-value/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java Wed Jun 15 12:29:57 2016
@@ -83,12 +83,12 @@ public class SchemaSubentryModifier
private Dn getDn( SchemaObject obj ) throws LdapInvalidDnException
{
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
buf.append( "m-oid=" ).append( obj.getOid() ).append( ",ou=" );
if ( obj instanceof LdapSyntax )
{
- buf.append( "syntaxes" );
+ buf.append( SchemaConstants.SYNTAXES );
}
else if ( obj instanceof MatchingRule )
{
Modified: directory/apacheds/branches/apacheds-value/interceptors/subtree/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-value/interceptors/subtree/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java?rev=1748572&r1=1748571&r2=1748572&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-value/interceptors/subtree/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java (original)
+++ directory/apacheds/branches/apacheds-value/interceptors/subtree/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java Wed Jun 15 12:29:57 2016
@@ -36,7 +36,6 @@ import org.apache.directory.api.ldap.mod
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.entry.Modification;
import org.apache.directory.api.ldap.model.entry.ModificationOperation;
-import org.apache.directory.api.ldap.model.entry.StringValue;
import org.apache.directory.api.ldap.model.entry.Value;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException;
@@ -98,7 +97,7 @@ public class SubentryInterceptor extends
/** the subentry control OID */
private static final String SUBENTRY_CONTROL = Subentries.OID;
- private Value<String> subentryOC;
+ private Value subentryOC;
/** The SubTree specification parser instance */
private SubtreeSpecificationParser ssParser;
@@ -134,6 +133,7 @@ public class SubentryInterceptor extends
/**
* {@inheritDoc}
*/
+ @Override
public boolean accept( SearchOperationContext searchContext, Entry entry ) throws LdapException
{
// See if the requested entry is a subentry
@@ -150,6 +150,7 @@ public class SubentryInterceptor extends
/**
* {@inheritDoc}
*/
+ @Override
public String toString( String tabs )
{
return tabs + "HideSubentriesFilter";
@@ -165,6 +166,7 @@ public class SubentryInterceptor extends
/**
* {@inheritDoc}
*/
+ @Override
public boolean accept( SearchOperationContext searchContext, Entry entry ) throws LdapException
{
// See if the requested entry is a subentry
@@ -181,6 +183,7 @@ public class SubentryInterceptor extends
/**
* {@inheritDoc}
*/
+ @Override
public String toString( String tabs )
{
return tabs + "HideEntriesFilter";
@@ -196,6 +199,7 @@ public class SubentryInterceptor extends
*
* @param directoryService The DirectoryService instance
*/
+ @Override
public void init( DirectoryService directoryService ) throws LdapException
{
super.init( directoryService );
@@ -203,25 +207,25 @@ public class SubentryInterceptor extends
nexus = directoryService.getPartitionNexus();
ssParser = new SubtreeSpecificationParser( schemaManager );
+ AttributeType ocAt = directoryService.getAtProvider().getObjectClass();
// prepare to find all subentries in all namingContexts
Set<String> suffixes = nexus.listSuffixes();
- ExprNode filter = new EqualityNode<String>( directoryService.getAtProvider().getObjectClass(), new StringValue(
- SchemaConstants.SUBENTRY_OC ) );
+ ExprNode filter = new EqualityNode<String>( ocAt, new Value( ocAt, SchemaConstants.SUBENTRY_OC ) );
SearchControls controls = new SearchControls();
controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
controls.setReturningAttributes( new String[]
{ SchemaConstants.SUBTREE_SPECIFICATION_AT, SchemaConstants.OBJECT_CLASS_AT } );
- subentryOC = new StringValue( directoryService.getAtProvider().getObjectClass(), SchemaConstants.SUBENTRY_OC );
+ subentryOC = new Value( ocAt, SchemaConstants.SUBENTRY_OC );
// search each namingContext for subentries
for ( String suffix : suffixes )
{
- Dn suffixDn = dnFactory.create( suffix );
-
CoreSession adminSession = directoryService.getAdminSession();
+ Dn suffixDn = dnFactory.create( suffix );
+
SearchOperationContext searchOperationContext = new SearchOperationContext( adminSession, suffixDn, filter,
controls );
searchOperationContext.setAliasDerefMode( AliasDerefMode.NEVER_DEREF_ALIASES );
@@ -286,7 +290,7 @@ public class SubentryInterceptor extends
*/
private Set<AdministrativeRole> getSubentryAdminRoles( Entry subentry ) throws LdapException
{
- Set<AdministrativeRole> adminRoles = new HashSet<AdministrativeRole>();
+ Set<AdministrativeRole> adminRoles = new HashSet<>();
Attribute oc = subentry.get( directoryService.getAtProvider().getObjectClass() );
@@ -527,7 +531,7 @@ public class SubentryInterceptor extends
private List<Modification> getModsOnEntryRdnChange( Dn oldName, Dn newName, Entry entry ) throws LdapException
{
- List<Modification> modifications = new ArrayList<Modification>();
+ List<Modification> modifications = new ArrayList<>();
/*
* There are two different situations warranting action. First if
@@ -569,7 +573,7 @@ public class SubentryInterceptor extends
if ( opAttr != null )
{
opAttr = opAttr.clone();
- opAttr.remove( subentryDn.getNormName() );
+ opAttr.remove( subentryDn.getName() );
if ( opAttr.size() < 1 )
{
@@ -588,7 +592,7 @@ public class SubentryInterceptor extends
{
ModificationOperation op = ModificationOperation.ADD_ATTRIBUTE;
Attribute opAttr = new DefaultAttribute( operationalAttribute );
- opAttr.add( subentryDn.getNormName() );
+ opAttr.add( subentryDn.getName() );
modifications.add( new DefaultModification( op, opAttr ) );
}
}
@@ -614,17 +618,17 @@ public class SubentryInterceptor extends
switch ( mod.getOperation() )
{
case ADD_ATTRIBUTE:
- for ( Value<?> value : mod.getAttribute() )
+ for ( Value value : mod.getAttribute() )
{
- ocFinalState.add( value.getString() );
+ ocFinalState.add( value.getValue() );
}
break;
case REMOVE_ATTRIBUTE:
- for ( Value<?> value : mod.getAttribute() )
+ for ( Value value : mod.getAttribute() )
{
- ocFinalState.remove( value.getString() );
+ ocFinalState.remove( value.getValue() );
}
break;
@@ -652,8 +656,8 @@ public class SubentryInterceptor extends
private void getOperationalModForReplace( boolean hasRole, AttributeType attributeType, Entry entry, Dn oldDn,
Dn newDn, List<Modification> modifications ) throws LdapInvalidAttributeValueException
{
- String oldDnStr = oldDn.getNormName();
- String newDnStr = newDn.getNormName();
+ String oldDnStr = oldDn.getName();
+ String newDnStr = newDn.getName();
if ( hasRole )
{
@@ -681,7 +685,7 @@ public class SubentryInterceptor extends
private List<Modification> getOperationalModsForReplace( Dn oldDn, Dn newDn, Subentry subentry, Entry entry )
throws Exception
{
- List<Modification> modifications = new ArrayList<Modification>();
+ List<Modification> modifications = new ArrayList<>();
getOperationalModForReplace( subentry.isAccessControlAdminRole(), directoryService.getAtProvider()
.getAccessControlSubentries(), entry, oldDn, newDn, modifications );
@@ -702,33 +706,33 @@ public class SubentryInterceptor extends
*/
private List<Attribute> getSubentryOperationalAttributes( Dn dn, Subentry subentry ) throws LdapException
{
- List<Attribute> attributes = new ArrayList<Attribute>();
+ List<Attribute> attributes = new ArrayList<>();
if ( subentry.isAccessControlAdminRole() )
{
Attribute accessControlSubentries = new DefaultAttribute( directoryService.getAtProvider()
- .getAccessControlSubentries(), dn.getNormName() );
+ .getAccessControlSubentries(), dn.getName() );
attributes.add( accessControlSubentries );
}
if ( subentry.isSchemaAdminRole() )
{
Attribute subschemaSubentry = new DefaultAttribute(
- directoryService.getAtProvider().getSubschemaSubentry(), dn.getNormName() );
+ directoryService.getAtProvider().getSubschemaSubentry(), dn.getName() );
attributes.add( subschemaSubentry );
}
if ( subentry.isCollectiveAdminRole() )
{
Attribute collectiveAttributeSubentries = new DefaultAttribute( directoryService.getAtProvider()
- .getCollectiveAttributeSubentries(), dn.getNormName() );
+ .getCollectiveAttributeSubentries(), dn.getName() );
attributes.add( collectiveAttributeSubentries );
}
if ( subentry.isTriggersAdminRole() )
{
Attribute tiggerExecutionSubentries = new DefaultAttribute( directoryService.getAtProvider()
- .getTriggerExecutionSubentries(), dn.getNormName() );
+ .getTriggerExecutionSubentries(), dn.getName() );
attributes.add( tiggerExecutionSubentries );
}
@@ -751,8 +755,8 @@ public class SubentryInterceptor extends
*/
private List<Modification> getOperationalModsForRemove( Dn subentryDn, Entry candidate ) throws LdapException
{
- List<Modification> modifications = new ArrayList<Modification>();
- String dn = subentryDn.getNormName();
+ List<Modification> modifications = new ArrayList<>();
+ String dn = subentryDn.getName();
for ( AttributeType operationalAttribute : directoryService.getAtProvider().getSubentryOperationalAttributes() )
{
@@ -781,7 +785,7 @@ public class SubentryInterceptor extends
private List<Modification> getOperationalModsForAdd( Entry entry, List<Attribute> operationalAttributes )
throws LdapException
{
- List<Modification> modifications = new ArrayList<Modification>();
+ List<Modification> modifications = new ArrayList<>();
for ( Attribute operationalAttribute : operationalAttributes )
{
@@ -791,7 +795,7 @@ public class SubentryInterceptor extends
{
Attribute newOperationalAttribute = operationalAttribute.clone();
- for ( Value<?> value : opAttrInEntry )
+ for ( Value value : opAttrInEntry )
{
newOperationalAttribute.add( value );
}
@@ -816,7 +820,7 @@ public class SubentryInterceptor extends
private List<Modification> getModsOnEntryModification( Dn name, Entry oldEntry, Entry newEntry )
throws LdapException
{
- List<Modification> modList = new ArrayList<Modification>();
+ List<Modification> modList = new ArrayList<>();
for ( Dn subentryDn : directoryService.getSubentryCache() )
{
@@ -843,7 +847,7 @@ public class SubentryInterceptor extends
if ( opAttr != null )
{
opAttr = opAttr.clone();
- opAttr.remove( subentryDn.getNormName() );
+ opAttr.remove( subentryDn.getName() );
if ( opAttr.size() < 1 )
{
@@ -862,7 +866,7 @@ public class SubentryInterceptor extends
{
ModificationOperation op = ModificationOperation.ADD_ATTRIBUTE;
Attribute opAttr = new DefaultAttribute( operationalAttribute );
- opAttr.add( subentryDn.getNormName() );
+ opAttr.add( subentryDn.getName() );
modList.add( new DefaultModification( op, opAttr ) );
}
}
@@ -885,7 +889,7 @@ public class SubentryInterceptor extends
entry.put( operational );
}
- operational.add( subentryDn.getNormName() );
+ operational.add( subentryDn.getName() );
}
@@ -895,6 +899,7 @@ public class SubentryInterceptor extends
/**
* {@inheritDoc}
*/
+ @Override
public void add( AddOperationContext addContext ) throws LdapException
{
Dn dn = addContext.getDn();
@@ -1023,6 +1028,7 @@ public class SubentryInterceptor extends
/**
* {@inheritDoc}
*/
+ @Override
public void delete( DeleteOperationContext deleteContext ) throws LdapException
{
Dn dn = deleteContext.getDn();
@@ -1067,6 +1073,7 @@ public class SubentryInterceptor extends
/**
* {@inheritDoc}
*/
+ @Override
public void modify( ModifyOperationContext modifyContext ) throws LdapException
{
Dn dn = modifyContext.getDn();
@@ -1225,7 +1232,7 @@ public class SubentryInterceptor extends
List<Modification> subentriesOpAttrMods = getModsOnEntryModification( dn, entry, newEntry );
- if ( subentriesOpAttrMods.size() > 0 )
+ if ( !subentriesOpAttrMods.isEmpty() )
{
nexus.modify( new ModifyOperationContext( modifyContext.getSession(), dn, subentriesOpAttrMods ) );
}
@@ -1262,6 +1269,7 @@ public class SubentryInterceptor extends
* @param moveContext The context containing all the needed informations to proceed
* @throws LdapException If the move failed
*/
+ @Override
public void move( MoveOperationContext moveContext ) throws LdapException
{
Dn oldDn = moveContext.getDn();
@@ -1287,7 +1295,11 @@ public class SubentryInterceptor extends
baseDn = baseDn.add( ss.getBase() );
Dn newName = newSuperiorDn;
newName = newName.add( oldDn.getRdn() );
- newName.apply( schemaManager );
+
+ if ( !newName.isSchemaAware() )
+ {
+ newName = new Dn( schemaManager, newName );
+ }
directoryService.getSubentryCache().addSubentry( newName, subentry );
@@ -1315,7 +1327,11 @@ public class SubentryInterceptor extends
{
Entry candidate = subentries.get();
Dn dn = candidate.getDn();
- dn.apply( schemaManager );
+
+ if ( !dn.isSchemaAware() )
+ {
+ dn = new Dn( schemaManager, dn );
+ }
if ( directoryService.getEvaluator().evaluate( ss, apName, dn, candidate ) )
{
@@ -1365,7 +1381,7 @@ public class SubentryInterceptor extends
List<Modification> mods = getModsOnEntryRdnChange( oldDn, newDn, entry );
// Update the entry operational attributes
- if ( mods.size() > 0 )
+ if ( !mods.isEmpty() )
{
nexus.modify( new ModifyOperationContext( moveContext.getSession(), newDn, mods ) );
}
@@ -1376,6 +1392,7 @@ public class SubentryInterceptor extends
/**
* {@inheritDoc}
*/
+ @Override
public void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException
{
Dn oldDn = moveAndRenameContext.getDn();
@@ -1393,7 +1410,11 @@ public class SubentryInterceptor extends
Dn newName = newSuperiorDn.getParent();
newName = newName.add( moveAndRenameContext.getNewRdn() );
- newName.apply( schemaManager );
+
+ if ( !newName.isSchemaAware() )
+ {
+ newName = new Dn( schemaManager, newName );
+ }
directoryService.getSubentryCache().addSubentry( newName, subentry );
@@ -1420,7 +1441,11 @@ public class SubentryInterceptor extends
{
Entry candidate = subentries.get();
Dn dn = candidate.getDn();
- dn.apply( schemaManager );
+
+ if ( !dn.isSchemaAware() )
+ {
+ dn = new Dn( schemaManager, dn );
+ }
if ( directoryService.getEvaluator().evaluate( ss, apName, dn, candidate ) )
{
@@ -1462,7 +1487,7 @@ public class SubentryInterceptor extends
Dn newDn = moveAndRenameContext.getNewDn();
List<Modification> mods = getModsOnEntryRdnChange( oldDn, newDn, entry );
- if ( mods.size() > 0 )
+ if ( !mods.isEmpty() )
{
nexus.modify( new ModifyOperationContext( moveAndRenameContext.getSession(), newDn, mods ) );
}
@@ -1473,6 +1498,7 @@ public class SubentryInterceptor extends
/**
* {@inheritDoc}
*/
+ @Override
public void rename( RenameOperationContext renameContext ) throws LdapException
{
Dn oldDn = renameContext.getDn();
@@ -1490,7 +1516,11 @@ public class SubentryInterceptor extends
Dn newName = oldDn.getParent();
newName = newName.add( renameContext.getNewRdn() );
- newName.apply( schemaManager );
+
+ if ( !newName.isSchemaAware() )
+ {
+ newName = new Dn( schemaManager, newName );
+ }
directoryService.getSubentryCache().addSubentry( newName, subentry );
next( renameContext );
@@ -1515,7 +1545,11 @@ public class SubentryInterceptor extends
{
Entry candidate = subentries.get();
Dn dn = candidate.getDn();
- dn.apply( schemaManager );
+
+ if ( !dn.isSchemaAware() )
+ {
+ dn = new Dn( schemaManager, dn );
+ }
if ( directoryService.getEvaluator().evaluate( ss, apName, dn, candidate ) )
{
@@ -1558,7 +1592,7 @@ public class SubentryInterceptor extends
List<Modification> mods = getModsOnEntryRdnChange( oldDn, newName, entry );
- if ( mods.size() > 0 )
+ if ( !mods.isEmpty() )
{
nexus.modify( new ModifyOperationContext( renameContext.getSession(), newName, mods ) );
}
@@ -1569,6 +1603,7 @@ public class SubentryInterceptor extends
/**
* {@inheritDoc}
*/
+ @Override
public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException
{
EntryFilteringCursor cursor = next( searchContext );
Modified: directory/apacheds/branches/apacheds-value/interceptors/subtree/src/test/java/org/apache/directory/server/core/subtree/RefinementEvaluatorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-value/interceptors/subtree/src/test/java/org/apache/directory/server/core/subtree/RefinementEvaluatorTest.java?rev=1748572&r1=1748571&r2=1748572&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-value/interceptors/subtree/src/test/java/org/apache/directory/server/core/subtree/RefinementEvaluatorTest.java (original)
+++ directory/apacheds/branches/apacheds-value/interceptors/subtree/src/test/java/org/apache/directory/server/core/subtree/RefinementEvaluatorTest.java Wed Jun 15 12:29:57 2016
@@ -26,7 +26,7 @@ import static org.junit.Assert.fail;
import org.apache.directory.api.ldap.model.entry.Attribute;
import org.apache.directory.api.ldap.model.entry.DefaultAttribute;
-import org.apache.directory.api.ldap.model.entry.StringValue;
+import org.apache.directory.api.ldap.model.entry.Value;
import org.apache.directory.api.ldap.model.filter.EqualityNode;
import org.apache.directory.api.ldap.model.filter.ExprNode;
import org.apache.directory.api.ldap.model.filter.FilterParser;
@@ -123,7 +123,7 @@ public class RefinementEvaluatorTest
try
{
- assertFalse( evaluator.evaluate( new EqualityNode( ( String ) null, new StringValue( "" ) ), null ) );
+ assertFalse( evaluator.evaluate( new EqualityNode( ( String ) null, "" ), null ) );
fail( "should never get here due to an IAE" );
}
catch ( IllegalArgumentException iae )
@@ -132,7 +132,7 @@ public class RefinementEvaluatorTest
try
{
- assertFalse( evaluator.evaluate( new EqualityNode( ( String ) null, new StringValue( "" ) ),
+ assertFalse( evaluator.evaluate( new EqualityNode( ( String ) null, "" ),
new DefaultAttribute( "cn", CN_AT ) ) );
fail( "should never get here due to an IAE" );
}
@@ -150,18 +150,18 @@ public class RefinementEvaluatorTest
// positive test
objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "person" );
assertTrue( evaluator
- .evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "person" ) ), objectClasses ) );
+ .evaluate( new EqualityNode( OBJECT_CLASS_AT, new Value( "person" ) ), objectClasses ) );
objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "person", "blah" );
assertTrue( evaluator
- .evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "person" ) ), objectClasses ) );
+ .evaluate( new EqualityNode( OBJECT_CLASS_AT, new Value( "person" ) ), objectClasses ) );
// negative tests
objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "person" );
- assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "blah" ) ), objectClasses ) );
+ assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new Value( "blah" ) ), objectClasses ) );
objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "blah" );
- assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "person" ) ),
+ assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new Value( "person" ) ),
objectClasses ) );
}
@@ -172,20 +172,20 @@ public class RefinementEvaluatorTest
Attribute objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "person" );
// positive test
- assertTrue( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "2.5.6.6" ) ),
+ assertTrue( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new Value( "2.5.6.6" ) ),
objectClasses ) );
objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "person", "blah" );
- assertTrue( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "2.5.6.6" ) ),
+ assertTrue( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new Value( "2.5.6.6" ) ),
objectClasses ) );
// negative tests
objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "person" );
- assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "2.5.6.5" ) ),
+ assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new Value( "2.5.6.5" ) ),
objectClasses ) );
objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "blah" );
- assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "2.5.6.5" ) ),
+ assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new Value( "2.5.6.5" ) ),
objectClasses ) );
}
Modified: directory/apacheds/branches/apacheds-value/interceptors/subtree/src/test/java/org/apache/directory/server/core/subtree/RefinementLeafEvaluatorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-value/interceptors/subtree/src/test/java/org/apache/directory/server/core/subtree/RefinementLeafEvaluatorTest.java?rev=1748572&r1=1748571&r2=1748572&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-value/interceptors/subtree/src/test/java/org/apache/directory/server/core/subtree/RefinementLeafEvaluatorTest.java (original)
+++ directory/apacheds/branches/apacheds-value/interceptors/subtree/src/test/java/org/apache/directory/server/core/subtree/RefinementLeafEvaluatorTest.java Wed Jun 15 12:29:57 2016
@@ -27,7 +27,7 @@ import static org.junit.Assert.fail;
import org.apache.directory.api.ldap.model.constants.SchemaConstants;
import org.apache.directory.api.ldap.model.entry.Attribute;
import org.apache.directory.api.ldap.model.entry.DefaultAttribute;
-import org.apache.directory.api.ldap.model.entry.StringValue;
+import org.apache.directory.api.ldap.model.entry.Value;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.filter.EqualityNode;
import org.apache.directory.api.ldap.model.filter.GreaterEqNode;
@@ -123,7 +123,7 @@ public class RefinementLeafEvaluatorTest
try
{
- assertFalse( evaluator.evaluate( new GreaterEqNode( "", new StringValue( "" ) ), objectClasses ) );
+ assertFalse( evaluator.evaluate( new GreaterEqNode( "", "" ), objectClasses ) );
fail( "should never get here due to an NE" );
}
catch ( LdapException ne )
@@ -132,7 +132,7 @@ public class RefinementLeafEvaluatorTest
try
{
- assertFalse( evaluator.evaluate( new EqualityNode( "", new StringValue( "" ) ), objectClasses ) );
+ assertFalse( evaluator.evaluate( new EqualityNode( "", "" ), objectClasses ) );
fail( "should never get here due to an NE" );
}
catch ( IllegalArgumentException iae )
@@ -141,7 +141,7 @@ public class RefinementLeafEvaluatorTest
try
{
- assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "" ) ), objectClasses ) );
+ assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new Value( "" ) ), objectClasses ) );
fail( "should never get here due to an IAE" );
}
catch ( IllegalArgumentException iae )
@@ -151,7 +151,7 @@ public class RefinementLeafEvaluatorTest
try
{
objectClasses = new DefaultAttribute( "cn", OBJECT_CLASS_AT.getName() );
- assertFalse( evaluator.evaluate( new EqualityNode( CN_AT, new StringValue( "" ) ), objectClasses ) );
+ assertFalse( evaluator.evaluate( new EqualityNode( CN_AT, new Value( "" ) ), objectClasses ) );
fail( "should never get here due to an IAE" );
}
catch ( IllegalArgumentException iae )
@@ -167,20 +167,20 @@ public class RefinementLeafEvaluatorTest
// positive test
Attribute objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "person" );
assertTrue( evaluator
- .evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "person" ) ), objectClasses ) );
+ .evaluate( new EqualityNode( OBJECT_CLASS_AT, new Value( "person" ) ), objectClasses ) );
objectClasses = new DefaultAttribute( OBJECT_CLASS_AT );
objectClasses.add( "person" );
objectClasses.add( "blah" );
assertTrue( evaluator
- .evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "person" ) ), objectClasses ) );
+ .evaluate( new EqualityNode( OBJECT_CLASS_AT, new Value( "person" ) ), objectClasses ) );
// negative tests
objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "person" );
- assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "blah" ) ), objectClasses ) );
+ assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new Value( "blah" ) ), objectClasses ) );
objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "blah" );
- assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "person" ) ),
+ assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new Value( "person" ) ),
objectClasses ) );
}
@@ -191,22 +191,22 @@ public class RefinementLeafEvaluatorTest
Attribute objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "person" );
// positive test
- assertTrue( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "2.5.6.6" ) ),
+ assertTrue( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new Value( "2.5.6.6" ) ),
objectClasses ) );
objectClasses = new DefaultAttribute( OBJECT_CLASS_AT );
objectClasses.add( "person" );
objectClasses.add( "blah" );
- assertTrue( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "2.5.6.6" ) ),
+ assertTrue( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new Value( "2.5.6.6" ) ),
objectClasses ) );
// negative tests
objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "person" );
- assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "2.5.6.5" ) ),
+ assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new Value( "2.5.6.5" ) ),
objectClasses ) );
objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "blah" );
- assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "2.5.6.5" ) ),
+ assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new Value( "2.5.6.5" ) ),
objectClasses ) );
}
}
Modified: directory/apacheds/branches/apacheds-value/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/AbstractStoredProcedureParameterInjector.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-value/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/AbstractStoredProcedureParameterInjector.java?rev=1748572&r1=1748571&r2=1748572&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-value/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/AbstractStoredProcedureParameterInjector.java (original)
+++ directory/apacheds/branches/apacheds-value/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/AbstractStoredProcedureParameterInjector.java Wed Jun 15 12:29:57 2016
@@ -44,10 +44,36 @@ public abstract class AbstractStoredProc
private Map<Class<?>, MicroInjector> injectors;
+ MicroInjector operationPrincipalInjector = new MicroInjector()
+ {
+ @Override
+ public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapException
+ {
+ return getOperationPrincipal();
+ }
+ };
+
+ MicroInjector ldapContextInjector = new MicroInjector()
+ {
+ @Override
+ public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapException
+ {
+ Generic_LDAP_CONTEXT ldapCtxParam = ( Generic_LDAP_CONTEXT ) param;
+ Dn ldapCtxName = ldapCtxParam.getCtxName();
+
+ CoreSession session = opContext.getSession();
+ LookupOperationContext lookupContext =
+ new LookupOperationContext( session, ldapCtxName, SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+
+ return session.getDirectoryService().getPartitionNexus().lookup( lookupContext );
+ }
+ };
+
+
public AbstractStoredProcedureParameterInjector( OperationContext opContext )
{
this.opContext = opContext;
- injectors = new HashMap<Class<?>, MicroInjector>();
+ injectors = new HashMap<>();
injectors.put( StoredProcedureParameter.Generic_OPERATION_PRINCIPAL.class, operationPrincipalInjector );
injectors.put( StoredProcedureParameter.Generic_LDAP_CONTEXT.class, ldapContextInjector );
}
@@ -56,8 +82,7 @@ public abstract class AbstractStoredProc
protected Dn getOperationPrincipal() throws LdapInvalidDnException
{
Principal principal = opContext.getSession().getEffectivePrincipal();
- Dn userName = opContext.getSession().getDirectoryService().getDnFactory().create( principal.getName() );
- return userName;
+ return opContext.getSession().getDirectoryService().getDnFactory().create( principal.getName() );
}
@@ -79,10 +104,11 @@ public abstract class AbstractStoredProc
}
+ @Override
public final List<Object> getArgumentsToInject( OperationContext opContext,
List<StoredProcedureParameter> parameterList ) throws LdapException
{
- List<Object> arguments = new ArrayList<Object>();
+ List<Object> arguments = new ArrayList<>();
Iterator<StoredProcedureParameter> it = parameterList.iterator();
@@ -95,27 +121,4 @@ public abstract class AbstractStoredProc
return arguments;
}
-
- MicroInjector operationPrincipalInjector = new MicroInjector()
- {
- public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapException
- {
- return getOperationPrincipal();
- }
- };
-
- MicroInjector ldapContextInjector = new MicroInjector()
- {
- public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapException
- {
- Generic_LDAP_CONTEXT ldapCtxParam = ( Generic_LDAP_CONTEXT ) param;
- Dn ldapCtxName = ldapCtxParam.getCtxName();
-
- CoreSession session = opContext.getSession();
- LookupOperationContext lookupContext =
- new LookupOperationContext( session, ldapCtxName, SchemaConstants.ALL_ATTRIBUTES_ARRAY );
-
- return session.getDirectoryService().getPartitionNexus().lookup( lookupContext );
- }
- };
}