Skip to content

Commit 686eebc

Browse files
committed
fixes for #197
1 parent d39a640 commit 686eebc

File tree

6 files changed

+59
-41
lines changed

6 files changed

+59
-41
lines changed

quick-start/src/main/java/com/marklogic/hub/model/EntityModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public String toString() {
107107
sb.append("{");
108108
sb.append("entityName=");
109109
sb.append(entityName);
110-
sb.append("isSynched=");
110+
sb.append(" isSynched=");
111111
sb.append(isSynched);
112112
sb.append("}");
113113

quick-start/src/main/java/com/marklogic/hub/service/DataHubService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public void install() throws DataHubException {
3131
}
3232

3333
public void installUserModules() throws DataHubException {
34+
LOGGER.debug("installUserModules");
3435
DataHub dataHub = getDataHub();
3536
try {
3637
LOGGER.debug("pluginDir:" + environmentConfiguration.getUserPluginDir());

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class DataHubServerApiController extends BaseController {
5252
MediaType.APPLICATION_JSON_UTF8_VALUE }, produces = { MediaType.APPLICATION_JSON_UTF8_VALUE })
5353
public LoginForm postLogin(@RequestBody LoginForm loginForm, BindingResult bindingResult, HttpSession session,
5454
HttpServletRequest request) throws Exception {
55+
LOGGER.debug("POST: login");
5556
try {
5657
if (isValidDirectory(loginForm.getUserPluginDir())) {
5758

@@ -61,6 +62,7 @@ public LoginForm postLogin(@RequestBody LoginForm loginForm, BindingResult bindi
6162
loginForm.setServerVersionAccepted(dataHubService.isServerAcceptable());
6263
loginForm.setHasErrors(false);
6364
loginForm.setLoggedIn(true);
65+
loginForm.setUninstalling(false);
6466
environmentConfiguration.saveConfigurationToFile();
6567
session.setAttribute("loginForm", loginForm);
6668

@@ -106,32 +108,26 @@ private boolean isValidDirectory(String userPluginDir) {
106108
return false;
107109
}
108110

109-
@RequestMapping(value = "login", method = RequestMethod.GET)
111+
@RequestMapping(value = "login-status", method = RequestMethod.GET)
110112
public LoginForm getLoginStatus(HttpSession session) {
113+
LOGGER.debug("GET: login-status");
111114
LoginForm loginForm = (LoginForm) session.getAttribute("loginForm");
115+
112116
if (loginForm == null) {
117+
// need to load last configuration
113118
loginForm = new LoginForm();
114119
this.environmentConfiguration.loadConfigurationFromFiles();
115120
this.retrieveEnvironmentConfiguration(loginForm);
121+
loginForm.setUninstalling(false);
116122
session.setAttribute("loginForm", loginForm);
117-
118123
} else if (loginForm.isInstalled()) {
119124
loginForm.setEntities(entityManagerService.getEntities());
120125
loginForm.refreshSelectedEntity();
121-
122-
List<EntityModel> entities = loginForm.getEntities();
123-
for (Iterator iterator = entities.iterator(); iterator.hasNext();) {
124-
EntityModel entityModel = (EntityModel) iterator.next();
125-
if (!entityModel.isSynched()) {
126-
synchronized (syncStatusService) {
127-
LOGGER.debug("not synched ... installing modules ...");
128-
this.installUserModules(session);
129-
LOGGER.debug("modules installed.");
130-
}
131-
break;
132-
}
126+
synchronized (syncStatusService) {
127+
LOGGER.debug("installing modules ...");
128+
this.installUserModules(session);
129+
LOGGER.debug("modules installed.");
133130
}
134-
135131
}
136132

137133
LOGGER.debug("after login: " + loginForm.toString());
@@ -141,8 +137,10 @@ public LoginForm getLoginStatus(HttpSession session) {
141137

142138
@RequestMapping(value = "logout", method = RequestMethod.POST)
143139
public LoginForm postLogout(HttpSession session) {
140+
LOGGER.debug("POST: logout");
144141
LoginForm loginForm = (LoginForm) session.getAttribute("loginForm");
145142
loginForm.setLoggedIn(false);
143+
loginForm.setUninstalling(false);
146144
this.retrieveEnvironmentConfiguration(loginForm);
147145

148146
Enumeration<String> attrNames = session.getAttributeNames();
@@ -155,6 +153,7 @@ public LoginForm postLogout(HttpSession session) {
155153

156154
@RequestMapping(value = "install", method = RequestMethod.POST)
157155
public LoginForm install(HttpSession session) {
156+
LOGGER.debug("POST: install");
158157
dataHubService.install();
159158
LoginForm loginForm = (LoginForm) session.getAttribute("loginForm");
160159
loginForm.setInstalled(true);
@@ -164,15 +163,18 @@ public LoginForm install(HttpSession session) {
164163

165164
@RequestMapping(value = "uninstall", method = RequestMethod.POST)
166165
public LoginForm uninstall(HttpSession session) {
167-
dataHubService.uninstall();
166+
LOGGER.debug("POST: uninstall");
168167
LoginForm loginForm = (LoginForm) session.getAttribute("loginForm");
168+
loginForm.setUninstalling(true);
169+
dataHubService.uninstall();
169170
loginForm.setInstalled(false);
170171
this.unLoadUserModules(loginForm);
171172
return loginForm;
172173
}
173174

174175
@RequestMapping(value = "install-user-modules", method = RequestMethod.POST)
175176
public LoginForm installUserModules(HttpSession session) {
177+
LOGGER.debug("POST: install-user-modules");
176178
synchronized (syncStatusService) {
177179
dataHubService.installUserModules();
178180

@@ -188,6 +190,7 @@ public LoginForm installUserModules(HttpSession session) {
188190

189191
@RequestMapping(value = "validate-user-modules", method = RequestMethod.GET)
190192
public JsonNode validateUserModules(HttpSession session) {
193+
LOGGER.debug("GET: validate-user-modules");
191194
synchronized (syncStatusService) {
192195
return dataHubService.validateUserModules();
193196
}

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

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -99,35 +99,41 @@ public LoginForm saveEntity(@RequestBody EntityForm entityForm, BindingResult bi
9999
*/
100100
@RequestMapping(value = "status-change", method = RequestMethod.GET)
101101
public LoginForm getStatusChange(HttpServletRequest request) {
102+
LOGGER.debug("GET: status-change");
102103
HttpSession session = request.getSession();
103104

104105
synchronized (syncStatusService) {
105106
try {
106107
syncStatusService.wait();
107-
LOGGER.debug("status change");
108108
} catch (InterruptedException e) {
109109
}
110110

111111
// refresh the list of entities saved in the session
112112
LoginForm loginForm = (LoginForm) session.getAttribute("loginForm");
113-
if (null == loginForm) {
114-
loginForm = new LoginForm();
113+
if (null != loginForm && loginForm.isLoggedIn()) {
114+
LOGGER.debug("status change:" + loginForm.toString());
115+
// add checking if data hub is installed and the server is
116+
// acceptable. Something may have changed the server or removed
117+
// the
118+
// data hub outside the app
119+
120+
if (!loginForm.isUninstalling()) {
121+
loginForm.setInstalled(dataHubService.isInstalled());
122+
loginForm.setServerVersionAccepted(dataHubService.isServerAcceptable());
123+
if (loginForm.isInstalled()) {
124+
// if (loginForm.isInstalled()) {
125+
List<EntityModel> entities = entityManagerService.getEntities();
126+
loginForm.setEntities(entities);
127+
loginForm.refreshSelectedEntity();
128+
}
129+
}
130+
131+
// refresh the session loginForm
132+
session.setAttribute("loginForm", loginForm);
133+
// LOGGER.debug("installing modules ...");
134+
// dataHubService.installUserModules();
115135
}
116136

117-
// add checking if data hub is installed and the server is
118-
// acceptable. Something may have changed the server or removed the
119-
// data hub outside the app
120-
loginForm.setInstalled(dataHubService.isInstalled());
121-
loginForm.setServerVersionAccepted(dataHubService.isServerAcceptable());
122-
if (loginForm.isInstalled()) {
123-
List<EntityModel> entities = entityManagerService.getEntities();
124-
loginForm.setEntities(entities);
125-
loginForm.refreshSelectedEntity();
126-
}
127-
128-
// refresh the session loginForm
129-
session.setAttribute("loginForm", loginForm);
130-
131137
return loginForm;
132138
}
133139
}
@@ -148,10 +154,8 @@ public void destroy() throws Exception {
148154
@Override
149155
public void onWatchEvent(Path path, WatchEvent<Path> event) {
150156
synchronized (syncStatusService) {
151-
LOGGER.debug("change detected ...");
157+
LOGGER.debug("change detected ...");
152158
syncStatusService.notifyAll();
153-
LOGGER.debug("installing modules ...");
154-
dataHubService.installUserModules();
155159
}
156160
}
157161
}

quick-start/src/main/java/com/marklogic/hub/web/form/LoginForm.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class LoginForm extends BaseForm {
1818
private boolean serverVersionAccepted;
1919
private boolean installed;
2020
private boolean loggedIn;
21+
private boolean uninstalling;
2122
private List<EntityModel> entities = new ArrayList<EntityModel>();
2223
private EntityModel selectedEntity;
2324

@@ -89,6 +90,14 @@ public boolean isLoggedIn() {
8990
return loggedIn;
9091
}
9192

93+
public boolean isUninstalling() {
94+
return uninstalling;
95+
}
96+
97+
public void setUninstalling(boolean uninstalling) {
98+
this.uninstalling = uninstalling;
99+
}
100+
92101
public void setLoggedIn(boolean loggedIn) {
93102
this.loggedIn = loggedIn;
94103
}
@@ -144,7 +153,8 @@ public String toString() {
144153
return "LoginForm [mlHost=" + mlHost + ", mlStagingPort=" + mlStagingPort + ", mlFinalPort=" + mlFinalPort
145154
+ ", mlTracePort=" + mlTracePort + ", mlUsername=" + mlUsername + ", mlPassword=" + mlPassword
146155
+ ", userPluginDir=" + userPluginDir + ", serverVersionAccepted=" + serverVersionAccepted
147-
+ ", installed=" + installed + ", loggedIn=" + loggedIn + ", entities=" + entities + ", selectedEntity="
156+
+ ", installed=" + installed + ", loggedIn=" + loggedIn + " uninstalling=" + uninstalling
157+
+ ", entities=" + entities + ", selectedEntity="
148158
+ selectedEntity + "]";
149159
}
150160

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
}
5353

5454
function getLoginStatus() {
55-
return $http.get('api/data-hub/login')
55+
return $http.get('api/data-hub/login-status')
5656
.success(function(data) {
5757
self.status = data;
5858
})
@@ -203,11 +203,11 @@
203203
'params': params
204204
});
205205
}
206-
206+
207207
function getJsonFile(filePath) {
208208
return $http.get(filePath);
209209
}
210-
210+
211211
function downloadMlcpOptionsFile(data) {
212212
return $http.post('api/flows/options/download', data);
213213
}

0 commit comments

Comments
 (0)