package art.servers.transactionsserver.model.access.login; import art.library.model.devices.user.UserIdentification; import art.library.model.transactions.useraccess.AddressLogin; import art.library.utils.mail.MailMessage; import art.servers.transactionsserver.Shared; import java.time.Instant; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.TimeZone; public class BlockingNotificationGenerator { public static MailMessage generateUserBlockedMessage(UserIdentification userIdentification) { MailMessage message = new MailMessage(); message.subject = generateSubject(); message.body = generateBlockedMessageBody( Shared.getMessage("User account") + " " + userIdentification.name + " " + Shared.getMessage("is blocked and needs to be unblock by admin."), userIdentification.timestampEnd, userIdentification.console, userIdentification.name); return message; } public static MailMessage generateAddressBlockedMessage(AddressLogin addresssLogin, String user) { MailMessage message = new MailMessage(); message.subject = generateSubject(); message.body = generateBlockedMessageBody( Shared.getMessage("Address IP") + " " + addresssLogin.loginAddress + " " + Shared.getMessage("is blocked and needs to be unblock by admin."), addresssLogin.timestamp, addresssLogin.loginAddress, user); return message; } private static String generateSubject() { return Shared.getMessage("BLOCKING.NOTIFICATION.GENERATOR.SUBJECT"); } private static String generateBlockedMessageBody(String specificBody, long timestamp, String address, String user) { String body = Shared.getMessage("BLOCKING.NOTIFICATION.GENERATOR.BODY.1") + "\r\n"; body = body + Shared.getMessage("BLOCKING.NOTIFICATION.GENERATOR.BODY.2") + "\r\n"; body = body + "\r\n"; body = body + Shared.getMessage("Date") + " : " + getFormatedCurrentStringDate(timestamp) + "\r\n"; body = body + Shared.getMessage("IP") + " : " + address + "\r\n"; body = body + Shared.getMessage("User") + " : " + user + "\r\n"; body = body + "\r\n"; body = body + specificBody; body = body + "\r\n"; body = body + "\r\n"; body = body + Shared.getMessage("BLOCKING.NOTIFICATION.GENERATOR.BODY.GREETINGS.1"); body = body + "\r\n"; body = body + Shared.getMessage("BLOCKING.NOTIFICATION.GENERATOR.BODY.GREETINGS.2"); body = body + "\r\n"; body = body + Shared.getMessage("BLOCKING.NOTIFICATION.GENERATOR.BODY.GREETINGS.3"); return body; } private static String getFormatedCurrentStringDate(long timestamp) { LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), TimeZone.getDefault().toZoneId()); DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Shared.getMessage("yyyy/MM/dd HH:mm:ss")); return localDateTime.format(formatter); } }