Index: lams_admin/conf/language/lams/ApplicationResources.properties =================================================================== diff -u -rdd6fcf5c4586df136532e8f6baba9210b93742fb -ra83af819892556fe8f7b87f6d5983d71377d4f8e --- lams_admin/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision dd6fcf5c4586df136532e8f6baba9210b93742fb) +++ lams_admin/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision a83af819892556fe8f7b87f6d5983d71377d4f8e) @@ -153,7 +153,10 @@ sysadmin.cache.clear = Clear Hibernate cache sysadmin.clear = Clear sysadmin.cache.cleared = Cache cleared +sysadmin.garbage.clear = Run Garbage Collector +sysadmin.garbage.cleared = Garbage Collector triggered sysadmin.job.list = Job list +sysadmin.job.list = Job list sysadmin.list.job = List scheduled jobs in Quartz queue sysadmin.edit.default.tool.content = Edit default tool content cache.maintain = Maintain LAMS cache Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/CleanupController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/CleanupController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/CleanupController.java (revision a83af819892556fe8f7b87f6d5983d71377d4f8e) @@ -0,0 +1,137 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.admin.web.controller; + +import java.io.File; + +import javax.management.MalformedObjectNameException; +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.admin.web.form.CleanupForm; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.util.FileUtil; +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 + */ +@Controller +@RequestMapping("/cleanup") +public class CleanupController { + private static Logger log = Logger.getLogger(CleanupController.class); + + @Autowired + @Qualifier("adminMessageService") + private MessageService messageService; + + @RequestMapping(path = "/start") + public String start(@ModelAttribute CleanupForm cleanupForm, HttpServletRequest request) throws Exception { + // check user is sysadmin + if (!(request.isUserInRole(Role.SYSADMIN))) { + request.setAttribute("errorName", "CleanupAction"); + request.setAttribute("errorMessage", messageService.getMessage("error.need.sysadmin")); + return "error"; + } + + // check if url contains request for refresh folder sizes only + String action = WebUtil.readStrParam(request, "action", true); + 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)); + request.setAttribute("filesDeleted", + messageService.getMessage("msg.cleanup.files.deleted", new Integer[] { filesDeleted })); + } else { + errorMap.add("numDays", messageService.getMessage("error.non.negative.number.required")); + } + } + 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(path = "/garbage", method = RequestMethod.POST) + public String cleanUpGarbage() throws MalformedObjectNameException { + System.gc(); + return "redirect:start.do?garbageCollectorRun=true"; + } + + @RequestMapping("/refresh") + public String refresh(@ModelAttribute CleanupForm cleanupForm, HttpServletRequest request) throws Exception { + + // display temp files info + File oldFiles[] = FileUtil.getOldTempFiles(0); + long zipTotal = 0; + long tmpTotal = 0; + if (oldFiles != null) { + for (int i = 0; i < oldFiles.length; i++) { + if (oldFiles[i].getName().startsWith(TempDirectoryFilter.zip_prefix)) { + zipTotal += FileUtil.calculateFileSize(oldFiles[i]); + } else if (oldFiles[i].getName().startsWith(TempDirectoryFilter.tmp_prefix)) { + tmpTotal += FileUtil.calculateFileSize(oldFiles[i]); + } + } + } + request.setAttribute("zipTotal", zipTotal / 1024); + request.setAttribute("tmpTotal", tmpTotal / 1024); + + return "cleanup"; + } + +} Fisheye: Tag a83af819892556fe8f7b87f6d5983d71377d4f8e refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/CleanupTempFilesController.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/web/cleanup.jsp =================================================================== diff -u -rdd6fcf5c4586df136532e8f6baba9210b93742fb -ra83af819892556fe8f7b87f6d5983d71377d4f8e --- lams_admin/web/cleanup.jsp (.../cleanup.jsp) (revision dd6fcf5c4586df136532e8f6baba9210b93742fb) +++ lams_admin/web/cleanup.jsp (.../cleanup.jsp) (revision a83af819892556fe8f7b87f6d5983d71377d4f8e) @@ -82,6 +82,23 @@ + +
+
+ + + +
+ +
+ + " /> + + + + +
+