From d734f762a644a0f127f09e28faab8a39dbc65447 Mon Sep 17 00:00:00 2001 From: Salman Manoe Date: Tue, 31 Dec 2024 16:59:08 +0700 Subject: [PATCH] Update controller Clean code --- .../controller/PerlakuanController.java | 137 +++---- ...PermintaanBarangDariRuanganController.java | 82 ---- .../PermintaanPenunjangController.java | 36 -- .../controller/PersepsiKognisiController.java | 118 ++---- .../controller/PersepsiPasienController.java | 118 ++---- .../controller/PerspektifController.java | 131 ++---- .../PertanyaanSurveyController.java | 189 +++------ .../PesertaAsuransiBpjsNakerController.java | 121 +++--- .../controller/PesertaDidikController.java | 163 ++------ .../controller/PioController.java | 165 ++------ ...nningDiklatHumasMarketBiayaController.java | 174 ++++---- .../PlanningDiklatHumasMarketController.java | 377 ++++++------------ 12 files changed, 541 insertions(+), 1270 deletions(-) delete mode 100644 jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PermintaanBarangDariRuanganController.java delete mode 100644 jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PermintaanPenunjangController.java diff --git a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PerlakuanController.java b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PerlakuanController.java index 8df96ecd..4154cdc8 100644 --- a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PerlakuanController.java +++ b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PerlakuanController.java @@ -1,111 +1,76 @@ package com.jasamedika.medifirst2000.controller; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; - +import com.jasamedika.medifirst2000.base.vo.BaseModelVO; +import com.jasamedika.medifirst2000.constants.MessageResource; +import com.jasamedika.medifirst2000.controller.base.LocaleController; +import com.jasamedika.medifirst2000.exception.ServiceVOException; +import com.jasamedika.medifirst2000.service.PerlakuanService; +import com.jasamedika.medifirst2000.vo.PerlakuanVO; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.orm.jpa.JpaSystemException; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.jasamedika.medifirst2000.base.vo.BaseModelVO; -import com.jasamedika.medifirst2000.constants.Constants; -import com.jasamedika.medifirst2000.constants.MessageResource; -import com.jasamedika.medifirst2000.controller.base.LocaleController; -import com.jasamedika.medifirst2000.core.web.WebConstants; -import com.jasamedika.medifirst2000.exception.ServiceVOException; -import com.jasamedika.medifirst2000.service.PerlakuanService; -import com.jasamedika.medifirst2000.util.rest.RestUtil; -import com.jasamedika.medifirst2000.vo.PerlakuanVO; +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.util.Map; + +import static com.jasamedika.medifirst2000.constants.Constants.MessageInfo.ERROR_MESSAGE; +import static com.jasamedika.medifirst2000.core.web.WebConstants.HttpHeaderInfo.LABEL_SUCCESS; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonHttpStatus; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonResponse; +import static org.slf4j.LoggerFactory.getLogger; +import static org.springframework.http.HttpStatus.*; +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import static org.springframework.web.bind.annotation.RequestMethod.GET; +import static org.springframework.web.bind.annotation.RequestMethod.POST; @RestController @RequestMapping("/perlakuan") -public class PerlakuanController extends LocaleController{ - private static final Logger LOGGER = LoggerFactory - .getLogger(PerlakuanController.class); - +public class PerlakuanController extends LocaleController { + + private static final Logger LOGGER = getLogger(PerlakuanController.class); + @Autowired private PerlakuanService perlakuanService; - - @RequestMapping(value = "/save-perlakuan/", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> addVO(@Valid @RequestBody PerlakuanVO vo,HttpServletRequest request) { - - try{ + + @RequestMapping(value = "/save-perlakuan/", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) + public ResponseEntity> addVO(@Valid @RequestBody PerlakuanVO vo, HttpServletRequest request) { + try { Map result = perlakuanService.savePerlakuan(vo); if (null != result) - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS,request)); - return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage); + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, CREATED, mapHeaderMessage); } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when add perlakuan", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, - mapHeaderMessage); - + LOGGER.error("Got ServiceVOException {} when savePerlakuan", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when add limbah b3 keluar", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, - mapHeaderMessage); + LOGGER.error("Got JpaSystemException {} when savePerlakuan", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } } - - @RequestMapping(value = "/get-all-perlakuan/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> getAllVO(HttpServletRequest request) { - - try { - Map result=perlakuanService.getPerlakuanAll(); - if (null != result) - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS,request )); - return RestUtil.getJsonResponse(result, HttpStatus.CREATED,mapHeaderMessage); - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when get all perlakuan", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, - mapHeaderMessage); - } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when get all perlakuan", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, - mapHeaderMessage); - } - } - - @RequestMapping(value = "/get-by-id", method = RequestMethod.GET) - public ResponseEntity> getById( - @RequestParam(value = "id", required = true) Integer id,HttpServletRequest request) { - + + @RequestMapping(value = "/get-all-perlakuan/", method = GET, produces = APPLICATION_JSON_VALUE) + public ResponseEntity> getAllVO(HttpServletRequest request) { try { - Map result=perlakuanService.getPerlakuanById(id); - if (null != result) - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS,request )); - return RestUtil.getJsonResponse(result, HttpStatus.CREATED,mapHeaderMessage); - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when get all perlakuan", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, - mapHeaderMessage); - } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when get all perlakuan", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, - mapHeaderMessage); - } + Map result = perlakuanService.getPerlakuanAll(); + if (null != result) + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, CREATED, mapHeaderMessage); + } catch (ServiceVOException e) { + LOGGER.error("Got ServiceVOException {} when getPerlakuanAll", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); + } catch (JpaSystemException jse) { + LOGGER.error("Got JpaSystemException {} when getPerlakuanAll", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); + } } } diff --git a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PermintaanBarangDariRuanganController.java b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PermintaanBarangDariRuanganController.java deleted file mode 100644 index ceb04d1a..00000000 --- a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PermintaanBarangDariRuanganController.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.jasamedika.medifirst2000.controller; - -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.orm.jpa.JpaSystemException; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - -import com.jasamedika.medifirst2000.constants.Constants; -import com.jasamedika.medifirst2000.constants.MessageResource; -import com.jasamedika.medifirst2000.controller.base.LocaleController; -import com.jasamedika.medifirst2000.core.web.WebConstants; -import com.jasamedika.medifirst2000.exception.ServiceVOException; -import com.jasamedika.medifirst2000.service.PermintaanBarangDariRuanganService; -import com.jasamedika.medifirst2000.util.rest.RestUtil; -import com.jasamedika.medifirst2000.vo.PermintaanBarangDariRuanganVO; - -@RestController -@RequestMapping("/permintaan-barang-dari-ruangan") -public class PermintaanBarangDariRuanganController extends LocaleController { - - @Autowired - private PermintaanBarangDariRuanganService permintaanBarangDariRuanganService; - - private static final Logger LOGGER = LoggerFactory.getLogger(PermintaanBarangDariRuanganController.class); - - @RequestMapping(value = "/save-permintaan-barang-dari-ruangan", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> savePermintaanBarangDariRuangan( - @Valid @RequestBody PermintaanBarangDariRuanganVO vo, HttpServletRequest request) { - try { - Map result = permintaanBarangDariRuanganService.savePermintaanBarangDariRuangan(vo); - if (null != result) - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, - getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage); - - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when save Permintaan Barang Dari Ruangan", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when save Permintaan Barang Dari Ruangan", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - } - - } - - @RequestMapping(value = "/update-permintaan-barang-dari-ruangan", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> updatePermintaanBarangDariRuangan( - @Valid @RequestBody PermintaanBarangDariRuanganVO vo, HttpServletRequest request) { - try { - Map result = permintaanBarangDariRuanganService.updatePermintaanBarangDariRuangan(vo); - if (null != result) - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, - getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage); - - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when update Permintaan Barang Dari Ruangan", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when update Permintaan Barang Dari Ruangan", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - } - - } - -} diff --git a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PermintaanPenunjangController.java b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PermintaanPenunjangController.java deleted file mode 100644 index 51ffd0a1..00000000 --- a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PermintaanPenunjangController.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.jasamedika.medifirst2000.controller; - -import java.util.List; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.RestController; - -import com.jasamedika.medifirst2000.controller.base.LocaleController; -import com.jasamedika.medifirst2000.service.StrukOrderService; - -@RestController -@RequestMapping("/permintaan-penunjang") -public class PermintaanPenunjangController extends LocaleController{ - - @Autowired - private StrukOrderService strukOrderService; - - private static final Logger LOGGER = LoggerFactory.getLogger(PermintaanPenunjangController.class); - - @RequestMapping(value = "/find-permintaan-penunjang") - @ResponseBody - public List> loadPengkajianAwal( - @RequestParam(value = "dateStart", required = false) String dateStart, - @RequestParam(value = "dateEnd", required = false) String dateEnd, - @RequestParam(value = "id", required = false) Integer id, - @RequestParam(value = "noRegistrasi", required = false) String noRegistrasi) { - return strukOrderService.HistoryPenunjang(dateStart, dateEnd, id, noRegistrasi); - } - -} diff --git a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PersepsiKognisiController.java b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PersepsiKognisiController.java index 110793cc..e9b97c8a 100644 --- a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PersepsiKognisiController.java +++ b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PersepsiKognisiController.java @@ -1,34 +1,33 @@ package com.jasamedika.medifirst2000.controller; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; - +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.jasamedika.medifirst2000.constants.MessageResource; +import com.jasamedika.medifirst2000.controller.base.LocaleController; +import com.jasamedika.medifirst2000.entities.PersepsiKognisi; +import com.jasamedika.medifirst2000.exception.ServiceVOException; +import com.jasamedika.medifirst2000.service.PersepsiKognisiService; +import com.jasamedika.medifirst2000.vo.PersepsiKognisiVO; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.orm.jpa.JpaSystemException; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.jasamedika.medifirst2000.constants.Constants; -import com.jasamedika.medifirst2000.constants.MessageResource; -import com.jasamedika.medifirst2000.controller.base.IBaseRestController; -import com.jasamedika.medifirst2000.controller.base.LocaleController; -import com.jasamedika.medifirst2000.core.web.WebConstants; -import com.jasamedika.medifirst2000.exception.ServiceVOException; -import com.jasamedika.medifirst2000.service.PersepsiKognisiService; -import com.jasamedika.medifirst2000.util.rest.RestUtil; -import com.jasamedika.medifirst2000.vo.PersepsiKognisiVO; +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.util.Map; + +import static com.jasamedika.medifirst2000.constants.Constants.MessageInfo.ERROR_MESSAGE; +import static com.jasamedika.medifirst2000.core.web.WebConstants.HttpHeaderInfo.LABEL_ERROR; +import static com.jasamedika.medifirst2000.core.web.WebConstants.HttpHeaderInfo.LABEL_SUCCESS; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonHttpStatus; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonResponse; +import static org.slf4j.LoggerFactory.getLogger; +import static org.springframework.http.HttpStatus.*; +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import static org.springframework.web.bind.annotation.RequestMethod.POST; /** * Controller class for PersepsiKognisiController @@ -37,70 +36,35 @@ import com.jasamedika.medifirst2000.vo.PersepsiKognisiVO; */ @RestController @RequestMapping("/persepsi-kognisi") -@JsonIgnoreProperties(ignoreUnknown = true) -public class PersepsiKognisiController extends LocaleController implements - IBaseRestController { - - private static final Logger LOGGER = LoggerFactory.getLogger(PersepsiKognisiController.class); +@JsonIgnoreProperties(ignoreUnknown = true) +public class PersepsiKognisiController extends LocaleController { + + private static final Logger LOGGER = getLogger(PersepsiKognisiController.class); @Autowired - private PersepsiKognisiService persepsiKognisiService; + private PersepsiKognisiService persepsiKognisiService; - @RequestMapping(value = "/save-persepsi-kognisi", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> save(@Valid @RequestBody PersepsiKognisiVO vo,HttpServletRequest request) { + @RequestMapping(value = "/save-persepsi-kognisi", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) + public ResponseEntity> save(@Valid @RequestBody PersepsiKognisiVO vo, + HttpServletRequest request) { try { - Map result = persepsiKognisiService.addPersepsiKognisi(vo); - - if (null != result){ - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS,request )); - }else{ - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_ERROR,getMessage(MessageResource.LABEL_ERROR,request )); + Map result = persepsiKognisiService.addPersepsiKognisi(vo); + if (null != result) { + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + } else { + mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request)); } - SaveLog("Persepsi Kognisi", "Pemeriksaan",request); - return RestUtil.getJsonResponse(result, HttpStatus.CREATED,mapHeaderMessage); - + SaveLog("Persepsi Kognisi", "Pemeriksaan", request); + return getJsonResponse(result, CREATED, mapHeaderMessage); } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when add Pasien", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); + LOGGER.error("Got ServiceVOException {} when addPersepsiKognisi", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when add Pasien", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); + LOGGER.error("Got JpaSystemException {} when addPersepsiKognisi", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } - } - @Override - public ResponseEntity> getAllVOWithQueryString(HttpServletRequest request, - Integer page, Integer limit, String sort, String dir) { - return null; - } - - @Override - public ResponseEntity getVO(Integer id) { - return null; - } - - @Override - public ResponseEntity addVO(PersepsiKognisiVO vo) { - return null; - } - - @Override - public ResponseEntity editVO(PersepsiKognisiVO vo) { - return null; - } - - @Override - public ResponseEntity deleteVO(Integer id) { - return null; - } - - @Override - public ResponseEntity> getAllVO() { - return null; - } - - } diff --git a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PersepsiPasienController.java b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PersepsiPasienController.java index 51bbcd1c..6c8989f4 100644 --- a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PersepsiPasienController.java +++ b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PersepsiPasienController.java @@ -1,34 +1,33 @@ package com.jasamedika.medifirst2000.controller; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; - +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.jasamedika.medifirst2000.constants.MessageResource; +import com.jasamedika.medifirst2000.controller.base.LocaleController; +import com.jasamedika.medifirst2000.entities.PersepsiPasien; +import com.jasamedika.medifirst2000.exception.ServiceVOException; +import com.jasamedika.medifirst2000.service.PersepsiPasienService; +import com.jasamedika.medifirst2000.vo.PersepsiPasienVO; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.orm.jpa.JpaSystemException; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.jasamedika.medifirst2000.constants.Constants; -import com.jasamedika.medifirst2000.constants.MessageResource; -import com.jasamedika.medifirst2000.controller.base.IBaseRestController; -import com.jasamedika.medifirst2000.controller.base.LocaleController; -import com.jasamedika.medifirst2000.core.web.WebConstants; -import com.jasamedika.medifirst2000.exception.ServiceVOException; -import com.jasamedika.medifirst2000.service.PersepsiPasienService; -import com.jasamedika.medifirst2000.util.rest.RestUtil; -import com.jasamedika.medifirst2000.vo.PersepsiPasienVO; +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.util.Map; + +import static com.jasamedika.medifirst2000.constants.Constants.MessageInfo.ERROR_MESSAGE; +import static com.jasamedika.medifirst2000.core.web.WebConstants.HttpHeaderInfo.LABEL_ERROR; +import static com.jasamedika.medifirst2000.core.web.WebConstants.HttpHeaderInfo.LABEL_SUCCESS; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonHttpStatus; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonResponse; +import static org.slf4j.LoggerFactory.getLogger; +import static org.springframework.http.HttpStatus.*; +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import static org.springframework.web.bind.annotation.RequestMethod.POST; /** * Controller class for PersepsiPasienController @@ -37,70 +36,35 @@ import com.jasamedika.medifirst2000.vo.PersepsiPasienVO; */ @RestController @RequestMapping("/persepsi-pasien") -@JsonIgnoreProperties(ignoreUnknown = true) -public class PersepsiPasienController extends LocaleController implements - IBaseRestController { - - private static final Logger LOGGER = LoggerFactory.getLogger(PersepsiPasienController.class); +@JsonIgnoreProperties(ignoreUnknown = true) +public class PersepsiPasienController extends LocaleController { + + private static final Logger LOGGER = getLogger(PersepsiPasienController.class); @Autowired - private PersepsiPasienService persepsiPasienService; + private PersepsiPasienService persepsiPasienService; - @RequestMapping(value = "/save-persepsi-pasien", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> save(@Valid @RequestBody PersepsiPasienVO vo,HttpServletRequest request) { + @RequestMapping(value = "/save-persepsi-pasien", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) + public ResponseEntity> save(@Valid @RequestBody PersepsiPasienVO vo, + HttpServletRequest request) { try { - Map result = persepsiPasienService.addPersepsiPasien(vo); - - if (null != result){ - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS,request )); - }else{ - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_ERROR,getMessage(MessageResource.LABEL_ERROR,request )); + Map result = persepsiPasienService.addPersepsiPasien(vo); + if (null != result) { + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + } else { + mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request)); } - SaveLog("Persepsi Pasien", "Pemeriksaan",request); - return RestUtil.getJsonResponse(result, HttpStatus.CREATED,mapHeaderMessage); - + SaveLog("Persepsi Pasien", "Pemeriksaan", request); + return getJsonResponse(result, CREATED, mapHeaderMessage); } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when add Pasien", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); + LOGGER.error("Got ServiceVOException {} when addPersepsiPasien", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when add Pasien", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); + LOGGER.error("Got JpaSystemException {} when addPersepsiPasien", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } - } - @Override - public ResponseEntity> getAllVOWithQueryString(HttpServletRequest request, - Integer page, Integer limit, String sort, String dir) { - return null; - } - - @Override - public ResponseEntity getVO(Integer id) { - return null; - } - - @Override - public ResponseEntity addVO(PersepsiPasienVO vo) { - return null; - } - - @Override - public ResponseEntity editVO(PersepsiPasienVO vo) { - return null; - } - - @Override - public ResponseEntity deleteVO(Integer id) { - return null; - } - - @Override - public ResponseEntity> getAllVO() { - return null; - } - - } diff --git a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PerspektifController.java b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PerspektifController.java index 86b0ef66..8baee37a 100644 --- a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PerspektifController.java +++ b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PerspektifController.java @@ -1,121 +1,78 @@ package com.jasamedika.medifirst2000.controller; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; - +import com.jasamedika.medifirst2000.constants.MessageResource; +import com.jasamedika.medifirst2000.controller.base.LocaleController; +import com.jasamedika.medifirst2000.entities.Perspektif; +import com.jasamedika.medifirst2000.exception.ServiceVOException; +import com.jasamedika.medifirst2000.service.PerspektifService; +import com.jasamedika.medifirst2000.vo.PasienVO; +import com.jasamedika.medifirst2000.vo.PerspektifVO; +import net.kaczmarzyk.spring.data.jpa.domain.Equal; +import net.kaczmarzyk.spring.data.jpa.web.annotation.Spec; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specifications; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.orm.jpa.JpaSystemException; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.jasamedika.medifirst2000.constants.Constants; -import com.jasamedika.medifirst2000.constants.MessageResource; -import com.jasamedika.medifirst2000.controller.base.IBaseRestController; -import com.jasamedika.medifirst2000.controller.base.LocaleController; -import com.jasamedika.medifirst2000.core.web.WebConstants; -import com.jasamedika.medifirst2000.entities.Perspektif; -import com.jasamedika.medifirst2000.exception.ServiceVOException; -import com.jasamedika.medifirst2000.service.PerspektifService; -import com.jasamedika.medifirst2000.util.rest.RestUtil; -import com.jasamedika.medifirst2000.vo.PerspektifVO; +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.util.Collection; +import java.util.Map; -import net.kaczmarzyk.spring.data.jpa.domain.Equal; -import net.kaczmarzyk.spring.data.jpa.web.annotation.Spec; +import static com.jasamedika.medifirst2000.constants.Constants.MessageInfo.ERROR_MESSAGE; +import static com.jasamedika.medifirst2000.core.web.WebConstants.HttpHeaderInfo.LABEL_SUCCESS; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonHttpStatus; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonResponse; +import static org.slf4j.LoggerFactory.getLogger; +import static org.springframework.http.HttpStatus.*; +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import static org.springframework.web.bind.annotation.RequestMethod.GET; +import static org.springframework.web.bind.annotation.RequestMethod.POST; @RestController @RequestMapping("/perspektif") -public class PerspektifController extends LocaleController -implements IBaseRestController{ +public class PerspektifController extends LocaleController { + + private static final Logger LOGGER = getLogger(PerspektifController.class); @Autowired private PerspektifService perspektifService; - - private static final Logger LOGGER = LoggerFactory - .getLogger(PegawaiController.class); - - @Override - public ResponseEntity> getAllVOWithQueryString(HttpServletRequest request, Integer page, - Integer limit, String sort, String dir) { - return null; - } - @Override - public ResponseEntity getVO(Integer id) { - return null; - } - - @Override - public ResponseEntity addVO(PerspektifVO vo) { - return null; - } - - @Override - public ResponseEntity editVO(PerspektifVO vo) { - return null; - } - - @Override - public ResponseEntity deleteVO(Integer id) { - return null; - } - - @Override - public ResponseEntity> getAllVO() { - return null; - } - - @RequestMapping(value="/find-all/", method= RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> findAll( + @RequestMapping(value = "/find-all/", method = GET, produces = APPLICATION_JSON_VALUE) + public ResponseEntity> findAll( @RequestParam(value = "page", required = false, defaultValue = "0") Integer page, @RequestParam(value = "take", required = false, defaultValue = "100") Integer take, @RequestParam(value = "sort", required = false, defaultValue = "id") String sort, @RequestParam(value = "dir", required = false, defaultValue = "asc") String dir, @Spec(path = "id", params = "id", spec = Equal.class) Specification spec1, - @Spec(path = "jenisIndikatorId", params = "jenisIndikatorId", spec = Equal.class) Specification spec2) - { - Map result = new HashMap(); - Specification spec = Specifications.where(spec1).and(spec2); - result = perspektifService.findAll(page, take, sort,dir, spec); - return constructListPageResult(result); + @Spec(path = "jenisIndikatorId", params = "jenisIndikatorId", spec = Equal.class) Specification spec2) { + Specification spec = Specifications.where(spec1).and(spec2); + Map result = perspektifService.findAll(page, take, sort, dir, spec); + return constructListPageResult(result); } - @RequestMapping(value="/save/", method= RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> save(@Valid @RequestBody PerspektifVO vo,HttpServletRequest request){ - try{ + @RequestMapping(value = "/save/", method = POST, produces = APPLICATION_JSON_VALUE) + public ResponseEntity> save(@Valid @RequestBody PerspektifVO vo, HttpServletRequest request) { + try { Map result = perspektifService.save(vo); - if(null!= result) - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS,request)); - return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage); - + if (null != result) + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, CREATED, mapHeaderMessage); } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when add/update perspektif", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, - mapHeaderMessage); - + LOGGER.error("Got ServiceVOException {} when perspektifService.save", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when add/update perspektif", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, - mapHeaderMessage); + LOGGER.error("Got JpaSystemException {} when perspektifService.save", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } - } + } diff --git a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PertanyaanSurveyController.java b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PertanyaanSurveyController.java index 90a536a8..11c3fc58 100644 --- a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PertanyaanSurveyController.java +++ b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PertanyaanSurveyController.java @@ -1,162 +1,95 @@ package com.jasamedika.medifirst2000.controller; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; - +import com.jasamedika.medifirst2000.constants.MessageResource; +import com.jasamedika.medifirst2000.controller.base.LocaleController; +import com.jasamedika.medifirst2000.exception.ServiceVOException; +import com.jasamedika.medifirst2000.service.PertanyaanSurveyService; +import com.jasamedika.medifirst2000.vo.PertanyaanSurveyVO; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.orm.jpa.JpaSystemException; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -import com.jasamedika.medifirst2000.constants.Constants; -import com.jasamedika.medifirst2000.constants.MessageResource; -import com.jasamedika.medifirst2000.controller.base.IBaseRestController; -import com.jasamedika.medifirst2000.controller.base.LocaleController; -import com.jasamedika.medifirst2000.core.web.WebConstants; -import com.jasamedika.medifirst2000.exception.ServiceVOException; -import com.jasamedika.medifirst2000.service.PertanyaanSurveyService; -import com.jasamedika.medifirst2000.util.rest.RestUtil; -import com.jasamedika.medifirst2000.vo.PertanyaanSurveyVO; +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.util.Map; + +import static com.jasamedika.medifirst2000.constants.Constants.MessageInfo.ERROR_MESSAGE; +import static com.jasamedika.medifirst2000.core.web.WebConstants.HttpHeaderInfo.LABEL_ERROR; +import static com.jasamedika.medifirst2000.core.web.WebConstants.HttpHeaderInfo.LABEL_SUCCESS; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonHttpStatus; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonResponse; +import static org.slf4j.LoggerFactory.getLogger; +import static org.springframework.http.HttpStatus.*; +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import static org.springframework.web.bind.annotation.RequestMethod.GET; +import static org.springframework.web.bind.annotation.RequestMethod.POST; @RestController @RequestMapping("pertanyaanSurvey") -public class PertanyaanSurveyController extends LocaleController implements IBaseRestController { - +public class PertanyaanSurveyController extends LocaleController { + + private static final Logger LOGGER = getLogger(PertanyaanSurveyController.class); + @Autowired private PertanyaanSurveyService pertanyaanSurveyService; - - private static final Logger LOGGER = LoggerFactory - .getLogger(PertanyaanSurveyController.class); - - @RequestMapping(value = "/save-pertanyaan-survey/", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> addVO(@Valid @RequestBody PertanyaanSurveyVO vo, HttpServletRequest request) { - + + @RequestMapping(value = "/save-pertanyaan-survey/", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) + public ResponseEntity> addVO(@Valid @RequestBody PertanyaanSurveyVO vo, + HttpServletRequest request) { try { - Map result=pertanyaanSurveyService.addPertanyaan(vo); + Map result = pertanyaanSurveyService.addPertanyaan(vo); if (null != result) - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS,request )); - return RestUtil.getJsonResponse(result, HttpStatus.CREATED,mapHeaderMessage); + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, CREATED, mapHeaderMessage); } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when add PertanyaanSurveyVO", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, - mapHeaderMessage); + LOGGER.error("Got ServiceVOException {} when pertanyaanSurveyService.addPertanyaan", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when add PertanyaanSurveyVO", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, - mapHeaderMessage); + LOGGER.error("Got JpaSystemException {} when pertanyaanSurveyService.addPertanyaan", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } } - - @RequestMapping(value = "/update-pertanyaan-survey/", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> updateVO(@Valid @RequestBody PertanyaanSurveyVO vo, HttpServletRequest request) { - + + @RequestMapping(value = "/find-all/", method = GET, produces = APPLICATION_JSON_VALUE) + public ResponseEntity> getAllVO(HttpServletRequest request) { try { - Map result=pertanyaanSurveyService.addPertanyaan(vo); + Map result = pertanyaanSurveyService.findAllPertanyaanSurveyFromMapping(); if (null != result) - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS,request )); - return RestUtil.getJsonResponse(result, HttpStatus.CREATED,mapHeaderMessage); + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, CREATED, mapHeaderMessage); } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when add PertanyaanSurveyVO", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, - mapHeaderMessage); + LOGGER.error("Got ServiceVOException {} when findAllPertanyaanSurveyFromMapping", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when add PertanyaanSurveyVO", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, - mapHeaderMessage); + LOGGER.error("Got JpaSystemException {} when findAllPertanyaanSurveyFromMapping", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } } - - @RequestMapping(value = "/find-all/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> getAllVO(HttpServletRequest request) { - + + @RequestMapping(value = "/delete-pertanyaan/{id}", method = GET, produces = APPLICATION_JSON_VALUE) + public ResponseEntity> getAllInformasiKetersediaanKamar(@PathVariable("id") Integer id, + HttpServletRequest request) { try { - Map result=pertanyaanSurveyService.findAllPertanyaanSurveyFromMapping(); - if (null != result) - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS,request )); - return RestUtil.getJsonResponse(result, HttpStatus.CREATED,mapHeaderMessage); - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when get all PertanyaanSurveyVO", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, - mapHeaderMessage); - } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when get all PertanyaanSurveyVO", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, - mapHeaderMessage); - } - } - - @RequestMapping(value = "/delete-pertanyaan/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> getAllInformasiKetersediaanKamar(@PathVariable("id") Integer id,HttpServletRequest request) { - Map result = null; - try{ - result = pertanyaanSurveyService.deletePertanyaan(id); - Boolean dataFound=new Boolean((boolean) result.get("dataFound")); - - if(dataFound){ - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS,request )); + Map result = pertanyaanSurveyService.deletePertanyaan(id); + boolean dataFound = (boolean) result.get("dataFound"); + if (dataFound) { + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + } else { + mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request)); } - else{ - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_ERROR,getMessage(MessageResource.LABEL_ERROR,request )); - } - }catch (Exception e){ - e.printStackTrace(); + return getJsonResponse(result, OK); + } catch (Exception e) { + throw new ServiceVOException(e.getMessage()); } - return RestUtil.getJsonResponse(result, HttpStatus.OK); - } - - @Override - public ResponseEntity> getAllVOWithQueryString(HttpServletRequest request, - Integer page, Integer limit, String sort, String dir) { - return null; - } - - @Override - public ResponseEntity getVO(Integer id) { - return null; - } - - @Override - public ResponseEntity addVO(PertanyaanSurveyVO vo) { - return null; - } - - @Override - public ResponseEntity editVO(PertanyaanSurveyVO vo) { - return null; - } - - @Override - public ResponseEntity deleteVO(Integer id) { - return null; - } - - @Override - public ResponseEntity> getAllVO() { - return null; } } diff --git a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PesertaAsuransiBpjsNakerController.java b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PesertaAsuransiBpjsNakerController.java index e70c7c8e..048053bb 100644 --- a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PesertaAsuransiBpjsNakerController.java +++ b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PesertaAsuransiBpjsNakerController.java @@ -1,106 +1,75 @@ package com.jasamedika.medifirst2000.controller; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - import com.jasamedika.medifirst2000.constants.MessageResource; import com.jasamedika.medifirst2000.controller.base.LocaleController; -import com.jasamedika.medifirst2000.core.web.WebConstants; import com.jasamedika.medifirst2000.dto.PesertaAsuransiBpjsNakerDto; import com.jasamedika.medifirst2000.service.PesertaAsuransiBpjsNakerService; -import com.jasamedika.medifirst2000.util.rest.RestUtil; import com.jasamedika.medifirst2000.vo.AsuransiPasienVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; +import java.util.Map; + +import static com.jasamedika.medifirst2000.core.web.WebConstants.HttpHeaderInfo.LABEL_SUCCESS; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonHttpStatus; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonResponse; +import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; +import static org.springframework.http.HttpStatus.OK; +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import static org.springframework.web.bind.annotation.RequestMethod.GET; +import static org.springframework.web.bind.annotation.RequestMethod.POST; @RestController -@RequestMapping(value="/peserta-asuransi-bpjs-naker") +@RequestMapping(value = "/peserta-asuransi-bpjs-naker") public class PesertaAsuransiBpjsNakerController extends LocaleController { - + @Autowired private PesertaAsuransiBpjsNakerService pesertaAsuransiBpjsNakerService; - @RequestMapping(value="/save-peserta-asuransi-bpjs-naker", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> save(@RequestBody PesertaAsuransiBpjsNakerDto dto, + @RequestMapping(value = "/save-peserta-asuransi-bpjs-naker", method = POST, produces = APPLICATION_JSON_VALUE) + public ResponseEntity> save(@RequestBody PesertaAsuransiBpjsNakerDto dto, HttpServletRequest request) { - Map result = pesertaAsuransiBpjsNakerService.save(dto); + Map result = pesertaAsuransiBpjsNakerService.save(dto); if (!result.isEmpty()) { - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, OK, mapHeaderMessage); } - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } - @RequestMapping(value="/get-peserta-asuransi-bpjs-naker", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> get( - @RequestParam(value="idAsuransi", required = true) Integer idAsuransi, - HttpServletRequest request) { - Map result = pesertaAsuransiBpjsNakerService.get(idAsuransi); - - if (result!=null) { - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); - } - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - } - - @RequestMapping(value="/get-all-peserta-asuransi-bpjs-naker", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity>> getAll( - HttpServletRequest request) { + @RequestMapping(value = "/get-all-peserta-asuransi-bpjs-naker", method = GET, produces = APPLICATION_JSON_VALUE) + public ResponseEntity>> getAll(HttpServletRequest request) { List> result = pesertaAsuransiBpjsNakerService.getAll(); - - if (result!=null) { - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); + if (result != null) { + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, OK, mapHeaderMessage); } - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } - - @RequestMapping(value="/get-all-pegawai-aktif", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity>> getAllPegawaiAktif( - HttpServletRequest request) { + + @RequestMapping(value = "/get-all-pegawai-aktif", method = GET, produces = APPLICATION_JSON_VALUE) + public ResponseEntity>> getAllPegawaiAktif(HttpServletRequest request) { List> result = pesertaAsuransiBpjsNakerService.getAllPegawai(); - - if (result!=null) { - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); + if (result != null) { + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, OK, mapHeaderMessage); } - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } - @RequestMapping(value="/get-all-rekanan", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity>> getAllRekanan( - HttpServletRequest request) { - List> result = pesertaAsuransiBpjsNakerService.getAllRekanan(); - - if (result!=null) { - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); - } - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - } - - @RequestMapping(value="/get-all-hubungan-peserta", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity>> getAllHubunganPeserta( - HttpServletRequest request) { + @RequestMapping(value = "/get-all-hubungan-peserta", method = GET, produces = APPLICATION_JSON_VALUE) + public ResponseEntity>> getAllHubunganPeserta(HttpServletRequest request) { List> result = pesertaAsuransiBpjsNakerService.getAllHubunganPeserta(); - - if (result!=null) { - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); + if (result != null) { + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, OK, mapHeaderMessage); } - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } - } diff --git a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PesertaDidikController.java b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PesertaDidikController.java index 53acae70..49176ba3 100644 --- a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PesertaDidikController.java +++ b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PesertaDidikController.java @@ -1,32 +1,30 @@ package com.jasamedika.medifirst2000.controller; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - +import com.jasamedika.medifirst2000.constants.MessageResource; +import com.jasamedika.medifirst2000.controller.base.LocaleController; +import com.jasamedika.medifirst2000.entities.Rekanan; +import com.jasamedika.medifirst2000.exception.ServiceVOException; +import com.jasamedika.medifirst2000.service.PesertaDidikService; +import com.jasamedika.medifirst2000.vo.InputMouPKSTempVO; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.orm.jpa.JpaSystemException; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.jasamedika.medifirst2000.constants.Constants; -import com.jasamedika.medifirst2000.constants.MessageResource; -import com.jasamedika.medifirst2000.controller.base.LocaleController; -import com.jasamedika.medifirst2000.core.web.WebConstants; -import com.jasamedika.medifirst2000.entities.Rekanan; -import com.jasamedika.medifirst2000.exception.ServiceVOException; -import com.jasamedika.medifirst2000.service.PesertaDidikService; -import com.jasamedika.medifirst2000.util.rest.RestUtil; -import com.jasamedika.medifirst2000.vo.InputMouPKSTempVO; -import com.jasamedika.medifirst2000.vo.PesertaDidikVO; +import javax.servlet.http.HttpServletRequest; + +import static com.jasamedika.medifirst2000.constants.Constants.MessageInfo.ERROR_MESSAGE; +import static com.jasamedika.medifirst2000.core.web.WebConstants.HttpHeaderInfo.LABEL_SUCCESS; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonHttpStatus; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonResponse; +import static org.slf4j.LoggerFactory.getLogger; +import static org.springframework.http.HttpStatus.*; +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import static org.springframework.web.bind.annotation.RequestMethod.POST; + /** * PesertaDidikController * @@ -34,120 +32,29 @@ import com.jasamedika.medifirst2000.vo.PesertaDidikVO; */ @RestController @RequestMapping("/peserta-didik") -public class PesertaDidikController extends LocaleController { - private static final Logger LOGGER = LoggerFactory - .getLogger(PesertaDidikController.class); - +public class PesertaDidikController extends LocaleController { + + private static final Logger LOGGER = getLogger(PesertaDidikController.class); + @Autowired private PesertaDidikService pesertaDidikService; - @RequestMapping(value = "/save-data-peserta-didik", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> savePesertaDidik(@RequestBody PesertaDidikVO vo,HttpServletRequest request){ - try { - Map result = pesertaDidikService.savePesertaDidik(vo); - if (null != result) - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS,request )); - RestUtil.getJsonHttpStatus(HttpStatus.CREATED); - return RestUtil.getJsonResponse(result, HttpStatus.CREATED,mapHeaderMessage); - - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when add Riwayat Pekerjaan", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when add Riwayat Pekerjaan", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - } - - } - @RequestMapping(value = "/input-mou-pks", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity tambahDataInputPKSMou(@RequestBody InputMouPKSTempVO vo,HttpServletRequest request){ + @RequestMapping(value = "/input-mou-pks", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) + public ResponseEntity tambahDataInputPKSMou(@RequestBody InputMouPKSTempVO vo, HttpServletRequest request) { try { Rekanan result = pesertaDidikService.inputMouPKS(vo); if (null != result) - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS,request )); - RestUtil.getJsonHttpStatus(HttpStatus.CREATED); - return RestUtil.getJsonResponse("Status Sukses", HttpStatus.CREATED,mapHeaderMessage); + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse("Status Sukses", CREATED, mapHeaderMessage); + } catch (ServiceVOException e) { + LOGGER.error("Got ServiceVOException {} when inputMouPKS", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); + } catch (JpaSystemException jse) { + LOGGER.error("Got JpaSystemException {} when inputMouPKS", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); + } + } - } catch (ServiceVOException e) { - //LOGGER.error("Got exception {} when add Riwayat Pekerjaan", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - } catch (JpaSystemException jse) { - //LOGGER.error("Got exception {} when add Riwayat Pekerjaan", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - } - //return null; - } - @RequestMapping(value = "/get-all-rekanan-on-peserta-didik/", method = RequestMethod.GET) - public ResponseEntity< Map> findAllPegwawaiNoPaging(@RequestParam(value = "key", required = false) String key,HttpServletRequest request) { - try { - - // long tgl=Date.parse(tanggal); - Map listPegawaiVo = pesertaDidikService.findAllRekananByInstitusiForPesertaDidik(); - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS,request )); - return RestUtil.getJsonResponse(listPegawaiVo, HttpStatus.OK,mapHeaderMessage); - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when get all dokter", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when get all dokter", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - } - } - @RequestMapping(value = "/get-all-pegawai-no-paging-search", method = RequestMethod.GET) - public ResponseEntity< Map> findAllPegawaiNoPagingSearch(@RequestParam(value = "namaPegawai") String namaPegawai,HttpServletRequest request) { - try { - - Map listPegawaiVo = pesertaDidikService.findAllPegawaiNoPagingSearch(namaPegawai); - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS,request )); - return RestUtil.getJsonResponse(listPegawaiVo, HttpStatus.OK,mapHeaderMessage); - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when get all dokter", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when get all dokter", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - } - } - @RequestMapping(value = "/get-all-pegawai-by-pengajar", method = RequestMethod.GET) - public ResponseEntity< Map> findAllPegawaiByJenisPegawaiPengajar(HttpServletRequest request) { - try { - - Map listPegawaiVo = pesertaDidikService.findAllPegawaiByJenisPegawaiPengajar(); - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS,request )); - return RestUtil.getJsonResponse(listPegawaiVo, HttpStatus.OK,mapHeaderMessage); - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when get all dokter", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when get all dokter", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - } - } - @RequestMapping(value = "/get-all-pegawai-by-peserta-didik", method = RequestMethod.GET) - public ResponseEntity< Map> findAllPegawaiByJenisPegawaiPesertaDidik(HttpServletRequest request) { - try { - - Map listPegawaiVo = pesertaDidikService.findAllPegawaiByJenisPegawaiPesertaDidik(); - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS,request )); - return RestUtil.getJsonResponse(listPegawaiVo, HttpStatus.OK,mapHeaderMessage); - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when get all dokter", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when get all dokter", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - } - } } diff --git a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PioController.java b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PioController.java index b8cf647d..dde6bcfe 100644 --- a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PioController.java +++ b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PioController.java @@ -1,154 +1,57 @@ package com.jasamedika.medifirst2000.controller; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; - +import com.jasamedika.medifirst2000.constants.MessageResource; +import com.jasamedika.medifirst2000.controller.base.LocaleController; +import com.jasamedika.medifirst2000.entities.Pio; +import com.jasamedika.medifirst2000.exception.ServiceVOException; +import com.jasamedika.medifirst2000.service.PioService; +import com.jasamedika.medifirst2000.vo.PioVO; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.orm.jpa.JpaSystemException; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.jasamedika.medifirst2000.constants.Constants; -import com.jasamedika.medifirst2000.constants.MessageResource; -import com.jasamedika.medifirst2000.controller.base.IBaseRestController; -import com.jasamedika.medifirst2000.controller.base.LocaleController; -import com.jasamedika.medifirst2000.core.web.WebConstants; -import com.jasamedika.medifirst2000.exception.ServiceVOException; -import com.jasamedika.medifirst2000.service.PioService; -import com.jasamedika.medifirst2000.util.rest.RestUtil; -import com.jasamedika.medifirst2000.vo.PioVO; +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.util.Map; + +import static com.jasamedika.medifirst2000.constants.Constants.MessageInfo.ERROR_MESSAGE; +import static com.jasamedika.medifirst2000.core.web.WebConstants.HttpHeaderInfo.LABEL_SUCCESS; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonHttpStatus; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonResponse; +import static org.slf4j.LoggerFactory.getLogger; +import static org.springframework.http.HttpStatus.*; +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import static org.springframework.web.bind.annotation.RequestMethod.POST; @RestController @RequestMapping("/pio") -public class PioController extends LocaleController implements -IBaseRestController { - +public class PioController extends LocaleController { + + private static final Logger LOGGER = getLogger(PioController.class); + @Autowired - private PioService pioService; - - private static final Logger LOGGER = LoggerFactory - .getLogger(PioController.class); + private PioService pioService; - @Override - public ResponseEntity> getAllVOWithQueryString(HttpServletRequest request, Integer page, - Integer limit, String sort, String dir) { - return null; - } - - @Override - public ResponseEntity getVO(Integer id) { - return null; - } - - @RequestMapping(value = "/save-pio/", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity addVO(@Valid @RequestBody PioVO vo,HttpServletRequest request) { + @RequestMapping(value = "/save-pio/", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) + public ResponseEntity addVO(@Valid @RequestBody PioVO vo, HttpServletRequest request) { try { - Map result= pioService.savePio(vo); - - if (null != result) - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS,request )); - return RestUtil.getJsonResponse("", HttpStatus.CREATED,mapHeaderMessage); - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when add Pio", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, - mapHeaderMessage); - } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when add Pio", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, - mapHeaderMessage); - } - - } - - @RequestMapping(value = "/update-pio/", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity editVO(@Valid @RequestBody PioVO vo) { - try { - PioVO result = (PioVO) pioService.update(vo); - + Map result = pioService.savePio(vo); if (null != result) - return RestUtil.getJsonResponse("", HttpStatus.OK); + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse("", CREATED, mapHeaderMessage); } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when update Pio", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, - mapHeaderMessage); + LOGGER.error("Got ServiceVOException {} when savePio", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when update Pio", - jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, - mapHeaderMessage); + LOGGER.error("Got JpaSystemException {} when savePio", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } - - return RestUtil.getJsonHttpStatus(HttpStatus.NOT_ACCEPTABLE); - } - - @RequestMapping(value = "/delete-pio/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity deleteVO(Integer id) { - try { - if (pioService.delete(id) == true) - return RestUtil.getJsonResponse("", HttpStatus.CREATED); - - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when delete Pio", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, - mapHeaderMessage); - } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when delete Pio", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, - mapHeaderMessage); - } - - return RestUtil.getJsonHttpStatus(HttpStatus.NOT_ACCEPTABLE); - } - - @Override - public ResponseEntity> getAllVO() { - return null; - } - - - @SuppressWarnings("unchecked") - @RequestMapping(value = "/search-pio", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> getAllVOWithQueryString( - @RequestParam(value = "page", required = false ,defaultValue = "0") Integer page, - @RequestParam(value = "limit", required = false ,defaultValue = "10") Integer limit, - @RequestParam(value = "sort", required = false, defaultValue = "id") String sort, - @RequestParam(value = "dir", required = false, defaultValue = "asc") String dir){ - Map resultPageMap = pioService.findAllWithPageAndLimitAndSortByAndDirectionParameter(page, - limit, sort, dir); - - return constructListPageResult(resultPageMap); - } - - - - - @Override - public ResponseEntity addVO(PioVO vo) { - return null; } } diff --git a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PlanningDiklatHumasMarketBiayaController.java b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PlanningDiklatHumasMarketBiayaController.java index a37b9949..5c17d5dc 100644 --- a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PlanningDiklatHumasMarketBiayaController.java +++ b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PlanningDiklatHumasMarketBiayaController.java @@ -1,159 +1,123 @@ package com.jasamedika.medifirst2000.controller; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; - +import com.jasamedika.medifirst2000.constants.MessageResource; +import com.jasamedika.medifirst2000.controller.base.LocaleController; +import com.jasamedika.medifirst2000.exception.ServiceVOException; +import com.jasamedika.medifirst2000.service.PlanningDiklatHumasMarketBiayaService; +import com.jasamedika.medifirst2000.vo.PlanningDiklatHumasMarketBiayaVO; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.orm.jpa.JpaSystemException; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.jasamedika.medifirst2000.constants.Constants; -import com.jasamedika.medifirst2000.constants.MessageResource; -import com.jasamedika.medifirst2000.controller.base.LocaleController; -import com.jasamedika.medifirst2000.core.web.WebConstants; -import com.jasamedika.medifirst2000.exception.ServiceVOException; -import com.jasamedika.medifirst2000.service.PlanningDiklatHumasMarketBiayaService; -import com.jasamedika.medifirst2000.util.rest.RestUtil; -import com.jasamedika.medifirst2000.vo.PlanningDiklatHumasMarketBiayaVO; +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.util.Map; + +import static com.jasamedika.medifirst2000.constants.Constants.MessageInfo.ERROR_MESSAGE; +import static com.jasamedika.medifirst2000.core.web.WebConstants.HttpHeaderInfo.LABEL_SUCCESS; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonHttpStatus; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonResponse; +import static org.slf4j.LoggerFactory.getLogger; +import static org.springframework.http.HttpStatus.*; +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import static org.springframework.web.bind.annotation.RequestMethod.GET; +import static org.springframework.web.bind.annotation.RequestMethod.POST; @RestController @RequestMapping("/planningdiklathumasmarketbiaya") -public class PlanningDiklatHumasMarketBiayaController extends LocaleController{ - private static final Logger LOGGER = LoggerFactory.getLogger(PlanningDiklatHumasMarketBiayaController.class); - +public class PlanningDiklatHumasMarketBiayaController extends LocaleController { + + private static final Logger LOGGER = getLogger(PlanningDiklatHumasMarketBiayaController.class); + @Autowired - private PlanningDiklatHumasMarketBiayaService planningDiklatHumasMarketBiayaService; - - @RequestMapping( - value = "/save-planning-dhm-biaya", - method = RequestMethod.POST, - produces = MediaType.APPLICATION_JSON_VALUE, - consumes = MediaType.APPLICATION_JSON_VALUE) + private PlanningDiklatHumasMarketBiayaService planningDiklatHumasMarketBiayaService; + + @RequestMapping(value = "/save-planning-dhm-biaya", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) public ResponseEntity> savePlanningDHMBiaya( @Valid @RequestBody PlanningDiklatHumasMarketBiayaVO vo, HttpServletRequest request) { - try { Map result = this.planningDiklatHumasMarketBiayaService.savePlanningDHMBiaya(vo); - if (result != null) - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, - getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage); + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, CREATED, mapHeaderMessage); } catch (ServiceVOException e) { - - LOGGER.error("Got exception {} when savePlanningDHMBiaya", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - + LOGGER.error("Got ServiceVOException {} when savePlanningDHMBiaya", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { - - LOGGER.error("Got exception {} when savePlanningDHMBiaya", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - } + LOGGER.error("Got JpaSystemException {} when savePlanningDHMBiaya", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); + } } - - @RequestMapping( - value = "/get-list-bynoplanning", - method = RequestMethod.GET, - produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> getLoadDataByNoPlanning( - @RequestParam(value = "noPlanning", required = true) String noPlanning, HttpServletRequest request) { + @RequestMapping(value = "/get-list-bynoplanning", method = GET, produces = APPLICATION_JSON_VALUE) + public ResponseEntity> getLoadDataByNoPlanning( + @RequestParam(value = "noPlanning") String noPlanning, HttpServletRequest request) { try { Map result = this.planningDiklatHumasMarketBiayaService.getListPDHMBiaya(noPlanning); - if (null != result) { - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, - getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, OK, mapHeaderMessage); } else { - return RestUtil.getJsonResponse(result, HttpStatus.NOT_FOUND, mapHeaderMessage); + return getJsonResponse(null, NOT_FOUND, mapHeaderMessage); } - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when getLoadDataByNoPlanning", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - + LOGGER.error("Got ServiceVOException {} when getListPDHMBiaya", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when getLoadDataByNoPlanning", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - + LOGGER.error("Got JpaSystemException {} when getListPDHMBiaya", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } } - - @RequestMapping( - value = "/get-produk-byharga", - method = RequestMethod.GET, - produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> getProdukByHarga(HttpServletRequest request) { + @RequestMapping(value = "/get-produk-byharga", method = GET, produces = APPLICATION_JSON_VALUE) + public ResponseEntity> getProdukByHarga(HttpServletRequest request) { try { Map result = this.planningDiklatHumasMarketBiayaService.getListProdukByHarga(); - if (null != result) { - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, - getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, OK, mapHeaderMessage); } else { - return RestUtil.getJsonResponse(result, HttpStatus.NOT_FOUND, mapHeaderMessage); + return getJsonResponse(null, NOT_FOUND, mapHeaderMessage); } - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when getProdukByHarga", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - + LOGGER.error("Got ServiceVOException {} when getListProdukByHarga", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when getProdukByHarga", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - + LOGGER.error("Got JpaSystemException {} when getListProdukByHarga", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } } - - - @RequestMapping( - value = "/get-produk-asal", - method = RequestMethod.GET, - produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> getProdukAsal(HttpServletRequest request) { + @RequestMapping(value = "/get-produk-asal", method = GET, produces = APPLICATION_JSON_VALUE) + public ResponseEntity> getProdukAsal(HttpServletRequest request) { try { Map result = this.planningDiklatHumasMarketBiayaService.getListAsalProduk(); - if (null != result) { - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, - getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, OK, mapHeaderMessage); } else { - return RestUtil.getJsonResponse(result, HttpStatus.NOT_FOUND, mapHeaderMessage); + return getJsonResponse(null, NOT_FOUND, mapHeaderMessage); } - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when getProdukAsal", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - + LOGGER.error("Got ServiceVOException {} when getListAsalProduk", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when getProdukAsal", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - + LOGGER.error("Got JpaSystemException {} when getListAsalProduk", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } } - + } diff --git a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PlanningDiklatHumasMarketController.java b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PlanningDiklatHumasMarketController.java index a58e5196..a4044318 100644 --- a/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PlanningDiklatHumasMarketController.java +++ b/jasamedika-web/src/main/java/com/jasamedika/medifirst2000/controller/PlanningDiklatHumasMarketController.java @@ -1,345 +1,208 @@ package com.jasamedika.medifirst2000.controller; - -import java.util.HashMap; -import java.util.Map; +import com.jasamedika.medifirst2000.constants.MessageResource; +import com.jasamedika.medifirst2000.controller.base.LocaleController; +import com.jasamedika.medifirst2000.exception.ServiceVOException; +import com.jasamedika.medifirst2000.service.PlanningDiklatHumasMarketService; +import com.jasamedika.medifirst2000.vo.PlanningDiklatHumasMarketVO; +import com.jasamedika.medifirst2000.vo.StrukPlanningVO; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.orm.jpa.JpaSystemException; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; +import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.orm.jpa.JpaSystemException; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import com.jasamedika.medifirst2000.constants.Constants; -import com.jasamedika.medifirst2000.constants.MessageResource; -import com.jasamedika.medifirst2000.controller.base.LocaleController; -import com.jasamedika.medifirst2000.core.web.WebConstants; -import com.jasamedika.medifirst2000.exception.ServiceVOException; -import com.jasamedika.medifirst2000.service.PlanningDiklatHumasMarketService; -import com.jasamedika.medifirst2000.util.rest.RestUtil; -import com.jasamedika.medifirst2000.vo.AkunVO; -import com.jasamedika.medifirst2000.vo.PlanningDiklatHumasMarketVO; -import com.jasamedika.medifirst2000.vo.StrukPlanningVO; +import static com.jasamedika.medifirst2000.constants.Constants.MessageInfo.ERROR_MESSAGE; +import static com.jasamedika.medifirst2000.core.web.WebConstants.HttpHeaderInfo.LABEL_SUCCESS; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonHttpStatus; +import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonResponse; +import static org.slf4j.LoggerFactory.getLogger; +import static org.springframework.http.HttpStatus.*; +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import static org.springframework.web.bind.annotation.RequestMethod.GET; +import static org.springframework.web.bind.annotation.RequestMethod.POST; @RestController @RequestMapping("/planningdiklathumasmarket") -public class PlanningDiklatHumasMarketController extends LocaleController { - private static final Logger LOGGER = LoggerFactory.getLogger(PlanningDiklatHumasMarketController.class); - +public class PlanningDiklatHumasMarketController extends LocaleController { + + private static final Logger LOGGER = getLogger(PlanningDiklatHumasMarketController.class); + @Autowired private PlanningDiklatHumasMarketService planningDiklatHumasMarketService; - - @RequestMapping( - value = "/save-planning-dhm", - method = RequestMethod.POST, - produces = MediaType.APPLICATION_JSON_VALUE, - consumes = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> savePlanningDHM( - @Valid @RequestBody StrukPlanningVO vo, HttpServletRequest request) { - + + @RequestMapping(value = "/save-planning-dhm", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) + public ResponseEntity> savePlanningDHM(@Valid @RequestBody StrukPlanningVO vo, + HttpServletRequest request) { try { Map result = this.planningDiklatHumasMarketService.saveStrukPlanning(vo); - if (result != null) - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, - getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage); + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, CREATED, mapHeaderMessage); } catch (ServiceVOException e) { - - LOGGER.error("Got exception {} when savePlanningDHM", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - + LOGGER.error("Got ServiceVOException {} when saveStrukPlanning", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { - - LOGGER.error("Got exception {} when savePlanningDHM", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - } - } - - @RequestMapping( - value = "/get-list-bynoplanning", - method = RequestMethod.GET, - produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> getLoadDataByNoPlanning( - @RequestParam(value = "noPlanning", required = true) String noPlanning, HttpServletRequest request) { - - try { - Map result = this.planningDiklatHumasMarketService.getListPlanningDHM(noPlanning); - - if (null != result) { - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, - getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); - } else { - return RestUtil.getJsonResponse(result, HttpStatus.NOT_FOUND, mapHeaderMessage); - } - - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when getLoadDataByNoPlanning", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - - } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when getLoadDataByNoPlanning", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - + LOGGER.error("Got JpaSystemException {} when saveStrukPlanning", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } } - - @RequestMapping( - value = "/get-list-noplanning", - method = RequestMethod.GET, - produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> getLoadDataNoPlanning(HttpServletRequest request) { + @RequestMapping(value = "/get-list-noplanning", method = GET, produces = APPLICATION_JSON_VALUE) + public ResponseEntity> getLoadDataNoPlanning(HttpServletRequest request) { try { Map result = this.planningDiklatHumasMarketService.getListNoPlanningDHM(); - if (null != result) { - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, - getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, OK, mapHeaderMessage); } else { - return RestUtil.getJsonResponse(result, HttpStatus.NOT_FOUND, mapHeaderMessage); + return getJsonResponse(result, HttpStatus.NOT_FOUND, mapHeaderMessage); } - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when getLoadDataNoPlanning", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - + LOGGER.error("Got ServiceVOException {} when getListNoPlanningDHM", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when getLoadDataNoPlanning", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - + LOGGER.error("Got JpaSystemException {} when getListNoPlanningDHM", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } } - - - @RequestMapping( - value = "/get-load-planning-dhm", - method = RequestMethod.GET, - produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> getLoadData(HttpServletRequest request) { + @RequestMapping(value = "/get-load-planning-dhm", method = GET, produces = APPLICATION_JSON_VALUE) + public ResponseEntity> getLoadData(HttpServletRequest request) { try { Map result = this.planningDiklatHumasMarketService.getLoadData(); - if (null != result) { - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, - getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, OK, mapHeaderMessage); } else { - return RestUtil.getJsonResponse(result, HttpStatus.NOT_FOUND, mapHeaderMessage); + return getJsonResponse(null, NOT_FOUND, mapHeaderMessage); } - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when getLoadData", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - + LOGGER.error("Got ServiceVOException {} when planningDiklatHumasMarketService.getLoadData", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when getLoadData", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - + LOGGER.error("Got JpaSystemException {} when planningDiklatHumasMarketService.getLoadData", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } } - - @RequestMapping( - value = "/get-load-dokumensk", - method = RequestMethod.GET, - produces = MediaType.APPLICATION_JSON_VALUE) + @RequestMapping(value = "/get-load-dokumensk", method = GET, produces = APPLICATION_JSON_VALUE) public ResponseEntity> getListDokumen(HttpServletRequest request) { - try { Map result = this.planningDiklatHumasMarketService.getListDokumen(); - if (null != result) { - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, - getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, OK, mapHeaderMessage); } else { - return RestUtil.getJsonResponse(result, HttpStatus.NOT_FOUND, mapHeaderMessage); + return getJsonResponse(null, NOT_FOUND, mapHeaderMessage); } - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when getListDokumen", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - + LOGGER.error("Got ServiceVOException {} when getListDokumen", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when getListDokumen", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - + LOGGER.error("Got JpaSystemException {} when getListDokumen", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } } - - @RequestMapping( - value = "/get-load-jenisanggaran", - method = RequestMethod.GET, - produces = MediaType.APPLICATION_JSON_VALUE) + + @RequestMapping(value = "/get-load-jenisanggaran", method = GET, produces = APPLICATION_JSON_VALUE) public ResponseEntity> getListJenisAnggaran(HttpServletRequest request) { - try { Map result = this.planningDiklatHumasMarketService.getListJenisAnggaran(); - if (null != result) { - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, - getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, OK, mapHeaderMessage); } else { - return RestUtil.getJsonResponse(result, HttpStatus.NOT_FOUND, mapHeaderMessage); + return getJsonResponse(null, NOT_FOUND, mapHeaderMessage); } - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when getListJenisAnggaran", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - + LOGGER.error("Got ServiceVOException {} when getListJenisAnggaran", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when getListJenisAnggaran", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - + LOGGER.error("Got JpaSystemException {} when getListJenisAnggaran", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } } - - @RequestMapping( - value = "/get-load-jenistempat", - method = RequestMethod.GET, - produces = MediaType.APPLICATION_JSON_VALUE) + + @RequestMapping(value = "/get-load-jenistempat", method = GET, produces = APPLICATION_JSON_VALUE) public ResponseEntity> getListJenisTempat(HttpServletRequest request) { - try { Map result = this.planningDiklatHumasMarketService.getListJenisTempat(); - if (null != result) { - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, - getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, OK, mapHeaderMessage); } else { - return RestUtil.getJsonResponse(result, HttpStatus.NOT_FOUND, mapHeaderMessage); + return getJsonResponse(null, NOT_FOUND, mapHeaderMessage); } - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when getListJenisTempat", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - + LOGGER.error("Got ServiceVOException {} when getListJenisTempat", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when getListJenisTempat", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - + LOGGER.error("Got JpaSystemException {} when getListJenisTempat", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } } - - @RequestMapping( - value = "/get-load-rekanan", - method = RequestMethod.GET, - produces = MediaType.APPLICATION_JSON_VALUE) + + @RequestMapping(value = "/get-load-rekanan", method = GET, produces = APPLICATION_JSON_VALUE) public ResponseEntity> getListRekanan(HttpServletRequest request) { - try { Map result = this.planningDiklatHumasMarketService.getListRekanan(); - if (null != result) { - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, - getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, OK, mapHeaderMessage); } else { - return RestUtil.getJsonResponse(result, HttpStatus.NOT_FOUND, mapHeaderMessage); + return getJsonResponse(null, NOT_FOUND, mapHeaderMessage); } - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when getListRekanan", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - + LOGGER.error("Got ServiceVOException {} when getListRekanan", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when getListRekanan", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - + LOGGER.error("Got JpaSystemException {} when getListRekanan", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); } } - - @RequestMapping(value = "/get-no-surat/", method = RequestMethod.GET) - public ResponseEntity> getNoSurat(HttpServletRequest request) { - + + @RequestMapping(value = "/save-pelaksana-dhm", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) + public ResponseEntity> savePelaksanaDHM(@Valid @RequestBody PlanningDiklatHumasMarketVO vo, + HttpServletRequest request) { try { - String noSurat=planningDiklatHumasMarketService.getNoSurat(); - System.out.println("Lukman debug "+ noSurat); - Map result=new HashMap(); - result.put("noSurat", noSurat); - if (null != result) - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS,request )); - return RestUtil.getJsonResponse(result, HttpStatus.OK,mapHeaderMessage); - } catch (ServiceVOException e) { - LOGGER.error("Got exception {} when add nota-dinas", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, - mapHeaderMessage); - } catch (JpaSystemException jse) { - LOGGER.error("Got exception {} when add nota-dinas", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, - jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, - mapHeaderMessage); - } - } - - @RequestMapping( - value = "/save-pelaksana-dhm", - method = RequestMethod.POST, - produces = MediaType.APPLICATION_JSON_VALUE, - consumes = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> savePelaksanaDHM( - @Valid @RequestBody PlanningDiklatHumasMarketVO vo, HttpServletRequest request) { - - try { Map result = this.planningDiklatHumasMarketService.saveDHMPelaksana(vo); - if (result != null) - mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, - getMessage(MessageResource.LABEL_SUCCESS, request)); - return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage); + mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); + return getJsonResponse(result, CREATED, mapHeaderMessage); } catch (ServiceVOException e) { - - LOGGER.error("Got exception {} when savePelaksanaDHM", e.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); - + LOGGER.error("Got ServiceVOException {} when saveDHMPelaksana", e.getMessage()); + addHeaderMessage(ERROR_MESSAGE, e.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { - - LOGGER.error("Got exception {} when savePelaksanaDHM", jse.getMessage()); - addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.CONFLICT, mapHeaderMessage); - } catch(Exception ex) { - LOGGER.error("Exception at savePelasanaDHN", ex.getMessage()); - return RestUtil.getJsonHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); + LOGGER.error("Got JpaSystemException {} when saveDHMPelaksana", jse.getMessage()); + addHeaderMessage(ERROR_MESSAGE, jse.getMessage()); + return getJsonHttpStatus(CONFLICT, mapHeaderMessage); + } catch (Exception ex) { + LOGGER.error("Exception at {} saveDHMPelaksana", ex.getMessage()); + return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage); } } - - - }