[AAF-21] Updated Copyright Headers for AAF
[aaf/authz.git] / authz-cmd / src / main / java / com / att / cmd / perm / Describe.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aaf\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
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \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
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package com.att.cmd.perm;\r
24 \r
25 import com.att.cadi.CadiException;\r
26 import com.att.cadi.LocatorException;\r
27 import com.att.cadi.client.Future;\r
28 import com.att.cadi.client.Rcli;\r
29 import com.att.cadi.client.Retryable;\r
30 import com.att.cmd.AAFcli;\r
31 import com.att.cmd.Cmd;\r
32 import com.att.cmd.Param;\r
33 import com.att.cssa.rserv.HttpMethods;\r
34 import com.att.inno.env.APIException;\r
35 \r
36 import aaf.v2_0.PermRequest;\r
37 \r
38 public class Describe extends Cmd {\r
39         private static final String PERM_PATH = "/authz/perm";\r
40         public Describe(Perm parent) {\r
41                 super(parent,"describe", \r
42                                 new Param("type",true),\r
43                                 new Param("instance", true),\r
44                                 new Param("action", true),\r
45                                 new Param("description",true)); \r
46         }\r
47 \r
48         @Override\r
49         public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException {\r
50                 return same(new Retryable<Integer>() {\r
51                         @Override\r
52                         public Integer code(Rcli<?> client) throws CadiException, APIException {\r
53                                 int idx = index;\r
54                                 String type = args[idx++];\r
55                                 String instance = args[idx++];\r
56                                 String action = args[idx++];\r
57                                 StringBuilder desc = new StringBuilder();\r
58                                 while (idx < args.length) {\r
59                                         desc.append(args[idx++] + ' ');\r
60                                 }\r
61                 \r
62                                 PermRequest pr = new PermRequest();\r
63                                 pr.setType(type);\r
64                                 pr.setInstance(instance);\r
65                                 pr.setAction(action);\r
66                                 pr.setDescription(desc.toString());\r
67                 \r
68                                 // Set Start/End commands\r
69                                 setStartEnd(pr);\r
70                                 \r
71                                 Future<PermRequest> fp = null;\r
72                                 int rv;\r
73 \r
74                                 fp = client.update(\r
75                                         PERM_PATH,\r
76                                         getDF(PermRequest.class),\r
77                                         pr\r
78                                         );\r
79 \r
80                                 if(fp.get(AAFcli.timeout())) {\r
81                                         rv=fp.code();\r
82                                         pw().println("Description added to Permission");\r
83                                 } else {\r
84                                         if((rv=fp.code())==202) {\r
85                                                 pw().print("Adding description");\r
86                                                 pw().println(" Accepted, but requires Approvals before actualizing");\r
87                                         } else {\r
88                                                 error(fp);\r
89                                         }\r
90                                 }\r
91                                 return rv;\r
92                         }\r
93                 });\r
94         }\r
95 \r
96         @Override\r
97         public void detailedHelp(int indent, StringBuilder sb) {\r
98                 detailLine(sb,indent,"Add a description to a permission");\r
99                 api(sb,indent,HttpMethods.PUT,"authz/perm",PermRequest.class,true);\r
100         }\r
101 }\r