Add the "@Override" annotation above this method signature - SonarFix
[aaf/authz.git] / auth / auth-cass / src / main / java / org / onap / aaf / auth / dao / cached / CachedPermDAO.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21
22 package org.onap.aaf.auth.dao.cached;
23
24 import java.util.List;
25
26 import org.onap.aaf.auth.dao.CIDAO;
27 import org.onap.aaf.auth.dao.CachedDAO;
28 import org.onap.aaf.auth.dao.cass.PermDAO;
29 import org.onap.aaf.auth.dao.cass.RoleDAO;
30 import org.onap.aaf.auth.dao.cass.Status;
31 import org.onap.aaf.auth.dao.cass.PermDAO.Data;
32 import org.onap.aaf.auth.env.AuthzTrans;
33 import org.onap.aaf.auth.layer.Result;
34
35 public class CachedPermDAO extends CachedDAO<AuthzTrans,PermDAO, PermDAO.Data> {
36
37     public CachedPermDAO(PermDAO dao, CIDAO<AuthzTrans> info, long expiresIn) {
38         super(dao, info, PermDAO.CACHE_SEG, expiresIn);
39     }
40
41     public Result<List<Data>> readNS(AuthzTrans trans, final String ns) {
42         DAOGetter getter = new DAOGetter(trans,dao()) {
43         @Override
44             public Result<List<Data>> call() {
45                 return dao.readNS(trans, ns);
46             }
47         };
48
49         Result<List<Data>> lurd = get(trans, ns, getter);
50         if (lurd.isOKhasData()) {
51             return lurd;
52         } else {
53
54         }
55         return Result.err(Status.ERR_PermissionNotFound,"No Permission found - " + lurd.details);
56     }
57
58     public Result<List<Data>> readChildren(AuthzTrans trans, final String ns, final String type) {
59         return dao().readChildren(trans,ns,type);
60     }
61
62     /**
63      *
64      * @param trans
65      * @param ns
66      * @param type
67      * @return
68      */
69     public Result<List<Data>> readByType(AuthzTrans trans, final String ns, final String type) {
70         DAOGetter getter = new DAOGetter(trans,dao()) {
71         @Override
72             public Result<List<Data>> call() {
73                 return dao.readByType(trans, ns, type);
74             }
75         };
76
77         // Note: Can reuse index1 here, because there is no name collision versus response
78         Result<List<Data>> lurd = get(trans, ns+'|'+type, getter);
79         if (lurd.isOK() && lurd.isEmpty()) {
80             return Result.err(Status.ERR_PermissionNotFound,"No Permission found");
81         }
82         return lurd;
83     }
84
85     /**
86      * Add desciption to this permission
87      *
88      * @param trans
89      * @param ns
90      * @param type
91      * @param instance
92      * @param action
93      * @param description
94      * @return
95      */
96     public Result<Void> addDescription(AuthzTrans trans, String ns, String type,
97             String instance, String action, String description) {
98         //TODO Invalidate?
99         return dao().addDescription(trans, ns, type, instance, action, description);
100     }
101
102     public Result<Void> addRole(AuthzTrans trans, PermDAO.Data perm, RoleDAO.Data role) {
103         Result<Void> rv = dao().addRole(trans,perm,role.encode());
104         if (trans.debug().isLoggable())
105             trans.debug().log("Adding",role.encode(),"to", perm, "with CachedPermDAO.addRole");
106         invalidate(trans,perm);
107         return rv;
108     }
109
110     public Result<Void> delRole(AuthzTrans trans, Data perm, RoleDAO.Data role) {
111         Result<Void> rv = dao().delRole(trans,perm,role.encode());
112         if (trans.debug().isLoggable())
113             trans.debug().log("Removing",role.encode(),"from", perm, "with CachedPermDAO.delRole");
114         invalidate(trans,perm);
115         return rv;
116     }
117
118
119 }