Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/29/09 13:46:38 (15 years ago)
Author:
msteinbi
Message:

new methods for project within job manager (#466)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Server.Core/3.2/JobManager.cs

    r1934 r1948  
    3030using HeuristicLab.Hive.Server.Core.InternalInterfaces;
    3131using HeuristicLab.DataAccess.Interfaces;
     32using System.Data;
    3233
    3334namespace HeuristicLab.Hive.Server.Core {
     
    356357
    357358    public ResponseList<Project> GetAllProjects() {
    358       IList<Project> testList = new List<Project>();
    359 
    360       Project p1 = new Project();
    361       p1.Id = Guid.NewGuid();
    362       p1.Name = "TestProject1";
    363       Project p2 = new Project();
    364       p2.Id = Guid.NewGuid();
    365       p2.Name = "TestProject2";
    366       Project p3 = new Project();
    367       p3.Id = Guid.NewGuid();
    368       p3.Name = "TestProject3";
    369       Project p4 = new Project();
    370       p4.Id = Guid.NewGuid();
    371       p4.Name = "TestProject4";
    372       testList.Add(p1);
    373       testList.Add(p2);
    374       testList.Add(p3);
    375       testList.Add(p4);
    376 
     359      ISession session = factory.GetSessionForCurrentThread();
    377360      ResponseList<Project> response = new ResponseList<Project>();
    378       response.List = testList;
    379       response.Success = true;
    380 
     361
     362      try {
     363        IProjectAdapter projectAdapter =
     364          session.GetDataAdapter<Project, IProjectAdapter>();
     365
     366        List<Project> allProjects = new List<Project>(projectAdapter.GetAll());
     367        response.List = allProjects;
     368        response.Success = true;
     369        return response;
     370      }
     371      finally {
     372        if (session != null)
     373          session.EndSession();
     374      }
     375    }
     376
     377    private Response createUpdateProject(Project project) {
     378      ISession session = factory.GetSessionForCurrentThread();
     379      Response response = new Response();
     380      ITransaction tx = null;
     381
     382      try {
     383        IProjectAdapter projectAdapter =
     384          session.GetDataAdapter<Project, IProjectAdapter>();
     385
     386        if (project.Name == null || project.Name == "") {
     387          response.Success = false;
     388          response.StatusMessage = ApplicationConstants.RESPONSE_JOB_PROJECT_NAME_EMPTY;
     389          return response;
     390        }
     391        tx = session.BeginTransaction();
     392        projectAdapter.Update(project);
     393
     394        tx.Commit();
     395        response.Success = true;
     396        response.StatusMessage = ApplicationConstants.RESPONSE_JOB_PROJECT_ADDED;
     397      } catch (ConstraintException ce) {
     398        if (tx != null)
     399          tx.Rollback();
     400        response.Success = false;
     401        response.StatusMessage = ce.Message;
     402      }
     403      catch (Exception ex) {
     404        if (tx != null)
     405          tx.Rollback();
     406        throw ex;
     407      }
     408      finally {
     409        if (session != null)
     410          session.EndSession();
     411      }
    381412      return response;
    382413    }
    383414
    384415    public Response CreateProject(Project project) {
    385       throw new NotImplementedException();
     416      return createUpdateProject(project);
    386417    }
    387418
    388419    public Response ChangeProject(Project project) {
    389       throw new NotImplementedException();
     420      return createUpdateProject(project);
    390421    }
    391422
    392423    public Response DeleteProject(Guid projectId) {
    393       throw new NotImplementedException();
     424      ISession session = factory.GetSessionForCurrentThread();
     425      Response response = new Response();
     426      ITransaction tx = null;
     427
     428      try {
     429        IProjectAdapter projectAdapter =
     430          session.GetDataAdapter<Project, IProjectAdapter>();
     431
     432        Project project = projectAdapter.GetById(projectId);
     433        if (project == null) {
     434          response.Success = false;
     435          response.StatusMessage = ApplicationConstants.RESPONSE_JOB_PROJECT_DOESNT_EXIST;
     436          return response;
     437        }
     438        projectAdapter.Delete(project);
     439        tx.Commit();
     440        response.Success = true;
     441        response.StatusMessage = ApplicationConstants.RESPONSE_JOB_PROJECT_DELETED;
     442      }
     443      catch (Exception e) {
     444        if (tx != null)
     445          tx.Rollback();
     446        response.Success = false;
     447        response.StatusMessage = e.Message;
     448      }
     449      finally {
     450        if (session != null)
     451          session.EndSession();
     452      }
     453      return response;
    394454    }
    395455
    396456    public ResponseList<Job> GetJobsByProject(Guid projectId) {
    397       throw new NotImplementedException();
     457      ISession session = factory.GetSessionForCurrentThread();
     458      ResponseList<Job> response = new ResponseList<Job>();
     459
     460      try {
     461        IJobAdapter jobAdapter =
     462          session.GetDataAdapter<Job, IJobAdapter>();
     463        List<Job> jobsByProject = new List<Job>(jobAdapter.GetJobsByProject(projectId));
     464        response.List = jobsByProject;
     465        response.Success = true;
     466      }
     467      finally {
     468        if (session != null)
     469          session.EndSession();
     470      }
     471      return response;
    398472    }
    399473
Note: See TracChangeset for help on using the changeset viewer.