Bump MRI upstreams
[aaa.git] / aaa-cli / src / main / java / org / opendaylight / aaa / cli / dmstore / AddRole.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.api.action.Command;
12 import org.apache.karaf.shell.api.action.Option;
13 import org.apache.karaf.shell.api.action.lifecycle.Service;
14 import org.opendaylight.aaa.api.model.Role;
15 import org.opendaylight.aaa.cli.AaaCliAbstractCommand;
16 import org.opendaylight.aaa.cli.utils.DataStoreUtils;
17
18 /**
19  * Adds a role.
20  *
21  * @author mserngawy
22  */
23 @Service
24 @Command(name = "add-role", scope = "aaa", description = "Add role.")
25 public class AddRole extends AaaCliAbstractCommand {
26     @Option(name = "-name",
27             aliases = { "--roleName" },
28             description = "The role name",
29             required = true,
30             multiValued = false)
31     private String roleName;
32
33     @Option(name = "-dname",
34             aliases = { "--domainName" },
35             description = "The domain name",
36             required = true,
37             multiValued = false)
38     private String domainName;
39
40     @Option(name = "-desc",
41             aliases = { "--roleDescription" },
42             description = "The role Description",
43             required = true,
44             multiValued = false)
45     private String roleDesc;
46
47     @Override
48     public Object execute() throws Exception {
49         if (super.execute() == null) {
50             return LOGIN_FAILED_MESS;
51         }
52         Role role = new Role();
53         role.setDescription(roleDesc);
54         role.setName(roleName);
55         final String domainId = DataStoreUtils.getDomainId(identityStore, domainName);
56         if (domainId == null) {
57             return "Domain does not exist";
58         }
59         role.setDomainid(domainId);
60         role = identityStore.writeRole(role);
61         if (role != null) {
62             return "Role " + roleName + " has been created, Role Id is " + role.getRoleid();
63         }
64         return null;
65     }
66 }