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.DataAccess;
|
---|
28 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
29 | using System.Data;
|
---|
30 | using HeuristicLab.DataAccess.ADOHelper;
|
---|
31 | using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters;
|
---|
32 | using System.Data.Common;
|
---|
33 | using System.Data.SqlClient;
|
---|
34 | using HeuristicLab.Hive.Server.ADODataAccess.TableAdapterWrapper;
|
---|
35 |
|
---|
36 | namespace HeuristicLab.Hive.Server.ADODataAccess {
|
---|
37 | class ClientGroupAdapter :
|
---|
38 | DataAdapterBase<dsHiveServerTableAdapters.ClientGroupTableAdapter,
|
---|
39 | ClientGroup,
|
---|
40 | dsHiveServer.ClientGroupRow>,
|
---|
41 | IClientGroupAdapter {
|
---|
42 | #region Fields
|
---|
43 | private ManyToManyRelationHelper<
|
---|
44 | dsHiveServerTableAdapters.ClientGroup_ResourceTableAdapter,
|
---|
45 | dsHiveServer.ClientGroup_ResourceRow> manyToManyRelationHelper = null;
|
---|
46 |
|
---|
47 | private ManyToManyRelationHelper<dsHiveServerTableAdapters.ClientGroup_ResourceTableAdapter,
|
---|
48 | dsHiveServer.ClientGroup_ResourceRow> ManyToManyRelationHelper {
|
---|
49 | get {
|
---|
50 | if (manyToManyRelationHelper == null) {
|
---|
51 | manyToManyRelationHelper =
|
---|
52 | new ManyToManyRelationHelper<dsHiveServerTableAdapters.ClientGroup_ResourceTableAdapter,
|
---|
53 | dsHiveServer.ClientGroup_ResourceRow>(new ClientGroup_ResourceAdapterWrapper());
|
---|
54 | }
|
---|
55 |
|
---|
56 | manyToManyRelationHelper.Session = Session as Session;
|
---|
57 |
|
---|
58 | return manyToManyRelationHelper;
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | private IResourceAdapter resourceAdapter = null;
|
---|
63 |
|
---|
64 | private IResourceAdapter ResAdapter {
|
---|
65 | get {
|
---|
66 | if (resourceAdapter == null)
|
---|
67 | resourceAdapter =
|
---|
68 | this.Session.GetDataAdapter<Resource, IResourceAdapter>();
|
---|
69 |
|
---|
70 | return resourceAdapter;
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | private IClientAdapter clientAdapter = null;
|
---|
75 |
|
---|
76 | private IClientAdapter ClientAdapter {
|
---|
77 | get {
|
---|
78 | if (clientAdapter == null)
|
---|
79 | clientAdapter =
|
---|
80 | this.Session.GetDataAdapter<ClientInfo, IClientAdapter>();
|
---|
81 |
|
---|
82 | return clientAdapter;
|
---|
83 | }
|
---|
84 | }
|
---|
85 | #endregion
|
---|
86 |
|
---|
87 | public ClientGroupAdapter():
|
---|
88 | base(new ClientGroupAdapterWrapper()) {
|
---|
89 | }
|
---|
90 |
|
---|
91 | #region Overrides
|
---|
92 | protected override ClientGroup ConvertRow(dsHiveServer.ClientGroupRow row,
|
---|
93 | ClientGroup clientGroup) {
|
---|
94 | if (row != null && clientGroup != null) {
|
---|
95 | /*Parent - Permission Owner*/
|
---|
96 | clientGroup.Id = row.ResourceId;
|
---|
97 | ResAdapter.GetById(clientGroup.Id);
|
---|
98 |
|
---|
99 | ICollection<Guid> resources =
|
---|
100 | ManyToManyRelationHelper.GetRelationships(clientGroup.Id);
|
---|
101 |
|
---|
102 | clientGroup.Resources.Clear();
|
---|
103 | foreach(Guid resource in resources) {
|
---|
104 | ClientInfo client =
|
---|
105 | ClientAdapter.GetById(resource);
|
---|
106 |
|
---|
107 | if (client == null) {
|
---|
108 | //client group
|
---|
109 | ClientGroup group =
|
---|
110 | GetById(resource);
|
---|
111 |
|
---|
112 | clientGroup.Resources.Add(group);
|
---|
113 | } else {
|
---|
114 | clientGroup.Resources.Add(client);
|
---|
115 | }
|
---|
116 | }
|
---|
117 |
|
---|
118 | return clientGroup;
|
---|
119 | } else
|
---|
120 | return null;
|
---|
121 | }
|
---|
122 |
|
---|
123 | protected override dsHiveServer.ClientGroupRow ConvertObj(ClientGroup clientGroup,
|
---|
124 | dsHiveServer.ClientGroupRow row) {
|
---|
125 | if (clientGroup != null && row != null) {
|
---|
126 | row.ResourceId = clientGroup.Id;
|
---|
127 | }
|
---|
128 |
|
---|
129 | return row;
|
---|
130 | }
|
---|
131 | #endregion
|
---|
132 |
|
---|
133 | #region IClientGroupAdapter Members
|
---|
134 | protected override void doUpdate(ClientGroup group) {
|
---|
135 | if (group != null) {
|
---|
136 | ResAdapter.Update(group);
|
---|
137 |
|
---|
138 | base.doUpdate(group);
|
---|
139 |
|
---|
140 | List<Guid> relationships =
|
---|
141 | new List<Guid>();
|
---|
142 | foreach(Resource res in group.Resources) {
|
---|
143 | if (res is ClientInfo) {
|
---|
144 | ClientAdapter.Update(res as ClientInfo);
|
---|
145 | } else if (res is ClientGroup) {
|
---|
146 | Update(res as ClientGroup);
|
---|
147 | } else {
|
---|
148 | ResAdapter.Update(res);
|
---|
149 | }
|
---|
150 |
|
---|
151 | relationships.Add(res.Id);
|
---|
152 | }
|
---|
153 |
|
---|
154 | ManyToManyRelationHelper.UpdateRelationships(group.Id,
|
---|
155 | relationships);
|
---|
156 | }
|
---|
157 | }
|
---|
158 |
|
---|
159 | public ClientGroup GetByName(string name) {
|
---|
160 | ClientGroup group = new ClientGroup();
|
---|
161 | Resource res =
|
---|
162 | ResAdapter.GetByName(name);
|
---|
163 |
|
---|
164 | if (res != null) {
|
---|
165 | return GetById(res.Id);
|
---|
166 | }
|
---|
167 |
|
---|
168 | return null;
|
---|
169 | }
|
---|
170 |
|
---|
171 | public ICollection<ClientGroup> MemberOf(Resource resource) {
|
---|
172 | throw new NotImplementedException();
|
---|
173 | }
|
---|
174 |
|
---|
175 | protected override bool doDelete(ClientGroup group) {
|
---|
176 | if (group != null) {
|
---|
177 | //delete all relationships
|
---|
178 | ManyToManyRelationHelper.UpdateRelationships(group.Id,
|
---|
179 | new List<Guid>());
|
---|
180 |
|
---|
181 | return base.doDelete(group) &&
|
---|
182 | ResAdapter.Delete(group);
|
---|
183 | }
|
---|
184 |
|
---|
185 | return false;
|
---|
186 | }
|
---|
187 |
|
---|
188 | #endregion
|
---|
189 | }
|
---|
190 | }
|
---|