Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C4CF91119F for ; Tue, 13 May 2014 14:07:52 +0000 (UTC) Received: (qmail 43934 invoked by uid 500); 13 May 2014 14:07:52 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 43895 invoked by uid 500); 13 May 2014 14:07:52 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 43887 invoked by uid 99); 13 May 2014 14:07:52 -0000 Received: from Unknown (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 May 2014 14:07:52 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 May 2014 14:07:51 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id A900C2388860; Tue, 13 May 2014 14:07:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@directory.apache.org From: kayyagari@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140513140726.A900C2388860@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ ${project.groupId} + apacheds-interceptors-number + + + + ${project.groupId} apacheds-interceptors-authz 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 @@ + + + + + + 4.0.0 + + org.apache.directory.server + apacheds-interceptors + 2.0.0-M17-SNAPSHOT + + + apacheds-interceptors-number + ApacheDS Interceptor to increment numeric attributes + bundle + + + Numeric attribute value incrementing interceptor + + + + + ${project.groupId} + apacheds-core-api + test-jar + test + + + + ${project.groupId} + apacheds-core-shared + + + + org.apache.directory.api + api-ldap-extras-util + + + + org.apache.directory.api + api-ldap-model + + + + org.apache.directory.api + api-util + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${basedir}/target/server-work + + + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + verify + + jar + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + META-INF/MANIFEST.MF + false + + + + + + org.apache.felix + maven-bundle-plugin + true + true + + META-INF + + ${project.groupId}.interceptors.admin + + {local-packages};version=${project.version};-noimport:=true + + + + + + + + + src/main/resources + true + + **/*.gif + + + + + + 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 Apache Directory Project + */ +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 incMap = new HashMap(); + + + @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 lst = new ArrayList(); + + 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 mods = new ArrayList(); + + 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 @@ hash schema trigger + number 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 @@ ${project.groupId} + apacheds-interceptors-number + ${project.version} + + + + ${project.groupId} apacheds-interceptors-authn ${project.version} 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