AAA-160: Fix aaa-cli commands
[aaa.git] / aaa-cli / src / main / java / org / opendaylight / aaa / cli / dmstore / RemoveDomain.java
1 /*
2  * Copyright (c) 2016, 2017 Inocybe Technologies. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.aaa.cli.dmstore;
10
11 import org.apache.karaf.shell.commands.Command;
12 import org.apache.karaf.shell.commands.Option;
13 import org.opendaylight.aaa.cli.AaaCliAbstractCommand;
14 import org.opendaylight.aaa.cli.utils.CliUtils;
15 import org.opendaylight.aaa.cli.utils.DataStoreUtils;
16 import org.opendaylight.aaa.shiro.idm.IdmLightProxy;
17
18 @Command(name = "remove-domain", scope = "aaa", description = "Remove domain.")
19
20 /**
21  * @author mserngawy
22  *
23  */
24 public class RemoveDomain extends AaaCliAbstractCommand {
25
26     @Option(name = "-name", aliases = {
27             "--domainName" }, description = "The domain name", required = true, multiValued = false)
28     private String domainName = "";
29
30     public RemoveDomain() {
31         super();
32     }
33
34     @Override
35     protected Object doExecute() throws Exception {
36         if (super.doExecute() == null) {
37             return CliUtils.LOGIN_FAILED_MESS;
38         }
39         final String domainId = DataStoreUtils.getDomainId(identityStore, domainName);
40         if (domainId == null) {
41             return "User does not exist";
42         }
43         if (identityStore.deleteDomain(domainId) == null) {
44             return "Failed to delete domain " + domainName;
45         }
46         IdmLightProxy.clearClaimCache();
47         return "Domain " + domainName + "has been deleted.";
48     }
49 }