Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/15/17 17:51:28 (6 years ago)
Author:
jzenisek
Message:

#2839

  • worked on Job operations add&update
  • worked on ProjectPermission handling
  • worked on Project-Resource assignment
Location:
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/AssignedJobResourceDao.cs

    r15528 r15530  
    2222    }
    2323
    24     public bool CheckJobGrantedForResources(Guid jobId, Guid[] resourceIds) {
    25       return DataContext.ExecuteQuery<int>(CheckJobGrantedForResourcesQueryString).Count() > 0;
     24    public bool CheckJobGrantedForResources(Guid jobId, IEnumerable<Guid> resourceIds) {
     25      string paramResourceIds = string.Join(",", resourceIds.Select(x => string.Format("'{0}'", x)));
     26      if (!string.IsNullOrWhiteSpace(paramResourceIds)) {
     27        string queryString = string.Format(CheckJobGrantedForResourcesQueryString, jobId, paramResourceIds);
     28        return DataContext.ExecuteQuery<int>(queryString).Count() == 0;
     29      }
     30      return false;
    2631    }
    2732
     
    4348        SELECT ResourceId, ParentResourceId
    4449        FROM [Resource]
    45         WHERE ResourceId = {0}
     50        WHERE ResourceId = {1}
    4651        UNION ALL
    4752        SELECT r.ResourceId, r.ParentResourceId
     
    5257      FROM rbranch, AssignedJobResource ajr
    5358      WHERE rbranch.ResourceId = ajr.ResourceId
    54       AND ajr.JobId = {1}
     59      AND ajr.JobId = {0}
    5560    ";
    5661    private const string CheckTaskGrantedForResourceQueryString = @"
     
    5863        SELECT ResourceId, ParentResourceId
    5964        FROM [Resource]
    60         WHERE ResourceId = {0}
     65        WHERE ResourceId = {1}
    6166        UNION ALL
    6267        SELECT r.ResourceId, r.ParentResourceId
     
    6873      WHERE rbranch.ResourceId = ajr.ResourceId
    6974      AND ajr.JobId = t.JobId
    70       AND t.JobId = {1}
     75      AND t.JobId = {0}
    7176    ";
    7277    private const string CheckJobGrantedForResourcesQueryString = @"
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/AssignedProjectResourceDao.cs

    r15411 r15530  
    4545    }
    4646
     47    public bool CheckProjectGrantedForResources(Guid projectId, IEnumerable<Guid> resourceIds) {
     48      string paramResourceIds = string.Join(",", resourceIds.Select(x => string.Format("'{0}'", x)));
     49      if (!string.IsNullOrWhiteSpace(paramResourceIds)) {
     50        string queryString = string.Format(CheckProjectGrantedForResourcesQueryString, projectId, paramResourceIds);
     51        return DataContext.ExecuteQuery<int>(queryString).Count() == 0;
     52      }
     53      return false;
     54    }
     55
     56    public IEnumerable<Resource> GetAllGrantedResourcesByProjectId(Guid projectId) {
     57      return DataContext.ExecuteQuery<Resource>(GetAllGrantedResourcesByProjectIdQueryString, projectId);
     58    }
     59
     60    public IEnumerable<Guid> GetAllGrantedResourceIdsByProjectId(Guid projectId) {
     61      return DataContext.ExecuteQuery<Guid>(GetAllGrantedResourceIdsByProjectIdQueryString, projectId);
     62    }
     63
    4764    #region Compiled queries
    4865    private static readonly Func<DataContext, Guid, IEnumerable<AssignedProjectResource>> GetByProjectIdGetByIdQuery =
     
    5875         WHERE ProjectId = '{0}'
    5976           AND ResourceId IN ({1});";
     77    private const string CheckProjectGrantedForResourcesQueryString = @"
     78    WITH rtree AS
     79    (
     80      SELECT ResourceId, ParentResourceId
     81      FROM [Resource]
     82      UNION ALL
     83      SELECT rt.ResourceId, r.ParentResourceId
     84      FROM [Resource] r
     85      JOIN rtree rt ON rt.ParentResourceId = r.ResourceId
     86    )
     87    SELECT r.ResourceId
     88    FROM [Resource] r
     89    WHERE r.ResourceId IN ({1})
     90    EXCEPT
     91    (
     92      SELECT rtree.ResourceId
     93      FROM rtree, [AssignedProjectResource] apr
     94      WHERE rtree.ParentResourceId = apr.ResourceId
     95      AND apr.ProjectId = {0}
     96      UNION
     97      SELECT apr.ResourceId
     98      FROM [AssignedProjectResource] apr
     99      WHERE apr.ProjectId = {0}
     100    )
     101    ";
     102    private const string GetAllGrantedResourcesByProjectIdQueryString = @"
     103      WITH rtree AS
     104      (
     105        SELECT ResourceId, ParentResourceId
     106        FROM [Resource]
     107        UNION ALL
     108        SELECT rt.ResourceId, r.ParentResourceId
     109        FROM [Resource] r
     110        JOIN rtree rt ON rt.ParentResourceId = r.ResourceId
     111      )
     112      SELECT res.*
     113      FROM rtree, [AssignedProjectResource] apr, [Resource] res
     114      WHERE rtree.ParentResourceId = apr.ResourceId
     115      AND rtree.ResourceId = res.ResourceId
     116      AND apr.ProjectId = {0}
     117      UNION
     118      SELECT res.*
     119      FROM [AssignedProjectResource] apr, [Resource] res
     120      WHERE apr.ResourceId = res.ResourceId
     121      AND apr.ProjectId = {0}
     122    ";
     123    private const string GetAllGrantedResourceIdsByProjectIdQueryString = @"
     124    WITH rtree AS
     125    (
     126      SELECT ResourceId, ParentResourceId
     127      FROM [Resource]
     128      UNION ALL
     129      SELECT rt.ResourceId, r.ParentResourceId
     130      FROM [Resource] r
     131      JOIN rtree rt ON rt.ParentResourceId = r.ResourceId
     132    )
     133    SELECT rtree.ResourceId
     134    FROM rtree, [AssignedProjectResource] apr
     135    WHERE rtree.ParentResourceId = apr.ResourceId
     136    AND apr.ProjectId = {0}
     137    UNION
     138    SELECT apr.ResourceId
     139    FROM [AssignedProjectResource] apr
     140    WHERE apr.ProjectId = {0}
     141    ";
    60142    #endregion
    61143  }
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectPermissionDao.cs

    r15379 r15530  
    3737    }
    3838
    39     public void DeleteByProjectAndGrantedUserId(Guid projectId, IEnumerable<Guid> grantedUserId) {
    40       string paramIds = string.Join(",", grantedUserId.Select(x => string.Format("'{0}'", x)));
     39    public bool CheckUserGrantedForProject(Guid projectId, IEnumerable<Guid> userAndGroupIds) {
     40      string paramUserAndGroupIds = string.Join(",", userAndGroupIds.Select(x => string.Format("'{0}'", x)));
     41      if(!string.IsNullOrWhiteSpace(paramUserAndGroupIds)) {
     42        string queryString = string.Format(CheckUserGrantedForProjectQueryString, projectId, paramUserAndGroupIds);
     43        return DataContext.ExecuteQuery<int>(queryString).First() > 0;
     44      }
     45      return false;
     46    }
     47
     48    public void DeleteByProjectIdAndGrantedUserIds(Guid projectId, IEnumerable<Guid> grantedUserIds) {
     49      string paramIds = string.Join(",", grantedUserIds.Select(x => string.Format("'{0}'", x)));
    4150      if (!string.IsNullOrWhiteSpace(paramIds)) {
    42         string query = string.Format(DeleteByGrantedUserQuery, projectId, paramIds);
     51        string query = string.Format(DeleteByProjectIdAndGrantedUserIdsQueryString, projectId, paramIds);
     52        DataContext.ExecuteCommand(query);
     53      }
     54    }
     55
     56    public void DeleteByProjectIdsAndGrantedUserIds(IEnumerable<Guid> projectIds, IEnumerable<Guid> grantedUserIds) {
     57      string paramProjectIds = string.Join(",", projectIds.Select(x => string.Format("'{0}'", x)));
     58      string paramUserIds = string.Join(",", grantedUserIds.Select(x => string.Format("'{0}'", x)));
     59      if (!string.IsNullOrWhiteSpace(paramProjectIds) && !string.IsNullOrWhiteSpace(paramUserIds)) {
     60        string query = string.Format(DeleteByProjectIdsAndGrantedUserIdsQueryString, paramProjectIds, paramUserIds);
    4361        DataContext.ExecuteCommand(query);
    4462      }
     
    5472
    5573    #region String queries
    56     private const string DeleteByGrantedUserQuery =
    57       @"DELETE FROM [ProjectPermission]
    58          WHERE ProjectId = '{0}'
    59            AND GrantedUserId IN ({1});";
     74    private const string DeleteByProjectIdAndGrantedUserIdsQueryString = @"
     75      DELETE FROM [ProjectPermission]
     76      WHERE ProjectId = '{0}'
     77      AND GrantedUserId IN ({1});
     78    ";
     79    private const string DeleteByProjectIdsAndGrantedUserIdsQueryString = @"
     80      DELETE FROM [ProjectPermission]
     81      WHERE ProjectId IN '({0})'
     82      AND GrantedUserId IN ({1});
     83    ";
     84    private const string CheckUserGrantedForProjectQueryString = @"
     85      SELECT COUNT(pp.ProjectId)
     86      FROM [ProjectPermission] pp
     87      WHERE pp.ProjectId = {0}
     88      AND pp.GrantedUserId IN ({1})
     89    ";
    6090    #endregion
    6191  }
Note: See TracChangeset for help on using the changeset viewer.