directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1538544 - in /directory/escimo/trunk: common/src/main/java/org/apache/directory/scim/search/ common/src/main/java/org/apache/directory/scim/util/ common/src/test/java/org/apache/directory/scim/search/ ldap/src/main/java/org/apache/director...
Date Mon, 04 Nov 2013 10:28:04 GMT
Author: kayyagari
Date: Mon Nov  4 10:28:04 2013
New Revision: 1538544

URL: http://svn.apache.org/r1538544
Log:
o added a method to convert SCIM date to LDAP date format
o added tests

Added:
    directory/escimo/trunk/common/src/test/java/org/apache/directory/scim/search/ResourceUtilTest.java
Modified:
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/search/Operator.java
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/util/ResourceUtil.java
    directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapResourceProvider.java
    directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapUtil.java
    directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MetaAttributeHandler.java

Modified: directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/search/Operator.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/search/Operator.java?rev=1538544&r1=1538543&r2=1538544&view=diff
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/search/Operator.java
(original)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/search/Operator.java
Mon Nov  4 10:28:04 2013
@@ -20,7 +20,7 @@
 package org.apache.directory.scim.search;
 
 /**
- * TODO Operator.
+ * An enum to hold all the operators used in search filters.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
@@ -94,10 +94,6 @@ public enum Operator
     /** Unknown operator */
     UNKNOWN("", "unknown operator");
     
-    //LEFT_PARENTHESIS("(", "left parenthesis"),
-    
-    //RIGHT_PARENTHESIS(")", "right parenthesis");
-    
     private String val;
     
     private String desc;

Modified: directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/util/ResourceUtil.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/util/ResourceUtil.java?rev=1538544&r1=1538543&r2=1538544&view=diff
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/util/ResourceUtil.java
(original)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/util/ResourceUtil.java
Mon Nov  4 10:28:04 2013
@@ -20,6 +20,7 @@
 package org.apache.directory.scim.util;
 
 
+
 /**
  * TODO ResourceUtil.
  *
@@ -27,7 +28,7 @@ package org.apache.directory.scim.util;
  */
 public class ResourceUtil
 {
-    public static String formatDate( String zTime )
+    public static String toScimDate( String zTime )
     {
         //parse a value like 20120302164134Z to 2012-03-02T16:41:34Z 
         StringBuilder sb = new StringBuilder();
@@ -66,4 +67,12 @@ public class ResourceUtil
         return sb.toString();
     }
 
+    public static String toLdapDate( String scimTime )
+    {
+        scimTime = scimTime.replace( "-", "" );
+        scimTime = scimTime.replace( ":", "" );
+        scimTime = scimTime.replace( "T", "" );
+        
+        return scimTime;
+    }
 }

