Update controller

Clean code
This commit is contained in:
Salman Manoe 2025-02-03 13:42:28 +07:00
parent c3ee97b3d2
commit 92a4d78560
53 changed files with 266 additions and 432 deletions

View File

@ -48,7 +48,7 @@ public class AsesmenGiziAwalController extends LocaleController<RegistrasiPelaya
Map<String, Object> result = asesmenGiziAwalService.saveAsesmenGiziAwal(vo); Map<String, Object> result = asesmenGiziAwalService.saveAsesmenGiziAwal(vo);
if (null != result) if (null != result)
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
SaveLog("Assesment Gizi Awal", "Pemeriksaan", request); SaveLog("Assesment Gizi Awal", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when saveAsesmenGiziAwal", e.getMessage()); LOGGER.error("Got ServiceVOException {} when saveAsesmenGiziAwal", e.getMessage());

View File

@ -43,7 +43,7 @@ public class AsesmenGiziLanjutController extends LocaleController<RegistrasiPela
Map<String, Object> result = asesmenGiziLanjutService.saveAsesmenGiziLanjut(vo); Map<String, Object> result = asesmenGiziLanjutService.saveAsesmenGiziLanjut(vo);
if (null != result) if (null != result)
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
SaveLog("Assesment Gizi Lanjut", "Pemeriksaan Khusus", request); SaveLog("Assesment Gizi Lanjut", "Pemeriksaan Khusus");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when saveAsesmenGiziLanjut", e.getMessage()); LOGGER.error("Got ServiceVOException {} when saveAsesmenGiziLanjut", e.getMessage());

View File

@ -101,8 +101,7 @@ public class AuthenticateController {
return RestUtil.getJsonHttpStatus(HttpStatus.NOT_ACCEPTABLE, mapHeaderMessage); return RestUtil.getJsonHttpStatus(HttpStatus.NOT_ACCEPTABLE, mapHeaderMessage);
} }
GrantedAuthority authority = new SimpleGrantedAuthority("USER"); GrantedAuthority authority = new SimpleGrantedAuthority("USER");
String token = tokenAuthenticationService.addAuthentication(httpResponse, String token = tokenAuthenticationService.addAuthentication(new UserAuthentication(new User(loginUserVo.getNamaUser(), loginUserVo.getKataSandi(),
new UserAuthentication(new User(loginUserVo.getNamaUser(), loginUserVo.getKataSandi(),
Collections.singletonList(authority)))); Collections.singletonList(authority))));
boolean isSupervising = request.getHeader(Constants.HttpHeader.SUPERVISING) != null; boolean isSupervising = request.getHeader(Constants.HttpHeader.SUPERVISING) != null;
if (isSupervising) { // supervising login if (isSupervising) { // supervising login
@ -168,8 +167,7 @@ public class AuthenticateController {
return RestUtil.getJsonHttpStatus(HttpStatus.NOT_ACCEPTABLE, mapHeaderMessage); return RestUtil.getJsonHttpStatus(HttpStatus.NOT_ACCEPTABLE, mapHeaderMessage);
} }
GrantedAuthority authority = new SimpleGrantedAuthority("USER"); GrantedAuthority authority = new SimpleGrantedAuthority("USER");
String token = tokenAuthenticationService.addAuthentication(httpResponse, String token = tokenAuthenticationService.addAuthentication(new UserAuthentication(new User(loginUserVo.getNamaUser(), loginUserVo.getKataSandi(),
new UserAuthentication(new User(loginUserVo.getNamaUser(), loginUserVo.getKataSandi(),
Collections.singletonList(authority)))); Collections.singletonList(authority))));
boolean isSupervising = request.getHeader(Constants.HttpHeader.SUPERVISING) != null; boolean isSupervising = request.getHeader(Constants.HttpHeader.SUPERVISING) != null;
if (isSupervising) { // supervising login if (isSupervising) { // supervising login

View File

@ -55,7 +55,7 @@ public class FisisPemeriksaanDokterController extends LocaleController<FisisPeme
} else { } else {
mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request)); mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request));
} }
SaveLog("Pemeriksaan Fisis Dokter", "Dokter", request); SaveLog("Pemeriksaan Fisis Dokter", "Dokter");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addFisisPemeriksaanDokter", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addFisisPemeriksaanDokter", e.getMessage());

View File

@ -57,7 +57,7 @@ public class KebutuhanDasarController extends LocaleController<KebutuhanDasarVO>
} else { } else {
mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request)); mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request));
} }
SaveLog("Kebutuhan Dasar Perawat", "Perawat", request); SaveLog("Kebutuhan Dasar Perawat", "Perawat");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addKebutuhanDasar", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addKebutuhanDasar", e.getMessage());

View File

@ -102,7 +102,7 @@ public class KelasController extends LocaleController<KelasVO> {
Map<String, Object> result = kelasService.findKelasByRuangan(ruanganId); Map<String, Object> result = kelasService.findKelasByRuangan(ruanganId);
if (null != result) if (null != result)
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
SaveLog("Get kelas by ruangan", "Permintaan", request); SaveLog("Get kelas by ruangan", "Permintaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when findKelasByRuangan", e.getMessage()); LOGGER.error("Got ServiceVOException {} when findKelasByRuangan", e.getMessage());

View File

@ -53,7 +53,7 @@ public class KonsepDiriController extends LocaleController<KonsepDiriVO> {
} else { } else {
mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request)); mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request));
} }
SaveLog("Konsep Diri", "Pemeriksaan", request); SaveLog("Konsep Diri", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addKonsepDiri", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addKonsepDiri", e.getMessage());

View File

@ -61,7 +61,7 @@ public class KonsultasiController extends LocaleController<AntrianPasienDiPeriks
} else { } else {
mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request)); mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request));
} }
SaveLog("Konsultasi", "Dokter", request); SaveLog("Konsultasi", "Dokter");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addKonsultasi2", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addKonsultasi2", e.getMessage());

View File

@ -54,7 +54,7 @@ public class KopingController extends LocaleController<KopingVO> {
} else { } else {
mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request)); mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request));
} }
SaveLog("Koping", "Pemeriksaan", request); SaveLog("Koping", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addKoping", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addKoping", e.getMessage());

View File

@ -49,7 +49,7 @@ public class MasalahKeperawatanController extends LocaleController<TriaseVO> {
if (null != result) if (null != result)
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
getJsonHttpStatus(CREATED); getJsonHttpStatus(CREATED);
SaveLog("Masalah Keperawatan", "Pemeriksaan", request); SaveLog("Masalah Keperawatan", "Pemeriksaan");
return getJsonResponse("Status Sukses", CREATED, mapHeaderMessage); return getJsonResponse("Status Sukses", CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when saveMasalahKeperawatanService", e.getMessage()); LOGGER.error("Got ServiceVOException {} when saveMasalahKeperawatanService", e.getMessage());

View File

@ -53,7 +53,7 @@ public class NilaiNilaiController extends LocaleController<NilaiNilaiVO> {
} else { } else {
mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request)); mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request));
} }
SaveLog("Nilai Nilai", "Pemeriksaan", request); SaveLog("Nilai Nilai", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addNilaiNilai", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addNilaiNilai", e.getMessage());

View File

