2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
7 * Modifications Copyright (C) 2018 IBM.
8 * ===========================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END====================================================
24 package org.onap.aaf.auth.cmd.user;
26 import java.text.ParseException;
27 import java.util.Date;
29 import org.onap.aaf.auth.cmd.AAFcli;
30 import org.onap.aaf.auth.cmd.BaseCmd;
31 import org.onap.aaf.auth.cmd.Param;
32 import org.onap.aaf.auth.rserv.HttpMethods;
33 import org.onap.aaf.cadi.CadiException;
34 import org.onap.aaf.cadi.LocatorException;
35 import org.onap.aaf.cadi.client.Future;
36 import org.onap.aaf.cadi.client.Rcli;
37 import org.onap.aaf.cadi.client.Retryable;
38 import org.onap.aaf.misc.env.APIException;
39 import org.onap.aaf.misc.env.util.Chrono;
40 import org.onap.aaf.misc.rosetta.env.RosettaDF;
42 import aaf.v2_0.DelgRequest;
44 public class Delg extends BaseCmd<User> {
45 static final String AUTHZ_DELG = "/authz/delegate";
46 private static final String[] options = {"add","upd","del"};
48 public Delg(User user) throws APIException {
49 super(user,"delegate",
50 new Param(optionsToString(options),true),
51 new Param("from",true),
52 new Param("to REQ A&U",false),
53 new Param("until (YYYY-MM-DD) REQ A", false)
58 public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException {
59 return same(new Retryable<Integer>() {
61 public Integer code(Rcli<?> client) throws CadiException, APIException {
63 DelgRequest dr = new DelgRequest();
66 int option= whichOption(options, args[idx++]);
67 String user = fullID(args[idx++]);
70 String delegate = fullID(args[idx++]);
71 dr.setDelegate(delegate);
72 if (option<2 && args.length>idx) {
75 date = Chrono.dateOnlyFmt.parse(args[idx++]);
76 } catch (ParseException e) {
77 throw new CadiException(e);
79 dr.setEnd(Chrono.timeStamp(date));
83 Future<DelgRequest> fp;
84 RosettaDF<DelgRequest> df = getDF(DelgRequest.class);
86 setQueryParamsOn(client);
90 fp = client.create(AUTHZ_DELG, df, dr);
94 fp = client.update(AUTHZ_DELG, df, dr);
98 fp = client.delete(AUTHZ_DELG, df, dr);
102 throw new CadiException("Bad Argument");
105 if (fp.get(AAFcli.timeout())) {
106 pw().append("Delegate ");
117 public void detailedHelp(int indentParam, StringBuilder sb) {
118 int indent = indentParam;
119 detailLine(sb,indent,"Add, Update or Delete Delegate");
121 detailLine(sb,indent,"A Delegate is a person who will temporarily cover the Approval and");
122 detailLine(sb,indent,"Ownership questions on behalf of the person Responsible.");
124 detailLine(sb,indent,"fromID - the person who is the Responsible person of record");
125 detailLine(sb,indent,"toID - the person who will be delegated (required for Add/Update)");
126 detailLine(sb,indent,"until - the end date for this delegation");
128 api(sb,indent,HttpMethods.POST,AUTHZ_DELG,DelgRequest.class,true);
129 api(sb,indent,HttpMethods.DELETE,AUTHZ_DELG,DelgRequest.class,false);
130 api(sb,indent,HttpMethods.PUT,AUTHZ_DELG,DelgRequest.class,false);