Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.Core/3.2/ServerConsoleFacade.cs @ 1949

Last change on this file since 1949 was 1932, checked in by msteinbi, 15 years ago

new BO Project
added new methods for project handling within jobManager
(#599)

File size: 7.2 KB
RevLine 
[907]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
22using System;
[800]23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Hive.Contracts.Interfaces;
27using HeuristicLab.Hive.Contracts.BusinessObjects;
[902]28using HeuristicLab.Hive.Contracts;
[1648]29using HeuristicLab.Security.Contracts.Interfaces;
[1769]30using HeuristicLab.Hive.Server.Core.InternalInterfaces;
[800]31
32namespace HeuristicLab.Hive.Server.Core {
33  public class ServerConsoleFacade: IServerConsoleFacade {
[1099]34    private IClientManager clientManager =
35      ServiceLocator.GetClientManager();
[1084]36
[1099]37    private IJobManager jobManager =
38      ServiceLocator.GetJobManager();
39
[1769]40    private IHivePermissionManager secMan = ServiceLocator.GetHivePermissionManager();
[1084]41
[1648]42    public Guid sessionID = Guid.Empty;
43
[1086]44    public Response Login(string username, string password) {
45      Response resp = new Response();
[1801]46     
47      /*
[1769]48      sessionID = secMan.Login(username, password);
[1800]49      if (sessionID == Guid.Empty) {
[1648]50        resp.Success = false;
[1800]51        resp.StatusMessage = ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_FAILED;
52      } else {
[1648]53        resp.Success = true;
54        resp.StatusMessage =
55          ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_SUCCESS;
56      }
[1801]57      */
58      sessionID = Guid.Empty;
59      resp.Success = true;
60      resp.StatusMessage = ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_SUCCESS;
[1086]61      return resp;
[1084]62    }
63
64
[902]65    public ResponseList<ClientInfo> GetAllClients() {
[1769]66      if (HasPermission(PermissiveSecurityAction.List_AllClients))
[1648]67        return clientManager.GetAllClients();
68      else
69        throw new PermissionException();
[800]70    }
71
[902]72    public ResponseList<ClientGroup> GetAllClientGroups() {
[1769]73      if (HasPermission(PermissiveSecurityAction.List_AllClientGroups))
[1648]74        return clientManager.GetAllClientGroups();
75      else
76        throw new PermissionException();
[800]77    }
78
[902]79    public ResponseList<UpTimeStatistics> GetAllUpTimeStatistics() {
[1769]80      if (HasPermission(PermissiveSecurityAction.Show_Statistics))
[1648]81        return clientManager.GetAllUpTimeStatistics();
82      else
83        throw new PermissionException();
[800]84    }
85
[1825]86    public ResponseObject<ClientGroup> AddClientGroup(ClientGroup clientGroup) {
[1769]87      if (HasPermission(PermissiveSecurityAction.Add_ClientGroup))
[1648]88        return clientManager.AddClientGroup(clientGroup);
89      else
90        throw new PermissionException();
[934]91    }
92
[1449]93    public Response AddResourceToGroup(Guid clientGroupId, Resource resource) {
[1769]94      if (HasPermission(PermissiveSecurityAction.Add_Resource))
[1648]95        return clientManager.AddResourceToGroup(clientGroupId, resource);
96      else
97        throw new PermissionException();
[934]98    }
99
[1449]100    public Response DeleteResourceFromGroup(Guid clientGroupId, Guid resourceId) {
[1769]101      if (HasPermission(PermissiveSecurityAction.Delete_Resource))
[1648]102        return clientManager.DeleteResourceFromGroup(clientGroupId, resourceId);
103      else
104        throw new PermissionException();
[934]105    }
106
[800]107
[902]108    public ResponseList<HeuristicLab.Hive.Contracts.BusinessObjects.Job> GetAllJobs() {
[1769]109      if (HasPermission(PermissiveSecurityAction.Get_AllJobs))
[1648]110        return jobManager.GetAllJobs();
111      else
112        throw new PermissionException();
[800]113    }
[1648]114
[967]115    public ResponseObject<Job> AddNewJob(Job job) {
[1805]116      if (HasPermission(PermissiveSecurityAction.Add_Job))
[1648]117        return jobManager.AddNewJob(job);
118      else
119        throw new PermissionException();
[967]120    }
[800]121
[1509]122    public ResponseObject<JobResult> GetLastJobResultOf(Guid jobId, bool requested) {
[1769]123      if (HasPermission(PermissiveSecurityAction.Get_LastJobResult))
[1648]124        return jobManager.GetLastJobResultOf(jobId, requested);
125      else
126        throw new PermissionException();
[1171]127    }
128
[1799]129    public ResponseList<JobResult> GetAllJobResults(Guid jobId) {
[1769]130      if (HasPermission(PermissiveSecurityAction.Get_AllJobResults))
[1648]131        return jobManager.GetAllJobResults(jobId);
132      else
133        throw new PermissionException();
134    }
135
[1449]136    public Response RemoveJob(Guid jobId) {
[1769]137      if (HasPermission(PermissiveSecurityAction.Remove_Job))
[1648]138        return jobManager.RemoveJob(jobId);
139      else
140        throw new PermissionException();
[967]141    }
142
[1509]143    public Response RequestSnapshot(Guid jobId) {
[1769]144      if (HasPermission(PermissiveSecurityAction.Request_Snapshot))
[1648]145        return jobManager.RequestSnapshot(jobId);
146      else
147        throw new PermissionException();
[1509]148    }
149
150    public Response AbortJob(Guid jobId) {
[1769]151      if (HasPermission(PermissiveSecurityAction.Abort_Job))
[1648]152        return jobManager.AbortJob(jobId);
153      else
154        throw new PermissionException();
[1509]155    }
156
[1769]157    public ResponseObject<List<ClientGroup>> GetAllGroupsOfResource(Guid resourceId) {
158      if (HasPermission(PermissiveSecurityAction.Get_AllGroupsOfResource))
159        return clientManager.GetAllGroupsOfResource(resourceId);
160      else
161        throw new PermissionException();     
[1627]162    }
163
[1824]164    public Response DeleteClientGroup(Guid clientGroupId) {
165      return clientManager.DeleteClientGroup(clientGroupId);
166    }
167
[1769]168  /*
169    private bool HasPermission(Guid action) {
170      return (sessionID == Guid.Empty) ? false : secMan.CheckPermission(sessionID, action, Guid.Empty);
171    }
172
173    private bool HasPermission(Guid action, Guid entityId) {
174      return (sessionID == Guid.Empty) ? false : secMan.CheckPermission(sessionID, action, entityId);
175    }
176   */
177
178    [Obsolete("Only for testing!")]
179    private bool HasPermission(Guid g) { return true; }
180    [Obsolete("Only for testing!")]
[1804]181    private bool HasPermission(Guid g, Guid f) { return true; }
[1769]182
[1648]183    public class PermissionException : Exception {
184      public PermissionException()
185        : base("Current user has insufficent rights for this action!") {
186      }
187
188      public PermissionException(string msg)
189        : base(msg) {
190      }
191
192
193    }
[1932]194
195    public ResponseList<Project> GetAllProjects() {
196      return jobManager.GetAllProjects();
197    }
198
199    public Response CreateProject(Project project) {
200      return jobManager.CreateProject(project);
201    }
202
203    public Response ChangeProject(Project project) {
204      return jobManager.ChangeProject(project);
205    }
206
207    public Response DeleteProject(Guid projectId) {
208      return jobManager.DeleteProject(projectId);
209    }
210
211    public ResponseList<Job> GetJobsByProject(Guid projectId) {
212      return jobManager.GetJobsByProject(projectId);
213    }
214
[800]215  }
216}
Note: See TracBrowser for help on using the repository browser.