1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\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
11 * * http://www.apache.org/licenses/LICENSE-2.0
\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
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.dao.aaf.cached;
\r
25 import java.util.List;
\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
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
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
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
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
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
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
73 return dao().readChildren(trans,ns,name);
\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
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
93 * Add description to this role
\r
98 * @param description
\r
101 public Result<Void> addDescription(AuthzTrans trans, String ns, String name, String description) {
\r
103 return dao().addDescription(trans, ns, name, description);
\r