1 | #region License Information
|
---|
2 |
|
---|
3 | /* HeuristicLab
|
---|
4 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
5 | *
|
---|
6 | * This file is part of HeuristicLab.
|
---|
7 | *
|
---|
8 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
9 | * it under the terms of the GNU General Public License as published by
|
---|
10 | * the Free Software Foundation, either version 3 of the License, or
|
---|
11 | * (at your option) any later version.
|
---|
12 | *
|
---|
13 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | * GNU General Public License for more details.
|
---|
17 | *
|
---|
18 | * You should have received a copy of the GNU General Public License
|
---|
19 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #endregion
|
---|
23 |
|
---|
24 | using System;
|
---|
25 | using System.Collections.Generic;
|
---|
26 | using System.Linq;
|
---|
27 | using System.Text;
|
---|
28 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
29 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
30 | using HeuristicLab.Hive.Contracts;
|
---|
31 | using HeuristicLab.Hive.Server.DataAccess;
|
---|
32 | using HeuristicLab.DataAccess.Interfaces;
|
---|
33 | using HeuristicLab.Hive.Server.LINQDataAccess;
|
---|
34 | using ClientGroup=HeuristicLab.Hive.Contracts.BusinessObjects.ClientGroupDto;
|
---|
35 |
|
---|
36 | namespace HeuristicLab.Hive.Server.Core {
|
---|
37 | internal class ClientManager : IClientManager {
|
---|
38 | private List<ClientGroup> clientGroups;
|
---|
39 |
|
---|
40 | public ClientManager() {
|
---|
41 | clientGroups = new List<ClientGroup>();
|
---|
42 | }
|
---|
43 |
|
---|
44 | #region IClientManager Members
|
---|
45 |
|
---|
46 | /// <summary>
|
---|
47 | /// Returns all clients stored in the database
|
---|
48 | /// </summary>
|
---|
49 | /// <returns></returns>
|
---|
50 | public ResponseList<ClientDto> GetAllClients() {
|
---|
51 | ResponseList<ClientDto> response = new ResponseList<ClientDto>();
|
---|
52 |
|
---|
53 | response.List = new List<ClientDto>(DaoLocator.ClientDao.FindAll());
|
---|
54 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTS;
|
---|
55 | response.Success = true;
|
---|
56 |
|
---|
57 | return response;
|
---|
58 | }
|
---|
59 |
|
---|
60 | /// <summary>
|
---|
61 | /// returns all client groups stored in the database
|
---|
62 | /// </summary>
|
---|
63 | /// <returns></returns>
|
---|
64 | public ResponseList<ClientGroup> GetAllClientGroups() {
|
---|
65 | ResponseList<ClientGroup> response = new ResponseList<ClientGroup>();
|
---|
66 |
|
---|
67 | List<ClientGroup> allClientGroups =
|
---|
68 | new List<ClientGroup>(DaoLocator.ClientGroupDao.FindAllWithSubGroupsAndClients());
|
---|
69 | ClientGroup emptyClientGroup = new ClientGroup();
|
---|
70 | IEnumerable<ClientDto> groupLessClients = DaoLocator.ClientDao.FindAllClientsWithoutGroup();
|
---|
71 | if (groupLessClients != null) {
|
---|
72 | foreach (ClientDto currClient in groupLessClients) {
|
---|
73 | emptyClientGroup.Resources.Add(currClient);
|
---|
74 | }
|
---|
75 | }
|
---|
76 | emptyClientGroup.Id = Guid.Empty;
|
---|
77 | allClientGroups.Add(emptyClientGroup);
|
---|
78 |
|
---|
79 | response.List = allClientGroups;
|
---|
80 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTGROUPS;
|
---|
81 | response.Success = true;
|
---|
82 |
|
---|
83 | return response;
|
---|
84 | }
|
---|
85 |
|
---|
86 | public ResponseList<UpTimeStatisticsDto> GetAllUpTimeStatistics() {
|
---|
87 | ResponseList<UpTimeStatisticsDto> response = new ResponseList<UpTimeStatisticsDto>();
|
---|
88 | response.Success = true;
|
---|
89 | return response;
|
---|
90 | }
|
---|
91 |
|
---|
92 | /// <summary>
|
---|
93 | /// Add a client group into the database
|
---|
94 | /// </summary>
|
---|
95 | /// <param name="clientGroup"></param>
|
---|
96 | /// <returns></returns>
|
---|
97 | public ResponseObject<ClientGroup> AddClientGroup(ClientGroup clientGroup) {
|
---|
98 | ResponseObject<ClientGroup> response = new ResponseObject<ClientGroup>();
|
---|
99 |
|
---|
100 | if (clientGroup.Id != Guid.Empty) {
|
---|
101 | response.Success = false;
|
---|
102 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_ID_MUST_NOT_BE_SET;
|
---|
103 | }
|
---|
104 | else {
|
---|
105 | clientGroup = DaoLocator.ClientGroupDao.Insert(clientGroup);
|
---|
106 | //clientGroupAdapter.Update(clientGroup);
|
---|
107 | response.Obj = clientGroup;
|
---|
108 | response.Success = true;
|
---|
109 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_ADDED;
|
---|
110 | }
|
---|
111 |
|
---|
112 | return response;
|
---|
113 | }
|
---|
114 |
|
---|
115 | /// <summary>
|
---|
116 | /// Add a resource to a group
|
---|
117 | /// </summary>
|
---|
118 | /// <param name="clientGroupId"></param>
|
---|
119 | /// <param name="resource"></param>
|
---|
120 | /// <returns></returns>
|
---|
121 | public Response AddResourceToGroup(Guid clientGroupId, ResourceDto resource) {
|
---|
122 | Response response = new Response();
|
---|
123 |
|
---|
124 | ClientGroup clientGroup = DaoLocator.ClientGroupDao.FindById(clientGroupId);
|
---|
125 | if (clientGroup == null) {
|
---|
126 | response.Success = false;
|
---|
127 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST;
|
---|
128 | return response;
|
---|
129 | }
|
---|
130 | clientGroup.Resources.Add(resource);
|
---|
131 | DaoLocator.ClientGroupDao.AddRessourceToClientGroup(resource.Id, clientGroup.Id);
|
---|
132 | //clientGroupAdapter.Update(clientGroup);
|
---|
133 |
|
---|
134 | response.Success = true;
|
---|
135 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_ADDED_TO_GROUP;
|
---|
136 |
|
---|
137 | return response;
|
---|
138 | }
|
---|
139 |
|
---|
140 | /// <summary>
|
---|
141 | /// Remove a resource from a group
|
---|
142 | /// </summary>
|
---|
143 | /// <param name="clientGroupId"></param>
|
---|
144 | /// <param name="resourceId"></param>
|
---|
145 | /// <returns></returns>
|
---|
146 | public Response DeleteResourceFromGroup(Guid clientGroupId, Guid resourceId) {
|
---|
147 | Response response = new Response();
|
---|
148 |
|
---|
149 | ClientGroup clientGroup = DaoLocator.ClientGroupDao.FindById(clientGroupId);
|
---|
150 | if (clientGroup == null) {
|
---|
151 | response.Success = false;
|
---|
152 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST;
|
---|
153 | return response;
|
---|
154 | }
|
---|
155 | foreach (ResourceDto resource in clientGroup.Resources) {
|
---|
156 | if (resource.Id == resourceId) {
|
---|
157 | clientGroup.Resources.Remove(resource);
|
---|
158 | DaoLocator.ClientGroupDao.RemoveRessourceFromClientGroup(resource.Id, clientGroup.Id);
|
---|
159 | //clientGroupAdapter.Update(clientGroup);
|
---|
160 | response.Success = true;
|
---|
161 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_REMOVED;
|
---|
162 | return response;
|
---|
163 | }
|
---|
164 | }
|
---|
165 | response.Success = false;
|
---|
166 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_NOT_FOUND;
|
---|
167 |
|
---|
168 | return response;
|
---|
169 | }
|
---|
170 |
|
---|
171 | public ResponseObject<List<ClientGroup>> GetAllGroupsOfResource(Guid resourceId) {
|
---|
172 | ResponseObject<List<ClientGroup>> response = new ResponseObject<List<ClientGroup>>();
|
---|
173 |
|
---|
174 | ClientDto client = DaoLocator.ClientDao.FindById(resourceId);
|
---|
175 | if (client != null) {
|
---|
176 | List<ClientGroup> groupsOfClient = new List<ClientGroup>(DaoLocator.ClientGroupDao.MemberOf(client));
|
---|
177 | response.Obj = groupsOfClient;
|
---|
178 | response.Success = true;
|
---|
179 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_GROUPS_OF_CLIENT;
|
---|
180 | }
|
---|
181 | else {
|
---|
182 | response.Obj = new List<ClientGroup>();
|
---|
183 | response.Success = false;
|
---|
184 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_NOT_FOUND;
|
---|
185 | }
|
---|
186 |
|
---|
187 | return response;
|
---|
188 | }
|
---|
189 |
|
---|
190 | public Response DeleteClientGroup(Guid clientGroupId) {
|
---|
191 | Response response = new Response();
|
---|
192 |
|
---|
193 | ClientGroup clientGroup = DaoLocator.ClientGroupDao.FindById(clientGroupId);
|
---|
194 | if (clientGroup == null) {
|
---|
195 | response.Success = false;
|
---|
196 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST;
|
---|
197 | return response;
|
---|
198 | }
|
---|
199 |
|
---|
200 | DaoLocator.ClientGroupDao.Delete(clientGroup);
|
---|
201 |
|
---|
202 | response.Success = true;
|
---|
203 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DELETED;
|
---|
204 | return response;
|
---|
205 | }
|
---|
206 |
|
---|
207 | public ResponseList<AppointmentDto> GetUptimeCalendarForResource(Guid guid) {
|
---|
208 | ResponseList<AppointmentDto> response = new ResponseList<AppointmentDto>();
|
---|
209 | response.List = new List<AppointmentDto>(DaoLocator.UptimeCalendarDao.GetUptimeCalendarForResource(guid));
|
---|
210 | response.Success = true;
|
---|
211 | return response;
|
---|
212 | }
|
---|
213 |
|
---|
214 | public Response SetUptimeCalendarForResource(Guid guid, IEnumerable<AppointmentDto> appointments) {
|
---|
215 | DaoLocator.UptimeCalendarDao.SetUptimeCalendarForResource(guid, appointments);
|
---|
216 | return new Response {Success = true};
|
---|
217 | }
|
---|
218 | #endregion
|
---|
219 | }
|
---|
220 | } |
---|