Changeset 15527


Ignore:
Timestamp:
12/14/17 15:08:38 (2 years ago)
Author:
jzenisek
Message:

#2839

  • updated dbml (removed ResourcePermission and ResourceIds in Job-Table)
  • updated Resource and Project Daos
Location:
branches/HiveProjectManagement
Files:
1 deleted
6 edited

Legend:

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

    r15508 r15527  
    3333    }
    3434
    35     public IEnumerable<Project> GetProjectsByChildId(Guid id) {
    36       return DataContext.ExecuteQuery<Project>(GetProjectsByChildIdQuery, id);
     35    public IEnumerable<Project> GetChildProjectsById(Guid id) {
     36      return DataContext.ExecuteQuery<Project>(GetChildProjectsByIdQuery, id);
    3737    }
    3838
    39     public IEnumerable<Guid> GetProjectIdsByChildId(Guid id) {
    40       return DataContext.ExecuteQuery<Guid>(GetProjectIdsByChildIdQuery, id);
     39    public IEnumerable<Guid> GetChildProjectIdsById(Guid id) {
     40      return DataContext.ExecuteQuery<Guid>(GetChildProjectIdsByIdQuery, id);
     41    }
     42
     43    public IEnumerable<Project> GetParentProjectsById(Guid id) {
     44      return DataContext.ExecuteQuery<Project>(GetParentProjectsByIdQuery, id);
     45    }
     46
     47    public IEnumerable<Guid> GetParentProjectIdsById(Guid id) {
     48      return DataContext.ExecuteQuery<Guid>(GetParentProjectIdsByIdQuery, id);
     49    }
     50
     51    public IEnumerable<Project> GetCurrentAndParentProjectsById(Guid id) {
     52      return DataContext.ExecuteQuery<Project>(GetCurrentAndParentProjectsByIdQuery, id);
     53    }
     54
     55    public IEnumerable<Guid> GetCurrentAndParentProjectIdsById(Guid id) {
     56      return DataContext.ExecuteQuery<Guid>(GetCurrentAndParentProjectIdsByIdQuery, id);
    4157    }
    4258
     
    5066
    5167    #region String queries
    52     private const string GetProjectsByChildIdQuery = @"
    53       WITH ptree AS
     68    private const string GetChildProjectsByIdQuery = @"
     69      WITH ptree AS
    5470      (
    5571        SELECT ProjectId, ParentProjectId
    56         FROM [Project]
     72        FROM [Project]
    5773        UNION ALL
    5874        SELECT pt.ProjectId, p.ParentProjectId
     
    6278      SELECT DISTINCT pro.*
    6379      FROM ptree, [Project] pro
    64       WHERE ptree.ProjectId = {0}
    65       AND ptree.ParentProjectId = pro.ProjectId
     80      WHERE ptree.ParentProjectId = {0}
     81      AND ptree.ProjectId = pro.ProjectId
    6682    ";
    67     private const string GetProjectIdsByChildIdQuery = @"
     83    private const string GetChildProjectIdsByIdQuery = @"
    6884      WITH ptree AS
     85      (
     86        SELECT ProjectId, ParentProjectId
     87        FROM [Project]
     88        UNION ALL
     89        SELECT pt.ProjectId, r.ParentProjectId
     90        FROM [Project] r
     91        JOIN ptree pt ON pt.ParentProjectId = r.ProjectId AND r.ParentProjectId <> r.ProjectId AND pt.ParentProjectId <> pt.ProjectId
     92      )
     93      SELECT DISTINCT ptree.ProjectId
     94      FROM ptree
     95      WHERE ptree.ParentProjectId = {0}
     96    ";
     97    private const string GetParentProjectsByIdQuery = @"
     98      WITH pbranch AS
    6999      (
    70100        SELECT ProjectId, ParentProjectId
    71101        FROM [Project]
    72102        UNION ALL
    73         SELECT pt.ProjectId, p.ParentProjectId
     103        SELECT pb.ProjectId, p.ParentProjectId
    74104        FROM [Project] p
    75         JOIN ptree pt ON pt.ParentProjectId = p.ProjectId AND p.ParentProjectId <> p.ProjectId AND pt.ParentProjectId <> pt.ProjectId
     105        JOIN pbranch pb ON pb.ParentProjectId = p.ProjectId AND p.ParentProjectId <> p.ProjectId AND pb.ParentProjectId <> pb.ProjectId
    76106      )
    77       SELECT DISTINCT ptree.ParentProjectId
    78       FROM ptree
    79       WHERE ptree.ProjectId = {0}
     107      SELECT DISTINCT pro.*
     108      FROM pbranch, [Project] pro
     109      WHERE pbranch.ProjectId = {0}
     110      AND pbranch.ParentProjectId = pro.ProjectId
     111    ";
     112    private const string GetParentProjectIdsByIdQuery = @"
     113      WITH pbranch AS
     114      (
     115        SELECT ProjectId, ParentProjectId
     116        FROM [Project]
     117        UNION ALL
     118        SELECT pb.ProjectId, p.ParentProjectId
     119        FROM [Project] p
     120        JOIN pbranch pb ON pb.ParentProjectId = p.ProjectId AND p.ParentProjectId <> p.ProjectId AND pb.ParentProjectId <> pb.ProjectId
     121      )
     122      SELECT DISTINCT pbranch.ParentProjectId
     123      FROM pbranch
     124      WHERE pbranch.ProjectId = {0}
     125    ";
     126    private const string GetCurrentAndParentProjectsByIdQuery = @"
     127      WITH pbranch AS
     128      (
     129        SELECT ProjectId, ParentProjectId
     130        FROM Project
     131        WHERE ProjectId = {0}
     132        UNION ALL
     133        SELECT p.ProjectId, p.ParentProjectId
     134        FROM Project p
     135        JOIN pbranch pb ON pb.ParentProjectId = p.ProjectId
     136      )
     137      SELECT DISTINCT pro.*
     138      FROM pbranch, Project pro
     139      WHERE pbranch.ProjectId = pro.ProjectId
     140    ";
     141    private const string GetCurrentAndParentProjectIdsByIdQuery = @"
     142      WITH pbranch AS
     143      (
     144        SELECT ProjectId, ParentProjectId
     145        FROM Project
     146        WHERE ProjectId = {0}
     147        UNION ALL
     148        SELECT p.ProjectId, p.ParentProjectId
     149        FROM Project p
     150        JOIN pbranch pb ON pb.ParentProjectId = p.ProjectId
     151      )
     152      SELECT DISTINCT pbranch.ProjectId
     153      FROM pbranch
    80154    ";
    81155    #endregion
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ResourceDao.cs

    r15503 r15527  
    4141    }
    4242
    43     public IEnumerable<Resource> GetResourcesByParentId(Guid id) {
    44       return DataContext.ExecuteQuery<Resource>(GetResourcesByParentIdQuery, id);
     43    public IEnumerable<Resource> GetChildResourcesById(Guid id) {
     44      return DataContext.ExecuteQuery<Resource>(GetChildResourcesByIdQuery, id);
    4545    }
    4646
    47     public IEnumerable<Guid> GetResourceIdsByParentId(Guid id) {
    48       return DataContext.ExecuteQuery<Guid>(GetResourceIdsByParentIdQuery, id);
     47    public IEnumerable<Guid> GetChildResourceIdsById(Guid id) {
     48      return DataContext.ExecuteQuery<Guid>(GetChildResourceIdsByIdQuery, id);
    4949    }
    5050
    51     public IEnumerable<Resource> GetResourcesByChildId(Guid id) {
    52       return DataContext.ExecuteQuery<Resource>(GetResourcesByChildIdQuery, id);
     51    public IEnumerable<Resource> GetParentResourcesById(Guid id) {
     52      return DataContext.ExecuteQuery<Resource>(GetParentResourcesByIdQuery, id);
    5353    }
    5454
    55     public IEnumerable<Guid> GetResourceIdsByChildId(Guid id) {
    56       return DataContext.ExecuteQuery<Guid>(GetResourceIdsByChildIdQuery, id);
     55    public IEnumerable<Guid> GetParentResourceIdsById(Guid id) {
     56      return DataContext.ExecuteQuery<Guid>(GetParentResourceIdsByIdQuery, id);
     57    }
     58
     59    public IEnumerable<Resource> GetCurrentAndParentResourcesById(Guid id) {
     60      return DataContext.ExecuteQuery<Resource>(GetCurrentAndParentResourcesByIdQuery, id);
     61    }
     62
     63    public IEnumerable<Guid> GetCurrentAndParentResourceIdsById(Guid id) {
     64      return DataContext.ExecuteQuery<Guid>(GetCurrentAndParentResourceIdsByIdQuery, id);
    5765    }
    5866
     
    7280
    7381    #region String queries
    74     private const string GetResourcesByParentIdQuery = @"
     82    private const string GetChildResourcesByIdQuery = @"
    7583      WITH rtree AS
    7684      (
     
    8492      SELECT DISTINCT res.*
    8593      FROM rtree, [Resource] res
    86       WHERE rtree.ParentResourceId = ({0})
     94      WHERE rtree.ParentResourceId = {0}
    8795      AND rtree.ResourceId = res.ResourceId
    8896    ";
    89     private const string GetResourceIdsByParentIdQuery = @"
     97    private const string GetChildResourceIdsByIdQuery = @"
    9098      WITH rtree AS
    9199      (
     
    99107      SELECT DISTINCT rtree.ResourceId
    100108      FROM rtree
    101       WHERE rtree.ParentResourceId = ({0})
     109      WHERE rtree.ParentResourceId = {0}
    102110    ";
    103     private const string GetResourcesByChildIdQuery = @"
    104       WITH rtree AS
     111    private const string GetParentResourcesByIdQuery = @"
     112      WITH rbranch AS
    105113      (
    106114        SELECT ResourceId, ParentResourceId
    107115        FROM [Resource]
    108116        UNION ALL
    109         SELECT rt.ResourceId, r.ParentResourceId
     117        SELECT rb.ResourceId, r.ParentResourceId
    110118        FROM [Resource] r
    111         JOIN rtree rt ON rt.ParentResourceId = r.ResourceId AND r.ParentResourceId <> r.ResourceId AND rt.ParentResourceId <> rt.ResourceId
     119        JOIN rbranch rb ON rb.ParentResourceId = r.ResourceId AND r.ParentResourceId <> r.ResourceId AND rb.ParentResourceId <> rb.ResourceId
    112120      )
    113121      SELECT DISTINCT res.*
    114       FROM rtree, [Resource] res
    115       WHERE rtree.ResourceId = ({0})
    116       AND rtree.ParentResourceId = res.ResourceId
     122      FROM rbranch, [Resource] res
     123      WHERE rbranch.ResourceId = {0}
     124      AND rbranch.ParentResourceId = res.ResourceId
    117125    ";
    118     private const string GetResourceIdsByChildIdQuery = @"
    119       WITH rtree AS
     126    private const string GetParentResourceIdsByIdQuery = @"
     127      WITH rbranch AS
    120128      (
    121129        SELECT ResourceId, ParentResourceId
    122130        FROM [Resource]
    123131        UNION ALL
    124         SELECT rt.ResourceId, r.ParentResourceId
     132        SELECT rb.ResourceId, r.ParentResourceId
    125133        FROM [Resource] r
    126         JOIN rtree rt ON rt.ParentResourceId = r.ResourceId AND r.ParentResourceId <> r.ResourceId AND rt.ParentResourceId <> rt.ResourceId
     134        JOIN rbranch rb ON rb.ParentResourceId = r.ResourceId AND r.ParentResourceId <> r.ResourceId AND rb.ParentResourceId <> rb.ResourceId
    127135      )
    128       SELECT DISTINCT rtree.ParentResourceId
    129       FROM rtree
    130       WHERE rtree.ResourceId = ({0})
     136      SELECT DISTINCT rbranch.ParentResourceId
     137      FROM rbranch
     138      WHERE rbranch.ResourceId = {0}
     139    ";
     140    private const string GetCurrentAndParentResourcesByIdQuery = @"
     141      WITH rbranch AS
     142      (
     143        SELECT ResourceId, ParentResourceId
     144        FROM [Resource]
     145        WHERE ResourceId = {0}
     146        UNION ALL
     147        SELECT r.ResourceId, r.ParentResourceId
     148        FROM [Resource] r
     149        JOIN rbranch rb ON rb.ParentResourceId = r.ResourceId
     150      )
     151      SELECT DISTINCT res.*
     152      FROM rbranch, [Resource] res
     153      WHERE rbranch.ResourceId = res.ResourceId
     154    ";
     155    private const string GetCurrentAndParentResourceIdsByIdQuery = @"
     156      WITH rbranch AS
     157      (
     158        SELECT ResourceId, ParentResourceId
     159        FROM [Resource]
     160        WHERE ResourceId = {0}
     161        UNION ALL
     162        SELECT r.ResourceId, r.ParentResourceId
     163        FROM [Resource] r
     164        JOIN rbranch rb ON rb.ParentResourceId = r.ResourceId
     165      )
     166      SELECT DISTINCT rbranch.ResourceId
     167      FROM rbranch
    131168    ";
    132169    #endregion
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml

    r15526 r15527  
    44      <Column Name="ResourceId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
    55      <Column Name="ProjectId" Storage="_JobId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
    6       <Association Name="Resource_AssignedResource" Member="Resource" ThisKey="ResourceId" OtherKey="ResourceId" Type="Resource" IsForeignKey="true" DeleteRule="CASCADE" />
    7       <Association Name="Project_AssignedResource" Member="Project" ThisKey="ProjectId" OtherKey="ProjectId" Type="Project" IsForeignKey="true" DeleteRule="CASCADE" />
     6      <Association Name="Resource_AssignedProjectResource" Member="Resource" ThisKey="ResourceId" OtherKey="ResourceId" Type="Resource" IsForeignKey="true" DeleteRule="CASCADE" />
     7      <Association Name="Project_AssignedProjectResource" Member="Project" ThisKey="ProjectId" OtherKey="ProjectId" Type="Project" IsForeignKey="true" DeleteRule="CASCADE" />
    88    </Type>
    99  </Table>
     
    3737      <Column Name="HbInterval" Type="System.Int32" DbType="Int" CanBeNull="false" />
    3838      <Column Name="OwnerUserId" Type="System.Guid" DbType="UniqueIdentifier" CanBeNull="true" />
    39       <Association Name="Resource_AssignedResource" Member="AssignedProjectResources" Storage="_AssignedResources" ThisKey="ResourceId" OtherKey="ResourceId" Type="AssignedProjectResource" />
     39      <Association Name="Resource_AssignedProjectResource" Member="AssignedProjectResources" Storage="_AssignedResources" ThisKey="ResourceId" OtherKey="ResourceId" Type="AssignedProjectResource" />
    4040      <Association Name="Resource_Resource" Member="ChildResources" ThisKey="ResourceId" OtherKey="ParentResourceId" Type="Resource" />
    4141      <Association Name="Resource_Downtime" Member="Downtimes" Storage="_UptimeCalendars" ThisKey="ResourceId" OtherKey="ResourceId" Type="Downtime" />
    4242      <Association Name="Resource_StateLog" Member="StateLogs" ThisKey="ResourceId" OtherKey="SlaveId" Type="StateLog" />
    43       <Association Name="Resource_ResourcePermission" Member="ResourcePermissions" ThisKey="ResourceId" OtherKey="ResourceId" Type="ResourcePermission" />
    4443      <Association Name="Resource_AssignedTaskResource" Member="AssignedTaskResources" ThisKey="ResourceId" OtherKey="ResourceId" Type="AssignedTaskResource" />
    4544      <Association Name="Resource_Resource" Member="ParentResource" ThisKey="ParentResourceId" OtherKey="ResourceId" Type="Resource" IsForeignKey="true" />
     
    103102      <Column Name="Name" Type="System.String" DbType="VarChar(MAX)" CanBeNull="false" />
    104103      <Column Name="Description" Type="System.String" DbType="VarChar(MAX)" CanBeNull="true" />
    105       <Column Name="ResourceIds" Type="System.String" DbType="VarChar(MAX)" CanBeNull="true" />
    106104      <Column Name="OwnerUserId" Storage="_UserId" Type="System.Guid" DbType="UniqueIdentifier" CanBeNull="false" />
    107105      <Column Name="DateCreated" Type="System.DateTime" DbType="DateTime" CanBeNull="false" />
     
    155153      <Column Name="LifecycleId" Type="System.Int32" DbType="Int" IsPrimaryKey="true" CanBeNull="false" />
    156154      <Column Name="LastCleanup" Type="System.DateTime" DbType="DateTime" CanBeNull="false" />
    157     </Type>
    158   </Table>
    159   <Table Name="dbo.ResourcePermission" Member="ResourcePermissions">
    160     <Type Name="ResourcePermission">
    161       <Column Name="ResourceId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
    162       <Column Name="GrantedUserId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
    163       <Column Name="GrantedByUserId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" CanBeNull="false" />
    164       <Association Name="Resource_ResourcePermission" Member="Resource" ThisKey="ResourceId" OtherKey="ResourceId" Type="Resource" IsForeignKey="true" />
    165155    </Type>
    166156  </Table>
     
    268258      <Column Name="StartDate" Type="System.DateTime" DbType="DateTime NOT NULL" CanBeNull="false" />
    269259      <Column Name="EndDate" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />
    270       <Association Name="Project_AssignedResource" Member="AssignedProjectResources" Storage="_AssignedResources" ThisKey="ProjectId" OtherKey="ProjectId" Type="AssignedProjectResource" />
     260      <Association Name="Project_AssignedProjectResource" Member="AssignedProjectResources" Storage="_AssignedResources" ThisKey="ProjectId" OtherKey="ProjectId" Type="AssignedProjectResource" />
    271261      <Association Name="Project_Job" Member="Jobs" ThisKey="ProjectId" OtherKey="ProjectId" Type="Job" />
    272262      <Association Name="Project_Project" Member="ChildProjects" Storage="_Projects" ThisKey="ProjectId" OtherKey="ParentProjectId" Type="Project" />
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml.layout

    r15526 r15527  
    3939      </nestedChildShapes>
    4040    </classShape>
    41     <classShape Id="e6f840cc-2968-4be1-b234-eef624ccacbb" absoluteBounds="4.125, 2.625, 2, 2.1554996744791666">
     41    <classShape Id="e6f840cc-2968-4be1-b234-eef624ccacbb" absoluteBounds="4.125, 2.625, 2, 1.9631982421874996">
    4242      <DataClassMoniker Name="/HiveDataContext/Job" />
    4343      <nestedChildShapes>
    44         <elementListCompartment Id="0c65d4e1-256a-4a91-9a57-392f25e4de7f" absoluteBounds="4.1400000000000006, 3.0850000000000009, 1.9700000000000002, 1.5954996744791665" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
     44        <elementListCompartment Id="0c65d4e1-256a-4a91-9a57-392f25e4de7f" absoluteBounds="4.1400000000000006, 3.0850000000000009, 1.9700000000000002, 1.4031982421875" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
    4545      </nestedChildShapes>
    4646    </classShape>
     
    6969      </nodes>
    7070    </inheritanceConnector>
    71     <associationConnector edgePoints="[(13.25 : 2.15469482421875); (15.71875 : 2.15469482421875); (15.71875 : 8.25)]" manuallyRouted="true" fixedFrom="NotFixed" fixedTo="NotFixed">
    72       <AssociationMoniker Name="/HiveDataContext/Resource/Resource_AssignedResource" />
    73       <nodes>
    74         <classShapeMoniker Id="706a4581-6daf-4e71-ae2a-87d50b27a051" />
    75         <classShapeMoniker Id="a929c9dc-69f4-4488-ba1c-a2342bf81d89" />
    76       </nodes>
    77     </associationConnector>
    7871    <classShape Id="6bc13f26-f9a8-4597-b054-35be34190d12" absoluteBounds="4.125, 1, 2, 1.3862939453125">
    7972      <DataClassMoniker Name="/HiveDataContext/TaskData" />
     
    9588      </nodes>
    9689    </associationConnector>
    97     <associationConnector edgePoints="[(8.875 : 6.56814697265625); (8.5 : 6.56814697265625)]" fixedFrom="Algorithm" fixedTo="Algorithm">
     90    <associationConnector edgePoints="[(8.875 : 6.56814697265625); (8.5 : 6.56814697265625)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    9891      <AssociationMoniker Name="/HiveDataContext/Plugin/Plugin_RequiredPlugin" />
    9992      <nodes>
     
    162155      </nodes>
    163156    </associationConnector>
    164     <associationConnector edgePoints="[(6.5 : 2.50564697265625); (3.75 : 2.50564697265625)]" fixedFrom="NotFixed" fixedTo="NotFixed">
     157    <associationConnector edgePoints="[(6.5 : 2.50564697265625); (3.75 : 2.50564697265625)]" fixedFrom="Algorithm" fixedTo="Algorithm">
    165158      <AssociationMoniker Name="/HiveDataContext/Task/Task_StateLog" />
    166159      <nodes>
     
    169162      </nodes>
    170163    </associationConnector>
    171     <associationConnector edgePoints="[(6.125 : 3.37100341796875); (6.5 : 3.37100341796875)]" fixedFrom="NotFixed" fixedTo="NotFixed">
     164    <associationConnector edgePoints="[(6.125 : 3.37100341796875); (6.5 : 3.37100341796875)]" fixedFrom="Algorithm" fixedTo="Algorithm">
    172165      <AssociationMoniker Name="/HiveDataContext/Job/Job_Task" />
    173166      <nodes>
     
    176169      </nodes>
    177170    </associationConnector>
    178     <associationConnector edgePoints="[(4.125 : 4.20274983723958); (3.75 : 4.20274983723958)]" fixedFrom="NotFixed" fixedTo="NotFixed">
     171    <associationConnector edgePoints="[(4.125 : 4.10659912109375); (3.75 : 4.10659912109375)]" fixedFrom="Algorithm" fixedTo="Algorithm">
    179172      <AssociationMoniker Name="/HiveDataContext/Job/Job_JobPermission" />
    180173      <nodes>
     
    183176      </nodes>
    184177    </associationConnector>
    185     <classShape Id="a3f352be-9f15-4e73-8d44-3e8ac02fb4cf" absoluteBounds="11.25, 3.875, 2, 1.3862939453124996">
    186       <DataClassMoniker Name="/HiveDataContext/ResourcePermission" />
    187       <nestedChildShapes>
    188         <elementListCompartment Id="45e2f1a8-8a1e-4647-b649-10ec55976ab4" absoluteBounds="11.265, 4.335, 1.9700000000000002, 0.8262939453125" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
    189       </nestedChildShapes>
    190     </classShape>
    191     <associationConnector edgePoints="[(12.5942481820367 : 2.9631982421875); (12.5942481820367 : 3.875)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    192       <AssociationMoniker Name="/HiveDataContext/Resource/Resource_ResourcePermission" />
    193       <nodes>
    194         <classShapeMoniker Id="706a4581-6daf-4e71-ae2a-87d50b27a051" />
    195         <classShapeMoniker Id="a3f352be-9f15-4e73-8d44-3e8ac02fb4cf" />
    196       </nodes>
    197     </associationConnector>
    198178    <classShape Id="f9e8867f-fd15-4a72-8ca4-4f02cd3f141f" absoluteBounds="4.125, 5.5, 2, 1.1939925130208327">
    199179      <DataClassMoniker Name="/HiveDataContext/UserPriority" />
     
    299279      </nodes>
    300280    </associationConnector>
    301     <associationConnector edgePoints="[(13.25 : 8.84699625651042); (13.875 : 8.84699625651042)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    302       <AssociationMoniker Name="/HiveDataContext/Project/Project_AssignedResource" />
    303       <nodes>
    304         <classShapeMoniker Id="30778876-b5f6-4a97-9ec7-792011973d75" />
    305         <classShapeMoniker Id="a929c9dc-69f4-4488-ba1c-a2342bf81d89" />
    306       </nodes>
    307     </associationConnector>
    308     <associationConnector edgePoints="[(11.25 : 9.42390055338542); (10.375 : 9.42390055338542); (10.375 : 8); (4 : 8); (4 : 5.15549967447917); (5.125 : 5.15549967447917); (5.125 : 4.78049967447917)]" fixedFrom="NotFixed" fixedTo="NotFixed">
     281    <associationConnector edgePoints="[(11.25 : 9.42390055338542); (10.375 : 9.42390055338542); (10.375 : 8); (4 : 8); (4 : 4.9631982421875); (5.125 : 4.9631982421875); (5.125 : 4.5881982421875)]" fixedFrom="Algorithm" fixedTo="Algorithm">
    309282      <AssociationMoniker Name="/HiveDataContext/Project/Project_Job" />
    310283      <nodes>
     
    326299      </nodes>
    327300    </associationConnector>
    328     <associationConnector edgePoints="[(12.25 : 2.9631982421875); (12.25 : 3.8125); (11.1875 : 3.8125); (11.1875 : 4.97199625651042); (10.875 : 4.97199625651042)]" fixedFrom="Algorithm" fixedTo="Algorithm">
     301    <associationConnector edgePoints="[(12.25 : 2.9631982421875); (12.25 : 4.97199625651042); (10.875 : 4.97199625651042)]" fixedFrom="Algorithm" fixedTo="Algorithm">
    329302      <AssociationMoniker Name="/HiveDataContext/Resource/Resource_AssignedTaskResource" />
    330303      <nodes>
    331304        <classShapeMoniker Id="706a4581-6daf-4e71-ae2a-87d50b27a051" />
    332305        <classShapeMoniker Id="72ac5c1b-0fdf-43a1-bbe7-3774893b40af" />
     306      </nodes>
     307    </associationConnector>
     308    <associationConnector edgePoints="[(13.25 : 2.15469482421875); (15.71875 : 2.15469482421875); (15.71875 : 8.25)]" fixedFrom="Algorithm" fixedTo="Algorithm">
     309      <AssociationMoniker Name="/HiveDataContext/Resource/Resource_AssignedProjectResource" />
     310      <nodes>
     311        <classShapeMoniker Id="706a4581-6daf-4e71-ae2a-87d50b27a051" />
     312        <classShapeMoniker Id="a929c9dc-69f4-4488-ba1c-a2342bf81d89" />
     313      </nodes>
     314    </associationConnector>
     315    <associationConnector edgePoints="[(13.25 : 8.84699625651042); (13.875 : 8.84699625651042)]" fixedFrom="Algorithm" fixedTo="Algorithm">
     316      <AssociationMoniker Name="/HiveDataContext/Project/Project_AssignedProjectResource" />
     317      <nodes>
     318        <classShapeMoniker Id="30778876-b5f6-4a97-9ec7-792011973d75" />
     319        <classShapeMoniker Id="a929c9dc-69f4-4488-ba1c-a2342bf81d89" />
    333320      </nodes>
    334321    </associationConnector>
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.designer.cs

    r15526 r15527  
    6767    partial void UpdateLifecycle(Lifecycle instance);
    6868    partial void DeleteLifecycle(Lifecycle instance);
    69     partial void InsertResourcePermission(ResourcePermission instance);
    70     partial void UpdateResourcePermission(ResourcePermission instance);
    71     partial void DeleteResourcePermission(ResourcePermission instance);
    7269    partial void InsertUserPriority(UserPriority instance);
    7370    partial void UpdateUserPriority(UserPriority instance);
     
    222219    }
    223220   
    224     public System.Data.Linq.Table<ResourcePermission> ResourcePermissions
    225     {
    226       get
    227       {
    228         return this.GetTable<ResourcePermission>();
    229       }
    230     }
    231    
    232221    public System.Data.Linq.Table<UserPriority> UserPriorities
    233222    {
     
    938927    private EntitySet<StateLog> _StateLogs;
    939928   
    940     private EntitySet<ResourcePermission> _ResourcePermissions;
    941    
    942929    private EntitySet<AssignedTaskResource> _AssignedTaskResources;
    943930   
     
    968955      this._UptimeCalendars = new EntitySet<Downtime>(new Action<Downtime>(this.attach_UptimeCalendars), new Action<Downtime>(this.detach_UptimeCalendars));
    969956      this._StateLogs = new EntitySet<StateLog>(new Action<StateLog>(this.attach_StateLogs), new Action<StateLog>(this.detach_StateLogs));
    970       this._ResourcePermissions = new EntitySet<ResourcePermission>(new Action<ResourcePermission>(this.attach_ResourcePermissions), new Action<ResourcePermission>(this.detach_ResourcePermissions));
    971957      this._AssignedTaskResources = new EntitySet<AssignedTaskResource>(new Action<AssignedTaskResource>(this.attach_AssignedTaskResources), new Action<AssignedTaskResource>(this.detach_AssignedTaskResources));
    972958      this._ParentResource = default(EntityRef<Resource>);
     
    11501136    }
    11511137   
    1152     [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Resource_ResourcePermission", Storage="_ResourcePermissions", ThisKey="ResourceId", OtherKey="ResourceId")]
    1153     public EntitySet<ResourcePermission> ResourcePermissions
    1154     {
    1155       get
    1156       {
    1157         return this._ResourcePermissions;
    1158       }
    1159       set
    1160       {
    1161         this._ResourcePermissions.Assign(value);
    1162       }
    1163     }
    1164    
    11651138    [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Resource_AssignedTaskResource", Storage="_AssignedTaskResources", ThisKey="ResourceId", OtherKey="ResourceId")]
    11661139    public EntitySet<AssignedTaskResource> AssignedTaskResources
     
    12731246   
    12741247    private void detach_StateLogs(StateLog entity)
    1275     {
    1276       this.SendPropertyChanging();
    1277       entity.Resource = null;
    1278     }
    1279    
    1280     private void attach_ResourcePermissions(ResourcePermission entity)
    1281     {
    1282       this.SendPropertyChanging();
    1283       entity.Resource = this;
    1284     }
    1285    
    1286     private void detach_ResourcePermissions(ResourcePermission entity)
    12871248    {
    12881249      this.SendPropertyChanging();
     
    24802441    private string _Description;
    24812442   
    2482     private string _ResourceIds;
    2483    
    24842443    private System.Guid _UserId;
    24852444   
     
    25042463    partial void OnDescriptionChanging(string value);
    25052464    partial void OnDescriptionChanged();
    2506     partial void OnResourceIdsChanging(string value);
    2507     partial void OnResourceIdsChanged();
    25082465    partial void OnOwnerUserIdChanging(System.Guid value);
    25092466    partial void OnOwnerUserIdChanged();
     
    25782535          this.SendPropertyChanged("Description");
    25792536          this.OnDescriptionChanged();
    2580         }
    2581       }
    2582     }
    2583    
    2584     [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ResourceIds", DbType="VarChar(MAX)")]
    2585     public string ResourceIds
    2586     {
    2587       get
    2588       {
    2589         return this._ResourceIds;
    2590       }
    2591       set
    2592       {
    2593         if ((this._ResourceIds != value))
    2594         {
    2595           this.OnResourceIdsChanging(value);
    2596           this.SendPropertyChanging();
    2597           this._ResourceIds = value;
    2598           this.SendPropertyChanged("ResourceIds");
    2599           this.OnResourceIdsChanged();
    26002537        }
    26012538      }
     
    36213558          this.SendPropertyChanged("LastCleanup");
    36223559          this.OnLastCleanupChanged();
    3623         }
    3624       }
    3625     }
    3626    
    3627     public event PropertyChangingEventHandler PropertyChanging;
    3628    
    3629     public event PropertyChangedEventHandler PropertyChanged;
    3630    
    3631     protected virtual void SendPropertyChanging()
    3632     {
    3633       if ((this.PropertyChanging != null))
    3634       {
    3635         this.PropertyChanging(this, emptyChangingEventArgs);
    3636       }
    3637     }
    3638    
    3639     protected virtual void SendPropertyChanged(String propertyName)
    3640     {
    3641       if ((this.PropertyChanged != null))
    3642       {
    3643         this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    3644       }
    3645     }
    3646   }
    3647  
    3648   [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.ResourcePermission")]
    3649   public partial class ResourcePermission : INotifyPropertyChanging, INotifyPropertyChanged
    3650   {
    3651    
    3652     private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
    3653    
    3654     private System.Guid _ResourceId;
    3655    
    3656     private System.Guid _GrantedUserId;
    3657    
    3658     private System.Guid _GrantedByUserId;
    3659    
    3660     private EntityRef<Resource> _Resource;
    3661    
    3662     #region Extensibility Method Definitions
    3663     partial void OnLoaded();
    3664     partial void OnValidate(System.Data.Linq.ChangeAction action);
    3665     partial void OnCreated();
    3666     partial void OnResourceIdChanging(System.Guid value);
    3667     partial void OnResourceIdChanged();
    3668     partial void OnGrantedUserIdChanging(System.Guid value);
    3669     partial void OnGrantedUserIdChanged();
    3670     partial void OnGrantedByUserIdChanging(System.Guid value);
    3671     partial void OnGrantedByUserIdChanged();
    3672     #endregion
    3673    
    3674     public ResourcePermission()
    3675     {
    3676       this._Resource = default(EntityRef<Resource>);
    3677       OnCreated();
    3678     }
    3679    
    3680     [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ResourceId", DbType="UniqueIdentifier NOT NULL", IsPrimaryKey=true)]
    3681     public System.Guid ResourceId
    3682     {
    3683       get
    3684       {
    3685         return this._ResourceId;
    3686       }
    3687       set
    3688       {
    3689         if ((this._ResourceId != value))
    3690         {
    3691           if (this._Resource.HasLoadedOrAssignedValue)
    3692           {
    3693             throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
    3694           }
    3695           this.OnResourceIdChanging(value);
    3696           this.SendPropertyChanging();
    3697           this._ResourceId = value;
    3698           this.SendPropertyChanged("ResourceId");
    3699           this.OnResourceIdChanged();
    3700         }
    3701       }
    3702     }
    3703    
    3704     [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_GrantedUserId", DbType="UniqueIdentifier NOT NULL", IsPrimaryKey=true)]
    3705     public System.Guid GrantedUserId
    3706     {
    3707       get
    3708       {
    3709         return this._GrantedUserId;
    3710       }
    3711       set
    3712       {
    3713         if ((this._GrantedUserId != value))
    3714         {
    3715           this.OnGrantedUserIdChanging(value);
    3716           this.SendPropertyChanging();
    3717           this._GrantedUserId = value;
    3718           this.SendPropertyChanged("GrantedUserId");
    3719           this.OnGrantedUserIdChanged();
    3720         }
    3721       }
    3722     }
    3723    
    3724     [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_GrantedByUserId", DbType="UniqueIdentifier NOT NULL")]
    3725     public System.Guid GrantedByUserId
    3726     {
    3727       get
    3728       {
    3729         return this._GrantedByUserId;
    3730       }
    3731       set
    3732       {
    3733         if ((this._GrantedByUserId != value))
    3734         {
    3735           this.OnGrantedByUserIdChanging(value);
    3736           this.SendPropertyChanging();
    3737           this._GrantedByUserId = value;
    3738           this.SendPropertyChanged("GrantedByUserId");
    3739           this.OnGrantedByUserIdChanged();
    3740         }
    3741       }
    3742     }
    3743    
    3744     [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Resource_ResourcePermission", Storage="_Resource", ThisKey="ResourceId", OtherKey="ResourceId", IsForeignKey=true)]
    3745     public Resource Resource
    3746     {
    3747       get
    3748       {
    3749         return this._Resource.Entity;
    3750       }
    3751       set
    3752       {
    3753         Resource previousValue = this._Resource.Entity;
    3754         if (((previousValue != value)
    3755               || (this._Resource.HasLoadedOrAssignedValue == false)))
    3756         {
    3757           this.SendPropertyChanging();
    3758           if ((previousValue != null))
    3759           {
    3760             this._Resource.Entity = null;
    3761             previousValue.ResourcePermissions.Remove(this);
    3762           }
    3763           this._Resource.Entity = value;
    3764           if ((value != null))
    3765           {
    3766             value.ResourcePermissions.Add(this);
    3767             this._ResourceId = value.ResourceId;
    3768           }
    3769           else
    3770           {
    3771             this._ResourceId = default(System.Guid);
    3772           }
    3773           this.SendPropertyChanged("Resource");
    37743560        }
    37753561      }
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs

    r15508 r15527  
    10161016    #endregion
    10171017
    1018     #region ResourcePermission Methods
    1019     // only for authorized Administrator/ResourceOwner
    1020     public void GrantResourcePermissions(Guid resourceId, Guid[] grantedUserIds) {
    1021       RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    1022       AuthorizationManager.AuthorizeForResourceAdministration(resourceId);
    1023       var pm = PersistenceManager;
    1024       using(new PerformanceLogger("GrantResourcePermissions")) {
    1025         pm.UseTransaction(() => {
    1026           var resourceDao = pm.ResourceDao;
    1027           var resource = resourceDao.GetById(resourceId);
    1028           var resourcePermissions = resource.ResourcePermissions.ToList();
    1029           foreach(var id in grantedUserIds) {
    1030             if(resourcePermissions.All(x => x.GrantedUserId != id)) {
    1031               resource.ResourcePermissions.Add(new DA.ResourcePermission {
    1032                 GrantedUserId = id,
    1033                 GrantedByUserId = UserManager.CurrentUserId
    1034               });
    1035             }
    1036           }
    1037           pm.SubmitChanges();
    1038         });
    1039       }
    1040     }
    1041 
    1042 
    1043     // only for authorized Administrator/ResourceOwner
    1044     public void RevokeResourcePermissions(Guid resourceId, Guid[] grantedUserIds) {
    1045       RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    1046       AuthorizationManager.AuthorizeForResourceAdministration(resourceId);
    1047       var pm = PersistenceManager;
    1048       using(new PerformanceLogger("RevokeResourcePermission")) {
    1049         pm.UseTransaction(() => {
    1050           var resourcePermissionDao = pm.ResourcePermissionDao;
    1051           resourcePermissionDao.DeleteByResourceIdAndGrantedUserId(resourceId, grantedUserIds);
    1052           pm.SubmitChanges();
    1053         });
    1054       }
    1055     }
    1056 
    1057 
    1058     // OBSOLETE (change to public if...)
    1059     // only for authorized Administrator/ResourceOwner/(Sub)ProjectOwner to which the Resource (i.e. resourceId) is assigned
    1060     private void GrantResourcePermissions(Guid resourceId, Guid projectId, Guid[] grantedUserIds) {
    1061       RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    1062       //AuthorizationManager.AuthorizeForResourceAdministration(resourceId);
    1063       var pm = PersistenceManager;
    1064       using (new PerformanceLogger("GrantResourcePermissions")) {
    1065         pm.UseTransaction(() => {
    1066           // TODO-JAN
    1067           pm.SubmitChanges();
    1068         });
    1069       }
    1070     }
    1071 
    1072     // OBSOLETE (change to public if...)
    1073     // only for authorized Administrator/ResourceOwner/(Sub)ProjectOwner to which the Resource (i.e. resourceId) is assigned
    1074     private void RevokeResourcePermissions(Guid resourceId, Guid projectId, Guid[] grantedUserIds) {
    1075       // TODO-JAN
    1076     }
    1077 
    1078     #endregion
    1079 
    10801018    #region Downtime Methods
    10811019    public Guid AddDowntime(DT.Downtime downtimeDto) {
     
    12041142    //}
    12051143
    1206    private void CheckTaskPermissions(IPersistenceManager pm, DT.Task task, IEnumerable<Guid> resourceIds) {
     1144    private void CheckTaskPermissions(IPersistenceManager pm, DT.Task task, IEnumerable<Guid> resourceIds) {
    12071145      var jobDao = pm.JobDao;
    12081146      var projectDao = pm.ProjectDao;
    12091147      var resourceDao = pm.ResourceDao;
    1210       var resourcePermissionDao = pm.ResourcePermissionDao;
    12111148      var projectPermissionDao = pm.ProjectPermissionDao;
    12121149      var currentUserId = UserManager.CurrentUserId;
    1213 
    1214       //// PART 1: user-resource permission check (V1)
    1215       //// get granted (parent) resources
    1216       //var allGrantedResourceIds = pm.UseTransaction(() => {
    1217       //  return resourcePermissionDao.GetAll().ToList()
    1218       //    .Where(x => x.GrantedUserId == currentUserId
    1219       //      || UserManager.VerifyUser(currentUserId, new List<Guid> { x.GrantedUserId }))
    1220       //    .Select(y => y.ResourceId)
    1221       //    .ToList();
    1222       //});
    1223 
    1224       //// get children of granted parent resources
    1225       //var userGrantedChildResourceIds = pm.UseTransaction(() => {
    1226       //  return allGrantedResourceIds
    1227       //  .SelectMany(x => resourceDao.GetResourcesByParentId(x))
    1228       //  .Select(y => y.ResourceId);
    1229       //});
    1230 
    1231       //// join list of parent and child resources
    1232       //allGrantedResourceIds.AddRange(userGrantedChildResourceIds);
    1233 
    1234       // PART 1: user-resource permission check (V2)
    1235       // collect the current currentUserId and all Ids of affiliated groups
    1236       var userAndGroupIds = new List<Guid> { currentUserId };
    1237       userAndGroupIds.AddRange(UserManager.GetUserGroupIdsOfUser(currentUserId));
    1238 
    1239       // get all granted resourceIds
    1240       var allGrantedResourceIds = resourcePermissionDao.GetByUserAndGroupIds(userAndGroupIds).ToList();
    1241 
    1242       // get all owned resourceIds (including child resourceIds)
    1243       var ownedResourceIds = resourceDao.GetAll()
    1244         .Where(x => x.OwnerUserId == currentUserId)
    1245         .Select(x => x.ResourceId).ToList();
    1246       var ownedChildResourceIds = ownedResourceIds.SelectMany(x => resourceDao.GetResourceIdsByParentId(x));
    1247       ownedResourceIds.AddRange(ownedChildResourceIds);
    1248 
    1249       // join list of owned into the list with granted resourceIds
    1250       allGrantedResourceIds.AddRange(ownedResourceIds);
    1251 
    1252       // check the argument resourceIds against the list of granted (and owned) ones
    1253       if (resourceIds.Except(allGrantedResourceIds).Any()) {
    1254         throw new SecurityException(NOT_AUTHORIZED_RESOURCE);
    1255       }
    12561150
    12571151      // PART 2: user-project permission check
     
    12621156      // PART 3: project-resource permission check
    12631157      var assignedResourceIds = project.AssignedProjectResources.Select(x => x.ResourceId).ToList();
    1264       var assignedChildResourceIds = assignedResourceIds.SelectMany(x => resourceDao.GetResourceIdsByParentId(x));
     1158      var assignedChildResourceIds = assignedResourceIds.SelectMany(x => resourceDao.GetChildResourceIdsById(x));
    12651159      assignedResourceIds.AddRange(assignedChildResourceIds);
    12661160      if (resourceIds.Except(assignedResourceIds).Any()) {
     
    12791173      var projectDao = pm.ProjectDao;
    12801174      var projectBranch = new List<DA.Project>() { project };
    1281       projectBranch.AddRange(projectDao.GetProjectsByChildId(project.ProjectId));
     1175      projectBranch.AddRange(projectDao.GetParentProjectsById(project.ProjectId));
    12821176      if (projectBranch
    12831177        .Select(x => x.OwnerUserId)
    12841178        .Contains(UserManager.CurrentUserId)) {
    1285         return; 
     1179        return;
    12861180      }
    12871181
    12881182      // case 3
    1289       if(project.ProjectPermissions
     1183      if (project.ProjectPermissions
    12901184        .Select(x => x.GrantedUserId)
    12911185        .Contains(UserManager.CurrentUserId)) {
    12921186        return;
    12931187      }
    1294       if(projectBranch
     1188      if (projectBranch
    12951189        .SelectMany(x => x.ProjectPermissions)
    12961190        .Select(x => x.GrantedUserId)
     
    13081202
    13091203      var projectBranch = new List<DA.Project> { project };
    1310       projectBranch.AddRange(projectDao.GetProjectsByChildId(project.ProjectId));
     1204      projectBranch.AddRange(projectDao.GetParentProjectsById(project.ProjectId));
    13111205      var ownedProjects = projectBranch.Where(x => x.OwnerUserId == UserManager.CurrentUserId).ToList();
    13121206
    13131207      // get all assigned resourceIds (including children) of owned projects in this branch
    13141208      var assignedResourceIds = ownedProjects.SelectMany(x => x.AssignedProjectResources).Select(x => x.ResourceId).ToList();
    1315       var assignedChildResourceIds = assignedResourceIds.SelectMany(x => resourceDao.GetResourceIdsByChildId(x));
     1209      var assignedChildResourceIds = assignedResourceIds.SelectMany(x => resourceDao.GetParentResourceIdsById(x));
    13161210      assignedResourceIds.AddRange(assignedChildResourceIds);
    13171211
    13181212      // look up if all resourceIds are among the assigned ones
    1319       if(resourceIds.Except(assignedResourceIds).Any()) {
     1213      if (resourceIds.Except(assignedResourceIds).Any()) {
    13201214        throw new SecurityException(NOT_AUTHORIZED_RESOURCE);
    13211215      }
     
    13361230      // check if user is administrator, owner of the project or any parent project
    13371231      var projectTree = new List<DA.Project> { project };
    1338       projectTree.AddRange(projectDao.GetProjectsByChildId(projectId));
    1339       if(!projectTree.Select(x => x.OwnerUserId).Contains(UserManager.CurrentUserId)
     1232      projectTree.AddRange(projectDao.GetParentProjectsById(projectId));
     1233      if (!projectTree.Select(x => x.OwnerUserId).Contains(UserManager.CurrentUserId)
    13401234        && !RoleVerifier.IsInRole(HiveRoles.Administrator)) {
    13411235        throw new SecurityException(NOT_AUTHORIZED_PROJECT);
     
    13511245      // note: this should be faster than checking all children of the assigned
    13521246      // resource(-groups) for the certain resourceId
    1353       var parentResourceIds = resourceDao.GetResourceIdsByChildId(resourceId);
    1354       if(assignedResources.Select(x => x.ResourceId)
     1247      var parentResourceIds = resourceDao.GetParentResourceIdsById(resourceId);
     1248      if (assignedResources.Select(x => x.ResourceId)
    13551249        .Intersect(parentResourceIds).Count() > 0) {
    13561250        return resource;
Note: See TracChangeset for help on using the changeset viewer.