Update PegawaiDto
Penyesuaian validator json save kelengkapan data NIK pegawai
This commit is contained in:
parent
c4796f568e
commit
0ea04dfb6a
@ -1,5 +1,10 @@
|
|||||||
package com.jasamedika.medifirst2000.dto;
|
package com.jasamedika.medifirst2000.dto;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
|
|
||||||
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
|
|
||||||
import com.jasamedika.medifirst2000.helper.Caption;
|
import com.jasamedika.medifirst2000.helper.Caption;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -7,9 +12,12 @@ import com.jasamedika.medifirst2000.helper.Caption;
|
|||||||
* @since Feb 24, 2023
|
* @since Feb 24, 2023
|
||||||
*/
|
*/
|
||||||
public class PegawaiDto {
|
public class PegawaiDto {
|
||||||
|
@NotNull(message = "ID Pegawai tidak boleh null")
|
||||||
@Caption(value = "ID Pegawai")
|
@Caption(value = "ID Pegawai")
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
|
@NotEmpty(message = "NIK harus diisi")
|
||||||
|
@Pattern(regexp = "\\d{16}", message = "Format NIK tidak sesuai")
|
||||||
@Caption(value = "NIK Pegawai")
|
@Caption(value = "NIK Pegawai")
|
||||||
private String noIdentitas;
|
private String noIdentitas;
|
||||||
|
|
||||||
|
|||||||
@ -1472,7 +1472,7 @@ public class PegawaiController extends LocaleController<PegawaiVO> implements IB
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/kelengkapan", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping(value = "/kelengkapan", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||||
public ResponseEntity<Boolean> completePegawai(@RequestBody PegawaiDto dto) {
|
public ResponseEntity<Boolean> completePegawai(@Valid @RequestBody PegawaiDto dto) {
|
||||||
try {
|
try {
|
||||||
pegawaiService.completeDataPegawai(dto);
|
pegawaiService.completeDataPegawai(dto);
|
||||||
return RestUtil.getJsonResponse(true, HttpStatus.CREATED);
|
return RestUtil.getJsonResponse(true, HttpStatus.CREATED);
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
|||||||
|
|
||||||
import com.jasamedika.medifirst2000.base.vo.validation.ValidationErrorVO;
|
import com.jasamedika.medifirst2000.base.vo.validation.ValidationErrorVO;
|
||||||
import com.jasamedika.medifirst2000.constants.Constants;;
|
import com.jasamedika.medifirst2000.constants.Constants;;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception Handler Rest Controller class
|
* Exception Handler Rest Controller class
|
||||||
*
|
*
|
||||||
@ -30,8 +31,7 @@ import com.jasamedika.medifirst2000.constants.Constants;;
|
|||||||
@Order(1) // Pertama masuk
|
@Order(1) // Pertama masuk
|
||||||
public class RestErrorHandler {
|
public class RestErrorHandler {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory
|
private static final Logger LOGGER = LoggerFactory.getLogger(RestErrorHandler.class);
|
||||||
.getLogger(RestErrorHandler.class);
|
|
||||||
|
|
||||||
private MessageSource messageSource;
|
private MessageSource messageSource;
|
||||||
|
|
||||||
@ -43,8 +43,7 @@ public class RestErrorHandler {
|
|||||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ValidationErrorVO processValidationError(
|
public ValidationErrorVO processValidationError(MethodArgumentNotValidException ex) {
|
||||||
MethodArgumentNotValidException ex) {
|
|
||||||
LOGGER.warn("Handling data validation error");
|
LOGGER.warn("Handling data validation error");
|
||||||
BindingResult result = ex.getBindingResult();
|
BindingResult result = ex.getBindingResult();
|
||||||
List<FieldError> fieldErrors = result.getFieldErrors();
|
List<FieldError> fieldErrors = result.getFieldErrors();
|
||||||
@ -56,8 +55,7 @@ public class RestErrorHandler {
|
|||||||
ValidationErrorVO dto = new ValidationErrorVO();
|
ValidationErrorVO dto = new ValidationErrorVO();
|
||||||
|
|
||||||
for (FieldError fieldError : fieldErrors) {
|
for (FieldError fieldError : fieldErrors) {
|
||||||
String localizedErrorMessage = resolveLocalizedErrorMessage(fieldError);
|
dto.addFieldError(fieldError.getField(), fieldError.getDefaultMessage());
|
||||||
dto.addFieldError(fieldError.getField(), localizedErrorMessage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return dto;
|
return dto;
|
||||||
@ -68,8 +66,7 @@ public class RestErrorHandler {
|
|||||||
*/
|
*/
|
||||||
private String resolveLocalizedErrorMessage(FieldError fieldError, String locale) {
|
private String resolveLocalizedErrorMessage(FieldError fieldError, String locale) {
|
||||||
Locale currentLocale = LocaleContextHolder.getLocale();
|
Locale currentLocale = LocaleContextHolder.getLocale();
|
||||||
String localizedErrorMessage = messageSource.getMessage(fieldError,
|
String localizedErrorMessage = messageSource.getMessage(fieldError, currentLocale);
|
||||||
currentLocale);
|
|
||||||
|
|
||||||
// If the message was not found, return the most accurate field error
|
// If the message was not found, return the most accurate field error
|
||||||
// code instead.
|
// code instead.
|
||||||
@ -87,8 +84,7 @@ public class RestErrorHandler {
|
|||||||
* resolve error message with default locale
|
* resolve error message with default locale
|
||||||
*/
|
*/
|
||||||
private String resolveLocalizedErrorMessage(FieldError fieldError) {
|
private String resolveLocalizedErrorMessage(FieldError fieldError) {
|
||||||
String localizedErrorMessage = messageSource.getMessage(fieldError,
|
String localizedErrorMessage = messageSource.getMessage(fieldError, new Locale(Constants.Locale.INA));
|
||||||
new Locale(Constants.Locale.INA));
|
|
||||||
|
|
||||||
// If the message was not found, return the most accurate field error
|
// If the message was not found, return the most accurate field error
|
||||||
// code instead.
|
// code instead.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user