Index: lams_central/src/java/org/lamsfoundation/lams/authoring/ObjectExtractor.java =================================================================== diff -u -r73b16b1e6ae040974e8ba89abf3497abceb9420f -r96033f32ff880d045b4c087f52628d233dc98095 --- lams_central/src/java/org/lamsfoundation/lams/authoring/ObjectExtractor.java (.../ObjectExtractor.java) (revision 73b16b1e6ae040974e8ba89abf3497abceb9420f) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/ObjectExtractor.java (.../ObjectExtractor.java) (revision 96033f32ff880d045b4c087f52628d233dc98095) @@ -767,7 +767,7 @@ throws ObjectExtractorException { String toolOutputDefinition = JsonUtil.optString(activityDetails, AuthoringJsonTags.TOOL_OUTPUT_DEFINITION); if (StringUtils.isNotBlank(toolOutputDefinition)) { - ActivityEvaluation evaluation = toolActivity.getEvaluation(); + ActivityEvaluation evaluation = activityDAO.getEvaluationByActivityId(toolActivity.getActivityId()); if (evaluation == null) { evaluation = new ActivityEvaluation(); evaluation.setActivity(toolActivity); @@ -780,59 +780,8 @@ } else { evaluation.setWeight(Integer.valueOf(weight)); } - toolActivity.setEvaluation(evaluation); - } else { - // update the parent toolActivity - toolActivity.setEvaluation(null); - } - activityDAO.update(toolActivity); - } - private void parseCompetences(ArrayNode competenceList) throws ObjectExtractorException { - Set existingCompetences = learningDesign.getCompetences(); - if (competenceList != null) { - for (JsonNode competenceJSON : competenceList) { - String title = JsonUtil.optString(competenceJSON, AuthoringJsonTags.TITLE); - String description = JsonUtil.optString(competenceJSON, AuthoringJsonTags.DESCRIPTION); - - if (getComptenceFromSet(existingCompetences, title) != null) { - Competence updateCompetence = getComptenceFromSet(existingCompetences, title); - updateCompetence.setDescription(description); - competenceDAO.saveOrUpdate(updateCompetence); - } else { - Competence newCompetence = new Competence(); - newCompetence.setTitle(title); - newCompetence.setDescription(description); - newCompetence.setLearningDesign(learningDesign); - competenceDAO.saveOrUpdate(newCompetence); - } - } - - // now go through and delete any competences from the old list, - // that dont exist in the new list. - Set removeCompetences = new HashSet<>(); - if (existingCompetences != null) { - if ((competenceList != null) && (competenceList.size() > 0)) { - for (Competence existingCompetence : existingCompetences) { - boolean remove = true; - for (JsonNode competenceJSON : competenceList) { - if (existingCompetence.getTitle() - .equals(JsonUtil.optString(competenceJSON, AuthoringJsonTags.TITLE))) { - remove = false; - break; - } - } - - if (remove) { - removeCompetences.add(existingCompetence); - } - } - } else { - removeCompetences.addAll(existingCompetences); - } - // competenceDAO.deleteAll(removeCompetences); - learningDesign.getCompetences().removeAll(removeCompetences); - } + activityDAO.insertOrUpdate(evaluation); } } @@ -1228,8 +1177,8 @@ } private void buildPermissionGateActivity(PermissionGateActivity activity, ObjectNode activityDetails) { - activity.setGateStopAtPrecedingActivity(JsonUtil.optBoolean(activityDetails, - AuthoringJsonTags.GATE_STOP_AT_PRECEDING_ACTIVITY, false)); + activity.setGateStopAtPrecedingActivity( + JsonUtil.optBoolean(activityDetails, AuthoringJsonTags.GATE_STOP_AT_PRECEDING_ACTIVITY, false)); activity.setSystemTool(getSystemTool(SystemTool.PERMISSION_GATE)); } @@ -1248,8 +1197,8 @@ Boolean isGateActivityCompletionBased = JsonUtil.optBoolean(activityDetails, AuthoringJsonTags.GATE_ACTIVITY_COMPLETION_BASED); activity.setGateActivityCompletionBased(isGateActivityCompletionBased); - activity.setGateStopAtPrecedingActivity(JsonUtil.optBoolean(activityDetails, - AuthoringJsonTags.GATE_STOP_AT_PRECEDING_ACTIVITY, false)); + activity.setGateStopAtPrecedingActivity( + JsonUtil.optBoolean(activityDetails, AuthoringJsonTags.GATE_STOP_AT_PRECEDING_ACTIVITY, false)); activity.setSystemTool(getSystemTool(SystemTool.SCHEDULE_GATE)); } @@ -1672,8 +1621,8 @@ } private void buildConditionGateActivity(ConditionGateActivity activity, ObjectNode activityDetails) { - activity.setGateStopAtPrecedingActivity(JsonUtil.optBoolean(activityDetails, - AuthoringJsonTags.GATE_STOP_AT_PRECEDING_ACTIVITY, false)); + activity.setGateStopAtPrecedingActivity( + JsonUtil.optBoolean(activityDetails, AuthoringJsonTags.GATE_STOP_AT_PRECEDING_ACTIVITY, false)); activity.setSystemTool(getSystemTool(SystemTool.CONDITION_GATE)); } } \ No newline at end of file Index: lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java =================================================================== diff -u -r585c5afc5fcabdb88754b7c1bd7f7ec5eef4e150 -r96033f32ff880d045b4c087f52628d233dc98095 --- lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java (.../AuthoringService.java) (revision 585c5afc5fcabdb88754b7c1bd7f7ec5eef4e150) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java (.../AuthoringService.java) (revision 96033f32ff880d045b4c087f52628d233dc98095) @@ -1045,6 +1045,9 @@ if (activity.isBranchingActivity()) { activityDAO.insert(activity); } + if (activity.isToolActivity() && ((ToolActivity) activity).getEvaluation() != null) { + activityDAO.insertOrUpdate(((ToolActivity) activity).getEvaluation()); + } } return newActivities; @@ -1492,6 +1495,9 @@ activity.setXcoord(300); activity.setYcoord(300); activityDAO.insert(activity); + if (activity.getEvaluation() != null) { + activityDAO.insert(activity.getEvaluation()); + } // make Gradebook aware of the activity List defnDTOList = getToolOutputDefinitions(toolContentID, @@ -1508,7 +1514,6 @@ ActivityEvaluation evaluation = new ActivityEvaluation(); evaluation.setToolOutputDefinition(gradebookToolOutputDefinitionName); evaluation.setActivity(activity); - activity.setEvaluation(evaluation); activityDAO.update(activity); } Index: lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java =================================================================== diff -u -rc975a1230b65f2245c5c77ba413afe97a2816df9 -r96033f32ff880d045b4c087f52628d233dc98095 --- lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java (.../LessonManagerServlet.java) (revision c975a1230b65f2245c5c77ba413afe97a2816df9) +++ lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java (.../LessonManagerServlet.java) (revision 96033f32ff880d045b4c087f52628d233dc98095) @@ -928,8 +928,8 @@ if (StringUtils.isNotBlank(userName)) { // integrationService.addExtUserToLesson(extServer, IntegrationConstants.METHOD_LEARNER, lessonId, // userName, firstName, lastName, email, courseId, countryIsoCode, langIsoCode); - integrationService.addExtUserToCourseAndLesson(extServer, IntegrationConstants.METHOD_LEARNER, lessonId, - userName, firstName, lastName, email, courseId, country, locale); + integrationService.addExtUserToCourseAndLesson(extServer, IntegrationConstants.METHOD_LEARNER, + lessonId, userName, firstName, lastName, email, courseId, country, locale); } i++; } @@ -946,8 +946,8 @@ } if (StringUtils.isNotBlank(userName)) { - integrationService.addExtUserToCourseAndLesson(extServer, IntegrationConstants.METHOD_MONITOR, lessonId, - userName, firstName, lastName, email, courseId, country, locale); + integrationService.addExtUserToCourseAndLesson(extServer, IntegrationConstants.METHOD_MONITOR, + lessonId, userName, firstName, lastName, email, courseId, country, locale); } i++; } @@ -1018,8 +1018,8 @@ Element lessonElement = document.createElement(CentralConstants.ELEM_LESSON); lessonElement.setAttribute(CentralConstants.ATTR_LESSON_ID, "" + lessonId); lessonElement.setAttribute("lessonName", lesson.getLessonName()); - String createDateTime = lesson.getCreateDateTime().toString(); - lessonElement.setAttribute("createDateTime", StringUtils.isBlank(createDateTime) ? "" : createDateTime); + String createDateTime = lesson.getCreateDateTime().toString(); + lessonElement.setAttribute("createDateTime", StringUtils.isBlank(createDateTime) ? "" : createDateTime); // calculate lesson's MaxPossibleMark Long lessonMaxPossibleMark = lamsCoreToolService.getLessonMaxPossibleMark(lesson); @@ -1179,8 +1179,8 @@ toolOutputsElement.setAttribute(CentralConstants.ATTR_LESSON_ID, "" + lessonId); toolOutputsElement.setAttribute("name", lesson.getLessonName()); - String createDateTime = lesson.getCreateDateTime().toString(); - toolOutputsElement.setAttribute("createDateTime", StringUtils.isBlank(createDateTime) ? "" : createDateTime); + String createDateTime = lesson.getCreateDateTime().toString(); + toolOutputsElement.setAttribute("createDateTime", StringUtils.isBlank(createDateTime) ? "" : createDateTime); List learnerProgresses = lessonService.getUserProgressForLesson(lesson.getLessonId()); List toolSessions = lamsCoreToolService.getToolSessionsByLesson(lesson); @@ -1370,7 +1370,8 @@ ToolOutputDefinition definition = toolOutputDefinitions.get(outputName); if (isAuthoredToolOutputs) { - ActivityEvaluation evaluation = activity.getEvaluation(); + ActivityEvaluation evaluation = (ActivityEvaluation) userManagementService + .findById(ActivityEvaluation.class, activity.getActivityId()); if (evaluation != null) { if (outputName.equals(evaluation.getToolOutputDefinition())) { ToolOutput toolOutput = lamsCoreToolService.getOutputFromTool(outputName, toolSession, Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/ToolActivity.java =================================================================== diff -u -r92525f17be9db4e57a8551ff92d004f319fb4b73 -r96033f32ff880d045b4c087f52628d233dc98095 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/ToolActivity.java (.../ToolActivity.java) (revision 92525f17be9db4e57a8551ff92d004f319fb4b73) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/ToolActivity.java (.../ToolActivity.java) (revision 96033f32ff880d045b4c087f52628d233dc98095) @@ -36,11 +36,10 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; -import javax.persistence.OneToOne; +import javax.persistence.Transient; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.log4j.Logger; -import org.hibernate.annotations.Cascade; import org.lamsfoundation.lams.gradebook.GradebookUserActivity; import org.lamsfoundation.lams.learningdesign.strategy.ToolActivityStrategy; import org.lamsfoundation.lams.lesson.Lesson; @@ -51,6 +50,7 @@ import org.lamsfoundation.lams.tool.ToolSession; import org.lamsfoundation.lams.tool.exception.RequiredGroupMissingException; import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.service.UserManagementService; import org.lamsfoundation.lams.util.MessageService; /** @@ -78,13 +78,12 @@ @OneToMany(mappedBy = "toolActivity") private Set competenceMappings = new HashSet<>(); - @OneToOne(fetch = FetchType.LAZY, mappedBy = "activity") - @Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE) - private ActivityEvaluation evaluation; - @OneToMany(mappedBy = "activity") private Set gradebookUserActivities = new HashSet<>(); + @Transient + private ActivityEvaluation evaluation; + /** default constructor */ public ToolActivity() { super.simpleActivityStrategy = new ToolActivityStrategy(this); @@ -115,12 +114,14 @@ newToolActivity.setCompetenceMappings(newCompetenceMappings); - if (this.evaluation != null) { + ActivityEvaluation evaluation = (ActivityEvaluation) UserManagementService.getInstance() + .findById(ActivityEvaluation.class, this.getActivityId()); + if (evaluation != null) { ActivityEvaluation newEvaluation = new ActivityEvaluation(); newEvaluation.setToolOutputDefinition(evaluation.getToolOutputDefinition()); newEvaluation.setWeight(evaluation.getWeight()); newEvaluation.setActivity(newToolActivity); - newToolActivity.setEvaluation(newEvaluation); + newToolActivity.evaluation = newEvaluation; } return newToolActivity; @@ -262,15 +263,12 @@ return evaluation; } - public void setEvaluation(ActivityEvaluation evaluation) { - this.evaluation = evaluation; - } - public Set getGradebookUserActivities() { return gradebookUserActivities; } public void setGradebookUserActivities(Set gradebookUserActivities) { this.gradebookUserActivities = gradebookUserActivities; } + } \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/dao/IActivityDAO.java =================================================================== diff -u -r2188972474f8d186d6811e3dea2e4136be669335 -r96033f32ff880d045b4c087f52628d233dc98095 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/dao/IActivityDAO.java (.../IActivityDAO.java) (revision 2188972474f8d186d6811e3dea2e4136be669335) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/dao/IActivityDAO.java (.../IActivityDAO.java) (revision 96033f32ff880d045b4c087f52628d233dc98095) @@ -27,6 +27,7 @@ import org.lamsfoundation.lams.dao.IBaseDAO; import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.ActivityEvaluation; import org.lamsfoundation.lams.learningdesign.LearningDesign; import org.lamsfoundation.lams.learningdesign.ToolActivity; @@ -143,5 +144,6 @@ * @return */ ToolActivity getToolActivityByToolContentId(Long toolContentId); - -} + + ActivityEvaluation getEvaluationByActivityId(long activityId); +} \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/dao/hibernate/ActivityDAO.java =================================================================== diff -u -r2188972474f8d186d6811e3dea2e4136be669335 -r96033f32ff880d045b4c087f52628d233dc98095 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/dao/hibernate/ActivityDAO.java (.../ActivityDAO.java) (revision 2188972474f8d186d6811e3dea2e4136be669335) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/dao/hibernate/ActivityDAO.java (.../ActivityDAO.java) (revision 96033f32ff880d045b4c087f52628d233dc98095) @@ -28,6 +28,7 @@ import org.hibernate.Query; import org.lamsfoundation.lams.dao.hibernate.LAMSBaseDAO; import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.ActivityEvaluation; import org.lamsfoundation.lams.learningdesign.ChosenBranchingActivity; import org.lamsfoundation.lams.learningdesign.ConditionGateActivity; import org.lamsfoundation.lams.learningdesign.FloatingActivity; @@ -238,4 +239,9 @@ List list = this.doFindCacheable(ActivityDAO.FIND_BY_LIBRARY_ID, libraryID); return list != null && list.size() != 0 ? (Activity) list.get(0) : null; } -} + + @Override + public ActivityEvaluation getEvaluationByActivityId(long activityId) { + return find(ActivityEvaluation.class, activityId); + } +} \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/dto/AuthoringActivityDTO.java =================================================================== diff -u -r92525f17be9db4e57a8551ff92d004f319fb4b73 -r96033f32ff880d045b4c087f52628d233dc98095 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/dto/AuthoringActivityDTO.java (.../AuthoringActivityDTO.java) (revision 92525f17be9db4e57a8551ff92d004f319fb4b73) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/dto/AuthoringActivityDTO.java (.../AuthoringActivityDTO.java) (revision 96033f32ff880d045b4c087f52628d233dc98095) @@ -48,6 +48,7 @@ import org.lamsfoundation.lams.learningdesign.SequenceActivity; import org.lamsfoundation.lams.learningdesign.ToolActivity; import org.lamsfoundation.lams.learningdesign.ToolBranchingActivity; +import org.lamsfoundation.lams.usermanagement.service.UserManagementService; import org.lamsfoundation.lams.util.HelpUtil; /** @@ -426,9 +427,10 @@ } } - if (toolActivity.getEvaluation() != null) { + ActivityEvaluation eval = (ActivityEvaluation) UserManagementService.getInstance() + .findById(ActivityEvaluation.class, toolActivity.getActivityId()); + if (eval != null) { evaluation = new ArrayList<>(); - ActivityEvaluation eval = toolActivity.getEvaluation(); evaluation.add(eval.getToolOutputDefinition()); if (eval.getWeight() != null) { evaluation.add(String.valueOf(eval.getWeight())); Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/ExportToolContentService.java =================================================================== diff -u -r92525f17be9db4e57a8551ff92d004f319fb4b73 -r96033f32ff880d045b4c087f52628d233dc98095 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/ExportToolContentService.java (.../ExportToolContentService.java) (revision 92525f17be9db4e57a8551ff92d004f319fb4b73) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/ExportToolContentService.java (.../ExportToolContentService.java) (revision 96033f32ff880d045b4c087f52628d233dc98095) @@ -484,6 +484,7 @@ exportedContentFolders.add(contentFolderID); } } + } // end all activities export // skipping unwanted elements; learning design DTO is altered @@ -1337,8 +1338,7 @@ activityEvaluation.setWeight(Integer.valueOf(eval.get(1))); } activityEvaluation.setActivity((ToolActivity) act); - ((ToolActivity) act).setEvaluation(activityEvaluation); - activityDAO.update(act); + activityDAO.insert(activityEvaluation); } } @@ -1442,7 +1442,8 @@ // Any transitions relating with this tool will be removed! Long fromId = transDto.getFromActivityID(); Long toId = transDto.getToActivityID(); - if (((fromId != null) && removedActMap.containsKey(fromId)) || ((toId != null) && removedActMap.containsKey(toId))) { + if (((fromId != null) && removedActMap.containsKey(fromId)) + || ((toId != null) && removedActMap.containsKey(toId))) { continue; } Transition trans = getTransition(transDto, activityMapper); Index: lams_common/src/java/org/lamsfoundation/lams/tool/service/LamsCoreToolService.java =================================================================== diff -u -r02ce40b60524aa33d326fbda824dcd43f566ab94 -r96033f32ff880d045b4c087f52628d233dc98095 --- lams_common/src/java/org/lamsfoundation/lams/tool/service/LamsCoreToolService.java (.../LamsCoreToolService.java) (revision 02ce40b60524aa33d326fbda824dcd43f566ab94) +++ lams_common/src/java/org/lamsfoundation/lams/tool/service/LamsCoreToolService.java (.../LamsCoreToolService.java) (revision 96033f32ff880d045b4c087f52628d233dc98095) @@ -159,9 +159,9 @@ // if haven't found an existing tool session then create one if (toolSession == null) { if (log.isDebugEnabled()) { - log.debug("Creating tool session for [" + activity.getActivityId() + "," - + activity.getTitle() + "] for learner [" + learner.getLogin() + "] lesson [" - + lesson.getLessonId() + "," + lesson.getLessonName() + "]."); + log.debug("Creating tool session for [" + activity.getActivityId() + "," + activity.getTitle() + + "] for learner [" + learner.getLogin() + "] lesson [" + lesson.getLessonId() + "," + + lesson.getLessonName() + "]."); } toolSession = activity.createToolSessionForActivity(messageService, learner, lesson); @@ -238,7 +238,7 @@ @Override public Long notifyToolToCopyContent(Long toolContentId, String customCSV) throws DataMissingException, ToolException { - ToolContent toolContent = (ToolContent) toolContentDAO.find(ToolContent.class, toolContentId); + ToolContent toolContent = toolContentDAO.find(ToolContent.class, toolContentId); if (toolContent == null) { String error = "The toolContentID " + toolContentId + " is not valid. No such record exists on the database."; @@ -349,8 +349,8 @@ private boolean isActivityReadOnlyFlag(Activity activity) { if (activity.isComplexActivity()) { - for (Activity childActivity : (Set) ((ComplexActivity) systemToolDAO.find(ComplexActivity.class, - activity.getActivityId())).getActivities()) { + for (Activity childActivity : systemToolDAO.find(ComplexActivity.class, activity.getActivityId()) + .getActivities()) { if (isActivityReadOnlyFlag(childActivity)) { return true; } @@ -365,7 +365,7 @@ public SortedMap getOutputDefinitionsFromTool(Long toolContentId, int definitionType) throws ToolException { - ToolContent toolContent = (ToolContent) toolContentDAO.find(ToolContent.class, toolContentId); + ToolContent toolContent = toolContentDAO.find(ToolContent.class, toolContentId); if (toolContent == null) { String error = "The toolContentID " + toolContentId + " is not valid. No such record exists on the database."; @@ -402,7 +402,7 @@ int definitionType, Long inputToolContentId) throws ToolException { SortedMap definitions = getOutputDefinitionsFromTool(outputToolContentId, definitionType); - ToolContent toolContent = (ToolContent) toolContentDAO.find(ToolContent.class, inputToolContentId); + ToolContent toolContent = toolContentDAO.find(ToolContent.class, inputToolContentId); if (toolContent == null) { String error = "The toolContentID " + inputToolContentId + " is not valid. No such record exists on the database."; @@ -422,7 +422,7 @@ Class[] supportedClasses = contentManager.getSupportedToolOutputDefinitionClasses(definitionType); if (supportedClasses != null) { - Set keysToRemove = new TreeSet(); + Set keysToRemove = new TreeSet<>(); for (String key : definitions.keySet()) { ToolOutputDefinition value = definitions.get(key); Class valueClass = value.getValueClass(); @@ -550,7 +550,7 @@ LamsCoreToolService.log.error(error); throw new DataMissingException(error); } - + if (!CommonConstants.TOOL_SIGNATURE_ASSESSMENT.equals(tool.getToolSignature())) { String error = "Only Assessment is capable of providing VSA answers. Bu this session belongs to tool: " + tool.getToolSignature(); @@ -573,7 +573,7 @@ throw new ToolException(message, e); } } - + @Override public List getConfidenceLevelsByToolSession(ToolSession toolSession) { @@ -605,7 +605,7 @@ throw new ToolException(message, e); } } - + @Override public boolean isUserLeaderInActivity(ToolSession toolSession, User learner) throws ToolException { if (toolSession == null) { @@ -713,12 +713,15 @@ @Override public Long getActivityMaxPossibleMark(ToolActivity activity) { // if ActivityEvaluation is not set it means activity will produce no toolOutputs and thus max possible mark is null - if ((activity == null) || (activity.getEvaluation() == null)) { + if (activity == null) { return null; } // the first available activity evaluation will be the only one that activity has - ActivityEvaluation evaluation = activity.getEvaluation(); + ActivityEvaluation evaluation = activityDAO.getEvaluationByActivityId(activity.getActivityId()); + if (evaluation == null) { + return null; + } // searching for the according toolOutputDefinition SortedMap toolOutputDefinitions = getOutputDefinitionsFromTool( @@ -742,7 +745,7 @@ Set activities = getLearningDesignActivities(lesson.getLearningDesign()); // calculate lesson's MaxPossibleMark - Long lessonMaxPossibleMark = 0L; + long lessonMaxPossibleMark = 0L; //take into account whether learning design uses grade weight if (isWeightedMarks(activities)) { lessonMaxPossibleMark = 100L; @@ -767,7 +770,7 @@ private boolean isWeightedMarks(Set activities) { for (ToolActivity toolActivity : activities) { - ActivityEvaluation eval = toolActivity.getEvaluation(); + ActivityEvaluation eval = activityDAO.getEvaluationByActivityId(toolActivity.getActivityId()); if (eval != null && eval.getWeight() != null && eval.getWeight() > 0) { return true; } @@ -779,10 +782,9 @@ * Returns lesson tool activities. It works almost the same as lesson.getLearningDesign().getActivities() except it * solves problem with first activity unable to cast to ToolActivity. */ - @SuppressWarnings("unchecked") private Set getLearningDesignActivities(LearningDesign design) { - Set activities = new TreeSet(); - Set toolActivities = new TreeSet(); + Set activities = new TreeSet<>(); + Set toolActivities = new TreeSet<>(); /* * Hibernate CGLIB is failing to load the first activity in the sequence as a ToolActivity for some mysterious @@ -796,8 +798,12 @@ activities.addAll(design.getActivities()); for (Activity activity : activities) { - if (activity instanceof ToolActivity) { - ToolActivity toolActivity = (ToolActivity) activity; + if (activity.isToolActivity()) { + if (!(activity instanceof ToolActivity)) { + + } + ToolActivity toolActivity = (ToolActivity) (activity instanceof ToolActivity ? activity + : activityDAO.getActivityByActivityId(activity.getActivityId())); toolActivities.add(toolActivity); } } @@ -829,11 +835,11 @@ try { sessionManager.removeToolSession(toolSession.getToolSessionId()); } catch (DataMissingException e) { - log.error("Unable to delete tool data for tool session " - + toolSession.getToolSessionId() + " as toolSession does not exist", e); + log.error("Unable to delete tool data for tool session " + toolSession.getToolSessionId() + + " as toolSession does not exist", e); } catch (ToolException e) { - log.error("Unable to delete tool data for tool session " - + toolSession.getToolSessionId() + " as tool threw an exception", e); + log.error("Unable to delete tool data for tool session " + toolSession.getToolSessionId() + + " as tool threw an exception", e); } // now remove the tool session from the core tables. @@ -929,7 +935,7 @@ url = WebUtil.appendParameterToURL(url, AttributeNames.PARAM_TOOL_CONTENT_ID, activity.getToolContentId().toString()); // should have used LessonService, but reusing existing tools is just easier - Lesson lesson = (Lesson) toolContentDAO.find(Lesson.class, lessonID); + Lesson lesson = toolContentDAO.find(Lesson.class, lessonID); url = WebUtil.appendParameterToURL(url, AttributeNames.PARAM_CONTENT_FOLDER_ID, lesson.getLearningDesign().getContentFolderID()); Index: lams_common/src/java/org/lamsfoundation/lams/tool/service/LamsToolService.java =================================================================== diff -u -rec9b0ffc2e88f3504fd7505ee8474f86d89a2458 -r96033f32ff880d045b4c087f52628d233dc98095 --- lams_common/src/java/org/lamsfoundation/lams/tool/service/LamsToolService.java (.../LamsToolService.java) (revision ec9b0ffc2e88f3504fd7505ee8474f86d89a2458) +++ lams_common/src/java/org/lamsfoundation/lams/tool/service/LamsToolService.java (.../LamsToolService.java) (revision 96033f32ff880d045b4c087f52628d233dc98095) @@ -186,18 +186,17 @@ @Override public String getActivityEvaluation(Long toolContentId) { ToolActivity toolActivity = activityDAO.getToolActivityByToolContentId(toolContentId); - ActivityEvaluation evaluation = toolActivity.getEvaluation(); + ActivityEvaluation evaluation = activityDAO.getEvaluationByActivityId(toolActivity.getActivityId()); return evaluation == null ? null : evaluation.getToolOutputDefinition(); } @Override public void setActivityEvaluation(Long toolContentId, String toolOutputDefinition) { ToolActivity toolActivity = activityDAO.getToolActivityByToolContentId(toolContentId); - ActivityEvaluation evaluation = toolActivity.getEvaluation(); + ActivityEvaluation evaluation = activityDAO.getEvaluationByActivityId(toolActivity.getActivityId()); if (StringUtils.isEmpty(toolOutputDefinition)) { if (evaluation != null) { - toolActivity.setEvaluation(null); activityDAO.delete(evaluation); } gradebookService.removeActivityMark(toolContentId); @@ -208,7 +207,6 @@ if (evaluation == null) { evaluation = new ActivityEvaluation(); evaluation.setActivity(toolActivity); - toolActivity.setEvaluation(evaluation); } else { isToolOutputDefinitionChanged = !toolOutputDefinition.equals(evaluation.getToolOutputDefinition()); } Index: lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/UserManagementService.java =================================================================== diff -u -rf0c17850a35fb02594aaff53a4a175b536eba889 -r96033f32ff880d045b4c087f52628d233dc98095 --- lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/UserManagementService.java (.../UserManagementService.java) (revision f0c17850a35fb02594aaff53a4a175b536eba889) +++ lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/UserManagementService.java (.../UserManagementService.java) (revision 96033f32ff880d045b4c087f52628d233dc98095) @@ -83,6 +83,7 @@ import org.lamsfoundation.lams.util.imgscalr.ResizePictureUtil; import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.beans.factory.InitializingBean; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; @@ -97,7 +98,7 @@ * * @author Fei Yang, Manpreet Minhas */ -public class UserManagementService implements IUserManagementService { +public class UserManagementService implements IUserManagementService, InitializingBean { private Logger log = Logger.getLogger(UserManagementService.class); @@ -125,6 +126,27 @@ private IToolContentHandler centralToolContentHandler; + private static IUserManagementService instance; + + /* + * Sometimes we need access to a service from within an entity. + * For example when fetching ActivityEvaluation for ToolActivity - they should not be in OneToOne relationship + * as it can not be cached, i.e. is always eagerly fetched. + * This singleton-type access to service allows fetching data from DB from wherever in code. + * It is probably a bad design, but we can not enforce lazy loading in any other reasonable way + * and eager loading makes up a good part of queries sent to DB. + * The service fetched this way should probably be used for read-only queries + * as we deliver the real service object, not its transactional proxy. + */ + @Override + public void afterPropertiesSet() { + instance = this; + } + + public static IUserManagementService getInstance() { + return instance; + } + // --------------------------------------------------------------------- // Service Methods // --------------------------------------------------------------------- Index: lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/dto/GBActivityGridRowDTO.java =================================================================== diff -u -r66731316c708697a11666228c114ae5ce8bf0b23 -r96033f32ff880d045b4c087f52628d233dc98095 --- lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/dto/GBActivityGridRowDTO.java (.../GBActivityGridRowDTO.java) (revision 66731316c708697a11666228c114ae5ce8bf0b23) +++ lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/dto/GBActivityGridRowDTO.java (.../GBActivityGridRowDTO.java) (revision 96033f32ff880d045b4c087f52628d233dc98095) @@ -31,6 +31,7 @@ import org.lamsfoundation.lams.learningdesign.ActivityEvaluation; import org.lamsfoundation.lams.learningdesign.CompetenceMapping; import org.lamsfoundation.lams.learningdesign.ToolActivity; +import org.lamsfoundation.lams.usermanagement.service.UserManagementService; import org.springframework.web.util.HtmlUtils; public class GBActivityGridRowDTO extends GradebookGridRowDTO { @@ -96,7 +97,8 @@ if (activity.isToolActivity()) { ToolActivity toolActivity = (ToolActivity) activity; - ActivityEvaluation eval = toolActivity.getEvaluation(); + ActivityEvaluation eval = (ActivityEvaluation) UserManagementService.getInstance() + .findById(ActivityEvaluation.class, toolActivity.getActivityId()); if (eval != null && eval.getWeight() != null) { this.weight = eval.getWeight(); } Index: lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/service/GradebookService.java =================================================================== diff -u -rf45a5d1838441e0a57b623a6765d88736cf9f323 -r96033f32ff880d045b4c087f52628d233dc98095 --- lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/service/GradebookService.java (.../GradebookService.java) (revision f45a5d1838441e0a57b623a6765d88736cf9f323) +++ lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/service/GradebookService.java (.../GradebookService.java) (revision 96033f32ff880d045b4c087f52628d233dc98095) @@ -687,14 +687,17 @@ Long activityId = activity.getActivityId(); Lesson lesson = lessonDAO.getLessonForActivity(activityId); - if ((lesson == null) || (activity == null) || !(activity instanceof ToolActivity) - || (((ToolActivity) activity).getEvaluation() == null)) { + if ((lesson == null) || (activity == null) || !(activity instanceof ToolActivity)) { return; } + ToolActivity toolActivity = (ToolActivity) activity; + ActivityEvaluation eval = activityDAO.getEvaluationByActivityId(toolActivity.getActivityId()); + if (eval == null) { + return; + } // Getting the first activity evaluation - ActivityEvaluation eval = toolActivity.getEvaluation(); String toolOutputDefinition = eval.getToolOutputDefinition(); Map userToGradebookUserActivityMap = getUserToGradebookUserActivityMap(activity, @@ -733,14 +736,16 @@ ToolSession toolSession = toolService.getToolSessionByLearner(learner, activity); if ((toolSession == null) || (toolSession == null) || (learner == null) || (lesson == null) - || (activity == null) || !(activity instanceof ToolActivity) - || (((ToolActivity) activity).getEvaluation() == null)) { + || (activity == null) || !(activity instanceof ToolActivity)) { return; } ToolActivity toolActivity = (ToolActivity) activity; // Getting the first activity evaluation - ActivityEvaluation eval = toolActivity.getEvaluation(); + ActivityEvaluation eval = activityDAO.getEvaluationByActivityId(toolActivity.getActivityId()); + if (eval == null) { + return; + } try { ToolOutput toolOutput = toolService.getOutputFromTool(eval.getToolOutputDefinition(), toolSession, @@ -793,7 +798,7 @@ if (activity.isToolActivity()) { // fetch real object, otherwise there is a cast error ToolActivity act = (ToolActivity) activityDAO.getActivityByActivityId(activity.getActivityId()); - ActivityEvaluation eval = act.getEvaluation(); + ActivityEvaluation eval = activityDAO.getEvaluationByActivityId(act.getActivityId()); if (eval != null && eval.getWeight() != null && eval.getWeight() > 0) { String[] evaluation = new String[3]; evaluation[0] = act.getTitle(); @@ -1507,7 +1512,8 @@ for (ToolActivity activity : activityToUserDTOMap.keySet()) { String toolSignature = activity.getTool().getToolSignature(); //check whether toolActivity has a NumericToolOutput - if (activity.getEvaluation() != null && LESSON_EXPORT_TOOL_ACTIVITIES.contains(toolSignature)) { + ActivityEvaluation eval = activityDAO.getEvaluationByActivityId(activity.getActivityId()); + if (eval != null && LESSON_EXPORT_TOOL_ACTIVITIES.contains(toolSignature)) { filteredActivityToUserDTOMap.put(activity, activityToUserDTOMap.get(activity)); } } @@ -1521,7 +1527,7 @@ for (Activity activity : filteredActivityToUserDTOMap.keySet()) { String activityName = activity.getTitle(); if (isWeighted && activity.isToolActivity()) { - ActivityEvaluation eval = ((ToolActivity) activity).getEvaluation(); + ActivityEvaluation eval = activityDAO.getEvaluationByActivityId(activity.getActivityId()); activityName += " " + getMessage("gradebook.export.weight", new Object[] { eval == null || eval.getWeight() == null ? 0 : eval.getWeight() }); } @@ -1576,7 +1582,7 @@ String activityName = activity.getTitle(); if (isWeighted && activity.isToolActivity()) { - ActivityEvaluation eval = ((ToolActivity) activity).getEvaluation(); + ActivityEvaluation eval = activityDAO.getEvaluationByActivityId(activity.getActivityId()); activityName += " " + getMessage("gradebook.export.weight", new Object[] { eval == null || eval.getWeight() == null ? 0 : eval.getWeight() }); } @@ -1669,7 +1675,7 @@ : activity.getTitle(); if (isWeighted && activity.isToolActivity()) { - ActivityEvaluation eval = activity.getEvaluation(); + ActivityEvaluation eval = activityDAO.getEvaluationByActivityId(activity.getActivityId()); activityRowName += " " + getMessage("gradebook.export.weight", new Object[] { eval == null || eval.getWeight() == null ? 0 : eval.getWeight() }); } @@ -2027,7 +2033,7 @@ for (Activity activity : activities) { String activityName = activity.getTitle(); if (isWeighted && activity.isToolActivity()) { - ActivityEvaluation eval = ((ToolActivity) activity).getEvaluation(); + ActivityEvaluation eval = activityDAO.getEvaluationByActivityId(activity.getActivityId()); activityName += " " + getMessage("gradebook.export.weight", new Object[] { eval == null || eval.getWeight() == null ? 0 : eval.getWeight() }); } @@ -2117,8 +2123,9 @@ } Integer weight = weighted ? 0 : null; - if (activity.getEvaluation() != null && activity.getEvaluation().getWeight() != null) { - weight = activity.getEvaluation().getWeight(); + ActivityEvaluation eval = activityDAO.getEvaluationByActivityId(activity.getActivityId()); + if (eval != null && eval.getWeight() != null) { + weight = eval.getWeight(); } Long weightedActivityTotalMarks = weight != null ? weight : rawActivityTotalMarks; @@ -2478,10 +2485,11 @@ Double rawMark = inputRawMark != null ? inputRawMark : 0.0; if (useWeightings) { ToolActivity activity = guact.getActivity(); - if (activity.getEvaluation() == null || activity.getEvaluation().getWeight() == null) { + ActivityEvaluation eval = activityDAO.getEvaluationByActivityId(activity.getActivityId()); + if (eval == null || eval.getWeight() == null) { return 0.0; } else { - return doWeightedMarkCalc(rawMark, activity, activity.getEvaluation().getWeight(), + return doWeightedMarkCalc(rawMark, activity, eval.getWeight(), toolService.getActivityMaxPossibleMark(activity)); } } Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java =================================================================== diff -u -rf7710a226fa06c406ec260be0f929c91e48495c5 -r96033f32ff880d045b4c087f52628d233dc98095 --- lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java (.../LearnerService.java) (revision f7710a226fa06c406ec260be0f929c91e48495c5) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java (.../LearnerService.java) (revision 96033f32ff880d045b4c087f52628d233dc98095) @@ -51,6 +51,7 @@ import org.lamsfoundation.lams.learning.web.util.ActivityMapping; import org.lamsfoundation.lams.learning.web.util.LearningWebUtil; import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.ActivityEvaluation; import org.lamsfoundation.lams.learningdesign.BranchActivityEntry; import org.lamsfoundation.lams.learningdesign.BranchCondition; import org.lamsfoundation.lams.learningdesign.BranchingActivity; @@ -673,10 +674,14 @@ User learner = progress.getUser(); Lesson lesson = progress.getLesson(); - if ((learner == null) || (lesson == null) || (activity == null) || !(activity instanceof ToolActivity) - || (((ToolActivity) activity).getEvaluation() == null)) { + if ((learner == null) || (lesson == null) || (activity == null) || !(activity instanceof ToolActivity)) { return; } + ActivityEvaluation evaluation = activityDAO.getEvaluationByActivityId(activity.getActivityId()); + if (evaluation == null) { + return; + } + ToolSession toolSession = lamsCoreToolService.getToolSessionByLearner(learner, activity); if (toolSession == null) { return;