Done ticket GEPAFINBE-39

This commit is contained in:
rajesh
2024-10-11 10:19:23 +05:30
parent 90aae05fa4
commit 8a14059b0c
18 changed files with 531 additions and 4 deletions

View File

@@ -92,4 +92,20 @@ public class DateTimeUtil {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
return LocalDateTime.parse(dateTimeStr, formatter);
}
public static String parseLocalTimeToString(LocalTime time, String format) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
return time.format(formatter);
}
// Method 2: Convert String and format to LocalTime
public static LocalTime parseStringToLocalTime(String timeString, String format) {
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
return LocalTime.parse(timeString, formatter);
} catch (DateTimeParseException e) {
System.out.println("Invalid time format: " + e.getMessage());
return null;
}
}
}

View File

@@ -0,0 +1,78 @@
package net.gepafin.tendermanagement.util;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import com.mailgun.api.v3.MailgunMessagesApi;
import com.mailgun.client.MailgunClient;
@Component
public class MailUtil {
@Value("${apiKey}")
private String apiKeyValue;
@Value("${mailGun_user}")
private String mailGunUser;
@Value("${mailGun_apiKey}")
private String mailGunApiKey;
@Value("${mailGun_domainName}")
private String mailGunDomainName;
@Value("${mailGun_base_url}")
private String mailGunBaseUrl;
@Value("${isMailSendingEnabled}")
private String isEmailSendingEnabled;
@Autowired
private Environment environment;
public Boolean isTestProfileActivated() {
String[] activeProfiles = environment.getActiveProfiles();
return Arrays.stream(activeProfiles).anyMatch("test"::equals);
}
public void sendMailByMailGunAPI(List<String> recipents, List<String> CC, List<String> BCC, String subject,
String body, String replyTo) {
if (Boolean.FALSE.equals(Boolean.parseBoolean(isEmailSendingEnabled))) {
return;
}
MailgunMessagesApi mailgunMessagesApi = MailgunClient.config(mailGunBaseUrl, mailGunApiKey)
.createApi(MailgunMessagesApi.class);
String mailFrom = mailGunUser;
com.mailgun.model.message.Message.MessageBuilder temp = com.mailgun.model.message.Message.builder()
.replyTo(replyTo).from(mailFrom).to(recipents).subject(subject).html(body);
if (Boolean.FALSE.equals(CollectionUtils.isEmpty(CC))) {
temp.cc(CC);
}
if (Boolean.FALSE.equals(CollectionUtils.isEmpty(BCC))) {
temp.bcc(BCC);
}
if (Boolean.FALSE.equals(isTestProfileActivated())) {
com.mailgun.model.message.Message message = temp.build();
mailgunMessagesApi.sendMessage(mailGunDomainName, message);
}
}
public void sendByMailGun(String subject, String body, List<String> receiverEmails, String replyTo) {
sendMailByMailGunAPI(receiverEmails, null, null, subject, body, replyTo);
}
}

View File

@@ -5,6 +5,7 @@ import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
@@ -276,4 +277,30 @@ public class Utils {
}
}
public static Map<String, Map<String, String>> parseJsonContent(String jsonContent) {
ObjectMapper objectMapper = new ObjectMapper();
try {
return mapper.readValue(jsonContent, HashMap.class);
} catch (Exception exception) {
log.error(exception.getMessage());
}
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;
}
// 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 : "");
}
}