Apply comments for MDSAL Store
[aaa.git] / aaa-idmlight / src / main / java / org / opendaylight / aaa / idm / rest / RoleHandler.java
index 711094eb11e0f022d2b08f7ea3efdb1bf8f22eff..f2478a8670944dcbd80beb489738f6bc239e48e2 100644 (file)
@@ -26,19 +26,20 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
+import org.opendaylight.aaa.api.IDMStoreException;
+import org.opendaylight.aaa.api.IIDMStore;
+import org.opendaylight.aaa.api.model.IDMError;
+import org.opendaylight.aaa.api.model.Role;
+import org.opendaylight.aaa.api.model.Roles;
+import org.opendaylight.aaa.idm.IdmLightApplication;
 import org.opendaylight.aaa.idm.IdmLightProxy;
-import org.opendaylight.aaa.idm.model.IDMError;
-import org.opendaylight.aaa.idm.model.Role;
-import org.opendaylight.aaa.idm.model.Roles;
-import org.opendaylight.aaa.idm.persistence.RoleStore;
-import org.opendaylight.aaa.idm.persistence.StoreException;
+import org.opendaylight.aaa.idm.ServiceLocator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Path("/v1/roles")
 public class RoleHandler {
    private static Logger logger = LoggerFactory.getLogger(RoleHandler.class);
-   private static RoleStore roleStore = new RoleStore();
 
    @GET
    @Produces("application/json")
@@ -46,10 +47,10 @@ public class RoleHandler {
       logger.info("get /roles");
       Roles roles=null;
       try {
-         roles = roleStore.getRoles();
+         roles = ServiceLocator.INSTANCE.getStore().getRoles();
       }
-      catch (StoreException se) {
-         return new IDMError(500,"internal error getting roles",se.message).response();
+      catch (IDMStoreException se) {
+         return new IDMError(500,"internal error getting roles",se.getMessage()).response();
       }
       return Response.ok(roles).build();
    }
@@ -62,10 +63,10 @@ public class RoleHandler {
       Role role=null;
 
       try {
-         role = roleStore.getRole(id);
+         role = ServiceLocator.INSTANCE.getStore().readRole(id);
       }
-      catch(StoreException se) {
-         return new IDMError(500,"internal error getting roles",se.message).response();
+      catch(IDMStoreException se) {
+         return new IDMError(500,"internal error getting roles",se.getMessage()).response();
       }
 
       if (role==null) {
@@ -85,30 +86,30 @@ public class RoleHandler {
          if (role.getName()==null) {
             return new IDMError(404,"name must be defined on role create","").response();
          }
-         else if (role.getName().length()>RoleStore.MAX_FIELD_LEN) {
-            return new IDMError(400,"role name max length is :" + RoleStore.MAX_FIELD_LEN,"").response();
+         else if (role.getName().length()> IdmLightApplication.MAX_FIELD_LEN) {
+            return new IDMError(400,"role name max length is :" + IdmLightApplication.MAX_FIELD_LEN,"").response();
          }
 
          // domain
-         if (role.getDomainID()==null) {
+         if (role.getDomainid()==null) {
             return new IDMError(404,"The role's domain must be defined on role when creating a role.","").response();
          }
-         else if (role.getDomainID().length()>RoleStore.MAX_FIELD_LEN) {
-            return new IDMError(400,"role domain max length is :" + RoleStore.MAX_FIELD_LEN,"").response();
+         else if (role.getDomainid().length()>IdmLightApplication.MAX_FIELD_LEN) {
+            return new IDMError(400,"role domain max length is :" + IdmLightApplication.MAX_FIELD_LEN,"").response();
          }
 
          // description
          if (role.getDescription()==null) {
             role.setDescription("");
          }
-         else if (role.getDescription().length()>RoleStore.MAX_FIELD_LEN) {
-            return new IDMError(400,"role description max length is :" + RoleStore.MAX_FIELD_LEN,"").response();
+         else if (role.getDescription().length()>IdmLightApplication.MAX_FIELD_LEN) {
+            return new IDMError(400,"role description max length is :" + IdmLightApplication.MAX_FIELD_LEN,"").response();
          }
 
-         role = roleStore.createRole(role);
+         role = ServiceLocator.INSTANCE.getStore().writeRole(role);
       }
-      catch (StoreException se) {
-         return new IDMError(500,"internal error creating role",se.message).response();
+      catch (IDMStoreException se) {
+         return new IDMError(500,"internal error creating role",se.getMessage()).response();
       }
 
       return Response.status(201).entity(role).build();
@@ -126,24 +127,24 @@ public class RoleHandler {
 
          // name
          // TODO: names should be unique
-         if ((role.getName()!=null) && (role.getName().length()>RoleStore.MAX_FIELD_LEN)) {
-            return new IDMError(400,"role name max length is :" + RoleStore.MAX_FIELD_LEN,"").response();
+         if ((role.getName()!=null) && (role.getName().length()>IdmLightApplication.MAX_FIELD_LEN)) {
+            return new IDMError(400,"role name max length is :" + IdmLightApplication.MAX_FIELD_LEN,"").response();
          }
 
          // description
-         if ((role.getDescription()!=null) && (role.getDescription().length()>RoleStore.MAX_FIELD_LEN)) {
-            return new IDMError(400,"role description max length is :" + RoleStore.MAX_FIELD_LEN,"").response();
+         if ((role.getDescription()!=null) && (role.getDescription().length()>IdmLightApplication.MAX_FIELD_LEN)) {
+            return new IDMError(400,"role description max length is :" + IdmLightApplication.MAX_FIELD_LEN,"").response();
          }
 
-         role = roleStore.putRole(role);
+         role = ServiceLocator.INSTANCE.getStore().updateRole(role);
          if (role==null) {
             return new IDMError(404,"role id not found :" + id,"").response();
          }
          IdmLightProxy.clearClaimCache();
          return Response.status(200).entity(role).build();
       }
-      catch (StoreException se) {
-         return new IDMError(500,"internal error putting role",se.message).response();
+      catch (IDMStoreException se) {
+         return new IDMError(500,"internal error putting role",se.getMessage()).response();
       }
    }
 
@@ -153,15 +154,13 @@ public class RoleHandler {
       logger.info("Delete /roles/" + id);
 
       try {
-         Role role = new Role();
-         role.setRoleid(id);
-         role = roleStore.deleteRole(role);
+         Role role = ServiceLocator.INSTANCE.getStore().deleteRole(id);
          if (role==null) {
             return new IDMError(404,"role id not found :" + id,"").response();
          }
       }
-      catch (StoreException se) {
-         return new IDMError(500,"internal error deleting role",se.message).response();
+      catch (IDMStoreException se) {
+         return new IDMError(500,"internal error deleting role",se.getMessage()).response();
       }
       IdmLightProxy.clearClaimCache();
       return Response.status(204).build();