Free cookie consent management tool by TermsFeed Policy Generator

Changeset 934 for trunk/sources


Ignore:
Timestamp:
12/10/08 11:35:34 (16 years ago)
Author:
msteinbi
Message:

Implementation of UserRoleManager (#417)

Location:
trunk/sources
Files:
1 added
1 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Contracts/ApplicationConstants.cs

    r929 r934  
    1212    public static string RESPONSE_USERROLE_USER_DOESNT_EXIST = "UserRole.UserDoesntExist";
    1313    public static string RESPONSE_USERROLE_USER_REMOVED = "UserRole.UserRemoved";
     14    public static string RESPONSE_USERROLE_USERGROUP_EXISTS_ALLREADY = "UserRole.UsergroupExistsAllready";
     15    public static string RESPONSE_USERROLE_USERGROUP_ADDED = "UserRole.UserGroupAdded";
     16    public static string RESPONSE_USERROLE_USERGROUP_DOESNT_EXIST = "UserRole.UserGroupDoesntExist";
     17    public static string RESPONSE_USERROLE_PERMISSIONOWNER_DOESNT_EXIST = "UserRole.PermissionOwnerDoesntExist";
     18    public static string RESPONSE_USERROLE_PERMISSIONOWNER_REMOVED = "UserRole.PermissionOwnerRemoved";
     19    public static string RESPONSE_USERROLE_PERMISSIONOWNER_ADDED = "UserRole.PermissionOwnerAdded";
     20    public static string RESPONSE_USERROLE_GET_ALL_USERGROUPS = "UserRole.AllUserGroupsReturned";
    1421
    1522    public static string RESPONSE_CLIENT_GET_ALL_CLIENTS = "Client.GetAllClients";
     23    public static string RESPONSE_CLIENT_GET_ALL_CLIENTGROUPS = "Client.GetAllClientGroups";
    1624
    1725    public static string RESPONSE_COMMUNICATOR_HARDBEAT_RECEIVED = "Communicator.HeardbeatReceived";
  • trunk/sources/HeuristicLab.Hive.Contracts/BusinessObjects/ClientGroup.cs

    r827 r934  
    3434    [DataMember]
    3535    public List<Resource> Resources { get; set; }
     36
     37    public ClientGroup() {
     38      Resources = new List<Resource>();
     39    }
    3640  }
    3741}
  • trunk/sources/HeuristicLab.Hive.Contracts/BusinessObjects/UserGroup.cs

    r930 r934  
    3232    [DataMember]
    3333    public IList<PermissionOwner> Members { get; set; }
     34
     35    public UserGroup() {
     36      Members = new List<PermissionOwner>();
     37    }
    3438  }
    3539}
  • trunk/sources/HeuristicLab.Hive.Contracts/HeuristicLab.Hive.Contracts.csproj

    r925 r934  
    44    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    55    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    6     <ProductVersion>9.0.21022</ProductVersion>
     6    <ProductVersion>9.0.30729</ProductVersion>
    77    <SchemaVersion>2.0</SchemaVersion>
    88    <ProjectGuid>{134F93D7-E7C8-4ECD-9923-7F63259A60D8}</ProjectGuid>
     
    116116    <None Include="Properties\AssemblyInfo.frame" />
    117117  </ItemGroup>
     118  <ItemGroup>
     119    <EmbeddedResource Include="HiveServerMessages.resx" />
     120  </ItemGroup>
    118121  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    119122  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  • trunk/sources/HeuristicLab.Hive.Contracts/Interfaces/IClientManager.cs

    r902 r934  
    1919    ResponseList<ClientGroup> GetAllClientGroups();
    2020    [OperationContract]
     21    Response AddClientGroup(ClientGroup clientGroup);
     22    [OperationContract]
     23    Response AddResourceToGroup(long clientGroupId, Resource resource);
     24    [OperationContract]
     25    Response DeleteResourceFromGroup(long clientGroupId, long resourceId);
     26    [OperationContract]
    2127    ResponseList<UpTimeStatistics> GetAllUpTimeStatistics();
    2228  }
  • trunk/sources/HeuristicLab.Hive.Contracts/Interfaces/IUserRoleManager.cs

    r902 r934  
    2525    ResponseList<UserGroup> GetAllUserGroups();
    2626    [OperationContract]
    27     Response AddUserToGroup(long groupId, long userId);
     27    Response AddPermissionOwnerToGroup(long groupId, PermissionOwner permissionOwner);
    2828    [OperationContract]
    29     Response RemoveUserFromGroup(long groupId, long userId);
     29    Response RemovePermissionOwnerFromGroup(long groupId, long userId);
    3030  }
    3131}
  • trunk/sources/HeuristicLab.Hive.Server.Core/ClientCommunicator.cs

    r929 r934  
    1616  /// </summary>
    1717  public class ClientCommunicator: IClientCommunicator {
    18     List<ClientInfo> clients;
    1918    LinkedList<long> jobs;
    2019    int nrOfJobs = 1;
  • trunk/sources/HeuristicLab.Hive.Server.Core/ClientManager.cs

    r929 r934  
    3333
    3434    IClientAdapter clientAdapter;
     35    IClientGroupAdapter clientGroupAdapter;
    3536
    36     List<ClientInfo> clients;
    3737    List<ClientGroup> clientGroups;
    3838
    3939    public ClientManager() {
    4040      clientAdapter = ServiceLocator.GetClientAdapter();
     41      clientGroupAdapter = ServiceLocator.GetClientGroupAdapter();
    4142
    42       clients = new List<ClientInfo>();
    4343      clientGroups = new List<ClientGroup>();
    44 
    45       ClientInfo c1 = new ClientInfo { ClientId=Guid.NewGuid(), Name="Client1", CpuSpeedPerCore=2500, Memory=4096, ResourceId=1, State=State.idle };
    46       ClientInfo c2 = new ClientInfo { ClientId=Guid.NewGuid(), Name="Client2",  CpuSpeedPerCore=2100, Memory=2048, ResourceId=2, State=State.idle };
    47       ClientInfo c3 = new ClientInfo { ClientId = Guid.NewGuid(), Name="Client3", CpuSpeedPerCore = 3400, Memory = 4096, ResourceId = 3, State = State.calculating };
    48 
    49       clients.Add(c1);
    50       clients.Add(c2);
    51       clients.Add(c3);
    5244
    5345      ClientGroup cg = new ClientGroup { ResourceId = 4, Name = "SuperGroup", ClientGroupId = 1 };
    5446      cg.Resources = new List<Resource>();
    55       cg.Resources.Add(c1);     
    56       cg.Resources.Add(c2);
    57       cg.Resources.Add(c3);
    5847
    5948      clientGroups.Add(cg);
     
    7463    public ResponseList<ClientGroup> GetAllClientGroups() {
    7564      ResponseList<ClientGroup> response = new ResponseList<ClientGroup>();
    76       response.List = clientGroups;
     65
     66      response.List = new List<ClientGroup>(clientGroupAdapter.GetAllClientGroups());
     67      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTGROUPS;
    7768      response.Success = true;
     69
    7870      return response;
    7971    }
     
    8577    }
    8678
     79    public Response AddClientGroup(ClientGroup clientGroup) {
     80      throw new NotImplementedException();
     81    }
     82
     83    public Response AddResourceToGroup(long clientGroupId, Resource resource) {
     84      throw new NotImplementedException();
     85    }
     86
     87    public Response DeleteResourceFromGroup(long clientGroupId, long resourceId) {
     88      throw new NotImplementedException();
     89    }
    8790    #endregion
    8891  }
  • trunk/sources/HeuristicLab.Hive.Server.Core/HeuristicLab.Hive.Server.Core.csproj

    r925 r934  
    44    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    55    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    6     <ProductVersion>9.0.21022</ProductVersion>
     6    <ProductVersion>9.0.30729</ProductVersion>
    77    <SchemaVersion>2.0</SchemaVersion>
    88    <ProjectGuid>{898B31CF-81DC-453B-AEB3-BDF83197A7EE}</ProjectGuid>
     
    103103    </ProjectReference>
    104104  </ItemGroup>
    105   <ItemGroup>
    106     <EmbeddedResource Include="HiveServerMessages.resx" />
    107   </ItemGroup>
    108105  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    109106  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  • trunk/sources/HeuristicLab.Hive.Server.Core/ServerConsoleFacade.cs

    r925 r934  
    4848    }
    4949
     50    public Response AddClientGroup(ClientGroup clientGroup) {
     51      return clientManager.AddClientGroup(clientGroup);
     52    }
     53
     54    public Response AddResourceToGroup(long clientGroupId, Resource resource) {
     55      return clientManager.AddResourceToGroup(clientGroupId, resource);
     56    }
     57
     58    public Response DeleteResourceFromGroup(long clientGroupId, long resourceId) {
     59      return clientManager.DeleteResourceFromGroup(clientGroupId, resourceId);
     60    }
     61
    5062    #endregion
    5163
     
    7385
    7486    public Response RemoveUser(long userId) {
    75       throw new NotImplementedException();
     87      return userRoleManager.RemoveUser(userId);
    7688    }
    7789
    7890    public Response AddNewUserGroup(UserGroup userGroup) {
    79       throw new NotImplementedException();
     91      return userRoleManager.AddNewUserGroup(userGroup);
    8092    }
    8193
    8294    public Response RemoveUserGroup(long groupId) {
    83       throw new NotImplementedException();
     95      return userRoleManager.RemoveUserGroup(groupId);
    8496    }
    8597
    86     public Response AddUserToGroup(long groupId, long userId) {
    87       throw new NotImplementedException();
     98    public Response AddPermissionOwnerToGroup(long groupId, PermissionOwner permissionOwner) {
     99      return userRoleManager.AddPermissionOwnerToGroup(groupId, permissionOwner);
    88100    }
    89101
    90     public Response RemoveUserFromGroup(long groupId, long userId) {
    91       throw new NotImplementedException();
     102    public Response RemovePermissionOwnerFromGroup(long groupId, long userId) {
     103      return userRoleManager.RemovePermissionOwnerFromGroup(groupId, userId);
    92104    }
    93105
    94106    #endregion
    95 
    96107  }
    97108}
  • trunk/sources/HeuristicLab.Hive.Server.Core/UserRoleManager.cs

    r929 r934  
    1313  class UserRoleManager: IUserRoleManager {
    1414
    15     List<User> users;
    16     List<UserGroup> userGroups;
    17 
    1815    IUserAdapter userAdapter;
     16    IUserGroupAdapter userGroupAdapter;
    1917
    2018    public UserRoleManager() {
    2119      userAdapter = ServiceLocator.GetUserAdapter();
    22 
    23       users = new List<User>();
    24       userGroups = new List<UserGroup>();
    25 
    26       users.Add(new User { PermissionOwnerId = 1, Name = "Hugo", Password = "hUg0" });
    27       users.Add(new User { PermissionOwnerId = 2, Name = "Seppl", Password = "seppl" });
    28       users.Add(new User { PermissionOwnerId = 3, Name = "Greg", Password = "greg" });
    29 
    30       userGroups.Add(new UserGroup { PermissionOwnerId = 4 });
    31       userGroups.Add(new UserGroup { PermissionOwnerId = 5 });
     20      userGroupAdapter = ServiceLocator.GetUserGroupAdapter();
    3221    }
    3322
     
    6453      ResponseList<UserGroup> response = new ResponseList<UserGroup>();
    6554
     55      response.List = new List<UserGroup>(userGroupAdapter.GetAllUserGroups());
     56      response.Success = true;
     57      response.StatusMessage = ApplicationConstants.RESPONSE_USERROLE_GET_ALL_USERGROUPS;
     58
    6659      return response;
    6760    }
     
    7568        return response;
    7669      }
     70      userAdapter.DeleteUser(user);
    7771      response.Success = true;
    7872      response.StatusMessage = ApplicationConstants.RESPONSE_USERROLE_USER_REMOVED;
     
    8276
    8377    public Response AddNewUserGroup(UserGroup userGroup) {
    84       return null;
     78      Response response = new Response();
     79
     80      UserGroup userGroupFromDb = userGroupAdapter.GetUserGroupById(userGroup.PermissionOwnerId);
     81      if (userGroupFromDb != null) {
     82        response.Success = false;
     83        response.StatusMessage = ApplicationConstants.RESPONSE_USERROLE_USERGROUP_EXISTS_ALLREADY;
     84        return response;
     85      }
     86      userGroupAdapter.UpdateUserGroup(userGroup);
     87      response.Success = false;
     88      response.StatusMessage = ApplicationConstants.RESPONSE_USERROLE_USERGROUP_ADDED;
     89
     90      return response;
    8591    }
    8692
    8793    public Response RemoveUserGroup(long groupId) {
    88       return null;
     94      Response response = new Response();
     95
     96      UserGroup userGroupFromDb = userGroupAdapter.GetUserGroupById(groupId);
     97      if (userGroupFromDb == null) {
     98        response.Success = false;
     99        response.StatusMessage = ApplicationConstants.RESPONSE_USERROLE_USERGROUP_DOESNT_EXIST;
     100        return response;
     101      }
     102      userGroupAdapter.DeleteUserGroup(userGroupFromDb);
     103      response.Success = false;
     104      response.StatusMessage = ApplicationConstants.RESPONSE_USERROLE_USERGROUP_ADDED;
     105
     106      return response;
    89107    }
    90108
    91     public Response AddUserToGroup(long groupId, long userId) {
    92       throw new NotImplementedException();
     109    public Response AddPermissionOwnerToGroup(long groupId, PermissionOwner permissionOwner) {
     110      Response response = new Response();
     111     
     112      UserGroup userGroup = userGroupAdapter.GetUserGroupById(groupId);
     113      if (userGroup == null) {
     114        response.Success = false;
     115        response.StatusMessage = ApplicationConstants.RESPONSE_USERROLE_USERGROUP_DOESNT_EXIST;
     116        return response;
     117      }
     118      userGroup.Members.Add(permissionOwner);
     119      userGroupAdapter.UpdateUserGroup(userGroup);
     120
     121      response.Success = true;
     122      response.StatusMessage = ApplicationConstants.RESPONSE_USERROLE_PERMISSIONOWNER_ADDED;
     123
     124      return response;
    93125    }
    94126
    95     public Response RemoveUserFromGroup(long groupId, long userId) {
    96       throw new NotImplementedException();
     127    public Response RemovePermissionOwnerFromGroup(long groupId, long permissionOwnerId) {
     128      Response response = new Response();
     129
     130      UserGroup userGroup = userGroupAdapter.GetUserGroupById(groupId);
     131      if (userGroup == null) {
     132        response.Success = false;
     133        response.StatusMessage = ApplicationConstants.RESPONSE_USERROLE_USERGROUP_DOESNT_EXIST;
     134        return response;
     135      }
     136      User user = userAdapter.GetUserById(permissionOwnerId);
     137      if (user == null) {
     138        response.Success = false;
     139        response.StatusMessage = ApplicationConstants.RESPONSE_USERROLE_PERMISSIONOWNER_DOESNT_EXIST;
     140        return response;
     141      }
     142      foreach (PermissionOwner permissionOwner in userGroup.Members) {
     143        if (permissionOwner.PermissionOwnerId == permissionOwnerId) {
     144          userGroup.Members.Remove(permissionOwner);
     145          userGroupAdapter.UpdateUserGroup(userGroup);
     146          response.Success = true;
     147          response.StatusMessage = ApplicationConstants.RESPONSE_USERROLE_PERMISSIONOWNER_REMOVED;
     148          return response;
     149        }
     150      }
     151      response.Success = false;
     152      response.StatusMessage = ApplicationConstants.RESPONSE_USERROLE_PERMISSIONOWNER_DOESNT_EXIST;
     153     
     154      return response;
    97155    }
    98156
Note: See TracChangeset for help on using the changeset viewer.