Free cookie consent management tool by TermsFeed Policy Generator

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

#2839

  • worked on UpdateJob(..)
  • adapted permission and assignment handling methods
  • adpated dbml of HiveDataContext using the designer (added delete rules and onNull-handling)
Location:
branches/HiveProjectManagement
Files:
3 edited

Legend:

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

    r15630 r15643  
    4545    }
    4646
     47    public IEnumerable<Job> GetJobsReadyForDeletion() {
     48      return GetJobsReadyForDeletionQuery(DataContext);
     49    }
     50
    4751
    4852    #region Compiled queries
     
    6266         where job.State == jobState
    6367         select job.JobId).ToList());
     68    private static readonly Func<DataContext, IEnumerable<Job>> GetJobsReadyForDeletionQuery =
     69      CompiledQuery.Compile((DataContext db) =>
     70        (from job in db.GetTable<Job>()
     71         where job.State == JobState.StatisticsPending
     72         && (from task in db.GetTable<Task>()
     73             where task.JobId == job.JobId
     74             select task.State == TaskState.Finished
     75              || task.State == TaskState.Aborted
     76              || task.State == TaskState.Failed).All(x => x)
     77         select job).ToList());
    6478    #endregion
    6579
     
    6983      WHERE JobState = {0}
    7084    ";
     85    private const string GetStatisticsPendingJobs = @"
     86      SELECT DISTINCT j.*
     87      FROM [Job] j
     88      WHERE j.JobState = 'StatisticsPending'
     89      AND 'Calculating' NOT IN (
     90        SELECT t.TaskState
     91        FROM [Task] t
     92        WHERE t.JobId = j.JobId)
     93    ";
    7194    #endregion
    7295  }
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.designer.cs

    r15630 r15643  
    390390    }
    391391   
    392     [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Resource_AssignedProjectResource", Storage="_Resource", ThisKey="ResourceId", OtherKey="ResourceId", IsForeignKey=true, DeleteRule="CASCADE")]
     392    [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Resource_AssignedProjectResource", Storage="_Resource", ThisKey="ResourceId", OtherKey="ResourceId", IsForeignKey=true, DeleteRule="CASCADE", DeleteOnNull=true)]
    393393    public Resource Resource
    394394    {
     
    424424    }
    425425   
    426     [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Project_AssignedProjectResource", Storage="_Project", ThisKey="ProjectId", OtherKey="ProjectId", IsForeignKey=true, DeleteRule="CASCADE")]
     426    [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Project_AssignedProjectResource", Storage="_Project", ThisKey="ProjectId", OtherKey="ProjectId", IsForeignKey=true, DeleteRule="CASCADE", DeleteOnNull=true)]
    427427    public Project Project
    428428    {
     
    10981098    }
    10991099   
    1100     [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Resource_AssignedProjectResource", Storage="_AssignedResources", ThisKey="ResourceId", OtherKey="ResourceId")]
     1100    [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Resource_AssignedProjectResource", Storage="_AssignedResources", ThisKey="ResourceId", OtherKey="ResourceId", DeleteRule="CASCADE")]
    11011101    public EntitySet<AssignedProjectResource> AssignedProjectResources
    11021102    {
     
    11631163    }
    11641164   
    1165     [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Resource_AssignedJobResource", Storage="_AssignedJobResources", ThisKey="ResourceId", OtherKey="ResourceId")]
     1165    [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Resource_AssignedJobResource", Storage="_AssignedJobResources", ThisKey="ResourceId", OtherKey="ResourceId", DeleteRule="CASCADE")]
    11661166    public EntitySet<AssignedJobResource> AssignedJobResources
    11671167    {
     
    26692669    }
    26702670   
    2671     [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Job_Task", Storage="_Jobs", ThisKey="JobId", OtherKey="JobId")]
     2671    [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Job_Task", Storage="_Jobs", ThisKey="JobId", OtherKey="JobId", DeleteRule="CASCADE")]
    26722672    public EntitySet<Task> Tasks
    26732673    {
     
    26822682    }
    26832683   
    2684     [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Job_JobPermission", Storage="_HiveExperimentPermissions", ThisKey="JobId", OtherKey="JobId")]
     2684    [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Job_JobPermission", Storage="_HiveExperimentPermissions", ThisKey="JobId", OtherKey="JobId", DeleteRule="CASCADE")]
    26852685    public EntitySet<JobPermission> JobPermissions
    26862686    {
     
    26952695    }
    26962696   
    2697     [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Job_AssignedJobResource", Storage="_AssignedJobResources", ThisKey="JobId", OtherKey="JobId")]
     2697    [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Job_AssignedJobResource", Storage="_AssignedJobResources", ThisKey="JobId", OtherKey="JobId", DeleteRule="CASCADE")]
    26982698    public EntitySet<AssignedJobResource> AssignedJobResources
    26992699    {
     
    35333533    }
    35343534   
    3535     [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Job_JobPermission", Storage="_HiveExperiment", ThisKey="JobId", OtherKey="JobId", IsForeignKey=true)]
     3535    [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Job_JobPermission", Storage="_HiveExperiment", ThisKey="JobId", OtherKey="JobId", IsForeignKey=true, DeleteRule="CASCADE", DeleteOnNull=true)]
    35363536    public Job Job
    35373537    {
     
    58335833    }
    58345834   
    5835     [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Project_AssignedProjectResource", Storage="_AssignedResources", ThisKey="ProjectId", OtherKey="ProjectId")]
     5835    [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Project_AssignedProjectResource", Storage="_AssignedResources", ThisKey="ProjectId", OtherKey="ProjectId", DeleteRule="CASCADE")]
    58365836    public EntitySet<AssignedProjectResource> AssignedProjectResources
    58375837    {
     
    58725872    }
    58735873   
    5874     [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Project_ProjectPermission", Storage="_ProjectPermissions", ThisKey="ProjectId", OtherKey="ProjectId")]
     5874    [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Project_ProjectPermission", Storage="_ProjectPermissions", ThisKey="ProjectId", OtherKey="ProjectId", DeleteRule="CASCADE")]
    58755875    public EntitySet<ProjectPermission> ProjectPermissions
    58765876    {
     
    60846084    }
    60856085   
    6086     [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Project_ProjectPermission", Storage="_Project", ThisKey="ProjectId", OtherKey="ProjectId", IsForeignKey=true)]
     6086    [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Project_ProjectPermission", Storage="_Project", ThisKey="ProjectId", OtherKey="ProjectId", IsForeignKey=true, DeleteRule="CASCADE", DeleteOnNull=true)]
    60876087    public Project Project
    60886088    {
     
    63866386    }
    63876387   
    6388     [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Resource_AssignedJobResource", Storage="_Resource", ThisKey="ResourceId", OtherKey="ResourceId", IsForeignKey=true)]
     6388    [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Resource_AssignedJobResource", Storage="_Resource", ThisKey="ResourceId", OtherKey="ResourceId", IsForeignKey=true, DeleteRule="CASCADE", DeleteOnNull=true)]
    63896389    public Resource Resource
    63906390    {
     
    64206420    }
    64216421   
    6422     [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Job_AssignedJobResource", Storage="_Job", ThisKey="JobId", OtherKey="JobId", IsForeignKey=true)]
     6422    [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Job_AssignedJobResource", Storage="_Job", ThisKey="JobId", OtherKey="JobId", IsForeignKey=true, DeleteRule="CASCADE", DeleteOnNull=true)]
    64236423    public Job Job
    64246424    {
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs

    r15630 r15643  
    507507          } else {
    508508            var addedJobResourceIds = resourceIds.Except(job.AssignedJobResources.Select(x => x.ResourceId));
    509             var removedJobResourceIds = job.AssignedJobResources.Select(x => x.ResourceId).Except(resourceIds);
     509            var removedJobResourceIds = job.AssignedJobResources
     510              .Select(x => x.ResourceId)
     511              .Except(resourceIds)
     512              .ToArray();
    510513           
    511514            // remove resource assignments
     
    855858      AuthorizationManager.AuthorizeForProjectAdministration(projectId);
    856859      var pm = PersistenceManager;
    857       using (new PerformanceLogger("GrantProjectPermissions")) {
     860      using (new PerformanceLogger("SaveProjectPermissions")) {
    858861        var projectDao = pm.ProjectDao;
    859862        var projectPermissionDao = pm.ProjectPermissionDao;
     
    863866          var project = projectDao.GetById(projectId);
    864867          if (project == null) return;
    865           //if (project.ProjectPermissions == null) project.ProjectPermissions = new System.Data.Linq.EntitySet<DA.ProjectPermission>();
    866           var projectPermissions = project.ProjectPermissions.Select(x => x.GrantedUserId);
    867           var addedPermissions = grantedUserIds.Except(projectPermissions);
     868          var projectPermissions = project.ProjectPermissions.Select(x => x.GrantedUserId).ToArray();
     869          //var addedPermissions = grantedUserIds.Except(projectPermissions);
    868870          var removedPermissions = projectPermissions.Except(grantedUserIds);
    869871
     
    874876          } else {
    875877            assignedJobResourceDao.DeleteByProjectIdAndUserIds(project.ProjectId, removedPermissions);
    876             foreach(var item in project.ProjectPermissions.ToList().Where(x => removedPermissions.Contains(x.GrantedUserId))) {
     878            foreach(var item in project.ProjectPermissions
     879              .Where(x => removedPermissions.Contains(x.GrantedUserId))
     880              .ToList()) {
    877881              project.ProjectPermissions.Remove(item);
    878882            }
     
    907911                p.ProjectPermissions.Clear();
    908912              } else {
    909                 foreach(var item in p.ProjectPermissions.ToList().Where(x => removedPermissions.Contains(x.GrantedUserId))) {
     913                foreach(var item in p.ProjectPermissions
     914                  .Where(x => removedPermissions.Contains(x.GrantedUserId))
     915                  .ToList()) {
    910916                  p.ProjectPermissions.Remove(item);
    911917                }
     
    979985      AuthorizationManager.AuthorizeForProjectResourceAdministration(projectId, resourceIds);
    980986      var pm = PersistenceManager;
    981       using (new PerformanceLogger("AssignProjectResources")) {
     987      using (new PerformanceLogger("SaveProjectResourceAssignments")) {
    982988        var projectDao = pm.ProjectDao;
    983989        var assignedProjectResourceDao = pm.AssignedProjectResourceDao;
     
    985991        pm.UseTransaction(() => {
    986992          var project = projectDao.GetById(projectId);
    987           var assignedResources = project.AssignedProjectResources.Select(x => x.ResourceId);
    988           var addedAssignments = resourceIds.Except(assignedResources);
     993          var assignedResources = project.AssignedProjectResources.Select(x => x.ResourceId).ToArray();
     994          //var addedAssignments = resourceIds.Except(assignedResources);
    989995          var removedAssignments = assignedResources.Except(resourceIds);
    990996
     
    992998          if (reassign) {
    993999            assignedJobResourceDao.DeleteByProjectId(project.ProjectId);
    994             //assignedProjectResourceDao.DeleteByProjectIds(new List<Guid> { projectId });
    9951000            project.AssignedProjectResources.Clear();
    9961001          } else {
    9971002            assignedJobResourceDao.DeleteByProjectIdAndResourceIds(projectId, removedAssignments);
    998             //assignedProjectResourceDao.DeleteByProjectIdAndResourceIds(projectId, removedAssignments);
    999             foreach (var item in project.AssignedProjectResources.ToList().Where(x => removedAssignments.Contains(x.ResourceId))) {
     1003            foreach (var item in project.AssignedProjectResources
     1004              .Where(x => removedAssignments.Contains(x.ResourceId))
     1005              .ToList()) {
    10001006              project.AssignedProjectResources.Remove(item);
    10011007            }
     
    10301036              } else {
    10311037                //assignedProjectResourceDao.DeleteByProjectIdAndResourceIds(p.ProjectId, removedAssignments);
    1032                 foreach (var item in p.AssignedProjectResources.ToList().Where(x => removedAssignments.Contains(x.ResourceId))) {
     1038                //for(int i = p.AssignedProjectResources.Count -1; i >= 0; i--) {
     1039                //  if(removedAssignments.Contains(p.AssignedProjectResources[i].ResourceId)) {
     1040                //    p.AssignedProjectResources.RemoveAt(i);
     1041                //  }
     1042                //}
     1043                foreach (var item in p.AssignedProjectResources
     1044                  .Where(x => removedAssignments.Contains(x.ResourceId))
     1045                  .ToList()) {
    10331046                  p.AssignedProjectResources.Remove(item);
    10341047                }
Note: See TracChangeset for help on using the changeset viewer.