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.actions;
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.List;
28 import org.onap.aaf.auth.dao.cass.ApprovalDAO;
29 import org.onap.aaf.auth.dao.cass.UserRoleDAO;
30 import org.onap.aaf.auth.dao.cass.ApprovalDAO.Data;
31 import org.onap.aaf.auth.dao.hl.Function.FUTURE_OP;
32 import org.onap.aaf.auth.dao.hl.Function.Lookup;
33 import org.onap.aaf.auth.dao.hl.Function.OP_STATUS;
34 import org.onap.aaf.auth.env.AuthzTrans;
35 import org.onap.aaf.auth.helpers.Approval;
36 import org.onap.aaf.auth.helpers.Future;
37 import org.onap.aaf.auth.helpers.UserRole;
38 import org.onap.aaf.auth.layer.Result;
39 import org.onap.aaf.misc.env.APIException;
41 import com.datastax.driver.core.Cluster;
43 public class URFutureApproveExec extends ActionDAO<List<Approval>, OP_STATUS, Future> {
45 public URFutureApproveExec(AuthzTrans trans, Cluster cluster, boolean dryRun) throws APIException, IOException {
46 super(trans,cluster, dryRun);
49 public URFutureApproveExec(AuthzTrans trans, ActionDAO<?,?,?> adao) {
54 public Result<OP_STATUS> exec(AuthzTrans trans, List<Approval> app, Future future) {
56 return Result.err(Result.ERR_ActionNotCompleted,"Not Executed");
59 final List<ApprovalDAO.Data> apprs = new ArrayList<>();
60 final List<UserRoleDAO.Data> urs = new ArrayList<>();
61 for(Approval a : app) {
63 UserRole ur = UserRole.get(a.add.user, future.role);
68 Result<OP_STATUS> rv = f.performFutureOp(trans, FUTURE_OP.A, future.fdd,
69 new Lookup<List<ApprovalDAO.Data>>() {
71 public List<Data> get(AuthzTrans trans, Object ... noop) {
75 new Lookup<UserRoleDAO.Data>() {
77 public UserRoleDAO.Data get(AuthzTrans trans, Object ... keys) {
78 List<UserRole> lur = UserRole.byUser.get(keys[0]);
80 for(UserRole ur : lur) {
81 if(ur.role().equals(keys[1])) {
92 trans.info().printf("Denied %s on %s", future.memo(),future.fdd.target);
95 trans.info().printf("Completed %s on %s", future.memo(),future.fdd.target);
98 trans.info().printf("Future %s on %s has lapsed", future.memo(),future.fdd.target);
103 trans.error().log("Error completing",future.memo(),rv.errorString());