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 com.att.cmd.user;
\r
25 import java.text.ParseException;
\r
26 import java.util.Date;
\r
28 import com.att.cadi.CadiException;
\r
29 import com.att.cadi.LocatorException;
\r
30 import com.att.cadi.client.Future;
\r
31 import com.att.cadi.client.Rcli;
\r
32 import com.att.cadi.client.Retryable;
\r
33 import com.att.cmd.AAFcli;
\r
34 import com.att.cmd.BaseCmd;
\r
35 import com.att.cmd.Param;
\r
36 import com.att.cssa.rserv.HttpMethods;
\r
37 import com.att.inno.env.APIException;
\r
38 import com.att.inno.env.util.Chrono;
\r
39 import com.att.rosetta.env.RosettaDF;
\r
41 import aaf.v2_0.DelgRequest;
\r
43 public class Delg extends BaseCmd<User> {
\r
44 static final String AUTHZ_DELG = "/authz/delegate";
\r
45 private final static String[] options = {"add","upd","del"};
\r
47 public Delg(User user) throws APIException {
\r
48 super(user,"delegate",
\r
49 new Param(optionsToString(options),true),
\r
50 new Param("from",true),
\r
51 new Param("to REQ A&U",false),
\r
52 new Param("until (YYYY-MM-DD) REQ A", false)
\r
57 public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException {
\r
58 return same(new Retryable<Integer>() {
\r
60 public Integer code(Rcli<?> client) throws CadiException, APIException {
\r
62 String realm = getOrgRealm();
\r
63 DelgRequest dr = new DelgRequest();
\r
66 int option= whichOption(options, args[idx++]);
\r
67 String user = args[idx++];
\r
68 if (user.indexOf('@') < 0 && realm != null) user += '@' + realm;
\r
71 String delegate = args[idx++];
\r
72 if (delegate.indexOf('@') < 0 && realm != null) delegate += '@' + realm;
\r
73 dr.setDelegate(delegate);
\r
74 if(option<2 && args.length>idx) {
\r
77 date = Chrono.dateOnlyFmt.parse(args[idx++]);
\r
78 } catch (ParseException e) {
\r
79 throw new CadiException(e);
\r
81 dr.setEnd(Chrono.timeStamp(date));
\r
85 Future<DelgRequest> fp;
\r
86 RosettaDF<DelgRequest> df = getDF(DelgRequest.class);
\r
88 setQueryParamsOn(client);
\r
92 fp = client.create(AUTHZ_DELG, df, dr);
\r
96 fp = client.update(AUTHZ_DELG, df, dr);
\r
100 fp = client.delete(AUTHZ_DELG, df, dr);
\r
104 throw new CadiException("Bad Argument");
\r
107 if(fp.get(AAFcli.timeout())) {
\r
108 pw().append("Delegate ");
\r
109 pw().println(verb);
\r
119 public void detailedHelp(int _indent, StringBuilder sb) {
\r
120 int indent = _indent;
\r
121 detailLine(sb,indent,"Add, Update or Delete Delegate");
\r
123 detailLine(sb,indent,"A Delegate is a person who will temporarily cover the Approval and");
\r
124 detailLine(sb,indent,"Ownership questions on behalf of the person Responsible.");
\r
126 detailLine(sb,indent,"fromID - the person who is the Responsible person of record");
\r
127 detailLine(sb,indent,"toID - the person who will be delegated (required for Add/Update)");
\r
128 detailLine(sb,indent,"until - the end date for this delegation");
\r
130 api(sb,indent,HttpMethods.POST,AUTHZ_DELG,DelgRequest.class,true);
\r
131 api(sb,indent,HttpMethods.DELETE,AUTHZ_DELG,DelgRequest.class,false);
\r
132 api(sb,indent,HttpMethods.PUT,AUTHZ_DELG,DelgRequest.class,false);
\r