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>
|
|
}
|