From 4172e9644d60d5e15213b7fb99870281ed60a4c8 Mon Sep 17 00:00:00 2001 From: Bojnourdi Date: Tue, 11 Aug 2015 11:22:18 +0200 Subject: [PATCH] - Study DAO client finished. --- .../com/edf/gde/services/StudyService.java | 4 +- .../test/com/edf/gde/dao/StudyDaoClient.java | 39 ++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/projects/GDE_App/GDE-war/src/java/com/edf/gde/services/StudyService.java b/projects/GDE_App/GDE-war/src/java/com/edf/gde/services/StudyService.java index b432759..4f53707 100644 --- a/projects/GDE_App/GDE-war/src/java/com/edf/gde/services/StudyService.java +++ b/projects/GDE_App/GDE-war/src/java/com/edf/gde/services/StudyService.java @@ -24,7 +24,7 @@ public class StudyService extends BaseService { public static final String ServiceName = "StudyService"; public static final int CREATESTUDY = 1; public static final int SETSTUDYSTATE = 2; - public static final int FINDSTUDYBYID = 3; + public static final int READSTUDY = 3; public static final int DELETESTUDY = 4; @EJB private StudyEJB studyEjb; @@ -56,7 +56,7 @@ public class StudyService extends BaseService { studyEjb.setStudyState(studyId, status); } break; - case FINDSTUDYBYID: { + case READSTUDY: { long studyId = commandTO.getLong("studyId"); StudyTO studyTO = studyEjb.findById(studyId); resultTO.setData(toJson(studyTO)); diff --git a/projects/GDE_App/GDE-war/test/com/edf/gde/dao/StudyDaoClient.java b/projects/GDE_App/GDE-war/test/com/edf/gde/dao/StudyDaoClient.java index 73e256a..75146a9 100644 --- a/projects/GDE_App/GDE-war/test/com/edf/gde/dao/StudyDaoClient.java +++ b/projects/GDE_App/GDE-war/test/com/edf/gde/dao/StudyDaoClient.java @@ -18,7 +18,7 @@ public class StudyDaoClient extends BaseDao { public static final String ServiceName = "StudyService"; public static final int CREATESTUDY = 1; public static final int SETSTUDYSTATE = 2; - public static final int FINDSTUDYBYID = 3; + public static final int READSTUDY = 3; public static final int DELETESTUDY = 4; protected DaoResponseHandler daoResponseHandler; @@ -48,4 +48,41 @@ public class StudyDaoClient extends BaseDao { throw new RuntimeException("Unable to create study"); } + public void setStudyState(long studyId, int state) throws IOException { + CommandTO commandTO = createCommand(SETSTUDYSTATE); + commandTO.setInt("lock", state); + commandTO.setLong("studyId", studyId); + if (postAsJSonData(commandTO, daoResponseHandler)) { + CommandResultTO resultTO = daoResponseHandler.getResultTO(); + if (resultTO.getCode() != CommandResultTO.OK) { + throw new RuntimeException("Server error"); + } + } + throw new RuntimeException("Unable to change study state"); + } + + public StudyTO readStudy(long studyId) throws IOException { + CommandTO commandTO = createCommand(READSTUDY); + commandTO.setLong("studyId", studyId); + if (postAsJSonData(commandTO, daoResponseHandler)) { + CommandResultTO resultTO = daoResponseHandler.getResultTO(); + if (resultTO.getCode() == CommandResultTO.OK) { + StudyTO newStudyTO = fromJson(resultTO.getData(), StudyTO.class); + return newStudyTO; + } + } + throw new RuntimeException("Unable to read study"); + } + + public void deleteStudy(long studyId) throws IOException { + CommandTO commandTO = createCommand(DELETESTUDY); + commandTO.setLong("studyId", studyId); + if (postAsJSonData(commandTO, daoResponseHandler)) { + CommandResultTO resultTO = daoResponseHandler.getResultTO(); + if (resultTO.getCode() != CommandResultTO.OK) { + throw new RuntimeException("Server error"); + } + } + throw new RuntimeException("Unable to delete study"); + } } -- 2.39.2