Update project structure to org.onap.aaf
[aaf/authz.git] / authz-cmd / src / main / java / org / onap / aaf / cmd / ns / Delete.java
diff --git a/authz-cmd/src/main/java/org/onap/aaf/cmd/ns/Delete.java b/authz-cmd/src/main/java/org/onap/aaf/cmd/ns/Delete.java
new file mode 100644 (file)
index 0000000..5254d46
--- /dev/null
@@ -0,0 +1,90 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aaf\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * ===========================================================================\r
+ * * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * * you may not use this file except in compliance with the License.\r
+ * * You may obtain a copy of the License at\r
+ * * \r
+ *  *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * * \r
+ *  * Unless required by applicable law or agreed to in writing, software\r
+ * * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * * See the License for the specific language governing permissions and\r
+ * * limitations under the License.\r
+ * * ============LICENSE_END====================================================\r
+ * *\r
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package org.onap.aaf.cmd.ns;\r
+\r
+import org.onap.aaf.cmd.AAFcli;\r
+import org.onap.aaf.cmd.Cmd;\r
+import org.onap.aaf.cmd.Param;\r
+import org.onap.aaf.cssa.rserv.HttpMethods;\r
+\r
+import org.onap.aaf.cadi.CadiException;\r
+import org.onap.aaf.cadi.LocatorException;\r
+import org.onap.aaf.cadi.client.Future;\r
+import org.onap.aaf.cadi.client.Rcli;\r
+import org.onap.aaf.cadi.client.Retryable;\r
+import org.onap.aaf.inno.env.APIException;\r
+\r
+/**\r
+ * p\r
+ *\r
+ */\r
+public class Delete extends Cmd {\r
+       public Delete(NS parent) {\r
+               super(parent,"delete", \r
+                               new Param("name",true)); \r
+       }\r
+\r
+       @Override\r
+       public int _exec(final int idx, final String ... args) throws CadiException, APIException, LocatorException {\r
+               return same(new Retryable<Integer>() {\r
+                       @Override\r
+                       public Integer code(Rcli<?> client) throws CadiException, APIException {\r
+                               int index = idx;\r
+                               StringBuilder path = new StringBuilder("/authz/ns/");\r
+                               path.append(args[index++]);\r
+                               \r
+                               // Send "Force" if set\r
+                               setQueryParamsOn(client);\r
+                               Future<Void> fp = client.delete(path.toString(),Void.class);\r
+                               \r
+                               if(fp.get(AAFcli.timeout())) {\r
+                                       pw().println("Deleted Namespace");\r
+                               } else {\r
+                                       error(fp);\r
+                               }\r
+                               return fp.code();\r
+                       }\r
+               });\r
+       }\r
+\r
+       @Override\r
+       public void detailedHelp(int _indent, StringBuilder sb) {\r
+               int indent = _indent;\r
+               detailLine(sb,indent,"Delete a Namespace");\r
+               indent+=4;\r
+               detailLine(sb,indent,"Namespaces cannot normally be deleted when there are still credentials,");\r
+               detailLine(sb,indent,"permissions or roles associated with them. These can be deleted");\r
+               detailLine(sb,indent,"automatically by setting \"force\" property.");\r
+               detailLine(sb,indent,"i.e. set force=true or just starting with \"force\"");\r
+               detailLine(sb,indent," (note force is unset after first use)");\r
+               sb.append('\n');\r
+               detailLine(sb,indent,"If \"set force=move\" is set, credentials are deleted, but ");\r
+               detailLine(sb,indent,"Permissions and Roles are assigned to the Parent Namespace instead of");\r
+               detailLine(sb,indent,"being deleted.  Similarly, Namespaces can be created even though there");\r
+               detailLine(sb,indent,"are Roles/Perms whose type starts with the requested sub-namespace.");\r
+               detailLine(sb,indent,"They are simply reassigned to the Child Namespace");\r
+               indent-=4;\r
+               api(sb,indent,HttpMethods.DELETE,"authz/ns/<ns>[?force=true]",Void.class,true);\r
+       }\r
+\r
+}\r