[845] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 |
|
---|
| 27 | using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
|
---|
| 28 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
[925] | 29 | using System.Runtime.CompilerServices;
|
---|
[845] | 30 |
|
---|
| 31 | namespace HeuristicLab.Hive.Server.ADODataAccess {
|
---|
[925] | 32 | class UserAdapter : DataAdapterBase, IUserAdapter {
|
---|
[845] | 33 | private dsHiveServerTableAdapters.HiveUserTableAdapter adapter =
|
---|
| 34 | new dsHiveServerTableAdapters.HiveUserTableAdapter();
|
---|
| 35 |
|
---|
[925] | 36 | private dsHiveServer.HiveUserDataTable data =
|
---|
| 37 | new dsHiveServer.HiveUserDataTable();
|
---|
[845] | 38 |
|
---|
[925] | 39 | private IPermissionOwnerAdapter permOwnerAdapter =
|
---|
| 40 | ServiceLocator.GetPermissionOwnerAdapter();
|
---|
| 41 |
|
---|
[939] | 42 | private IUserGroupAdapter userGroupAdapter = null;
|
---|
| 43 |
|
---|
[925] | 44 | public UserAdapter() {
|
---|
| 45 | adapter.Fill(data);
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | protected override void Update() {
|
---|
| 49 | this.adapter.Update(this.data);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[899] | 52 | private User Convert(dsHiveServer.HiveUserRow row,
|
---|
| 53 | User user) {
|
---|
| 54 | if (row != null && user != null) {
|
---|
| 55 | /*Parent - PermissionOwner*/
|
---|
| 56 | user.PermissionOwnerId = row.PermissionOwnerId;
|
---|
[925] | 57 | permOwnerAdapter.GetPermissionOwnerById(user);
|
---|
[845] | 58 |
|
---|
| 59 | /*User*/
|
---|
[899] | 60 | if (!row.IsPasswordNull())
|
---|
| 61 | user.Password = row.Password;
|
---|
| 62 | else
|
---|
| 63 | user.Password = String.Empty;
|
---|
[845] | 64 |
|
---|
| 65 | return user;
|
---|
| 66 | } else
|
---|
| 67 | return null;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | private dsHiveServer.HiveUserRow Convert(User user,
|
---|
| 71 | dsHiveServer.HiveUserRow row) {
|
---|
| 72 | if (user != null && row != null) {
|
---|
| 73 | row.Password = user.Password;
|
---|
| 74 |
|
---|
[899] | 75 | return row;
|
---|
| 76 | } else
|
---|
| 77 | return null;
|
---|
[845] | 78 | }
|
---|
| 79 |
|
---|
| 80 | #region IUserAdapter Members
|
---|
| 81 |
|
---|
[925] | 82 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
[845] | 83 | public void UpdateUser(User user) {
|
---|
[905] | 84 | if (user != null) {
|
---|
| 85 | permOwnerAdapter.UpdatePermissionOwner(user);
|
---|
| 86 |
|
---|
[925] | 87 | dsHiveServer.HiveUserRow row =
|
---|
| 88 | data.FindByPermissionOwnerId(user.PermissionOwnerId);
|
---|
| 89 | if (row == null) {
|
---|
[905] | 90 | row = data.NewHiveUserRow();
|
---|
| 91 | row.PermissionOwnerId = user.PermissionOwnerId;
|
---|
| 92 | data.AddHiveUserRow(row);
|
---|
[925] | 93 | }
|
---|
[905] | 94 |
|
---|
| 95 | Convert(user, row);
|
---|
| 96 | }
|
---|
[845] | 97 | }
|
---|
| 98 |
|
---|
[899] | 99 | public User GetUserById(long userId) {
|
---|
[905] | 100 | User user = new User();
|
---|
| 101 |
|
---|
[925] | 102 | dsHiveServer.HiveUserRow row =
|
---|
| 103 | data.FindByPermissionOwnerId(userId);
|
---|
| 104 |
|
---|
| 105 | if(row != null) {
|
---|
[905] | 106 | Convert(row, user);
|
---|
| 107 |
|
---|
| 108 | return user;
|
---|
| 109 | } else {
|
---|
| 110 | return null;
|
---|
| 111 | }
|
---|
[845] | 112 | }
|
---|
| 113 |
|
---|
[899] | 114 | public User GetUserByName(String name) {
|
---|
[905] | 115 | User user = new User();
|
---|
| 116 |
|
---|
[925] | 117 | PermissionOwner permOwner =
|
---|
| 118 | permOwnerAdapter.GetPermissionOwnerByName(name);
|
---|
| 119 |
|
---|
| 120 | if (permOwner != null) {
|
---|
[905] | 121 | dsHiveServer.HiveUserRow row =
|
---|
[925] | 122 | data.FindByPermissionOwnerId(permOwner.PermissionOwnerId);
|
---|
[905] | 123 |
|
---|
[925] | 124 | if (row != null) {
|
---|
| 125 | Convert(row, user);
|
---|
| 126 |
|
---|
| 127 | return user;
|
---|
| 128 | }
|
---|
[905] | 129 | }
|
---|
[925] | 130 |
|
---|
| 131 | return null;
|
---|
[899] | 132 | }
|
---|
| 133 |
|
---|
[845] | 134 | public ICollection<User> GetAllUsers() {
|
---|
[905] | 135 | ICollection<User> allUsers =
|
---|
| 136 | new List<User>();
|
---|
| 137 |
|
---|
| 138 | foreach (dsHiveServer.HiveUserRow row in data) {
|
---|
| 139 | User user = new User();
|
---|
| 140 | Convert(row, user);
|
---|
| 141 | allUsers.Add(user);
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | return allUsers;
|
---|
[845] | 145 | }
|
---|
| 146 |
|
---|
[925] | 147 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
[845] | 148 | public bool DeleteUser(User user) {
|
---|
[925] | 149 | if (user != null) {
|
---|
| 150 | dsHiveServer.HiveUserRow row =
|
---|
| 151 | data.FindByPermissionOwnerId(user.PermissionOwnerId);
|
---|
| 152 |
|
---|
| 153 | if (row != null) {
|
---|
[939] | 154 | if (userGroupAdapter == null)
|
---|
| 155 | userGroupAdapter =
|
---|
| 156 | ServiceLocator.GetUserGroupAdapter();
|
---|
| 157 |
|
---|
| 158 | ICollection<UserGroup> userGroups =
|
---|
| 159 | userGroupAdapter.MemberOf(user);
|
---|
| 160 |
|
---|
| 161 | foreach (UserGroup group in userGroups) {
|
---|
| 162 | group.Members.Remove(user);
|
---|
| 163 | userGroupAdapter.UpdateUserGroup(group);
|
---|
| 164 | }
|
---|
| 165 |
|
---|
[925] | 166 | data.RemoveHiveUserRow(row);
|
---|
| 167 |
|
---|
| 168 | return permOwnerAdapter.DeletePermissionOwner(user);
|
---|
| 169 | }
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | return false;
|
---|
[845] | 173 | }
|
---|
| 174 |
|
---|
| 175 | #endregion
|
---|
| 176 | }
|
---|
| 177 | }
|
---|