Skip to content

Commit fa85b79

Browse files
committed
Merge branch 'maeisabelle-130-RememberLastInputPath'
2 parents f8ba29f + e5cf7b6 commit fa85b79

File tree

8 files changed

+146
-78
lines changed

8 files changed

+146
-78
lines changed

marklogic-data-hub/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ dependencies {
2626
compile 'com.marklogic:ml-app-deployer:2.0'
2727
compile 'commons-io:commons-io:2.4'
2828
compile 'org.apache.commons:commons-csv:1.2'
29-
compile('com.marklogic:mlcp:8.0-4') {
29+
compile('com.marklogic:mlcp:8.0-5') {
3030
exclude module : 'servlet-api'
3131
exclude group: 'com.google.guava', module: 'guava'
3232
}
33-
compile 'com.google.guava:guava:11.0.2'
33+
compile 'com.google.guava:guava:19.0'
3434
testCompile 'org.springframework.batch:spring-batch-test:3.0.6.RELEASE'
3535
testCompile 'junit:junit:4.12'
3636
testCompile 'xmlunit:xmlunit:1.3'

marklogic-data-hub/src/main/java/com/marklogic/hub/DataHubContentPump.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void execute() throws IOException {
5252
// run mlcp
5353
expandedArgs = OptionsFileUtil.expandArguments(arguments);
5454
runCommand(expandedArgs);
55-
} catch (Exception ex) {
55+
} catch (Throwable ex) {
5656
LOG.error("Error while expanding arguments", ex);
5757
System.err.println(ex.getMessage());
5858
System.err.println("Try 'mlcp help' for usage.");

quick-start/src/main/java/com/marklogic/hub/config/EnvironmentConfiguration.java

Lines changed: 77 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@
1717

1818
/***
1919
*
20-
* @author mturiana This class is used to get the value of the keys in
21-
* application.properties
20+
* @author mturiana
21+
*
22+
* This class is used to get the value of the keys from the properties file
2223
*/
2324
@Component
2425
public class EnvironmentConfiguration {
2526

2627
private static final Logger LOGGER = LoggerFactory
2728
.getLogger(EnvironmentConfiguration.class);
2829

29-
private static final String PROPERTIES_FILENAME = "environment.properties";
30+
private static final String ENVIRONMENT_PROPERTIES_FILENAME = "environment.properties";
31+
private static final String FLOW_PROPERTIES_FILENAME = "flow.properties";
3032
private static final String DEFAULT_SUFFIX = ".default";
3133
private static final String SERVER_PORT = "server.port";
3234
private static final String ML_HOST = "mlHost";
@@ -41,183 +43,194 @@ public class EnvironmentConfiguration {
4143
@Autowired
4244
private Environment environment;
4345

44-
private Properties properties = new Properties();
46+
private Properties environmentProperties = new Properties();
47+
private Properties flowProperties = new Properties();
4548

4649
public String getServerPort() {
4750
return this.environment.getProperty(SERVER_PORT);
4851
}
4952

5053
public String getMLHost() {
51-
String value = this.properties.getProperty(ML_HOST);
54+
String value = this.environmentProperties.getProperty(ML_HOST);
5255
if (value != null) {
5356
return value;
5457
}
5558
value = this.environment.getProperty(ML_HOST);
5659
if (value != null) {
57-
this.properties.setProperty(ML_HOST, value);
60+
this.environmentProperties.setProperty(ML_HOST, value);
5861
return value;
5962
}
6063
return this.environment.getProperty(ML_HOST + DEFAULT_SUFFIX);
6164
}
6265

6366
public String getMLUsername() {
64-
String value = this.properties.getProperty(ML_USERNAME);
67+
String value = this.environmentProperties.getProperty(ML_USERNAME);
6568
if (value != null) {
6669
return value;
6770
}
6871
value = this.environment.getProperty(ML_USERNAME);
6972
if (value != null) {
70-
this.properties.setProperty(ML_USERNAME, value);
73+
this.environmentProperties.setProperty(ML_USERNAME, value);
7174
return value;
7275
}
7376
return this.environment.getProperty(ML_USERNAME + DEFAULT_SUFFIX);
7477
}
7578

7679
public String getMLPassword() {
77-
String value = this.properties.getProperty("mlPassword");
80+
String value = this.environmentProperties.getProperty("mlPassword");
7881
if (value != null) {
7982
return value;
8083
}
8184
value = this.environment.getProperty(ML_PASSWORD);
8285
if (value != null) {
83-
this.properties.setProperty(ML_PASSWORD, value);
86+
this.environmentProperties.setProperty(ML_PASSWORD, value);
8487
return value;
8588
}
8689
return this.environment.getProperty(ML_PASSWORD + DEFAULT_SUFFIX);
8790
}
8891

8992
public String getMLStagingRestPort() {
90-
String value = this.properties.getProperty(ML_STAGING_REST_PORT);
93+
String value = this.environmentProperties.getProperty(ML_STAGING_REST_PORT);
9194
if (value != null) {
9295
return value;
9396
}
9497
value = this.environment.getProperty(ML_STAGING_REST_PORT);
9598
if (value != null) {
96-
this.properties.setProperty(ML_STAGING_REST_PORT, value);
99+
this.environmentProperties.setProperty(ML_STAGING_REST_PORT, value);
97100
return value;
98101
}
99102
return this.environment.getProperty(ML_STAGING_REST_PORT + DEFAULT_SUFFIX);
100103
}
101104

102105
public String getMLFinalRestPort() {
103-
String value = this.properties.getProperty(ML_FINAL_REST_PORT);
106+
String value = this.environmentProperties.getProperty(ML_FINAL_REST_PORT);
104107
if (value != null) {
105108
return value;
106109
}
107110
value = this.environment.getProperty(ML_FINAL_REST_PORT);
108111
if (value != null) {
109-
this.properties.setProperty(ML_FINAL_REST_PORT, value);
112+
this.environmentProperties.setProperty(ML_FINAL_REST_PORT, value);
110113
return value;
111114
}
112115
return this.environment.getProperty(ML_FINAL_REST_PORT + DEFAULT_SUFFIX);
113116
}
114117

115118
public String getMLAuth() {
116-
String value = this.properties.getProperty(ML_AUTH);
119+
String value = this.environmentProperties.getProperty(ML_AUTH);
117120
if (value != null) {
118121
return value;
119122
}
120123
value = this.environment.getProperty(ML_AUTH);
121124
if (value != null) {
122-
this.properties.setProperty(ML_AUTH, value);
125+
this.environmentProperties.setProperty(ML_AUTH, value);
123126
return value;
124127
}
125128
return this.environment.getProperty(ML_AUTH + DEFAULT_SUFFIX);
126129
}
127130

128131
public String getUserPluginDir() {
129-
String value = this.properties.getProperty(USER_PLUGIN_DIR);
132+
String value = this.environmentProperties.getProperty(USER_PLUGIN_DIR);
130133
if (value != null) {
131134
return value;
132135
}
133136
value = this.environment.getProperty(USER_PLUGIN_DIR);
134137
if (value != null) {
135-
this.properties.setProperty(USER_PLUGIN_DIR, value);
138+
this.environmentProperties.setProperty(USER_PLUGIN_DIR, value);
136139
return value;
137140
}
138141
return this.environment.getProperty(USER_PLUGIN_DIR + DEFAULT_SUFFIX);
139142
}
140143

141144
public String getAssetInstallTimeFilePath() {
142-
String value = this.properties.getProperty(ASSET_INSTALL_TIME_FILE);
145+
String value = this.environmentProperties.getProperty(ASSET_INSTALL_TIME_FILE);
143146
if (value != null) {
144147
return value;
145148
}
146149
value = this.environment.getProperty(ASSET_INSTALL_TIME_FILE);
147150
if (value != null) {
148-
this.properties.setProperty(ASSET_INSTALL_TIME_FILE, value);
151+
this.environmentProperties.setProperty(ASSET_INSTALL_TIME_FILE, value);
149152
return value;
150153
}
151154
return "./assetInstallTime.properties";
152155
}
153156

154157
public void setMLHost(String mlHost) {
155-
this.properties.setProperty(ML_HOST, mlHost);
158+
this.environmentProperties.setProperty(ML_HOST, mlHost);
156159
}
157160

158161
public void setMLStagingRestPort(String mlStagingRestPort) {
159-
this.properties.setProperty(ML_STAGING_REST_PORT, mlStagingRestPort);
162+
this.environmentProperties.setProperty(ML_STAGING_REST_PORT, mlStagingRestPort);
160163
}
161164

162165
public void setMLFinalRestPort(String mlFinalRestPort) {
163-
this.properties.setProperty(ML_FINAL_REST_PORT, mlFinalRestPort);
166+
this.environmentProperties.setProperty(ML_FINAL_REST_PORT, mlFinalRestPort);
164167
}
165168

166169
public void setMLUsername(String mlUsername) {
167-
this.properties.setProperty(ML_USERNAME, mlUsername);
170+
this.environmentProperties.setProperty(ML_USERNAME, mlUsername);
168171
}
169172

170173
public void setMLPassword(String mlPassword) {
171-
this.properties.setProperty(ML_PASSWORD, mlPassword);
174+
this.environmentProperties.setProperty(ML_PASSWORD, mlPassword);
172175
}
173176

174177
public void setUserPluginDir(String userPluginDir) {
175-
this.properties.setProperty(USER_PLUGIN_DIR, userPluginDir);
178+
this.environmentProperties.setProperty(USER_PLUGIN_DIR, userPluginDir);
176179
}
177180

178181
public void setAssetInstallTimeFilePath(String assetInstallTimeFilePath) {
179-
this.properties.setProperty(ASSET_INSTALL_TIME_FILE, assetInstallTimeFilePath);
180-
}
181-
182-
public void loadConfigurationFromFile() {
183-
InputStream is = null;
184-
try {
185-
File file = new File(PROPERTIES_FILENAME);
186-
if(file.exists()) {
187-
is = new FileInputStream( file );
188-
properties.load( is );
189-
}
190-
} catch ( Exception e ) {
191-
is = null;
192-
}
182+
this.environmentProperties.setProperty(ASSET_INSTALL_TIME_FILE, assetInstallTimeFilePath);
193183
}
194184

195-
public void saveConfigurationToFile() {
196-
OutputStream out = null;
197-
try {
198-
out = new FileOutputStream(new File(PROPERTIES_FILENAME));
199-
this.properties.store(out, null);
200-
} catch (FileNotFoundException e) {
201-
LOGGER.error("environment.properties is not found", e.getMessage());
202-
} catch (IOException e) {
203-
LOGGER.error("Error saving configuration.", e.getMessage());
204-
} finally {
205-
if (out != null) {
206-
try {
207-
out.close();
208-
} catch (IOException e) {
209-
LOGGER.error("Error closing output stream.", e.getMessage());
210-
}
211-
}
212-
}
185+
public void loadConfigurationFromFiles() {
186+
loadConfigurationFromFile(environmentProperties, ENVIRONMENT_PROPERTIES_FILENAME);
187+
loadConfigurationFromFile(environmentProperties, FLOW_PROPERTIES_FILENAME);
213188
}
189+
190+
public void loadConfigurationFromFile(Properties configProperties, String fileName) {
191+
InputStream is = null;
192+
try {
193+
File file = new File(fileName);
194+
if(file.exists()) {
195+
is = new FileInputStream( file );
196+
configProperties.load( is );
197+
}
198+
} catch ( Exception e ) {
199+
is = null;
200+
}
201+
}
214202

215-
public void removeSavedConfiguration() {
216-
this.properties = new Properties();
217-
File file = new File(PROPERTIES_FILENAME);
218-
if(file.exists()) {
219-
file.delete();
220-
}
203+
public void saveConfigurationToFile() {
204+
saveConfigurationToFile(environmentProperties, ENVIRONMENT_PROPERTIES_FILENAME);
221205
}
206+
207+
private void saveConfigurationToFile(Properties configProperties, String fileName) {
208+
OutputStream out = null;
209+
try {
210+
out = new FileOutputStream(new File(fileName));
211+
configProperties.store(out, null);
212+
} catch (FileNotFoundException e) {
213+
LOGGER.error(fileName + " is not found", e.getMessage());
214+
} catch (IOException e) {
215+
LOGGER.error("Error saving configuration.", e.getMessage());
216+
} finally {
217+
if (out != null) {
218+
try {
219+
out.close();
220+
} catch (IOException e) {
221+
LOGGER.error("Error closing output stream.", e.getMessage());
222+
}
223+
}
224+
}
225+
}
226+
227+
public void saveOrUpdateFlowInputPath(String entityName, String flowName, String inputPath) {
228+
this.flowProperties.setProperty(entityName + "-" + flowName, inputPath);
229+
saveConfigurationToFile(flowProperties, FLOW_PROPERTIES_FILENAME);
230+
}
231+
232+
public String getFlowInputPath(String entityName, String flowName) {
233+
return this.flowProperties.getProperty(entityName + "-" + flowName);
234+
}
222235

223236
}

quick-start/src/main/java/com/marklogic/hub/web/controller/api/DataHubServerApiController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public LoginForm getLoginStatus(HttpSession session) {
113113
LoginForm loginForm = (LoginForm) session.getAttribute("loginForm");
114114
if (loginForm == null) {
115115
loginForm = new LoginForm();
116-
this.environmentConfiguration.loadConfigurationFromFile();
116+
this.environmentConfiguration.loadConfigurationFromFiles();
117117
this.retrieveEnvironmentConfiguration(loginForm);
118118
session.setAttribute("loginForm", loginForm);
119119
} else if (loginForm.isInstalled()) {

quick-start/src/main/java/com/marklogic/hub/web/controller/api/FlowApiController.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ public void afterJob(JobExecution jobExecution) {
190190

191191
@RequestMapping(value="/run/input", method = RequestMethod.POST)
192192
public BigInteger runInputFlow(@RequestBody RunFlowModel runFlow) {
193+
194+
saveInputPath(runFlow);
195+
193196
CancellableTask task = new CancellableTask() {
194197

195198
@Override
@@ -228,6 +231,23 @@ public void run(BasicFuture<?> resultFuture) {
228231
};
229232
return taskManagerService.addTask(task);
230233
}
234+
235+
@RequestMapping(value = "/input-path", method = RequestMethod.GET, produces = { MediaType.TEXT_PLAIN_VALUE })
236+
@ResponseBody
237+
public String getPreviousInputPath(HttpServletRequest request) {
238+
String entityName = request.getParameter("entityName");
239+
String flowName = request.getParameter("flowName");
240+
return getPreviousInputPath(entityName,flowName);
241+
}
242+
243+
private String getPreviousInputPath(String entityName, String flowName) {
244+
String value = environmentConfiguration.getFlowInputPath(entityName, flowName);
245+
return value == null ? "." : value;
246+
}
247+
248+
private void saveInputPath(RunFlowModel runFlow) {
249+
environmentConfiguration.saveOrUpdateFlowInputPath(runFlow.getEntityName(), runFlow.getFlowName(), runFlow.getInputPath());
250+
}
231251

232252
@RequestMapping(value = "/runInParallel", method = RequestMethod.POST)
233253
public void runFlowsInParallel(HttpServletRequest request) {

quick-start/src/main/resources/static/app/services/dataHubService.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
saveFlow: saveFlow,
3131
displayMessage: displayMessage,
3232
searchPath: searchPath,
33-
showApiDoc: showApiDoc
33+
showApiDoc: showApiDoc,
34+
getPreviousInputPath : getPreviousInputPath
3435
});
3536

3637
function login(loginForm) {
@@ -194,11 +195,21 @@
194195
$rootScope.notificationBar.message = message;
195196
$rootScope.notificationBar.show = true;
196197
}
197-
198+
198199
function showApiDoc() {
199200
$window.open('#/api-doc', '_blank');
200201
}
201-
202+
203+
function getPreviousInputPath(entityName, flowName) {
204+
var params = {
205+
entityName: entityName,
206+
flowName: flowName
207+
};
208+
return $http.get('api/flows/input-path', {
209+
'params': params
210+
});
211+
}
212+
202213
}
203214

204215
function TaskManagerService($http, $q, $route) {

0 commit comments

Comments
 (0)