Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Instrument Control
NomadCommandSystem
Commits
534408fe
Commit
534408fe
authored
Apr 16, 2020
by
helene ortiz
Browse files
allow virtual clients to set their own home directory
parent
3639c498
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/fr/ill/ics/util/ConfigManager.java
View file @
534408fe
...
@@ -57,15 +57,15 @@ import fr.ill.ics.util.exception.PropertyNotFoundException;
...
@@ -57,15 +57,15 @@ import fr.ill.ics.util.exception.PropertyNotFoundException;
* </p>
* </p>
*/
*/
public
class
ConfigManager
{
public
class
ConfigManager
{
public
final
static
String
PROPERTIES_EXTENSION
=
".properties"
;
public
final
static
String
PROPERTIES_EXTENSION
=
".properties"
;
public
final
static
String
PROPERTIES_PATTERN
=
"Properties.xml"
;
public
final
static
String
PROPERTIES_PATTERN
=
"Properties.xml"
;
public
final
static
String
VIEW_PATTERN
=
"View.xml"
;
public
final
static
String
VIEW_PATTERN
=
"View.xml"
;
public
final
static
String
COMMAND_VIEW_PATTERN
=
"CommandView.xml"
;
public
final
static
String
COMMAND_VIEW_PATTERN
=
"CommandView.xml"
;
public
static
final
String
D
OT_NOMAD
_DIRECTORY
=
".nomad"
;
public
static
final
String
D
EFAULT_LOCAL_FILES
_DIRECTORY
=
".nomad"
;
public
static
final
String
NOMAD_CHAT_FILES
=
".nomadChats"
;
public
static
final
String
NOMAD_CHAT_FILES
=
".nomadChats"
;
public
final
static
String
USER_HOME
=
System
.
getProperty
(
"user.home"
);
public
final
static
String
USER_HOME
=
System
.
getProperty
(
"user.home"
);
public
final
static
String
NOMAD_CLIENT_FILES
=
USER_HOME
;
public
final
static
String
NOMAD_CLIENT_FILES
=
USER_HOME
;
...
@@ -90,7 +90,7 @@ public class ConfigManager {
...
@@ -90,7 +90,7 @@ public class ConfigManager {
public
final
static
String
MAGNIFY_FACTOR_INDEX
=
"MAGNIFY_FACTOR_INDEX"
;
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_USER_NAME
=
"REMOTE_USER_NAME"
;
public
final
static
String
REMOTE_INSTRUMENT
=
"REMOTE_INSTRUMENT"
;
public
final
static
String
REMOTE_INSTRUMENT
=
"REMOTE_INSTRUMENT"
;
public
final
static
String
USE_NOMADLOGS
=
"USE_NOMADLOGS"
;
public
final
static
String
USE_NOMADLOGS
=
"USE_NOMADLOGS"
;
public
final
static
String
X_CONDITIONS_SPY
=
"X_CONDITIONS_SPY"
;
public
final
static
String
X_CONDITIONS_SPY
=
"X_CONDITIONS_SPY"
;
...
@@ -105,7 +105,7 @@ public class ConfigManager {
...
@@ -105,7 +105,7 @@ public class ConfigManager {
public
static
final
String
COMMAND_LINE_PARALLEL_SEPARATOR
=
"; "
;
public
static
final
String
COMMAND_LINE_PARALLEL_SEPARATOR
=
"; "
;
public
static
final
String
COMMAND_LINE_SEQUENTIAL_SEPARATOR
=
"\n"
;
public
static
final
String
COMMAND_LINE_SEQUENTIAL_SEPARATOR
=
"\n"
;
public
static
final
String
COMMAND_LINE_BACKGROUND_SEPARATOR
=
"&"
;
public
static
final
String
COMMAND_LINE_BACKGROUND_SEPARATOR
=
"&"
;
public
static
final
String
CLIENT_TYPE_PROPERTY
=
"clientType"
;
public
static
final
String
CLIENT_TYPE_PROPERTY
=
"clientType"
;
public
final
static
String
FCU_EXTENSION
=
".txt"
;
public
final
static
String
FCU_EXTENSION
=
".txt"
;
...
@@ -116,11 +116,12 @@ public class ConfigManager {
...
@@ -116,11 +116,12 @@ public class ConfigManager {
public
static
boolean
CONFIGURATION_ERROR
=
false
;
public
static
boolean
CONFIGURATION_ERROR
=
false
;
private
static
Set
<
ConfigurationException
>
configurationExceptions
;
private
static
Set
<
ConfigurationException
>
configurationExceptions
;
private
boolean
remoteClient
=
false
;
private
boolean
remoteClient
=
false
;
private
boolean
mainClient
=
true
;
private
boolean
mainClient
=
true
;
private
String
clientType
;
private
String
clientType
;
private
String
localFilesDirectory
=
DEFAULT_LOCAL_FILES_DIRECTORY
;
/**
/**
* @return the unique instance of this class
* @return the unique instance of this class
...
@@ -192,7 +193,7 @@ public class ConfigManager {
...
@@ -192,7 +193,7 @@ public class ConfigManager {
if
(
files
!=
null
)
{
if
(
files
!=
null
)
{
propertiesFiles
.
addAll
(
Arrays
.
asList
(
files
));
propertiesFiles
.
addAll
(
Arrays
.
asList
(
files
));
}
}
// Load all .properties files from USER_HOME/.nomad directory
// Load all .properties files from USER_HOME/.nomad directory
files
=
FileHelper
.
getFilesListByExtension
(
USER_HOME
+
FILE_SEPARATOR
+
".nomad"
+
FILE_SEPARATOR
,
PROPERTIES_EXTENSION
,
true
,
true
);
files
=
FileHelper
.
getFilesListByExtension
(
USER_HOME
+
FILE_SEPARATOR
+
".nomad"
+
FILE_SEPARATOR
,
PROPERTIES_EXTENSION
,
true
,
true
);
if
(
files
!=
null
)
{
if
(
files
!=
null
)
{
...
@@ -233,7 +234,7 @@ public class ConfigManager {
...
@@ -233,7 +234,7 @@ public class ConfigManager {
clientType
=
getString
(
ConfigManager
.
CLIENT_TYPE_PROPERTY
).
toLowerCase
();
clientType
=
getString
(
ConfigManager
.
CLIENT_TYPE_PROPERTY
).
toLowerCase
();
mainClient
=
(
clientType
.
equals
(
TokenManager
.
ClientType
.
MAIN
.
toString
().
toLowerCase
())
||
clientType
.
equals
(
TokenManager
.
ClientType
.
TABLET
.
toString
().
toLowerCase
()));
mainClient
=
(
clientType
.
equals
(
TokenManager
.
ClientType
.
MAIN
.
toString
().
toLowerCase
())
||
clientType
.
equals
(
TokenManager
.
ClientType
.
TABLET
.
toString
().
toLowerCase
()));
remoteClient
=
!
mainClient
;
remoteClient
=
!
mainClient
;
initPreferences
();
initPreferences
();
}
}
...
@@ -499,7 +500,7 @@ public class ConfigManager {
...
@@ -499,7 +500,7 @@ public class ConfigManager {
if
(
configurationExceptions
==
null
)
{
if
(
configurationExceptions
==
null
)
{
configurationExceptions
=
new
HashSet
<
ConfigurationException
>();
configurationExceptions
=
new
HashSet
<
ConfigurationException
>();
}
}
if
(
configurationExceptions
.
add
(
configurationException
))
{
if
(
configurationExceptions
.
add
(
configurationException
))
{
// First time for this property
// First time for this property
//System.out.println("Exception added: " + configurationException + " FROM " + configurationException.getClassName() + ".." + configurationException.getMethodName());
//System.out.println("Exception added: " + configurationException + " FROM " + configurationException.getClassName() + ".." + configurationException.getMethodName());
...
@@ -528,7 +529,7 @@ public class ConfigManager {
...
@@ -528,7 +529,7 @@ public class ConfigManager {
}
}
}
else
if
(
configurationException
instanceof
CommandNotFoundException
)
{
}
else
if
(
configurationException
instanceof
CommandNotFoundException
)
{
CommandNotFoundException
cnfe
=
(
CommandNotFoundException
)
configurationException
;
CommandNotFoundException
cnfe
=
(
CommandNotFoundException
)
configurationException
;
if
(
cnfe
.
getControllerName
()
!=
null
&&
cnfe
.
getControllerName
().
equals
(
controllerName
))
{
if
(
cnfe
.
getControllerName
()
!=
null
&&
cnfe
.
getControllerName
().
equals
(
controllerName
))
{
if
(
set
==
null
)
{
if
(
set
==
null
)
{
...
@@ -536,7 +537,7 @@ public class ConfigManager {
...
@@ -536,7 +537,7 @@ public class ConfigManager {
}
}
set
.
add
(
cnfe
);
set
.
add
(
cnfe
);
}
}
}
else
if
(
configurationException
instanceof
ParticularWidgetNotFoundException
)
{
}
else
if
(
configurationException
instanceof
ParticularWidgetNotFoundException
)
{
ParticularWidgetNotFoundException
pwnfe
=
(
ParticularWidgetNotFoundException
)
configurationException
;
ParticularWidgetNotFoundException
pwnfe
=
(
ParticularWidgetNotFoundException
)
configurationException
;
if
(
pwnfe
.
getControllerName
().
equals
(
controllerName
))
{
if
(
pwnfe
.
getControllerName
().
equals
(
controllerName
))
{
...
@@ -563,50 +564,50 @@ public class ConfigManager {
...
@@ -563,50 +564,50 @@ public class ConfigManager {
public
Set
<
ConfigurationException
>
getConfigurationExceptions
()
{
public
Set
<
ConfigurationException
>
getConfigurationExceptions
()
{
return
configurationExceptions
;
return
configurationExceptions
;
}
}
public
String
getServerEndpoint
()
{
public
String
getServerEndpoint
()
{
// The server endpoint can be entirely defined in the variable 'serverEndpoint'.
// The server endpoint can be entirely defined in the variable 'serverEndpoint'.
String
serverEndpoint
=
getStringOrNothingAtAll
(
"serverEndpoint"
);
String
serverEndpoint
=
getStringOrNothingAtAll
(
"serverEndpoint"
);
if
(
serverEndpoint
!=
null
)
{
if
(
serverEndpoint
!=
null
)
{
System
.
out
.
println
(
"================> serverEndPoint "
+
serverEndpoint
);
System
.
out
.
println
(
"================> serverEndPoint "
+
serverEndpoint
);
return
serverEndpoint
;
return
serverEndpoint
;
}
}
// The server endpoint can be partially defined in the variable 'serverPort'.
// The server endpoint can be partially defined in the variable 'serverPort'.
// In that case, the own IP address is used.
// 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.
// 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.
// In future implementation of requester/responder this may not be necessary.
String
serverPort
=
getStringOrNothingAtAll
(
"serverPort"
);
String
serverPort
=
getStringOrNothingAtAll
(
"serverPort"
);
// Default value for port.
// Default value for port.
if
(
serverPort
==
null
)
{
if
(
serverPort
==
null
)
{
serverPort
=
"7000"
;
serverPort
=
"7000"
;
}
}
try
{
try
{
serverEndpoint
=
"tcp://"
+
InetAddress
.
getLocalHost
().
getHostAddress
()
+
":"
+
serverPort
;
serverEndpoint
=
"tcp://"
+
InetAddress
.
getLocalHost
().
getHostAddress
()
+
":"
+
serverPort
;
System
.
out
.
println
(
"================> serverEndPoint "
+
serverEndpoint
);
System
.
out
.
println
(
"================> serverEndPoint "
+
serverEndpoint
);
return
serverEndpoint
;
return
serverEndpoint
;
}
catch
(
UnknownHostException
e
)
{
}
catch
(
UnknownHostException
e
)
{
}
}
return
"tcp://localhost:7000"
;
return
"tcp://localhost:7000"
;
}
}
public
String
getNomadServerEndpoint
()
{
public
String
getNomadServerEndpoint
()
{
String
nomadServerEndpoint
=
getStringOrNothingAtAll
(
"nomadServerEndpoint"
);
String
nomadServerEndpoint
=
getStringOrNothingAtAll
(
"nomadServerEndpoint"
);
if
(
nomadServerEndpoint
!=
null
)
{
if
(
nomadServerEndpoint
!=
null
)
{
System
.
out
.
println
(
"================> nomadServerEndPoint "
+
nomadServerEndpoint
);
System
.
out
.
println
(
"================> nomadServerEndPoint "
+
nomadServerEndpoint
);
return
nomadServerEndpoint
;
return
nomadServerEndpoint
;
}
}
return
"tcp://localhost:7000"
;
return
"tcp://localhost:7000"
;
}
}
public
boolean
mockMode
()
{
public
boolean
mockMode
()
{
String
value
=
getStringOrNothingAtAll
(
"mockMode"
);
String
value
=
getStringOrNothingAtAll
(
"mockMode"
);
if
(
value
!=
null
)
{
if
(
value
!=
null
)
{
...
@@ -614,7 +615,7 @@ public class ConfigManager {
...
@@ -614,7 +615,7 @@ public class ConfigManager {
}
}
return
false
;
return
false
;
}
}
public
boolean
isRemoteClient
()
{
public
boolean
isRemoteClient
()
{
return
remoteClient
;
return
remoteClient
;
}
}
...
@@ -626,4 +627,22 @@ public class ConfigManager {
...
@@ -626,4 +627,22 @@ public class ConfigManager {
public
String
getClientType
()
{
public
String
getClientType
()
{
return
clientType
;
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
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment