1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.cmd.user;
\r
25 import java.text.ParseException;
\r
26 import java.util.Date;
\r
28 import org.onap.aaf.cmd.AAFcli;
\r
29 import org.onap.aaf.cmd.BaseCmd;
\r
30 import org.onap.aaf.cmd.Param;
\r
31 import org.onap.aaf.cssa.rserv.HttpMethods;
\r
33 import org.onap.aaf.cadi.CadiException;
\r
34 import org.onap.aaf.cadi.LocatorException;
\r
35 import org.onap.aaf.cadi.client.Future;
\r
36 import org.onap.aaf.cadi.client.Rcli;
\r
37 import org.onap.aaf.cadi.client.Retryable;
\r
38 import org.onap.aaf.inno.env.APIException;
\r
39 import org.onap.aaf.inno.env.util.Chrono;
\r
40 import org.onap.aaf.rosetta.env.RosettaDF;
\r
42 import aaf.v2_0.DelgRequest;
\r
44 public class Delg extends BaseCmd<User> {
\r
45 static final String AUTHZ_DELG = "/authz/delegate";
\r
46 private final static String[] options = {"add","upd","del"};
\r
48 public Delg(User user) throws APIException {
\r
49 super(user,"delegate",
\r
50 new Param(optionsToString(options),true),
\r
51 new Param("from",true),
\r
52 new Param("to REQ A&U",false),
\r
53 new Param("until (YYYY-MM-DD) REQ A", false)
\r
58 public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException {
\r
59 return same(new Retryable<Integer>() {
\r
61 public Integer code(Rcli<?> client) throws CadiException, APIException {
\r
63 String realm = getOrgRealm();
\r
64 DelgRequest dr = new DelgRequest();
\r
67 int option= whichOption(options, args[idx++]);
\r
68 String user = args[idx++];
\r
69 if (user.indexOf('@') < 0 && realm != null) user += '@' + realm;
\r
72 String delegate = args[idx++];
\r
73 if (delegate.indexOf('@') < 0 && realm != null) delegate += '@' + realm;
\r
74 dr.setDelegate(delegate);
\r
75 if(option<2 && args.length>idx) {
\r
78 date = Chrono.dateOnlyFmt.parse(args[idx++]);
\r
79 } catch (ParseException e) {
\r
80 throw new CadiException(e);
\r
82 dr.setEnd(Chrono.timeStamp(date));
\r
86 Future<DelgRequest> fp;
\r
87 RosettaDF<DelgRequest> df = getDF(DelgRequest.class);
\r
89 setQueryParamsOn(client);
\r
93 fp = client.create(AUTHZ_DELG, df, dr);
\r
97 fp = client.update(AUTHZ_DELG, df, dr);
\r
101 fp = client.delete(AUTHZ_DELG, df, dr);
\r
105 throw new CadiException("Bad Argument");
\r
108 if(fp.get(AAFcli.timeout())) {
\r
109 pw().append("Delegate ");
\r
110 pw().println(verb);
\r
120 public void detailedHelp(int _indent, StringBuilder sb) {
\r
121 int indent = _indent;
\r
122 detailLine(sb,indent,"Add, Update or Delete Delegate");
\r
124 detailLine(sb,indent,"A Delegate is a person who will temporarily cover the Approval and");
\r
125 detailLine(sb,indent,"Ownership questions on behalf of the person Responsible.");
\r
127 detailLine(sb,indent,"fromID - the person who is the Responsible person of record");
\r
128 detailLine(sb,indent,"toID - the person who will be delegated (required for Add/Update)");
\r
129 detailLine(sb,indent,"until - the end date for this delegation");
\r
131 api(sb,indent,HttpMethods.POST,AUTHZ_DELG,DelgRequest.class,true);
\r
132 api(sb,indent,HttpMethods.DELETE,AUTHZ_DELG,DelgRequest.class,false);
\r
133 api(sb,indent,HttpMethods.PUT,AUTHZ_DELG,DelgRequest.class,false);
\r