Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/05/18 15:13:25 (7 years ago)
Author:
jzenisek
Message:

#2839 worked on service side mgmt of project-resource assignments and project-user permissions

Location:
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos
Files:
5 edited

Legend:

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

    r15552 r15577  
    3030    }
    3131
     32    public void DeleteByProjectIds(IEnumerable<Guid> projectIds) {
     33      string paramProjectIds = string.Join(",", projectIds.Select(x => string.Format("'{0}'", x)));
     34      if (!string.IsNullOrWhiteSpace(paramProjectIds)) {
     35        string queryString = string.Format(DeleteByProjectIdsQueryString, paramProjectIds);
     36        DataContext.ExecuteCommand(queryString);
     37      }
     38    }
     39
    3240    public void DeleteByProjectIdsAndUserIds(IEnumerable<Guid> projectIds, IEnumerable<Guid> userIds) {
    3341      string paramProjectIds = string.Join(",", projectIds.Select(x => string.Format("'{0}'", x)));
    34       string paramUserIds = string.Join(",", userIds.Select(x => string.Format("'{0}'", x)));
     42      string paramUserIds = string.Join(",", userIds.ToList().Select(x => string.Format("'{0}'", x)));
    3543      if (!string.IsNullOrWhiteSpace(paramProjectIds) && !string.IsNullOrWhiteSpace(paramUserIds)) {
    3644        string queryString = string.Format(DeleteByProjectIdsAndUserIdsQueryString, paramProjectIds, paramUserIds);
     
    8391    #region String queries
    8492    private const string DeleteByProjectIdQueryString = @"
    85       DELETE FROM [AssignedJobResource] ajr
    86       WHERE ajr.JobId IN
    87         (
    88           SELECT j.JobId
    89           FROM [Job] j
    90           WHERE j.ProjectId = {0}
     93      DELETE FROM [AssignedJobResource]
     94      WHERE JobId IN
     95        (
     96          SELECT j.JobId
     97          FROM [Job] j
     98          WHERE j.ProjectId = '{0}'
    9199        )
    92100    ";
    93101    private const string DeleteByProjectIdAndUserIdsQueryString = @"
    94       DELETE FROM [AssignedJobResource] ajr
    95       WHERE ajr.JobId IN
    96         (
    97           SELECT j.JobId
    98           FROM [Job] j
    99           WHERE j.ProjectId = {0}
     102      DELETE FROM [AssignedJobResource]
     103      WHERE JobId IN
     104        (
     105          SELECT j.JobId
     106          FROM [Job] j
     107          WHERE j.ProjectId = '{0}'
    100108          AND j.OwnerUserId IN ({1})
    101109        )
    102110    ";
     111    private const string DeleteByProjectIdsQueryString = @"
     112      DELETE FROM [AssignedJobResource]
     113      WHERE JobId IN
     114        (
     115          SELECT j.JobId
     116          FROM [Job] j
     117          WHERE j.ProjectId IN ({0})
     118        )
     119    ";
    103120    private const string DeleteByProjectIdsAndUserIdsQueryString = @"
    104       DELETE FROM [AssignedJobResource] ajr
    105       WHERE ajr.JobId IN
     121      DELETE FROM [AssignedJobResource]
     122      WHERE JobId IN
    106123        (
    107124          SELECT j.JobId
     
    112129    ";
    113130    private const string DeleteByProjectIdAndResourceIdsQueryString = @"
    114       DELETE FROM [AssignedJobResource] ajr
    115       WHERE ajr.JobId IN
    116         (
    117           SELECT j.JobId
    118           FROM [Job] j
    119           WHERE j.ProjectId = {0}
    120         )
    121       AND ajr.ResourceId IN ({1})
     131      DELETE FROM [AssignedJobResource]
     132      WHERE JobId IN
     133        (
     134          SELECT j.JobId
     135          FROM [Job] j
     136          WHERE j.ProjectId = '{0}'
     137        )
     138      AND ResourceId IN ({1})
    122139    ";
    123140    private const string DeleteByProjectIdsAndResourceIdsQueryString = @"
    124       DELETE FROM [AssignedJobResource] ajr
    125       WHERE ajr.JobId IN
     141      DELETE FROM [AssignedJobResource]
     142      WHERE JobId IN
    126143        (
    127144          SELECT j.JobId
     
    129146          WHERE j.ProjectId IN ({0})
    130147        )
    131       AND ajr.ResourceId IN ({1})
     148      AND ResourceId IN ({1})
    132149    ";
    133150    private const string CheckJobGrantedForResourceQueryString = @"
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/AssignedProjectResourceDao.cs

    r15546 r15577  
    3838
    3939    public void DeleteByProjectIdAndResourceIds(Guid projectId, IEnumerable<Guid> resourceIds) {
    40       string paramIds = string.Join(",", resourceIds.Select(x => string.Format("'{0}'", x)));
     40      string paramIds = string.Join(",", resourceIds.ToList().Select(x => string.Format("'{0}'", x)));
    4141      if (!string.IsNullOrWhiteSpace(paramIds)) {
    4242        string query = string.Format(DeleteByProjectIdAndResourceIdsQueryString, projectId, paramIds);
     
    4646
    4747    public void DeleteByProjectIdsAndResourceIds(IEnumerable<Guid> projectIds, IEnumerable<Guid> resourceIds) {
    48       string paramProjectIds = string.Join(",", projectIds.Select(x => string.Format("'{0}'", x)));
    49       string paramResourceIds = string.Join(",", resourceIds.Select(x => string.Format("'{0}'", x)));
    50       if (!string.IsNullOrWhiteSpace(paramResourceIds)) {
     48      string paramProjectIds = string.Join(",", projectIds.ToList().Select(x => string.Format("'{0}'", x)));
     49      string paramResourceIds = string.Join(",", resourceIds.ToList().Select(x => string.Format("'{0}'", x)));
     50      if (!string.IsNullOrWhiteSpace(paramProjectIds) && !string.IsNullOrWhiteSpace(paramResourceIds)) {
    5151        string query = string.Format(DeleteByProjectIdsAndResourceIdsQueryString, paramProjectIds, paramResourceIds);
    5252        DataContext.ExecuteCommand(query);
     
    5454    }
    5555
     56    public void DeleteByProjectIds(IEnumerable<Guid> projectIds) {
     57      string paramProjectIds = string.Join(",", projectIds.ToList().Select(x => string.Format("'{0}'", x)));
     58      if (!string.IsNullOrWhiteSpace(paramProjectIds)) {
     59        string query = string.Format(DeleteByProjectIdsQueryString, paramProjectIds);
     60        DataContext.ExecuteCommand(query);
     61      }
     62    }
     63
    5664    public bool CheckProjectGrantedForResources(Guid projectId, IEnumerable<Guid> resourceIds) {
    57       string paramResourceIds = string.Join(",", resourceIds.Select(x => string.Format("'{0}'", x)));
     65      string paramResourceIds = string.Join(",", resourceIds.ToList().Select(x => string.Format("'{0}'", x)));
    5866      if (!string.IsNullOrWhiteSpace(paramResourceIds)) {
    5967        string queryString = string.Format(CheckProjectGrantedForResourcesQueryString, projectId, paramResourceIds);
     
    8593
    8694    #region String queries
    87     private const string DeleteByProjectIdAndResourceIdsQueryString =
    88       @"DELETE FROM [AssignedProjectResource]
    89          WHERE ProjectId = '{0}'
    90            AND ResourceId IN ({1});";
    91     private const string DeleteByProjectIdsAndResourceIdsQueryString =
    92       @"DELETE FROM [AssignedProjectResource]
    93              WHERE ProjectId IN ({0})
    94                AND ResourceId IN ({1});";
     95    private const string DeleteByProjectIdAndResourceIdsQueryString = @"
     96      DELETE FROM [AssignedProjectResource]
     97        WHERE ProjectId = '{0}'
     98        AND ResourceId IN ({1});
     99    ";
     100    private const string DeleteByProjectIdsAndResourceIdsQueryString = @"
     101      DELETE FROM [AssignedProjectResource]
     102        WHERE ProjectId IN ({0})
     103        AND ResourceId IN ({1});
     104    ";
     105    private const string DeleteByProjectIdsQueryString = @"
     106      DELETE FROM [AssignedProjectResource]
     107        WHERE ProjectId IN ({0})
     108    ";
    95109    private const string CheckProjectGrantedForResourcesQueryString = @"
    96110    WITH rtree AS
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectDao.cs

    r15552 r15577  
    3333    }
    3434
    35     public IEnumerable<Project> GetGrantedProjectsForUser(IEnumerable<Guid> userAndGroupIds) {
    36       return GetGrantedProjectsForUserQuery(DataContext, userAndGroupIds);
     35    public IEnumerable<Project> GetUsageGrantedProjectsForUser(IEnumerable<Guid> userAndGroupIds) {
     36      string paramUserAndGroupIds = string.Join(",", userAndGroupIds.ToList().Select(x => string.Format("'{0}'", x)));
     37      if (!string.IsNullOrWhiteSpace(paramUserAndGroupIds)) {
     38        string queryString = string.Format(GetUsageGrantedProjectsForUserQueryString, paramUserAndGroupIds);
     39        return DataContext.ExecuteQuery<Project>(queryString);
     40      }
     41      return Enumerable.Empty<Project>();
     42    }
     43
     44    public IEnumerable<Project> GetAdministrationGrantedProjectsForUser(Guid userId) {
     45      return DataContext.ExecuteQuery<Project>(GetAdministrationGrantedProjectsForUserQueryString, userId);
    3746    }
    3847
     
    6776         where project.ProjectId == projectId
    6877         select project).SingleOrDefault());
    69     private static readonly Func<DataContext, IEnumerable<Guid>, IEnumerable<Project>> GetGrantedProjectsForUserQuery =
    70       CompiledQuery.Compile((DataContext db, IEnumerable<Guid> userAndGroupIds) =>
    71       (from project in db.GetTable<Project>()
    72        join projectPermission in db.GetTable<ProjectPermission>()
    73        on project.ProjectId equals projectPermission.ProjectId
    74        where userAndGroupIds.Contains(projectPermission.GrantedUserId)
    75        select project).Distinct());
    7678    #endregion
    7779
    78       #region String queries
     80    #region String queries
     81    private const string GetUsageGrantedProjectsForUserQueryString = @"
     82      SELECT DISTINCT p.*
     83      FROM [Project] p, [ProjectPermission] pp
     84      WHERE p.ProjectId = pp.ProjectId
     85      AND pp.GrantedUserId IN ({0})
     86    ";
     87
     88    private const string GetAdministrationGrantedProjectsForUserQueryString = @"
     89      WITH ptree AS
     90      (
     91        SELECT ProjectId, ParentProjectId
     92        FROM [Project]
     93        UNION ALL
     94        SELECT pt.ProjectId, p.ParentProjectId
     95        FROM [Project] p
     96        JOIN ptree pt ON pt.ParentProjectId = p.ProjectId AND p.ParentProjectId <> p.ProjectId AND pt.ParentProjectId <> pt.ProjectId
     97      )
     98      SELECT DISTINCT parent.*
     99      FROM [Project] parent
     100      WHERE parent.OwnerUserId = {0}
     101      UNION
     102      SELECT DISTINCT child.*
     103      FROM ptree, [Project] parent, [Project] child
     104      WHERE ptree.ParentProjectId = parent.ProjectId
     105      AND ptree.ProjectId = child.ProjectId
     106      AND parent.OwnerUserId = {0}
     107    ";
     108
    79109    private const string GetChildProjectsByIdQuery = @"
    80110      WITH ptree AS
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectPermissionDao.cs

    r15552 r15577  
    3838
    3939    public bool CheckUserGrantedForProject(Guid projectId, IEnumerable<Guid> userAndGroupIds) {
    40       string paramUserAndGroupIds = string.Join(",", userAndGroupIds.Select(x => string.Format("'{0}'", x)));
     40      string paramUserAndGroupIds = string.Join(",", userAndGroupIds.ToList().Select(x => string.Format("'{0}'", x)));
    4141      if(!string.IsNullOrWhiteSpace(paramUserAndGroupIds)) {
    4242        string queryString = string.Format(CheckUserGrantedForProjectQueryString, projectId, paramUserAndGroupIds);
     
    4747
    4848    public void DeleteByProjectIdAndGrantedUserIds(Guid projectId, IEnumerable<Guid> grantedUserIds) {
    49       string paramIds = string.Join(",", grantedUserIds.Select(x => string.Format("'{0}'", x)));
     49      string paramIds = string.Join(",", grantedUserIds.ToList().Select(x => string.Format("'{0}'", x)));
    5050      if (!string.IsNullOrWhiteSpace(paramIds)) {
    5151        string query = string.Format(DeleteByProjectIdAndGrantedUserIdsQueryString, projectId, paramIds);
     
    5555
    5656    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)));
     57      string paramProjectIds = string.Join(",", projectIds.ToList().Select(x => string.Format("'{0}'", x)));
     58      string paramUserIds = string.Join(",", grantedUserIds.ToList().Select(x => string.Format("'{0}'", x)));
    5959      if (!string.IsNullOrWhiteSpace(paramProjectIds) && !string.IsNullOrWhiteSpace(paramUserIds)) {
    6060        string query = string.Format(DeleteByProjectIdsAndGrantedUserIdsQueryString, paramProjectIds, paramUserIds);
     
    7979    private const string DeleteByProjectIdsAndGrantedUserIdsQueryString = @"
    8080      DELETE FROM [ProjectPermission]
    81       WHERE ProjectId IN '({0})'
     81      WHERE ProjectId IN ({0})
    8282      AND GrantedUserId IN ({1});
    8383    ";
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ResourceDao.cs

    r15540 r15577  
    3838
    3939    public bool CheckExistence(IEnumerable<Guid> ids) {
    40       string paramResourceIds = string.Join(",", ids.Select(x => string.Format("'{0}'", x)));
     40      string paramResourceIds = string.Join(",", ids.ToList().Select(x => string.Format("'{0}'", x)));
    4141      if (!string.IsNullOrWhiteSpace(paramResourceIds)) {
    4242        string queryString = string.Format(CountExistenceQuery, paramResourceIds);
    43         return DataContext.ExecuteQuery<int>(queryString).Count() == ids.Count();
     43        return DataContext.ExecuteQuery<int>(queryString).SingleOrDefault() == ids.Count();
    4444      }
    4545      return false;
Note: See TracChangeset for help on using the changeset viewer.