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.batch.actions;
24 import java.io.IOException;
25 import java.util.Date;
26 import java.util.GregorianCalendar;
28 import org.onap.aaf.auth.batch.helpers.Approval;
29 import org.onap.aaf.auth.batch.helpers.UserRole;
30 import org.onap.aaf.auth.dao.cass.FutureDAO;
31 import org.onap.aaf.auth.dao.cass.NsDAO;
32 import org.onap.aaf.auth.dao.hl.Function;
33 import org.onap.aaf.auth.dao.hl.Question;
34 import org.onap.aaf.auth.dao.hl.Function.FUTURE_OP;
35 import org.onap.aaf.auth.env.AuthzTrans;
36 import org.onap.aaf.auth.layer.Result;
37 import org.onap.aaf.auth.org.Organization.Expiration;
38 import org.onap.aaf.misc.env.APIException;
39 import org.onap.aaf.misc.env.util.Chrono;
41 import com.datastax.driver.core.Cluster;
43 public class URFutureApprove extends ActionDAO<UserRole, String,String> implements Action<UserRole,String,String>, Key<UserRole> {
44 private final Date start;
45 private final Date expires;
47 public URFutureApprove(AuthzTrans trans, Cluster cluster, boolean dryRun) throws APIException, IOException {
48 super(trans,cluster, dryRun);
49 GregorianCalendar gc = new GregorianCalendar();
51 expires = trans.org().expiration(gc, Expiration.Future).getTime();
54 public URFutureApprove(AuthzTrans trans, ActionDAO<?,?,?> adao) {
56 GregorianCalendar gc = new GregorianCalendar();
58 expires = trans.org().expiration(gc, Expiration.Future).getTime();
62 public Result<String> exec(AuthzTrans trans, UserRole ur,String text) {
64 return Result.ok(text);
66 Result<NsDAO.Data> rns = q.deriveNs(trans, ur.ns());
69 FutureDAO.Data data = new FutureDAO.Data();
70 data.id=null; // let Create function assign UUID
71 data.target=Function.FOP_USER_ROLE;
75 data.expires = ur.expires();
77 data.construct = ur.urdd().bytify();
78 } catch (IOException e) {
81 Result<String> rfuture = f.createFuture(trans, data, Function.FOP_USER_ROLE, ur.user(), rns.value, FUTURE_OP.A);
83 trans.info().log(rfuture.value, text, ur.user(), data.memo);
85 trans.error().log(rfuture.details, text);
89 return Result.err(rns);
95 public String key(UserRole ur) {
97 if (expires.before(start)) {
98 expire = "' - EXPIRED ";
100 expire = "' - expiring ";
103 if (Question.OWNER.equals(ur.rname())) {
104 return Approval.RE_VALIDATE_OWNER + ur.ns() + expire + Chrono.dateOnlyStamp(ur.expires());
105 } else if (Question.ADMIN.equals(ur.rname())) {
106 return Approval.RE_VALIDATE_ADMIN + ur.ns() + expire + Chrono.dateOnlyStamp(ur.expires());
108 return Approval.RE_APPROVAL_IN_ROLE + ur.role() + expire + Chrono.dateOnlyStamp(ur.expires());