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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.