Resolved conflicts

This commit is contained in:
rajesh
2025-01-02 15:45:37 +05:30
158 changed files with 5895 additions and 1053 deletions

View File

@@ -28,7 +28,6 @@ import net.gepafin.tendermanagement.constants.GepafinConstant;
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;
@@ -45,9 +44,12 @@ import net.gepafin.tendermanagement.web.rest.api.errors.FeignClientForbiddenExce
import net.gepafin.tendermanagement.web.rest.api.errors.FeignClientNotFoundException;
import net.gepafin.tendermanagement.web.rest.api.errors.FeignClientUnauthorizedException;
import net.gepafin.tendermanagement.web.rest.api.errors.FeignClientValidationException;
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;
import javax.crypto.Cipher;
import javax.crypto.Mac;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
@@ -56,6 +58,9 @@ import static org.apache.commons.lang3.StringUtils.isEmpty;
public class Utils {
// @Autowired
// private static TokenProvider tokenProvider;
public static final Logger log = LoggerFactory.getLogger(Utils.class);
private static final ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule()).configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
@@ -571,4 +576,125 @@ 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 String generateAuthTokenForLoginToOdessa() {
try {
// Your weak secret key
String secretKey = GepafinConstant.AUTH_JWT_SECRET_KEY;
// Header
String header = GepafinConstant.JWT_ALGO_HEADER;
String encodedHeader = Base64.getUrlEncoder().withoutPadding().encodeToString(header.getBytes(StandardCharsets.UTF_8));
// Payload
String payload = "{\"iat\":" + (System.currentTimeMillis() / 1000) + "}";
String encodedPayload = Base64.getUrlEncoder().withoutPadding().encodeToString(payload.getBytes(StandardCharsets.UTF_8));
// Combine header and payload
String dataToSign = encodedHeader + "." + encodedPayload;
// Sign the token manually
Mac mac = Mac.getInstance(GepafinConstant.HMAC_ALGO);
SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(StandardCharsets.UTF_8), GepafinConstant.HMAC_ALGO);
mac.init(secretKeySpec);
byte[] signatureBytes = mac.doFinal(dataToSign.getBytes(StandardCharsets.UTF_8));
String signature = Base64.getUrlEncoder().withoutPadding().encodeToString(signatureBytes);
// Return the final JWT
return dataToSign + "." + signature;
} catch (Exception e) {
throw new RuntimeException("Failed to generate JWT token", e);
}
}
// public static void setHttpServletRequestForNdgProcess(HttpServletRequest originalRequest) {
//
// // Validate original request
// if (originalRequest == null) {
// throw new IllegalArgumentException("Original request cannot be null.");
// }
//
// // Create a mock request
// Claims tokenClaims = tokenProvider.getClaimsFromToken(tokenProvider.extractTokenFromRequest(originalRequest));
// MockHttpServletRequest mockRequest = new MockHttpServletRequest();
// mockRequest.setRequestURI(originalRequest.getRequestURI());
// mockRequest.setMethod(originalRequest.getMethod());
//
// // Copy essential headers and attributes from the original request
// Enumeration<String> headerNames = originalRequest.getHeaderNames();
// while (headerNames.hasMoreElements()) {
// String headerName = headerNames.nextElement();
// String headerValue = originalRequest.getHeader(headerName);
// if (headerValue != null) {
// mockRequest.addHeader(headerName, headerValue);
// }
// }
//
// // Set a specific attribute if required
// if (originalRequest.getAttribute(GepafinConstant.USER_ACTION_ID) != null) {
// mockRequest.setAttribute(GepafinConstant.USER_ACTION_ID, originalRequest.getAttribute(GepafinConstant.USER_ACTION_ID));
// }
//
// ServletRequestAttributes attributes = new ServletRequestAttributes(mockRequest);
// RequestContextHolder.setRequestAttributes(attributes);
// // Log successful context setting
// log.info("Successfully set mock request for NDG process with URI: {}", mockRequest.getRequestURI());
// }
public static Long extractHubIdFromPayload(String payload) {
Long hubId;
try {
String[] parts = payload.split(":");
if (parts.length > 2) {
hubId = Long.valueOf(parts[2]);
return hubId;
} else {
hubId = null;
}
} catch (Exception e) {
throw new RuntimeException("No Hub id present in payload", e);
}
return null;
}
// Method to convert a JSON string to an object of type T
public static <T> T convertStringToObject(String jsonString, Class<T> clazz) {
try {
return mapper.readValue(jsonString, clazz);
} catch (Exception e) {
e.printStackTrace();
// Handle the exception appropriately (e.g., throw a custom exception)
return null;
}
}
// Method to convert an object of type T to a JSON string
public static <T> String convertObjectToString(T object) {
try {
return mapper.writeValueAsString(object);
} catch (Exception e) {
e.printStackTrace();
// Handle the exception appropriately (e.g., throw a custom exception)
return null;
}
}
public static String createChannelForUserAndCompany(Long userId, Long companyId) {
return GepafinConstant.COMMON_SINGLE_CHANNEL_PREFIX + userId + GepafinConstant.COMPANY_PREFIX + companyId;
}
}