Changeset 15628
- Timestamp:
- 01/17/18 15:24:44 (7 years ago)
- Location:
- branches/HiveProjectManagement
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/AssignedProjectResourceDao.cs
r15577 r15628 107 107 WHERE ProjectId IN ({0}) 108 108 "; 109 // tested 109 110 private const string CheckProjectGrantedForResourcesQueryString = @" 110 111 WITH rtree AS … … 125 126 FROM rtree, [AssignedProjectResource] apr 126 127 WHERE rtree.ParentResourceId = apr.ResourceId 127 AND apr.ProjectId = {0}128 AND apr.ProjectId = '{0}' 128 129 UNION 129 130 SELECT apr.ResourceId 130 131 FROM [AssignedProjectResource] apr 131 WHERE apr.ProjectId = {0}132 WHERE apr.ProjectId = '{0}' 132 133 ) 133 134 "; … … 146 147 WHERE rtree.ParentResourceId = apr.ResourceId 147 148 AND rtree.ResourceId = res.ResourceId 148 AND apr.ProjectId = {0}149 AND apr.ProjectId = '{0}' 149 150 UNION 150 151 SELECT res.* 151 152 FROM [AssignedProjectResource] apr, [Resource] res 152 153 WHERE apr.ResourceId = res.ResourceId 153 AND apr.ProjectId = {0}154 AND apr.ProjectId = '{0}' 154 155 "; 155 156 private const string GetAllGrantedResourceIdsByProjectIdQueryString = @" … … 166 167 FROM rtree, [AssignedProjectResource] apr 167 168 WHERE rtree.ParentResourceId = apr.ResourceId 168 AND apr.ProjectId = {0}169 AND apr.ProjectId = '{0}' 169 170 UNION 170 171 SELECT apr.ResourceId 171 172 FROM [AssignedProjectResource] apr 172 WHERE apr.ProjectId = {0}173 WHERE apr.ProjectId = '{0}' 173 174 "; 174 175 private const string GetAllGrantedResourceIdsOfOwnedParentProjectsQueryString = @" -
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectPermissionDao.cs
r15577 r15628 74 74 private const string DeleteByProjectIdAndGrantedUserIdsQueryString = @" 75 75 DELETE FROM [ProjectPermission] 76 WHERE ProjectId = '{0}'76 WHERE ProjectId = {0} 77 77 AND GrantedUserId IN ({1}); 78 78 "; … … 85 85 SELECT COUNT(pp.ProjectId) 86 86 FROM [ProjectPermission] pp 87 WHERE pp.ProjectId = {0}87 WHERE pp.ProjectId = '{0}' 88 88 AND pp.GrantedUserId IN ({1}) 89 89 "; -
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/TaskDao.cs
r15497 r15628 64 64 /// <param name="finished">if true, all parent task which have FinishWhenChildJobsFinished=true are returned, otherwise only FinishWhenChildJobsFinished=false are returned</param> 65 65 /// <returns></returns> 66 public IEnumerable<Task> GetParentTasks (IEnumerable<Guid> resourceIds, int count, bool finished) {66 public IEnumerable<Task> GetParentTasks_Old(IEnumerable<Guid> resourceIds, int count, bool finished) { 67 67 var query = from ar in AssignedTaskResourceTable 68 68 where resourceIds.Contains(ar.ResourceId) … … 83 83 } 84 84 85 /// <summary> 86 /// returns all parent tasks which are waiting for their child tasks to finish 87 /// </summary> 88 /// <param name="resourceIds">list of resourceids which for which the task should be valid</param> 89 /// <param name="count">maximum number of task to return</param> 90 /// <param name="finished">if true, all parent task which have FinishWhenChildJobsFinished=true are returned, otherwise only FinishWhenChildJobsFinished=false are returned</param> 91 /// <returns></returns> 92 public IEnumerable<Task> GetParentTasks(IEnumerable<Guid> resourceIds, int count, bool finished) { 93 var query = from t in Table 94 where t.State == TaskState.Waiting 95 && t.IsParentTask 96 && !t.Job.AssignedJobResources.Select(x => x.ResourceId).Except(resourceIds).Any() 97 && t.FinishWhenChildJobsFinished == finished 98 && t.ChildJobs.Any() 99 && t.ChildJobs.All(x => 100 x.State == TaskState.Finished 101 || x.State == TaskState.Aborted 102 || x.State == TaskState.Failed) 103 orderby t.Priority descending 104 select t; 105 return count == 0 ? query.ToArray() : query.Take(count).ToArray(); 106 } 107 85 108 public void UpdateExecutionTime(Guid taskId, double executionTime) { 86 109 DataContext.ExecuteCommand(UpdateExecutionTimeQuery, executionTime, DateTime.Now, taskId); … … 96 119 97 120 #region String queries 121 private const string GetParentTasksQueryString = @" 122 SELECT t.* FROM [Task] t, [Job] j, [AssignedJobResource] ajr 123 WHERE t.IsParentTask = 1 124 AND t.TaskState = 'Waiting' 125 AND t.JobId = j.JobId 126 AND j.JobId = ajr.JobId 127 AND t.FinishWhenChildJobsFinished = 1 128 ... TODO (not necessary) 129 "; 98 130 private const string GetWaitingTasksQueryString = @" 99 131 WITH pr AS ( -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Converter.cs
r15411 r15628 143 143 #endregion 144 144 145 #region AssignedJobResource 146 public static DT.AssignedJobResource ToDto(this DA.AssignedJobResource source) { 147 if (source == null) return null; 148 return new DT.AssignedJobResource { 149 JobId = source.JobId, 150 ResourceId = source.ResourceId 151 }; 152 } 153 public static DA.AssignedJobResource ToEntity(this DT.AssignedJobResource source) { 154 if (source == null) return null; 155 var result = new DA.AssignedJobResource(); 156 source.CopyToEntity(result); 157 return result; 158 } 159 public static void CopyToEntity(this DT.AssignedJobResource source, DA.AssignedJobResource target) { 160 if ((source == null) || (target == null)) return; 161 target.JobId = source.JobId; 162 target.ResourceId = source.ResourceId; 163 } 164 #endregion 165 145 166 #region JobPermission 146 167 public static DT.JobPermission ToDto(this DA.JobPermission source) { -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HeuristicLab.Services.Hive-3.3.csproj
r15508 r15628 119 119 <ItemGroup> 120 120 <Compile Include="Converter.cs" /> 121 <Compile Include="DataTransfer\AssignedJobResource.cs" /> 121 122 <Compile Include="DataTransfer\AssignedProjectResource.cs" /> 122 123 <Compile Include="DataTransfer\Command.cs" /> -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs
r15580 r15628 69 69 70 70 #region Task Methods 71 [Obsolete]71 72 72 public Guid AddTask(DT.Task task, DT.TaskData taskData, IEnumerable<Guid> resourceIds) { 73 73 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); … … 397 397 } 398 398 399 [Obsolete]400 399 public Guid AddJob(DT.Job jobDto) { 401 400 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); … … 497 496 jobDto.CopyToEntity(job); 498 497 499 // remove former resource assignments500 job.AssignedJobResources.Clear();501 // add resource assignments502 job.AssignedJobResources.AddRange(resourceIds.Select(503 x => new DA.AssignedJobResource {504 ResourceId = x505 }));506 507 498 if (!exists) { 499 // add resource assignments 500 job.AssignedJobResources.AddRange(resourceIds.Select( 501 x => new DA.AssignedJobResource { 502 ResourceId = x 503 })); 508 504 jobDao.Save(job); 505 } else { 506 var addedJobResourceIds = resourceIds.Except(job.AssignedJobResources.Select(x => x.ResourceId)); 507 var removedJobResourceIds = job.AssignedJobResources.Select(x => x.ResourceId).Except(resourceIds); 508 509 // remove resource assignments 510 foreach(var rid in removedJobResourceIds) { 511 var ajr = job.AssignedJobResources.Where(x => x.ResourceId == rid).SingleOrDefault(); 512 if (ajr != null) job.AssignedJobResources.Remove(ajr); 513 } 514 515 // add resource assignments 516 job.AssignedJobResources.AddRange(addedJobResourceIds.Select( 517 x => new DA.AssignedJobResource { 518 ResourceId = x 519 })); 509 520 } 510 521 pm.SubmitChanges(); … … 520 531 var jobDao = pm.JobDao; 521 532 pm.UseTransaction(() => { 522 // child tasks will be deleted by db-trigger 533 // not necessary anymore: child tasks will be deleted by db-trigger 534 // now: tasks are deleted by jobId 523 535 // entries in AssignedJobResource will be deleted by foreign key clause CASCADE ON DELETE 524 536 jobDao.Delete(jobId); 525 537 pm.SubmitChanges(); 526 538 }); 539 } 540 } 541 542 public IEnumerable<DT.AssignedJobResource> GetAssignedResourcesForJob(Guid jobId) { 543 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 544 AuthorizationManager.AuthorizeForJob(jobId, DT.Permission.Full); 545 var pm = PersistenceManager; 546 var assignedJobResourceDao = pm.AssignedJobResourceDao; 547 using (new PerformanceLogger("GetAssignedResourcesForProject")) { 548 return pm.UseTransaction(() => 549 assignedJobResourceDao.GetByJobId(jobId) 550 .Select(x => x.ToDto()) 551 .ToList() 552 ); 527 553 } 528 554 } … … 747 773 748 774 public DT.Project GetProject(Guid projectId) { 749 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator );775 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 750 776 var pm = PersistenceManager; 751 777 using (new PerformanceLogger("GetProject")) { … … 758 784 public IEnumerable<DT.Project> GetProjects() { 759 785 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 760 bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator);786 //bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator); 761 787 var pm = PersistenceManager; 762 788 using (new PerformanceLogger("GetProjects")) { 763 789 var projectDao = pm.ProjectDao; 764 var projectPermissionDao = pm.ProjectPermissionDao;790 //var projectPermissionDao = pm.ProjectPermissionDao; 765 791 var currentUserId = UserManager.CurrentUserId; 766 792 var userAndGroupIds = new List<Guid> { currentUserId }; … … 820 846 pm.UseTransaction(() => { 821 847 var project = projectDao.GetById(projectId); 848 if (project == null) return; 849 //if (project.ProjectPermissions == null) project.ProjectPermissions = new System.Data.Linq.EntitySet<DA.ProjectPermission>(); 822 850 var projectPermissions = project.ProjectPermissions.Select(x => x.GrantedUserId); 823 851 var addedPermissions = grantedUserIds.Except(projectPermissions); … … 1037 1065 public IEnumerable<DT.AssignedProjectResource> GetAssignedResourcesForProject(Guid projectId) { 1038 1066 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 1067 AuthorizationManager.AuthorizeUserForProjectUse(UserManager.CurrentUserId, projectId); 1068 var pm = PersistenceManager; 1069 using (new PerformanceLogger("GetAssignedResourcesForProject")) { 1070 var assignedProjectResourceDao = pm.AssignedProjectResourceDao; 1071 return pm.UseTransaction(() => assignedProjectResourceDao.GetByProjectId(projectId) 1072 .Select(x => x.ToDto()) 1073 .ToList() 1074 ); 1075 } 1076 } 1077 1078 public IEnumerable<DT.AssignedProjectResource> GetAssignedResourcesForProjectAdministration(Guid projectId) { 1079 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 1080 AuthorizationManager.AuthorizeForProjectAdministration(projectId); 1039 1081 var pm = PersistenceManager; 1040 1082 using (new PerformanceLogger("GetAssignedResourcesForProject")) { -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Manager/AuthorizationManager.cs
r15577 r15628 96 96 var projectDao = pm.ProjectDao; 97 97 pm.UseTransaction(() => { 98 // check if project exists (not necessary) 99 var project = projectDao.GetById(projectId); 100 if (project == null) throw new SecurityException(NOT_AUTHORIZED_USERPROJECT); 101 102 var projectBranch = projectDao.GetCurrentAndParentProjectsById(projectId); 98 var projectBranch = projectDao.GetCurrentAndParentProjectsById(projectId).ToList(); 103 99 if(!projectBranch.Select(x => x.OwnerUserId).Contains(currentUserId) 104 100 && !RoleVerifier.IsInRole(HiveRoles.Administrator)) { … … 129 125 130 126 // check if user is owner of a parent project 131 var projectBranch = projectDao.GetParentProjectsById(projectId) ;127 var projectBranch = projectDao.GetParentProjectsById(projectId).ToList(); 132 128 if (!projectBranch.Select(x => x.OwnerUserId).Contains(currentUserId) 133 129 && !RoleVerifier.IsInRole(HiveRoles.Administrator)) { … … 136 132 137 133 // check if the all argument resourceIds are among the assigned resources of the owned projects 138 var grantedResourceIds = assignedProjectResourceDao.GetAllGrantedResourceIdsOfOwnedParentProjects(projectId, currentUserId) ;134 var grantedResourceIds = assignedProjectResourceDao.GetAllGrantedResourceIdsOfOwnedParentProjects(projectId, currentUserId).ToList(); 139 135 if(resourceIds.Except(grantedResourceIds).Any()) { 140 136 throw new SecurityException(NOT_AUTHORIZED_USERRESOURCE); -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/ServiceContracts/IHiveService.cs
r15577 r15628 31 31 public interface IHiveService { 32 32 #region Task Methods 33 [OperationContract] 34 Guid AddTask(Task task, TaskData taskData, IEnumerable<Guid> resourceIds); 33 //[OperationContract] 34 //Guid AddTask(Task task, TaskData taskData, IEnumerable<Guid> resourceIds); 35 36 [OperationContract] 37 Guid AddTask(Task task, TaskData taskData); 35 38 36 39 [OperationContract] … … 77 80 IEnumerable<Job> GetJobs(); 78 81 79 [OperationContract] 80 Guid AddJob(Job jobDto); 81 82 [OperationContract] 83 void UpdateJob(Job jobDto); 82 //[OperationContract] 83 //Guid AddJob(Job jobDto); 84 85 [OperationContract] 86 Guid AddJob(Job jobDto, IEnumerable<Guid> resourceIds); 87 88 //[OperationContract] 89 //void UpdateJob(Job jobDto); 90 91 [OperationContract] 92 void UpdateJob(Job jobDto, IEnumerable<Guid> resourceIds); 84 93 85 94 [OperationContract] 86 95 void DeleteJob(Guid JobId); 96 97 [OperationContract] 98 IEnumerable<AssignedJobResource> GetAssignedResourcesForJob(Guid jobId); 87 99 #endregion 88 100 … … 178 190 [OperationContract] 179 191 IEnumerable<AssignedProjectResource> GetAssignedResourcesForProject(Guid projectId); 192 193 [OperationContract] 194 IEnumerable<AssignedProjectResource> GetAssignedResourcesForProjectAdministration(Guid projectId); 180 195 #endregion 181 196
Note: See TracChangeset
for help on using the changeset viewer.