788efbe8dd045d96bcfbf31db85b0b0c575e714b
[aaf/authz.git] / authz-cass / src / main / java / org / onap / aaf / dao / aaf / cached / CachedRoleDAO.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aaf\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * ===========================================================================\r
7  * * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * * you may not use this file except in compliance with the License.\r
9  * * You may obtain a copy of the License at\r
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \r
13  *  * Unless required by applicable law or agreed to in writing, software\r
14  * * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * * See the License for the specific language governing permissions and\r
17  * * limitations under the License.\r
18  * * ============LICENSE_END====================================================\r
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package org.onap.aaf.dao.aaf.cached;\r
24 \r
25 import java.util.List;\r
26 \r
27 import org.onap.aaf.authz.env.AuthzTrans;\r
28 import org.onap.aaf.authz.layer.Result;\r
29 import org.onap.aaf.dao.CIDAO;\r
30 import org.onap.aaf.dao.CachedDAO;\r
31 import org.onap.aaf.dao.aaf.cass.PermDAO;\r
32 import org.onap.aaf.dao.aaf.cass.RoleDAO;\r
33 import org.onap.aaf.dao.aaf.cass.Status;\r
34 import org.onap.aaf.dao.aaf.cass.RoleDAO.Data;\r
35 \r
36 public class CachedRoleDAO extends CachedDAO<AuthzTrans,RoleDAO, RoleDAO.Data> {\r
37         public CachedRoleDAO(RoleDAO dao, CIDAO<AuthzTrans> info) {\r
38                 super(dao, info, RoleDAO.CACHE_SEG);\r
39         }\r
40 \r
41         public Result<List<Data>> readNS(AuthzTrans trans, final String ns) {\r
42                 DAOGetter getter = new DAOGetter(trans,dao()) {\r
43                         public Result<List<Data>> call() {\r
44                                 return dao.readNS(trans, ns);\r
45                         }\r
46                 };\r
47                 \r
48                 Result<List<Data>> lurd = get(trans, ns, getter);\r
49                 if(lurd.isOK() && lurd.isEmpty()) {\r
50                         return Result.err(Status.ERR_RoleNotFound,"No Role found");\r
51                 }\r
52                 return lurd;\r
53         }\r
54 \r
55         public Result<List<Data>> readName(AuthzTrans trans, final String name) {\r
56                 DAOGetter getter = new DAOGetter(trans,dao()) {\r
57                         public Result<List<Data>> call() {\r
58                                 return dao().readName(trans, name);\r
59                         }\r
60                 };\r
61                 \r
62                 Result<List<Data>> lurd = get(trans, name, getter);\r
63                 if(lurd.isOK() && lurd.isEmpty()) {\r
64                         return Result.err(Status.ERR_RoleNotFound,"No Role found");\r
65                 }\r
66                 return lurd;\r
67         }\r
68 \r
69         public Result<List<Data>> readChildren(AuthzTrans trans, final String ns, final String name) {\r
70                 // At this point, I'm thinking it's better not to try to cache "*" results\r
71                 // Data probably won't be accurate, and adding it makes every update invalidate most of the cache\r
72                 // 2/4/2014\r
73                 return dao().readChildren(trans,ns,name);\r
74         }\r
75 \r
76         public Result<Void> addPerm(AuthzTrans trans, RoleDAO.Data rd, PermDAO.Data perm) {\r
77                 Result<Void> rv = dao().addPerm(trans,rd,perm);\r
78                 if(trans.debug().isLoggable())\r
79                         trans.debug().log("Adding",perm,"to", rd, "with CachedRoleDAO.addPerm");\r
80                 invalidate(trans, rd);\r
81                 return rv;\r
82         }\r
83 \r
84         public Result<Void> delPerm(AuthzTrans trans, RoleDAO.Data rd, PermDAO.Data perm) {\r
85                 Result<Void> rv = dao().delPerm(trans,rd,perm);\r
86                 if(trans.debug().isLoggable())\r
87                         trans.debug().log("Removing",perm,"from", rd, "with CachedRoleDAO.addPerm");\r
88                 invalidate(trans, rd);\r
89                 return rv;\r
90         }\r
91         \r
92         /**\r
93          * Add description to this role\r
94          * \r
95          * @param trans\r
96          * @param ns\r
97          * @param name\r
98          * @param description\r
99          * @return\r
100          */\r
101         public Result<Void> addDescription(AuthzTrans trans, String ns, String name, String description) {\r
102                 //TODO Invalidate?\r
103                 return dao().addDescription(trans, ns, name, description);\r
104 \r
105         }\r
106 \r
107 }\r