Index: lams_admin/conf/language/lams/ApplicationResources.properties
===================================================================
diff -u -rf54c292e64bc98100d0bdaf34f361bb5e786bde4 -rdd6fcf5c4586df136532e8f6baba9210b93742fb
--- lams_admin/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision f54c292e64bc98100d0bdaf34f361bb5e786bde4)
+++ lams_admin/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision dd6fcf5c4586df136532e8f6baba9210b93742fb)
@@ -149,6 +149,10 @@
sysadmin.headline = System Administration
sysadmin.config.settings.edit = Edit configuration settings
sysadmin.batch.temp.file.delete = Delete old temporary files
+sysadmin.cleanup = Clean up cache and files
+sysadmin.cache.clear = Clear Hibernate cache
+sysadmin.clear = Clear
+sysadmin.cache.cleared = Cache cleared
sysadmin.job.list = Job list
sysadmin.list.job = List scheduled jobs in Quartz queue
sysadmin.edit.default.tool.content = Edit default tool content
Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/CleanupTempFilesController.java
===================================================================
diff -u -rf2ad75cef0c507a64877942631fee13efbc6ed50 -rdd6fcf5c4586df136532e8f6baba9210b93742fb
--- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/CleanupTempFilesController.java (.../CleanupTempFilesController.java) (revision f2ad75cef0c507a64877942631fee13efbc6ed50)
+++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/CleanupTempFilesController.java (.../CleanupTempFilesController.java) (revision dd6fcf5c4586df136532e8f6baba9210b93742fb)
@@ -24,6 +24,7 @@
import java.io.File;
+import javax.management.MalformedObjectNameException;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
@@ -34,13 +35,15 @@
import org.lamsfoundation.lams.util.MessageService;
import org.lamsfoundation.lams.util.TempDirectoryFilter;
import org.lamsfoundation.lams.util.WebUtil;
+import org.lamsfoundation.lams.util.hibernate.HibernateSessionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
/**
* @author jliew
@@ -55,11 +58,10 @@
private MessageService messageService;
@RequestMapping(path = "/start")
- public String execute(@ModelAttribute CleanupForm cleanupForm, HttpServletRequest request) throws Exception {
-
+ public String start(@ModelAttribute CleanupForm cleanupForm, HttpServletRequest request) throws Exception {
// check user is sysadmin
if (!(request.isUserInRole(Role.SYSADMIN))) {
- request.setAttribute("errorName", "CleanupTempFilesAction");
+ request.setAttribute("errorName", "CleanupAction");
request.setAttribute("errorMessage", messageService.getMessage("error.need.sysadmin"));
return "error";
}
@@ -69,28 +71,41 @@
if (action != null && StringUtils.equals(action, "refresh")) {
return refresh(cleanupForm, request);
}
+ return "cleanup";
+ }
+ @RequestMapping(path = "/files", method = RequestMethod.POST)
+ public String cleanUpFiles(@ModelAttribute CleanupForm cleanupForm, HttpServletRequest request) throws Exception {
+ // check user is sysadmin
+ if (!(request.isUserInRole(Role.SYSADMIN))) {
+ request.setAttribute("errorName", "CleanupTempFilesAction");
+ request.setAttribute("errorMessage", messageService.getMessage("error.need.sysadmin"));
+ return "error";
+ }
+
MultiValueMap errorMap = new LinkedMultiValueMap<>();
Integer numDays = cleanupForm.getNumDays();
// delete directories if form has been submitted
if (numDays != null) {
if (numDays >= 0) {
int filesDeleted = FileUtil.cleanupOldFiles(FileUtil.getOldTempFiles(numDays));
- String args[] = new String[1];
- args[0] = new Integer(filesDeleted).toString();
- request.setAttribute("filesDeleted", messageService.getMessage("msg.cleanup.files.deleted", args));
+ request.setAttribute("filesDeleted",
+ messageService.getMessage("msg.cleanup.files.deleted", new Integer[] { filesDeleted }));
} else {
errorMap.add("numDays", messageService.getMessage("error.non.negative.number.required"));
}
- } else {
- // recommended number of days to leave temp files
- cleanupForm.setNumDays(1);
}
request.setAttribute("errorMap", errorMap);
return "cleanup";
}
+ @RequestMapping(path = "/cache", method = RequestMethod.POST)
+ public String cleanUpCache() throws MalformedObjectNameException {
+ boolean cacheCleared = HibernateSessionManager.clearCache();
+ return "redirect:start.do?cacheCleared=" + cacheCleared;
+ }
+
@RequestMapping("/refresh")
public String refresh(@ModelAttribute CleanupForm cleanupForm, HttpServletRequest request) throws Exception {
@@ -110,12 +125,6 @@
request.setAttribute("zipTotal", zipTotal / 1024);
request.setAttribute("tmpTotal", tmpTotal / 1024);
- // set default numDays
- Integer numDays = cleanupForm.getNumDays();
- if (numDays == null) {
- cleanupForm.setNumDays(1);
- }
-
return "cleanup";
}
Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/SysAdminStartController.java
===================================================================
diff -u -r8af1f7ba45d2ed7f050169ad43dce290f53661cf -rdd6fcf5c4586df136532e8f6baba9210b93742fb
--- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/SysAdminStartController.java (.../SysAdminStartController.java) (revision 8af1f7ba45d2ed7f050169ad43dce290f53661cf)
+++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/SysAdminStartController.java (.../SysAdminStartController.java) (revision dd6fcf5c4586df136532e8f6baba9210b93742fb)
@@ -72,7 +72,7 @@
links = new ArrayList<>();
links.add(new LinkBean("logevent/start.do", "label.event.log"));
- links.add(new LinkBean("cleanup/start.do", "sysadmin.batch.temp.file.delete"));
+ links.add(new LinkBean("cleanup/start.do", "sysadmin.cleanup"));
links.add(new LinkBean("cleanupPreviewLessons/start.do", "sysadmin.batch.preview.lesson.delete"));
links.add(new LinkBean("statistics/start.do", "admin.statistics.title"));
groupedLinks.add(new Object[] { AdminConstants.START_MONITOR_LINKS, links });
Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/form/CleanupForm.java
===================================================================
diff -u -r550e1b37b507779064955267ef47e9085f791357 -rdd6fcf5c4586df136532e8f6baba9210b93742fb
--- lams_admin/src/java/org/lamsfoundation/lams/admin/web/form/CleanupForm.java (.../CleanupForm.java) (revision 550e1b37b507779064955267ef47e9085f791357)
+++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/form/CleanupForm.java (.../CleanupForm.java) (revision dd6fcf5c4586df136532e8f6baba9210b93742fb)
@@ -26,6 +26,11 @@
private Integer numDays;
+ public CleanupForm() {
+ // recommended number of days to leave temp files
+ numDays = 1;
+ }
+
public Integer getNumDays() {
return numDays;
}
Index: lams_admin/web/cleanup.jsp
===================================================================
diff -u -r37bb2ae017713b44cdfd6a55cfceca28c3efab02 -rdd6fcf5c4586df136532e8f6baba9210b93742fb
--- lams_admin/web/cleanup.jsp (.../cleanup.jsp) (revision 37bb2ae017713b44cdfd6a55cfceca28c3efab02)
+++ lams_admin/web/cleanup.jsp (.../cleanup.jsp) (revision dd6fcf5c4586df136532e8f6baba9210b93742fb)
@@ -6,7 +6,7 @@
-
+
${title}
@@ -17,45 +17,71 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
- :
-
-
-
-
-
" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ :
+
+
+
+ " />
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+ " />
+
+
+
+
+
+
Index: lams_common/src/java/org/lamsfoundation/lams/util/hibernate/HibernateSessionManager.java
===================================================================
diff -u -rf53bf7195291dc2c87f096afb30e0b2c78ed63fc -rdd6fcf5c4586df136532e8f6baba9210b93742fb
--- lams_common/src/java/org/lamsfoundation/lams/util/hibernate/HibernateSessionManager.java (.../HibernateSessionManager.java) (revision f53bf7195291dc2c87f096afb30e0b2c78ed63fc)
+++ lams_common/src/java/org/lamsfoundation/lams/util/hibernate/HibernateSessionManager.java (.../HibernateSessionManager.java) (revision dd6fcf5c4586df136532e8f6baba9210b93742fb)
@@ -1,5 +1,7 @@
package org.lamsfoundation.lams.util.hibernate;
+import org.apache.log4j.Logger;
+import org.hibernate.Cache;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.context.internal.ManagedSessionContext;
@@ -18,7 +20,8 @@
public class HibernateSessionManager {
private static SessionFactory sessionFactory;
- // private static Logger log = Logger.getLogger(HibernateSessionManager.class);
+ private static Logger log = Logger.getLogger(HibernateSessionManager.class);
+
/**
* Makes sure that an open Hibernate session is bound to current thread.
*/
@@ -58,6 +61,24 @@
return HibernateSessionManager.getSessionFactory().getStatistics();
}
+ public static boolean clearCache() {
+ try {
+ Session session = HibernateSessionManager.getSessionFactory().getCurrentSession();
+ if (session != null) {
+ session.clear();
+ }
+
+ Cache cache = HibernateSessionManager.getSessionFactory().getCache();
+ if (cache != null) {
+ cache.evictAllRegions();
+ }
+ } catch (Exception e) {
+ log.error("Error while clearing cache", e);
+ return false;
+ }
+ return true;
+ }
+
private static SessionFactory getSessionFactory() {
if (HibernateSessionManager.sessionFactory == null) {
WebApplicationContext wac = WebApplicationContextUtils