Added: directory/escimo/trunk/common/src/test/java/org/apache/directory/scim/search/ResourceUtilTest.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/test/java/org/apache/directory/scim/search/ResourceUtilTest.java?rev=1538544&view=auto
==============================================================================
--- directory/escimo/trunk/common/src/test/java/org/apache/directory/scim/search/ResourceUtilTest.java
(added)
+++ directory/escimo/trunk/common/src/test/java/org/apache/directory/scim/search/ResourceUtilTest.java
Mon Nov  4 10:28:04 2013
@@ -0,0 +1,54 @@
+/*
+ *   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.scim.search;
+
+
+import org.apache.directory.scim.util.ResourceUtil;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+
+/**
+ * TODO ResourceUtilTest.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ResourceUtilTest
+{
+    @Test
+    public void testScimDateToLdapDate()
+    {
+        String scimDate = "2012-03-02T16:41:34Z";
+
+        String ldapDate = ResourceUtil.toLdapDate( scimDate );
+        assertEquals( "20120302164134Z", ldapDate );
+    }
+
+
+    @Test
+    public void testLdapDateToScimDate()
+    {
+        String ldapDate = "20120302164134Z";
+
+        String scimDate = ResourceUtil.toScimDate( ldapDate );
+        assertEquals( "2012-03-02T16:41:34Z", scimDate );
+    }
+
+}

Modified: directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapResourceProvider.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapResourceProvider.java?rev=1538544&r1=1538543&r2=1538544&view=diff
==============================================================================
--- directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapResourceProvider.java
(original)
+++ directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapResourceProvider.java
Mon Nov  4 10:28:04 2013
@@ -1134,7 +1134,7 @@ public class LdapResourceProvider implem
             }
             else if ( sc instanceof GeneralizedTimeSyntaxChecker )
             {
-                return ResourceUtil.formatDate( ldapValue.getString() );
+                return ResourceUtil.toScimDate( ldapValue.getString() );
             }
         }
 

Modified: directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapUtil.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapUtil.java?rev=1538544&r1=1538543&r2=1538544&view=diff
==============================================================================
--- directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapUtil.java
(original)
+++ directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapUtil.java
Mon Nov  4 10:28:04 2013
@@ -38,6 +38,8 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.message.ModifyRequest;
 import org.apache.directory.api.ldap.model.schema.AttributeType;
 import org.apache.directory.api.ldap.model.schema.SchemaManager;
+import org.apache.directory.api.ldap.model.schema.SyntaxChecker;
+import org.apache.directory.api.ldap.model.schema.syntaxCheckers.GeneralizedTimeSyntaxChecker;
 import org.apache.directory.api.util.Base64;
 import org.apache.directory.api.util.Strings;
 import org.apache.directory.scim.AttributeHandler;
@@ -51,6 +53,7 @@ import org.apache.directory.scim.schema.
 import org.apache.directory.scim.search.BranchNode;
 import org.apache.directory.scim.search.FilterNode;
 import org.apache.directory.scim.search.TerminalNode;
+import org.apache.directory.scim.util.ResourceUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -451,26 +454,35 @@ public class LdapUtil
                 return null;
             }
             
+            String value = tn.getValue();
+            
+            SyntaxChecker sc = at.getSyntax().getSyntaxChecker();
+            
+            if( sc instanceof GeneralizedTimeSyntaxChecker )
+            {
+                value = ResourceUtil.toLdapDate( value );
+            }
+            
             switch( scimFilter.getOperator() )
             {
                 case EQ:
-                    ldapFilter = new EqualityNode<String>( at, new StringValue( tn.getValue()
) );
+                    ldapFilter = new EqualityNode<String>( at, new StringValue( value
) );
                     break;
                   
                 case CO:
                     List<String> anyPattern = new ArrayList<String>();
-                    anyPattern.add( tn.getValue() );
+                    anyPattern.add( value );
                     ldapFilter = new SubstringNode( anyPattern, at, null, null );
                     break;
                 
                 case GT:
                 case GE:
-                    ldapFilter = new GreaterEqNode<String>( at, new StringValue( tn.getValue()
) );
+                    ldapFilter = new GreaterEqNode<String>( at, new StringValue( value
) );
                     break;
                     
                 case LT:
                 case LE:
-                    ldapFilter = new LessEqNode<String>( at, new StringValue( tn.getValue()
) );
+                    ldapFilter = new LessEqNode<String>( at, new StringValue( value
) );
                     break;
                     
                 case PR:
@@ -478,7 +490,7 @@ public class LdapUtil
                     break;
                     
                 case SW:
-                    ldapFilter = new SubstringNode( at, tn.getValue(), null );
+                    ldapFilter = new SubstringNode( at, value, null );
                     break;
             }
         }

Modified: directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MetaAttributeHandler.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MetaAttributeHandler.java?rev=1538544&r1=1538543&r2=1538544&view=diff
==============================================================================
--- directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MetaAttributeHandler.java
(original)
+++ directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MetaAttributeHandler.java
Mon Nov  4 10:28:04 2013
@@ -60,7 +60,7 @@ public class MetaAttributeHandler extend
             if( atCreated != null )
             {
                 SimpleAttribute created = new SimpleAttribute( "created" );
-                createTimestamp = ResourceUtil.formatDate( atCreated.getString() );
+                createTimestamp = ResourceUtil.toScimDate( atCreated.getString() );
                 created.setValue( createTimestamp );
                 atList.add( created );
             }
@@ -70,7 +70,7 @@ public class MetaAttributeHandler extend
             if( atlastMod != null )
             {
                 lastModified = new SimpleAttribute( "lastModified" );
-                lastModified.setValue( ResourceUtil.formatDate( atlastMod.getString() ) );
+                lastModified.setValue( ResourceUtil.toScimDate( atlastMod.getString() ) );
             }
             else if( createTimestamp != null )
             {



Mime
View raw message