@ -49,7 +49,7 @@ public class PapAlergiController extends LocaleController<PapAlergiVO> {
Map<String, Object> result = papAlergiService.addAlergi(vo); Map<String, Object> result = papAlergiService.addAlergi(vo);
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
result.put("message", "Berhasil"); result.put("message", "Berhasil");
SaveLog("Alergi", "Pemeriksaan", request); SaveLog("Alergi", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addAlergi", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addAlergi", e.getMessage());

View File

@ -49,7 +49,7 @@ public class PapAnamesisController extends LocaleController<PapAnamesisVO> {
Map<String, Object> result = papAnamesisService.addAnamesis(vo); Map<String, Object> result = papAnamesisService.addAnamesis(vo);
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
result.put("message", "Berhasil"); result.put("message", "Berhasil");
SaveLog("Anamnesis", "Pemeriksaan", request); SaveLog("Anamnesis", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addAnamesis", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addAnamesis", e.getMessage());

View File

@ -49,7 +49,7 @@ public class PapEliminasiController extends LocaleController<PapEliminasiVO> {
Map<String, Object> result = papEliminasiService.addEliminasi(vo); Map<String, Object> result = papEliminasiService.addEliminasi(vo);
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
result.put("message", "Berhasil"); result.put("message", "Berhasil");
SaveLog("Eliminasi", "Pemeriksaan", request); SaveLog("Eliminasi", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addEliminasi", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addEliminasi", e.getMessage());

View File

@ -50,7 +50,7 @@ public class PapGastrointestinalController extends LocaleController<PapGastroint
Map<String, Object> result = papGastrointestinalService.addGastrointestinal(vo); Map<String, Object> result = papGastrointestinalService.addGastrointestinal(vo);
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
result.put("message", "Berhasil"); result.put("message", "Berhasil");
SaveLog("Gastrointestinal", "Pemeriksaan", request); SaveLog("Gastrointestinal", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addGastrointestinal", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addGastrointestinal", e.getMessage());

View File

@ -53,7 +53,7 @@ public class PapGenataliaController extends LocaleController<PapGenataliaVO> {
Map<String, Object> result = papGenataliaService.addGenatalia(vo); Map<String, Object> result = papGenataliaService.addGenatalia(vo);
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
result.put("message", "Berhasil"); result.put("message", "Berhasil");
SaveLog("Genatalia", "Pemeriksaan", request); SaveLog("Genatalia", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addGenatalia", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addGenatalia", e.getMessage());

View File

@ -49,7 +49,7 @@ public class PapGigiMulutController extends LocaleController<PapGigiMulutVO> {
Map<String, Object> result = papGigiMulutService.addGigiMulut(vo); Map<String, Object> result = papGigiMulutService.addGigiMulut(vo);
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
result.put("message", "Berhasil"); result.put("message", "Berhasil");
SaveLog("Gigi Mulut", "Pemeriksaan Khusus", request); SaveLog("Gigi Mulut", "Pemeriksaan Khusus");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addGigiMulut", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addGigiMulut", e.getMessage());

View File

@ -52,7 +52,7 @@ public class PapInstruksiPerjanjianController extends LocaleController<PapInstru
Map<String, Object> result = papInstruksiPerjanjianService.addInstruksiPerjanjian(vo); Map<String, Object> result = papInstruksiPerjanjianService.addInstruksiPerjanjian(vo);
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
result.put("message", "Berhasil"); result.put("message", "Berhasil");
SaveLog("Perjanjian", "Instruksi", request); SaveLog("Perjanjian", "Instruksi");
return getJsonResponse(result, CREATED); return getJsonResponse(result, CREATED);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addInstruksiPerjanjian", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addInstruksiPerjanjian", e.getMessage());

View File

@ -49,7 +49,7 @@ public class PapIntegumenController extends LocaleController<PapIntegumenVO> {
Map<String, Object> result = papIntegumenService.addIntegumen(vo); Map<String, Object> result = papIntegumenService.addIntegumen(vo);
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
result.put("message", "Berhasil"); result.put("message", "Berhasil");
SaveLog("Integumen", "Pemeriksaan", request); SaveLog("Integumen", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addIntegumen", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addIntegumen", e.getMessage());

View File

@ -45,7 +45,7 @@ public class PapKebutuhanEdukasiController extends LocaleController<PapKebutuhan
Map<String, Object> result = papKebutuhanEdukasiService.addKebutuhanEdukasi(vo); Map<String, Object> result = papKebutuhanEdukasiService.addKebutuhanEdukasi(vo);
if (null != result) if (null != result)
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
SaveLog("Kebutuhan Edukasi", "Pemeriksaan", request); SaveLog("Kebutuhan Edukasi", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addKebutuhanEdukasi", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addKebutuhanEdukasi", e.getMessage());

View File

@ -52,7 +52,7 @@ public class PapKeluhanTambahanController extends LocaleController<PapKeluhanTam
Map<String, Object> result = papKeluhanTambahanService.addKeluhanTambahan(vo); Map<String, Object> result = papKeluhanTambahanService.addKeluhanTambahan(vo);
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
result.put("message", "Berhasil"); result.put("message", "Berhasil");
SaveLog("Keluhan Tambahan", "Pemeriksaan", request); SaveLog("Keluhan Tambahan", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addKeluhanTambahan", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addKeluhanTambahan", e.getMessage());

View File

@ -54,7 +54,7 @@ public class PapKeluhanUtamaController extends LocaleController<PapKeluhanUtamaV
Map<String, Object> result = papKeluhanUtamaService.addKeluhanUtama(vo); Map<String, Object> result = papKeluhanUtamaService.addKeluhanUtama(vo);
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
result.put("message", "Berhasil"); result.put("message", "Berhasil");
SaveLog("Keluhan Utama", "Pemeriksaan", request); SaveLog("Keluhan Utama", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addKeluhanUtama", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addKeluhanUtama", e.getMessage());

View File

@ -50,7 +50,7 @@ public class PapMuskuloskeletalController extends LocaleController<PapMuskuloske
Map<String, Object> result = papMuskuloskeletalService.addMuskuloskeletal(vo); Map<String, Object> result = papMuskuloskeletalService.addMuskuloskeletal(vo);
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
result.put("message", "Berhasil"); result.put("message", "Berhasil");
SaveLog("Muskuloskeletal", "Pemeriksaan", request); SaveLog("Muskuloskeletal", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addMuskuloskeletal", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addMuskuloskeletal", e.getMessage());

View File

@ -49,7 +49,7 @@ public class PapNeurologiController extends LocaleController<PapNeurologiVO> {
Map<String, Object> result = papNeurologiService.addNeurologi(vo); Map<String, Object> result = papNeurologiService.addNeurologi(vo);
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
result.put("message", "Berhasil"); result.put("message", "Berhasil");
SaveLog("Neurologi", "Pemeriksaan", request); SaveLog("Neurologi", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addNeurologi", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addNeurologi", e.getMessage());

View File

@ -53,7 +53,7 @@ public class PapObstetriController extends LocaleController<PapObstetriVO> {
} else { } else {
mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request)); mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request));
} }
SaveLog("Pengkajian Khusus Obstetri", "Pengkajian Khusus", request); SaveLog("Pengkajian Khusus Obstetri", "Pengkajian Khusus");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when savePapObstetri", e.getMessage()); LOGGER.error("Got ServiceVOException {} when savePapObstetri", e.getMessage());

View File

@ -50,7 +50,7 @@ public class PapPernapasanController extends LocaleController<PapPernapasanVO> {
Map<String, Object> result = papPernapasanService.addPernapasan(vo); Map<String, Object> result = papPernapasanService.addPernapasan(vo);
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
result.put("message", "Berhasil"); result.put("message", "Berhasil");
SaveLog("Pernapasan", "Pemeriksaan", request); SaveLog("Pernapasan", "Pemeriksaan");
return getJsonResponse(result, CREATED); return getJsonResponse(result, CREATED);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addPernapasan", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addPernapasan", e.getMessage());

View File

@ -50,7 +50,7 @@ public class PapRiwayatPsikososialController extends LocaleController<PapRiwayat
Map<String, Object> result = papRiwayatPsikososialService.addRiwayatPsikososial(vo); Map<String, Object> result = papRiwayatPsikososialService.addRiwayatPsikososial(vo);
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
result.put("message", "Berhasil"); result.put("message", "Berhasil");
SaveLog("Riwayat Psikososial", "Pemeriksaan", request); SaveLog("Riwayat Psikososial", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addRiwayatPsikososial", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addRiwayatPsikososial", e.getMessage());

View File

@ -49,7 +49,7 @@ public class PapSirkulasiController extends LocaleController<PapSirkulasiVO> {
Map<String, Object> result = papSirkulasiService.addSirkulasi(vo); Map<String, Object> result = papSirkulasiService.addSirkulasi(vo);
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
result.put("message", "Berhasil"); result.put("message", "Berhasil");
SaveLog("Sirkulasi", "Pemeriksaan", request); SaveLog("Sirkulasi", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addSirkulasi", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addSirkulasi", e.getMessage());

View File

@ -56,7 +56,7 @@ public class PasienPulangController extends LocaleController<PasienPulangVO> {
mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request)); mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request));
} }
} }
SaveLog("Pasien Pulang", "Instruksi", request); SaveLog("Pasien Pulang", "Instruksi");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when updatepasienPulang", e.getMessage()); LOGGER.error("Got ServiceVOException {} when updatepasienPulang", e.getMessage());

View File

@ -50,7 +50,7 @@ public class PembedahanDanInstruksiController extends LocaleController<Pembedaha
Map<String, Object> result = pembedahanDanInstruksiService.addPembedahanDanInstruksi(vo); Map<String, Object> result = pembedahanDanInstruksiService.addPembedahanDanInstruksi(vo);
mapHeaderMessage.clear(); mapHeaderMessage.clear();
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
SaveLog("Laporan Pembedahan dan Instruksi Bedah", "Bedah", request); SaveLog("Laporan Pembedahan dan Instruksi Bedah", "Bedah");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addPembedahanDanInstruksi", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addPembedahanDanInstruksi", e.getMessage());

View File

