Commit 534408fe authored by helene ortiz's avatar helene ortiz
Browse files

allow virtual clients to set their own home directory

parent 3639c498
......@@ -57,15 +57,15 @@ import fr.ill.ics.util.exception.PropertyNotFoundException;
* </p>
*/
public class ConfigManager {
public final static String PROPERTIES_EXTENSION = ".properties";
public final static String PROPERTIES_PATTERN = "Properties.xml";
public final static String VIEW_PATTERN = "View.xml";
public final static String COMMAND_VIEW_PATTERN = "CommandView.xml";
public static final String DOT_NOMAD_DIRECTORY = ".nomad";
public static final String DEFAULT_LOCAL_FILES_DIRECTORY = ".nomad";
public static final String NOMAD_CHAT_FILES = ".nomadChats";
public final static String USER_HOME = System.getProperty("user.home");
public final static String NOMAD_CLIENT_FILES = USER_HOME;
......@@ -90,7 +90,7 @@ public class ConfigManager {
public final static String MAGNIFY_FACTOR_INDEX = "MAGNIFY_FACTOR_INDEX";
public final static String REMOTE_USER_NAME = "REMOTE_USER_NAME";
public final static String REMOTE_INSTRUMENT = "REMOTE_INSTRUMENT";
public final static String USE_NOMADLOGS = "USE_NOMADLOGS";
public final static String X_CONDITIONS_SPY = "X_CONDITIONS_SPY";
......@@ -105,7 +105,7 @@ public class ConfigManager {
public static final String COMMAND_LINE_PARALLEL_SEPARATOR = "; ";
public static final String COMMAND_LINE_SEQUENTIAL_SEPARATOR = "\n";
public static final String COMMAND_LINE_BACKGROUND_SEPARATOR = "&";
public static final String CLIENT_TYPE_PROPERTY = "clientType";
public final static String FCU_EXTENSION = ".txt";
......@@ -116,11 +116,12 @@ public class ConfigManager {
public static boolean CONFIGURATION_ERROR = false;
private static Set<ConfigurationException> configurationExceptions;
private boolean remoteClient = false;
private boolean mainClient = true;
private String clientType;
private String localFilesDirectory = DEFAULT_LOCAL_FILES_DIRECTORY;
/**
* @return the unique instance of this class
......@@ -192,7 +193,7 @@ public class ConfigManager {
if (files != null) {
propertiesFiles.addAll(Arrays.asList(files));
}
// Load all .properties files from USER_HOME/.nomad directory
files = FileHelper.getFilesListByExtension(USER_HOME + FILE_SEPARATOR + ".nomad" + FILE_SEPARATOR, PROPERTIES_EXTENSION, true, true);
if (files != null) {
......@@ -233,7 +234,7 @@ public class ConfigManager {
clientType = getString(ConfigManager.CLIENT_TYPE_PROPERTY).toLowerCase();
mainClient = (clientType.equals(TokenManager.ClientType.MAIN.toString().toLowerCase()) || clientType.equals(TokenManager.ClientType.TABLET.toString().toLowerCase()));
remoteClient = !mainClient;
initPreferences();
}
......@@ -499,7 +500,7 @@ public class ConfigManager {
if (configurationExceptions == null) {
configurationExceptions = new HashSet<ConfigurationException>();
}
if (configurationExceptions.add(configurationException)) {
// First time for this property
//System.out.println("Exception added: " + configurationException + " FROM " + configurationException.getClassName() + ".." + configurationException.getMethodName());
......@@ -528,7 +529,7 @@ public class ConfigManager {
}
} else if (configurationException instanceof CommandNotFoundException) {
CommandNotFoundException cnfe = (CommandNotFoundException)configurationException;
if (cnfe.getControllerName() != null && cnfe.getControllerName().equals(controllerName)) {
if (set == null) {
......@@ -536,7 +537,7 @@ public class ConfigManager {
}
set.add(cnfe);
}
} else if (configurationException instanceof ParticularWidgetNotFoundException) {
ParticularWidgetNotFoundException pwnfe = (ParticularWidgetNotFoundException)configurationException;
if (pwnfe.getControllerName().equals(controllerName)) {
......@@ -563,50 +564,50 @@ public class ConfigManager {
public Set<ConfigurationException> getConfigurationExceptions() {
return configurationExceptions;
}
public String getServerEndpoint() {
// The server endpoint can be entirely defined in the variable 'serverEndpoint'.
String serverEndpoint = getStringOrNothingAtAll("serverEndpoint");
if (serverEndpoint != null) {
System.out.println("================> serverEndPoint " + serverEndpoint);
return serverEndpoint;
}
// The server endpoint can be partially defined in the variable 'serverPort'.
// In that case, the own IP address is used.
// It is necessary in case of a remote client because this endpoint is passed to the server responder to contact the client for its response.
// In future implementation of requester/responder this may not be necessary.
String serverPort = getStringOrNothingAtAll("serverPort");
// Default value for port.
if (serverPort == null) {
serverPort = "7000";
}
try {
serverEndpoint = "tcp://" + InetAddress.getLocalHost().getHostAddress() + ":" + serverPort;
System.out.println("================> serverEndPoint " + serverEndpoint);
return serverEndpoint;
} catch (UnknownHostException e) {
}
return "tcp://localhost:7000";
}
public String getNomadServerEndpoint() {
String nomadServerEndpoint = getStringOrNothingAtAll("nomadServerEndpoint");
if (nomadServerEndpoint != null) {
System.out.println("================> nomadServerEndPoint " + nomadServerEndpoint);
return nomadServerEndpoint;
}
return "tcp://localhost:7000";
}
public boolean mockMode() {
String value = getStringOrNothingAtAll("mockMode");
if (value != null) {
......@@ -614,7 +615,7 @@ public class ConfigManager {
}
return false;
}
public boolean isRemoteClient() {
return remoteClient;
}
......@@ -626,4 +627,22 @@ public class ConfigManager {
public String getClientType() {
return clientType;
}
public String getLocalFilesDirectory() {
return localFilesDirectory;
}
public void setLocalFilesDirectory(String localFilesDirectory) {
if (!new File(localFilesDirectory).exists()) {
// Directory does not exist: create it
File file = new File(localFilesDirectory);
file.mkdir();
}
if (!new File(localFilesDirectory + ConfigManager.FILE_SEPARATOR + ConfigManager.NOMAD_CHAT_FILES).exists()) {
// Directory for chat's files does not exist: create it
File file = new File(localFilesDirectory + ConfigManager.FILE_SEPARATOR + ConfigManager.NOMAD_CHAT_FILES);
file.mkdir();
}
this.localFilesDirectory = localFilesDirectory;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment