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()) {
43 public Result<List<Data>> call() {
44 return dao.readNS(trans, ns);
48 Result<List<Data>> lurd = get(trans, ns, getter);
49 if (lurd.isOK() && lurd.isEmpty()) {
50 return Result.err(Status.ERR_RoleNotFound,"No Role found");
55 public Result<List<Data>> readName(AuthzTrans trans, final String name) {
56 DAOGetter getter = new DAOGetter(trans,dao()) {
58 public Result<List<Data>> call() {
59 return dao().readName(trans, name);
63 Result<List<Data>> lurd = get(trans, name, getter);
64 if (lurd.isOK() && lurd.isEmpty()) {
65 return Result.err(Status.ERR_RoleNotFound,"No Role found");
70 public Result<List<Data>> readChildren(AuthzTrans trans, final String ns, final String name) {
71 // At this point, I'm thinking it's better not to try to cache "*" results
72 // Data probably won't be accurate, and adding it makes every update invalidate most of the cache
74 return dao().readChildren(trans,ns,name);
77 public Result<Void> addPerm(AuthzTrans trans, RoleDAO.Data rd, PermDAO.Data perm) {
78 Result<Void> rv = dao().addPerm(trans,rd,perm);
79 if (trans.debug().isLoggable())
80 trans.debug().log("Adding",perm,"to", rd, "with CachedRoleDAO.addPerm");
81 invalidate(trans, rd);
85 public Result<Void> delPerm(AuthzTrans trans, RoleDAO.Data rd, PermDAO.Data perm) {
86 Result<Void> rv = dao().delPerm(trans,rd,perm);
87 if (trans.debug().isLoggable())
88 trans.debug().log("Removing",perm,"from", rd, "with CachedRoleDAO.addPerm");
89 invalidate(trans, rd);
94 * Add description to this role
102 public Result<Void> addDescription(AuthzTrans trans, String ns, String name, String description) {
104 return dao().addDescription(trans, ns, name, description);