Fisheye: Tag d5655905b56e2063bc3854df756ef16572d2c745 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/LibraryManageAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/ToolContentListAction.java =================================================================== diff -u -r81664cec15f3a1f6cc57f59aeae16719aafcf464 -rd5655905b56e2063bc3854df756ef16572d2c745 --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/ToolContentListAction.java (.../ToolContentListAction.java) (revision 81664cec15f3a1f6cc57f59aeae16719aafcf464) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/ToolContentListAction.java (.../ToolContentListAction.java) (revision d5655905b56e2063bc3854df756ef16572d2c745) @@ -48,6 +48,7 @@ import org.lamsfoundation.lams.usermanagement.Role; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; import org.springframework.web.context.WebApplicationContext; @@ -63,82 +64,186 @@ */ public class ToolContentListAction extends Action { - private String getUserLanguage() { - HttpSession ss = SessionManager.getSession(); - UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - return user != null ? user.getLocaleLanguage() : ""; - } + private static final String PARAM_ACTION = "action"; + private static final String PARAM_LIBRARY_ID = "libraryID"; + private static final String ATTRIBUTE_ERROR_NAME = "errorName"; + private static final String ATTRIBUTE_ERROR_MESSAGE = "errorMessage"; + private static final String ATTRIBUTE_LIBRARY = "toolLibrary"; + private static final String ATTRIBUTE_VALIDITY = "learningLibraryValidity"; + private static final String ATTRIBUTE_TOOL_VERSIONS = "toolVersions"; + private static final String ATTRIBUTE_DATABASE_VERSIONS = "dbVersions"; + + private static final String FORWARD_SUCCESS = "toolcontentlist"; + private static final String FORWARD_ERROR = "error"; + + private static final String ACTION_ENABLE = "enable"; + private static final String ACTION_DISABLE = "disable"; + + private static final String QUERY_DATABASE_VERSIONS = "select system_name, patch_level from patches"; + + private static ILearningDesignService learningDesignService; + private static IUserManagementService userManagementService; + private static DataSource dataSource; + + @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // check permission if (!(request.isUserInRole(Role.SYSADMIN) || request.isUserInRole(Role.AUTHOR_ADMIN))) { - request.setAttribute("errorName", "ToolContentListAction"); - request.setAttribute("errorMessage", AdminServiceProxy.getMessageService(getServlet().getServletContext()) - .getMessage("error.authorisation")); - return mapping.findForward("error"); + request.setAttribute(ToolContentListAction.ATTRIBUTE_ERROR_NAME, "ToolContentListAction"); + request.setAttribute( + ToolContentListAction.ATTRIBUTE_ERROR_MESSAGE, + AdminServiceProxy.getMessageService(getServlet().getServletContext()).getMessage( + "error.authorisation")); + return mapping.findForward(ToolContentListAction.FORWARD_ERROR); } + + // not just display, but enable/disable a learning library + String param = request.getParameter(ToolContentListAction.PARAM_ACTION); + if (StringUtils.equals(param, ToolContentListAction.ACTION_ENABLE)) { + if (checkPriviledge(request)) { + enableLibrary(mapping, form, request, response); + } else { + return mapping.findForward(ToolContentListAction.FORWARD_ERROR); + } + } else { + if (StringUtils.equals(param, ToolContentListAction.ACTION_DISABLE)) { + if (checkPriviledge(request)) { + disableLibrary(mapping, form, request, response); + } else { + return mapping.findForward(ToolContentListAction.FORWARD_ERROR); + } + } + } - // get learning library dtos - WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() - .getServletContext()); - ILearningDesignService learningDesignService = (ILearningDesignService) ctx.getBean("learningDesignService"); + // get learning library dtos and their validity + List learningLibraryDTOs = getLearningDesignService().getAllLearningLibraryDetails(false, + getUserLanguage()); + // this is filled when executing following method, for efficiency purposes + HashMap learningLibraryValidity = new HashMap(learningLibraryDTOs.size()); + ArrayList toolLibrary = filterMultipleToolEntries(learningLibraryDTOs, + learningLibraryValidity); + request.setAttribute(ToolContentListAction.ATTRIBUTE_LIBRARY, toolLibrary); + request.setAttribute(ToolContentListAction.ATTRIBUTE_VALIDITY, learningLibraryValidity); - List learningLibraryDTOs = learningDesignService.getAllLearningLibraryDetails(getUserLanguage()); - - ArrayList activeTools = filterActiveTools(learningLibraryDTOs); - request.setAttribute("activeTools", activeTools); - // get tool versions - IUserManagementService usermanagementService = (IUserManagementService) ctx.getBean("userManagementService"); - HashMap toolVersions = new HashMap(); - List tools = usermanagementService.findAll(Tool.class); + List tools = getUserManagementService().findAll(Tool.class); for (Tool tool : tools) { toolVersions.put(tool.getToolId(), tool.getToolVersion()); } - request.setAttribute("toolVersions", toolVersions); + request.setAttribute(ToolContentListAction.ATTRIBUTE_TOOL_VERSIONS, toolVersions); // get tool database versions HashMap dbVersions = new HashMap(); - DataSource dataSource = (DataSource) ctx.getBean("dataSource"); - Connection conn = dataSource.getConnection(); - PreparedStatement query = conn.prepareStatement("select system_name, patch_level from patches"); + Connection conn = getDataSource().getConnection(); + PreparedStatement query = conn.prepareStatement(ToolContentListAction.QUERY_DATABASE_VERSIONS); ResultSet results = query.executeQuery(); while (results.next()) { dbVersions.put(results.getString("system_name"), results.getInt("patch_level")); } - request.setAttribute("dbVersions", dbVersions); + request.setAttribute(ToolContentListAction.ATTRIBUTE_DATABASE_VERSIONS, dbVersions); - return mapping.findForward("toolcontentlist"); + return mapping.findForward(ToolContentListAction.FORWARD_SUCCESS); } - // returns LibraryActivityDTOs of valid tools from full list of tools - private ArrayList filterActiveTools(List learningLibraryDTOs) { + // returns full list of learning libraries, valid or not + private ArrayList filterMultipleToolEntries(List learningLibraryDTOs, + HashMap learningLibraryValidity) { ArrayList activeTools = new ArrayList(); - for (int i = 0; i < learningLibraryDTOs.size(); i++) { - LearningLibraryDTO dto = (LearningLibraryDTO) learningLibraryDTOs.get(i); - if (dto.getValidFlag()) { - List templateActivities = dto.getTemplateActivities(); - for (int j = 0; j < templateActivities.size(); j++) { - LibraryActivityDTO template = (LibraryActivityDTO) templateActivities.get(j); - if (template.getToolContentID() != null) { - if (!toolExists(template, activeTools)) + ArrayList activeCombinedTools = new ArrayList(); + for (LearningLibraryDTO learningLibraryDTO : learningLibraryDTOs) { + // populate information about learning libary validity + learningLibraryValidity.put(learningLibraryDTO.getLearningLibraryID(), learningLibraryDTO.getValidFlag()); + for (LibraryActivityDTO template : (List) learningLibraryDTO.getTemplateActivities()) { + // no learning library ID = a part of combined learning library, we already have it in the list + if (template.getLearningLibraryID() != null) { + // combined libraries do not have tool content ID set + if (template.getToolContentID() == null) { + if (!toolExists(template, activeCombinedTools)) { + activeCombinedTools.add(template); + } + } else { + if (!toolExists(template, activeTools)) { activeTools.add(template); + } } } } } + // put combined libraries at the end, purely for easy of use + activeTools.addAll(activeCombinedTools); return activeTools; } - private boolean toolExists(LibraryActivityDTO item, ArrayList list) { - for (LibraryActivityDTO l : list) { - if (StringUtils.equals(item.getToolSignature(), l.getToolSignature())) + private boolean toolExists(LibraryActivityDTO newItem, ArrayList list) { + for (LibraryActivityDTO libraryActivityDTO : list) { + if (newItem.getLearningLibraryID().equals(libraryActivityDTO.getLearningLibraryID())) { return true; + } } return false; } -} + private String getUserLanguage() { + HttpSession ss = SessionManager.getSession(); + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + return user == null ? "" : user.getLocaleLanguage(); + } + + private boolean checkPriviledge(HttpServletRequest request) { + if (!getUserManagementService().isUserSysAdmin()) { + request.setAttribute(ToolContentListAction.ATTRIBUTE_ERROR_NAME, "ToolContentListAction"); + request.setAttribute( + ToolContentListAction.ATTRIBUTE_ERROR_MESSAGE, + AdminServiceProxy.getMessageService(getServlet().getServletContext()).getMessage( + "error.no.sysadmin.priviledge")); + return false; + } + return true; + } + + private void disableLibrary(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + Long learningLibraryId = WebUtil.readLongParam(request, ToolContentListAction.PARAM_LIBRARY_ID, false); + ILearningDesignService ldService = getLearningDesignService(); + ldService.setValid(learningLibraryId, false); + } + + private void enableLibrary(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + Long learningLibraryId = WebUtil.readLongParam(request, ToolContentListAction.PARAM_LIBRARY_ID, false); + ILearningDesignService ldService = getLearningDesignService(); + ldService.setValid(learningLibraryId, true); + + } + + private ILearningDesignService getLearningDesignService() { + if (ToolContentListAction.learningDesignService == null) { + WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() + .getServletContext()); + ToolContentListAction.learningDesignService = (ILearningDesignService) ctx.getBean("learningDesignService"); + } + return ToolContentListAction.learningDesignService; + } + + private IUserManagementService getUserManagementService() { + if (ToolContentListAction.userManagementService == null) { + WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() + .getServletContext()); + ToolContentListAction.userManagementService = (IUserManagementService) ctx.getBean("userManagementService"); + } + return ToolContentListAction.userManagementService; + } + + private DataSource getDataSource() { + if (ToolContentListAction.dataSource == null) { + WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() + .getServletContext()); + ToolContentListAction.dataSource = (DataSource) ctx.getBean("dataSource"); + } + return ToolContentListAction.dataSource; + } +} \ No newline at end of file Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/SysAdminStartAction.java =================================================================== diff -u -r009fbce36f45d0929f8007c4bbc798242f57d3af -rd5655905b56e2063bc3854df756ef16572d2c745 --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/SysAdminStartAction.java (.../SysAdminStartAction.java) (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/SysAdminStartAction.java (.../SysAdminStartAction.java) (revision d5655905b56e2063bc3854df756ef16572d2c745) @@ -71,7 +71,6 @@ links.add(new LinkBean("loginmaintain.do", "sysadmin.maintain.loginpage")); links.add(new LinkBean("serverlist.do", "sysadmin.maintain.external.servers")); links.add(new LinkBean("register.do", "sysadmin.register.server")); - links.add(new LinkBean("libraryManage.do", "sysadmin.library.management")); links.add(new LinkBean("statistics.do", "admin.statistics.title")); links.add(new LinkBean("themeManagement.do", "admin.themes.title")); links.add(new LinkBean("timezonemanagement.do", "admin.timezone.title")); Fisheye: Tag d5655905b56e2063bc3854df756ef16572d2c745 refers to a dead (removed) revision in file `lams_admin/web/librarylist.jsp'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/web/toolcontent/toolcontentlist.jsp =================================================================== diff -u -rde62f86fb8e48baa6e3c361b0eded0324baef071 -rd5655905b56e2063bc3854df756ef16572d2c745 --- lams_admin/web/toolcontent/toolcontentlist.jsp (.../toolcontentlist.jsp) (revision de62f86fb8e48baa6e3c361b0eded0324baef071) +++ lams_admin/web/toolcontent/toolcontentlist.jsp (.../toolcontentlist.jsp) (revision d5655905b56e2063bc3854df756ef16572d2c745) @@ -13,7 +13,7 @@

- + @@ -26,8 +26,9 @@ + - + @@ -41,28 +42,36 @@ + + + + + + + + + + - - - ?toolContentID=&contentFolderID=-1" - - - - - - - -    - "> - - - - - + + + + ?toolContentID=&contentFolderID=-1" + + + + + +    + "> + + + -

\ No newline at end of file +

+

${fn:length(toolLibrary)}

\ No newline at end of file