Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/10/16 15:04:15 (8 years ago)
Author:
abeham
Message:

#2588:

  • Added table, FK constraints, and FK indexes to database
  • Updated Linq2Sql mapping
  • Added service methods and dtos for downloading
Location:
trunk/sources/HeuristicLab.Services.OKB/3.3
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Services.OKB/3.3/HeuristicLab.Services.OKB-3.3.csproj

    r13501 r13682  
    283283    <Compile Include="RunCreation\DataTransfer\BinaryValue.cs" />
    284284    <Compile Include="RunCreation\DataTransfer\BoolValue.cs" />
     285    <Compile Include="RunCreation\DataTransfer\SingleObjectiveSolution.cs" />
     286    <Compile Include="RunCreation\DataTransfer\Solution.cs" />
    285287    <Compile Include="RunCreation\DataTransfer\TimeSpanValue.cs" />
    286288    <Compile Include="RunCreation\DataTransfer\PercentValue.cs" />
     
    295297    <Compile Include="RunCreation\DataTransfer\StringValue.cs" />
    296298    <Compile Include="RunCreation\DataTransfer\Value.cs" />
     299    <Compile Include="RunCreation\MissingSolution.cs" />
    297300    <Compile Include="RunCreation\MissingProblem.cs" />
    298301    <Compile Include="RunCreation\RunCreationService.cs" />
  • trunk/sources/HeuristicLab.Services.OKB/3.3/RunCreation/Convert.cs

    r13511 r13682  
    3838      if (source == null) return null;
    3939      return new DT.Problem { Id = source.Id, Name = source.Name, Description = source.Description, ProblemClass = Convert.ToDto(source.ProblemClass), DataType = Convert.ToDto(source.DataType) };
     40    }
     41
     42    public static DT.SingleObjectiveSolution ToDto(DA.SingleObjectiveSolution source) {
     43      if (source == null) return null;
     44      return new DT.SingleObjectiveSolution() {
     45        Id = source.Id,
     46        ProblemId = source.ProblemId.Value,
     47        RunId = source.RunId,
     48        Quality = source.Quality
     49      };
    4050    }
    4151
  • trunk/sources/HeuristicLab.Services.OKB/3.3/RunCreation/IRunCreationService.cs

    r13511 r13682  
    4444
    4545    [OperationContract]
     46    [FaultContract(typeof(MissingProblem))]
     47    IEnumerable<Solution> GetSolutions(long problemId);
     48
     49    [OperationContract]
     50    [FaultContract(typeof(MissingSolution))]
     51    byte[] GetSolutionData(long solutionId);
     52
     53    [OperationContract]
    4654    void AddRun(Run run);
    4755
  • trunk/sources/HeuristicLab.Services.OKB/3.3/RunCreation/MissingProblem.cs

    r13501 r13682  
    2828    public string Message { get; set; }
    2929
    30     public MissingProblem(string message, params object[] c) {
    31       Message = string.Format(message, c);
     30    public MissingProblem(long problemId) {
     31      Message = string.Format("Problem with id {0} cannot be found", problemId);
    3232    }
    3333  }
  • trunk/sources/HeuristicLab.Services.OKB/3.3/RunCreation/RunCreationService.cs

    r13513 r13682  
    127127    }
    128128
     129    public IEnumerable<DataTransfer.Solution> GetSolutions(long problemId) {
     130      roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser);
     131
     132      using (OKBDataContext okb = new OKBDataContext()) {
     133        var problem = okb.Problems.SingleOrDefault(x => x.Id == problemId);
     134        if (problem == null) throw new FaultException<MissingProblem>(new MissingProblem(problemId));
     135        // TODO: In case of multi-objective problems one has to check whether it contains single- or multi-objective problems
     136        var result = problem.SingleObjectiveSolutions.Select(x => Convert.ToDto(x)).ToList();
     137        if (roleVerifier.IsInRole(OKBRoles.OKBAdministrator)) {
     138          return result;
     139        } else {
     140          var problemUsers = okb.ProblemUsers.Where(x => x.ProblemId == problemId).ToList();
     141          if (problemUsers.Count == 0 || userManager.VerifyUser(userManager.CurrentUserId, problemUsers.Select(y => y.UserGroupId).ToList())) {
     142            return result;
     143          } else {
     144            return null;
     145          }
     146        }
     147      }
     148    }
     149
     150    public byte[] GetSolutionData(long solutionId) {
     151      roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser);
     152
     153      using (OKBDataContext okb = new OKBDataContext()) {
     154        var solution = okb.SingleObjectiveSolutions.SingleOrDefault(x => x.Id == solutionId);
     155        if (solution == null) throw new FaultException<MissingSolution>(new MissingSolution(solutionId));
     156
     157        var result = solution.BinaryData.Data.ToArray();
     158        if (roleVerifier.IsInRole(OKBRoles.OKBAdministrator)) {
     159          return result;
     160        } else {
     161          var problemUsers = okb.ProblemUsers.Where(x => x.ProblemId == solution.ProblemId).ToList();
     162          if (problemUsers.Count == 0 || userManager.VerifyUser(userManager.CurrentUserId, problemUsers.Select(y => y.UserGroupId).ToList())) {
     163            return result;
     164          } else {
     165            return null;
     166          }
     167        }
     168      }
     169    }
     170
    129171    public void AddRun(DataTransfer.Run run) {
    130172      roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser);
     
    150192      using (OKBDataContext okb = new OKBDataContext()) {
    151193        var problem = okb.Problems.SingleOrDefault(x => x.Id == problemId);
    152         if (problem == null) throw new FaultException<MissingProblem>(new MissingProblem("Problem with id {0} cannot be found", problemId));
     194        if (problem == null) throw new FaultException<MissingProblem>(new MissingProblem(problemId));
    153195
    154196        DoSetCharacteristicValue(okb, problem, value);
     
    162204      using (OKBDataContext okb = new OKBDataContext()) {
    163205        var problem = okb.Problems.SingleOrDefault(x => x.Id == problemId);
    164         if (problem == null) throw new FaultException<MissingProblem>(new MissingProblem("Problem with id {0} cannot be found", problemId));
     206        if (problem == null) throw new FaultException<MissingProblem>(new MissingProblem(problemId));
    165207
    166208        foreach (var v in values) {
Note: See TracChangeset for help on using the changeset viewer.