Skip to content

Commit

Permalink
Display a confirmation box if stopping a module will automatically sh…
Browse files Browse the repository at this point in the history
…ut down other dependent modules - TRUNK-4011

Cleaning up the moduleList.jsp file

Adding review changes
  • Loading branch information
surangak authored and wluyima committed Aug 23, 2013
1 parent 753b05e commit ae924a9
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 3 deletions.
25 changes: 25 additions & 0 deletions api/src/main/java/org/openmrs/module/ModuleFactory.java
Expand Up @@ -26,6 +26,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.Vector;
import java.util.WeakHashMap;
Expand Down Expand Up @@ -1459,4 +1460,28 @@ private static void saveGlobalProperty(String key, String value, String desc) {
log.warn("Unable to save the global property", t);
}
}

/**
* Convenience method used to identify module interdependencies and alert the user before modules are shut down.
*
* @param moduleId the moduleId used to identify the module being validated
* @return List<dependentModules> the list of moduleId's which depend on the module about to be shutdown.
* @since 1.10
*/
public static List<String> getDependencies(String moduleId) {
List<String> dependentModules = null;
Module module = getModuleById(moduleId);

Map<String, Module> startedModules = getStartedModulesMap();
String modulePackage = module.getPackageName();

for (Entry<String, Module> entry : startedModules.entrySet()) {
if (!moduleId.equals(entry.getKey()) && entry.getValue().getRequiredModules().contains(modulePackage)) {
if (dependentModules == null)
dependentModules = new ArrayList<String>();
dependentModules.add(entry.getKey() + " " + entry.getValue().getVersion());
}
}
return dependentModules;
}
}
@@ -0,0 +1,51 @@
/**
* The contents of this file are subject to the OpenMRS Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://license.openmrs.org
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/
package org.openmrs.module.web.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.module.ModuleFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
* Controller which allows users to identify dependencies between modules for shutdown/restart purposes.
*/
@Controller
@RequestMapping(value = "/admin/modules/manage/")
public class ModuleManagementController {

/**
* Logger for this class and subclasses
*/
protected final Log log = LogFactory.getLog(getClass());

@RequestMapping(value = "/checkdependencies", method = RequestMethod.GET)
@ResponseBody
public List<String> manage(@RequestParam(value = "moduleId") String moduleId, HttpServletRequest request,
HttpServletResponse response) throws IOException {
return ModuleFactory.getDependencies(moduleId);

}

}
3 changes: 3 additions & 0 deletions webapp/src/main/webapp/WEB-INF/messages.properties
Expand Up @@ -1965,6 +1965,9 @@ Module.stopped=Module {0} has been stopped
Module.error=Error processing Module
Module.errorStarting=Error starting Module - {0}
Module.errorClickForDetails=Error starting! Click for details
Module.dependencyValidationNotice=Attention. Dependent modules detected !
Module.dependencyShutdownNotice=The following modules will also be shutdown if you decide to continue with this action.
Module.dependencyUnloadNotice=The following modules will also be removed from the system if you decide to continue with this action.
Module.invalid=Invalid module specified {0}
Module.notStarted=Not Started
Module.loadedAndStarted=Module loaded and started successfully
Expand Down
62 changes: 59 additions & 3 deletions webapp/src/main/webapp/WEB-INF/view/admin/modules/moduleList.jsp
Expand Up @@ -11,6 +11,61 @@
<script type="text/javascript">
var oTable;
function escapeSpecialCharacters(moduleId){
var segments = moduleId.split(".");
if(segments.length > 1){
moduleId = segments[0] + ('\\.') + segments[1];
}
return moduleId;
}
function getDependencies(module, isUnloadFlag){
var moduleId = module.parentNode.parentNode.id;
var path = "${pageContext.request.contextPath}/admin/modules/manage/checkdependencies.form";
path = path + "?moduleId=" + moduleId;
$j.ajax({
async : false,
type : "GET",
url : path,
dataType : "text",
success : function(data) {
if(data != ""){
var message;
if(isUnloadFlag == false){
message = '<openmrs:message code="Module.dependencyShutdownNotice" javaScriptEscape="true"/>';
}else{
message = '<openmrs:message code="Module.dependencyUnloadNotice" javaScriptEscape="true"/>';
}
message += '<br/><br/>' + JSON.parse(data);
document.getElementById('dependency-confirmation-message').innerHTML = message;
$j( "#dialog-confirm" ).dialog({
resizable: false,
width: '50%',
modal: true,
buttons: {
"Ok": function() {
$j( this ).dialog( "close" );
moduleId = escapeSpecialCharacters(moduleId);
$j('#' + moduleId + '-form').append('<input type="hidden" name="stop.x" value="stop.x">');
$j('#' + moduleId + '-form').submit();
},
Cancel: function() {
$j( this ).dialog( "close" );
}
}
});
}else{
moduleId = escapeSpecialCharacters(moduleId);
$j('#' + moduleId + '-form').append('<input type="hidden" name="stop.x" value="stop.x">');
$j('#' + moduleId + '-form').submit();
}
}
});
return false;
}
$j(document).ready(function() {
$j('#addUpgradePopup').dialog({
autoOpen: false,
Expand Down Expand Up @@ -68,6 +123,7 @@
<h2><openmrs:message code="Module.header" /></h2>

<p><openmrs:message code="Module.notice" /></p>
<div id="dialog-confirm" title="<openmrs:message code="Module.dependencyValidationNotice"/>"><p id="dependency-confirmation-message"></p></div>

<c:choose>
<c:when test="${allowAdmin == 'true'}">
Expand Down Expand Up @@ -149,7 +205,7 @@
<tbody>
</c:if>

<form method="post">
<form id="${module.moduleId}-form" method="post">
<input type="hidden" name="moduleId" value="${module.moduleId}" />
<tr class='${varStatus.index % 2 == 0 ? "oddRow" : "evenRow" }' id="${module.moduleId}">
<c:choose>
Expand All @@ -160,11 +216,11 @@
<input type="image" src="${pageContext.request.contextPath}/images/play.gif" name="start" onclick="document.getElementById('hiddenAction').value = this.value" title="<openmrs:message code="Module.start.help"/>" alt="<openmrs:message code="Module.start"/>" />
</c:when>
<c:otherwise>
<input type="image" src="${pageContext.request.contextPath}/images/stop.gif" name="stop" onclick="document.getElementById('hiddenAction').value = this.value" title="<openmrs:message code="Module.stop.help"/>" alt="<openmrs:message code="Module.stop"/>" />
<input type="image" src="${pageContext.request.contextPath}/images/stop.gif" name="stop" onclick="return getDependencies(this, false);" title="<openmrs:message code="Module.stop.help"/>" alt="<openmrs:message code="Module.stop"/>" />
</c:otherwise>
</c:choose>
</td>
<td valign="top"><input type="image" src="${pageContext.request.contextPath}/images/trash.gif" name="unload" onclick="return confirm('<openmrs:message code="Module.unloadWarning"/>');" title="<openmrs:message code="Module.unload.help"/>" title="<openmrs:message code="Module.unload"/>" alt="<openmrs:message code="Module.unload"/>" /></td>
<td valign="top"><input type="image" src="${pageContext.request.contextPath}/images/trash.gif" name="unload" onclick="return getDependencies(this, true);" title="<openmrs:message code="Module.unload.help"/>" title="<openmrs:message code="Module.unload"/>" alt="<openmrs:message code="Module.unload"/>" /></td>
</c:when>
<c:otherwise>
<td valign="top">
Expand Down

0 comments on commit ae924a9

Please sign in to comment.