Index: lams_central/src/java/org/lamsfoundation/lams/web/outcome/OutcomeController.java =================================================================== diff -u -r67db3e1b2ada0d59ff98c807a54282783797c5e6 -r0f2b554d8e5dca78a8e936730490d03ecd0357ba --- lams_central/src/java/org/lamsfoundation/lams/web/outcome/OutcomeController.java (.../OutcomeController.java) (revision 67db3e1b2ada0d59ff98c807a54282783797c5e6) +++ lams_central/src/java/org/lamsfoundation/lams/web/outcome/OutcomeController.java (.../OutcomeController.java) (revision 0f2b554d8e5dca78a8e936730490d03ecd0357ba) @@ -22,10 +22,7 @@ package org.lamsfoundation.lams.web.outcome; -import java.util.Collections; -import java.util.Comparator; import java.util.Date; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; @@ -46,6 +43,7 @@ import org.lamsfoundation.lams.outcome.OutcomeScale; import org.lamsfoundation.lams.outcome.OutcomeScaleItem; import org.lamsfoundation.lams.outcome.service.IOutcomeService; +import org.lamsfoundation.lams.outcome.service.OutcomeService; import org.lamsfoundation.lams.security.ISecurityService; import org.lamsfoundation.lams.usermanagement.Role; import org.lamsfoundation.lams.usermanagement.User; @@ -309,7 +307,7 @@ List outcomeMappings = outcomeService.getOutcomeMappings(lessonId, toolContentId, itemId, qbQuestionId); - OutcomeController.filterQuestionMappings(outcomeMappings); + OutcomeService.filterQuestionMappings(outcomeMappings); ArrayNode responseJSON = JsonNodeFactory.instance.arrayNode(); for (OutcomeMapping outcomeMapping : outcomeMappings) { @@ -645,32 +643,4 @@ errorMap.add("GLOBAL", messageService.getMessage("outcome.manage.add.error.code.blank")); } } - - /** - * There can be duplicates in mappings, if one comes from activity and the other comes from a QB question that the - * activity imported. - * We need to get rid of duplicates and sort the remaining mappings. - */ - private static void filterQuestionMappings(List mappings) { - Iterator iterator = mappings.iterator(); - while (iterator.hasNext()) { - OutcomeMapping mapping = iterator.next(); - boolean duplicateFound = false; - for (OutcomeMapping otherMapping : mappings) { - if (!mapping.getMappingId().equals(otherMapping.getMappingId()) - && mapping.getOutcome().getOutcomeId().equals(otherMapping.getOutcome().getOutcomeId())) { - duplicateFound = true; - break; - } - } - // remove the one coming from activity, not one coming from question - if (duplicateFound && mapping.getQbQuestionId() == null) { - iterator.remove(); - } - } - - Collections.sort(mappings, - Comparator.comparing(OutcomeMapping::getOutcome, Comparator.comparing(Outcome::getName))); - } - } \ No newline at end of file Index: lams_central/src/java/org/lamsfoundation/lams/web/qb/QbStatsController.java =================================================================== diff -u -r0b1e74374b821758fdda7835d8d283bf84fa8db0 -r0f2b554d8e5dca78a8e936730490d03ecd0357ba --- lams_central/src/java/org/lamsfoundation/lams/web/qb/QbStatsController.java (.../QbStatsController.java) (revision 0b1e74374b821758fdda7835d8d283bf84fa8db0) +++ lams_central/src/java/org/lamsfoundation/lams/web/qb/QbStatsController.java (.../QbStatsController.java) (revision 0f2b554d8e5dca78a8e936730490d03ecd0357ba) @@ -1,87 +1,108 @@ -/**************************************************************** - * 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.web.qb; - -import java.util.Collection; - -import javax.servlet.http.HttpSession; - -import org.apache.log4j.Logger; -import org.lamsfoundation.lams.qb.dto.QbStatsDTO; -import org.lamsfoundation.lams.qb.model.QbCollection; -import org.lamsfoundation.lams.qb.service.IQbService; -import org.lamsfoundation.lams.usermanagement.dto.UserDTO; -import org.lamsfoundation.lams.util.Configuration; -import org.lamsfoundation.lams.util.ConfigurationKeys; -import org.lamsfoundation.lams.util.MessageService; -import org.lamsfoundation.lams.web.session.SessionManager; -import org.lamsfoundation.lams.web.util.AttributeNames; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; - -@Controller -@RequestMapping("/qb/stats") -public class QbStatsController { - private static Logger log = Logger.getLogger(QbStatsController.class); - - @Autowired - @Qualifier("centralMessageService") - private MessageService messageService; - - @Autowired - private IQbService qbService; - - @RequestMapping("/show") - public String showStats(@RequestParam long qbQuestionUid, Model model) throws Exception { - QbStatsDTO stats = qbService.getQuestionStats(qbQuestionUid); - model.addAttribute("stats", stats); - - Collection existingCollections = qbService.getQuestionCollectionsByUid(qbQuestionUid); - model.addAttribute("existingCollections", existingCollections); - - Integer userId = getUserId(); - Collection availableCollections = qbService.getUserCollections(userId); - availableCollections.removeAll(existingCollections); - model.addAttribute("availableCollections", availableCollections); - - boolean permanentRemove = existingCollections.size() <= 1; - model.addAttribute("permanentRemove", permanentRemove); - model.addAttribute("permanentRemovePossible", - permanentRemove ? qbService.removeQuestionPossibleByUid(qbQuestionUid) : false); - - model.addAttribute("transferAllowed", - Configuration.getAsBoolean(ConfigurationKeys.QB_COLLECTIONS_TRANSFER_ALLOW)); - - return "qb/stats"; - } - - private Integer getUserId() { - HttpSession ss = SessionManager.getSession(); - UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - return user != null ? user.getUserID() : null; - } +/**************************************************************** + * 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.web.qb; + +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +import javax.servlet.http.HttpSession; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.outcome.OutcomeMapping; +import org.lamsfoundation.lams.outcome.service.IOutcomeService; +import org.lamsfoundation.lams.outcome.service.OutcomeService; +import org.lamsfoundation.lams.qb.dto.QbStatsDTO; +import org.lamsfoundation.lams.qb.model.QbCollection; +import org.lamsfoundation.lams.qb.service.IQbService; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.ConfigurationKeys; +import org.lamsfoundation.lams.util.MessageService; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller +@RequestMapping("/qb/stats") +public class QbStatsController { + private static Logger log = Logger.getLogger(QbStatsController.class); + + @Autowired + @Qualifier("centralMessageService") + private MessageService messageService; + + @Autowired + private IQbService qbService; + + @Autowired + private IOutcomeService outcomeService; + + @RequestMapping("/show") + public String showStats(@RequestParam long qbQuestionUid, Model model) throws Exception { + QbStatsDTO stats = qbService.getQuestionStats(qbQuestionUid); + model.addAttribute("stats", stats); + + Integer userId = getUserId(); + int qbQuestionId = stats.getQuestion().getQuestionId(); + boolean managementAllowed = qbService.isQuestionInUserCollection(qbQuestionId, userId); + model.addAttribute("managementAllowed", managementAllowed); + + Collection existingCollections = qbService.getQuestionCollectionsByUid(qbQuestionUid); + model.addAttribute("existingCollections", existingCollections); + + if (managementAllowed) { + Collection availableCollections = qbService.getUserCollections(userId); + availableCollections.removeAll(existingCollections); + model.addAttribute("availableCollections", availableCollections); + + boolean permanentRemove = existingCollections.size() <= 1; + model.addAttribute("permanentRemove", permanentRemove); + model.addAttribute("permanentRemovePossible", + permanentRemove ? qbService.removeQuestionPossibleByUid(qbQuestionUid) : false); + + model.addAttribute("transferAllowed", + Configuration.getAsBoolean(ConfigurationKeys.QB_COLLECTIONS_TRANSFER_ALLOW)); + + } else { + List outcomeMappings = outcomeService.getOutcomeMappings(null, null, null, qbQuestionId); + OutcomeService.filterQuestionMappings(outcomeMappings); + List outcomes = outcomeMappings.stream() + .collect(Collectors.mapping(m -> m.getOutcome().getName(), Collectors.toList())); + model.addAttribute("outcomes", outcomes); + } + + return "qb/stats"; + } + + private Integer getUserId() { + HttpSession ss = SessionManager.getSession(); + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + return user != null ? user.getUserID() : null; + } } \ No newline at end of file Index: lams_central/web/qb/stats.jsp =================================================================== diff -u -r4cea4e785c1ece3773109846b5bf78d25b0240d2 -r0f2b554d8e5dca78a8e936730490d03ecd0357ba --- lams_central/web/qb/stats.jsp (.../stats.jsp) (revision 4cea4e785c1ece3773109846b5bf78d25b0240d2) +++ lams_central/web/qb/stats.jsp (.../stats.jsp) (revision 0f2b554d8e5dca78a8e936730490d03ecd0357ba) @@ -58,8 +58,8 @@