inisialisasi

This commit is contained in:
tias
2024-06-15 16:59:12 +07:00
commit 3e97011f66
90 changed files with 5620 additions and 0 deletions
@@ -0,0 +1,25 @@
package org.sadigit.control.errorhandler;
import java.util.LinkedHashMap;
import java.util.Map;
import org.sadigit.control.exception.BadRequestBodyException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
@Provider
public class BadRequestBodyErrorHandler implements ExceptionMapper<BadRequestBodyException> {
@Override
public Response toResponse(BadRequestBodyException exception) {
Map<String, Object> response = new LinkedHashMap<>();
response.put("status", false);
response.put("title", "Bad Request");
response.put("message", exception.getMessage());
return Response.status(403).entity(response).build();
}
}
@@ -0,0 +1,26 @@
package org.sadigit.control.errorhandler;
import java.util.LinkedHashMap;
import java.util.Map;
import org.sadigit.control.exception.FileProcessingException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
@Provider
public class FileProcessingErrorHandler implements ExceptionMapper<FileProcessingException> {
@Override
public Response toResponse(FileProcessingException exception) {
Map<String, Object> response = new LinkedHashMap<>();
response.put("status", false);
response.put("title", "Bad Request");
response.put("message", exception.getMessage());
return Response.status(403).entity(response).build();
}
}
@@ -0,0 +1,31 @@
package org.sadigit.control.errorhandler;
import java.util.Map;
import java.util.stream.Collectors;
import jakarta.validation.ConstraintViolationException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j;
@Provider
@Slf4j
public class ValidationExceptionErrorHandler implements ExceptionMapper<ConstraintViolationException>{
@Override
public Response toResponse(ConstraintViolationException exception) {
var errorStructure = exception.getConstraintViolations()
.stream()
.map(violation -> Map.of(
"path", violation.getPropertyPath().toString(),
"message", violation.getMessage()
))
.collect(Collectors.toList());
log.error("Validation error: {}", errorStructure);
return Response.status(Response.Status.OK).entity(errorStructure).build();
}
}
@@ -0,0 +1,5 @@
package org.sadigit.control.exception;
public class AppFlowException extends RuntimeException{
}
@@ -0,0 +1,17 @@
package org.sadigit.control.exception;
public class BadRequestBodyException extends RuntimeException {
private static final long serialVersionUID = 1L;
public BadRequestBodyException() {
super();
}
public BadRequestBodyException(String msg) {
super(msg);
}
public BadRequestBodyException(String msg, Exception e) {
super(msg, e);
}
}
@@ -0,0 +1,17 @@
package org.sadigit.control.exception;
public class FileProcessingException extends RuntimeException {
private static final long serialVersionUID = 1L;
public FileProcessingException() {
super();
}
public FileProcessingException(String msg) {
super(msg);
}
public FileProcessingException(String msg, Exception e) {
super(msg, e);
}
}
@@ -0,0 +1,24 @@
// package org.sadigit.control.security;
// import io.quarkus.elytron.security.common.BcryptUtil;
// import io.quarkus.security.jpa.Password;
// import io.quarkus.security.jpa.Roles;
// import io.quarkus.security.jpa.UserDefinition;
// import io.quarkus.security.jpa.Username;
// @UserDefinition
// public class User {
// @Username
// public String username;
// @Password
// public String password;
// @Roles
// public String role;
// public User(String username, String password, String role) {
// this.username = username;
// this.password = BcryptUtil.bcryptHash(password);
// this.role = role;
// }
// }