/
InteractionPreference.java
268 lines (216 loc) · 7.17 KB
/
InteractionPreference.java
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/**
*
*/
package net.sf.taverna.t2.activities.interaction.preference;
import java.awt.GraphicsEnvironment;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;
import org.apache.log4j.Logger;
import uk.org.taverna.configuration.app.ApplicationConfiguration;
/**
* @author alanrw
*
*/
public class InteractionPreference {
private ApplicationConfiguration appConfig;
private static final String USE_JETTY = "useJetty";
private static final String DEFAULT_USE_JETTY = "true";
private static final String PORT = "port";
private static final String DEFAULT_PORT = "8080";
private static final String HOST = "host";
private static final String DEFAULT_HOST = "http://localhost";
private static final String WEBDAV_PATH = "webdavPath";
private static final String DEFAULT_WEBDAV_PATH = "/interaction";
private static final String FEED_PATH = "feedPath";
private static final String DEFAULT_FEED_PATH = "/feed";
private static final String USE_USERNAME = "Secure with username / password";
private static final String DEFAULT_USE_USERNAME = "false";
// private static final String USE_HTTPS = "Use HTTPS";
// private static final String DEFAULT_USE_HTTPS = "false";
private final Logger logger = Logger.getLogger(InteractionPreference.class);
private final Properties properties;
private File getConfigFile() {
final File home = appConfig
.getApplicationHomeDir();
final File config = new File(home, "conf");
if (!config.exists()) {
config.mkdir();
}
final File configFile = new File(config, this.getFilePrefix() + "-"
+ this.getUUID() + ".config");
return configFile;
}
private InteractionPreference(ApplicationConfiguration appConfig) {
setAppConfig(appConfig);
final File configFile = this.getConfigFile();
this.properties = new Properties();
if (configFile.exists()) {
try {
final FileReader reader = new FileReader(configFile);
this.properties.load(reader);
reader.close();
} catch (final FileNotFoundException e) {
this.logger.error(e);
} catch (final IOException e) {
this.logger.error(e);
}
}
if (GraphicsEnvironment.isHeadless()
|| ((System.getProperty("java.awt.headless") != null) && System
.getProperty("java.awt.headless").equals("true"))) {
final String definedHost = System
.getProperty("taverna.interaction.host");
if (definedHost != null) {
this.properties.setProperty(USE_JETTY, "false");
this.logger.info("USE_JETTY set to false");
this.properties.setProperty(HOST, definedHost);
}
final String definedPort = System
.getProperty("taverna.interaction.port");
if (definedPort != null) {
this.properties.setProperty(PORT, definedPort);
}
final String definedWebDavPath = System
.getProperty("taverna.interaction.webdav_path");
if (definedWebDavPath != null) {
this.properties.setProperty(WEBDAV_PATH, definedWebDavPath);
}
final String definedFeedPath = System
.getProperty("taverna.interaction.feed_path");
if (definedFeedPath != null) {
this.properties.setProperty(FEED_PATH, definedFeedPath);
}
} else {
this.logger.info("Running non-headless");
}
this.fillDefaultProperties();
}
private void fillDefaultProperties() {
if (!this.properties.containsKey(USE_JETTY)) {
this.properties.setProperty(USE_JETTY, DEFAULT_USE_JETTY);
this.logger.info("USE_JETTY set to " + DEFAULT_USE_JETTY);
}
if (!this.properties.containsKey(PORT)) {
this.properties.setProperty(PORT, DEFAULT_PORT);
}
if (!this.properties.containsKey(HOST)) {
this.properties.setProperty(HOST, DEFAULT_HOST);
}
if (!this.properties.containsKey(WEBDAV_PATH)) {
this.properties.setProperty(WEBDAV_PATH, DEFAULT_WEBDAV_PATH);
}
if (!this.properties.containsKey(FEED_PATH)) {
this.properties.setProperty(FEED_PATH, DEFAULT_FEED_PATH);
}
if (!this.properties.containsKey(USE_USERNAME)) {
this.properties.setProperty(USE_USERNAME, DEFAULT_USE_USERNAME);
}
/*
* if (!properties.containsKey(USE_HTTPS)) {
* properties.setProperty(USE_HTTPS, DEFAULT_USE_HTTPS); }
*/
}
public String getFilePrefix() {
return "Interaction";
}
public void store() {
try {
final FileOutputStream out = new FileOutputStream(
this.getConfigFile());
this.properties.store(out, "");
out.close();
} catch (final FileNotFoundException e) {
this.logger.error(e);
} catch (final IOException e) {
this.logger.error(e);
}
}
public String getUUID() {
return "DA992717-5A46-469D-AE25-883F0E4CD348";
}
public void setPort(final String text) {
this.properties.setProperty(PORT, text);
}
public void setHost(final String text) {
this.properties.setProperty(HOST, text);
}
public void setUseJetty(final boolean use) {
this.properties.setProperty(USE_JETTY, Boolean.toString(use));
}
public void setFeedPath(final String path) {
this.properties.setProperty(FEED_PATH, path);
}
public void setWebDavPath(final String path) {
this.properties.setProperty(WEBDAV_PATH, path);
}
public String getPort() {
return this.properties.getProperty(PORT);
}
public String getHost() {
return this.properties.getProperty(HOST);
}
public boolean getUseJetty() {
return (Boolean.parseBoolean(this.properties.getProperty(USE_JETTY)));
}
public String getFeedPath() {
return this.properties.getProperty(FEED_PATH);
}
public String getWebDavPath() {
return this.properties.getProperty(WEBDAV_PATH);
}
public String getDefaultHost() {
return DEFAULT_HOST;
}
public String getDefaultFeedPath() {
return DEFAULT_FEED_PATH;
}
public String getDefaultWebDavPath() {
return DEFAULT_WEBDAV_PATH;
}
public String getFeedUrlString() {
return this.getHost() + ":" + this.getPort() + this.getFeedPath();
}
public String getLocationUrl() {
return this.getHost() + ":" + this.getPort() + this.getWebDavPath();
}
public boolean getUseUsername() {
return (Boolean.parseBoolean(this.properties.getProperty(USE_USERNAME)));
}
public void setUseUsername(final boolean useUsername) {
this.properties
.setProperty(USE_USERNAME, Boolean.toString(useUsername));
}
public String getOutputDataUrlString(final String interactionId) {
return this.getLocationUrl()
+ "/interaction" + interactionId + "OutputData.json";
}
public String getInputDataUrlString(final String interactionId) {
return this.getLocationUrl()
+ "/interaction" + interactionId + "InputData.json";
}
public URL getFeedUrl() throws MalformedURLException {
return new URL(this.getFeedUrlString());
}
public String getInteractionUrlString(final String interactionId) {
return this.getLocationUrl()
+ "/interaction" + interactionId + ".html";
}
public String getPresentationUrlString(final String interactionId) {
return this.getLocationUrl()
+ "/presentation" + interactionId + ".html";
}
public String getPublicationUrlString(final String interactionId,
final String key) {
return this.getLocationUrl()
+ "/interaction" + interactionId + "_" + key;
}
public void setAppConfig(ApplicationConfiguration appConfig) {
this.appConfig = appConfig;
}
}