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;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Hive.Server.ADODataAccess {
|
---|
31 | class UserAdapter: IUserAdapter {
|
---|
32 | private dsHiveServerTableAdapters.HiveUserTableAdapter adapter =
|
---|
33 | new dsHiveServerTableAdapters.HiveUserTableAdapter();
|
---|
34 |
|
---|
35 | private PermissionOwnerAdapter permOwnerAdapter =
|
---|
36 | new PermissionOwnerAdapter();
|
---|
37 |
|
---|
38 | private User Convert(dsHiveServer.HiveUserRow row,
|
---|
39 | User user) {
|
---|
40 | if (row != null && user != null) {
|
---|
41 | /*Parent - PermissionOwner*/
|
---|
42 | user.PermissionOwnerId = row.PermissionOwnerId;
|
---|
43 | permOwnerAdapter.FillPermissionOwner(user);
|
---|
44 |
|
---|
45 | /*User*/
|
---|
46 | if (!row.IsPasswordNull())
|
---|
47 | user.Password = row.Password;
|
---|
48 | else
|
---|
49 | user.Password = String.Empty;
|
---|
50 |
|
---|
51 | return user;
|
---|
52 | } else
|
---|
53 | return null;
|
---|
54 | }
|
---|
55 |
|
---|
56 | private dsHiveServer.HiveUserRow Convert(User user,
|
---|
57 | dsHiveServer.HiveUserRow row) {
|
---|
58 | if (user != null && row != null) {
|
---|
59 | row.PermissionOwnerId = user.PermissionOwnerId;
|
---|
60 | row.Password = user.Password;
|
---|
61 |
|
---|
62 | return row;
|
---|
63 | } else
|
---|
64 | return null;
|
---|
65 | }
|
---|
66 |
|
---|
67 | #region IUserAdapter Members
|
---|
68 |
|
---|
69 | public void UpdateUser(User user) {
|
---|
70 | if (user != null) {
|
---|
71 | permOwnerAdapter.UpdatePermissionOwner(user);
|
---|
72 |
|
---|
73 | dsHiveServer.HiveUserDataTable data =
|
---|
74 | adapter.GetDataById(user.PermissionOwnerId);
|
---|
75 |
|
---|
76 | dsHiveServer.HiveUserRow row;
|
---|
77 | if (data.Count == 0) {
|
---|
78 | row = data.NewHiveUserRow();
|
---|
79 | row.PermissionOwnerId = user.PermissionOwnerId;
|
---|
80 | data.AddHiveUserRow(row);
|
---|
81 | } else {
|
---|
82 | row = data[0];
|
---|
83 | }
|
---|
84 |
|
---|
85 | Convert(user, row);
|
---|
86 |
|
---|
87 | adapter.Update(data);
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | public User GetUserById(long userId) {
|
---|
92 | User user = new User();
|
---|
93 |
|
---|
94 | dsHiveServer.HiveUserDataTable data =
|
---|
95 | adapter.GetDataById(userId);
|
---|
96 | if (data.Count == 1) {
|
---|
97 | dsHiveServer.HiveUserRow row =
|
---|
98 | data[0];
|
---|
99 | Convert(row, user);
|
---|
100 |
|
---|
101 | return user;
|
---|
102 | } else {
|
---|
103 | return null;
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | public User GetUserByName(String name) {
|
---|
108 | User user = new User();
|
---|
109 |
|
---|
110 | dsHiveServer.HiveUserDataTable data =
|
---|
111 | adapter.GetDataByName(name);
|
---|
112 | if (data.Count == 1) {
|
---|
113 | dsHiveServer.HiveUserRow row =
|
---|
114 | data[0];
|
---|
115 | Convert(row, user);
|
---|
116 |
|
---|
117 | return user;
|
---|
118 | } else {
|
---|
119 | return null;
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | public ICollection<User> GetAllUsers() {
|
---|
124 | ICollection<User> allUsers =
|
---|
125 | new List<User>();
|
---|
126 |
|
---|
127 | dsHiveServer.HiveUserDataTable data =
|
---|
128 | adapter.GetData();
|
---|
129 |
|
---|
130 | foreach (dsHiveServer.HiveUserRow row in data) {
|
---|
131 | User user = new User();
|
---|
132 | Convert(row, user);
|
---|
133 | allUsers.Add(user);
|
---|
134 | }
|
---|
135 |
|
---|
136 | return allUsers;
|
---|
137 | }
|
---|
138 |
|
---|
139 | public bool DeleteUser(User user) {
|
---|
140 | //referential integrity will delete the client object
|
---|
141 | return permOwnerAdapter.DeletePermissionOwner(user);
|
---|
142 | }
|
---|
143 |
|
---|
144 | #endregion
|
---|
145 | }
|
---|
146 | }
|
---|