2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
22 package org.onap.aaf.auth.dao.cached;
24 import java.util.List;
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.RoleDAO.Data;
32 import org.onap.aaf.auth.env.AuthzTrans;
33 import org.onap.aaf.auth.layer.Result;
35 public class CachedRoleDAO extends CachedDAO<AuthzTrans,RoleDAO, RoleDAO.Data> {
36 public CachedRoleDAO(RoleDAO dao, CIDAO<AuthzTrans> info, long expiresIn) {
37 super(dao, info, RoleDAO.CACHE_SEG, expiresIn);
40 public Result<List<Data>> readNS(AuthzTrans trans, final String ns) {
41 DAOGetter getter = new DAOGetter(trans,dao()) {
42 public Result<List<Data>> call() {
43 return dao.readNS(trans, ns);
47 Result<List<Data>> lurd = get(trans, ns, getter);
48 if(lurd.isOK() && lurd.isEmpty()) {
49 return Result.err(Status.ERR_RoleNotFound,"No Role found");
54 public Result<List<Data>> readName(AuthzTrans trans, final String name) {
55 DAOGetter getter = new DAOGetter(trans,dao()) {
56 public Result<List<Data>> call() {
57 return dao().readName(trans, name);
61 Result<List<Data>> lurd = get(trans, name, getter);
62 if(lurd.isOK() && lurd.isEmpty()) {
63 return Result.err(Status.ERR_RoleNotFound,"No Role found");
68 public Result<List<Data>> readChildren(AuthzTrans trans, final String ns, final String name) {
69 // At this point, I'm thinking it's better not to try to cache "*" results
70 // Data probably won't be accurate, and adding it makes every update invalidate most of the cache
72 return dao().readChildren(trans,ns,name);
75 public Result<Void> addPerm(AuthzTrans trans, RoleDAO.Data rd, PermDAO.Data perm) {
76 Result<Void> rv = dao().addPerm(trans,rd,perm);
77 if(trans.debug().isLoggable())
78 trans.debug().log("Adding",perm,"to", rd, "with CachedRoleDAO.addPerm");
79 invalidate(trans, rd);
83 public Result<Void> delPerm(AuthzTrans trans, RoleDAO.Data rd, PermDAO.Data perm) {
84 Result<Void> rv = dao().delPerm(trans,rd,perm);
85 if(trans.debug().isLoggable())
86 trans.debug().log("Removing",perm,"from", rd, "with CachedRoleDAO.addPerm");
87 invalidate(trans, rd);
92 * Add description to this role
100 public Result<Void> addDescription(AuthzTrans trans, String ns, String name, String description) {
102 return dao().addDescription(trans, ns, name, description);