Update project structure to org.onap.aaf
[aaf/authz.git] / authz-cass / src / main / java / org / onap / aaf / dao / aaf / cached / CachedRoleDAO.java
diff --git a/authz-cass/src/main/java/org/onap/aaf/dao/aaf/cached/CachedRoleDAO.java b/authz-cass/src/main/java/org/onap/aaf/dao/aaf/cached/CachedRoleDAO.java
new file mode 100644 (file)
index 0000000..788efbe
--- /dev/null
@@ -0,0 +1,107 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aaf\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * ===========================================================================\r
+ * * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * * you may not use this file except in compliance with the License.\r
+ * * You may obtain a copy of the License at\r
+ * * \r
+ *  *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * * \r
+ *  * Unless required by applicable law or agreed to in writing, software\r
+ * * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * * See the License for the specific language governing permissions and\r
+ * * limitations under the License.\r
+ * * ============LICENSE_END====================================================\r
+ * *\r
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package org.onap.aaf.dao.aaf.cached;\r
+\r
+import java.util.List;\r
+\r
+import org.onap.aaf.authz.env.AuthzTrans;\r
+import org.onap.aaf.authz.layer.Result;\r
+import org.onap.aaf.dao.CIDAO;\r
+import org.onap.aaf.dao.CachedDAO;\r
+import org.onap.aaf.dao.aaf.cass.PermDAO;\r
+import org.onap.aaf.dao.aaf.cass.RoleDAO;\r
+import org.onap.aaf.dao.aaf.cass.Status;\r
+import org.onap.aaf.dao.aaf.cass.RoleDAO.Data;\r
+\r
+public class CachedRoleDAO extends CachedDAO<AuthzTrans,RoleDAO, RoleDAO.Data> {\r
+       public CachedRoleDAO(RoleDAO dao, CIDAO<AuthzTrans> info) {\r
+               super(dao, info, RoleDAO.CACHE_SEG);\r
+       }\r
+\r
+       public Result<List<Data>> readNS(AuthzTrans trans, final String ns) {\r
+               DAOGetter getter = new DAOGetter(trans,dao()) {\r
+                       public Result<List<Data>> call() {\r
+                               return dao.readNS(trans, ns);\r
+                       }\r
+               };\r
+               \r
+               Result<List<Data>> lurd = get(trans, ns, getter);\r
+               if(lurd.isOK() && lurd.isEmpty()) {\r
+                       return Result.err(Status.ERR_RoleNotFound,"No Role found");\r
+               }\r
+               return lurd;\r
+       }\r
+\r
+       public Result<List<Data>> readName(AuthzTrans trans, final String name) {\r
+               DAOGetter getter = new DAOGetter(trans,dao()) {\r
+                       public Result<List<Data>> call() {\r
+                               return dao().readName(trans, name);\r
+                       }\r
+               };\r
+               \r
+               Result<List<Data>> lurd = get(trans, name, getter);\r
+               if(lurd.isOK() && lurd.isEmpty()) {\r
+                       return Result.err(Status.ERR_RoleNotFound,"No Role found");\r
+               }\r
+               return lurd;\r
+       }\r
+\r
+       public Result<List<Data>> readChildren(AuthzTrans trans, final String ns, final String name) {\r
+               // At this point, I'm thinking it's better not to try to cache "*" results\r
+               // Data probably won't be accurate, and adding it makes every update invalidate most of the cache\r
+               // 2/4/2014\r
+               return dao().readChildren(trans,ns,name);\r
+       }\r
+\r
+       public Result<Void> addPerm(AuthzTrans trans, RoleDAO.Data rd, PermDAO.Data perm) {\r
+               Result<Void> rv = dao().addPerm(trans,rd,perm);\r
+               if(trans.debug().isLoggable())\r
+                       trans.debug().log("Adding",perm,"to", rd, "with CachedRoleDAO.addPerm");\r
+               invalidate(trans, rd);\r
+               return rv;\r
+       }\r
+\r
+       public Result<Void> delPerm(AuthzTrans trans, RoleDAO.Data rd, PermDAO.Data perm) {\r
+               Result<Void> rv = dao().delPerm(trans,rd,perm);\r
+               if(trans.debug().isLoggable())\r
+                       trans.debug().log("Removing",perm,"from", rd, "with CachedRoleDAO.addPerm");\r
+               invalidate(trans, rd);\r
+               return rv;\r
+       }\r
+       \r
+       /**\r
+        * Add description to this role\r
+        * \r
+        * @param trans\r
+        * @param ns\r
+        * @param name\r
+        * @param description\r
+        * @return\r
+        */\r
+       public Result<Void> addDescription(AuthzTrans trans, String ns, String name, String description) {\r
+               //TODO Invalidate?\r
+               return dao().addDescription(trans, ns, name, description);\r
+\r
+       }\r
+\r
+}\r