AT&T 2.0.19 Code drop, stage 3
[aaf/authz.git] / auth / auth-cmd / src / main / java / org / onap / aaf / auth / cmd / user / ListApprovals.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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====================================================
19  *
20  */
21
22 package org.onap.aaf.auth.cmd.user;
23
24 import org.onap.aaf.auth.cmd.AAFcli;
25 import org.onap.aaf.auth.cmd.Cmd;
26 import org.onap.aaf.auth.cmd.Param;
27 import org.onap.aaf.auth.rserv.HttpMethods;
28 import org.onap.aaf.cadi.CadiException;
29 import org.onap.aaf.cadi.LocatorException;
30 import org.onap.aaf.cadi.client.Future;
31 import org.onap.aaf.cadi.client.Rcli;
32 import org.onap.aaf.cadi.client.Retryable;
33 import org.onap.aaf.misc.env.APIException;
34
35 import aaf.v2_0.Approvals;
36
37 /**
38  * 
39  * @author Jonathan
40  *
41  */
42 public class ListApprovals extends Cmd {
43         private static final String HEADER = "List Approvals"; 
44         private final static String[] options = {"user","approver","ticket"};
45         public ListApprovals(List parent) {
46                 super(parent,"approvals", 
47                                 new Param(optionsToString(options),true),
48                                 new Param("value",true)); 
49         }
50
51         @Override
52         public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException {
53                 int idx = _idx;
54                 final String type = args[idx++];
55                 int option = whichOption(options,type);
56                 String value = args[idx++];
57                 final String fullValue;
58                 if (option != 2) {
59                         fullValue = fullID(value);
60                 } else {
61                     fullValue = value;
62                 }
63                 return same(new Retryable<Integer>() {
64                         @Override
65                         public Integer code(Rcli<?> client) throws CadiException, APIException {
66                                 Future<Approvals> fp = client.read(
67                                                 "/authz/approval/"+type+'/'+fullValue, 
68                                                 getDF(Approvals.class)
69                                                 );
70                                 if(fp.get(AAFcli.timeout())) {
71                                         ((List)parent).report(fp.value,HEADER + " by " + type,fullValue);
72                                         if(fp.code()==404) {
73                                             return 200;
74                                         }
75                                 } else {
76                                         error(fp);
77                                 }
78                                 return fp.code();
79                         }
80                 });
81         }
82
83         @Override
84         public void detailedHelp(int _indent, StringBuilder sb) {
85                 int indent = _indent;
86                 detailLine(sb,indent,HEADER);
87                 indent+=2;
88                 detailLine(sb,indent,"Approvals are used when the Requestor does not have the rights");
89                 detailLine(sb,indent,"to perform the action required.  Approvers are those listed as");
90                 detailLine(sb,indent,"responsible for Namespace associated with the request, and those");
91                 detailLine(sb,indent,"required by the Company by Policy.  This may be, for instance");
92                 detailLine(sb,indent,"the supervisor of the requestor");
93                 sb.append('\n');
94                 detailLine(sb,indent,"Delegates can be listed by User, Approver or Ticket.");
95                 indent-=2;
96                 api(sb,indent,HttpMethods.GET,"authz/approval/user/<value>",Approvals.class,true);
97                 api(sb,indent,HttpMethods.GET,"authz/approval/approver/<value>",Approvals.class,false);
98                 api(sb,indent,HttpMethods.GET,"authz/approval/ticket/<value>",Approvals.class,false);
99         }
100
101
102 }