Update controller
Clean code
This commit is contained in:
parent
c3ee97b3d2
commit
f5faf50737
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
|
|
||||||
|
|||||||
@ -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,10 +29,9 @@ 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,
|
||||||
|
|||||||
@ -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;
|
||||||
@ -190,12 +183,12 @@ public abstract class LocaleController<V extends BaseModelVO> {
|
|||||||
return RestUtil.getJsonResponse(null, HttpStatus.BAD_REQUEST, mapHeaderMessage);
|
return RestUtil.getJsonResponse(null, HttpStatus.BAD_REQUEST, mapHeaderMessage);
|
||||||
} else {
|
} else {
|
||||||
Collection<V> vos = (Collection<V>) map.get(WebConstants.PageParameter.LIST_DATA);
|
Collection<V> vos = (Collection<V>) map.get(WebConstants.PageParameter.LIST_DATA);
|
||||||
Map<String, String> mapHeaderMessage = new HashMap<>();
|
Map<String, String> mapHeaderMessage = new HashMap<>();
|
||||||
mapHeaderMessage.put(WebConstants.HttpHeaderInfo.TOTAL_PAGE_HEADER,
|
mapHeaderMessage.put(WebConstants.HttpHeaderInfo.TOTAL_PAGE_HEADER,
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,39 +1,33 @@
|
|||||||
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,
|
|
||||||
@RequestParam(value = "excludes", required = false) String excludes) {
|
@RequestParam(value = "excludes", required = false) String excludes) {
|
||||||
List<T> listVO = getAllVOFromService();
|
List<T> listVO = getAllVOFromService();
|
||||||
String[] arrExcludes = null;
|
String[] arrExcludes = null;
|
||||||
@ -44,35 +38,27 @@ public abstract class ParamRestController<T extends BaseModelVO> {
|
|||||||
arrIncludes = includes.split(Constants.COMMA);
|
arrIncludes = includes.split(Constants.COMMA);
|
||||||
if (arrExcludes != null && arrIncludes != null) {
|
if (arrExcludes != null && arrIncludes != null) {
|
||||||
listVO = jsonResult.use(
|
listVO = jsonResult.use(
|
||||||
JsonView.with(listVO).onClass(
|
JsonView.with(listVO).onClass(getClazz(), Match.match().exclude(arrExcludes).include(arrIncludes)))
|
||||||
getClazz(),
|
.returnValue();
|
||||||
Match.match().exclude(arrExcludes)
|
|
||||||
.include(arrIncludes))).returnValue();
|
|
||||||
}
|
}
|
||||||
if (arrExcludes != null && arrIncludes == null) {
|
if (arrExcludes != null && arrIncludes == null) {
|
||||||
listVO = jsonResult.use(
|
listVO = jsonResult
|
||||||
JsonView.with(listVO).onClass(getClazz(),
|
.use(JsonView.with(listVO).onClass(getClazz(), Match.match().include("*").exclude(arrExcludes)))
|
||||||
Match.match().include("*").exclude(arrExcludes)))
|
|
||||||
.returnValue();
|
.returnValue();
|
||||||
}
|
}
|
||||||
if (arrExcludes == null && arrIncludes != null) {
|
if (arrExcludes == null && arrIncludes != null) {
|
||||||
listVO = jsonResult.use(
|
listVO = jsonResult
|
||||||
JsonView.with(listVO).onClass(getClazz(),
|
.use(JsonView.with(listVO).onClass(getClazz(), Match.match().exclude("*").include(arrIncludes)))
|
||||||
Match.match().exclude("*").include(arrIncludes)))
|
|
||||||
.returnValue();
|
.returnValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
return RestUtil.getJsonResponse(listVO, HttpStatus.OK);
|
return RestUtil.getJsonResponse(listVO, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected Class<T> getClazz() {
|
protected Class<T> getClazz() {
|
||||||
return (Class<T>) GenericTypeResolver.resolveTypeArgument(getClass(),
|
return (Class<T>) GenericTypeResolver.resolveTypeArgument(getClass(), ParamRestController.class);
|
||||||
ParamRestController.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* method untuk mendapatkan all VO from service
|
|
||||||
* */
|
|
||||||
protected abstract List<T> getAllVOFromService();
|
protected abstract List<T> getAllVOFromService();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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,10 +28,9 @@ 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);
|
||||||
|
|||||||
@ -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
|
||||||
@ -33,132 +22,113 @@ 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;
|
String idRuanganTujuan = request.getHeader(Constants.HttpHeader.KD_RUANGAN_T) == null ? ""
|
||||||
try {
|
: request.getHeader(Constants.HttpHeader.KD_RUANGAN_T);
|
||||||
InputStream inputStream = request.getInputStream();
|
if (idRuanganTujuan.trim().isEmpty()) {
|
||||||
if (inputStream != null) {
|
JSONObject jObject;
|
||||||
reader = new BufferedReader(new InputStreamReader(inputStream));
|
try {
|
||||||
String hasil;
|
jObject = new JSONObject(body);
|
||||||
while ( (hasil = reader.readLine()) != null) {
|
} catch (JSONException e) {
|
||||||
stringBuilder.append(hasil);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
} else {
|
try {
|
||||||
stringBuilder.append("");
|
ExtractObjectJson(jObject, false);
|
||||||
}
|
} catch (Exception e) {
|
||||||
} catch (IOException ex) {
|
throw new RuntimeException(e);
|
||||||
throw ex;
|
}
|
||||||
} finally {
|
}
|
||||||
if (reader != null) {
|
}
|
||||||
try {
|
|
||||||
reader.close();
|
public String getHeader(String key) {
|
||||||
} catch (IOException ex) {
|
if (key.equals(Constants.HttpHeader.KD_RUANGAN_A)) {
|
||||||
throw ex;
|
if (autoIdTujuan.length() > 0) {
|
||||||
}
|
return autoIdTujuan.toString();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
body = stringBuilder.toString();
|
|
||||||
|
|
||||||
String idRuanganTujuan = request.getHeader(Constants.HttpHeader.KD_RUANGAN_T) == null ? ""
|
|
||||||
: request.getHeader(Constants.HttpHeader.KD_RUANGAN_T);
|
|
||||||
|
|
||||||
if ("".equals(idRuanganTujuan.trim())){
|
|
||||||
try{
|
|
||||||
JSONObject jObject = new JSONObject(body);
|
|
||||||
ExtractObjectJson(jObject, false);
|
|
||||||
}catch(Exception e){
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHeader(String key){
|
|
||||||
if (key.equals(Constants.HttpHeader.KD_RUANGAN_A)) {
|
|
||||||
if (autoIdTujuan.length() > 0){
|
|
||||||
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);
|
} else if (o instanceof JSONObject) {
|
||||||
} else if (o instanceof JSONObject){
|
ExtractObjectJson((JSONObject) o, true);
|
||||||
ExtractObjectJson((JSONObject) o, true);
|
}
|
||||||
}
|
} else if (ruangan && "id".equals(key)) {
|
||||||
} else if (ruangan && "id".equals(key)){
|
if (o instanceof Integer) {
|
||||||
if (o instanceof Integer){
|
autoIdTujuan.put(o);
|
||||||
autoIdTujuan.put(o);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
} else if (o instanceof JSONObject && !ruangan) {
|
||||||
} else if (o instanceof JSONObject && !ruangan) {
|
ExtractObjectJson((JSONObject) o, false);
|
||||||
ExtractObjectJson((JSONObject) o, false);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@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 final Logger log = LoggerFactory.getLogger(CORSFilter.class);
|
private static StringBuilder getStringBuilder(HttpServletRequest request) throws IOException {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
public CORSFilter() {
|
BufferedReader reader = null;
|
||||||
log.info("CORSFilter JasaMedika Web init");
|
try {
|
||||||
|
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
|
|
||||||
RequestWrapper myReq = new RequestWrapper((HttpServletRequest) req);
|
|
||||||
// End Syamsu
|
|
||||||
HttpServletRequest request = (HttpServletRequest) myReq;
|
|
||||||
HttpServletResponse response = (HttpServletResponse) res;
|
HttpServletResponse response = (HttpServletResponse) res;
|
||||||
|
response.setHeader("Access-Control-Allow-Origin", myReq.getHeader("Origin"));
|
||||||
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 +136,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
|
||||||
|
|||||||
@ -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
|
||||||
@ -27,41 +24,34 @@ import com.jasamedika.medifirst2000.security.service.TokenAuthenticationService;
|
|||||||
public class StatelessAuthenticationFilter extends GenericFilterBean {
|
public class StatelessAuthenticationFilter extends GenericFilterBean {
|
||||||
private final TokenAuthenticationService authenticationService;
|
private final TokenAuthenticationService authenticationService;
|
||||||
|
|
||||||
public StatelessAuthenticationFilter(
|
public StatelessAuthenticationFilter(TokenAuthenticationService authenticationService) {
|
||||||
TokenAuthenticationService authenticationService) {
|
|
||||||
this.authenticationService = authenticationService;
|
this.authenticationService = authenticationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doFilter(ServletRequest request, ServletResponse response,
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
|
||||||
FilterChain filterChain) throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
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", req.getHeader("Origin"));
|
||||||
res.setHeader("Access-Control-Allow-Origin",
|
|
||||||
req.getHeader("Origin"));
|
|
||||||
res.setHeader("Access-Control-Allow-Credentials", "true");
|
res.setHeader("Access-Control-Allow-Credentials", "true");
|
||||||
|
res.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
|
||||||
res.setHeader("Access-Control-Allow-Methods",
|
|
||||||
"POST, GET, OPTIONS, DELETE");
|
|
||||||
res.setHeader("Access-Control-Max-Age", "3600");
|
res.setHeader("Access-Control-Max-Age", "3600");
|
||||||
res.setHeader("Access-Control-Allow-Headers",
|
res.setHeader("Access-Control-Allow-Headers",
|
||||||
"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;
|
||||||
httpResponse.addHeader(Constants.MessageInfo.ERROR_MESSAGE,
|
httpResponse.addHeader(Constants.MessageInfo.ERROR_MESSAGE, "Error Token (Not Valid Token)");
|
||||||
"Error Token (Not Valid Token)");
|
|
||||||
filterChain.doFilter(request, response);
|
filterChain.doFilter(request, response);
|
||||||
}
|
}
|
||||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||||
filterChain.doFilter(request, response);
|
filterChain.doFilter(request, response);
|
||||||
SecurityContextHolder.getContext().setAuthentication(null);
|
SecurityContextHolder.getContext().setAuthentication(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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,9 @@ 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 +27,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) {
|
||||||
@ -43,62 +42,39 @@ public class RestErrorHandler {
|
|||||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ValidationErrorVO processValidationError(
|
public ValidationErrorVO processValidationError(MethodArgumentNotValidException ex) {
|
||||||
MethodArgumentNotValidException ex) {
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -364,4 +364,5 @@ public class AppInterceptor implements HandlerInterceptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,43 +1,35 @@
|
|||||||
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 set Unauthorized response from
|
||||||
* set Unauthorized response from "Unauthorized client"
|
* "Unauthorized client"
|
||||||
*
|
*
|
||||||
* @author Roberto
|
* @author Roberto
|
||||||
*/
|
*/
|
||||||
@Component("RestAuthenticationEntryPoint")
|
@Component("RestAuthenticationEntryPoint")
|
||||||
public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(RestAuthenticationEntryPoint.class);
|
|
||||||
|
|
||||||
|
|
||||||
/// Alter Syamsu
|
private static final Logger LOGGER = LoggerFactory.getLogger(RestAuthenticationEntryPoint.class);
|
||||||
|
|
||||||
@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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -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;
|
||||||
@ -19,8 +18,8 @@ import com.jasamedika.medifirst2000.security.service.TokenAuthenticationService;
|
|||||||
import com.jasamedika.medifirst2000.security.service.UserService;
|
import com.jasamedika.medifirst2000.security.service.UserService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SpringSecurityConfig class
|
* SpringSecurityConfig class Di sini Kita tidak menggunakan XML Config untuk
|
||||||
* Di sini Kita tidak menggunakan XML Config untuk Spring Security
|
* Spring Security
|
||||||
*
|
*
|
||||||
* @author Roberto
|
* @author Roberto
|
||||||
*/
|
*/
|
||||||
@ -31,92 +30,32 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RestAuthenticationEntryPoint restAuthenticationEntryPoint;
|
private RestAuthenticationEntryPoint restAuthenticationEntryPoint;
|
||||||
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final TokenAuthenticationService tokenAuthenticationService;
|
private final TokenAuthenticationService tokenAuthenticationService;
|
||||||
|
|
||||||
public SpringSecurityConfig() {
|
public SpringSecurityConfig() {
|
||||||
super(true);
|
super(true);
|
||||||
this.userService = new UserService();
|
this.userService = new UserService();
|
||||||
tokenAuthenticationService = new TokenAuthenticationService(
|
tokenAuthenticationService = new TokenAuthenticationService(Constants.JASAMEDIKA, userService);
|
||||||
Constants.JASAMEDIKA, userService);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
http.exceptionHandling()
|
http.exceptionHandling().authenticationEntryPoint(restAuthenticationEntryPoint).and().anonymous().and()
|
||||||
//restAuthenticationEntryPoint
|
.servletApi().and().headers().cacheControl().and().authorizeRequests().antMatchers("/favicon.ico")
|
||||||
.authenticationEntryPoint(restAuthenticationEntryPoint)
|
.permitAll().antMatchers("**/*.html").permitAll().antMatchers("**/*.css").permitAll()
|
||||||
|
.antMatchers("**/*.js").permitAll().antMatchers("/auth/**").permitAll()
|
||||||
.and()
|
.antMatchers("/registrasi-pasien-sms/**").permitAll().antMatchers("/report/**").permitAll()
|
||||||
.anonymous()
|
.antMatchers("/test-tanpa-auth/**").permitAll().antMatchers("/test/**").permitAll()
|
||||||
.and()
|
.antMatchers("/api-docs.json").permitAll().antMatchers("/api-docs/**").permitAll().anyRequest()
|
||||||
.servletApi()
|
.authenticated().and().addFilterBefore(new StatelessAuthenticationFilter(tokenAuthenticationService),
|
||||||
.and()
|
|
||||||
.headers()
|
|
||||||
.cacheControl()
|
|
||||||
.and()
|
|
||||||
.authorizeRequests()
|
|
||||||
|
|
||||||
|
|
||||||
// Allow anonymous resource requests
|
|
||||||
.antMatchers("/favicon.ico")
|
|
||||||
.permitAll()
|
|
||||||
.antMatchers("**/*.html")
|
|
||||||
.permitAll()
|
|
||||||
.antMatchers("**/*.css")
|
|
||||||
.permitAll()
|
|
||||||
.antMatchers("**/*.js")
|
|
||||||
.permitAll()
|
|
||||||
|
|
||||||
// Allow anonymous logins
|
|
||||||
.antMatchers("/auth/**")
|
|
||||||
.permitAll()
|
|
||||||
|
|
||||||
// Allow SMS gateway
|
|
||||||
.antMatchers("/registrasi-pasien-sms/**")
|
|
||||||
.permitAll()
|
|
||||||
|
|
||||||
// Allow SMS gateway
|
|
||||||
.antMatchers("/report/**")
|
|
||||||
.permitAll()
|
|
||||||
|
|
||||||
// URL tanpa auth deklarasikan di sini
|
|
||||||
.antMatchers("/test-tanpa-auth/**")
|
|
||||||
.permitAll()
|
|
||||||
.antMatchers("/test/**")
|
|
||||||
.permitAll()
|
|
||||||
|
|
||||||
.antMatchers("/api-docs.json")
|
|
||||||
.permitAll()
|
|
||||||
|
|
||||||
.antMatchers("/api-docs/**")
|
|
||||||
.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()
|
|
||||||
.authenticated()
|
|
||||||
.and()
|
|
||||||
|
|
||||||
// Custom Token based authentication based on the header
|
|
||||||
// previously given to the client
|
|
||||||
.addFilterBefore(
|
|
||||||
new StatelessAuthenticationFilter(
|
|
||||||
tokenAuthenticationService),
|
|
||||||
UsernamePasswordAuthenticationFilter.class);
|
UsernamePasswordAuthenticationFilter.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(AuthenticationManagerBuilder auth)
|
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||||
throws Exception {
|
auth.userDetailsService(userDetailsService()).passwordEncoder(new BCryptPasswordEncoder());
|
||||||
auth.userDetailsService(userDetailsService()).passwordEncoder(
|
|
||||||
new BCryptPasswordEncoder());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ -135,11 +74,5 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
public TokenAuthenticationService tokenAuthenticationService() {
|
public TokenAuthenticationService tokenAuthenticationService() {
|
||||||
return tokenAuthenticationService;
|
return tokenAuthenticationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @Bean(name = "springSecurityFilterChain", autowire = Autowire.BY_NAME)
|
|
||||||
// public DelegatingFilterProxy springSecurityFilterChain(){
|
|
||||||
// return new DelegatingFilterProxy();
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,33 +8,28 @@ import org.springframework.security.core.userdetails.User;
|
|||||||
import com.jasamedika.medifirst2000.security.service.UserService;
|
import com.jasamedika.medifirst2000.security.service.UserService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TokenHandler class
|
* TokenHandler class using <a href="https://github.com/jwtk/jjwt">jjwt</a>
|
||||||
* using jjwt https://github.com/jwtk/jjwt
|
*
|
||||||
*
|
|
||||||
* @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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,20 +6,22 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AppPermission annotation, digunakan untuk method yang butuh authorized dari database
|
* AppPermission annotation, digunakan untuk method yang butuh authorized dari
|
||||||
* can use in method only.
|
* database can use in method only.
|
||||||
|
*
|
||||||
* @author Roberto
|
* @author Roberto
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
public @interface AppPermission {
|
public @interface AppPermission {
|
||||||
public static final int ADD = 100;
|
|
||||||
public static final int UPDATE = 200;
|
int ADD = 100;
|
||||||
public static final int DELETE = 300;
|
int UPDATE = 200;
|
||||||
public static final int PRINT = 400;
|
int DELETE = 300;
|
||||||
public static final int VIEW = 500;
|
int PRINT = 400;
|
||||||
|
int VIEW = 500;
|
||||||
public static final int SPECIALS = 600;
|
int SPECIALS = 600;
|
||||||
|
|
||||||
int value();
|
int value();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
||||||
@ -20,8 +19,8 @@ import com.jasamedika.medifirst2000.security.model.UserAuthentication;
|
|||||||
@Component
|
@Component
|
||||||
public class TokenAuthenticationService {
|
public class TokenAuthenticationService {
|
||||||
|
|
||||||
public static TokenHandler tokenHandler;
|
public static TokenHandler tokenHandler;
|
||||||
|
|
||||||
public TokenAuthenticationService() {
|
public TokenAuthenticationService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,44 +28,32 @@ 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(), ""))
|
||||||
else{
|
return null;
|
||||||
try
|
final String[] tokens = request.getQueryString().split("&");
|
||||||
{
|
for (String tokenTemp : tokens) {
|
||||||
if(request.getQueryString()=="")return null;
|
if (tokenTemp.toLowerCase().contains(WebConstants.AUTH_HEADER_NAME.toLowerCase())) {
|
||||||
final String[] tokens= request.getQueryString().split("&");
|
token = tokenTemp.split("=")[1];
|
||||||
for (String tokenTemp : tokens) {
|
final User user = tokenHandler.parseUserFromToken(token);
|
||||||
if(tokenTemp.toLowerCase().indexOf(WebConstants.AUTH_HEADER_NAME.toLowerCase())>=0)
|
if (user != null) {
|
||||||
{
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,29 +1,27 @@
|
|||||||
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
|
||||||
org.springframework.security.core.userdetails.UserDetailsService
|
* org.springframework.security.core.userdetails.UserDetailsService
|
||||||
*
|
*
|
||||||
* @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,17 @@ 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(),
|
Collections.singletonList(authority));
|
||||||
Arrays.asList(authority));
|
|
||||||
detailsChecker.check(userDetails);
|
detailsChecker.check(userDetails);
|
||||||
return (User) userDetails;
|
return userDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -9,21 +9,17 @@ 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,7 +38,8 @@ public class RestUtil {
|
|||||||
/**
|
/**
|
||||||
* get JSON response from Object with HTTP status
|
* get JSON response from Object with HTTP status
|
||||||
*
|
*
|
||||||
* @param <T> source class
|
* @param <T>
|
||||||
|
* source class
|
||||||
* @return @ResponseEntity
|
* @return @ResponseEntity
|
||||||
*/
|
*/
|
||||||
public static <T> ResponseEntity<T> getJsonResponse(T src, HttpStatus status) {
|
public static <T> ResponseEntity<T> getJsonResponse(T src, HttpStatus status) {
|
||||||
@ -159,7 +160,7 @@ public class RestUtil {
|
|||||||
* string source JSON
|
* string source JSON
|
||||||
* @param type
|
* @param type
|
||||||
* class type result
|
* class type result
|
||||||
*/
|
*/
|
||||||
public static <T> T jsonToObject(String strJson, Class<T> type) {
|
public static <T> T jsonToObject(String strJson, Class<T> type) {
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
return gson.fromJson(strJson, type);
|
return gson.fromJson(strJson, type);
|
||||||
@ -168,7 +169,7 @@ public class RestUtil {
|
|||||||
/**
|
/**
|
||||||
* convert object to json
|
* convert object to json
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static String toJson(Object object) {
|
public static String toJson(Object object) {
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
return gson.toJson(object);
|
return gson.toJson(object);
|
||||||
|
|||||||
@ -2,7 +2,7 @@ package com.monitorjbl.json;
|
|||||||
|
|
||||||
public class JsonResult {
|
public class JsonResult {
|
||||||
private static final JsonResult instance = new JsonResult();
|
private static final JsonResult instance = new JsonResult();
|
||||||
private static final ThreadLocal<JsonView> current = new ThreadLocal<>();
|
private static final ThreadLocal<JsonView<?>> current = new ThreadLocal<>();
|
||||||
|
|
||||||
private JsonResult() {
|
private JsonResult() {
|
||||||
}
|
}
|
||||||
@ -16,7 +16,6 @@ public class JsonResult {
|
|||||||
* Type of object being rendered
|
* Type of object being rendered
|
||||||
* @return ResultWrapper to provide return value
|
* @return ResultWrapper to provide return value
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <E> ResultWrapper<E> use(JsonView<E> view) {
|
public <E> ResultWrapper<E> use(JsonView<E> view) {
|
||||||
current.set(view);
|
current.set(view);
|
||||||
return new ResultWrapper<>(view);
|
return new ResultWrapper<>(view);
|
||||||
@ -26,7 +25,7 @@ public class JsonResult {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JsonView get() {
|
static JsonView<?> get() {
|
||||||
return current.get();
|
return current.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +34,7 @@ public class JsonResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class ResultWrapper<T> {
|
public static class ResultWrapper<T> {
|
||||||
private JsonView<T> obj;
|
private final JsonView<T> obj;
|
||||||
|
|
||||||
private ResultWrapper(JsonView<T> obj) {
|
private ResultWrapper(JsonView<T> obj) {
|
||||||
this.obj = obj;
|
this.obj = obj;
|
||||||
|
|||||||
@ -1,18 +1,15 @@
|
|||||||
package com.monitorjbl.json;
|
package com.monitorjbl.json;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public class JsonResultRetriever {
|
public class JsonResultRetriever {
|
||||||
private static final Logger log = LoggerFactory.getLogger(JsonResultRetriever.class);
|
|
||||||
|
|
||||||
static boolean hasValue() {
|
static boolean hasValue() {
|
||||||
return JsonResult.get() != null;
|
return JsonResult.get() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JsonView<?> retrieve() {
|
||||||
|
JsonView<?> val = JsonResult.get();
|
||||||
|
JsonResult.unset();
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
static JsonView retrieve() {
|
|
||||||
JsonView val = JsonResult.get();
|
|
||||||
JsonResult.unset();
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,23 +11,19 @@ import java.util.List;
|
|||||||
|
|
||||||
public class JsonViewHttpEntityMethodProcessor extends HttpEntityMethodProcessor {
|
public class JsonViewHttpEntityMethodProcessor extends HttpEntityMethodProcessor {
|
||||||
|
|
||||||
public JsonViewHttpEntityMethodProcessor(List<HttpMessageConverter<?>> converters) {
|
public JsonViewHttpEntityMethodProcessor(List<HttpMessageConverter<?>> converters) {
|
||||||
super(converters);
|
super(converters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleReturnValue(Object returnValue, MethodParameter returnType,
|
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer,
|
||||||
|
NativeWebRequest webRequest) throws Exception {
|
||||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
if (returnValue instanceof ResponseEntity && JsonResultRetriever.hasValue()) {
|
||||||
if(returnValue instanceof ResponseEntity && JsonResultRetriever.hasValue()) {
|
JsonView<?> json = JsonResultRetriever.retrieve();
|
||||||
JsonView json = JsonResultRetriever.retrieve();
|
ResponseEntity<?> re = (ResponseEntity<?>) returnValue;
|
||||||
ResponseEntity re = (ResponseEntity) returnValue;
|
returnValue = ResponseEntity.status(re.getStatusCode()).headers(re.getHeaders()).body(json);
|
||||||
returnValue = ResponseEntity.status(re.getStatusCode())
|
}
|
||||||
.headers(re.getHeaders())
|
super.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
|
||||||
.body(json);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
super.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,26 +10,27 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class JsonViewMessageConverter extends MappingJackson2HttpMessageConverter {
|
public class JsonViewMessageConverter extends MappingJackson2HttpMessageConverter {
|
||||||
|
|
||||||
public JsonViewMessageConverter() {
|
public JsonViewMessageConverter() {
|
||||||
super();
|
super();
|
||||||
ObjectMapper defaultMapper = new ObjectMapper();
|
ObjectMapper defaultMapper = new ObjectMapper();
|
||||||
SimpleModule module = new SimpleModule();
|
SimpleModule module = new SimpleModule();
|
||||||
module.addSerializer(JsonView.class, new JsonViewSerializer());
|
module.addSerializer(JsonView.class, new JsonViewSerializer());
|
||||||
defaultMapper.registerModule(module);
|
defaultMapper.registerModule(module);
|
||||||
setObjectMapper(defaultMapper);
|
setObjectMapper(defaultMapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonViewMessageConverter(ObjectMapper mapper) {
|
public JsonViewMessageConverter(ObjectMapper mapper) {
|
||||||
super();
|
super();
|
||||||
SimpleModule module = new SimpleModule();
|
SimpleModule module = new SimpleModule();
|
||||||
module.addSerializer(JsonView.class, new JsonViewSerializer());
|
module.addSerializer(JsonView.class, new JsonViewSerializer());
|
||||||
mapper.registerModule(module);
|
mapper.registerModule(module);
|
||||||
setObjectMapper(mapper);
|
setObjectMapper(mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void writeInternal(Object object, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
|
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
|
||||||
super.writeInternal(object, outputMessage);
|
throws IOException, HttpMessageNotWritableException {
|
||||||
}
|
super.writeInternal(object, outputMessage);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -6,7 +6,9 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestResponseBody
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class JsonViewResponseProcessor extends RequestResponseBodyMethodProcessor {
|
public class JsonViewResponseProcessor extends RequestResponseBodyMethodProcessor {
|
||||||
public JsonViewResponseProcessor(List<HttpMessageConverter<?>> messageConverters) {
|
|
||||||
super(messageConverters);
|
public JsonViewResponseProcessor(List<HttpMessageConverter<?>> messageConverters) {
|
||||||
}
|
super(messageConverters);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,30 +11,31 @@ import org.springframework.web.method.support.ModelAndViewContainer;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class JsonViewReturnValueHandler implements HandlerMethodReturnValueHandler {
|
public class JsonViewReturnValueHandler implements HandlerMethodReturnValueHandler {
|
||||||
private static final Logger log = LoggerFactory.getLogger(JsonViewReturnValueHandler.class);
|
|
||||||
|
|
||||||
private final HandlerMethodReturnValueHandler delegate;
|
private static final Logger LOGGER = LoggerFactory.getLogger(JsonViewReturnValueHandler.class);
|
||||||
|
|
||||||
public JsonViewReturnValueHandler(List<HttpMessageConverter<?>> converters) {
|
private final HandlerMethodReturnValueHandler delegate;
|
||||||
this.delegate = new JsonViewResponseProcessor(converters);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public JsonViewReturnValueHandler(List<HttpMessageConverter<?>> converters) {
|
||||||
public boolean supportsReturnType(MethodParameter returnType) {
|
this.delegate = new JsonViewResponseProcessor(converters);
|
||||||
return delegate.supportsReturnType(returnType);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
public boolean supportsReturnType(MethodParameter returnType) {
|
||||||
Object val = returnValue;
|
return delegate.supportsReturnType(returnType);
|
||||||
if(JsonResultRetriever.hasValue()) {
|
}
|
||||||
val = JsonResultRetriever.retrieve();
|
|
||||||
log.debug("Found [" + ((JsonView) val).getValue().getClass() + "] to serialize");
|
|
||||||
} else {
|
|
||||||
log.debug("No JsonView found for thread, using returned value");
|
|
||||||
}
|
|
||||||
|
|
||||||
delegate.handleReturnValue(val, returnType, mavContainer, webRequest);
|
@Override
|
||||||
}
|
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer,
|
||||||
|
NativeWebRequest webRequest) throws Exception {
|
||||||
|
Object val = returnValue;
|
||||||
|
if (JsonResultRetriever.hasValue()) {
|
||||||
|
val = JsonResultRetriever.retrieve();
|
||||||
|
LOGGER.debug("Found [{}] to serialize", ((JsonView<?>) val).getValue().getClass());
|
||||||
|
} else {
|
||||||
|
LOGGER.debug("No JsonView found for thread, using returned value");
|
||||||
|
}
|
||||||
|
delegate.handleReturnValue(val, returnType, mavContainer, webRequest);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -15,38 +15,38 @@ import java.util.List;
|
|||||||
|
|
||||||
public class JsonViewSupportFactoryBean implements InitializingBean {
|
public class JsonViewSupportFactoryBean implements InitializingBean {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RequestMappingHandlerAdapter adapter;
|
private RequestMappingHandlerAdapter adapter;
|
||||||
private final JsonViewMessageConverter converter;
|
private final JsonViewMessageConverter converter;
|
||||||
|
|
||||||
public JsonViewSupportFactoryBean() {
|
public JsonViewSupportFactoryBean() {
|
||||||
this(new ObjectMapper());
|
this(new ObjectMapper());
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonViewSupportFactoryBean(ObjectMapper mapper) {
|
public JsonViewSupportFactoryBean(ObjectMapper mapper) {
|
||||||
this.converter = new JsonViewMessageConverter(mapper.copy());
|
this.converter = new JsonViewMessageConverter(mapper.copy());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>(adapter.getReturnValueHandlers());
|
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>(adapter.getReturnValueHandlers());
|
||||||
adapter.setMessageConverters(Collections.<HttpMessageConverter<?>>singletonList(converter));
|
adapter.setMessageConverters(Collections.singletonList(converter));
|
||||||
decorateHandlers(handlers);
|
decorateHandlers(handlers);
|
||||||
adapter.setReturnValueHandlers(handlers);
|
adapter.setReturnValueHandlers(handlers);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void decorateHandlers(List<HandlerMethodReturnValueHandler> handlers) {
|
private void decorateHandlers(List<HandlerMethodReturnValueHandler> handlers) {
|
||||||
List<HttpMessageConverter<?>> converters = new ArrayList<>(adapter.getMessageConverters());
|
List<HttpMessageConverter<?>> converters = new ArrayList<>(adapter.getMessageConverters());
|
||||||
converters.add(converter);
|
converters.add(converter);
|
||||||
for(HandlerMethodReturnValueHandler handler : handlers) {
|
for (HandlerMethodReturnValueHandler handler : handlers) {
|
||||||
int index = handlers.indexOf(handler);
|
int index = handlers.indexOf(handler);
|
||||||
if(handler instanceof HttpEntityMethodProcessor) {
|
if (handler instanceof HttpEntityMethodProcessor) {
|
||||||
handlers.set(index, new JsonViewHttpEntityMethodProcessor(converters));
|
handlers.set(index, new JsonViewHttpEntityMethodProcessor(converters));
|
||||||
} else if(handler instanceof RequestResponseBodyMethodProcessor) {
|
} else if (handler instanceof RequestResponseBodyMethodProcessor) {
|
||||||
handlers.set(index, new JsonViewReturnValueHandler(converters));
|
handlers.set(index, new JsonViewReturnValueHandler(converters));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user