[AAF-21] Initial code import
[aaf/authz.git] / authz-cmd / src / main / java / com / att / cmd / ns / Delete.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aai\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * Copyright © 2017 Amdocs\r
7  * * ===========================================================================\r
8  * * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * * you may not use this file except in compliance with the License.\r
10  * * You may obtain a copy of the License at\r
11  * * \r
12  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
13  * * \r
14  *  * Unless required by applicable law or agreed to in writing, software\r
15  * * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * * See the License for the specific language governing permissions and\r
18  * * limitations under the License.\r
19  * * ============LICENSE_END====================================================\r
20  * *\r
21  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
22  * *\r
23  ******************************************************************************/\r
24 package com.att.cmd.ns;\r
25 \r
26 import com.att.cadi.CadiException;\r
27 import com.att.cadi.LocatorException;\r
28 import com.att.cadi.client.Future;\r
29 import com.att.cadi.client.Rcli;\r
30 import com.att.cadi.client.Retryable;\r
31 import com.att.cmd.AAFcli;\r
32 import com.att.cmd.Cmd;\r
33 import com.att.cmd.Param;\r
34 import com.att.cssa.rserv.HttpMethods;\r
35 import com.att.inno.env.APIException;\r
36 \r
37 /**\r
38  * p\r
39  *\r
40  */\r
41 public class Delete extends Cmd {\r
42         public Delete(NS parent) {\r
43                 super(parent,"delete", \r
44                                 new Param("name",true)); \r
45         }\r
46 \r
47         @Override\r
48         public int _exec(final int idx, final String ... args) throws CadiException, APIException, LocatorException {\r
49                 return same(new Retryable<Integer>() {\r
50                         @Override\r
51                         public Integer code(Rcli<?> client) throws CadiException, APIException {\r
52                                 int index = idx;\r
53                                 StringBuilder path = new StringBuilder("/authz/ns/");\r
54                                 path.append(args[index++]);\r
55                                 \r
56                                 // Send "Force" if set\r
57                                 setQueryParamsOn(client);\r
58                                 Future<Void> fp = client.delete(path.toString(),Void.class);\r
59                                 \r
60                                 if(fp.get(AAFcli.timeout())) {\r
61                                         pw().println("Deleted Namespace");\r
62                                 } else {\r
63                                         error(fp);\r
64                                 }\r
65                                 return fp.code();\r
66                         }\r
67                 });\r
68         }\r
69 \r
70         @Override\r
71         public void detailedHelp(int _indent, StringBuilder sb) {\r
72                 int indent = _indent;\r
73                 detailLine(sb,indent,"Delete a Namespace");\r
74                 indent+=4;\r
75                 detailLine(sb,indent,"Namespaces cannot normally be deleted when there are still credentials,");\r
76                 detailLine(sb,indent,"permissions or roles associated with them. These can be deleted");\r
77                 detailLine(sb,indent,"automatically by setting \"force\" property.");\r
78                 detailLine(sb,indent,"i.e. set force=true or just starting with \"force\"");\r
79                 detailLine(sb,indent," (note force is unset after first use)");\r
80                 sb.append('\n');\r
81                 detailLine(sb,indent,"If \"set force=move\" is set, credentials are deleted, but ");\r
82                 detailLine(sb,indent,"Permissions and Roles are assigned to the Parent Namespace instead of");\r
83                 detailLine(sb,indent,"being deleted.  Similarly, Namespaces can be created even though there");\r
84                 detailLine(sb,indent,"are Roles/Perms whose type starts with the requested sub-namespace.");\r
85                 detailLine(sb,indent,"They are simply reassigned to the Child Namespace");\r
86                 indent-=4;\r
87                 api(sb,indent,HttpMethods.DELETE,"authz/ns/<ns>[?force=true]",Void.class,true);\r
88         }\r
89 \r
90 }\r