Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15628


Ignore:
Timestamp:
01/17/18 15:24:44 (7 years ago)
Author:
jzenisek
Message:

#2839

  • updated TaskDao towards independency of the formerly used Task-Resource assignment entity
  • updated several permission/assignment handling service methods for client
  • added AssignedJobResource DTO
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  
    107107        WHERE ProjectId IN ({0})
    108108    ";
     109    // tested
    109110    private const string CheckProjectGrantedForResourcesQueryString = @"
    110111    WITH rtree AS
     
    125126      FROM rtree, [AssignedProjectResource] apr
    126127      WHERE rtree.ParentResourceId = apr.ResourceId
    127       AND apr.ProjectId = {0}
     128      AND apr.ProjectId = '{0}'
    128129      UNION
    129130      SELECT apr.ResourceId
    130131      FROM [AssignedProjectResource] apr
    131       WHERE apr.ProjectId = {0}
     132      WHERE apr.ProjectId = '{0}'
    132133    )
    133134    ";
     
    146147      WHERE rtree.ParentResourceId = apr.ResourceId
    147148      AND rtree.ResourceId = res.ResourceId
    148       AND apr.ProjectId = {0}
     149      AND apr.ProjectId = '{0}'
    149150      UNION
    150151      SELECT res.*
    151152      FROM [AssignedProjectResource] apr, [Resource] res
    152153      WHERE apr.ResourceId = res.ResourceId
    153       AND apr.ProjectId = {0}
     154      AND apr.ProjectId = '{0}'
    154155    ";
    155156    private const string GetAllGrantedResourceIdsByProjectIdQueryString = @"
     
    166167    FROM rtree, [AssignedProjectResource] apr
    167168    WHERE rtree.ParentResourceId = apr.ResourceId
    168     AND apr.ProjectId = {0}
     169    AND apr.ProjectId = '{0}'
    169170    UNION
    170171    SELECT apr.ResourceId
    171172    FROM [AssignedProjectResource] apr
    172     WHERE apr.ProjectId = {0}
     173    WHERE apr.ProjectId = '{0}'
    173174    ";
    174175    private const string GetAllGrantedResourceIdsOfOwnedParentProjectsQueryString = @"
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectPermissionDao.cs

    r15577 r15628  
    7474    private const string DeleteByProjectIdAndGrantedUserIdsQueryString = @"
    7575      DELETE FROM [ProjectPermission]
    76       WHERE ProjectId = '{0}'
     76      WHERE ProjectId = {0}
    7777      AND GrantedUserId IN ({1});
    7878    ";
     
    8585      SELECT COUNT(pp.ProjectId)
    8686      FROM [ProjectPermission] pp
    87       WHERE pp.ProjectId = {0}
     87      WHERE pp.ProjectId = '{0}'
    8888      AND pp.GrantedUserId IN ({1})
    8989    ";
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/TaskDao.cs

    r15497 r15628  
    6464    /// <param name="finished">if true, all parent task which have FinishWhenChildJobsFinished=true are returned, otherwise only FinishWhenChildJobsFinished=false are returned</param>
    6565    /// <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) {
    6767      var query = from ar in AssignedTaskResourceTable
    6868                  where resourceIds.Contains(ar.ResourceId)
     
    8383    }
    8484
     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
    85108    public void UpdateExecutionTime(Guid taskId, double executionTime) {
    86109      DataContext.ExecuteCommand(UpdateExecutionTimeQuery, executionTime, DateTime.Now, taskId);
     
    96119
    97120    #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    ";
    98130    private const string GetWaitingTasksQueryString = @"
    99131      WITH pr AS (
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Converter.cs

    r15411 r15628  
    143143    #endregion
    144144
     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
    145166    #region JobPermission
    146167    public static DT.JobPermission ToDto(this DA.JobPermission source) {
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HeuristicLab.Services.Hive-3.3.csproj

    r15508 r15628  
    119119  <ItemGroup>
    120120    <Compile Include="Converter.cs" />
     121    <Compile Include="DataTransfer\AssignedJobResource.cs" />
    121122    <Compile Include="DataTransfer\AssignedProjectResource.cs" />
    122123    <Compile Include="DataTransfer\Command.cs" />
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs

    r15580 r15628  
    6969
    7070    #region Task Methods
    71     [Obsolete]
     71   
    7272    public Guid AddTask(DT.Task task, DT.TaskData taskData, IEnumerable<Guid> resourceIds) {
    7373      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
     
    397397    }
    398398
    399     [Obsolete]
    400399    public Guid AddJob(DT.Job jobDto) {
    401400      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
     
    497496          jobDto.CopyToEntity(job);
    498497
    499           // remove former resource assignments
    500           job.AssignedJobResources.Clear();
    501           // add resource assignments
    502           job.AssignedJobResources.AddRange(resourceIds.Select(
    503             x => new DA.AssignedJobResource {
    504               ResourceId = x
    505             }));
    506 
    507498          if (!exists) {
     499            // add resource assignments
     500            job.AssignedJobResources.AddRange(resourceIds.Select(
     501              x => new DA.AssignedJobResource {
     502                ResourceId = x
     503              }));
    508504            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              }));
    509520          }
    510521          pm.SubmitChanges();
     
    520531        var jobDao = pm.JobDao;
    521532        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
    523535          // entries in AssignedJobResource will be deleted by foreign key clause CASCADE ON DELETE
    524536          jobDao.Delete(jobId);
    525537          pm.SubmitChanges();
    526538        });
     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        );
    527553      }
    528554    }
     
    747773
    748774    public DT.Project GetProject(Guid projectId) {
    749       RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator);
     775      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    750776      var pm = PersistenceManager;
    751777      using (new PerformanceLogger("GetProject")) {
     
    758784    public IEnumerable<DT.Project> GetProjects() {
    759785      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    760       bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator);
     786      //bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator);
    761787      var pm = PersistenceManager;
    762788      using (new PerformanceLogger("GetProjects")) {
    763789        var projectDao = pm.ProjectDao;
    764         var projectPermissionDao = pm.ProjectPermissionDao;
     790        //var projectPermissionDao = pm.ProjectPermissionDao;
    765791        var currentUserId = UserManager.CurrentUserId;
    766792        var userAndGroupIds = new List<Guid> { currentUserId };
     
    820846        pm.UseTransaction(() => {
    821847          var project = projectDao.GetById(projectId);
     848          if (project == null) return;
     849          //if (project.ProjectPermissions == null) project.ProjectPermissions = new System.Data.Linq.EntitySet<DA.ProjectPermission>();
    822850          var projectPermissions = project.ProjectPermissions.Select(x => x.GrantedUserId);
    823851          var addedPermissions = grantedUserIds.Except(projectPermissions);
     
    10371065    public IEnumerable<DT.AssignedProjectResource> GetAssignedResourcesForProject(Guid projectId) {
    10381066      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);
    10391081      var pm = PersistenceManager;
    10401082      using (new PerformanceLogger("GetAssignedResourcesForProject")) {
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Manager/AuthorizationManager.cs

    r15577 r15628  
    9696      var projectDao = pm.ProjectDao;
    9797      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();
    10399        if(!projectBranch.Select(x => x.OwnerUserId).Contains(currentUserId)
    104100            && !RoleVerifier.IsInRole(HiveRoles.Administrator)) {
     
    129125
    130126        // check if user is owner of a parent project
    131         var projectBranch = projectDao.GetParentProjectsById(projectId);
     127        var projectBranch = projectDao.GetParentProjectsById(projectId).ToList();
    132128        if (!projectBranch.Select(x => x.OwnerUserId).Contains(currentUserId)
    133129            && !RoleVerifier.IsInRole(HiveRoles.Administrator)) {
     
    136132
    137133        // 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();
    139135        if(resourceIds.Except(grantedResourceIds).Any()) {
    140136          throw new SecurityException(NOT_AUTHORIZED_USERRESOURCE);
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/ServiceContracts/IHiveService.cs

    r15577 r15628  
    3131  public interface IHiveService {
    3232    #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);
    3538
    3639    [OperationContract]
     
    7780    IEnumerable<Job> GetJobs();
    7881
    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);
    8493
    8594    [OperationContract]
    8695    void DeleteJob(Guid JobId);
     96
     97    [OperationContract]
     98    IEnumerable<AssignedJobResource> GetAssignedResourcesForJob(Guid jobId);
    8799    #endregion
    88100
     
    178190    [OperationContract]
    179191    IEnumerable<AssignedProjectResource> GetAssignedResourcesForProject(Guid projectId);
     192
     193    [OperationContract]
     194    IEnumerable<AssignedProjectResource> GetAssignedResourcesForProjectAdministration(Guid projectId);
    180195    #endregion
    181196
Note: See TracChangeset for help on using the changeset viewer.