bck
Alejandro Acuña
2024-11-11 f1cb4443aede6d4657bdc3396c8914d3a9f4fa93
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
73
74
75
76
77
78
79
80
package art.servers.transactionsserver.test.persistence;
 
import art.library.interop.serialization.Serialization;
import art.library.model.devices.DevicePersistenceTimeless;
import art.library.model.devices.user.User;
import art.library.model.devices.user.UserInformation;
import art.library.persistence.PersistenceDatabase;
import art.library.persistence.PersistenceDatabaseParameters;
import art.library.utils.licence.Licence;
import java.lang.annotation.Annotation;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
 
public class PersistanceTestUsers
{
 
    static PersistenceDatabase persistence = null;
 
    public static void main(String[] args) throws Exception
    {
        try
        {
            PersistenceDatabaseParameters p = new PersistenceDatabaseParameters();
            p.type = "postgresql";
            p.driver = "org.postgresql.Driver";
            p.connectionString = "jdbc:postgresql://172.16.11.204:5432/ARTIC";
            p.user = "ARTIC";
            p.password = "chronos";
            p.connections = 1;
            p.pendingFolder = "database/pending/timeless";
            p.pendingDays = 7;
            p.pendingTimer = 60;
            persistence = new PersistenceDatabase(p);
 
            User user = new User();
            user.username = Licence.encrypt("root");
            user.information = new UserInformation();
            UserInformation information = user.getDeviceInformation();
            information.password = Licence.encrypt("626d77");
            information.group = "Administrator";
            information.name = "";
            information.surname = "";
            information.role = "Administrator";
            information.email = "sat.sistemas@aluvisagrupo.com";
            information.phone = "937119461";
            information.company = "ALUVISA";
            information.jobTitle = "IT Department";
            information.description = "Information Technology Department";
            
            String data = Serialization.toPrettyString(user);
            System.out.println(data);
            
            persistence.updateOrAddObject(new DevicePersistenceTimeless(user));
            
            List<User> users = (List<User>) (List<?>) persistence.getObject(DevicePersistenceTimeless.class.getName(), "type = '" + User.class.getName() + "'");
 
        } catch (Exception e)
        {
            Logger.getLogger(PersistanceTestUsers.class.getName()).log(Level.INFO, "", e);
        }
    }
 
    public static Object getAnnotation(Class clase, String annotationName, String attributeName) throws Exception
    {
        Annotation[] annotations = clase.getDeclaredAnnotations();
 
        for (Annotation annotation : annotations)
        {
            if (annotation.annotationType().getSimpleName().equals(annotationName))
            {
                Object result = annotation.annotationType().getMethod(attributeName).invoke(annotation);
                return result;
            }
        }
 
        throw new Exception();
    }
 
}