@ -54,7 +54,7 @@ public class PeranHubunganController extends LocaleController<PeranHubunganVO> {
} else { } else {
mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request)); mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request));
} }
SaveLog("Peran Hubungan", "Pemeriksaan", request); SaveLog("Peran Hubungan", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addPeranHubungan", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addPeranHubungan", e.getMessage());

View File

@ -54,7 +54,7 @@ public class PersepsiKognisiController extends LocaleController<PersepsiKognisiV
} else { } else {
mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request)); mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request));
} }
SaveLog("Persepsi Kognisi", "Pemeriksaan", request); SaveLog("Persepsi Kognisi", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addPersepsiKognisi", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addPersepsiKognisi", e.getMessage());

View File

@ -54,7 +54,7 @@ public class PersepsiPasienController extends LocaleController<PersepsiPasienVO>
} else { } else {
mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request)); mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request));
} }
SaveLog("Persepsi Pasien", "Pemeriksaan", request); SaveLog("Persepsi Pasien", "Pemeriksaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addPersepsiPasien", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addPersepsiPasien", e.getMessage());

View File

@ -58,7 +58,7 @@ public class ProdukDetailLabAnatomiController extends LocaleController<ProdukDet
} else { } else {
mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request)); mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request));
} }
SaveLog("Laboratorium Patologi Anatomi", "Laboratorium", request); SaveLog("Laboratorium Patologi Anatomi", "Laboratorium");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when addProdukDetailLabAnatomi", e.getMessage()); LOGGER.error("Got ServiceVOException {} when addProdukDetailLabAnatomi", e.getMessage());

View File

