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.cmd.user;
24 import java.text.ParseException;
25 import java.util.Date;
27 import org.onap.aaf.auth.cmd.AAFcli;
28 import org.onap.aaf.auth.cmd.BaseCmd;
29 import org.onap.aaf.auth.cmd.Param;
30 import org.onap.aaf.auth.rserv.HttpMethods;
31 import org.onap.aaf.cadi.CadiException;
32 import org.onap.aaf.cadi.LocatorException;
33 import org.onap.aaf.cadi.client.Future;
34 import org.onap.aaf.cadi.client.Rcli;
35 import org.onap.aaf.cadi.client.Retryable;
36 import org.onap.aaf.misc.env.APIException;
37 import org.onap.aaf.misc.env.util.Chrono;
38 import org.onap.aaf.misc.rosetta.env.RosettaDF;
40 import aaf.v2_0.DelgRequest;
42 public class Delg extends BaseCmd<User> {
43 static final String AUTHZ_DELG = "/authz/delegate";
44 private final static String[] options = {"add","upd","del"};
46 public Delg(User user) throws APIException {
47 super(user,"delegate",
48 new Param(optionsToString(options),true),
49 new Param("from",true),
50 new Param("to REQ A&U",false),
51 new Param("until (YYYY-MM-DD) REQ A", false)
56 public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException {
57 return same(new Retryable<Integer>() {
59 public Integer code(Rcli<?> client) throws CadiException, APIException {
61 DelgRequest dr = new DelgRequest();
64 int option= whichOption(options, args[idx++]);
65 String user = fullID(args[idx++]);
68 String delegate = fullID(args[idx++]);
69 dr.setDelegate(delegate);
70 if(option<2 && args.length>idx) {
73 date = Chrono.dateOnlyFmt.parse(args[idx++]);
74 } catch (ParseException e) {
75 throw new CadiException(e);
77 dr.setEnd(Chrono.timeStamp(date));
81 Future<DelgRequest> fp;
82 RosettaDF<DelgRequest> df = getDF(DelgRequest.class);
84 setQueryParamsOn(client);
88 fp = client.create(AUTHZ_DELG, df, dr);
92 fp = client.update(AUTHZ_DELG, df, dr);
96 fp = client.delete(AUTHZ_DELG, df, dr);
100 throw new CadiException("Bad Argument");
103 if(fp.get(AAFcli.timeout())) {
104 pw().append("Delegate ");
115 public void detailedHelp(int _indent, StringBuilder sb) {
116 int indent = _indent;
117 detailLine(sb,indent,"Add, Update or Delete Delegate");
119 detailLine(sb,indent,"A Delegate is a person who will temporarily cover the Approval and");
120 detailLine(sb,indent,"Ownership questions on behalf of the person Responsible.");
122 detailLine(sb,indent,"fromID - the person who is the Responsible person of record");
123 detailLine(sb,indent,"toID - the person who will be delegated (required for Add/Update)");
124 detailLine(sb,indent,"until - the end date for this delegation");
126 api(sb,indent,HttpMethods.POST,AUTHZ_DELG,DelgRequest.class,true);
127 api(sb,indent,HttpMethods.DELETE,AUTHZ_DELG,DelgRequest.class,false);
128 api(sb,indent,HttpMethods.PUT,AUTHZ_DELG,DelgRequest.class,false);