directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1529460 - in /directory/escimo/branches/json-schema-experiment/server/src/main/java/org/apache/directory/scim/rest: SchemaService.java ServerInitializer.java
Date Sat, 05 Oct 2013 14:35:40 GMT
Author: kayyagari
Date: Sat Oct  5 14:35:39 2013
New Revision: 1529460

URL: http://svn.apache.org/r1529460
Log:
schema service

Added:
    directory/escimo/branches/json-schema-experiment/server/src/main/java/org/apache/directory/scim/rest/SchemaService.java
Modified:
    directory/escimo/branches/json-schema-experiment/server/src/main/java/org/apache/directory/scim/rest/ServerInitializer.java

Added: directory/escimo/branches/json-schema-experiment/server/src/main/java/org/apache/directory/scim/rest/SchemaService.java
URL: http://svn.apache.org/viewvc/directory/escimo/branches/json-schema-experiment/server/src/main/java/org/apache/directory/scim/rest/SchemaService.java?rev=1529460&view=auto
==============================================================================
--- directory/escimo/branches/json-schema-experiment/server/src/main/java/org/apache/directory/scim/rest/SchemaService.java
(added)
+++ directory/escimo/branches/json-schema-experiment/server/src/main/java/org/apache/directory/scim/rest/SchemaService.java
Sat Oct  5 14:35:39 2013
@@ -0,0 +1,68 @@
+/*
+ *   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.rest;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.directory.scim.RequestContext;
+import org.apache.directory.scim.ResourceNotFoundException;
+import org.apache.directory.scim.User;
+import org.apache.directory.scim.json.ResourceSerializer;
+
+/**
+ * TODO SchemaService.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@Path( "Schemas" )
+public class SchemaService
+{
+
+    @GET
+    @Produces({MediaType.APPLICATION_JSON})
+    @Path("{uri}")
+    public Response getUser( @PathParam("uri") String schemaUri, @Context UriInfo uriInfo
)
+    {
+        ResponseBuilder rb = null;
+        
+        String json = ServerInitializer.getSchema( schemaUri );
+        
+        if( json != null )
+        {
+            rb = Response.ok( json, MediaType.APPLICATION_JSON );
+        }
+        else
+        {
+            rb = Response.status( Response.Status.NOT_FOUND ).entity( "No schema found with
the URI " + schemaUri );
+        }
+        
+        return rb.build();
+    }
+
+}

Modified: directory/escimo/branches/json-schema-experiment/server/src/main/java/org/apache/directory/scim/rest/ServerInitializer.java
URL: http://svn.apache.org/viewvc/directory/escimo/branches/json-schema-experiment/server/src/main/java/org/apache/directory/scim/rest/ServerInitializer.java?rev=1529460&r1=1529459&r2=1529460&view=diff
==============================================================================
--- directory/escimo/branches/json-schema-experiment/server/src/main/java/org/apache/directory/scim/rest/ServerInitializer.java
(original)
+++ directory/escimo/branches/json-schema-experiment/server/src/main/java/org/apache/directory/scim/rest/ServerInitializer.java
Sat Oct  5 14:35:39 2013
@@ -19,8 +19,17 @@
  */
 package org.apache.directory.scim.rest;
 
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.commons.lang.StringUtils;
 import org.apache.directory.scim.ProviderService;
+import org.apache.directory.scim.schema.SchemaUtil;
+
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
 
 /**
  * TODO ServerInitializer.
@@ -31,6 +40,8 @@ public class ServerInitializer
 {
     private static ProviderService provider;
     
+    private static Map<String,String> schemas = new HashMap<String, String>();
+    
     private static void init()
     {
         String fqcn = System.getProperty( "escimo.resource.provider", "org.apache.directory.scim.ldap.LdapResourceProvider"
);
@@ -50,6 +61,30 @@ public class ServerInitializer
             re.initCause( e );
             throw re;
         }
+        
+        try
+        {
+            JsonParser parser = new JsonParser();
+            
+            List<URL> urls = SchemaUtil.getDefaultSchemas();
+            for( URL u : urls )
+            {
+                String json = SchemaUtil.getSchemaJson( u );
+                JsonObject obj = ( JsonObject ) parser.parse( json );
+                String uri = obj.get( "id" ).getAsString();
+                
+                schemas.put( uri, json );
+            }
+            
+            // TODO load custom schemas
+        }
+        catch( Exception e )
+        {
+            RuntimeException re = new RuntimeException( "Failed to load the default schemas"
);
+            re.initCause( e );
+            throw re;
+        }
+        
     }
     
     public static ProviderService getProvider()
@@ -61,4 +96,10 @@ public class ServerInitializer
         
         return provider;
     }
+    
+    
+    public static String getSchema( String uri )
+    {
+        return schemas.get( uri );
+    }
 }



Mime
View raw message