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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Security.Permissions;
|
---|
26 | using HeuristicLab.Hive.Contracts;
|
---|
27 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
28 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
29 | using HeuristicLab.Hive.Contracts.ResponseObjects;
|
---|
30 | using HeuristicLab.Hive.Server.DataAccess;
|
---|
31 |
|
---|
32 | namespace 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.User)]
|
---|
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.User)]
|
---|
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.User)]
|
---|
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.User)]
|
---|
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.User)]
|
---|
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.User)]
|
---|
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.User)]
|
---|
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.User)]
|
---|
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.User)]
|
---|
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.User)]
|
---|
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.User)]
|
---|
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.User)]
|
---|
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.User)]
|
---|
160 | public Response DeleteJob(Guid jobId) {
|
---|
161 | using (contextFactory.GetContext()) {
|
---|
162 | var jobDto = DaoLocator.JobDao.FindById(jobId);
|
---|
163 | if (jobId != null) {
|
---|
164 | ServiceLocator.GetAuthorizationManager().Authorize(jobDto.UserId);
|
---|
165 | }
|
---|
166 | return jobManager.DeleteJob(jobId);
|
---|
167 | }
|
---|
168 | }
|
---|
169 |
|
---|
170 | [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
|
---|
171 | [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.User)]
|
---|
172 | public ResponseObject<JobDto> AddChildJob(Guid parentJobId, SerializedJob serializedJob) {
|
---|
173 | using (contextFactory.GetContext()) {
|
---|
174 | ServiceLocator.GetAuthorizationManager().AuthorizeJobs(parentJobId);
|
---|
175 | return jobManager.AddChildJob(parentJobId, serializedJob);
|
---|
176 | }
|
---|
177 | }
|
---|
178 | #endregion
|
---|
179 | }
|
---|
180 | }
|
---|