Index: lams_admin/conf/language/lams/ApplicationResources.properties =================================================================== diff -u -rc85b9ea4c571975cfc2755f4a4a946c0c20ce756 -rfba2480356aa5ddda0c8308eb917d72d16aa32eb --- lams_admin/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision c85b9ea4c571975cfc2755f4a4a946c0c20ce756) +++ lams_admin/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision fba2480356aa5ddda0c8308eb917d72d16aa32eb) @@ -164,6 +164,7 @@ sysadmin.headline =System Administration sysadmin.config.settings.edit =Edit configuration settings sysadmin.batch.temp.file.delete =Delete old temporary files +sysadmin.batch.preview.lesson.delete =Delete old preview lessons sysadmin.job.list =Job list sysadmin.list.job =List scheduled jobs in Quartz queue sysadmin.register.server =Register server @@ -228,6 +229,10 @@ msg.importv1.already.exist =The following logins already exist msg.cleanup.files.deleted ={0} files were deleted. msg.cleanup.warning =Warning: calculating the size of LAMS' temporary files may incur a performance hit on your server if it hasn't been cleaned out for a while. +msg.cleanup.preview.lesson.confirm =Are you sure you want to delete all preview lessons? +msg.cleanup.preview.lesson.error =Error while deleting preview lessons +label.cleanup.preview.lesson.count =Number of preview/all lessons: +label.cleanup.preview.lesson.progress =Deleting... label.exported.learning.designs =exported learning designs label.imported.learning.designs =imported learning designs label.unknown =unknown Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/CleanupPreviewLessonsAction.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/CleanupPreviewLessonsAction.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/CleanupPreviewLessonsAction.java (revision fba2480356aa5ddda0c8308eb917d72d16aa32eb) @@ -0,0 +1,133 @@ +/**************************************************************** + * 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.action; + +import java.io.IOException; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.log4j.Logger; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.apache.tomcat.util.json.JSONArray; +import org.apache.tomcat.util.json.JSONException; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.lesson.service.ILessonService; +import org.lamsfoundation.lams.monitoring.service.IMonitoringService; +import org.lamsfoundation.lams.security.ISecurityService; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.action.LamsDispatchAction; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +/** + * @author Marcin Cieslak + */ +public class CleanupPreviewLessonsAction extends LamsDispatchAction { + private static Logger log = Logger.getLogger(CleanupPreviewLessonsAction.class); + + private static IMonitoringService monitoringService; + private static ILessonService lessonService; + private static ISecurityService securityService; + + @Override + public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException { + if (!getSecurityService().isSysadmin(getUserID(), "display cleanup preview lessons", false)) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a sysadmin"); + return null; + } + + if (!(request.isUserInRole(Role.SYSADMIN))) { + request.setAttribute("errorName", "CleanupPreviewLessonsAction"); + request.setAttribute("errorMessage", AdminServiceProxy.getMessageService(getServlet().getServletContext()) + .getMessage("error.need.sysadmin")); + return mapping.findForward("error"); + } + + long[] lessonCount = getLessonService().getPreviewLessonCount(); + request.setAttribute("previewCount", lessonCount[0]); + request.setAttribute("allLessonCount", lessonCount[1]); + + return mapping.findForward("cleanup"); + } + + public ActionForward deletePreviewLessons(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, JSONException { + Integer userID = getUserID(); + Integer limit = WebUtil.readIntParam(request, "limit", true); + List lessonIDs = getLessonService().getPreviewLessons(limit); + for (Long lessonID : lessonIDs) { + log.info("Deleting preview lesson: " + lessonID); + // role is checked in this method + getMonitoringService().removeLessonPermanently(lessonID, userID); + } + + long[] lessonCount = getLessonService().getPreviewLessonCount(); + JSONArray responseJSON = new JSONArray(lessonCount); + response.setContentType("application/json;charset=utf-8"); + response.getWriter().print(responseJSON); + return null; + } + + private Integer getUserID() { + HttpSession ss = SessionManager.getSession(); + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + return user == null ? null : user.getUserID(); + } + + private IMonitoringService getMonitoringService() { + if (monitoringService == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); + monitoringService = (IMonitoringService) ctx.getBean("monitoringService"); + } + return monitoringService; + } + + private ILessonService getLessonService() { + if (lessonService == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); + lessonService = (ILessonService) ctx.getBean("lessonService"); + } + return lessonService; + } + + private ISecurityService getSecurityService() { + if (securityService == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); + securityService = (ISecurityService) ctx.getBean("securityService"); + } + return securityService; + } +} \ No newline at end of file Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/SysAdminStartAction.java =================================================================== diff -u -rc85b9ea4c571975cfc2755f4a4a946c0c20ce756 -rfba2480356aa5ddda0c8308eb917d72d16aa32eb --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/SysAdminStartAction.java (.../SysAdminStartAction.java) (revision c85b9ea4c571975cfc2755f4a4a946c0c20ce756) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/SysAdminStartAction.java (.../SysAdminStartAction.java) (revision fba2480356aa5ddda0c8308eb917d72d16aa32eb) @@ -69,6 +69,7 @@ links = new ArrayList(); links.add(new LinkBean("cleanup.do", "sysadmin.batch.temp.file.delete")); + links.add(new LinkBean("cleanupPreviewLessons.do", "sysadmin.batch.preview.lesson.delete")); links.add(new LinkBean("statistics.do", "admin.statistics.title")); groupedLinks.add(new Object[]{AdminConstants.START_MONITOR_LINKS,links}); Index: lams_admin/web/WEB-INF/struts-config.xml =================================================================== diff -u -r65efb0abb529cafc1977e284e2c9a4ed33722334 -rfba2480356aa5ddda0c8308eb917d72d16aa32eb --- lams_admin/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision 65efb0abb529cafc1977e284e2c9a4ed33722334) +++ lams_admin/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision fba2480356aa5ddda0c8308eb917d72d16aa32eb) @@ -518,7 +518,27 @@ redirect="false" /> + + + + + + + + + + + Index: lams_admin/web/cleanupPreviewLessons.jsp =================================================================== diff -u --- lams_admin/web/cleanupPreviewLessons.jsp (revision 0) +++ lams_admin/web/cleanupPreviewLessons.jsp (revision fba2480356aa5ddda0c8308eb917d72d16aa32eb) @@ -0,0 +1,72 @@ +<%@ include file="/taglibs.jsp"%> + + + + +

+ + + + ${previewCount} / ${allLessonCount} + + +
+ +
\ No newline at end of file Index: lams_build/lib/lams/lams.jar =================================================================== diff -u -rdd88db045211a9ac60afbfb74476638673bd33f7 -rfba2480356aa5ddda0c8308eb917d72d16aa32eb Binary files differ Index: lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILessonDAO.java =================================================================== diff -u -r51fb2a37254f24bb2a805d4ffd54482c779f43fa -rfba2480356aa5ddda0c8308eb917d72d16aa32eb --- lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILessonDAO.java (.../ILessonDAO.java) (revision 51fb2a37254f24bb2a805d4ffd54482c779f43fa) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILessonDAO.java (.../ILessonDAO.java) (revision fba2480356aa5ddda0c8308eb917d72d16aa32eb) @@ -192,4 +192,14 @@ * @return list of teachers that monitor the lesson which contains the tool with given session ID */ List getMonitorsByToolSessionId(Long sessionId); + + /** + * Finds number of preview and all lessons. + */ + long[] getPreviewLessonCount(); + + /** + * Finds IDs of preview lessons. + */ + List getPreviewLessons(Integer limit); } \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LessonDAO.java =================================================================== diff -u -r51fb2a37254f24bb2a805d4ffd54482c779f43fa -rfba2480356aa5ddda0c8308eb917d72d16aa32eb --- lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LessonDAO.java (.../LessonDAO.java) (revision 51fb2a37254f24bb2a805d4ffd54482c779f43fa) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LessonDAO.java (.../LessonDAO.java) (revision fba2480356aa5ddda0c8308eb917d72d16aa32eb) @@ -82,6 +82,12 @@ + "JOIN lams_group AS g ON g.group_id ging.staff_group_id AND g.grouping_id = ging.grouping_id " + "LEFT JOIN lams_user_group AS ug ON ug.group_id = g.group_id AND users.user_id = ug.user_id"; + private final static String COUNT_LESSONS = "SELECT COUNT (*) FROM " + Lesson.class.getName(); + private final static String COUNT_PREVIEW_LESSONS = "SELECT COUNT(*) FROM " + Lesson.class.getName() + + " AS lesson WHERE lesson.learningDesign.copyTypeID = " + LearningDesign.COPY_TYPE_PREVIEW; + private final static String FIND_PREVIEW_LESSON_IDS = "SELECT lesson.lessonId FROM " + Lesson.class.getName() + + " AS lesson WHERE lesson.learningDesign.copyTypeID = " + LearningDesign.COPY_TYPE_PREVIEW; + /** * Retrieves the Lesson. Used in instances where it cannot be lazy loaded so it forces an initialize. * @@ -358,4 +364,24 @@ } return result; } + + @Override + public long[] getPreviewLessonCount() { + Query query = getSession().createQuery(LessonDAO.COUNT_LESSONS); + long allLessons = ((Number) query.uniqueResult()).longValue(); + query = getSession().createQuery(LessonDAO.COUNT_PREVIEW_LESSONS); + long previewLessons = ((Number) query.uniqueResult()).longValue(); + + return new long[] { previewLessons, allLessons }; + } + + @Override + @SuppressWarnings("unchecked") + public List getPreviewLessons(Integer limit) { + Query query = getSession().createQuery(FIND_PREVIEW_LESSON_IDS); + if (limit != null) { + query.setMaxResults(limit); + } + return query.list(); + } } \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java =================================================================== diff -u -raa6183a82f06d3e58a7115eb0f4d9609c1fafd80 -rfba2480356aa5ddda0c8308eb917d72d16aa32eb --- lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java (.../ILessonService.java) (revision aa6183a82f06d3e58a7115eb0f4d9609c1fafd80) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java (.../ILessonService.java) (revision fba2480356aa5ddda0c8308eb917d72d16aa32eb) @@ -21,7 +21,6 @@ * **************************************************************** */ - package org.lamsfoundation.lams.lesson.service; import java.util.Collection; @@ -414,5 +413,16 @@ Set getReleasedSucceedingLessons(Long completedLessonId, Integer learnerId); void removeLearnerProgress(Long lessonId, Integer userId); + void saveLesson(Lesson lesson); + + /** + * Finds number of preview and all lessons. + */ + long[] getPreviewLessonCount(); + + /** + * Finds IDs of preview lessons. + */ + List getPreviewLessons(Integer limit); } \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java =================================================================== diff -u -r14340cffb8e7ee719460a70a3d0ddf0cebe7930b -rfba2480356aa5ddda0c8308eb917d72d16aa32eb --- lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java (.../LessonService.java) (revision 14340cffb8e7ee719460a70a3d0ddf0cebe7930b) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java (.../LessonService.java) (revision fba2480356aa5ddda0c8308eb917d72d16aa32eb) @@ -659,6 +659,16 @@ } @Override + public long[] getPreviewLessonCount() { + return lessonDAO.getPreviewLessonCount(); + } + + @Override + public List getPreviewLessons(Integer limit) { + return lessonDAO.getPreviewLessons(limit); + } + + @Override public boolean checkLessonReleaseConditions(Long lessonId, Integer learnerId) { Lesson lesson = getLesson(lessonId); if (lesson != null) { @@ -687,6 +697,7 @@ return releasedSucceedingLessons; } + @Override public void saveLesson(Lesson lesson) { lessonDAO.saveLesson(lesson); }