directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1594228 - in /directory/apacheds/trunk: ./ core/ interceptors/ interceptors/number/ interceptors/number/src/ interceptors/number/src/main/ interceptors/number/src/main/java/ interceptors/number/src/main/java/org/ interceptors/number/src/ma...
Date Tue, 13 May 2014 14:07:26 GMT
Author: kayyagari
Date: Tue May 13 14:07:25 2014
New Revision: 1594228

URL: http://svn.apache.org/r1594228
Log:
adding a new interceptor that increments any configured numeric attributes' value before adding
the corresponding entry

Added:
    directory/apacheds/trunk/interceptors/number/
    directory/apacheds/trunk/interceptors/number/pom.xml
    directory/apacheds/trunk/interceptors/number/src/
    directory/apacheds/trunk/interceptors/number/src/main/
    directory/apacheds/trunk/interceptors/number/src/main/java/
    directory/apacheds/trunk/interceptors/number/src/main/java/org/
    directory/apacheds/trunk/interceptors/number/src/main/java/org/apache/
    directory/apacheds/trunk/interceptors/number/src/main/java/org/apache/directory/
    directory/apacheds/trunk/interceptors/number/src/main/java/org/apache/directory/server/
    directory/apacheds/trunk/interceptors/number/src/main/java/org/apache/directory/server/core/
    directory/apacheds/trunk/interceptors/number/src/main/java/org/apache/directory/server/core/number/
    directory/apacheds/trunk/interceptors/number/src/main/java/org/apache/directory/server/core/number/NumberIncrementingInterceptor.java
Modified:
    directory/apacheds/trunk/core/pom.xml
    directory/apacheds/trunk/interceptors/pom.xml
    directory/apacheds/trunk/pom.xml
    directory/apacheds/trunk/server-config/src/main/resources/config.ldif

Modified: directory/apacheds/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/pom.xml?rev=1594228&r1=1594227&r2=1594228&view=diff
==============================================================================
--- directory/apacheds/trunk/core/pom.xml (original)
+++ directory/apacheds/trunk/core/pom.xml Tue May 13 14:07:25 2014
@@ -66,6 +66,11 @@
 
     <dependency>
       <groupId>${project.groupId}</groupId>
+      <artifactId>apacheds-interceptors-number</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>${project.groupId}</groupId>
       <artifactId>apacheds-interceptors-authz</artifactId>
     </dependency>
 

