From 2598745a2ad8d5ea2a0277d3b0277882782e17b0 Mon Sep 17 00:00:00 2001 From: Bojnourdi Date: Tue, 11 Aug 2015 11:09:16 +0200 Subject: [PATCH] - Begin client DAO implementation --- .../src/java/com/edf/gde/dao/StudyDao.java | 12 +++-- .../src/java/com/edf/gde/ejb/StudyEJB.java | 4 +- .../src/java/com/edf/gde/entities/Study.java | 12 ++--- .../com/edf/gde/services/StudyService.java | 20 ++++++-- .../test/com/edf/gde/dao/StudyDaoClient.java | 51 +++++++++++++++++++ projects/GDE_App/GDE-war/web/WEB-INF/web.xml | 8 +++ 6 files changed, 92 insertions(+), 15 deletions(-) create mode 100644 projects/GDE_App/GDE-war/test/com/edf/gde/dao/StudyDaoClient.java diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/StudyDao.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/StudyDao.java index 17a1e12..e070442 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/StudyDao.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/StudyDao.java @@ -26,9 +26,15 @@ public class StudyDao { return s.toStudyTO(); } - public void deleteStudy(StudyTO sto) { - Study s = Study.fromStudyTO(sto); - em.remove(s); + public void deleteStudy(long studyId) { + /* + Study s = Study.fromStudyTO(sto); + em.remove(s); + */ + /* We never remove a study */ + Study study = em.find(Study.class, studyId); + study.setDeleted(true); + study.setDeletionDate(new Date(System.currentTimeMillis())); } public StudyTO updateStudy(StudyTO sto) { diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/ejb/StudyEJB.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/ejb/StudyEJB.java index b2496bd..527ecd3 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/ejb/StudyEJB.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/ejb/StudyEJB.java @@ -27,9 +27,9 @@ public class StudyEJB { return dao.createStudy(sto); } - public void deleteStudy(StudyTO sto) { + public void deleteStudy(long studyId) { StudyDao dao = new StudyDao(em); - dao.deleteStudy(sto); + dao.deleteStudy(studyId); } public StudyTO updateStudy(StudyTO sto) { diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Study.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Study.java index 68687a2..9eca10a 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Study.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Study.java @@ -57,9 +57,9 @@ public class Study implements Serializable { @Temporal(TemporalType.TIMESTAMP) private Date updateDate; @Column(name = "valid") - private Boolean valid; + private boolean valid; @Column(name = "deleted") - private Boolean deleted; + private boolean deleted; @Column(name = "deletion_date") @Temporal(TemporalType.TIMESTAMP) private Date deletionDate; @@ -108,19 +108,19 @@ public class Study implements Serializable { this.updateDate = updateDate; } - public Boolean getValid() { + public boolean getValid() { return valid; } - public void setValid(Boolean valid) { + public void setValid(boolean valid) { this.valid = valid; } - public Boolean getDeleted() { + public boolean getDeleted() { return deleted; } - public void setDeleted(Boolean deleted) { + public void setDeleted(boolean deleted) { this.deleted = deleted; } 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 57ce633..b432759 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 @@ -17,14 +17,15 @@ import javax.servlet.http.HttpServletResponse; /** * - * @author mordicus + * @author Kavoos */ public class StudyService extends BaseService { public static final String ServiceName = "StudyService"; - public static final int CREATESTUDY = 1; + public static final int CREATESTUDY = 1; public static final int SETSTUDYSTATE = 2; - + public static final int FINDSTUDYBYID = 3; + public static final int DELETESTUDY = 4; @EJB private StudyEJB studyEjb; @EJB @@ -51,10 +52,21 @@ public class StudyService extends BaseService { case SETSTUDYSTATE: { long studyId = commandTO.getLong("studyId"); int lock = commandTO.getInt("lock"); - boolean status = (lock==1); + boolean status = (lock == 1); studyEjb.setStudyState(studyId, status); } break; + case FINDSTUDYBYID: { + long studyId = commandTO.getLong("studyId"); + StudyTO studyTO = studyEjb.findById(studyId); + resultTO.setData(toJson(studyTO)); + } + break; + case DELETESTUDY: { + long studyId = commandTO.getLong("studyId"); + studyEjb.deleteStudy(studyId); + } + break; } } catch (Exception ex) { // Return error on any error... 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 new file mode 100644 index 0000000..73e256a --- /dev/null +++ b/projects/GDE_App/GDE-war/test/com/edf/gde/dao/StudyDaoClient.java @@ -0,0 +1,51 @@ +/* + * (C) 2015 EDF + */ +package com.edf.gde.dao; + +import com.edf.gde.transferables.CommandTO; +import com.edf.gde.transferables.StudyTO; +import com.edf.gde.transferables.responses.CommandResultTO; +import java.io.IOException; +import restapi.RestContext; + +/** + * + * @author Kavoos + */ +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 DELETESTUDY = 4; + + protected DaoResponseHandler daoResponseHandler; + + public StudyDaoClient() { + getContext().setBaseResource("http://localhost:8080/GDE-war/StudyService"); + getContext().setUserName("admin"); + getContext().setPassword("edf123"); + daoResponseHandler = new DaoResponseHandler(); + } + + public StudyDaoClient(RestContext context) { + super(context); + daoResponseHandler = new DaoResponseHandler(); + } + + public StudyTO createStudy(StudyTO studyTO) throws IOException { + CommandTO commandTO = createCommand(CREATESTUDY); + commandTO.setData(toJson(studyTO)); + 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 create study"); + } + +} diff --git a/projects/GDE_App/GDE-war/web/WEB-INF/web.xml b/projects/GDE_App/GDE-war/web/WEB-INF/web.xml index bd50585..29d9579 100644 --- a/projects/GDE_App/GDE-war/web/WEB-INF/web.xml +++ b/projects/GDE_App/GDE-war/web/WEB-INF/web.xml @@ -8,6 +8,10 @@ UserServce com.edf.gde.services.UserService + + StudyService + com.edf.gde.services.StudyService + MetadataService /MetadataService @@ -16,6 +20,10 @@ UserServce /UserService + + StudyService + /StudyService + 30 -- 2.39.2