@ -11,6 +11,7 @@ import com.jasamedika.medifirst2000.entities.*;
import com.jasamedika.medifirst2000.enums.TipePasienEnum; import com.jasamedika.medifirst2000.enums.TipePasienEnum;
import com.jasamedika.medifirst2000.exception.ServiceVOException; import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.*; import com.jasamedika.medifirst2000.service.*;
import com.jasamedika.medifirst2000.util.DateUtil;
import com.jasamedika.medifirst2000.vo.*; import com.jasamedika.medifirst2000.vo.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -223,7 +224,7 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
permintaan = "Laboratorium"; permintaan = "Laboratorium";
} }
} }
SaveLog("Order " + permintaan, "Permintaaan", request); SaveLog("Order " + permintaan, "Permintaaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when saveOrderProduk", e.getMessage()); LOGGER.error("Got ServiceVOException {} when saveOrderProduk", e.getMessage());
@ -397,7 +398,7 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
Map<String, Object> result = pelayananObatService.savePelayananObat3(vo); Map<String, Object> result = pelayananObatService.savePelayananObat3(vo);
if (null != result) if (null != result)
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
SaveLog("Order Farmasi", "Permintaan", request); SaveLog("Order Farmasi", "Permintaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when savePelayananObat3", e.getMessage()); LOGGER.error("Got ServiceVOException {} when savePelayananObat3", e.getMessage());
@ -1189,9 +1190,8 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
List<HasilPemeriksaan> list = registrasiPelayananService.getHasilPemeriksaanByNoOrder(noOrder); List<HasilPemeriksaan> list = registrasiPelayananService.getHasilPemeriksaanByNoOrder(noOrder);
List<HasilLaboratoriumDto> dtos = new ArrayList<>(); List<HasilLaboratoriumDto> dtos = new ArrayList<>();
Alamat alamatPasien = alamatService.findByPasienId2(strukOrder.getNoCm().getId()); Alamat alamatPasien = alamatService.findByPasienId2(strukOrder.getNoCm().getId());
Integer usia = new Date( int selisihTahunSaatDaftar = DateUtil.getYear(new Date(strukOrder.getNoCm().getTglDaftar().getTime() - strukOrder.getNoCm().getTglLahir().getTime()));
strukOrder.getNoCm().getTglDaftar().getTime() - strukOrder.getNoCm().getTglLahir().getTime()).getYear() Integer usia = selisihTahunSaatDaftar - 70;
- 70;
Date now = new Date(); Date now = new Date();
PapPengambilanSpesimen papPengambilanSpesimen = papPengambilanSpesimenService PapPengambilanSpesimen papPengambilanSpesimen = papPengambilanSpesimenService
.findByNoOrderAndTglOrder2(strukOrder.getNoOrder(), strukOrder.getTglOrder()); .findByNoOrderAndTglOrder2(strukOrder.getNoOrder(), strukOrder.getTglOrder());
@ -1501,7 +1501,7 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
boolean dataFound = (boolean) result.get("dataFound"); boolean dataFound = (boolean) result.get("dataFound");
if (dataFound) { if (dataFound) {
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
SaveLog("Order Gizi", "Permintaan", request); SaveLog("Order Gizi", "Permintaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} else { } else {
mapHeaderMessage.put(ERROR_MESSAGE, getMessage(MessageResource.LABEL_ERROR, request)); mapHeaderMessage.put(ERROR_MESSAGE, getMessage(MessageResource.LABEL_ERROR, request));
@ -1529,7 +1529,7 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
toDate(startDate), toDate(endDate)); toDate(startDate), toDate(endDate));
if (null != result) if (null != result)
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
SaveLog("Order Gizi", "Permintaan", request); SaveLog("Order Gizi", "Permintaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when getOrderPelayananGiziMinuman", e.getMessage()); LOGGER.error("Got ServiceVOException {} when getOrderPelayananGiziMinuman", e.getMessage());
@ -1671,7 +1671,7 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
Map<String, Object> result = registrasiPelayananService.getTindakanPelayanan(noRec); Map<String, Object> result = registrasiPelayananService.getTindakanPelayanan(noRec);
if (null != result) if (null != result)
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
SaveLog("Order Tindakan", "Permintaan", request); SaveLog("Order Tindakan", "Permintaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} getTindakanPelayanan", e.getMessage()); LOGGER.error("Got ServiceVOException {} getTindakanPelayanan", e.getMessage());
@ -1691,7 +1691,7 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
List<Map<String, Object>> result = orderProdukService.saveVerifikasiGiziAll(dtos); List<Map<String, Object>> result = orderProdukService.saveVerifikasiGiziAll(dtos);
if (result != null) { if (result != null) {
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
SaveLog("Produk Gizi", "Permintaan", request); SaveLog("Produk Gizi", "Permintaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} else { } else {
mapHeaderMessage.put(ERROR_MESSAGE, getMessage(MessageResource.LABEL_ERROR, request)); mapHeaderMessage.put(ERROR_MESSAGE, getMessage(MessageResource.LABEL_ERROR, request));
@ -1715,7 +1715,7 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
List<Map<String, Object>> result = orderProdukService.cekStokGiziProduksi(vo); List<Map<String, Object>> result = orderProdukService.cekStokGiziProduksi(vo);
if (result != null) { if (result != null) {
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
SaveLog("Cek Produk Gizi", "Permintaan", request); SaveLog("Cek Produk Gizi", "Permintaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} else { } else {
mapHeaderMessage.put(ERROR_MESSAGE, getMessage(MessageResource.LABEL_ERROR, request)); mapHeaderMessage.put(ERROR_MESSAGE, getMessage(MessageResource.LABEL_ERROR, request));
@ -1740,7 +1740,7 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
boolean dataFound = (boolean) result.get("dataFound"); boolean dataFound = (boolean) result.get("dataFound");
if (dataFound) { if (dataFound) {
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
SaveLog("Produk Gizi", "Permintaan", request); SaveLog("Produk Gizi", "Permintaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} else { } else {
mapHeaderMessage.put(ERROR_MESSAGE, getMessage(MessageResource.LABEL_ERROR, request)); mapHeaderMessage.put(ERROR_MESSAGE, getMessage(MessageResource.LABEL_ERROR, request));
@ -1765,7 +1765,7 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
boolean dataFound = (boolean) result.get("dataFound"); boolean dataFound = (boolean) result.get("dataFound");
if (dataFound) { if (dataFound) {
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
SaveLog("Kirim Menu Gizi", "Permintaan", request); SaveLog("Kirim Menu Gizi", "Permintaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} else { } else {
mapHeaderMessage.put(ERROR_MESSAGE, getMessage(MessageResource.LABEL_ERROR, request)); mapHeaderMessage.put(ERROR_MESSAGE, getMessage(MessageResource.LABEL_ERROR, request));
@ -1789,7 +1789,7 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
Map<String, Object> result = orderProdukService.getOrderPelayananKirimMenuGiziMakanan(ruanganId); Map<String, Object> result = orderProdukService.getOrderPelayananKirimMenuGiziMakanan(ruanganId);
if (null != result) if (null != result)
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
SaveLog("Order Gizi", "Permintaan", request); SaveLog("Order Gizi", "Permintaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when getOrderPelayananKirimMenuGiziMakanan", e.getMessage()); LOGGER.error("Got ServiceVOException {} when getOrderPelayananKirimMenuGiziMakanan", e.getMessage());
@ -1809,7 +1809,7 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
Map<String, Object> result = orderProdukService.getOrderPelayananKirimMenuGiziMinuman(ruanganId); Map<String, Object> result = orderProdukService.getOrderPelayananKirimMenuGiziMinuman(ruanganId);
if (null != result) if (null != result)
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
SaveLog("Order Gizi", "Permintaan", request); SaveLog("Order Gizi", "Permintaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when getOrderPelayananKirimMenuGiziMinuman", e.getMessage()); LOGGER.error("Got ServiceVOException {} when getOrderPelayananKirimMenuGiziMinuman", e.getMessage());
@ -1829,7 +1829,7 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
Map<String, Object> result = orderProdukService.getOrder(noOrder); Map<String, Object> result = orderProdukService.getOrder(noOrder);
if (null != result) if (null != result)
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
SaveLog("Order Gizi", "Permintaan", request); SaveLog("Order Gizi", "Permintaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when getOrder", e.getMessage()); LOGGER.error("Got ServiceVOException {} when getOrder", e.getMessage());
@ -1869,7 +1869,7 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
permintaan = "Laboratorium"; permintaan = "Laboratorium";
} }
} }
SaveLog("Order " + permintaan, "Permintaaan", request); SaveLog("Order " + permintaan, "Permintaaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when saveOrderProduklab", e.getMessage()); LOGGER.error("Got ServiceVOException {} when saveOrderProduklab", e.getMessage());
@ -1912,7 +1912,7 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
Map<String, Object> result = orderProdukService.updateOrderProduklab(map, cito); Map<String, Object> result = orderProdukService.updateOrderProduklab(map, cito);
if (null != result) if (null != result)
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
SaveLog("Order ", "Ubah order laboratorium", request); SaveLog("Order ", "Ubah order laboratorium");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when updateOrderProduklab", e.getMessage()); LOGGER.error("Got ServiceVOException {} when updateOrderProduklab", e.getMessage());
@ -1932,7 +1932,7 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
List<Map<String, Object>> result = orderProdukService.getAllProdukProduksiGizi(menu); List<Map<String, Object>> result = orderProdukService.getAllProdukProduksiGizi(menu);
if (null != result) if (null != result)
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
SaveLog("Order Gizi", "Permintaan", request); SaveLog("Order Gizi", "Permintaan");
return getJsonResponse(result, CREATED, mapHeaderMessage); return getJsonResponse(result, CREATED, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got ServiceVOException {} when getAllProdukProduksiGizi", e.getMessage()); LOGGER.error("Got ServiceVOException {} when getAllProdukProduksiGizi", e.getMessage());

View File

@ -4,39 +4,29 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.jasamedika.medifirst2000.base.vo.BaseVO; import com.jasamedika.medifirst2000.base.vo.BaseVO;
import static org.springframework.web.bind.annotation.RequestMethod.*;
/** /**
* Base Rest Operation for Controller Class * Base Rest Operation for Controller Class
* *
* @author Roberto * @author Roberto
*/ */
public interface BaseRestController<V extends BaseVO> extends public interface BaseRestController<V extends BaseVO> extends RestPageController<V> {
RestPageController<V> {
@RequestMapping(value = "/{id}", method = RequestMethod.GET) @RequestMapping(value = "/{id}", method = GET)
@ResponseBody @ResponseBody
public ResponseEntity<V> getVO(@PathVariable("id") String id); ResponseEntity<V> getVO(@PathVariable("id") String id);
@RequestMapping(value = "/", method = RequestMethod.PUT) @RequestMapping(value = "/", method = POST, consumes = { "application/json" })
@ResponseBody @ResponseBody
public ResponseEntity<Integer> addVO(@RequestBody V vo); ResponseEntity<Integer> addVO(@RequestBody V vo);
@RequestMapping(value = "/", method = RequestMethod.POST, consumes = { "application/json" }) @RequestMapping(value = "/", method = PUT, consumes = { "application/json" })
@ResponseBody @ResponseBody
public ResponseEntity<Integer> editVO(@RequestBody V vo); ResponseEntity<Integer> editVO(@RequestBody V vo);
// @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
// @ResponseBody
// public ResponseEntity<String> deleteVO(@PathVariable("id") Integer id);
// @RequestMapping(value = "/", method = RequestMethod.GET)
// @ResponseBody
// public ResponseEntity<Collection<V>> getAllVO();
} }

View File

@ -19,11 +19,11 @@ public interface IBaseRestController<V extends BaseModelVO> extends IRestPageCon
@ResponseBody @ResponseBody
ResponseEntity<V> getVO(@PathVariable("id") Integer id); ResponseEntity<V> getVO(@PathVariable("id") Integer id);
@RequestMapping(value = "/", method = PUT, consumes = { "application/json" }) @RequestMapping(value = "/", method = POST, consumes = { "application/json" })
@ResponseBody @ResponseBody
ResponseEntity<String> addVO(@RequestBody V vo); ResponseEntity<String> addVO(@RequestBody V vo);
@RequestMapping(value = "/", method = POST, consumes = { "application/json" }) @RequestMapping(value = "/", method = PUT, consumes = { "application/json" })
@ResponseBody @ResponseBody
ResponseEntity<String> editVO(@RequestBody V vo); ResponseEntity<String> editVO(@RequestBody V vo);

View File

@ -1,16 +1,15 @@
package com.jasamedika.medifirst2000.controller.base; package com.jasamedika.medifirst2000.controller.base;
import java.util.Collection; import com.jasamedika.medifirst2000.base.vo.BaseModelVO;
import javax.servlet.http.HttpServletRequest;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping; 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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.jasamedika.medifirst2000.base.vo.BaseModelVO; import javax.servlet.http.HttpServletRequest;
import java.util.Collection;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
/** /**
* Base Rest Operation for 'pagination' Controller Class * Base Rest Operation for 'pagination' Controller Class
@ -30,12 +29,12 @@ public interface IRestPageController<V extends BaseModelVO> {
* : direction {asc:desc} * : direction {asc:desc}
* @return Collection of VO, Total-Count & Total Pages on response header * @return Collection of VO, Total-Count & Total Pages on response header
*/ */
@RequestMapping(value = "/list", method = RequestMethod.GET) @RequestMapping(value = "/list", method = GET)
@ResponseBody @ResponseBody
public ResponseEntity<Collection<V>> getAllVOWithQueryString( ResponseEntity<Collection<V>> getAllVOWithQueryString(
HttpServletRequest request, HttpServletRequest request,
@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "limit", required = false) Integer limit, @RequestParam(value = "limit", required = false) Integer limit,
@RequestParam(value = "sort", required = false, defaultValue = "id") String sort, @RequestParam(value = "sort", required = false, defaultValue = "id") String sort,
@RequestParam(value = "dir", required = false, defaultValue = "asc") String dir); @RequestParam(value = "dir", required = false, defaultValue = "asc") String dir);
} }

View File

@ -22,11 +22,9 @@ import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -37,6 +35,11 @@ import java.io.InputStreamReader;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.*; import java.util.*;
import static com.jasamedika.medifirst2000.constants.Constants.Locale.INA;
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;
/** /**
* Base Controller Class for handling messaga resource for internationalization * Base Controller Class for handling messaga resource for internationalization
* & locale * & locale
@ -45,10 +48,6 @@ import java.util.*;
*/ */
public abstract class LocaleController<V extends BaseModelVO> { public abstract class LocaleController<V extends BaseModelVO> {
/*
* messageSource bean injected for each controller for accessing message
* source
*/
@Autowired @Autowired
private ActivityPegawaiService activityPegawaiServiceImpl; private ActivityPegawaiService activityPegawaiServiceImpl;
@ -66,14 +65,11 @@ public abstract class LocaleController<V extends BaseModelVO> {
protected Map<String, String> mapHeaderMessage = new HashMap<>(); protected Map<String, String> mapHeaderMessage = new HashMap<>();
/*
* code locale
*/
protected String getMessage(String code, HttpServletRequest request) { protected String getMessage(String code, HttpServletRequest request) {
return messageSource.getMessage(code, null, new Locale(getCoociesLanguage(request))); return messageSource.getMessage(code, null, new Locale(getCoociesLanguage(request)));
} }
protected void SaveLog(String keterangan, String group, HttpServletRequest request) { protected void SaveLog(String keterangan, String group) {
activityPegawaiServiceImpl.record( activityPegawaiServiceImpl.record(
pegawaiConverter.transferModelToVO(loginUserService.getLoginUser().getPegawai(), new PegawaiVO()), pegawaiConverter.transferModelToVO(loginUserService.getLoginUser().getPegawai(), new PegawaiVO()),
new Date(), keterangan, group); new Date(), keterangan, group);
@ -115,7 +111,7 @@ public abstract class LocaleController<V extends BaseModelVO> {
} }
} }
@RequestMapping(value = "/lang/{lang}", method = RequestMethod.GET) @RequestMapping(value = "/lang/{lang}", method = GET)
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
@PathVariable("lang") String lang) { @PathVariable("lang") String lang) {
Cookie[] cookies = request.getCookies(); Cookie[] cookies = request.getCookies();
@ -150,27 +146,24 @@ public abstract class LocaleController<V extends BaseModelVO> {
return true; return true;
} }
/*
* default locale ID
*/
protected String getMessage(String code) { protected String getMessage(String code) {
return messageSource.getMessage(code, null, new Locale(Constants.Locale.INA)); return messageSource.getMessage(code, null, new Locale(INA));
} }
protected void addHeaderMessage(String key, String message) { protected void addHeaderMessage(String key, String message) {
this.mapHeaderMessage.put(key, message); this.mapHeaderMessage.put(key, message);
} }
@RequestMapping(value = "/entity-serelize/{entity}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/entity-serelize/{entity}", method = GET, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<ModelVO> serializeEntity(@PathVariable("entity") String entity, HttpServletRequest request) { public ResponseEntity<ModelVO> serializeEntity(@PathVariable("entity") String entity, HttpServletRequest request) {
ModelVO modelDTO = modelService.getModelSerializeEntity(entity, getCoociesLanguage(request)); ModelVO modelDTO = modelService.getModelSerializeEntity(entity, getCoociesLanguage(request));
return RestUtil.getJsonResponse(modelDTO, HttpStatus.OK); return RestUtil.getJsonResponse(modelDTO, OK);
} }
public String getCoociesLanguage(HttpServletRequest request) { public String getCoociesLanguage(HttpServletRequest request) {
Cookie[] cookie = request.getCookies(); Cookie[] cookie = request.getCookies();
Cookie cook; Cookie cook;
String lang = Constants.Locale.INA; String lang = INA;
if (cookie != null) { if (cookie != null) {
for (Cookie value : cookie) { for (Cookie value : cookie) {
cook = value; cook = value;
@ -195,7 +188,7 @@ public abstract class LocaleController<V extends BaseModelVO> {
String.valueOf(map.get(WebConstants.PageParameter.TOTAL_PAGES))); String.valueOf(map.get(WebConstants.PageParameter.TOTAL_PAGES)));
mapHeaderMessage.put(WebConstants.HttpHeaderInfo.TOTAL_COUNT_HEADER, mapHeaderMessage.put(WebConstants.HttpHeaderInfo.TOTAL_COUNT_HEADER,
String.valueOf(map.get(WebConstants.PageParameter.TOTAL_ELEMENTS))); String.valueOf(map.get(WebConstants.PageParameter.TOTAL_ELEMENTS)));
return RestUtil.getJsonResponse(vos, HttpStatus.OK, mapHeaderMessage); return RestUtil.getJsonResponse(vos, OK, mapHeaderMessage);
} }
} }

View File

@ -1,36 +1,30 @@
package com.jasamedika.medifirst2000.controller.base; package com.jasamedika.medifirst2000.controller.base;
import java.util.List;
import org.springframework.core.GenericTypeResolver;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.jasamedika.medifirst2000.base.vo.BaseModelVO; import com.jasamedika.medifirst2000.base.vo.BaseModelVO;
import com.jasamedika.medifirst2000.constants.Constants; import com.jasamedika.medifirst2000.constants.Constants;
import com.jasamedika.medifirst2000.util.rest.RestUtil; import com.jasamedika.medifirst2000.util.rest.RestUtil;
import com.monitorjbl.json.JsonResult; import com.monitorjbl.json.JsonResult;
import com.monitorjbl.json.JsonView; import com.monitorjbl.json.JsonView;
import com.monitorjbl.json.Match; import com.monitorjbl.json.Match;
import org.springframework.core.GenericTypeResolver;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
/** /**
* Base Controller Class for handling "include" parameter to controller * Base Controller Class for handling "include" parameter to controller
* @see https://github.com/monitorjbl/json-view * @see <a href="https://github.com/monitorjbl/json-view">reference</a>
* *
* @author Roberto * @author Roberto
*/ */
public abstract class ParamRestController<T extends BaseModelVO> { public abstract class ParamRestController<T extends BaseModelVO> {
private JsonResult jsonResult = JsonResult.instance();
/* private final JsonResult jsonResult = JsonResult.instance();
* Belum selesai, baru di parameter includes. Untuk field object juga belom.
* example :
* http://localhost:8080/jasamedika-web/{typeVOClass}/list-using-param
* ?includes =id,nama
*/
@RequestMapping(value = "/list-using-param", method = RequestMethod.GET) @RequestMapping(value = "/list-using-param", method = RequestMethod.GET)
public ResponseEntity<List<T>> listUsingParam( public ResponseEntity<List<T>> listUsingParam(
@RequestParam(value = "includes", required = false) String includes, @RequestParam(value = "includes", required = false) String includes,
@ -61,7 +55,6 @@ public abstract class ParamRestController<T extends BaseModelVO> {
Match.match().exclude("*").include(arrIncludes))) Match.match().exclude("*").include(arrIncludes)))
.returnValue(); .returnValue();
} }
return RestUtil.getJsonResponse(listVO, HttpStatus.OK); return RestUtil.getJsonResponse(listVO, HttpStatus.OK);
} }
@ -71,8 +64,6 @@ public abstract class ParamRestController<T extends BaseModelVO> {
ParamRestController.class); ParamRestController.class);
} }
/*
* method untuk mendapatkan all VO from service
* */
protected abstract List<T> getAllVOFromService(); protected abstract List<T> getAllVOFromService();
} }

View File

@ -1,14 +1,14 @@
package com.jasamedika.medifirst2000.controller.base; package com.jasamedika.medifirst2000.controller.base;
import java.util.Collection; import com.jasamedika.medifirst2000.base.vo.BaseVO;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping; 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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.jasamedika.medifirst2000.base.vo.BaseVO; import java.util.Collection;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
/** /**
* Base Rest Operation for 'pagination' Controller Class * Base Rest Operation for 'pagination' Controller Class
@ -28,11 +28,11 @@ public interface RestPageController<V extends BaseVO> {
* : direction {asc:desc} * : direction {asc:desc}
* @return Collection of VO, Total-Count & Total Pages on response header * @return Collection of VO, Total-Count & Total Pages on response header
*/ */
@RequestMapping(value = "/list", method = RequestMethod.GET) @RequestMapping(value = "/list", method = GET)
@ResponseBody @ResponseBody
public ResponseEntity<Collection<V>> getAllVOWithQueryString( ResponseEntity<Collection<V>> getAllVOWithQueryString(
@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "limit", required = false) Integer limit, @RequestParam(value = "limit", required = false) Integer limit,
@RequestParam(value = "sort", required = false, defaultValue = "id") String sort, @RequestParam(value = "sort", required = false, defaultValue = "id") String sort,
@RequestParam(value = "dir", required = false, defaultValue = "asc") String dir); @RequestParam(value = "dir", required = false, defaultValue = "asc") String dir);
} }