Added: directory/apacheds/trunk/interceptors/number/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/number/pom.xml?rev=1594228&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/number/pom.xml (added)
+++ directory/apacheds/trunk/interceptors/number/pom.xml Tue May 13 14:07:25 2014
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.directory.server</groupId>
+    <artifactId>apacheds-interceptors</artifactId>
+    <version>2.0.0-M17-SNAPSHOT</version>
+  </parent>
+  
+  <artifactId>apacheds-interceptors-number</artifactId>
+  <name>ApacheDS Interceptor to increment numeric attributes</name>
+  <packaging>bundle</packaging>
+
+  <description>
+    Numeric attribute value incrementing  interceptor
+  </description>
+
+  <dependencies>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>apacheds-core-api</artifactId>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>apacheds-core-shared</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.api</groupId>
+      <artifactId>api-ldap-extras-util</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.api</groupId>
+      <artifactId>api-ldap-model</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.api</groupId>
+      <artifactId>api-util</artifactId>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration> 
+          <systemPropertyVariables>
+            <workingDirectory>${basedir}/target/server-work</workingDirectory>
+          </systemPropertyVariables>
+        </configuration>
+      </plugin>
+      
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-source-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>attach-sources</id>
+            <phase>verify</phase>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <configuration>
+          <archive>
+            <manifestFile>META-INF/MANIFEST.MF</manifestFile>
+            <addMavenDescriptor>false</addMavenDescriptor>
+          </archive>
+        </configuration>
+      </plugin>
+      
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <inherited>true</inherited>
+        <extensions>true</extensions>
+        <configuration>
+          <manifestLocation>META-INF</manifestLocation>
+          <instructions>
+            <Bundle-SymbolicName>${project.groupId}.interceptors.admin</Bundle-SymbolicName>
+            <Export-Package>
+                {local-packages};version=${project.version};-noimport:=true
+            </Export-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+
+    <resources>
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>true</filtering>
+        <excludes>
+          <exclude>**/*.gif</exclude>
+        </excludes>
+      </resource>
+    </resources>
+  </build>
+</project>
+

Added: directory/apacheds/trunk/interceptors/number/src/main/java/org/apache/directory/server/core/number/NumberIncrementingInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/number/src/main/java/org/apache/directory/server/core/number/NumberIncrementingInterceptor.java?rev=1594228&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/number/src/main/java/org/apache/directory/server/core/number/NumberIncrementingInterceptor.java
(added)
+++ directory/apacheds/trunk/interceptors/number/src/main/java/org/apache/directory/server/core/number/NumberIncrementingInterceptor.java
Tue May 13 14:07:25 2014
@@ -0,0 +1,183 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.server.core.number;
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;
+
+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.DefaultEntry;
+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.ModificationOperation;
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.ldap.model.schema.MatchingRule;
+import org.apache.directory.server.core.api.DirectoryService;
+import org.apache.directory.server.core.api.entry.ClonedServerEntry;
+import org.apache.directory.server.core.api.interceptor.BaseInterceptor;
+import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
+import org.apache.directory.server.core.api.partition.Partition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * An interceptor to increment any attribute with integer matching rule
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class NumberIncrementingInterceptor extends BaseInterceptor
+{
+    /** A {@link Logger} for this class */
+    private static final Logger LOG = LoggerFactory.getLogger( NumberIncrementingInterceptor.class
);
+
+    /** the DN of the holder entry */
+    private Dn numberHolder;
+    
+    /** a map of integer attribute and it's present value */
+    private Map<String, AtomicInteger> incMap = new HashMap<String, AtomicInteger>();
+    
+    
+    @Override
+    public void init( DirectoryService directoryService ) throws LdapException
+    {
+        super.init( directoryService );
+        
+        numberHolder = new Dn( schemaManager, "ou=autoIncDataHolder,ou=system" );
+        
+        Partition systemPartition = directoryService.getSystemPartition();
+        
+        LookupOperationContext lookupContext = new LookupOperationContext( directoryService.getAdminSession(),
numberHolder, SchemaConstants.ALL_ATTRIBUTES_ARRAY ); 
+        Entry entry = systemPartition.lookup( lookupContext );
+        
+        if ( entry == null )
+        {
+            //FIXME make sure this entry addition gets replicated
+            entry = new DefaultEntry( schemaManager );
+            entry.setDn( numberHolder );
+            entry.add( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.ORGANIZATIONAL_UNIT_OC
);
+            entry.add( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.EXTENSIBLE_OBJECT_OC
);
+            entry.add( SchemaConstants.OU_AT, numberHolder.getRdn().getValue().getString()
);
+            entry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
+            entry.add( SchemaConstants.ENTRY_CSN_AT, directoryService.getCSN().toString()
);
+            
+            AddOperationContext addContext = new AddOperationContext( directoryService.getAdminSession()
);
+            addContext.setDn( numberHolder );
+            addContext.setEntry( new ClonedServerEntry( entry ) );
+            
+            LOG.debug( "Adding container entry to hold numeric attribute values" );
+            systemPartition.add( addContext );
+        }
+        else
+        {
+            for ( Attribute at : entry )
+            {
+                MatchingRule mr = at.getAttributeType().getEquality();
+                if ( mr != null )
+                {
+                    if ( SchemaConstants.INTEGER_MATCH_MR_OID.equals( mr.getOid() ) )
+                    {
+                        int t = Integer.parseInt( at.getString() );
+                        incMap.put( at.getId(), new AtomicInteger( t ) );
+                    }
+                }
+            }
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void add( AddOperationContext addContext ) throws LdapException
+    {
+        LOG.debug( ">>> Entering into the number incrementing interceptor, addRequest"
);
+
+        if ( addContext.isReplEvent() )
+        {
+            // Nope, go on.
+            next( addContext );
+            return;
+        }
+
+        Entry entry = addContext.getEntry();
+
+        List<Attribute> lst = new ArrayList<Attribute>();
+        
+        for( String oid : incMap.keySet() )
+        {
+            Attribute at = entry.get( oid );
+            if( at != null )
+            {
+                lst.add( at );
+            }
+        }
+        
+        if( lst.isEmpty() )
+        {
+            next( addContext );
+            return;
+        }
+
+        for( Attribute at : lst )
+        {
+            int stored = incMap.get( at.getId() ).get();
+            at.clear();
+            at.add( String.valueOf( stored + 1 ) );
+        }
+        
+        // Ok, we are golden.
+        next( addContext );
+
+        ModifyOperationContext bindModCtx = new ModifyOperationContext( directoryService.getAdminSession()
);
+        bindModCtx.setDn( numberHolder );
+        bindModCtx.setPushToEvtInterceptor( true );
+
+        List<Modification> mods = new ArrayList<Modification>();
+
+        for( Attribute at : lst )
+        {
+            AtomicInteger ai = incMap.get( at.getId() );
+            ai.set( ai.get() + 1 );
+            
+            Modification mod = new DefaultModification();
+            mod.setOperation( ModificationOperation.REPLACE_ATTRIBUTE );
+            mod.setAttribute( at );
+            
+            mods.add( mod );
+        }
+        
+        bindModCtx.setModItems( mods );
+        
+        directoryService.getPartitionNexus().modify( bindModCtx );
+        
+        LOG.debug( "Successfully updated numeric attribute in {}", numberHolder );
+    }
+}

Modified: directory/apacheds/trunk/interceptors/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/pom.xml?rev=1594228&r1=1594227&r2=1594228&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptors/pom.xml (original)
+++ directory/apacheds/trunk/interceptors/pom.xml Tue May 13 14:07:25 2014
@@ -52,6 +52,7 @@
     <module>hash</module>
     <module>schema</module>
     <module>trigger</module>
+    <module>number</module>
   </modules>
 
 </project>

Modified: directory/apacheds/trunk/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/pom.xml?rev=1594228&r1=1594227&r2=1594228&view=diff
==============================================================================
--- directory/apacheds/trunk/pom.xml (original)
+++ directory/apacheds/trunk/pom.xml Tue May 13 14:07:25 2014
@@ -603,6 +603,12 @@
       
       <dependency>
         <groupId>${project.groupId}</groupId>
+        <artifactId>apacheds-interceptors-number</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+
+      <dependency>
+        <groupId>${project.groupId}</groupId>
         <artifactId>apacheds-interceptors-authn</artifactId>
         <version>${project.version}</version>
       </dependency>

Modified: directory/apacheds/trunk/server-config/src/main/resources/config.ldif
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/resources/config.ldif?rev=1594228&r1=1594227&r2=1594228&view=diff
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/resources/config.ldif (original)
+++ directory/apacheds/trunk/server-config/src/main/resources/config.ldif Tue May 13 14:07:25
2014
@@ -250,6 +250,15 @@ ads-interceptorclassname: org.apache.dir
 ads-interceptorid: journalInterceptor
 ads-enabled: TRUE
 
+dn: ads-interceptorId=numberInterceptor,ou=interceptors,ads-directoryServiceId=default,ou=config
+objectclass: top
+objectclass: ads-base
+objectclass: ads-interceptor
+ads-interceptororder: 17
+ads-interceptorclassname: org.apache.directory.server.core.number.NumberIncrementingInterceptor
+ads-interceptorId: numberInterceptor
+ads-enabled: FALSE
+
 dn: ou=partitions,ads-directoryServiceId=default,ou=config
 ou: partitions
 objectclass: organizationalUnit



Mime
View raw message