Done ticket GEPAFINBE-219
This commit is contained in:
@@ -98,11 +98,19 @@ public class DateTimeUtil {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
|
||||
return LocalDateTime.parse(dateTimeStr, formatter);
|
||||
}
|
||||
public static LocalDateTime parseStringToLocalDateTime(String timestampStr) {
|
||||
// Use ISO_LOCAL_DATE_TIME to parse the input string
|
||||
return LocalDateTime.parse(timestampStr, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
|
||||
public static LocalDateTime parseStringToLocalDateTime(String dateStr) {
|
||||
if (dateStr == null || dateStr.isEmpty()) return null;
|
||||
|
||||
try {
|
||||
return LocalDateTime.parse(dateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
return LocalDateTime.parse(dateStr, DateTimeFormatter.ISO_DATE_TIME); // fallback
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String parseLocalTimeToString(LocalTime time, String format) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
|
||||
return time.format(formatter);
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package net.gepafin.tendermanagement.util;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.DigestInputStream;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
@Component
|
||||
public class FileHashUtil {
|
||||
|
||||
public static String calculateSHA256(InputStream inputStream) throws IOException {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||
|
||||
try (DigestInputStream dis = new DigestInputStream(inputStream, md)) {
|
||||
byte[] buffer = new byte[8192];
|
||||
while (dis.read(buffer) != -1) {
|
||||
// reading to compute hash
|
||||
}
|
||||
}
|
||||
|
||||
byte[] digest = md.digest();
|
||||
return bytesToHex(digest);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Could not generate hash", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String bytesToHex(byte[] bytes) {
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte b : bytes) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) hexString.append('0');
|
||||
hexString.append(hex);
|
||||
}
|
||||
return hexString.toString();
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,7 @@ import net.objecthunter.exp4j.ExpressionBuilder;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
@@ -60,6 +61,7 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
|
||||
import feign.FeignException;
|
||||
import io.micrometer.common.util.StringUtils;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
@@ -1043,5 +1045,12 @@ public class Utils {
|
||||
return new ArrayList<>(responseMap.values());
|
||||
}
|
||||
|
||||
public static HttpHeaders getHeaders(){
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.add(org.apache.http.HttpHeaders.USER_AGENT, "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0");
|
||||
return headers;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user