View File

@ -1,30 +1,19 @@
package com.jasamedika.medifirst2000.filter; package com.jasamedika.medifirst2000.filter;
import java.io.BufferedReader; import com.jasamedika.medifirst2000.constants.Constants;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Iterator;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.jasamedika.medifirst2000.constants.Constants; import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.Iterator;
/** /**
* CORSFilter class * CORSFilter class
@ -34,72 +23,49 @@ import com.jasamedika.medifirst2000.constants.Constants;
@Component @Component
public class CORSFilter implements Filter { public class CORSFilter implements Filter {
// Start Syamsu private static final Logger LOGGER = LoggerFactory.getLogger(CORSFilter.class);
public CORSFilter() {
LOGGER.info("CORSFilter JasaMedika Web init");
}
private static class RequestWrapper extends HttpServletRequestWrapper { private static class RequestWrapper extends HttpServletRequestWrapper {
final String body; final String body;
public RequestWrapper(ServletRequest req) throws IOException { public RequestWrapper(ServletRequest req) throws IOException {
super((HttpServletRequest) req); super((HttpServletRequest) req);
HttpServletRequest request = (HttpServletRequest) req; HttpServletRequest request = (HttpServletRequest) req;
StringBuilder stringBuilder = getStringBuilder(request);
StringBuilder stringBuilder = new StringBuilder(); body = stringBuilder.toString();
BufferedReader reader = null;
try {
InputStream inputStream = request.getInputStream();
if (inputStream != null) {
reader = new BufferedReader(new InputStreamReader(inputStream));
String hasil;
while ( (hasil = reader.readLine()) != null) {
stringBuilder.append(hasil);
}
} else {
stringBuilder.append("");
}
} catch (IOException ex) {
throw ex;
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ex) {
throw ex;
}
}
}
body = stringBuilder.toString();
String idRuanganTujuan = request.getHeader(Constants.HttpHeader.KD_RUANGAN_T) == null ? "" String idRuanganTujuan = request.getHeader(Constants.HttpHeader.KD_RUANGAN_T) == null ? ""
: request.getHeader(Constants.HttpHeader.KD_RUANGAN_T); : request.getHeader(Constants.HttpHeader.KD_RUANGAN_T);
if (idRuanganTujuan.trim().isEmpty()){
if ("".equals(idRuanganTujuan.trim())){ JSONObject jObject;
try{ try {
JSONObject jObject = new JSONObject(body); jObject = new JSONObject(body);
ExtractObjectJson(jObject, false); } catch (JSONException e) {
}catch(Exception e){ throw new RuntimeException(e);
}
} try {
} ExtractObjectJson(jObject, false);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
} }
public String getHeader(String key){ public String getHeader(String key){
if (key.equals(Constants.HttpHeader.KD_RUANGAN_A)) { if (key.equals(Constants.HttpHeader.KD_RUANGAN_A)) {
if (autoIdTujuan.length() > 0){ if (autoIdTujuan.length() > 0){
return autoIdTujuan.toString(); return autoIdTujuan.toString();
} }
} }
return super.getHeader(key); return super.getHeader(key);
} }
JSONArray autoIdTujuan = new JSONArray(); JSONArray autoIdTujuan = new JSONArray();
void ExtractObjectJson(JSONObject jObject, boolean ruangan) throws Exception {
void ExtractObjectJson(JSONObject jObject, boolean ruangan) throws Exception{ Iterator<?> iterator = jObject.keys();
Iterator iterator = jObject.keys(); while (iterator.hasNext()){
while (iterator.hasNext()){
String key = String.valueOf(iterator.next()); String key = String.valueOf(iterator.next());
Object o = jObject.get(key); Object o = jObject.get(key);
if (key.toLowerCase().contains("ruangan")){ if (key.toLowerCase().contains("ruangan")){
if (o instanceof Integer){ if (o instanceof Integer){
autoIdTujuan.put(o); autoIdTujuan.put(o);
@ -118,47 +84,47 @@ public class CORSFilter implements Filter {
} }
@Override @Override
public ServletInputStream getInputStream() throws IOException { public ServletInputStream getInputStream() {
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body.getBytes()); final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body.getBytes());
ServletInputStream servletInputStream = new ServletInputStream() { return new ServletInputStream() {
public int read() throws IOException { public int read() {
return byteArrayInputStream.read(); return byteArrayInputStream.read();
} }
}; };
return servletInputStream;
} }
@Override @Override
public BufferedReader getReader() throws IOException { public BufferedReader getReader() {
return new BufferedReader(new InputStreamReader(getInputStream())); return new BufferedReader(new InputStreamReader(getInputStream()));
} }
public String getBody() {
return this.body;
}
} }
// End Syamsu
private static StringBuilder getStringBuilder(HttpServletRequest request) throws IOException {
private final Logger log = LoggerFactory.getLogger(CORSFilter.class); StringBuilder stringBuilder = new StringBuilder();
BufferedReader reader = null;
public CORSFilter() { try {
log.info("CORSFilter JasaMedika Web init"); InputStream inputStream = request.getInputStream();
if (inputStream != null) {
reader = new BufferedReader(new InputStreamReader(inputStream));
String hasil;
while ( (hasil = reader.readLine()) != null) {
stringBuilder.append(hasil);
}
}
} finally {
if (reader != null)
reader.close();
}
return stringBuilder;
} }
@Override @Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException { throws IOException, ServletException {
RequestWrapper myReq = new RequestWrapper(req);
// Start Syamsu HttpServletResponse response = (HttpServletResponse) res;
RequestWrapper myReq = new RequestWrapper((HttpServletRequest) req); response.setHeader("Access-Control-Allow-Origin", myReq.getHeader("Origin"));
// End Syamsu
HttpServletRequest request = (HttpServletRequest) myReq;
HttpServletResponse response = (HttpServletResponse) res;
response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", response.setHeader("Access-Control-Allow-Headers",
@ -166,19 +132,11 @@ public class CORSFilter implements Filter {
+ "Supervising, RequestSupervisor, Module, Form, Action, AlamatUrlForm, KdRuangan, KdUser, " + "Supervising, RequestSupervisor, Module, Form, Action, AlamatUrlForm, KdRuangan, KdUser, "
+ "MandatoriData, idRuanganTujuan, ruanganTujuan"); + "MandatoriData, idRuanganTujuan, ruanganTujuan");
response.setHeader("Content-Type", "application/json"); response.setHeader("Content-Type", "application/json");
// String body = myReq.getBody();
// if (!"".equals(body.trim())){
// log.info("\n\n" + myReq.getBody() + "\n");
// }
chain.doFilter(myReq, res); chain.doFilter(myReq, res);
} }
@Override @Override
public void init(FilterConfig filterConfig) { public void init(FilterConfig filterConfig) {
} }
@Override @Override

View File

@ -1,8 +1,12 @@
package com.jasamedika.medifirst2000.filter; package com.jasamedika.medifirst2000.filter;
import com.fasterxml.jackson.core.JsonParseException;
import com.jasamedika.medifirst2000.constants.Constants;
import com.jasamedika.medifirst2000.security.service.TokenAuthenticationService;
import io.jsonwebtoken.MalformedJwtException; import io.jsonwebtoken.MalformedJwtException;
import org.springframework.security.core.Authentication;
import java.io.IOException; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.filter.GenericFilterBean;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -10,14 +14,7 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.filter.GenericFilterBean;
import com.fasterxml.jackson.core.JsonParseException;
import com.jasamedika.medifirst2000.constants.Constants;
import com.jasamedika.medifirst2000.security.service.TokenAuthenticationService;
/** /**
* StatelessAuthenticationFilter class * StatelessAuthenticationFilter class
@ -37,11 +34,9 @@ public class StatelessAuthenticationFilter extends GenericFilterBean {
HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletRequest req = (HttpServletRequest) request; HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response; HttpServletResponse res = (HttpServletResponse) response;
res.setHeader("Access-Control-Allow-Origin", res.setHeader("Access-Control-Allow-Origin",
req.getHeader("Origin")); req.getHeader("Origin"));
res.setHeader("Access-Control-Allow-Credentials", "true"); res.setHeader("Access-Control-Allow-Credentials", "true");
res.setHeader("Access-Control-Allow-Methods", res.setHeader("Access-Control-Allow-Methods",
"POST, GET, OPTIONS, DELETE"); "POST, GET, OPTIONS, DELETE");
res.setHeader("Access-Control-Max-Age", "3600"); res.setHeader("Access-Control-Max-Age", "3600");
@ -49,10 +44,8 @@ public class StatelessAuthenticationFilter extends GenericFilterBean {
"Content-Type, Accept, X-Requested-With, remember-me, X-AUTH-TOKEN, Supervising, " "Content-Type, Accept, X-Requested-With, remember-me, X-AUTH-TOKEN, Supervising, "
+ "RequestSupervisor, Module, Form, Action, AlamatUrlForm, KdRuangan, KdUser, " + "RequestSupervisor, Module, Form, Action, AlamatUrlForm, KdRuangan, KdUser, "
+ "MandatoriData"); + "MandatoriData");
Authentication authentication = null; Authentication authentication = null;
try { try {
authentication = authenticationService.getAuthentication(httpRequest); authentication = authenticationService.getAuthentication(httpRequest);
} catch (JsonParseException | MalformedJwtException e) { } catch (JsonParseException | MalformedJwtException e) {
HttpServletResponse httpResponse = (HttpServletResponse) response; HttpServletResponse httpResponse = (HttpServletResponse) response;
@ -64,4 +57,5 @@ public class StatelessAuthenticationFilter extends GenericFilterBean {
filterChain.doFilter(request, response); filterChain.doFilter(request, response);
SecurityContextHolder.getContext().setAuthentication(null); SecurityContextHolder.getContext().setAuthentication(null);
} }
} }

View File

@ -1,8 +1,7 @@
package com.jasamedika.medifirst2000.handler; package com.jasamedika.medifirst2000.handler;
import java.util.List; import com.jasamedika.medifirst2000.base.vo.validation.ValidationErrorVO;
import java.util.Locale; import com.jasamedika.medifirst2000.constants.Constants;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -18,8 +17,10 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import com.jasamedika.medifirst2000.base.vo.validation.ValidationErrorVO; import java.util.List;
import com.jasamedika.medifirst2000.constants.Constants;; import java.util.Locale;
/** /**
* Exception Handler Rest Controller class * Exception Handler Rest Controller class
* *
@ -27,13 +28,12 @@ import com.jasamedika.medifirst2000.constants.Constants;;
*/ */
@ControllerAdvice @ControllerAdvice
@Order(1) // Pertama masuk @Order(1)
public class RestErrorHandler { public class RestErrorHandler {
private static final Logger LOGGER = LoggerFactory private static final Logger LOGGER = LoggerFactory.getLogger(RestErrorHandler.class);
.getLogger(RestErrorHandler.class);
private MessageSource messageSource; private final MessageSource messageSource;
@Autowired @Autowired
public RestErrorHandler(MessageSource validationNessageSource) { public RestErrorHandler(MessageSource validationNessageSource) {
@ -48,57 +48,37 @@ public class RestErrorHandler {
LOGGER.warn("Handling data validation error"); LOGGER.warn("Handling data validation error");
BindingResult result = ex.getBindingResult(); BindingResult result = ex.getBindingResult();
List<FieldError> fieldErrors = result.getFieldErrors(); List<FieldError> fieldErrors = result.getFieldErrors();
return processFieldErrors(fieldErrors); return processFieldErrors(fieldErrors);
} }
private ValidationErrorVO processFieldErrors(List<FieldError> fieldErrors) { private ValidationErrorVO processFieldErrors(List<FieldError> fieldErrors) {
ValidationErrorVO dto = new ValidationErrorVO(); ValidationErrorVO dto = new ValidationErrorVO();
for (FieldError fieldError : fieldErrors) { for (FieldError fieldError : fieldErrors) {
String localizedErrorMessage = resolveLocalizedErrorMessage(fieldError); String localizedErrorMessage = resolveLocalizedErrorMessage(fieldError);
dto.addFieldError(fieldError.getField(), localizedErrorMessage); dto.addFieldError(fieldError.getField(), localizedErrorMessage);
} }
return dto; return dto;
} }
/*
* resolve error message with parameter locale
*/
private String resolveLocalizedErrorMessage(FieldError fieldError, String locale) { private String resolveLocalizedErrorMessage(FieldError fieldError, String locale) {
Locale currentLocale = LocaleContextHolder.getLocale(); Locale currentLocale = LocaleContextHolder.getLocale();
String localizedErrorMessage = messageSource.getMessage(fieldError, String localizedErrorMessage = messageSource.getMessage(fieldError,
currentLocale); currentLocale);
// If the message was not found, return the most accurate field error
// code instead.
// You can remove this check if you prefer to get the default error
// message.
if (localizedErrorMessage.equals(fieldError.getDefaultMessage())) { if (localizedErrorMessage.equals(fieldError.getDefaultMessage())) {
String[] fieldErrorCodes = fieldError.getCodes(); String[] fieldErrorCodes = fieldError.getCodes();
localizedErrorMessage = fieldErrorCodes[0]; localizedErrorMessage = fieldErrorCodes[0];
} }
return localizedErrorMessage; return localizedErrorMessage;
} }
/*
* resolve error message with default locale
*/
private String resolveLocalizedErrorMessage(FieldError fieldError) { private String resolveLocalizedErrorMessage(FieldError fieldError) {
String localizedErrorMessage = messageSource.getMessage(fieldError, String localizedErrorMessage = messageSource.getMessage(fieldError,
new Locale(Constants.Locale.INA)); new Locale(Constants.Locale.INA));
// If the message was not found, return the most accurate field error
// code instead.
// You can remove this check if you prefer to get the default error
// message.
if (localizedErrorMessage.equals(fieldError.getDefaultMessage())) { if (localizedErrorMessage.equals(fieldError.getDefaultMessage())) {
String[] fieldErrorCodes = fieldError.getCodes(); String[] fieldErrorCodes = fieldError.getCodes();
localizedErrorMessage = fieldErrorCodes[0]; localizedErrorMessage = fieldErrorCodes[0];
} }
return localizedErrorMessage; return localizedErrorMessage;
} }
} }

View File

@ -364,4 +364,5 @@ public class AppInterceptor implements HandlerInterceptor {
} }
} }
} }
} }

