Update Fixes from testing
[aaf/authz.git] / auth / auth-cmd / src / main / java / org / onap / aaf / auth / cmd / role / ListByPerm.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2018 IBM.
7  * ===========================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END====================================================
20  *
21  */
22
23 package org.onap.aaf.auth.cmd.role;
24
25 import java.io.UnsupportedEncodingException;
26 import java.net.URLEncoder;
27
28 import org.onap.aaf.auth.cmd.Cmd;
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.config.Config;
36 import org.onap.aaf.misc.env.APIException;
37
38 import aaf.v2_0.Roles;
39
40 /**
41  * Return Roles by NS
42  * 
43  * @author Jonathan
44  *
45  */
46 public class ListByPerm extends Cmd {
47     private static final String HEADER = "List Roles by Perm ";
48     
49     public ListByPerm(List parent) {
50         super(parent,"perm", 
51                 new Param("type",true),
52                 new Param("instance", true),
53                 new Param("action", true)); 
54     }
55
56     @Override
57     public int _exec(int idx0, final String ... args) throws CadiException, APIException, LocatorException {
58         int idx = idx0;
59         final String type=args[idx];
60         final String instance=args[++idx];
61         final String action = args[++idx];
62         
63         return same(((List)parent).new ListRoles() {
64             @Override
65             public Integer code(Rcli<?> client) throws CadiException, APIException {
66                 try {
67                     Future<Roles> fp = client.read(
68                             "/authz/roles/perm/"+type+'/' + 
69                                 URLEncoder.encode(instance,Config.UTF_8)+'/'+
70                                 action, 
71                             getDF(Roles.class)
72                             );
73                     return list(fp,client, HEADER+type+'|'+instance+'|'+action);
74                 } catch (UnsupportedEncodingException e) {
75                     throw new CadiException(e);
76                 }
77             }
78         });
79     }
80     
81     @Override
82     public void detailedHelp(int indent, StringBuilder sb) {
83         detailLine(sb,indent,HEADER);
84         api(sb,indent,HttpMethods.GET,"authz/roles/user/<user>",Roles.class,true);
85     }
86
87
88 }