AT&T 2.0.19 Code drop, stage 3
[aaf/authz.git] / auth / auth-cass / src / main / java / org / onap / aaf / auth / dao / cached / CachedCredDAO.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.CredDAO;
29 import org.onap.aaf.auth.dao.cass.Status;
30 import org.onap.aaf.auth.env.AuthzTrans;
31 import org.onap.aaf.auth.layer.Result;
32
33 public class CachedCredDAO extends CachedDAO<AuthzTrans, CredDAO, CredDAO.Data> {
34         public CachedCredDAO(CredDAO dao, CIDAO<AuthzTrans> info, long expiresIn) {
35                 super(dao, info, CredDAO.CACHE_SEG, expiresIn);
36         }
37         
38         /**
39          * Pass through Cred Lookup
40          * 
41          * Unlike Role and Perm, we don't need or want to cache these elements... Only used for NS Delete.
42          * 
43          * @param trans
44          * @param ns
45          * @return
46          */
47         public Result<List<CredDAO.Data>> readNS(AuthzTrans trans, final String ns) {
48                 
49                 return dao().readNS(trans, ns);
50         }
51         
52         public Result<List<CredDAO.Data>> readID(AuthzTrans trans, final String id) {
53                 DAOGetter getter = new DAOGetter(trans,dao()) {
54                         public Result<List<CredDAO.Data>> call() {
55                                 return dao().readID(trans, id);
56                         }
57                 };
58                 
59                 Result<List<CredDAO.Data>> lurd = get(trans, id, getter);
60                 if(lurd.isOK() && lurd.isEmpty()) {
61                         return Result.err(Status.ERR_UserNotFound,"No User Cred found");
62                 }
63                 return lurd;
64         }
65
66 }