View File

@ -1,18 +1,16 @@
package com.jasamedika.medifirst2000.security; package com.jasamedika.medifirst2000.security;
import java.io.IOException; import com.jasamedika.medifirst2000.constants.Constants;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.jasamedika.medifirst2000.constants.Constants; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/** /**
* RestAuthenticationEntryPoint class * RestAuthenticationEntryPoint class
@ -25,19 +23,14 @@ public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint {
private static final Logger LOGGER = LoggerFactory.getLogger(RestAuthenticationEntryPoint.class); private static final Logger LOGGER = LoggerFactory.getLogger(RestAuthenticationEntryPoint.class);
/// Alter Syamsu
@Override @Override
public void commence(HttpServletRequest request, public void commence(HttpServletRequest request,
HttpServletResponse response, AuthenticationException ae) HttpServletResponse response, AuthenticationException ae)
throws IOException, ServletException { throws IOException, ServletException {
LOGGER.error("Mencoba akses tanpa login"); LOGGER.error("Mencoba akses tanpa login");
response.getWriter().write("{" + Constants.MessageInfo.ERROR_MESSAGE + ":'Please login to get access'}"); response.getWriter().write("{" + Constants.MessageInfo.ERROR_MESSAGE + ":'Please login to get access'}");
response.setHeader(Constants.MessageInfo.ERROR_MESSAGE, "Please login to get access"); response.setHeader(Constants.MessageInfo.ERROR_MESSAGE, "Please login to get access");
response.setStatus(HttpServletResponse.SC_FORBIDDEN); response.setStatus(HttpServletResponse.SC_FORBIDDEN);
//response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
} }
} }

View File

@ -4,7 +4,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@ -45,9 +44,7 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
http.exceptionHandling() http.exceptionHandling()
//restAuthenticationEntryPoint
.authenticationEntryPoint(restAuthenticationEntryPoint) .authenticationEntryPoint(restAuthenticationEntryPoint)
.and() .and()
.anonymous() .anonymous()
.and() .and()
@ -57,9 +54,6 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
.cacheControl() .cacheControl()
.and() .and()
.authorizeRequests() .authorizeRequests()
// Allow anonymous resource requests
.antMatchers("/favicon.ico") .antMatchers("/favicon.ico")
.permitAll() .permitAll()
.antMatchers("**/*.html") .antMatchers("**/*.html")
@ -68,44 +62,23 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
.permitAll() .permitAll()
.antMatchers("**/*.js") .antMatchers("**/*.js")
.permitAll() .permitAll()
// Allow anonymous logins
.antMatchers("/auth/**") .antMatchers("/auth/**")
.permitAll() .permitAll()
// Allow SMS gateway
.antMatchers("/registrasi-pasien-sms/**") .antMatchers("/registrasi-pasien-sms/**")
.permitAll() .permitAll()
// Allow SMS gateway
.antMatchers("/report/**") .antMatchers("/report/**")
.permitAll() .permitAll()
// URL tanpa auth deklarasikan di sini
.antMatchers("/test-tanpa-auth/**") .antMatchers("/test-tanpa-auth/**")
.permitAll() .permitAll()
.antMatchers("/test/**") .antMatchers("/test/**")
.permitAll() .permitAll()
.antMatchers("/api-docs.json") .antMatchers("/api-docs.json")
.permitAll() .permitAll()
.antMatchers("/api-docs/**") .antMatchers("/api-docs/**")
.permitAll() .permitAll()
/*//Allow Download File Surat Masuk
.antMatchers("/surat-masuk/download-dokumen-template/**")
.permitAll()
.antMatchers("/surat-masuk/get-draft-surat/**")
.permitAll()*/
// All other request need to be authenticated
.anyRequest() .anyRequest()
.authenticated() .authenticated()
.and() .and()
// Custom Token based authentication based on the header
// previously given to the client
.addFilterBefore( .addFilterBefore(
new StatelessAuthenticationFilter( new StatelessAuthenticationFilter(
tokenAuthenticationService), tokenAuthenticationService),
@ -136,10 +109,4 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
return tokenAuthenticationService; return tokenAuthenticationService;
} }
// @Bean(name = "springSecurityFilterChain", autowire = Autowire.BY_NAME)
// public DelegatingFilterProxy springSecurityFilterChain(){
// return new DelegatingFilterProxy();
// }
} }

