Alejandro Acuña
2024-07-30 65a64a81d30f00f1fffd5da6866850e1308e1135
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.model.configuration;
 
import art.library.interop.InteropParameters;
import art.library.interop.InteropResponse;
import art.library.interop.serialization.Serialization;
import art.library.interop.serialization.SerializationException;
import art.library.model.transactions.messages.ConfigurationLanguage;
import art.library.utils.resources.Resources;
import art.servers.transactionsserver.Shared;
import java.io.File;
import java.io.FileInputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
 
public class ModelMessages
{
 
    public ModelMessages() throws Exception
    {
    }
 
    //<editor-fold defaultstate="collapsed" desc="Messages">
     /**
     * @param parameters <code>InteropParameters</code>
     * <p>name: "language" class: <code>String</code>
     * @return <code>InteropResponse</code> 
     * <code>ConfigurationLanguage</code>
     * @throws SerializationException 
     */
    public InteropResponse getConfigurationLanguage(InteropParameters parameters) throws SerializationException
    {
        String language = (String)parameters.getParameterValue("language");
        try
        {
            long timestamp = parameters.hasParameter("timestamp") ? Long.parseLong((String) parameters.getParameterValue("timestamp")) : 0L;
            
            File file = Resources.getResourceFile("data/" + Shared.getApplicationName() + ".messagesclient.json");
            if (file.lastModified() > timestamp)
            {
                ConfigurationLanguage configurationLanguage = (ConfigurationLanguage) Serialization.deserialize(ConfigurationLanguage.class.getName(),
                        new FileInputStream("data/" + Shared.getApplicationName() + ".messagesclient.json"));
                return new InteropResponse(configurationLanguage);
            }
 
            return new InteropResponse(new ConfigurationLanguage());
        } catch (Exception e)
        {
            String msg = "error getting messages";
            throw new SerializationException(e.getMessage());
        }
    }
 
    /**
     * @param parameters <code>InteropParameters</code>
     * <p>name: "language" class: <code>String</code>
     * <p>name: "configurationLanguage" class: <code>String[]</code>
     * @return <code>InteropResponse</code> 
     * <code>Boolean</code>
     * @throws SerializationException 
    */
    public InteropResponse setConfigurationLanguage(InteropParameters parameters) throws SerializationException
    {
        String language = (String)parameters.getParameterValue("language");
        ConfigurationLanguage configurationLanguage = (ConfigurationLanguage)parameters.getParameterValue("configurationLanguage");
        
        if ((configurationLanguage != null) && configurationLanguage.messages != null)
        {
            try
            {
                Serialization.serialize(configurationLanguage, new File("data/" + Shared.getApplicationName() + ".messagesclient.json"));
            } catch (Exception ex)
            {
                Logger.getLogger(ModelMessages.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return new InteropResponse(true);
    }
    //</editor-fold>
 
}