2 * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.nemo.user.tenantmanager;
\r
10 import java.util.Map;
\r
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId;
\r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserRoleName;
\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.RegisterUserInput;
\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;
\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.user.rev151010.user.roles.UserRole;
\r
19 * Created by z00293636 on 2015/9/20.
\r
21 public class RegisterUser {
\r
22 private final TenantManage tenantManage;
\r
24 public RegisterUser(TenantManage tenantManage)
\r
26 this.tenantManage = tenantManage;
\r
29 public String registerUser(RegisterUserInput input)
\r
31 String errorInfo = null;
\r
33 Map<UserRoleName, UserRole> userRoles = tenantManage.getUserRoles();
\r
34 Map<UserId, User> users = tenantManage.getUsers();
\r
36 if (userRoles == null || userRoles.isEmpty())
\r
38 errorInfo = "There are no roles be defined.";
\r
42 if (userRoles.containsKey(input.getUserRole()))
\r
44 if (users != null && users.containsKey(input.getUserId()))
\r
46 errorInfo = "The user has been registered.";
\r
50 tenantManage.addUser(input);
\r
55 errorInfo = "The role is not defined in the data store.";
\r