View File

@ -9,32 +9,34 @@ import com.jasamedika.medifirst2000.security.service.UserService;
/** /**
* TokenHandler class * TokenHandler class
* using jjwt https://github.com/jwtk/jjwt * using <a href="https://github.com/jwtk/jjwt">jjwt</a>
* *
* @author Roberto * @author Roberto
*/ */
public class TokenHandler { public class TokenHandler {
private final String secret;
private final UserService userService;
public TokenHandler(String secret, UserService userService) { private final String secret;
this.secret = secret; private final UserService userService;
this.userService = userService;
}
public User parseUserFromToken(String token) { public TokenHandler(String secret, UserService userService) {
String username = Jwts.parser() this.secret = secret;
.setSigningKey(secret) this.userService = userService;
.parseClaimsJws(token) }
.getBody()
.getSubject(); public User parseUserFromToken(String token) {
return userService.loadUserByUsername(username); String username = Jwts.parser()
} .setSigningKey(secret)
.parseClaimsJws(token)
.getBody()
.getSubject();
return userService.loadUserByUsername(username);
}
public String createTokenForUser(User user) {
return Jwts.builder().setHeaderParam("typ", "JWT")
.setSubject(user.getUsername())
.signWith(SignatureAlgorithm.HS512, secret)
.compact();
}
public String createTokenForUser(User user) {
return Jwts.builder().setHeaderParam("typ", "JWT")
.setSubject(user.getUsername())
.signWith(SignatureAlgorithm.HS512, secret)
.compact();
}
} }

