Merge "Add CLI for managing aaa data model"
[aaa.git] / aaa-cli / src / main / java / org / opendaylight / aaa / cli / dmstore / RemoveDomain.java
1 /*
2  * Copyright (c) 2016 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.apache.karaf.shell.console.OsgiCommandSupport;
14 import org.opendaylight.aaa.api.IIDMStore;
15 import org.opendaylight.aaa.cli.AaaCliAbstractCommand;
16 import org.opendaylight.aaa.cli.utils.CliUtils;
17 import org.opendaylight.aaa.cli.utils.DataStoreUtils;
18
19 @Command(name = "remove-domain", scope = "aaa", description = "Remove domain.")
20
21 /**
22  * @author mserngawy
23  *
24  */
25 public class RemoveDomain extends AaaCliAbstractCommand {
26
27     @Option(name = "-name",
28             aliases = { "--domainName" },
29             description = "The domain name",
30             required = true,
31             multiValued = false)
32     private String domainName = "";
33
34     public RemoveDomain(final IIDMStore identityStore) {
35         super(identityStore);
36     }
37
38     @Override
39     protected Object doExecute() throws Exception {
40         if (super.doExecute() == null) {
41             return CliUtils.LOGIN_FAILED_MESS;
42         }
43         final String domainId = DataStoreUtils.getDomainId(identityStore, domainName);
44         if (domainId == null) {
45             return "User does not exist";
46         }
47         if (identityStore.deleteDomain(domainId) == null) {
48             return "Failed to delete domain " + domainName;
49         }
50         return "Domain " + domainName + "has been deleted.";
51     }
52 }