1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 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.Web.Http;
|
---|
26 | using HeuristicLab.Services.Access;
|
---|
27 | using HeuristicLab.Services.Hive;
|
---|
28 | using HeuristicLab.Services.Hive.DataAccess.Interfaces;
|
---|
29 | using DTO = HeuristicLab.Services.WebApp.Statistics.WebApi.DataTransfer;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Services.WebApp.Statistics.WebApi {
|
---|
32 |
|
---|
33 | [Authorize]
|
---|
34 | public class DataController : ApiController {
|
---|
35 |
|
---|
36 | private IPersistenceManager PersistenceManager {
|
---|
37 | get { return ServiceLocator.Instance.PersistenceManager; }
|
---|
38 | }
|
---|
39 |
|
---|
40 | private IUserManager UserManager {
|
---|
41 | get { return ServiceLocator.Instance.UserManager; }
|
---|
42 | }
|
---|
43 | private IRoleVerifier RoleVerifier {
|
---|
44 | get { return ServiceLocator.Instance.RoleVerifier; }
|
---|
45 | }
|
---|
46 | private IAuthorizationManager AuthorizationManager {
|
---|
47 | get { return ServiceLocator.Instance.AuthorizationManager; }
|
---|
48 | }
|
---|
49 |
|
---|
50 | public IEnumerable<DTO.Job> GetJobs() {
|
---|
51 | return GetJobsByUserId(UserManager.CurrentUserId);
|
---|
52 | }
|
---|
53 |
|
---|
54 | public IEnumerable<DTO.Job> GetJobsByUserId(Guid id) {
|
---|
55 | if (id != UserManager.CurrentUserId) {
|
---|
56 | RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator);
|
---|
57 | }
|
---|
58 | using (var pm = PersistenceManager) {
|
---|
59 | return pm.UseTransaction(() => {
|
---|
60 | var dimJobDao = pm.DimJobDao;
|
---|
61 | return dimJobDao.GetByUserId(id).Select(x => new DTO.Job {
|
---|
62 | Id = x.JobId,
|
---|
63 | Name = x.JobName,
|
---|
64 | DateCreated = x.DateCreated
|
---|
65 | }).ToList();
|
---|
66 | });
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | public IEnumerable<DTO.Task> GetTasksByJobId(Guid id) {
|
---|
71 | using (var pm = PersistenceManager) {
|
---|
72 | return pm.UseTransaction(() => {
|
---|
73 | var dimJobDao = pm.JobDao;
|
---|
74 | var factTaskDao = pm.FactTaskDao;
|
---|
75 | var job = dimJobDao.GetById(id);
|
---|
76 | if (job != null && job.OwnerUserId != UserManager.CurrentUserId) {
|
---|
77 | RoleVerifier.AuthenticateForAllRoles(HiveRoles.Administrator);
|
---|
78 | }
|
---|
79 | return factTaskDao.GetByJobId(id).Select(x => new DTO.Task {
|
---|
80 | Id = x.TaskId,
|
---|
81 | CalculatingTime = x.CalculatingTime,
|
---|
82 | WaitingTime = x.WaitingTime,
|
---|
83 | TransferTime = x.TransferTime,
|
---|
84 | InitialWaitingTime = x.InitialWaitingTime,
|
---|
85 | NumCalculationRuns = x.NumCalculationRuns,
|
---|
86 | NumRetries = x.NumRetries,
|
---|
87 | CoresRequired = x.CoresRequired,
|
---|
88 | MemoryRequired = x.MemoryRequired,
|
---|
89 | Priority = x.Priority,
|
---|
90 | State = x.TaskState.ToString(),
|
---|
91 | LastClientId = x.LastClientId,
|
---|
92 | StartTime = x.StartTime,
|
---|
93 | EndTime = x.EndTime,
|
---|
94 | Exception = x.Exception
|
---|
95 | }).ToList();
|
---|
96 | });
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | }
|
---|
101 | }
|
---|