View File

@ -13,13 +13,11 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
public @interface AppPermission { public @interface AppPermission {
public static final int ADD = 100; int ADD = 100;
public static final int UPDATE = 200; int UPDATE = 200;
public static final int DELETE = 300; int DELETE = 300;
public static final int PRINT = 400; int PRINT = 400;
public static final int VIEW = 500; int VIEW = 500;
int SPECIALS = 600;
public static final int SPECIALS = 600;
int value(); int value();
} }

View File

@ -1,20 +1,18 @@
package com.jasamedika.medifirst2000.security.model; package com.jasamedika.medifirst2000.security.model;
import java.util.Collection;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.User;
import java.util.Collection;
/** /**
* UserAuthentication class * UserAuthentication class
* *
* @author Roberto * @author Roberto
*/ */
public class UserAuthentication implements Authentication { public class UserAuthentication implements Authentication {
/**
* serialVersionUID
*/
private static final long serialVersionUID = -7410905698525654537L; private static final long serialVersionUID = -7410905698525654537L;
private final User user; private final User user;
private boolean authenticated = true; private boolean authenticated = true;
@ -57,4 +55,5 @@ public class UserAuthentication implements Authentication {
public void setAuthenticated(boolean authenticated) { public void setAuthenticated(boolean authenticated) {
this.authenticated = authenticated; this.authenticated = authenticated;
} }
} }

View File

@ -1,16 +1,15 @@
package com.jasamedika.medifirst2000.security.service; package com.jasamedika.medifirst2000.security.service;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParseException;
import com.jasamedika.medifirst2000.core.web.WebConstants; import com.jasamedika.medifirst2000.core.web.WebConstants;
import com.jasamedika.medifirst2000.security.handler.TokenHandler; import com.jasamedika.medifirst2000.security.handler.TokenHandler;
import com.jasamedika.medifirst2000.security.model.UserAuthentication; import com.jasamedika.medifirst2000.security.model.UserAuthentication;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.util.Objects;
/** /**
* TokenAuthenticationService class * TokenAuthenticationService class
@ -29,43 +28,30 @@ public class TokenAuthenticationService {
tokenHandler = new TokenHandler(secret, userService); tokenHandler = new TokenHandler(secret, userService);
} }
public String addAuthentication(HttpServletResponse response, public String addAuthentication(UserAuthentication authentication) {
UserAuthentication authentication) {
final User user = authentication.getDetails(); final User user = authentication.getDetails();
return tokenHandler.createTokenForUser(user); return tokenHandler.createTokenForUser(user);
} }
public Authentication getAuthentication(HttpServletRequest request) public Authentication getAuthentication(HttpServletRequest request)
throws JsonParseException { throws JsonParseException {
String token = request.getHeader(WebConstants.AUTH_HEADER_NAME); String token = request.getHeader(WebConstants.AUTH_HEADER_NAME);
if (token != null) { if (token != null) {
final User user = tokenHandler.parseUserFromToken(token); final User user = tokenHandler.parseUserFromToken(token);
if (user != null) { if (user != null)
return new UserAuthentication(user); return new UserAuthentication(user);
} } else {
} if(Objects.equals(request.getQueryString(), ""))return null;
else{ final String[] tokens= request.getQueryString().split("&");
try for (String tokenTemp : tokens) {
{ if(tokenTemp.toLowerCase().contains(WebConstants.AUTH_HEADER_NAME.toLowerCase())) {
if(request.getQueryString()=="")return null; token =tokenTemp.split("=")[1];
final String[] tokens= request.getQueryString().split("&"); final User user = tokenHandler.parseUserFromToken(token);
for (String tokenTemp : tokens) { if (user != null) {
if(tokenTemp.toLowerCase().indexOf(WebConstants.AUTH_HEADER_NAME.toLowerCase())>=0) return new UserAuthentication(user);
{
token =tokenTemp.split("=")[1];
final User user = tokenHandler.parseUserFromToken(token);
if (user != null) {
return new UserAuthentication(user);
}
} }
} }
} }
catch(Exception e)
{
}
} }
return null; return null;
} }

View File

@ -1,19 +1,18 @@
package com.jasamedika.medifirst2000.security.service; package com.jasamedika.medifirst2000.security.service;
import java.util.Arrays; import com.jasamedika.medifirst2000.dao.LoginUserDao;
import java.util.List; import com.jasamedika.medifirst2000.entities.LoginUser;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AccountStatusUserDetailsChecker; import org.springframework.security.authentication.AccountStatusUserDetailsChecker;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.jasamedika.medifirst2000.dao.LoginUserDao; import java.util.Collections;
import com.jasamedika.medifirst2000.entities.LoginUser; import java.util.List;
/** /**
* UserService implements * UserService implements
@ -22,8 +21,7 @@ import com.jasamedika.medifirst2000.entities.LoginUser;
* @author Roberto * @author Roberto
*/ */
@Component @Component
public class UserService implements public class UserService implements UserDetailsService {
org.springframework.security.core.userdetails.UserDetailsService {
@Autowired @Autowired
private LoginUserDao loginUserDao; private LoginUserDao loginUserDao;
@ -34,28 +32,18 @@ public class UserService implements
super(); super();
} }
/**
* this method is called for rest authentication from client
*
* @author Roberto
*/
@Override @Override
public final User loadUserByUsername(String username) public final User loadUserByUsername(String username) throws UsernameNotFoundException {
throws UsernameNotFoundException {
List<LoginUser> loginUsers = loginUserDao.findByNamaUser(username); List<LoginUser> loginUsers = loginUserDao.findByNamaUser(username);
if (loginUsers.isEmpty()) { if (loginUsers.isEmpty())
throw new UsernameNotFoundException("user not found"); throw new UsernameNotFoundException("user not found");
}
LoginUser loginUser = loginUsers.get(0); LoginUser loginUser = loginUsers.get(0);
//validasi tambahan lakukan di sini
// GrantedAuthority authority = new SimpleGrantedAuthority(loginUser
// .getKelompokUser().getKelompokUser());
GrantedAuthority authority = new SimpleGrantedAuthority("USER"); GrantedAuthority authority = new SimpleGrantedAuthority("USER");
UserDetails userDetails = (UserDetails) new User( User userDetails = new User(
loginUser.getNamaUser(), loginUser.getKataSandi(), loginUser.getNamaUser(), loginUser.getKataSandi(),
Arrays.asList(authority)); Collections.singletonList(authority));
detailsChecker.check(userDetails); detailsChecker.check(userDetails);
return (User) userDetails; return userDetails;
} }
} }

View File

@ -9,21 +9,18 @@ import com.fasterxml.jackson.databind.SerializationFeature;
@Component @Component
public class JacksonConfiguration { public class JacksonConfiguration {
private ObjectMapper mapper;
public JacksonConfiguration() { public JacksonConfiguration() {
} }
public JacksonConfiguration(ObjectMapper mapper) { public JacksonConfiguration(ObjectMapper mapper) {
this.mapper = mapper; configureJackson(mapper);
configureJackson(mapper);
} }
public static ObjectMapper configureJackson(ObjectMapper mapper) { public static void configureJackson(ObjectMapper mapper) {
mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.setSerializationInclusion(Include.NON_NULL); mapper.setSerializationInclusion(Include.NON_NULL);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
false); false);
return mapper;
} }
} }