Resolved Conflicts
This commit is contained in:
@@ -37,6 +37,7 @@ import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.enums.MatchModeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.FilterCriteria;
|
||||
import net.gepafin.tendermanagement.model.request.GlobalFilters;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.*;
|
||||
import net.objecthunter.exp4j.Expression;
|
||||
@@ -111,6 +112,7 @@ public class Utils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String extractFileName(String filePath) {
|
||||
if (filePath == null || filePath.isEmpty()) {
|
||||
return null;
|
||||
@@ -123,6 +125,7 @@ public class Utils {
|
||||
return filePath;
|
||||
}
|
||||
}
|
||||
|
||||
public static String decodeBase64String(String decodedString) {
|
||||
if (StringUtils.isBlank(decodedString)) {
|
||||
return decodedString;
|
||||
@@ -130,18 +133,20 @@ public class Utils {
|
||||
byte[] decode = Base64.getDecoder().decode(decodedString.getBytes(StandardCharsets.UTF_8));
|
||||
return new String(decode, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static <T> void setIfNotNull(Consumer<T> setter, T value) {
|
||||
if (value != null) {
|
||||
setter.accept(value);
|
||||
}
|
||||
}
|
||||
public static <T> void setIfUpdated(Supplier<T> getter, Consumer<T> setter, T newValue) {
|
||||
T currentValue = getter.get();
|
||||
if (newValue != null && !newValue.equals(currentValue)) {
|
||||
setter.accept(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void setIfNotNull(Consumer<T> setter, T value) {
|
||||
if (value != null) {
|
||||
setter.accept(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void setIfUpdated(Supplier<T> getter, Consumer<T> setter, T newValue) {
|
||||
T currentValue = getter.get();
|
||||
if (newValue != null && !newValue.equals(currentValue)) {
|
||||
setter.accept(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> String convertListToJsonString(List<T> list) {
|
||||
try {
|
||||
return mapper.writeValueAsString(list);
|
||||
@@ -151,6 +156,7 @@ public class Utils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> List<T> convertJsonStringToList(String jsonString, Class<T> clazz) {
|
||||
try {
|
||||
TypeReference<List<T>> typeRef = new TypeReference<List<T>>() {
|
||||
@@ -166,6 +172,7 @@ public class Utils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String convertMapIntoJsonString(Map<String, Object> map) {
|
||||
try {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
@@ -180,6 +187,7 @@ public class Utils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Map<String, Object> convertIntoJson(String jsonString) {
|
||||
if (jsonString != null && !jsonString.isEmpty()) {
|
||||
try {
|
||||
@@ -192,6 +200,7 @@ public class Utils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T, U> U convertSourceObjectToDestinationObject(T source, Class<U> destinationClass) {
|
||||
try {
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
@@ -202,6 +211,7 @@ public class Utils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T> void retainOnlySpecificFields(T requestObject, List<T> retainFields) throws IllegalAccessException {
|
||||
// Get all declared fields of the request object's class
|
||||
Field[] fields = requestObject.getClass().getDeclaredFields();
|
||||
@@ -217,22 +227,23 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static String encodeData(String data) {
|
||||
return Base64.getEncoder().encodeToString(data.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
return Base64.getEncoder().encodeToString(data.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public static String decodeData(String token) {
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(token);
|
||||
return new String(decodedBytes, StandardCharsets.UTF_8);
|
||||
}
|
||||
public static String decodeData(String token) {
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(token);
|
||||
return new String(decodedBytes, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static String generateSecureSamlToken() {
|
||||
SecureRandom secureRandom = new SecureRandom();
|
||||
byte[] tokenBytes = new byte[24];
|
||||
secureRandom.nextBytes(tokenBytes);
|
||||
String token = Base64.getUrlEncoder().withoutPadding().encodeToString(tokenBytes);
|
||||
log.debug("Generated secure token: {}", token);
|
||||
return token;
|
||||
}
|
||||
SecureRandom secureRandom = new SecureRandom();
|
||||
byte[] tokenBytes = new byte[24];
|
||||
secureRandom.nextBytes(tokenBytes);
|
||||
String token = Base64.getUrlEncoder().withoutPadding().encodeToString(tokenBytes);
|
||||
log.debug("Generated secure token: {}", token);
|
||||
return token;
|
||||
}
|
||||
|
||||
public static String generateSecureToken() {
|
||||
SecureRandom secureRandom = new SecureRandom();
|
||||
byte[] tokenBytes = new byte[5];
|
||||
@@ -241,6 +252,7 @@ public class Utils {
|
||||
log.debug("Generated secure token: {}", token);
|
||||
return token;
|
||||
}
|
||||
|
||||
public static Map<String, List<Object>> convertStringIntoMap(String jsonString) {
|
||||
try {
|
||||
return mapper.readValue(jsonString, new TypeReference<Map<String, List<Object>>>() {
|
||||
@@ -250,26 +262,26 @@ public class Utils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void callException(Integer staus, FeignException ex) {
|
||||
switch (staus) {
|
||||
case 400:
|
||||
throw new FeignClientValidationException(HttpStatus.valueOf(staus), ex.getMessage());
|
||||
case 400:
|
||||
throw new FeignClientValidationException(HttpStatus.valueOf(staus), ex.getMessage());
|
||||
|
||||
case 401:
|
||||
throw new FeignClientUnauthorizedException(HttpStatus.valueOf(staus), ex.getMessage());
|
||||
case 401:
|
||||
throw new FeignClientUnauthorizedException(HttpStatus.valueOf(staus), ex.getMessage());
|
||||
|
||||
case 403:
|
||||
throw new FeignClientForbiddenException(HttpStatus.valueOf(staus), ex.getMessage());
|
||||
case 403:
|
||||
throw new FeignClientForbiddenException(HttpStatus.valueOf(staus), ex.getMessage());
|
||||
|
||||
case 404:
|
||||
throw new FeignClientNotFoundException(HttpStatus.valueOf(staus), ex.getMessage());
|
||||
default:
|
||||
log.error("Exception occured :- {0}", ex);
|
||||
throw ex;
|
||||
case 404:
|
||||
throw new FeignClientNotFoundException(HttpStatus.valueOf(staus), ex.getMessage());
|
||||
default:
|
||||
log.error("Exception occured :- {0}", ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Boolean isValidEmail(String email) {
|
||||
String EMAIL_REGEX = "^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+$";
|
||||
if (email == null || email.isEmpty()) {
|
||||
@@ -283,7 +295,7 @@ public class Utils {
|
||||
String data = String.valueOf(System.currentTimeMillis());
|
||||
return data.substring(data.length() - range);
|
||||
}
|
||||
|
||||
|
||||
public static String convertObjectToJsonString(Object object) {
|
||||
try {
|
||||
// Check if the object is a string
|
||||
@@ -327,7 +339,7 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, Map<String, String>> parseJsonContent(String jsonContent) {
|
||||
public static Map<String, Map<String, String>> parseJsonContent(String jsonContent) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
return mapper.readValue(jsonContent, HashMap.class);
|
||||
@@ -336,22 +348,23 @@ public class Utils {
|
||||
}
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
|
||||
// Utility method to replace placeholders with their values, handling nulls
|
||||
public static String replacePlaceholders(String text, Map<String, String> placeholders) {
|
||||
if (text == null) {
|
||||
return "";
|
||||
}
|
||||
for (Map.Entry<String, String> entry : placeholders.entrySet()) {
|
||||
text = replaceNull(text, entry.getKey(), entry.getValue());
|
||||
}
|
||||
return text;
|
||||
if (text == null) {
|
||||
return "";
|
||||
}
|
||||
for (Map.Entry<String, String> entry : placeholders.entrySet()) {
|
||||
text = replaceNull(text, entry.getKey(), entry.getValue());
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
// Method to safely replace nulls with an empty string or a default value
|
||||
private static String replaceNull(String text, String target, String replacement) {
|
||||
return text.replace(target, replacement != null ? replacement : "");
|
||||
return text.replace(target, replacement != null ? replacement : "");
|
||||
}
|
||||
|
||||
public static String getClientIpAddress(HttpServletRequest request) {
|
||||
String header = request.getHeader("X-Forwarded-For");
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(header)) {
|
||||
@@ -360,6 +373,7 @@ public class Utils {
|
||||
|
||||
return new StringTokenizer(header, ",").nextToken().trim();
|
||||
}
|
||||
|
||||
public static <T> List<T> convertJsonToList(String json, TypeReference<List<T>> typeRef) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
@@ -372,11 +386,15 @@ public class Utils {
|
||||
|
||||
public static String convertObjectToJson(Object obj) {
|
||||
try {
|
||||
if(obj == null){return null;}
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
return new ObjectMapper().writeValueAsString(obj);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Failed to convert object to JSON: {}", e.getMessage(), e);
|
||||
throw new RuntimeException("Failed to convert object to JSON", e);}}
|
||||
throw new RuntimeException("Failed to convert object to JSON", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String replaceSpacesWithUnderscores(String content) {
|
||||
if (content == null) {
|
||||
@@ -384,10 +402,10 @@ public class Utils {
|
||||
}
|
||||
return content.trim().replace(" ", "_");
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> convertJsonStringIntoJsonList(String jsonString) {
|
||||
try {
|
||||
if(isEmpty(jsonString))
|
||||
{
|
||||
if (isEmpty(jsonString)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
@@ -398,6 +416,7 @@ public class Utils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String convertToString(Object input) {
|
||||
if (input == null) {
|
||||
return "null"; // Return string "null" for null input
|
||||
@@ -459,6 +478,7 @@ public class Utils {
|
||||
throw new RuntimeException("Error converting map to string", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isValidDateString(String dateStr) {
|
||||
Pattern datePattern = Pattern.compile("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}");
|
||||
return datePattern.matcher(dateStr).matches();
|
||||
@@ -476,7 +496,7 @@ public class Utils {
|
||||
|
||||
return targetFormat.format(date);
|
||||
} catch (ParseException e) {
|
||||
log.error("error while prcoessing date formate");
|
||||
log.error("error while prcoessing date formate");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -522,6 +542,7 @@ public class Utils {
|
||||
return "Invalid amount format";
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isItalianFormattedAmount(String input) {
|
||||
// Regular expression to match Italian-style amounts (e.g., 41.003,00 or 123,45)
|
||||
String sanitizedInput = input.replace(",", "");
|
||||
@@ -534,7 +555,7 @@ public class Utils {
|
||||
|
||||
public static String encryptCredential(String value) {
|
||||
try {
|
||||
if(Boolean.FALSE.equals(isEmpty(value))) {
|
||||
if (Boolean.FALSE.equals(isEmpty(value))) {
|
||||
|
||||
IvParameterSpec iv = new IvParameterSpec(GepafinConstant.ENCRYPT_INIT_VECTOR.getBytes("UTF-8"));
|
||||
SecretKeySpec skeySpec = new SecretKeySpec(Base64.getDecoder().decode(GepafinConstant.ENCRYPT_KEY), "AES");
|
||||
@@ -555,7 +576,7 @@ public class Utils {
|
||||
|
||||
public static String decryptCredential(String encrypted) {
|
||||
try {
|
||||
if(Boolean.FALSE.equals(isEmpty(encrypted))) {
|
||||
if (Boolean.FALSE.equals(isEmpty(encrypted))) {
|
||||
|
||||
IvParameterSpec iv = new IvParameterSpec(GepafinConstant.ENCRYPT_INIT_VECTOR.getBytes("UTF-8"));
|
||||
SecretKeySpec skeySpec = new SecretKeySpec(Base64.getDecoder().decode(GepafinConstant.ENCRYPT_KEY), "AES");
|
||||
@@ -618,19 +639,19 @@ public class Utils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setHttpServletRequestForScheduler() {
|
||||
MockHttpServletRequest mockRequest = new MockHttpServletRequest();
|
||||
mockRequest.setRequestURI("/scheduled");
|
||||
mockRequest.setMethod("POST");
|
||||
ServletRequestAttributes attributes = new ServletRequestAttributes(mockRequest);
|
||||
RequestContextHolder.setRequestAttributes(attributes);
|
||||
}
|
||||
|
||||
public static void clearHttpServletRequest() {
|
||||
// Clear the RequestContextHolder after task execution
|
||||
RequestContextHolder.resetRequestAttributes();
|
||||
}
|
||||
public static void setHttpServletRequestForScheduler() {
|
||||
MockHttpServletRequest mockRequest = new MockHttpServletRequest();
|
||||
mockRequest.setRequestURI("/scheduled");
|
||||
mockRequest.setMethod("POST");
|
||||
ServletRequestAttributes attributes = new ServletRequestAttributes(mockRequest);
|
||||
RequestContextHolder.setRequestAttributes(attributes);
|
||||
}
|
||||
|
||||
public static void clearHttpServletRequest() {
|
||||
// Clear the RequestContextHolder after task execution
|
||||
RequestContextHolder.resetRequestAttributes();
|
||||
}
|
||||
|
||||
public static String generateAuthTokenForLoginToOdessa() {
|
||||
|
||||
@@ -739,7 +760,8 @@ public class Utils {
|
||||
public static String createChannelForUserAndCompany(Long userId, Long companyId) {
|
||||
return GepafinConstant.COMMON_SINGLE_CHANNEL_PREFIX + userId + GepafinConstant.COMPANY_PREFIX + companyId;
|
||||
}
|
||||
public static GlobalFilters setPageNumberAndLimit(GlobalFilters globalFilters){
|
||||
|
||||
public static GlobalFilters setPageNumberAndLimit(GlobalFilters globalFilters) {
|
||||
if (globalFilters == null) {
|
||||
if (globalFilters.getLimit() == null || globalFilters.getLimit() <= 0) {
|
||||
globalFilters.setLimit(GepafinConstant.DEFAULT_PAGE_LIMIT);
|
||||
@@ -767,6 +789,7 @@ public class Utils {
|
||||
private static Map<String, Object> defaultErrorResponse() {
|
||||
return Collections.singletonMap("message", Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
|
||||
}
|
||||
|
||||
public static List<String> extractValues(String input) {
|
||||
List<String> extractedValues = new ArrayList<>();
|
||||
Pattern pattern = Pattern.compile("\\{(.*?)\\}"); // Regex to match {value}
|
||||
@@ -777,6 +800,7 @@ public class Utils {
|
||||
}
|
||||
return extractedValues;
|
||||
}
|
||||
|
||||
public static double evaluateExpression(String expression) {
|
||||
try {
|
||||
Expression exp = new ExpressionBuilder(expression).build();
|
||||
@@ -786,6 +810,7 @@ public class Utils {
|
||||
return Double.NaN; // Return NaN if the expression is invalid
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isNumeric(String input) {
|
||||
if (input == null || input.trim().isEmpty()) {
|
||||
return false;
|
||||
@@ -793,9 +818,11 @@ public class Utils {
|
||||
|
||||
return input.matches("-?\\d+(\\.\\d+)?");
|
||||
}
|
||||
|
||||
public static boolean isValidBoolean(String value) {
|
||||
return "true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value);
|
||||
}
|
||||
|
||||
public static Map<String, Object> convertJsonStringToMap(String jsonString) {
|
||||
try {
|
||||
return mapper.readValue(jsonString, Map.class);
|
||||
@@ -905,8 +932,10 @@ public class Utils {
|
||||
switch (mode) {
|
||||
case DATEIS -> predicates.add(criteriaBuilder.equal(dateField, dateValue));
|
||||
case DATEISNOT -> predicates.add(criteriaBuilder.notEqual(dateField, dateValue));
|
||||
case BEFORE -> predicates.add(criteriaBuilder.lessThan(fieldPath.as(Timestamp.class), Timestamp.valueOf(dateTimeValue)));
|
||||
case AFTER -> predicates.add(criteriaBuilder.greaterThan(fieldPath.as(Timestamp.class), Timestamp.valueOf(dateTimeValue)));
|
||||
case BEFORE ->
|
||||
predicates.add(criteriaBuilder.lessThan(fieldPath.as(Timestamp.class), Timestamp.valueOf(dateTimeValue)));
|
||||
case AFTER ->
|
||||
predicates.add(criteriaBuilder.greaterThan(fieldPath.as(Timestamp.class), Timestamp.valueOf(dateTimeValue)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -937,4 +966,25 @@ public class Utils {
|
||||
Translator.toLocale(GepafinConstant.VALIDATION_ERROR_FILE_EMPTY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void applyFiltersByPagination(Root<?> root, CriteriaBuilder criteriaBuilder, List<Predicate> predicates, Map<String, FilterCriteria> filters) {
|
||||
if (Boolean.FALSE.equals(filters.isEmpty())) {
|
||||
for (Map.Entry<String, FilterCriteria> entry : filters.entrySet()) {
|
||||
String fieldName = entry.getKey();
|
||||
FilterCriteria filterCriteria = entry.getValue();
|
||||
Object value = filterCriteria.getValue();
|
||||
MatchModeEnum matchMode = filterCriteria.getMatchMode();
|
||||
|
||||
if (value != null && matchMode != null) {
|
||||
Path<?> fieldPath = root.get(fieldName);
|
||||
if (fieldPath != null) {
|
||||
Utils.applyStringFilter(fieldPath, criteriaBuilder, predicates, value, matchMode);
|
||||
Utils.applyNumberFilter(fieldPath, criteriaBuilder, predicates, value, matchMode);
|
||||
Utils.applyDateFilter(fieldPath, criteriaBuilder, predicates, value, matchMode, root);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -206,4 +206,12 @@ public class Validator {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public Boolean checkRequestedUserWithUserId(HttpServletRequest request,Long userId){
|
||||
UserEntity user=validateUser(request);
|
||||
UserEntity requestedUser=userService.validateUser(userId);
|
||||
if( Boolean.FALSE.equals(user.getId().equals(requestedUser.getId()))){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user