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 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.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.util.rest.RestUtil; import com.jasamedika.medifirst2000.service.MapRuanganToKelasService; import com.jasamedika.medifirst2000.vo.MapRuanganToKelasVO_; import com.jasamedika.medifirst2000.vo.RuanganVO; @RestController @RequestMapping("/mapRuanganToKelas") public class MapRuanganToKelasController extends LocaleController implements IBaseRestController { @Autowired private MapRuanganToKelasService mapRuanganToKelasService; private static final Logger LOGGER = LoggerFactory .getLogger(MapRuanganToKelasController.class); 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-map-ruangan-to-kelas", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity addVO(@Valid @RequestBody MapRuanganToKelasVO_ vo, HttpServletRequest request) { try { List result = mapRuanganToKelasService.addVo(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 Map Ruangan to Kelas", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when add Map Ruangan to Kelas", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/update-map-ruangan-to-kelas", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity editVO(@Valid @RequestBody MapRuanganToKelasVO_ vo) { try { List result = mapRuanganToKelasService.updateVo(vo); if (null != result) addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, ""); RestUtil.getJsonHttptatus(HttpStatus.CREATED); return RestUtil.getJsonResponse("", HttpStatus.CREATED); } catch (ServiceVOException e) { LOGGER.error("Got exception {} when update Map Ruangan to Kelas", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when update Map Ruangan to Kelas", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @SuppressWarnings("unchecked") @RequestMapping(value = "/search-map-ruangan-to-kelas", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity> getAllVOWithQueryString( @RequestParam(value = "page", required = false ,defaultValue = "1") 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 = mapRuanganToKelasService.findAllWithPageAndLimitAndSortByAndDirectionParameter(page, limit, sort, dir); return constructListPageResult(resultPageMap); } @RequestMapping(value = "/delete-mapRuanganToKelas/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity deleteVO(Integer id) { try { if (mapRuanganToKelasService.delete(id) == true) return RestUtil.getJsonResponse("", HttpStatus.CREATED); } catch (ServiceVOException e) { LOGGER.error("Got exception {} when delete MapRuanganToKelas", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when delete MapRuanganToKelas", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } return RestUtil.getJsonHttptatus(HttpStatus.NOT_ACCEPTABLE); } @Override public ResponseEntity> getAllVO() { return null; } @Override public ResponseEntity addVO(MapRuanganToKelasVO_ vo) { return null; } @RequestMapping(value = "/get-ruangan-by-kelas", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity> getRuanganByRuangan( @RequestParam(value="kelasId",required = false) Integer kelasId, HttpServletRequest request) { try { Map result = mapRuanganToKelasService.getRuanganByKelas(kelasId); 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 getRuanganByRuangan", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when getRuanganByRuangan", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/get-kelas-by-ruangan", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity> getKelasByRuangan( @RequestParam(value="ruanganId",required = false) Integer ruanganId, HttpServletRequest request) { try { Map result = mapRuanganToKelasService.getKelasByRuangan(ruanganId); 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 getKelasByRuangan", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when getKelasByRuangan", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/get-kamar-by-kelas", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity> getKamarByKelas( @RequestParam(value="kelasId",required = false) Integer kelasId, @RequestParam(value="ruanganId",required = false) Integer ruanganId, HttpServletRequest request) { try { Map result = mapRuanganToKelasService.getKamarByKelas(kelasId, ruanganId); 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 getKamarByKelas", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got exception {} when getKamarByKelas", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } }