Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/Facades/ClientFacade.cs @ 4424

Last change on this file since 4424 was 4424, checked in by cneumuel, 14 years ago
  • Added and updated License Information in every file
  • Sort and remove usings in every file
  • Deleted obsolete DataAccess.ADOHelper
  • Deleted some obsolete files
File size: 7.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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;
23using System.Collections.Generic;
24using System.Linq;
25using System.Security.Permissions;
26using HeuristicLab.Hive.Contracts;
27using HeuristicLab.Hive.Contracts.BusinessObjects;
28using HeuristicLab.Hive.Contracts.Interfaces;
29using HeuristicLab.Hive.Contracts.ResponseObjects;
30using HeuristicLab.Hive.Server.DataAccess;
31
32namespace HeuristicLab.Hive.Server.Core {
33  public class ClientFacade : IClientFacade {
34
35    private IJobManager jobManager = ServiceLocator.GetJobManager();
36    private IContextFactory contextFactory = ServiceLocator.GetContextFactory();
37
38    public ClientFacade() {
39    }
40
41    #region IClientFacade Members
42
43    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
44    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
45    public ResponseObject<JobDto> AddJob(SerializedJob job) {
46      using (contextFactory.GetContext()) {
47        return jobManager.AddNewJob(job);
48      }
49    }
50
51    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
52    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
53    public ResponseObject<JobDto> AddJobWithGroupStrings(SerializedJob job, IEnumerable<string> resources) {
54      using (contextFactory.GetContext()) {
55        return jobManager.AddJobWithGroupStrings(job, resources);
56      }
57    }
58
59    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
60    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
61    public Response RequestSnapshot(Guid jobId) {
62      using (contextFactory.GetContext()) {
63        ServiceLocator.GetAuthorizationManager().AuthorizeJobs(jobId);
64        return jobManager.RequestSnapshot(jobId);
65      }
66    }
67
68    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
69    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
70    public ResponseObject<SerializedJob> GetLastSerializedResult(Guid jobId) {
71      using (contextFactory.GetContext(false)) {
72        ServiceLocator.GetAuthorizationManager().AuthorizeJobs(jobId);
73        return jobManager.GetLastSerializedResult(jobId);
74      }
75    }
76
77    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
78    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
79    public ResponseObject<SerializedJob> GetSnapshotResult(Guid jobId) {
80      using (contextFactory.GetContext(false)) {
81        ServiceLocator.GetAuthorizationManager().AuthorizeJobs(jobId);
82        return jobManager.GetSnapshotResult(jobId);
83      }
84    }
85
86    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
87    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
88    public ResponseObject<JobDto> GetJobById(Guid jobId) {
89      using (contextFactory.GetContext(false)) {
90        ServiceLocator.GetAuthorizationManager().AuthorizeJobs(jobId);
91        return jobManager.GetJobById(jobId);
92      }
93    }
94
95    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
96    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
97    public Response AbortJob(Guid jobId) {
98      using (contextFactory.GetContext()) {
99        ServiceLocator.GetAuthorizationManager().AuthorizeJobs(jobId);
100        return jobManager.AbortJob(jobId);
101      }
102    }
103
104    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
105    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
106    public ResponseObject<JobResultList> GetJobResults(IEnumerable<Guid> jobIds) {
107      using (contextFactory.GetContext(false)) {
108        ServiceLocator.GetAuthorizationManager().AuthorizeJobs(jobIds.ToArray());
109        return jobManager.GetJobResults(jobIds);
110      }
111    }
112
113    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
114    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
115    public ResponseObject<JobResultList> GetChildJobResults(Guid? parentJobId, bool recursive, bool includeParent) {
116      using (contextFactory.GetContext(false)) {
117        if (parentJobId.HasValue) {
118          ServiceLocator.GetAuthorizationManager().AuthorizeJobs(parentJobId.Value);
119        }
120        // If parentJobId is null, GetChildJobResults will filter the results for the current user
121        return jobManager.GetChildJobResults(parentJobId, recursive, includeParent);
122      }
123    }
124
125    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
126    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
127    public ResponseObject<HiveExperimentDtoList> GetHiveExperiments() {
128      using (contextFactory.GetContext(false)) {
129        return jobManager.GetHiveExperiments();
130      }
131    }
132
133    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
134    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
135    public ResponseObject<HiveExperimentDto> UpdateHiveExperiment(HiveExperimentDto hiveExperimentDto) {
136      using (contextFactory.GetContext()) {
137        if (hiveExperimentDto.UserId == Guid.Empty) {
138          hiveExperimentDto.UserId = ServiceLocator.GetAuthorizationManager().UserId;
139        } else {
140          ServiceLocator.GetAuthorizationManager().Authorize(hiveExperimentDto.UserId);
141        }
142        return jobManager.UpdateHiveExperiment(hiveExperimentDto);
143      }
144    }
145
146    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
147    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
148    public Response DeleteHiveExperiment(Guid hiveExperimentId) {
149      using (contextFactory.GetContext()) {
150        var hiveExperimentDto = DaoLocator.HiveExperimentDao.FindById(hiveExperimentId);
151        if (hiveExperimentDto != null) {
152          ServiceLocator.GetAuthorizationManager().Authorize(hiveExperimentDto.UserId);
153        }
154        return jobManager.DeleteHiveExperiment(hiveExperimentId);
155      }
156    }
157
158    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
159    [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
160    public ResponseObject<JobDto> AddChildJob(Guid parentJobId, SerializedJob serializedJob) {
161      using (contextFactory.GetContext()) {
162        ServiceLocator.GetAuthorizationManager().AuthorizeJobs(parentJobId);
163        return jobManager.AddChildJob(parentJobId, serializedJob);
164      }
165    }
166    #endregion
167  }
168}
Note: See TracBrowser for help on using the repository browser.