Alejandro Acuña
2024-08-12 831c7bd85763b5eb5ef46664c65f0181824f9e13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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);
    }
}