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);
|
||||
if (null != result)
|
||||
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);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
if (null != result)
|
||||
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);
|
||||
} catch (ServiceVOException e) {
|
||||
LOGGER.error("Got ServiceVOException {} when saveAsesmenGiziLanjut", e.getMessage());
|
||||
|
||||
@ -101,8 +101,7 @@ public class AuthenticateController {
|
||||
return RestUtil.getJsonHttpStatus(HttpStatus.NOT_ACCEPTABLE, mapHeaderMessage);
|
||||
}
|
||||
GrantedAuthority authority = new SimpleGrantedAuthority("USER");
|
||||
String token = tokenAuthenticationService.addAuthentication(httpResponse,
|
||||
new UserAuthentication(new User(loginUserVo.getNamaUser(), loginUserVo.getKataSandi(),
|
||||
String token = tokenAuthenticationService.addAuthentication(new UserAuthentication(new User(loginUserVo.getNamaUser(), loginUserVo.getKataSandi(),
|
||||
Collections.singletonList(authority))));
|
||||
boolean isSupervising = request.getHeader(Constants.HttpHeader.SUPERVISING) != null;
|
||||
if (isSupervising) { // supervising login
|
||||
@ -168,8 +167,7 @@ public class AuthenticateController {
|
||||
return RestUtil.getJsonHttpStatus(HttpStatus.NOT_ACCEPTABLE, mapHeaderMessage);
|
||||
}
|
||||
GrantedAuthority authority = new SimpleGrantedAuthority("USER");
|
||||
String token = tokenAuthenticationService.addAuthentication(httpResponse,
|
||||
new UserAuthentication(new User(loginUserVo.getNamaUser(), loginUserVo.getKataSandi(),
|
||||
String token = tokenAuthenticationService.addAuthentication(new UserAuthentication(new User(loginUserVo.getNamaUser(), loginUserVo.getKataSandi(),
|
||||
Collections.singletonList(authority))));
|
||||
boolean isSupervising = request.getHeader(Constants.HttpHeader.SUPERVISING) != null;
|
||||
if (isSupervising) { // supervising login
|
||||
|
||||
@ -55,7 +55,7 @@ public class FisisPemeriksaanDokterController extends LocaleController<FisisPeme
|
||||
} else {
|
||||
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);
|
||||
} catch (ServiceVOException e) {
|
||||
LOGGER.error("Got ServiceVOException {} when addFisisPemeriksaanDokter", e.getMessage());
|
||||
|
||||
@ -57,7 +57,7 @@ public class KebutuhanDasarController extends LocaleController<KebutuhanDasarVO>
|
||||
} else {
|
||||
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);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
if (null != result)
|
||||
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);
|
||||
} catch (ServiceVOException e) {
|
||||
LOGGER.error("Got ServiceVOException {} when findKelasByRuangan", e.getMessage());
|
||||
|
||||
@ -53,7 +53,7 @@ public class KonsepDiriController extends LocaleController<KonsepDiriVO> {
|
||||
} else {
|
||||
mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request));
|
||||
}
|
||||
SaveLog("Konsep Diri", "Pemeriksaan", request);
|
||||
SaveLog("Konsep Diri", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
LOGGER.error("Got ServiceVOException {} when addKonsepDiri", e.getMessage());
|
||||
|
||||
@ -61,7 +61,7 @@ public class KonsultasiController extends LocaleController<AntrianPasienDiPeriks
|
||||
} else {
|
||||
mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request));
|
||||
}
|
||||
SaveLog("Konsultasi", "Dokter", request);
|
||||
SaveLog("Konsultasi", "Dokter");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
LOGGER.error("Got ServiceVOException {} when addKonsultasi2", e.getMessage());
|
||||
|
||||
@ -54,7 +54,7 @@ public class KopingController extends LocaleController<KopingVO> {
|
||||
} else {
|
||||
mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request));
|
||||
}
|
||||
SaveLog("Koping", "Pemeriksaan", request);
|
||||
SaveLog("Koping", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
LOGGER.error("Got ServiceVOException {} when addKoping", e.getMessage());
|
||||
|
||||
@ -49,7 +49,7 @@ public class MasalahKeperawatanController extends LocaleController<TriaseVO> {
|
||||
if (null != result)
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
getJsonHttpStatus(CREATED);
|
||||
SaveLog("Masalah Keperawatan", "Pemeriksaan", request);
|
||||
SaveLog("Masalah Keperawatan", "Pemeriksaan");
|
||||
return getJsonResponse("Status Sukses", CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
LOGGER.error("Got ServiceVOException {} when saveMasalahKeperawatanService", e.getMessage());
|
||||
|
||||
@ -53,7 +53,7 @@ public class NilaiNilaiController extends LocaleController<NilaiNilaiVO> {
|
||||
} else {
|
||||
mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request));
|
||||
}
|
||||
SaveLog("Nilai Nilai", "Pemeriksaan", request);
|
||||
SaveLog("Nilai Nilai", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
result.put("message", "Berhasil");
|
||||
SaveLog("Alergi", "Pemeriksaan", request);
|
||||
SaveLog("Alergi", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
result.put("message", "Berhasil");
|
||||
SaveLog("Anamnesis", "Pemeriksaan", request);
|
||||
SaveLog("Anamnesis", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
result.put("message", "Berhasil");
|
||||
SaveLog("Eliminasi", "Pemeriksaan", request);
|
||||
SaveLog("Eliminasi", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
result.put("message", "Berhasil");
|
||||
SaveLog("Gastrointestinal", "Pemeriksaan", request);
|
||||
SaveLog("Gastrointestinal", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
result.put("message", "Berhasil");
|
||||
SaveLog("Genatalia", "Pemeriksaan", request);
|
||||
SaveLog("Genatalia", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
result.put("message", "Berhasil");
|
||||
SaveLog("Gigi Mulut", "Pemeriksaan Khusus", request);
|
||||
SaveLog("Gigi Mulut", "Pemeriksaan Khusus");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
result.put("message", "Berhasil");
|
||||
SaveLog("Perjanjian", "Instruksi", request);
|
||||
SaveLog("Perjanjian", "Instruksi");
|
||||
return getJsonResponse(result, CREATED);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
result.put("message", "Berhasil");
|
||||
SaveLog("Integumen", "Pemeriksaan", request);
|
||||
SaveLog("Integumen", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
if (null != result)
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
SaveLog("Kebutuhan Edukasi", "Pemeriksaan", request);
|
||||
SaveLog("Kebutuhan Edukasi", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
result.put("message", "Berhasil");
|
||||
SaveLog("Keluhan Tambahan", "Pemeriksaan", request);
|
||||
SaveLog("Keluhan Tambahan", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
result.put("message", "Berhasil");
|
||||
SaveLog("Keluhan Utama", "Pemeriksaan", request);
|
||||
SaveLog("Keluhan Utama", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
result.put("message", "Berhasil");
|
||||
SaveLog("Muskuloskeletal", "Pemeriksaan", request);
|
||||
SaveLog("Muskuloskeletal", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
result.put("message", "Berhasil");
|
||||
SaveLog("Neurologi", "Pemeriksaan", request);
|
||||
SaveLog("Neurologi", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
LOGGER.error("Got ServiceVOException {} when addNeurologi", e.getMessage());
|
||||
|
||||
@ -53,7 +53,7 @@ public class PapObstetriController extends LocaleController<PapObstetriVO> {
|
||||
} else {
|
||||
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);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
result.put("message", "Berhasil");
|
||||
SaveLog("Pernapasan", "Pemeriksaan", request);
|
||||
SaveLog("Pernapasan", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
result.put("message", "Berhasil");
|
||||
SaveLog("Riwayat Psikososial", "Pemeriksaan", request);
|
||||
SaveLog("Riwayat Psikososial", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
result.put("message", "Berhasil");
|
||||
SaveLog("Sirkulasi", "Pemeriksaan", request);
|
||||
SaveLog("Sirkulasi", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
SaveLog("Pasien Pulang", "Instruksi", request);
|
||||
SaveLog("Pasien Pulang", "Instruksi");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
mapHeaderMessage.clear();
|
||||
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);
|
||||
} catch (ServiceVOException e) {
|
||||
LOGGER.error("Got ServiceVOException {} when addPembedahanDanInstruksi", e.getMessage());
|
||||
|
||||
@ -54,7 +54,7 @@ public class PeranHubunganController extends LocaleController<PeranHubunganVO> {
|
||||
} else {
|
||||
mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request));
|
||||
}
|
||||
SaveLog("Peran Hubungan", "Pemeriksaan", request);
|
||||
SaveLog("Peran Hubungan", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
LOGGER.error("Got ServiceVOException {} when addPeranHubungan", e.getMessage());
|
||||
|
||||
@ -54,7 +54,7 @@ public class PersepsiKognisiController extends LocaleController<PersepsiKognisiV
|
||||
} else {
|
||||
mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request));
|
||||
}
|
||||
SaveLog("Persepsi Kognisi", "Pemeriksaan", request);
|
||||
SaveLog("Persepsi Kognisi", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
LOGGER.error("Got ServiceVOException {} when addPersepsiKognisi", e.getMessage());
|
||||
|
||||
@ -54,7 +54,7 @@ public class PersepsiPasienController extends LocaleController<PersepsiPasienVO>
|
||||
} else {
|
||||
mapHeaderMessage.put(LABEL_ERROR, getMessage(MessageResource.LABEL_ERROR, request));
|
||||
}
|
||||
SaveLog("Persepsi Pasien", "Pemeriksaan", request);
|
||||
SaveLog("Persepsi Pasien", "Pemeriksaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
LOGGER.error("Got ServiceVOException {} when addPersepsiPasien", e.getMessage());
|
||||
|
||||
@ -58,7 +58,7 @@ public class ProdukDetailLabAnatomiController extends LocaleController<ProdukDet
|
||||
} else {
|
||||
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);
|
||||
} catch (ServiceVOException e) {
|
||||
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.exception.ServiceVOException;
|
||||
import com.jasamedika.medifirst2000.service.*;
|
||||
import com.jasamedika.medifirst2000.util.DateUtil;
|
||||
import com.jasamedika.medifirst2000.vo.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -223,7 +224,7 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
|
||||
permintaan = "Laboratorium";
|
||||
}
|
||||
}
|
||||
SaveLog("Order " + permintaan, "Permintaaan", request);
|
||||
SaveLog("Order " + permintaan, "Permintaaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
if (null != result)
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
SaveLog("Order Farmasi", "Permintaan", request);
|
||||
SaveLog("Order Farmasi", "Permintaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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<HasilLaboratoriumDto> dtos = new ArrayList<>();
|
||||
Alamat alamatPasien = alamatService.findByPasienId2(strukOrder.getNoCm().getId());
|
||||
Integer usia = new Date(
|
||||
strukOrder.getNoCm().getTglDaftar().getTime() - strukOrder.getNoCm().getTglLahir().getTime()).getYear()
|
||||
- 70;
|
||||
int selisihTahunSaatDaftar = DateUtil.getYear(new Date(strukOrder.getNoCm().getTglDaftar().getTime() - strukOrder.getNoCm().getTglLahir().getTime()));
|
||||
Integer usia = selisihTahunSaatDaftar - 70;
|
||||
Date now = new Date();
|
||||
PapPengambilanSpesimen papPengambilanSpesimen = papPengambilanSpesimenService
|
||||
.findByNoOrderAndTglOrder2(strukOrder.getNoOrder(), strukOrder.getTglOrder());
|
||||
@ -1501,7 +1501,7 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
|
||||
boolean dataFound = (boolean) result.get("dataFound");
|
||||
if (dataFound) {
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
SaveLog("Order Gizi", "Permintaan", request);
|
||||
SaveLog("Order Gizi", "Permintaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} else {
|
||||
mapHeaderMessage.put(ERROR_MESSAGE, getMessage(MessageResource.LABEL_ERROR, request));
|
||||
@ -1529,7 +1529,7 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
|
||||
toDate(startDate), toDate(endDate));
|
||||
if (null != result)
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
SaveLog("Order Gizi", "Permintaan", request);
|
||||
SaveLog("Order Gizi", "Permintaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
if (null != result)
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
SaveLog("Order Tindakan", "Permintaan", request);
|
||||
SaveLog("Order Tindakan", "Permintaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
if (result != null) {
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
SaveLog("Produk Gizi", "Permintaan", request);
|
||||
SaveLog("Produk Gizi", "Permintaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} else {
|
||||
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);
|
||||
if (result != null) {
|
||||
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);
|
||||
} else {
|
||||
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");
|
||||
if (dataFound) {
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
SaveLog("Produk Gizi", "Permintaan", request);
|
||||
SaveLog("Produk Gizi", "Permintaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} else {
|
||||
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");
|
||||
if (dataFound) {
|
||||
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);
|
||||
} else {
|
||||
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);
|
||||
if (null != result)
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
SaveLog("Order Gizi", "Permintaan", request);
|
||||
SaveLog("Order Gizi", "Permintaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
if (null != result)
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
SaveLog("Order Gizi", "Permintaan", request);
|
||||
SaveLog("Order Gizi", "Permintaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
if (null != result)
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
SaveLog("Order Gizi", "Permintaan", request);
|
||||
SaveLog("Order Gizi", "Permintaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
LOGGER.error("Got ServiceVOException {} when getOrder", e.getMessage());
|
||||
@ -1869,7 +1869,7 @@ public class RegistrasiPelayananController extends LocaleController<AntrianPasie
|
||||
permintaan = "Laboratorium";
|
||||
}
|
||||
}
|
||||
SaveLog("Order " + permintaan, "Permintaaan", request);
|
||||
SaveLog("Order " + permintaan, "Permintaaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
if (null != result)
|
||||
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);
|
||||
} catch (ServiceVOException e) {
|
||||
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);
|
||||
if (null != result)
|
||||
mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
|
||||
SaveLog("Order Gizi", "Permintaan", request);
|
||||
SaveLog("Order Gizi", "Permintaan");
|
||||
return getJsonResponse(result, CREATED, mapHeaderMessage);
|
||||
} catch (ServiceVOException e) {
|
||||
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.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.jasamedika.medifirst2000.base.vo.BaseVO;
|
||||
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.*;
|
||||
|
||||
/**
|
||||
* Base Rest Operation for Controller Class
|
||||
*
|
||||
* @author Roberto
|
||||
*/
|
||||
public interface BaseRestController<V extends BaseVO> extends
|
||||
RestPageController<V> {
|
||||
public interface BaseRestController<V extends BaseVO> extends RestPageController<V> {
|
||||
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/{id}", method = GET)
|
||||
@ResponseBody
|
||||
public ResponseEntity<V> getVO(@PathVariable("id") String id);
|
||||
|
||||
@RequestMapping(value = "/", method = RequestMethod.PUT)
|
||||
ResponseEntity<V> getVO(@PathVariable("id") String id);
|
||||
|
||||
@RequestMapping(value = "/", method = POST, consumes = { "application/json" })
|
||||
@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
|
||||
public 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();
|
||||
|
||||
|
||||
ResponseEntity<Integer> editVO(@RequestBody V vo);
|
||||
|
||||
}
|
||||
|
||||
@ -19,11 +19,11 @@ public interface IBaseRestController<V extends BaseModelVO> extends IRestPageCon
|
||||
@ResponseBody
|
||||
ResponseEntity<V> getVO(@PathVariable("id") Integer id);
|
||||
|
||||
@RequestMapping(value = "/", method = PUT, consumes = { "application/json" })
|
||||
@RequestMapping(value = "/", method = POST, consumes = { "application/json" })
|
||||
@ResponseBody
|
||||
ResponseEntity<String> addVO(@RequestBody V vo);
|
||||
|
||||
@RequestMapping(value = "/", method = POST, consumes = { "application/json" })
|
||||
@RequestMapping(value = "/", method = PUT, consumes = { "application/json" })
|
||||
@ResponseBody
|
||||
ResponseEntity<String> editVO(@RequestBody V vo);
|
||||
|
||||
|
||||
@ -1,16 +1,15 @@
|
||||
package com.jasamedika.medifirst2000.controller.base;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.jasamedika.medifirst2000.base.vo.BaseModelVO;
|
||||
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 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
|
||||
@ -30,10 +29,9 @@ public interface IRestPageController<V extends BaseModelVO> {
|
||||
* : direction {asc:desc}
|
||||
* @return Collection of VO, Total-Count & Total Pages on response header
|
||||
*/
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/list", method = GET)
|
||||
@ResponseBody
|
||||
public ResponseEntity<Collection<V>> getAllVOWithQueryString(
|
||||
HttpServletRequest request,
|
||||
ResponseEntity<Collection<V>> getAllVOWithQueryString(HttpServletRequest request,
|
||||
@RequestParam(value = "page", required = false) Integer page,
|
||||
@RequestParam(value = "limit", required = false) Integer limit,
|
||||
@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.context.MessageSource;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@ -37,6 +35,11 @@ import java.io.InputStreamReader;
|
||||
import java.net.URISyntaxException;
|
||||
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
|
||||
* & locale
|
||||
@ -45,10 +48,6 @@ import java.util.*;
|
||||
*/
|
||||
public abstract class LocaleController<V extends BaseModelVO> {
|
||||
|
||||
/*
|
||||
* messageSource bean injected for each controller for accessing message
|
||||
* source
|
||||
*/
|
||||
@Autowired
|
||||
private ActivityPegawaiService activityPegawaiServiceImpl;
|
||||
|
||||
@ -66,14 +65,11 @@ public abstract class LocaleController<V extends BaseModelVO> {
|
||||
|
||||
protected Map<String, String> mapHeaderMessage = new HashMap<>();
|
||||
|
||||
/*
|
||||
* code locale
|
||||
*/
|
||||
protected String getMessage(String code, HttpServletRequest 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(
|
||||
pegawaiConverter.transferModelToVO(loginUserService.getLoginUser().getPegawai(), new PegawaiVO()),
|
||||
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,
|
||||
@PathVariable("lang") String lang) {
|
||||
Cookie[] cookies = request.getCookies();
|
||||
@ -150,27 +146,24 @@ public abstract class LocaleController<V extends BaseModelVO> {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* default locale ID
|
||||
*/
|
||||
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) {
|
||||
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) {
|
||||
ModelVO modelDTO = modelService.getModelSerializeEntity(entity, getCoociesLanguage(request));
|
||||
return RestUtil.getJsonResponse(modelDTO, HttpStatus.OK);
|
||||
return RestUtil.getJsonResponse(modelDTO, OK);
|
||||
}
|
||||
|
||||
public String getCoociesLanguage(HttpServletRequest request) {
|
||||
Cookie[] cookie = request.getCookies();
|
||||
Cookie cook;
|
||||
String lang = Constants.Locale.INA;
|
||||
String lang = INA;
|
||||
if (cookie != null) {
|
||||
for (Cookie value : cookie) {
|
||||
cook = value;
|
||||
@ -190,12 +183,12 @@ public abstract class LocaleController<V extends BaseModelVO> {
|
||||
return RestUtil.getJsonResponse(null, HttpStatus.BAD_REQUEST, mapHeaderMessage);
|
||||
} else {
|
||||
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,
|
||||
String.valueOf(map.get(WebConstants.PageParameter.TOTAL_PAGES)));
|
||||
mapHeaderMessage.put(WebConstants.HttpHeaderInfo.TOTAL_COUNT_HEADER,
|
||||
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;
|
||||
|
||||
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.constants.Constants;
|
||||
import com.jasamedika.medifirst2000.util.rest.RestUtil;
|
||||
import com.monitorjbl.json.JsonResult;
|
||||
import com.monitorjbl.json.JsonView;
|
||||
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
|
||||
* @see https://github.com/monitorjbl/json-view
|
||||
* Base Controller Class for handling "include" parameter to controller
|
||||
*
|
||||
* @see <a href="https://github.com/monitorjbl/json-view">reference</a>
|
||||
*
|
||||
* @author Roberto
|
||||
*/
|
||||
public abstract class ParamRestController<T extends BaseModelVO> {
|
||||
private 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
|
||||
*/
|
||||
private final JsonResult jsonResult = JsonResult.instance();
|
||||
|
||||
@RequestMapping(value = "/list-using-param", method = RequestMethod.GET)
|
||||
public ResponseEntity<List<T>> listUsingParam(
|
||||
@RequestParam(value = "includes", required = false) String includes,
|
||||
public ResponseEntity<List<T>> listUsingParam(@RequestParam(value = "includes", required = false) String includes,
|
||||
@RequestParam(value = "excludes", required = false) String excludes) {
|
||||
List<T> listVO = getAllVOFromService();
|
||||
String[] arrExcludes = null;
|
||||
@ -44,35 +38,27 @@ public abstract class ParamRestController<T extends BaseModelVO> {
|
||||
arrIncludes = includes.split(Constants.COMMA);
|
||||
if (arrExcludes != null && arrIncludes != null) {
|
||||
listVO = jsonResult.use(
|
||||
JsonView.with(listVO).onClass(
|
||||
getClazz(),
|
||||
Match.match().exclude(arrExcludes)
|
||||
.include(arrIncludes))).returnValue();
|
||||
JsonView.with(listVO).onClass(getClazz(), Match.match().exclude(arrExcludes).include(arrIncludes)))
|
||||
.returnValue();
|
||||
}
|
||||
if (arrExcludes != null && arrIncludes == null) {
|
||||
listVO = jsonResult.use(
|
||||
JsonView.with(listVO).onClass(getClazz(),
|
||||
Match.match().include("*").exclude(arrExcludes)))
|
||||
listVO = jsonResult
|
||||
.use(JsonView.with(listVO).onClass(getClazz(), Match.match().include("*").exclude(arrExcludes)))
|
||||
.returnValue();
|
||||
}
|
||||
if (arrExcludes == null && arrIncludes != null) {
|
||||
listVO = jsonResult.use(
|
||||
JsonView.with(listVO).onClass(getClazz(),
|
||||
Match.match().exclude("*").include(arrIncludes)))
|
||||
listVO = jsonResult
|
||||
.use(JsonView.with(listVO).onClass(getClazz(), Match.match().exclude("*").include(arrIncludes)))
|
||||
.returnValue();
|
||||
}
|
||||
|
||||
return RestUtil.getJsonResponse(listVO, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Class<T> getClazz() {
|
||||
return (Class<T>) GenericTypeResolver.resolveTypeArgument(getClass(),
|
||||
ParamRestController.class);
|
||||
return (Class<T>) GenericTypeResolver.resolveTypeArgument(getClass(), ParamRestController.class);
|
||||
}
|
||||
|
||||
/*
|
||||
* method untuk mendapatkan all VO from service
|
||||
* */
|
||||
protected abstract List<T> getAllVOFromService();
|
||||
|
||||
}
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
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.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
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
|
||||
@ -28,10 +28,9 @@ public interface RestPageController<V extends BaseVO> {
|
||||
* : direction {asc:desc}
|
||||
* @return Collection of VO, Total-Count & Total Pages on response header
|
||||
*/
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/list", method = GET)
|
||||
@ResponseBody
|
||||
public ResponseEntity<Collection<V>> getAllVOWithQueryString(
|
||||
@RequestParam(value = "page", required = false) Integer page,
|
||||
ResponseEntity<Collection<V>> getAllVOWithQueryString(@RequestParam(value = "page", required = false) Integer page,
|
||||
@RequestParam(value = "limit", required = false) Integer limit,
|
||||
@RequestParam(value = "sort", required = false, defaultValue = "id") String sort,
|
||||
@RequestParam(value = "dir", required = false, defaultValue = "asc") String dir);
|
||||
|
||||
@ -1,30 +1,19 @@
|
||||
package com.jasamedika.medifirst2000.filter;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
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 com.jasamedika.medifirst2000.constants.Constants;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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
|
||||
@ -33,132 +22,113 @@ import com.jasamedika.medifirst2000.constants.Constants;
|
||||
*/
|
||||
@Component
|
||||
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 {
|
||||
final String body;
|
||||
|
||||
|
||||
public RequestWrapper(ServletRequest req) throws IOException {
|
||||
super((HttpServletRequest) req);
|
||||
|
||||
HttpServletRequest request = (HttpServletRequest) req;
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
InputStream inputStream = request.getInputStream();
|
||||
if (inputStream != null) {
|
||||
reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
String hasil;
|
||||
while ( (hasil = reader.readLine()) != null) {
|
||||
stringBuilder.append(hasil);
|
||||
}
|
||||
} else {
|
||||
stringBuilder.append("");
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw ex;
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException ex) {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
body = stringBuilder.toString();
|
||||
|
||||
String idRuanganTujuan = request.getHeader(Constants.HttpHeader.KD_RUANGAN_T) == null ? ""
|
||||
: 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();
|
||||
}
|
||||
StringBuilder stringBuilder = getStringBuilder(request);
|
||||
body = stringBuilder.toString();
|
||||
String idRuanganTujuan = request.getHeader(Constants.HttpHeader.KD_RUANGAN_T) == null ? ""
|
||||
: request.getHeader(Constants.HttpHeader.KD_RUANGAN_T);
|
||||
if (idRuanganTujuan.trim().isEmpty()) {
|
||||
JSONObject jObject;
|
||||
try {
|
||||
jObject = new JSONObject(body);
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
try {
|
||||
ExtractObjectJson(jObject, false);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(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);
|
||||
}
|
||||
|
||||
|
||||
JSONArray autoIdTujuan = new JSONArray();
|
||||
|
||||
void ExtractObjectJson(JSONObject jObject, boolean ruangan) throws Exception{
|
||||
Iterator iterator = jObject.keys();
|
||||
while (iterator.hasNext()){
|
||||
String key = String.valueOf(iterator.next());
|
||||
Object o = jObject.get(key);
|
||||
|
||||
if (key.toLowerCase().contains("ruangan")){
|
||||
if (o instanceof Integer){
|
||||
autoIdTujuan.put(o);
|
||||
} else if (o instanceof JSONObject){
|
||||
ExtractObjectJson((JSONObject) o, true);
|
||||
}
|
||||
} else if (ruangan && "id".equals(key)){
|
||||
if (o instanceof Integer){
|
||||
autoIdTujuan.put(o);
|
||||
return;
|
||||
}
|
||||
} else if (o instanceof JSONObject && !ruangan) {
|
||||
ExtractObjectJson((JSONObject) o, false);
|
||||
}
|
||||
}
|
||||
|
||||
void ExtractObjectJson(JSONObject jObject, boolean ruangan) throws Exception {
|
||||
Iterator<?> iterator = jObject.keys();
|
||||
while (iterator.hasNext()) {
|
||||
String key = String.valueOf(iterator.next());
|
||||
Object o = jObject.get(key);
|
||||
if (key.toLowerCase().contains("ruangan")) {
|
||||
if (o instanceof Integer) {
|
||||
autoIdTujuan.put(o);
|
||||
} else if (o instanceof JSONObject) {
|
||||
ExtractObjectJson((JSONObject) o, true);
|
||||
}
|
||||
} else if (ruangan && "id".equals(key)) {
|
||||
if (o instanceof Integer) {
|
||||
autoIdTujuan.put(o);
|
||||
return;
|
||||
}
|
||||
} else if (o instanceof JSONObject && !ruangan) {
|
||||
ExtractObjectJson((JSONObject) o, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ServletInputStream getInputStream() throws IOException {
|
||||
public ServletInputStream getInputStream() {
|
||||
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body.getBytes());
|
||||
ServletInputStream servletInputStream = new ServletInputStream() {
|
||||
public int read() throws IOException {
|
||||
return new ServletInputStream() {
|
||||
public int read() {
|
||||
return byteArrayInputStream.read();
|
||||
}
|
||||
};
|
||||
return servletInputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedReader getReader() throws IOException {
|
||||
public BufferedReader getReader() {
|
||||
return new BufferedReader(new InputStreamReader(getInputStream()));
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return this.body;
|
||||
}
|
||||
}
|
||||
// End Syamsu
|
||||
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(CORSFilter.class);
|
||||
|
||||
public CORSFilter() {
|
||||
log.info("CORSFilter JasaMedika Web init");
|
||||
private static StringBuilder getStringBuilder(HttpServletRequest request) throws IOException {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
InputStream inputStream = request.getInputStream();
|
||||
if (inputStream != null) {
|
||||
reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
String hasil;
|
||||
while ((hasil = reader.readLine()) != null) {
|
||||
stringBuilder.append(hasil);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (reader != null)
|
||||
reader.close();
|
||||
}
|
||||
return stringBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
|
||||
// Start Syamsu
|
||||
RequestWrapper myReq = new RequestWrapper((HttpServletRequest) req);
|
||||
// End Syamsu
|
||||
HttpServletRequest request = (HttpServletRequest) myReq;
|
||||
RequestWrapper myReq = new RequestWrapper(req);
|
||||
HttpServletResponse response = (HttpServletResponse) res;
|
||||
|
||||
response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
|
||||
response.setHeader("Access-Control-Allow-Origin", myReq.getHeader("Origin"));
|
||||
response.setHeader("Access-Control-Allow-Credentials", "true");
|
||||
|
||||
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
|
||||
response.setHeader("Access-Control-Max-Age", "3600");
|
||||
response.setHeader("Access-Control-Allow-Headers",
|
||||
@ -166,19 +136,11 @@ public class CORSFilter implements Filter {
|
||||
+ "Supervising, RequestSupervisor, Module, Form, Action, AlamatUrlForm, KdRuangan, KdUser, "
|
||||
+ "MandatoriData, idRuanganTujuan, ruanganTujuan");
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,8 +1,12 @@
|
||||
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 java.io.IOException;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.filter.GenericFilterBean;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
@ -10,14 +14,7 @@ import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
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;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* StatelessAuthenticationFilter class
|
||||
@ -27,41 +24,34 @@ import com.jasamedika.medifirst2000.security.service.TokenAuthenticationService;
|
||||
public class StatelessAuthenticationFilter extends GenericFilterBean {
|
||||
private final TokenAuthenticationService authenticationService;
|
||||
|
||||
public StatelessAuthenticationFilter(
|
||||
TokenAuthenticationService authenticationService) {
|
||||
public StatelessAuthenticationFilter(TokenAuthenticationService authenticationService) {
|
||||
this.authenticationService = authenticationService;
|
||||
}
|
||||
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain filterChain) throws IOException, ServletException {
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
|
||||
throws IOException, ServletException {
|
||||
HttpServletRequest httpRequest = (HttpServletRequest) request;
|
||||
HttpServletRequest req = (HttpServletRequest) request;
|
||||
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-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-Allow-Headers",
|
||||
"Content-Type, Accept, X-Requested-With, remember-me, X-AUTH-TOKEN, Supervising, "
|
||||
+ "RequestSupervisor, Module, Form, Action, AlamatUrlForm, KdRuangan, KdUser, "
|
||||
+ "MandatoriData");
|
||||
|
||||
+ "RequestSupervisor, Module, Form, Action, AlamatUrlForm, KdRuangan, KdUser, "
|
||||
+ "MandatoriData");
|
||||
Authentication authentication = null;
|
||||
try {
|
||||
|
||||
authentication = authenticationService.getAuthentication(httpRequest);
|
||||
} catch (JsonParseException | MalformedJwtException e) {
|
||||
HttpServletResponse httpResponse = (HttpServletResponse) response;
|
||||
httpResponse.addHeader(Constants.MessageInfo.ERROR_MESSAGE,
|
||||
"Error Token (Not Valid Token)");
|
||||
httpResponse.addHeader(Constants.MessageInfo.ERROR_MESSAGE, "Error Token (Not Valid Token)");
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
filterChain.doFilter(request, response);
|
||||
SecurityContextHolder.getContext().setAuthentication(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
package com.jasamedika.medifirst2000.handler;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.jasamedika.medifirst2000.base.vo.validation.ValidationErrorVO;
|
||||
import com.jasamedika.medifirst2000.constants.Constants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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.ResponseStatus;
|
||||
|
||||
import com.jasamedika.medifirst2000.base.vo.validation.ValidationErrorVO;
|
||||
import com.jasamedika.medifirst2000.constants.Constants;;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Exception Handler Rest Controller class
|
||||
*
|
||||
@ -27,13 +27,12 @@ import com.jasamedika.medifirst2000.constants.Constants;;
|
||||
*/
|
||||
|
||||
@ControllerAdvice
|
||||
@Order(1) // Pertama masuk
|
||||
@Order(1)
|
||||
public class RestErrorHandler {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory
|
||||
.getLogger(RestErrorHandler.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RestErrorHandler.class);
|
||||
|
||||
private MessageSource messageSource;
|
||||
private final MessageSource messageSource;
|
||||
|
||||
@Autowired
|
||||
public RestErrorHandler(MessageSource validationNessageSource) {
|
||||
@ -43,62 +42,39 @@ public class RestErrorHandler {
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ResponseBody
|
||||
public ValidationErrorVO processValidationError(
|
||||
MethodArgumentNotValidException ex) {
|
||||
public ValidationErrorVO processValidationError(MethodArgumentNotValidException ex) {
|
||||
LOGGER.warn("Handling data validation error");
|
||||
BindingResult result = ex.getBindingResult();
|
||||
List<FieldError> fieldErrors = result.getFieldErrors();
|
||||
|
||||
return processFieldErrors(fieldErrors);
|
||||
}
|
||||
|
||||
private ValidationErrorVO processFieldErrors(List<FieldError> fieldErrors) {
|
||||
ValidationErrorVO dto = new ValidationErrorVO();
|
||||
|
||||
for (FieldError fieldError : fieldErrors) {
|
||||
String localizedErrorMessage = resolveLocalizedErrorMessage(fieldError);
|
||||
dto.addFieldError(fieldError.getField(), localizedErrorMessage);
|
||||
}
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
/*
|
||||
* resolve error message with parameter locale
|
||||
*/
|
||||
|
||||
private String resolveLocalizedErrorMessage(FieldError fieldError, String locale) {
|
||||
Locale currentLocale = LocaleContextHolder.getLocale();
|
||||
String localizedErrorMessage = messageSource.getMessage(fieldError,
|
||||
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.
|
||||
String localizedErrorMessage = messageSource.getMessage(fieldError, currentLocale);
|
||||
if (localizedErrorMessage.equals(fieldError.getDefaultMessage())) {
|
||||
String[] fieldErrorCodes = fieldError.getCodes();
|
||||
localizedErrorMessage = fieldErrorCodes[0];
|
||||
}
|
||||
|
||||
return localizedErrorMessage;
|
||||
}
|
||||
|
||||
/*
|
||||
* resolve error message with default locale
|
||||
*/
|
||||
|
||||
private String resolveLocalizedErrorMessage(FieldError fieldError) {
|
||||
String localizedErrorMessage = messageSource.getMessage(fieldError,
|
||||
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.
|
||||
String localizedErrorMessage = messageSource.getMessage(fieldError, new Locale(Constants.Locale.INA));
|
||||
if (localizedErrorMessage.equals(fieldError.getDefaultMessage())) {
|
||||
String[] fieldErrorCodes = fieldError.getCodes();
|
||||
localizedErrorMessage = fieldErrorCodes[0];
|
||||
}
|
||||
|
||||
return localizedErrorMessage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -364,4 +364,5 @@ public class AppInterceptor implements HandlerInterceptor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,43 +1,35 @@
|
||||
package com.jasamedika.medifirst2000.security;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.jasamedika.medifirst2000.constants.Constants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||
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
|
||||
* set Unauthorized response from "Unauthorized client"
|
||||
* RestAuthenticationEntryPoint class set Unauthorized response from
|
||||
* "Unauthorized client"
|
||||
*
|
||||
* @author Roberto
|
||||
*/
|
||||
@Component("RestAuthenticationEntryPoint")
|
||||
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
|
||||
public void commence(HttpServletRequest request,
|
||||
HttpServletResponse response, AuthenticationException ae)
|
||||
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException ae)
|
||||
throws IOException, ServletException {
|
||||
|
||||
LOGGER.error("Mencoba akses tanpa login");
|
||||
response.getWriter().write("{" + 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.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.Configuration;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
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;
|
||||
|
||||
/**
|
||||
* SpringSecurityConfig class
|
||||
* Di sini Kita tidak menggunakan XML Config untuk Spring Security
|
||||
* SpringSecurityConfig class Di sini Kita tidak menggunakan XML Config untuk
|
||||
* Spring Security
|
||||
*
|
||||
* @author Roberto
|
||||
*/
|
||||
@ -31,92 +30,32 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Autowired
|
||||
private RestAuthenticationEntryPoint restAuthenticationEntryPoint;
|
||||
|
||||
|
||||
private final UserService userService;
|
||||
private final TokenAuthenticationService tokenAuthenticationService;
|
||||
|
||||
public SpringSecurityConfig() {
|
||||
super(true);
|
||||
this.userService = new UserService();
|
||||
tokenAuthenticationService = new TokenAuthenticationService(
|
||||
Constants.JASAMEDIKA, userService);
|
||||
tokenAuthenticationService = new TokenAuthenticationService(Constants.JASAMEDIKA, userService);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.exceptionHandling()
|
||||
//restAuthenticationEntryPoint
|
||||
.authenticationEntryPoint(restAuthenticationEntryPoint)
|
||||
|
||||
.and()
|
||||
.anonymous()
|
||||
.and()
|
||||
.servletApi()
|
||||
.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),
|
||||
http.exceptionHandling().authenticationEntryPoint(restAuthenticationEntryPoint).and().anonymous().and()
|
||||
.servletApi().and().headers().cacheControl().and().authorizeRequests().antMatchers("/favicon.ico")
|
||||
.permitAll().antMatchers("**/*.html").permitAll().antMatchers("**/*.css").permitAll()
|
||||
.antMatchers("**/*.js").permitAll().antMatchers("/auth/**").permitAll()
|
||||
.antMatchers("/registrasi-pasien-sms/**").permitAll().antMatchers("/report/**").permitAll()
|
||||
.antMatchers("/test-tanpa-auth/**").permitAll().antMatchers("/test/**").permitAll()
|
||||
.antMatchers("/api-docs.json").permitAll().antMatchers("/api-docs/**").permitAll().anyRequest()
|
||||
.authenticated().and().addFilterBefore(new StatelessAuthenticationFilter(tokenAuthenticationService),
|
||||
UsernamePasswordAuthenticationFilter.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(AuthenticationManagerBuilder auth)
|
||||
throws Exception {
|
||||
auth.userDetailsService(userDetailsService()).passwordEncoder(
|
||||
new BCryptPasswordEncoder());
|
||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth.userDetailsService(userDetailsService()).passwordEncoder(new BCryptPasswordEncoder());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ -135,11 +74,5 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
public TokenAuthenticationService 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;
|
||||
|
||||
/**
|
||||
* TokenHandler class
|
||||
* using jjwt https://github.com/jwtk/jjwt
|
||||
*
|
||||
* TokenHandler class using <a href="https://github.com/jwtk/jjwt">jjwt</a>
|
||||
*
|
||||
* @author Roberto
|
||||
*/
|
||||
public class TokenHandler {
|
||||
private final String secret;
|
||||
private final UserService userService;
|
||||
|
||||
public TokenHandler(String secret, UserService userService) {
|
||||
this.secret = secret;
|
||||
this.userService = userService;
|
||||
}
|
||||
private final String secret;
|
||||
private final UserService userService;
|
||||
|
||||
public User parseUserFromToken(String token) {
|
||||
String username = Jwts.parser()
|
||||
.setSigningKey(secret)
|
||||
.parseClaimsJws(token)
|
||||
.getBody()
|
||||
.getSubject();
|
||||
return userService.loadUserByUsername(username);
|
||||
}
|
||||
public TokenHandler(String secret, UserService userService) {
|
||||
this.secret = secret;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
public User parseUserFromToken(String token) {
|
||||
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;
|
||||
|
||||
/**
|
||||
* AppPermission annotation, digunakan untuk method yang butuh authorized dari database
|
||||
* can use in method only.
|
||||
* AppPermission annotation, digunakan untuk method yang butuh authorized dari
|
||||
* database can use in method only.
|
||||
*
|
||||
* @author Roberto
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface AppPermission {
|
||||
public static final int ADD = 100;
|
||||
public static final int UPDATE = 200;
|
||||
public static final int DELETE = 300;
|
||||
public static final int PRINT = 400;
|
||||
public static final int VIEW = 500;
|
||||
|
||||
public static final int SPECIALS = 600;
|
||||
|
||||
public @interface AppPermission {
|
||||
|
||||
int ADD = 100;
|
||||
int UPDATE = 200;
|
||||
int DELETE = 300;
|
||||
int PRINT = 400;
|
||||
int VIEW = 500;
|
||||
int SPECIALS = 600;
|
||||
|
||||
int value();
|
||||
|
||||
}
|
||||
|
||||
@ -1,20 +1,18 @@
|
||||
package com.jasamedika.medifirst2000.security.model;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* UserAuthentication class
|
||||
*
|
||||
* @author Roberto
|
||||
*/
|
||||
public class UserAuthentication implements Authentication {
|
||||
/**
|
||||
* serialVersionUID
|
||||
*/
|
||||
|
||||
private static final long serialVersionUID = -7410905698525654537L;
|
||||
private final User user;
|
||||
private boolean authenticated = true;
|
||||
@ -57,4 +55,5 @@ public class UserAuthentication implements Authentication {
|
||||
public void setAuthenticated(boolean authenticated) {
|
||||
this.authenticated = authenticated;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,16 +1,15 @@
|
||||
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.jasamedika.medifirst2000.core.web.WebConstants;
|
||||
import com.jasamedika.medifirst2000.security.handler.TokenHandler;
|
||||
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
|
||||
@ -20,8 +19,8 @@ import com.jasamedika.medifirst2000.security.model.UserAuthentication;
|
||||
@Component
|
||||
public class TokenAuthenticationService {
|
||||
|
||||
public static TokenHandler tokenHandler;
|
||||
|
||||
public static TokenHandler tokenHandler;
|
||||
|
||||
public TokenAuthenticationService() {
|
||||
}
|
||||
|
||||
@ -29,44 +28,32 @@ public class TokenAuthenticationService {
|
||||
tokenHandler = new TokenHandler(secret, userService);
|
||||
}
|
||||
|
||||
public String addAuthentication(HttpServletResponse response,
|
||||
UserAuthentication authentication) {
|
||||
public String addAuthentication(UserAuthentication authentication) {
|
||||
final User user = authentication.getDetails();
|
||||
return tokenHandler.createTokenForUser(user);
|
||||
return tokenHandler.createTokenForUser(user);
|
||||
}
|
||||
|
||||
public Authentication getAuthentication(HttpServletRequest request)
|
||||
throws JsonParseException {
|
||||
|
||||
public Authentication getAuthentication(HttpServletRequest request) throws JsonParseException {
|
||||
String token = request.getHeader(WebConstants.AUTH_HEADER_NAME);
|
||||
if (token != null) {
|
||||
final User user = tokenHandler.parseUserFromToken(token);
|
||||
if (user != null) {
|
||||
if (user != null)
|
||||
return new UserAuthentication(user);
|
||||
}
|
||||
}
|
||||
else{
|
||||
try
|
||||
{
|
||||
if(request.getQueryString()=="")return null;
|
||||
final String[] tokens= request.getQueryString().split("&");
|
||||
for (String tokenTemp : tokens) {
|
||||
if(tokenTemp.toLowerCase().indexOf(WebConstants.AUTH_HEADER_NAME.toLowerCase())>=0)
|
||||
{
|
||||
token =tokenTemp.split("=")[1];
|
||||
final User user = tokenHandler.parseUserFromToken(token);
|
||||
if (user != null) {
|
||||
return new UserAuthentication(user);
|
||||
}
|
||||
} else {
|
||||
if (Objects.equals(request.getQueryString(), ""))
|
||||
return null;
|
||||
final String[] tokens = request.getQueryString().split("&");
|
||||
for (String tokenTemp : tokens) {
|
||||
if (tokenTemp.toLowerCase().contains(WebConstants.AUTH_HEADER_NAME.toLowerCase())) {
|
||||
token = tokenTemp.split("=")[1];
|
||||
final User user = tokenHandler.parseUserFromToken(token);
|
||||
if (user != null) {
|
||||
return new UserAuthentication(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,29 +1,27 @@
|
||||
package com.jasamedika.medifirst2000.security.service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.jasamedika.medifirst2000.dao.LoginUserDao;
|
||||
import com.jasamedika.medifirst2000.entities.LoginUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.AccountStatusUserDetailsChecker;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
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.stereotype.Component;
|
||||
|
||||
import com.jasamedika.medifirst2000.dao.LoginUserDao;
|
||||
import com.jasamedika.medifirst2000.entities.LoginUser;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* UserService implements
|
||||
org.springframework.security.core.userdetails.UserDetailsService
|
||||
* org.springframework.security.core.userdetails.UserDetailsService
|
||||
*
|
||||
* @author Roberto
|
||||
*/
|
||||
@Component
|
||||
public class UserService implements
|
||||
org.springframework.security.core.userdetails.UserDetailsService {
|
||||
public class UserService implements UserDetailsService {
|
||||
|
||||
@Autowired
|
||||
private LoginUserDao loginUserDao;
|
||||
@ -34,28 +32,17 @@ public class UserService implements
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* this method is called for rest authentication from client
|
||||
*
|
||||
* @author Roberto
|
||||
*/
|
||||
@Override
|
||||
public final User loadUserByUsername(String username)
|
||||
throws UsernameNotFoundException {
|
||||
public final User loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
List<LoginUser> loginUsers = loginUserDao.findByNamaUser(username);
|
||||
if (loginUsers.isEmpty()) {
|
||||
if (loginUsers.isEmpty())
|
||||
throw new UsernameNotFoundException("user not found");
|
||||
}
|
||||
LoginUser loginUser = loginUsers.get(0);
|
||||
//validasi tambahan lakukan di sini
|
||||
|
||||
// GrantedAuthority authority = new SimpleGrantedAuthority(loginUser
|
||||
// .getKelompokUser().getKelompokUser());
|
||||
GrantedAuthority authority = new SimpleGrantedAuthority("USER");
|
||||
UserDetails userDetails = (UserDetails) new User(
|
||||
loginUser.getNamaUser(), loginUser.getKataSandi(),
|
||||
Arrays.asList(authority));
|
||||
User userDetails = new User(loginUser.getNamaUser(), loginUser.getKataSandi(),
|
||||
Collections.singletonList(authority));
|
||||
detailsChecker.check(userDetails);
|
||||
return (User) userDetails;
|
||||
return userDetails;
|
||||
}
|
||||
|
||||
}
|
||||
@ -9,21 +9,17 @@ import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
|
||||
@Component
|
||||
public class JacksonConfiguration {
|
||||
private ObjectMapper mapper;
|
||||
|
||||
public JacksonConfiguration() {
|
||||
}
|
||||
|
||||
public JacksonConfiguration(ObjectMapper mapper) {
|
||||
this.mapper = mapper;
|
||||
configureJackson(mapper);
|
||||
}
|
||||
|
||||
public static ObjectMapper configureJackson(ObjectMapper mapper) {
|
||||
public static void configureJackson(ObjectMapper mapper) {
|
||||
mapper.enable(SerializationFeature.INDENT_OUTPUT);
|
||||
mapper.setSerializationInclusion(Include.NON_NULL);
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
|
||||
false);
|
||||
return mapper;
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,7 +38,8 @@ public class RestUtil {
|
||||
/**
|
||||
* get JSON response from Object with HTTP status
|
||||
*
|
||||
* @param <T> source class
|
||||
* @param <T>
|
||||
* source class
|
||||
* @return @ResponseEntity
|
||||
*/
|
||||
public static <T> ResponseEntity<T> getJsonResponse(T src, HttpStatus status) {
|
||||
@ -159,7 +160,7 @@ public class RestUtil {
|
||||
* string source JSON
|
||||
* @param type
|
||||
* class type result
|
||||
*/
|
||||
*/
|
||||
public static <T> T jsonToObject(String strJson, Class<T> type) {
|
||||
Gson gson = new Gson();
|
||||
return gson.fromJson(strJson, type);
|
||||
@ -168,7 +169,7 @@ public class RestUtil {
|
||||
/**
|
||||
* convert object to json
|
||||
*
|
||||
*/
|
||||
*/
|
||||
public static String toJson(Object object) {
|
||||
Gson gson = new Gson();
|
||||
return gson.toJson(object);
|
||||
|
||||
@ -2,7 +2,7 @@ package com.monitorjbl.json;
|
||||
|
||||
public class 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() {
|
||||
}
|
||||
@ -16,7 +16,6 @@ public class JsonResult {
|
||||
* Type of object being rendered
|
||||
* @return ResultWrapper to provide return value
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E> ResultWrapper<E> use(JsonView<E> view) {
|
||||
current.set(view);
|
||||
return new ResultWrapper<>(view);
|
||||
@ -26,7 +25,7 @@ public class JsonResult {
|
||||
return instance;
|
||||
}
|
||||
|
||||
static JsonView get() {
|
||||
static JsonView<?> get() {
|
||||
return current.get();
|
||||
}
|
||||
|
||||
@ -35,7 +34,7 @@ public class JsonResult {
|
||||
}
|
||||
|
||||
public static class ResultWrapper<T> {
|
||||
private JsonView<T> obj;
|
||||
private final JsonView<T> obj;
|
||||
|
||||
private ResultWrapper(JsonView<T> obj) {
|
||||
this.obj = obj;
|
||||
|
||||
@ -1,18 +1,15 @@
|
||||
package com.monitorjbl.json;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class JsonResultRetriever {
|
||||
private static final Logger log = LoggerFactory.getLogger(JsonResultRetriever.class);
|
||||
|
||||
static boolean hasValue() {
|
||||
return JsonResult.get() != null;
|
||||
}
|
||||
static boolean hasValue() {
|
||||
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 JsonViewHttpEntityMethodProcessor(List<HttpMessageConverter<?>> converters) {
|
||||
super(converters);
|
||||
}
|
||||
public JsonViewHttpEntityMethodProcessor(List<HttpMessageConverter<?>> converters) {
|
||||
super(converters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleReturnValue(Object returnValue, MethodParameter returnType,
|
||||
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
||||
if(returnValue instanceof ResponseEntity && JsonResultRetriever.hasValue()) {
|
||||
JsonView json = JsonResultRetriever.retrieve();
|
||||
ResponseEntity re = (ResponseEntity) returnValue;
|
||||
returnValue = ResponseEntity.status(re.getStatusCode())
|
||||
.headers(re.getHeaders())
|
||||
.body(json);
|
||||
}
|
||||
|
||||
super.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
|
||||
}
|
||||
@Override
|
||||
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest) throws Exception {
|
||||
if (returnValue instanceof ResponseEntity && JsonResultRetriever.hasValue()) {
|
||||
JsonView<?> json = JsonResultRetriever.retrieve();
|
||||
ResponseEntity<?> re = (ResponseEntity<?>) returnValue;
|
||||
returnValue = ResponseEntity.status(re.getStatusCode()).headers(re.getHeaders()).body(json);
|
||||
}
|
||||
super.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -10,26 +10,27 @@ import java.io.IOException;
|
||||
|
||||
public class JsonViewMessageConverter extends MappingJackson2HttpMessageConverter {
|
||||
|
||||
public JsonViewMessageConverter() {
|
||||
super();
|
||||
ObjectMapper defaultMapper = new ObjectMapper();
|
||||
SimpleModule module = new SimpleModule();
|
||||
module.addSerializer(JsonView.class, new JsonViewSerializer());
|
||||
defaultMapper.registerModule(module);
|
||||
setObjectMapper(defaultMapper);
|
||||
}
|
||||
public JsonViewMessageConverter() {
|
||||
super();
|
||||
ObjectMapper defaultMapper = new ObjectMapper();
|
||||
SimpleModule module = new SimpleModule();
|
||||
module.addSerializer(JsonView.class, new JsonViewSerializer());
|
||||
defaultMapper.registerModule(module);
|
||||
setObjectMapper(defaultMapper);
|
||||
}
|
||||
|
||||
public JsonViewMessageConverter(ObjectMapper mapper) {
|
||||
super();
|
||||
SimpleModule module = new SimpleModule();
|
||||
module.addSerializer(JsonView.class, new JsonViewSerializer());
|
||||
mapper.registerModule(module);
|
||||
setObjectMapper(mapper);
|
||||
}
|
||||
public JsonViewMessageConverter(ObjectMapper mapper) {
|
||||
super();
|
||||
SimpleModule module = new SimpleModule();
|
||||
module.addSerializer(JsonView.class, new JsonViewSerializer());
|
||||
mapper.registerModule(module);
|
||||
setObjectMapper(mapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeInternal(Object object, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
|
||||
super.writeInternal(object, outputMessage);
|
||||
}
|
||||
@Override
|
||||
protected void writeInternal(Object object, HttpOutputMessage 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;
|
||||
|
||||
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;
|
||||
|
||||
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) {
|
||||
this.delegate = new JsonViewResponseProcessor(converters);
|
||||
}
|
||||
private final HandlerMethodReturnValueHandler delegate;
|
||||
|
||||
@Override
|
||||
public boolean supportsReturnType(MethodParameter returnType) {
|
||||
return delegate.supportsReturnType(returnType);
|
||||
}
|
||||
public JsonViewReturnValueHandler(List<HttpMessageConverter<?>> converters) {
|
||||
this.delegate = new JsonViewResponseProcessor(converters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
||||
Object val = returnValue;
|
||||
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");
|
||||
}
|
||||
@Override
|
||||
public boolean supportsReturnType(MethodParameter returnType) {
|
||||
return delegate.supportsReturnType(returnType);
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@Autowired
|
||||
private RequestMappingHandlerAdapter adapter;
|
||||
private final JsonViewMessageConverter converter;
|
||||
@Autowired
|
||||
private RequestMappingHandlerAdapter adapter;
|
||||
private final JsonViewMessageConverter converter;
|
||||
|
||||
public JsonViewSupportFactoryBean() {
|
||||
this(new ObjectMapper());
|
||||
}
|
||||
public JsonViewSupportFactoryBean() {
|
||||
this(new ObjectMapper());
|
||||
}
|
||||
|
||||
public JsonViewSupportFactoryBean(ObjectMapper mapper) {
|
||||
this.converter = new JsonViewMessageConverter(mapper.copy());
|
||||
}
|
||||
public JsonViewSupportFactoryBean(ObjectMapper mapper) {
|
||||
this.converter = new JsonViewMessageConverter(mapper.copy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>(adapter.getReturnValueHandlers());
|
||||
adapter.setMessageConverters(Collections.<HttpMessageConverter<?>>singletonList(converter));
|
||||
decorateHandlers(handlers);
|
||||
adapter.setReturnValueHandlers(handlers);
|
||||
}
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>(adapter.getReturnValueHandlers());
|
||||
adapter.setMessageConverters(Collections.singletonList(converter));
|
||||
decorateHandlers(handlers);
|
||||
adapter.setReturnValueHandlers(handlers);
|
||||
}
|
||||
|
||||
private void decorateHandlers(List<HandlerMethodReturnValueHandler> handlers) {
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<>(adapter.getMessageConverters());
|
||||
converters.add(converter);
|
||||
for(HandlerMethodReturnValueHandler handler : handlers) {
|
||||
int index = handlers.indexOf(handler);
|
||||
if(handler instanceof HttpEntityMethodProcessor) {
|
||||
handlers.set(index, new JsonViewHttpEntityMethodProcessor(converters));
|
||||
} else if(handler instanceof RequestResponseBodyMethodProcessor) {
|
||||
handlers.set(index, new JsonViewReturnValueHandler(converters));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
private void decorateHandlers(List<HandlerMethodReturnValueHandler> handlers) {
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<>(adapter.getMessageConverters());
|
||||
converters.add(converter);
|
||||
for (HandlerMethodReturnValueHandler handler : handlers) {
|
||||
int index = handlers.indexOf(handler);
|
||||
if (handler instanceof HttpEntityMethodProcessor) {
|
||||
handlers.set(index, new JsonViewHttpEntityMethodProcessor(converters));
|
||||
} else if (handler instanceof RequestResponseBodyMethodProcessor) {
|
||||
handlers.set(index, new JsonViewReturnValueHandler(converters));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user