Update project structure to org.onap.aaf
[aaf/authz.git] / authz-cass / src / main / java / org / onap / aaf / dao / aaf / cached / CachedCredDAO.java
diff --git a/authz-cass/src/main/java/org/onap/aaf/dao/aaf/cached/CachedCredDAO.java b/authz-cass/src/main/java/org/onap/aaf/dao/aaf/cached/CachedCredDAO.java
new file mode 100644 (file)
index 0000000..1467503
--- /dev/null
@@ -0,0 +1,67 @@
+/*******************************************************************************\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.CredDAO;\r
+import org.onap.aaf.dao.aaf.cass.Status;\r
+\r
+public class CachedCredDAO extends CachedDAO<AuthzTrans, CredDAO, CredDAO.Data> {\r
+       public CachedCredDAO(CredDAO dao, CIDAO<AuthzTrans> info) {\r
+               super(dao, info, CredDAO.CACHE_SEG);\r
+       }\r
+       \r
+       /**\r
+        * Pass through Cred Lookup\r
+        * \r
+        * Unlike Role and Perm, we don't need or want to cache these elements... Only used for NS Delete.\r
+        * \r
+        * @param trans\r
+        * @param ns\r
+        * @return\r
+        */\r
+       public Result<List<CredDAO.Data>> readNS(AuthzTrans trans, final String ns) {\r
+               \r
+               return dao().readNS(trans, ns);\r
+       }\r
+       \r
+       public Result<List<CredDAO.Data>> readID(AuthzTrans trans, final String id) {\r
+               DAOGetter getter = new DAOGetter(trans,dao()) {\r
+                       public Result<List<CredDAO.Data>> call() {\r
+                               return dao().readID(trans, id);\r
+                       }\r
+               };\r
+               \r
+               Result<List<CredDAO.Data>> lurd = get(trans, id, getter);\r
+               if(lurd.isOK() && lurd.isEmpty()) {\r
+                       return Result.err(Status.ERR_UserNotFound,"No User Cred found");\r
+               }\r
+               return lurd;\r
+       }\r
+\r
+}\r