Index: lams_central/src/java/org/lamsfoundation/lams/authoring/ObjectExtractor.java =================================================================== diff -u -r93d9ed164843c3e37b6bc66fbb3061b20db7abbd -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_central/src/java/org/lamsfoundation/lams/authoring/ObjectExtractor.java (.../ObjectExtractor.java) (revision 93d9ed164843c3e37b6bc66fbb3061b20db7abbd) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/ObjectExtractor.java (.../ObjectExtractor.java) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -43,6 +43,7 @@ import org.lamsfoundation.lams.learningdesign.BranchingActivity; import org.lamsfoundation.lams.learningdesign.ChosenGrouping; import org.lamsfoundation.lams.learningdesign.ComplexActivity; +import org.lamsfoundation.lams.learningdesign.ConditionGateActivity; import org.lamsfoundation.lams.learningdesign.GateActivity; import org.lamsfoundation.lams.learningdesign.Group; import org.lamsfoundation.lams.learningdesign.Grouping; @@ -1197,6 +1198,9 @@ else if (activity instanceof SystemGateActivity) { buildSystemGateActivity((SystemGateActivity) activity, activityDetails); } + else if (activity instanceof ConditionGateActivity) { + buildConditionGateActivity((ConditionGateActivity) activity, activityDetails); + } else { buildScheduleGateActivity((ScheduleGateActivity) activity, activityDetails); } @@ -1221,6 +1225,11 @@ activity.setSystemTool(getSystemTool(SystemTool.SYSTEM_GATE)); } + private void buildConditionGateActivity(ConditionGateActivity activity, Hashtable activityDetails) + throws WDDXProcessorConversionException { + activity.setSystemTool(getSystemTool(SystemTool.CONDITION_GATE)); + } + private void buildScheduleGateActivity(ScheduleGateActivity activity, Hashtable activityDetails) throws WDDXProcessorConversionException { //activity.setGateStartDateTime(WDDXProcessor.convertToDate(activityDetails,WDDXTAGS.GATE_START_DATE)); @@ -1427,7 +1436,9 @@ } @SuppressWarnings("unchecked") - /** Get the BranchActivityEntry details. This may be either for group based branching, or it may be for tool output based branching */ + /** Get the BranchActivityEntry details. + * This may be either for group based branching, it may be for tool output based branching or for a condition gate activity. + */ private BranchActivityEntry extractBranchActivityEntry(Hashtable details) throws WDDXProcessorConversionException { Long entryId = WDDXProcessor.convertToLong(details, WDDXTAGS.BRANCH_ACTIVITY_ENTRY_ID); @@ -1439,42 +1450,53 @@ Integer sequenceActivityUIID = WDDXProcessor.convertToInteger(details, WDDXTAGS.BRANCH_SEQUENCE_ACTIVITY_UIID); Integer branchingActivityUIID = WDDXProcessor.convertToInteger(details, WDDXTAGS.BRANCH_ACTIVITY_UIID); - SequenceActivity sequenceActivity = null; - Activity activity = newActivityMap.get(sequenceActivityUIID); - if (activity == null) { - throw new WDDXProcessorConversionException( - "Sequence Activity listed in the branch mapping list is missing. Mapping entry UUID " + entryUIID - + " sequenceActivityUIID " + sequenceActivityUIID); - } - else if (!activity.isSequenceActivity()) { - throw new WDDXProcessorConversionException( - "Activity listed in the branch mapping list is not a sequence activity. Mapping entry UUID " + entryUIID - + " sequenceActivityUIID " + sequenceActivityUIID); - } - else { - sequenceActivity = (SequenceActivity) activity; - } - Activity branchingActivity = newActivityMap.get(branchingActivityUIID); if (branchingActivity == null) { throw new WDDXProcessorConversionException( "Branching Activity listed in the branch mapping list is missing. Mapping entry UUID " + entryUIID + " branchingActivityUIID " + branchingActivityUIID); } - if (!branchingActivity.isBranchingActivity()) { + if (!branchingActivity.isBranchingActivity() && !branchingActivity.isConditionGate()) { throw new WDDXProcessorConversionException( - "Activity listed in the branch mapping list is not a branching activity. Mapping entry UUID " + entryUIID - + " branchingActivityUIID " + branchingActivityUIID); + "Activity listed in the branch mapping list is not a branching activity nor a condition gate. Mapping entry UUID " + + entryUIID + " branchingActivityUIID " + branchingActivityUIID); } + //sequence activity is null for a condition gate + SequenceActivity sequenceActivity = null; + if (!branchingActivity.isConditionGate()) { + Activity activity = newActivityMap.get(sequenceActivityUIID); + if (activity == null) { + throw new WDDXProcessorConversionException( + "Sequence Activity listed in the branch mapping list is missing. Mapping entry UUID " + entryUIID + + " sequenceActivityUIID " + sequenceActivityUIID); + } + else if (!activity.isSequenceActivity()) { + throw new WDDXProcessorConversionException( + "Activity listed in the branch mapping list is not a sequence activity. Mapping entry UUID " + entryUIID + + " sequenceActivityUIID " + sequenceActivityUIID); + } + else { + sequenceActivity = (SequenceActivity) activity; + } + } // If the mapping was created at runtime, there will be an ID but no IU ID field. // If it was created in authoring, will have a UI ID and may or may not have an ID. // So try to match up on UI ID first, failing that match on ID. Then the worst case, which is the mapping // is created at runtime but then modified in authoring (and has has a new UI ID added) is handled. BranchActivityEntry uiid_match = null; BranchActivityEntry id_match = null; - if (sequenceActivity.getBranchEntries() != null) { - Iterator iter = sequenceActivity.getBranchEntries().iterator(); + Iterator iter = null; + if (sequenceActivity != null) { + if (sequenceActivity.getBranchEntries() != null) { + iter = sequenceActivity.getBranchEntries().iterator(); + } + } + else { + iter = ((ConditionGateActivity) branchingActivity).getOpeningGateBranchEntries().iterator(); + } + + if (iter != null) { while (uiid_match == null && iter.hasNext()) { BranchActivityEntry possibleEntry = (BranchActivityEntry) iter.next(); if (entryUIID.equals(possibleEntry.getEntryUIID())) { @@ -1511,7 +1533,7 @@ if (entry == null) { if (condition != null) { - entry = condition.allocateBranchToCondition(entryUIID, sequenceActivity, (BranchingActivity) branchingActivity); + entry = condition.allocateBranchToCondition(entryUIID, sequenceActivity, branchingActivity); } else { entry = group.allocateBranchToGroup(entryUIID, sequenceActivity, (BranchingActivity) branchingActivity); @@ -1520,17 +1542,18 @@ else { entry.setEntryUIID(entryUIID); entry.setBranchSequenceActivity(sequenceActivity); - entry.setBranchingActivity((BranchingActivity) branchingActivity); + entry.setBranchingActivity(branchingActivity); } entry.setGroup(group); entry.setCondition(condition); - - if (sequenceActivity.getBranchEntries() == null) { - sequenceActivity.setBranchEntries(new HashSet()); + if (sequenceActivity != null) { + if (sequenceActivity.getBranchEntries() == null) { + sequenceActivity.setBranchEntries(new HashSet()); + } + sequenceActivity.getBranchEntries().add(entry); + activityDAO.update(sequenceActivity); } - sequenceActivity.getBranchEntries().add(entry); - activityDAO.update(sequenceActivity); if (group != null) { groupingDAO.update(group); Index: lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java =================================================================== diff -u -rb82c7d5b3659b3eaaba97fac70acc57c6aef720a -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java (.../AuthoringService.java) (revision b82c7d5b3659b3eaaba97fac70acc57c6aef720a) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java (.../AuthoringService.java) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -107,9 +107,9 @@ * @author Manpreet Minhas */ public class AuthoringService implements IAuthoringService, BeanFactoryAware { - - protected Logger log = Logger.getLogger(AuthoringService.class); + protected Logger log = Logger.getLogger(AuthoringService.class); + /** Required DAO's */ protected LearningDesignDAO learningDesignDAO; protected LearningLibraryDAO learningLibraryDAO; @@ -127,16 +127,16 @@ protected ILessonService lessonService; protected IMonitoringService monitoringService; protected IWorkspaceManagementService workspaceManagementService; - + protected ToolContentIDGenerator contentIDGenerator; - + /** The bean factory is used to create ObjectExtractor objects */ protected BeanFactory beanFactory; - - public AuthoringService(){ - + + public AuthoringService() { + } - + /********************************************** * Setter Methods * *******************************************/ @@ -153,59 +153,67 @@ public void setGroupDAO(GroupDAO groupDAO) { this.groupDAO = groupDAO; } + public void setGroupingDAO(GroupingDAO groupingDAO) { this.groupingDAO = groupingDAO; } - + /** * @param transitionDAO The transitionDAO to set */ public void setTransitionDAO(TransitionDAO transitionDAO) { this.transitionDAO = transitionDAO; } + /** * @param learningDesignDAO The learningDesignDAO to set. */ public void setLearningDesignDAO(LearningDesignDAO learningDesignDAO) { this.learningDesignDAO = learningDesignDAO; - } + } + /** * @param learningLibraryDAO The learningLibraryDAO to set. */ public void setLearningLibraryDAO(LearningLibraryDAO learningLibraryDAO) { this.learningLibraryDAO = learningLibraryDAO; } + /** * @param baseDAO The baseDAO to set. */ public void setBaseDAO(BaseDAO baseDAO) { this.baseDAO = baseDAO; } + /** * @param activityDAO The activityDAO to set. */ public void setActivityDAO(ActivityDAO activityDAO) { this.activityDAO = activityDAO; - } + } + /** * @param toolDAO The toolDAO to set */ public void setToolDAO(ToolDAO toolDAO) { this.toolDAO = toolDAO; } + /** * @param toolDAO The toolDAO to set */ public void setSystemToolDAO(SystemToolDAO systemToolDAO) { this.systemToolDAO = systemToolDAO; } + /** * @param licenseDAO The licenseDAO to set */ public void setLicenseDAO(LicenseDAO licenseDAO) { this.licenseDAO = licenseDAO; - } - + } + public ILamsCoreToolService getLamsCoreToolService() { return lamsCoreToolService; } @@ -217,13 +225,13 @@ public ILearningDesignService getLearningDesignService() { return learningDesignService; } - + /** * @param learningDesignService The Learning Design Validator Service */ public void setLearningDesignService(ILearningDesignService learningDesignService) { this.learningDesignService = learningDesignService; - } + } public MessageService getMessageService() { return messageService; @@ -241,46 +249,45 @@ this.monitoringService = monitoringService; } - public void setWorkspaceManagementService(IWorkspaceManagementService workspaceManagementService) { this.workspaceManagementService = workspaceManagementService; } /** - * @param contentIDGenerator The contentIDGenerator to set. - */ - public void setContentIDGenerator(ToolContentIDGenerator contentIDGenerator) - { - this.contentIDGenerator = contentIDGenerator; - } - + * @param contentIDGenerator The contentIDGenerator to set. + */ + public void setContentIDGenerator(ToolContentIDGenerator contentIDGenerator) { + this.contentIDGenerator = contentIDGenerator; + } + /** * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#getLearningDesign(java.lang.Long) */ - public LearningDesign getLearningDesign(Long learningDesignID){ + public LearningDesign getLearningDesign(Long learningDesignID) { return learningDesignDAO.getLearningDesignById(learningDesignID); } - + /** * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#saveLearningDesign(org.lamsfoundation.lams.learningdesign.LearningDesign) */ - public void saveLearningDesign(LearningDesign learningDesign){ + public void saveLearningDesign(LearningDesign learningDesign) { learningDesignDAO.insertOrUpdate(learningDesign); } + /** * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#getAllLearningDesigns() */ - public List getAllLearningDesigns(){ - return learningDesignDAO.getAllLearningDesigns(); + public List getAllLearningDesigns() { + return learningDesignDAO.getAllLearningDesigns(); } - + /** * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#getAllLearningLibraries() */ - public List getAllLearningLibraries(){ - return learningLibraryDAO.getAllLearningLibraries(); + public List getAllLearningLibraries() { + return learningLibraryDAO.getAllLearningLibraries(); } - + public BeanFactory getBeanFactory() { return beanFactory; } @@ -292,192 +299,205 @@ /********************************************** * Utility/Service Methods * *******************************************/ - - /** - * Helper method to retrieve the user data. Gets the id from the user details - * in the shared session - * @return the user id - */ - public static Integer getUserId() - { - HttpSession ss = SessionManager.getSession(); - UserDTO learner = (UserDTO) ss.getAttribute(AttributeNames.USER); - return learner != null ? learner.getUserID() : null; - } - - /** - * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#getToolOutputDefinitions(java.lang.Long) + /** + * Helper method to retrieve the user data. Gets the id from the user details + * in the shared session + * @return the user id */ - public String getToolOutputDefinitions(Long toolContentID)throws IOException{ - + public static Integer getUserId() { + HttpSession ss = SessionManager.getSession(); + UserDTO learner = (UserDTO) ss.getAttribute(AttributeNames.USER); + return learner != null ? learner.getUserID() : null; + } + + /** + * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#getToolOutputDefinitions(java.lang.Long) + */ + public String getToolOutputDefinitions(Long toolContentID) throws IOException { + SortedMap defns = lamsCoreToolService.getOutputDefinitionsFromTool(toolContentID); - - ArrayList defnDTOList = new ArrayList(defns != null ? defns.size():0); - if ( defns != null ) { - for ( ToolOutputDefinition defn : defns.values() ) { + + ArrayList defnDTOList = new ArrayList(defns != null ? defns.size() : 0); + if (defns != null) { + for (ToolOutputDefinition defn : defns.values()) { defnDTOList.add(new ToolOutputDefinitionDTO(defn)); } } FlashMessage flashMessage = new FlashMessage("getToolOutputDefinitions", defnDTOList); return flashMessage.serializeMessage(); } - + /** * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#getLearningDesignDetails(java.lang.Long, java.lang.Long) */ - public String getLearningDesignDetails(Long learningDesignID, String languageCode)throws IOException{ - FlashMessage flashMessage= null; + public String getLearningDesignDetails(Long learningDesignID, String languageCode) throws IOException { + FlashMessage flashMessage = null; LearningDesignDTO learningDesignDTO = learningDesignService.getLearningDesignDTO(learningDesignID, languageCode); - - if(learningDesignDTO==null) - flashMessage = FlashMessage.getNoSuchLearningDesignExists("getLearningDesignDetails",learningDesignID); - else{ - flashMessage = new FlashMessage("getLearningDesignDetails",learningDesignDTO); + + if (learningDesignDTO == null) { + flashMessage = FlashMessage.getNoSuchLearningDesignExists("getLearningDesignDetails", learningDesignID); } + else { + flashMessage = new FlashMessage("getLearningDesignDetails", learningDesignDTO); + } return flashMessage.serializeMessage(); } /** * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#isLearningDesignAvailable(LearningDesign, java.lang.Integer) */ public boolean isLearningDesignAvailable(LearningDesign design, Integer userID) throws LearningDesignException, IOException { - if(design == null) - throw new LearningDesignException(FlashMessage.getNoSuchLearningDesignExists("getLearningDesignDetails",design.getLearningDesignId()).serializeMessage()); - - if(design.getEditOverrideUser() != null && design.getEditOverrideLock() != null) - return (design.getEditOverrideUser().getUserId().equals(userID)) ? true : !design.getEditOverrideLock(); - else + if (design == null) { + throw new LearningDesignException(FlashMessage.getNoSuchLearningDesignExists("getLearningDesignDetails", + design.getLearningDesignId()).serializeMessage()); + } + + if (design.getEditOverrideUser() != null && design.getEditOverrideLock() != null) { + return design.getEditOverrideUser().getUserId().equals(userID) ? true : !design.getEditOverrideLock(); + } + else { return true; + } } - + private void setLessonLock(LearningDesign design, boolean lock) { Lesson lesson = null; - + // lock active lesson Set lessons = design.getLessons(); Iterator it = lessons.iterator(); - - while(it.hasNext()) { + + while (it.hasNext()) { lesson = (Lesson) it.next(); lesson.setLockedForEdit(lock); } } - + /** * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#setupEditOnFlyLock(LearningDesign, java.lang.Integer) */ - public boolean setupEditOnFlyLock(Long learningDesignID, Integer userID) throws LearningDesignException, UserException, IOException { - User user = (User)baseDAO.find(User.class,userID); - - LearningDesign design = learningDesignID!=null ? getLearningDesign(learningDesignID) : null; - - if(isLearningDesignAvailable(design, userID)) { - - if(design.getLessons().isEmpty()) + public boolean setupEditOnFlyLock(Long learningDesignID, Integer userID) throws LearningDesignException, UserException, + IOException { + User user = (User) baseDAO.find(User.class, userID); + + LearningDesign design = learningDesignID != null ? getLearningDesign(learningDesignID) : null; + + if (isLearningDesignAvailable(design, userID)) { + + if (design.getLessons().isEmpty()) { throw new LearningDesignException("There are no lessons attached to the design."); // TODO: add error msg - else if(user==null) - throw new UserException(messageService.getMessage("no.such.user.exist",new Object[]{userID})); - + } + else if (user == null) { + throw new UserException(messageService.getMessage("no.such.user.exist", new Object[] { userID })); + } + setLessonLock(design, true); - + // lock Learning Design design.setEditOverrideLock(true); design.setEditOverrideUser(user); - + learningDesignDAO.update(design); - + return true; - } else { + } + else { return false; } } - + /** * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#setupEditOnFlyGate(java.lang.Long, java.lang.Integer) */ public String setupEditOnFlyGate(Long learningDesignID, Integer userID) throws UserException, IOException { - User user = (User)baseDAO.find(User.class,userID); - LearningDesign design = learningDesignID!=null ? getLearningDesign(learningDesignID) : null; - - if(user==null) - throw new UserException(messageService.getMessage("no.such.user.exist",new Object[]{userID})); - - EditOnFlyProcessor processor = new EditOnFlyProcessor(design, activityDAO); /* parse Learning Design to find last read-only Activity */ - processor.parseLearningDesign(); - - ArrayList activities = processor.getLastReadOnlyActivity(); - addSystemGateAfterActivity(activities, design); /* add new System Gate after last read-only Activity */ - + User user = (User) baseDAO.find(User.class, userID); + LearningDesign design = learningDesignID != null ? getLearningDesign(learningDesignID) : null; + + if (user == null) { + throw new UserException(messageService.getMessage("no.such.user.exist", new Object[] { userID })); + } + + EditOnFlyProcessor processor = new EditOnFlyProcessor(design, activityDAO); /* parse Learning Design to find last read-only Activity */ + processor.parseLearningDesign(); + + ArrayList activities = processor.getLastReadOnlyActivity(); + addSystemGateAfterActivity(activities, design); /* add new System Gate after last read-only Activity */ + setLessonLock(design, false); - + learningDesignDAO.update(design); - + return new FlashMessage("setupEditOnFlyGate", true).serializeMessage(); } - - + /** * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#finishEditOnFly(java.lang.Long, java.lang.Integer) */ public String finishEditOnFly(Long learningDesignID, Integer userID) throws IOException { - FlashMessage flashMessage= null; + FlashMessage flashMessage = null; Lesson lesson = null; - - LearningDesign design = learningDesignID!=null ? learningDesignDAO.getLearningDesignById(learningDesignID) : null; - - User user = (User)baseDAO.find(User.class,userID); - if(user==null) + + LearningDesign design = learningDesignID != null ? learningDesignDAO.getLearningDesignById(learningDesignID) : null; + + User user = (User) baseDAO.find(User.class, userID); + if (user == null) { flashMessage = FlashMessage.getNoSuchUserExists("finishEditOnFly", userID); - - if(design != null) { /* only the user who is editing the design may unlock it */ - if(design.getEditOverrideUser().equals(user)) { + } + + if (design != null) { /* only the user who is editing the design may unlock it */ + if (design.getEditOverrideUser().equals(user)) { design.setEditOverrideLock(false); design.setEditOverrideUser(null); - - Set lessons = design.getLessons(); /* unlock lesson */ - + + Set lessons = design.getLessons(); /* unlock lesson */ + Iterator it = lessons.iterator(); - while(it.hasNext()) { + while (it.hasNext()) { lesson = (Lesson) it.next(); lesson.setLockedForEdit(false); } - - EditOnFlyProcessor processor = new EditOnFlyProcessor(design, activityDAO); /* parse Learning Design to find last read-only Activity (hopefully the system gate in this case) */ - processor.parseLearningDesign(); - - ArrayList activities = processor.getLastReadOnlyActivity(); - - GateActivity gate = null; /* open and release waiting list on system gate */ - - if(activities != null) - if(!activities.isEmpty() && activities.get(0).isGateActivity()) + + EditOnFlyProcessor processor = new EditOnFlyProcessor(design, activityDAO); /* parse Learning Design to find last read-only Activity (hopefully the system gate in this case) */ + processor.parseLearningDesign(); + + ArrayList activities = processor.getLastReadOnlyActivity(); + + GateActivity gate = null; /* open and release waiting list on system gate */ + + if (activities != null) { + if (!activities.isEmpty() && activities.get(0).isGateActivity()) { gate = (GateActivity) activities.get(0); - - if(gate != null) - design = removeTempSystemGate(gate, design); /* remove inputted system gate */ - - lessonService.performMarkLessonUncompleted(lesson.getLessonId()); /* the lesson may now have additional activities on the end, so clear any completed flags */ + } + } + if (gate != null) { + design = removeTempSystemGate(gate, design); /* remove inputted system gate */ + } + + lessonService.performMarkLessonUncompleted(lesson.getLessonId()); /* the lesson may now have additional activities on the end, so clear any completed flags */ + initialiseToolActivityForRuntime(design, lesson); learningDesignDAO.insertOrUpdate(design); - + flashMessage = new FlashMessage("finishEditOnFly", lesson.getLessonId()); - - } else { + + } + else { flashMessage = FlashMessage.getNoSuchUserExists("finishEditOnFly", userID); } - } else { - + } + else { + flashMessage = FlashMessage.getNoSuchLearningDesignExists("finishEditOnFly", learningDesignID); } - + return flashMessage.serializeMessage(); - + } - + /** * Remove a temp. System Gate from the design. Requires removing the gate from any learner progress entries - should only * be a current activity but remove it from previous and next, just in case. @@ -488,32 +508,34 @@ * @return Learning Design with removed System Gate */ public LearningDesign removeTempSystemGate(GateActivity gate, LearningDesign design) { - Transition toTransition = gate.getTransitionTo(); /* get transitions */ + Transition toTransition = gate.getTransitionTo(); /* get transitions */ Transition fromTransition = gate.getTransitionFrom(); - if(toTransition != null && fromTransition != null) { /* rearrange to-transition and/or delete redundant transition */ + if (toTransition != null && fromTransition != null) { /* rearrange to-transition and/or delete redundant transition */ toTransition.setToActivity(fromTransition.getToActivity()); toTransition.setToUIID(toTransition.getToActivity().getActivityUIID()); - + design.getTransitions().remove(fromTransition); transitionDAO.update(toTransition); - - } else if(toTransition != null && fromTransition == null) { + + } + else if (toTransition != null && fromTransition == null) { design.getTransitions().remove(toTransition); - } else if(toTransition == null && fromTransition != null) { + } + else if (toTransition == null && fromTransition != null) { design.setFirstActivity(fromTransition.getToActivity()); design.getTransitions().remove(fromTransition); } - - design.getActivities().remove(gate); /* remove temp system gate */ - - design.setDesignVersion(design.getDesignVersion() + 1); /* increment design version field */ - - lessonService.removeProgressReferencesToActivity(gate); /* need to remove it from any learner progress entries */ + design.getActivities().remove(gate); /* remove temp system gate */ + + design.setDesignVersion(design.getDesignVersion() + 1); /* increment design version field */ + + lessonService.removeProgressReferencesToActivity(gate); /* need to remove it from any learner progress entries */ + return design; } - + /** * Add a temp. System Gate. to the design. * @@ -522,584 +544,651 @@ */ public void addSystemGateAfterActivity(ArrayList activities, LearningDesign design) { GateActivity gate = null; - - Integer syncType = new Integer(Activity.SYSTEM_GATE_ACTIVITY_TYPE); + + Integer syncType = new Integer(Activity.SYSTEM_GATE_ACTIVITY_TYPE); Integer activityType = new Integer(Activity.SYSTEM_GATE_ACTIVITY_TYPE); Integer maxId = design.getMaxID(); - String title = "System Gate"; /* messageService.getMessage(MSG_KEY_SYNC_GATE); */ + String title = "System Gate"; /* messageService.getMessage(MSG_KEY_SYNC_GATE); */ - SystemTool systemTool = systemToolDAO.getSystemToolByID(SystemTool.SYSTEM_GATE); - Activity activity = (activities.isEmpty()) ? null : (Activity) activities.get(0); - - try { /* create new System Gate Activity */ + SystemTool systemTool = systemToolDAO.getSystemToolByID(SystemTool.SYSTEM_GATE); + Activity activity = activities.isEmpty() ? null : (Activity) activities.get(0); + + try { /* create new System Gate Activity */ gate = (GateActivity) Activity.getActivityInstance(syncType.intValue()); gate.setActivityTypeId(activityType.intValue()); gate.setActivityCategoryID(Activity.CATEGORY_SYSTEM); gate.setSystemTool(systemTool); gate.setActivityUIID(++maxId); - gate.setTitle(title!=null?title:"Gate"); + gate.setTitle(title != null ? title : "Gate"); gate.setGateOpen(false); gate.setWaitingLearners(null); gate.setGateActivityLevelId(GateActivity.LEARNER_GATE_LEVEL); gate.setApplyGrouping(false); // not nullable so default to false gate.setGroupingSupportType(Activity.GROUPING_SUPPORT_OPTIONAL); - gate.setOrderId(null); + gate.setOrderId(null); gate.setDefineLater(Boolean.FALSE); gate.setCreateDateTime(new Date()); gate.setRunOffline(Boolean.FALSE); gate.setReadOnly(Boolean.TRUE); gate.setLearningDesign(design); - + design.getActivities().add(gate); baseDAO.insert(gate); - + Transition fromTransition; Transition newTransition = new Transition(); Activity toActivity = null; - - if(activity != null) { - fromTransition = activity.getTransitionFrom(); /* update transitions */ - - if(fromTransition != null) { + + if (activity != null) { + fromTransition = activity.getTransitionFrom(); /* update transitions */ + + if (fromTransition != null) { toActivity = fromTransition.getToActivity(); - + fromTransition.setToActivity(gate); fromTransition.setToUIID(gate.getActivityUIID()); - + newTransition.setTransitionUIID(++maxId); newTransition.setFromActivity(gate); newTransition.setFromUIID(gate.getActivityUIID()); newTransition.setToActivity(toActivity); newTransition.setToUIID(toActivity.getActivityUIID()); newTransition.setLearningDesign(design); - + gate.setTransitionFrom(newTransition); - + toActivity.setTransitionTo(newTransition); - - Integer x1 = (activity.getXcoord() != null) ? activity.getXcoord() : 0; /* set x/y position for Gate */ - Integer x2 = (toActivity.getXcoord() != null) ? toActivity.getXcoord() : 0; - - gate.setXcoord(new Integer(((x1.intValue() + 123 + x2.intValue()) / 2) - 13)); - - Integer y1 = (activity.getYcoord() != null) ? activity.getYcoord() : 0; - Integer y2 = (toActivity.getYcoord() != null) ? toActivity.getYcoord() : 0; - - gate.setYcoord(new Integer((y1.intValue() + 50 + y2.intValue()) / 2)); - - } else { + + Integer x1 = activity.getXcoord() != null ? activity.getXcoord() : 0; /* set x/y position for Gate */ + Integer x2 = toActivity.getXcoord() != null ? toActivity.getXcoord() : 0; + + gate.setXcoord(new Integer((x1.intValue() + 123 + x2.intValue()) / 2 - 13)); + + Integer y1 = activity.getYcoord() != null ? activity.getYcoord() : 0; + Integer y2 = toActivity.getYcoord() != null ? toActivity.getYcoord() : 0; + + gate.setYcoord(new Integer((y1.intValue() + 50 + y2.intValue()) / 2)); + + } + else { //fromTransition = newTransition; - + newTransition.setTransitionUIID(++maxId); newTransition.setFromActivity(activity); newTransition.setFromUIID(activity.getActivityUIID()); newTransition.setToActivity(gate); newTransition.setToUIID(gate.getActivityUIID()); newTransition.setLearningDesign(design); - + activity.setTransitionFrom(fromTransition); gate.setTransitionTo(fromTransition); - - Integer x1 = (activity.getTransitionTo() != null) ? activity.getTransitionTo().getFromActivity().getXcoord() : 0; /* set x/y position for Gate */ - Integer x2 = (activity.getXcoord() != null) ? activity.getXcoord() : 0; - - if(x1 != null && x2 != null) gate.setXcoord(x2>=x1 ? new Integer(x2.intValue()+123+13+20) : new Integer(x2.intValue()-13-20)); - else gate.setXcoord(new Integer(x2.intValue()+123+13+20)); - + + Integer x1 = activity.getTransitionTo() != null ? activity.getTransitionTo().getFromActivity().getXcoord() + : 0; /* set x/y position for Gate */ + Integer x2 = activity.getXcoord() != null ? activity.getXcoord() : 0; + + if (x1 != null && x2 != null) { + gate.setXcoord(x2 >= x1 ? new Integer(x2.intValue() + 123 + 13 + 20) : new Integer( + x2.intValue() - 13 - 20)); + } + else { + gate.setXcoord(new Integer(x2.intValue() + 123 + 13 + 20)); + } + gate.setYcoord(activity.getYcoord() + 25); } - - } else { - fromTransition = newTransition; /* no read-only activities insert gate at start of sequence */ + + } + else { + fromTransition = newTransition; /* no read-only activities insert gate at start of sequence */ toActivity = design.getFirstActivity(); - + newTransition.setTransitionUIID(++maxId); newTransition.setToActivity(toActivity); newTransition.setToUIID(toActivity.getActivityUIID()); newTransition.setFromActivity(gate); newTransition.setFromUIID(gate.getActivityUIID()); newTransition.setLearningDesign(design); - + gate.setTransitionFrom(fromTransition); toActivity.setTransitionTo(fromTransition); - - gate.setGateOpen(false); /* keep gate door closed to stop learner's from going past this point */ - - design.setFirstActivity(gate); /* set gate as first activity in sequence */ - - Integer x1 = (toActivity.getXcoord() != null) ? toActivity.getXcoord() : 0; /* set x/y position for Gate */ - Integer x2 = (toActivity.getTransitionFrom() != null) ? toActivity.getTransitionFrom().getToActivity().getXcoord() : null; - - if(x1 != null && x2 != null) gate.setXcoord(x2>=x1 ? new Integer(x1.intValue()-13-20) : new Integer(x1.intValue()+123+13+20)); - else gate.setXcoord(new Integer(x1.intValue()-13-20)); - + + gate.setGateOpen(false); /* keep gate door closed to stop learner's from going past this point */ + + design.setFirstActivity(gate); /* set gate as first activity in sequence */ + + Integer x1 = toActivity.getXcoord() != null ? toActivity.getXcoord() : 0; /* set x/y position for Gate */ + Integer x2 = toActivity.getTransitionFrom() != null ? toActivity.getTransitionFrom().getToActivity().getXcoord() + : null; + + if (x1 != null && x2 != null) { + gate.setXcoord(x2 >= x1 ? new Integer(x1.intValue() - 13 - 20) : new Integer(x1.intValue() + 123 + 13 + 20)); + } + else { + gate.setXcoord(new Integer(x1.intValue() - 13 - 20)); + } + gate.setYcoord(toActivity.getYcoord() + 25); } - + design.getTransitions().add(newTransition); design.setMaxID(maxId); - - design.setDesignVersion(design.getDesignVersion() + 1); /* increment design version field */ - - if(gate != null) activityDAO.update(gate); - if(activity != null) activityDAO.update(activity); - if(toActivity != null) activityDAO.update(toActivity); - - if(fromTransition != null && !fromTransition.equals(newTransition)) baseDAO.update(fromTransition); - if(newTransition != null) baseDAO.insert(newTransition); - if(design != null) learningDesignDAO.insertOrUpdate(design); - - } catch(NullPointerException npe) { + + design.setDesignVersion(design.getDesignVersion() + 1); /* increment design version field */ + + if (gate != null) { + activityDAO.update(gate); + } + if (activity != null) { + activityDAO.update(activity); + } + if (toActivity != null) { + activityDAO.update(toActivity); + } + + if (fromTransition != null && !fromTransition.equals(newTransition)) { + baseDAO.update(fromTransition); + } + if (newTransition != null) { + baseDAO.insert(newTransition); + } + if (design != null) { + learningDesignDAO.insertOrUpdate(design); + } + + } + catch (NullPointerException npe) { log.error(npe.getMessage(), npe); } - + } - + /** * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#getFirstUnattemptedActivity(org.lamsfoundation.lams.learningdesign.LearningDesign) */ public Activity getFirstUnattemptedActivity(LearningDesign design) throws LearningDesignException { Activity activity = design.getFirstActivity(); - - while(activity.getReadOnly() && activity.getTransitionFrom() != null) { - activity = activity.getTransitionFrom().getToActivity(); + + while (activity.getReadOnly() && activity.getTransitionFrom() != null) { + activity = activity.getTransitionFrom().getToActivity(); } - + return activity; } - + private void initialiseToolActivityForRuntime(LearningDesign design, Lesson lesson) throws MonitoringServiceException { Date now = new Date(); Set activities = design.getActivities(); - for (Iterator i = activities.iterator(); i.hasNext();) { - Activity activity = (Activity) i.next(); - - if ( activity.isInitialised() ) { - if ( ! activity.isActivityReadOnly() && activity.isToolActivity() ) { - // Activity is initialised so it was set up previously. So its tool content will be okay - // but the run offline flags and define later flags might have been changed, so they need to be updated - // Content ID shouldn't change, but we update it in case it does change while we update the status flags. - ToolActivity toolActivity = (ToolActivity) activityDAO.getActivityByActivityId(activity.getActivityId()); - Long newContentId = lamsCoreToolService.notifyToolOfStatusFlags(toolActivity); - toolActivity.setToolContentId(newContentId); - } - - } else { - // this is a new activity - need to set up the content, do any scheduling, etc - // always have to copy the tool content, even though it may point to unique content - that way if the - // teacher has double clicked on the tool icon (and hence set up a tool content id) but not saved any content - // the code in copyToolContent will ensure that there is content for this activity. So we end up with a few - // unused records - we are trading database space for reliability. If we don't ensure that there is always - // a content record, then shortcomings in the createToolSession code may throw exceptions. - if ( activity.isToolActivity() ) { - ToolActivity toolActivity = (ToolActivity) activityDAO.getActivityByActivityId(activity.getActivityId()); - Long newContentId = lamsCoreToolService.notifyToolToCopyContent(toolActivity, true, null); - toolActivity.setToolContentId(newContentId); - - } else { - Integer newMaxId = monitoringService.startSystemActivity(activity, design.getMaxID(), now, lesson.getLessonName()); - if ( newMaxId != null ) { - design.setMaxID(newMaxId); - } - } - activity.setInitialised(Boolean.TRUE); - activityDAO.update(activity); - } - } + for (Iterator i = activities.iterator(); i.hasNext();) { + Activity activity = (Activity) i.next(); + + if (activity.isInitialised()) { + if (!activity.isActivityReadOnly() && activity.isToolActivity()) { + // Activity is initialised so it was set up previously. So its tool content will be okay + // but the run offline flags and define later flags might have been changed, so they need to be updated + // Content ID shouldn't change, but we update it in case it does change while we update the status flags. + ToolActivity toolActivity = (ToolActivity) activityDAO.getActivityByActivityId(activity.getActivityId()); + Long newContentId = lamsCoreToolService.notifyToolOfStatusFlags(toolActivity); + toolActivity.setToolContentId(newContentId); + } + + } + else { + // this is a new activity - need to set up the content, do any scheduling, etc + // always have to copy the tool content, even though it may point to unique content - that way if the + // teacher has double clicked on the tool icon (and hence set up a tool content id) but not saved any content + // the code in copyToolContent will ensure that there is content for this activity. So we end up with a few + // unused records - we are trading database space for reliability. If we don't ensure that there is always + // a content record, then shortcomings in the createToolSession code may throw exceptions. + if (activity.isToolActivity()) { + ToolActivity toolActivity = (ToolActivity) activityDAO.getActivityByActivityId(activity.getActivityId()); + Long newContentId = lamsCoreToolService.notifyToolToCopyContent(toolActivity, true, null); + toolActivity.setToolContentId(newContentId); + + } + else { + Integer newMaxId = monitoringService.startSystemActivity(activity, design.getMaxID(), now, lesson + .getLessonName()); + if (newMaxId != null) { + design.setMaxID(newMaxId); + } + } + activity.setInitialised(Boolean.TRUE); + activityDAO.update(activity); + } + } } - - public LearningDesign copyLearningDesign(Long originalDesignID,Integer copyType, - Integer userID, Integer workspaceFolderID, boolean setOriginalDesign) - throws UserException, LearningDesignException, - WorkspaceFolderException, IOException{ - + + public LearningDesign copyLearningDesign(Long originalDesignID, Integer copyType, Integer userID, Integer workspaceFolderID, + boolean setOriginalDesign) throws UserException, LearningDesignException, WorkspaceFolderException, IOException { + LearningDesign originalDesign = learningDesignDAO.getLearningDesignById(originalDesignID); - if(originalDesign==null) - throw new LearningDesignException(messageService.getMessage("no.such.learningdesign.exist",new Object[]{originalDesignID})); - - User user = (User)baseDAO.find(User.class,userID); - if(user==null) - throw new UserException(messageService.getMessage("no.such.user.exist",new Object[]{userID})); - - WorkspaceFolder workspaceFolder = (WorkspaceFolder)baseDAO.find(WorkspaceFolder.class,workspaceFolderID); - if(workspaceFolder==null) - throw new WorkspaceFolderException(messageService.getMessage("no.such.workspace.exist",new Object[]{workspaceFolderID})); - - if ( ! workspaceManagementService.isUserAuthorizedToModifyFolderContents(workspaceFolder.getWorkspaceFolderId(), user.getUserId()) ) { - throw new UserAccessDeniedException("User with user_id of " + user.getUserId() - +" is not authorized to copy a learning design into the workspace folder "+workspaceFolder.getWorkspaceFolderId()); + if (originalDesign == null) { + throw new LearningDesignException(messageService.getMessage("no.such.learningdesign.exist", + new Object[] { originalDesignID })); } - return copyLearningDesign(originalDesign,copyType,user,workspaceFolder, setOriginalDesign,null, null); + User user = (User) baseDAO.find(User.class, userID); + if (user == null) { + throw new UserException(messageService.getMessage("no.such.user.exist", new Object[] { userID })); + } + + WorkspaceFolder workspaceFolder = (WorkspaceFolder) baseDAO.find(WorkspaceFolder.class, workspaceFolderID); + if (workspaceFolder == null) { + throw new WorkspaceFolderException(messageService.getMessage("no.such.workspace.exist", + new Object[] { workspaceFolderID })); + } + + if (!workspaceManagementService.isUserAuthorizedToModifyFolderContents(workspaceFolder.getWorkspaceFolderId(), user + .getUserId())) { + throw new UserAccessDeniedException("User with user_id of " + user.getUserId() + + " is not authorized to copy a learning design into the workspace folder " + + workspaceFolder.getWorkspaceFolderId()); + } + + return copyLearningDesign(originalDesign, copyType, user, workspaceFolder, setOriginalDesign, null, null); } - - /** - * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#copyLearningDesign(org.lamsfoundation.lams.learningdesign.LearningDesign, java.lang.Integer, org.lamsfoundation.lams.usermanagement.User, org.lamsfoundation.lams.usermanagement.WorkspaceFolder, java.lang.Boolean, java.lang.String) - */ - public LearningDesign copyLearningDesign(LearningDesign originalLearningDesign,Integer copyType,User user, WorkspaceFolder workspaceFolder, - boolean setOriginalDesign, String newDesignName, String customCSV) - - { - String newTitle = newDesignName; - if ( newTitle == null ) { - newTitle = getUniqueNameForLearningDesign(originalLearningDesign.getTitle(), workspaceFolder!=null?workspaceFolder.getWorkspaceFolderId():null); - } - - LearningDesign newLearningDesign = LearningDesign.createLearningDesignCopy(originalLearningDesign,copyType,setOriginalDesign); - newLearningDesign.setTitle(newTitle); - newLearningDesign.setUser(user); - newLearningDesign.setWorkspaceFolder(workspaceFolder); - newLearningDesign.setEditOverrideLock(false); // clear the live edit flag - learningDesignDAO.insert(newLearningDesign); - - HashMap newActivities = updateDesignActivities(originalLearningDesign,newLearningDesign,0, customCSV); - updateDesignTransitions(originalLearningDesign,newLearningDesign, newActivities,0); - // set first activity assumes that the transitions are all set up correctly. - newLearningDesign.setFirstActivity(newLearningDesign.calculateFirstActivity()); - newLearningDesign.setLearningDesignUIID(originalLearningDesign.getLearningDesignUIID()); - return newLearningDesign; - } - - /** - * @throws UserException - * @throws WorkspaceFolderException - * @throws IOException - * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#insertLearningDesign(java.lang.Long, java.lang.Long, java.lang.Integer, java.lang.Boolean, java.lang.String, java.lang.Integer) - */ - public LearningDesign insertLearningDesign(Long originalDesignID, Long designToImportID, Integer userID, boolean createNewLearningDesign, String newDesignName, Integer workspaceFolderID, String customCSV) throws UserException, WorkspaceFolderException, IOException { - User user = (User)baseDAO.find(User.class,userID); - if(user==null) - throw new UserException(messageService.getMessage("no.such.user.exist",new Object[]{userID})); + /** + * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#copyLearningDesign(org.lamsfoundation.lams.learningdesign.LearningDesign, java.lang.Integer, org.lamsfoundation.lams.usermanagement.User, org.lamsfoundation.lams.usermanagement.WorkspaceFolder, java.lang.Boolean, java.lang.String) + */ + public LearningDesign copyLearningDesign(LearningDesign originalLearningDesign, Integer copyType, User user, + WorkspaceFolder workspaceFolder, boolean setOriginalDesign, String newDesignName, String customCSV) - LearningDesign mainDesign = learningDesignDAO.getLearningDesignById(originalDesignID); - if(mainDesign==null) - throw new LearningDesignException(messageService.getMessage("no.such.learningdesign.exist",new Object[]{originalDesignID})); + { + String newTitle = newDesignName; + if (newTitle == null) { + newTitle = getUniqueNameForLearningDesign(originalLearningDesign.getTitle(), + workspaceFolder != null ? workspaceFolder.getWorkspaceFolderId() : null); + } + LearningDesign newLearningDesign = LearningDesign.createLearningDesignCopy(originalLearningDesign, copyType, + setOriginalDesign); + newLearningDesign.setTitle(newTitle); + newLearningDesign.setUser(user); + newLearningDesign.setWorkspaceFolder(workspaceFolder); + newLearningDesign.setEditOverrideLock(false); // clear the live edit flag + learningDesignDAO.insert(newLearningDesign); + + HashMap newActivities = updateDesignActivities(originalLearningDesign, newLearningDesign, 0, customCSV); + updateDesignTransitions(originalLearningDesign, newLearningDesign, newActivities, 0); + // set first activity assumes that the transitions are all set up correctly. + newLearningDesign.setFirstActivity(newLearningDesign.calculateFirstActivity()); + newLearningDesign.setLearningDesignUIID(originalLearningDesign.getLearningDesignUIID()); + return newLearningDesign; + } + + /** + * @throws UserException + * @throws WorkspaceFolderException + * @throws IOException + * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#insertLearningDesign(java.lang.Long, java.lang.Long, java.lang.Integer, java.lang.Boolean, java.lang.String, java.lang.Integer) + */ + public LearningDesign insertLearningDesign(Long originalDesignID, Long designToImportID, Integer userID, + boolean createNewLearningDesign, String newDesignName, Integer workspaceFolderID, String customCSV) + throws UserException, WorkspaceFolderException, IOException { + + User user = (User) baseDAO.find(User.class, userID); + if (user == null) { + throw new UserException(messageService.getMessage("no.such.user.exist", new Object[] { userID })); + } + + LearningDesign mainDesign = learningDesignDAO.getLearningDesignById(originalDesignID); + if (mainDesign == null) { + throw new LearningDesignException(messageService.getMessage("no.such.learningdesign.exist", + new Object[] { originalDesignID })); + } + LearningDesign designToImport = learningDesignDAO.getLearningDesignById(designToImportID); - if(designToImport==null) - throw new LearningDesignException(messageService.getMessage("no.such.learningdesign.exist",new Object[]{designToImportID})); + if (designToImport == null) { + throw new LearningDesignException(messageService.getMessage("no.such.learningdesign.exist", + new Object[] { designToImportID })); + } - if ( createNewLearningDesign) { - WorkspaceFolder workspaceFolder = (WorkspaceFolder)baseDAO.find(WorkspaceFolder.class,workspaceFolderID); - if(workspaceFolder==null) - throw new WorkspaceFolderException(messageService.getMessage("no.such.workspace.exist",new Object[]{workspaceFolderID})); - if ( ! workspaceManagementService.isUserAuthorizedToModifyFolderContents(workspaceFolder.getWorkspaceFolderId(), user.getUserId()) ) { - throw new UserAccessDeniedException("User with user_id of " + user.getUserId() - +" is not authorized to store a copy a learning design into the workspace folder "+workspaceFolder); - } + if (createNewLearningDesign) { + WorkspaceFolder workspaceFolder = (WorkspaceFolder) baseDAO.find(WorkspaceFolder.class, workspaceFolderID); + if (workspaceFolder == null) { + throw new WorkspaceFolderException(messageService.getMessage("no.such.workspace.exist", + new Object[] { workspaceFolderID })); + } + if (!workspaceManagementService.isUserAuthorizedToModifyFolderContents(workspaceFolder.getWorkspaceFolderId(), user + .getUserId())) { + throw new UserAccessDeniedException("User with user_id of " + user.getUserId() + + " is not authorized to store a copy a learning design into the workspace folder " + workspaceFolder); + } - mainDesign = copyLearningDesign(mainDesign, LearningDesign.COPY_TYPE_NONE, user, workspaceFolder, false, newDesignName, customCSV ); - } else { - // updating the existing design so check the rights to the folder containing the design. If this is in live edit mode - boolean authorised = workspaceManagementService.isUserAuthorizedToModifyFolderContents(mainDesign.getWorkspaceFolder().getWorkspaceFolderId(), user.getUserId()); - if ( ! authorised ) { - authorised = mainDesign.getEditOverrideLock() != null && mainDesign.getEditOverrideLock().booleanValue() && userID.equals(mainDesign.getEditOverrideUser().getUserId()); - } - if ( ! authorised ) { - throw new UserAccessDeniedException("User with user_id of " + user.getUserId() - +" is not authorized to update a learning design into the workspace folder "+mainDesign.getWorkspaceFolder()); - } - } + mainDesign = copyLearningDesign(mainDesign, LearningDesign.COPY_TYPE_NONE, user, workspaceFolder, false, + newDesignName, customCSV); + } + else { + // updating the existing design so check the rights to the folder containing the design. If this is in live edit mode + boolean authorised = workspaceManagementService.isUserAuthorizedToModifyFolderContents(mainDesign + .getWorkspaceFolder().getWorkspaceFolderId(), user.getUserId()); + if (!authorised) { + authorised = mainDesign.getEditOverrideLock() != null && mainDesign.getEditOverrideLock().booleanValue() + && userID.equals(mainDesign.getEditOverrideUser().getUserId()); + } + if (!authorised) { + throw new UserAccessDeniedException("User with user_id of " + user.getUserId() + + " is not authorized to update a learning design into the workspace folder " + + mainDesign.getWorkspaceFolder()); + } + } - // now dump the import design into our main sequence. Leave the first activity ui id for the design as it is. - int uiidOffset = mainDesign.getMaxID().intValue(); - HashMap newActivities = updateDesignActivities(designToImport,mainDesign,uiidOffset, customCSV); - updateDesignTransitions(designToImport,mainDesign, newActivities,uiidOffset); - mainDesign.setMaxID(LearningDesign.addOffset(designToImport.getMaxID(),uiidOffset)); - mainDesign.setValidDesign(Boolean.FALSE); - learningDesignDAO.update(mainDesign); - - return mainDesign; + // now dump the import design into our main sequence. Leave the first activity ui id for the design as it is. + int uiidOffset = mainDesign.getMaxID().intValue(); + HashMap newActivities = updateDesignActivities(designToImport, mainDesign, uiidOffset, customCSV); + updateDesignTransitions(designToImport, mainDesign, newActivities, uiidOffset); + mainDesign.setMaxID(LearningDesign.addOffset(designToImport.getMaxID(), uiidOffset)); + mainDesign.setValidDesign(Boolean.FALSE); + learningDesignDAO.update(mainDesign); - } - /** - * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#copyLearningDesignToolContent(org.lamsfoundation.lams.learningdesign.LearningDesign, org.lamsfoundation.lams.learningdesign.LearningDesign, java.lang.Integer) - */ - private LearningDesign copyLearningDesignToolContent(LearningDesign design, LearningDesign originalLearningDesign, Integer copyType ) throws LearningDesignException { - - for (Iterator i = design.getActivities().iterator(); i.hasNext();) - { - Activity currentActivity = (Activity) i.next(); - if (currentActivity.isToolActivity()) - { - copyActivityToolContent(currentActivity, design.getCopyTypeID(), originalLearningDesign.getLearningDesignId(), null); - } - } - - return design; - } + return mainDesign; + } + /** + * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#copyLearningDesignToolContent(org.lamsfoundation.lams.learningdesign.LearningDesign, org.lamsfoundation.lams.learningdesign.LearningDesign, java.lang.Integer) + */ + private LearningDesign copyLearningDesignToolContent(LearningDesign design, LearningDesign originalLearningDesign, + Integer copyType) throws LearningDesignException { + + for (Iterator i = design.getActivities().iterator(); i.hasNext();) { + Activity currentActivity = (Activity) i.next(); + if (currentActivity.isToolActivity()) { + copyActivityToolContent(currentActivity, design.getCopyTypeID(), originalLearningDesign.getLearningDesignId(), + null); + } + } + + return design; + } + + /** * @param originalLearningDesign * @param copyType * @param currentActivity */ - private void copyActivityToolContent(Activity activity, Integer ldCopyType, Long originalLearningDesignId, String customCSV) { + private void copyActivityToolContent(Activity activity, Integer ldCopyType, Long originalLearningDesignId, String customCSV) { try { ToolActivity toolActivity = (ToolActivity) activity; // copy the content, but don't set the define later flags if it is preview - Long newContentId = lamsCoreToolService.notifyToolToCopyContent(toolActivity, ldCopyType != LearningDesign.COPY_TYPE_PREVIEW, customCSV); - toolActivity.setToolContentId(newContentId); - - // clear read only field - toolActivity.setReadOnly(false); - - } catch (DataMissingException e) { - String error = "Unable to copy a design / initialise the lesson. Data is missing for activity "+activity.getActivityUIID() - +" in learning design "+originalLearningDesignId - +" default content may be missing for the tool. Error was " - +e.getMessage(); - log.error(error,e); - throw new LearningDesignException(error,e); - } catch (ToolException e) { - String error = "Unable to copy a design / initialise the lesson. Tool encountered an error copying the data is missing for activity " - +activity.getActivityUIID() - +" in learning design "+originalLearningDesignId - +" default content may be missing for the tool. Error was " - +e.getMessage(); - log.error(error,e); - throw new LearningDesignException(error,e); + Long newContentId = lamsCoreToolService.notifyToolToCopyContent(toolActivity, + ldCopyType != LearningDesign.COPY_TYPE_PREVIEW, customCSV); + toolActivity.setToolContentId(newContentId); + + // clear read only field + toolActivity.setReadOnly(false); + } + catch (DataMissingException e) { + String error = "Unable to copy a design / initialise the lesson. Data is missing for activity " + + activity.getActivityUIID() + " in learning design " + originalLearningDesignId + + " default content may be missing for the tool. Error was " + e.getMessage(); + log.error(error, e); + throw new LearningDesignException(error, e); + } + catch (ToolException e) { + String error = "Unable to copy a design / initialise the lesson. Tool encountered an error copying the data is missing for activity " + + activity.getActivityUIID() + + " in learning design " + + originalLearningDesignId + + " default content may be missing for the tool. Error was " + e.getMessage(); + log.error(error, e); + throw new LearningDesignException(error, e); + } } - - /** - * Updates the Activity information in the newLearningDesign based - * on the originalLearningDesign. This any grouping details. - * - * As new activities are created, the UIID is incremented by the uiidOffset. If we are just copying a sequence this will - * be set to 0. But if we are importing a sequence into another sequence, this will be an offset value so we new ids guaranteed - * to be outside of the range of the main sequence (this may mean gaps in the uiids but that doesn't matter). - * - * @param originalLearningDesign The LearningDesign to be copied - * @param newLearningDesign The copy of the originalLearningDesign - * @return Map of all the new activities, where the key is the UIID value. This is used as an input to updateDesignTransitions - */ - private HashMap updateDesignActivities(LearningDesign originalLearningDesign, LearningDesign newLearningDesign, int uiidOffset, String customCSV){ - HashMap newActivities = new HashMap(); // key is UIID - HashMap newGroupings = new HashMap(); // key is UIID - + + /** + * Updates the Activity information in the newLearningDesign based + * on the originalLearningDesign. This any grouping details. + * + * As new activities are created, the UIID is incremented by the uiidOffset. If we are just copying a sequence this will + * be set to 0. But if we are importing a sequence into another sequence, this will be an offset value so we new ids guaranteed + * to be outside of the range of the main sequence (this may mean gaps in the uiids but that doesn't matter). + * + * @param originalLearningDesign The LearningDesign to be copied + * @param newLearningDesign The copy of the originalLearningDesign + * @return Map of all the new activities, where the key is the UIID value. This is used as an input to updateDesignTransitions + */ + private HashMap updateDesignActivities(LearningDesign originalLearningDesign, + LearningDesign newLearningDesign, int uiidOffset, String customCSV) { + HashMap newActivities = new HashMap(); // key is UIID + HashMap newGroupings = new HashMap(); // key is UIID + // as we create the activities, we need to record any "first child" UIID's for the sequence activity to process later - Map firstChildUIIDToSequence = new HashMap(); + Map firstChildUIIDToSequence = new HashMap(); - - Set oldParentActivities = originalLearningDesign.getParentActivities(); - if ( oldParentActivities != null ) { - Iterator iterator = oldParentActivities.iterator(); - while(iterator.hasNext()){ - processActivity((Activity)iterator.next(), newLearningDesign, newActivities, newGroupings, null, - originalLearningDesign.getLearningDesignId(), uiidOffset, customCSV); - } - } - - Collection activities = newActivities.values(); - - // Go back and find all the grouped activities and assign them the new groupings, based on the UIID. Can't - // be done as we go as the grouping activity may be processed after the grouped activity. - for ( Activity activity : activities) { - if ( activity.getGroupingUIID() != null ) { - activity.setGrouping(newGroupings.get(activity.getGroupingUIID())); - } - } - - // fix up any old "default activity" in the complex activities and the input activities - // and fix any branch mappings - for ( Activity activity : activities) { - if ( activity.isComplexActivity() ) { - ComplexActivity newComplex = (ComplexActivity) activity; - Activity oldDefaultActivity = newComplex.getDefaultActivity(); - if ( oldDefaultActivity != null ) { - Activity newDefaultActivity = newActivities.get(LearningDesign.addOffset(oldDefaultActivity.getActivityUIID(), uiidOffset)); - newComplex.setDefaultActivity(newDefaultActivity); - } - } + Set oldParentActivities = originalLearningDesign.getParentActivities(); + if (oldParentActivities != null) { + Iterator iterator = oldParentActivities.iterator(); + while (iterator.hasNext()) { + processActivity((Activity) iterator.next(), newLearningDesign, newActivities, newGroupings, null, + originalLearningDesign.getLearningDesignId(), uiidOffset, customCSV); + } + } - if ( activity.isSequenceActivity() ) { - SequenceActivity newSequenceActivity = (SequenceActivity) activity; - // Need to check if the sets are not null as these are new objects and Hibernate may not have backed them with collections yet. - if ( newSequenceActivity.getBranchEntries() != null && newSequenceActivity.getBranchEntries().size() > 0 ) { - - Activity parentActivity = newSequenceActivity.getParentActivity(); - if ( parentActivity.isChosenBranchingActivity() || - ( parentActivity.isGroupBranchingActivity() && parentActivity.getDefineLater()!=null && - parentActivity.getDefineLater().booleanValue())) { - // Don't have any preset up entries for a teacher chosen or a define later group based branching. - // Must be copying a design that was run previously. - newSequenceActivity.getBranchEntries().clear(); + Collection activities = newActivities.values(); - } else { - Iterator beIter = newSequenceActivity.getBranchEntries().iterator(); - while ( beIter.hasNext() ) { - // sequence activity will be correct but the branching activity and the grouping will be wrong - // the condition was copied by the sequence activity copy - BranchActivityEntry entry = (BranchActivityEntry) beIter.next(); - BranchingActivity oldBranchingActivity = entry.getBranchingActivity(); - entry.setBranchingActivity((BranchingActivity) newActivities.get(LearningDesign.addOffset(oldBranchingActivity.getActivityUIID(), uiidOffset))); - Group oldGroup = entry.getGroup(); - if ( oldGroup != null ) { - Grouping oldGrouping = oldGroup.getGrouping(); - Grouping newGrouping = newGroupings.get(LearningDesign.addOffset(oldGrouping.getGroupingUIID(), uiidOffset)); - if ( newGrouping != null ) { - entry.setGroup(newGrouping.getGroup(LearningDesign.addOffset(oldGroup.getGroupUIID(), uiidOffset))); - } - } - } - - } - } - } - - if ( activity.getInputActivities() != null && activity.getInputActivities().size() > 0 ) { - Set newInputActivities = new HashSet(); - Iterator inputIter = activity.getInputActivities().iterator(); - while (inputIter.hasNext()) { + // Go back and find all the grouped activities and assign them the new groupings, based on the UIID. Can't + // be done as we go as the grouping activity may be processed after the grouped activity. + for (Activity activity : activities) { + if (activity.getGroupingUIID() != null) { + activity.setGrouping(newGroupings.get(activity.getGroupingUIID())); + } + } + + // fix up any old "default activity" in the complex activities and the input activities + // and fix any branch mappings + for (Activity activity : activities) { + if (activity.isComplexActivity()) { + ComplexActivity newComplex = (ComplexActivity) activity; + Activity oldDefaultActivity = newComplex.getDefaultActivity(); + if (oldDefaultActivity != null) { + Activity newDefaultActivity = newActivities.get(LearningDesign.addOffset( + oldDefaultActivity.getActivityUIID(), uiidOffset)); + newComplex.setDefaultActivity(newDefaultActivity); + } + } + + if (activity.isSequenceActivity()) { + SequenceActivity newSequenceActivity = (SequenceActivity) activity; + // Need to check if the sets are not null as these are new objects and Hibernate may not have backed them with collections yet. + if (newSequenceActivity.getBranchEntries() != null && newSequenceActivity.getBranchEntries().size() > 0) { + + Activity parentActivity = newSequenceActivity.getParentActivity(); + if (parentActivity.isChosenBranchingActivity() || parentActivity.isGroupBranchingActivity() + && parentActivity.getDefineLater() != null && parentActivity.getDefineLater().booleanValue()) { + // Don't have any preset up entries for a teacher chosen or a define later group based branching. + // Must be copying a design that was run previously. + newSequenceActivity.getBranchEntries().clear(); + + } + else { + Iterator beIter = newSequenceActivity.getBranchEntries().iterator(); + while (beIter.hasNext()) { + // sequence activity will be correct but the branching activity and the grouping will be wrong + // the condition was copied by the sequence activity copy + BranchActivityEntry entry = (BranchActivityEntry) beIter.next(); + BranchingActivity oldBranchingActivity = (BranchingActivity) entry.getBranchingActivity(); + entry.setBranchingActivity(newActivities.get(LearningDesign.addOffset(oldBranchingActivity + .getActivityUIID(), uiidOffset))); + Group oldGroup = entry.getGroup(); + if (oldGroup != null) { + Grouping oldGrouping = oldGroup.getGrouping(); + Grouping newGrouping = newGroupings.get(LearningDesign.addOffset(oldGrouping.getGroupingUIID(), + uiidOffset)); + if (newGrouping != null) { + entry.setGroup(newGrouping.getGroup(LearningDesign.addOffset(oldGroup.getGroupUIID(), + uiidOffset))); + } + } + } + + } + } + } + + if (activity.getInputActivities() != null && activity.getInputActivities().size() > 0) { + Set newInputActivities = new HashSet(); + Iterator inputIter = activity.getInputActivities().iterator(); + while (inputIter.hasNext()) { Activity elem = (Activity) inputIter.next(); newInputActivities.add(newActivities.get(LearningDesign.addOffset(elem.getActivityUIID(), uiidOffset))); } - activity.getInputActivities().clear(); - activity.getInputActivities().addAll(newInputActivities); - } - } + activity.getInputActivities().clear(); + activity.getInputActivities().addAll(newInputActivities); + } + } - // The activities collection in the learning design may already exist (as we have already done a save on the design). - // If so, we can't just override the existing collection as the cascade causes an error. - // newLearningDesign.getActivities() will create a new TreeSet(new ActivityOrderComparator()) if there isn't an existing set - // If the uiidOffset is > 0, then we are adding activities, so we don't want to clear first. - if ( uiidOffset == 0 ) { - newLearningDesign.getActivities().clear(); - } - newLearningDesign.getActivities().addAll(activities); - - // On very rare occasions, we've had Hibernate try to save the branching entries before saving the branching activity - // which throws an exception as the branch_activity_id is null. So force any branching activities to save first. - // And yes, this IS a hack. (See LDEV-1786) - for ( Activity activity : activities) { - if ( activity.isBranchingActivity() ) { - activityDAO.insert(activity); - } - } - - return newActivities; - - } + // The activities collection in the learning design may already exist (as we have already done a save on the design). + // If so, we can't just override the existing collection as the cascade causes an error. + // newLearningDesign.getActivities() will create a new TreeSet(new ActivityOrderComparator()) if there isn't an existing set + // If the uiidOffset is > 0, then we are adding activities, so we don't want to clear first. + if (uiidOffset == 0) { + newLearningDesign.getActivities().clear(); + } + newLearningDesign.getActivities().addAll(activities); - /** As part of updateDesignActivities(), process an activity and, via recursive calls, the activity's child activities. Need to keep track - * of any new groupings created so we can go back and update the grouped activities with their new groupings at the end. Also copies the - * tool content. - * - * @param activity Activity to process. May not be null. - * @param newLearningDesign The new learning design. May not be null. - * @param newActivities Temporary set of new activities - as activities are processed they are added to the set. May not be null. - * @param newGroupings Temporary set of new groupings. Key is the grouping UUID. May not be null. - * @param parentActivity This activity's parent activity (if one exists). May be null. - */ - private void processActivity(Activity activity, LearningDesign newLearningDesign, Map newActivities, Map newGroupings, - Activity parentActivity, Long originalLearningDesignId, int uiidOffset, String customCSV) { + // On very rare occasions, we've had Hibernate try to save the branching entries before saving the branching activity + // which throws an exception as the branch_activity_id is null. So force any branching activities to save first. + // And yes, this IS a hack. (See LDEV-1786) + for (Activity activity : activities) { + if (activity.isBranchingActivity()) { + activityDAO.insert(activity); + } + } + + return newActivities; + + } + + /** As part of updateDesignActivities(), process an activity and, via recursive calls, the activity's child activities. Need to keep track + * of any new groupings created so we can go back and update the grouped activities with their new groupings at the end. Also copies the + * tool content. + * + * @param activity Activity to process. May not be null. + * @param newLearningDesign The new learning design. May not be null. + * @param newActivities Temporary set of new activities - as activities are processed they are added to the set. May not be null. + * @param newGroupings Temporary set of new groupings. Key is the grouping UUID. May not be null. + * @param parentActivity This activity's parent activity (if one exists). May be null. + */ + private void processActivity(Activity activity, LearningDesign newLearningDesign, Map newActivities, + Map newGroupings, Activity parentActivity, Long originalLearningDesignId, int uiidOffset, + String customCSV) { Activity newActivity = getActivityCopy(activity, newGroupings, uiidOffset); - newActivity.setActivityUIID( newActivity.getActivityUIID() ); + newActivity.setActivityUIID(newActivity.getActivityUIID()); newActivity.setLearningDesign(newLearningDesign); newActivity.setReadOnly(false); - if ( parentActivity != null ) { + if (parentActivity != null) { newActivity.setParentActivity(parentActivity); newActivity.setParentUIID(parentActivity.getActivityUIID()); } - newActivities.put(newActivity.getActivityUIID(),newActivity); + newActivities.put(newActivity.getActivityUIID(), newActivity); - if (newActivity.isToolActivity()) { - copyActivityToolContent(newActivity, newLearningDesign.getCopyTypeID(), originalLearningDesignId, customCSV); - } + if (newActivity.isToolActivity()) { + copyActivityToolContent(newActivity, newLearningDesign.getCopyTypeID(), originalLearningDesignId, customCSV); + } - Set oldChildActivities = getChildActivities((Activity)activity); - if ( oldChildActivities != null ) { + Set oldChildActivities = getChildActivities(activity); + if (oldChildActivities != null) { Iterator childIterator = oldChildActivities.iterator(); - while(childIterator.hasNext()){ - processActivity((Activity)childIterator.next(), newLearningDesign, newActivities, newGroupings, newActivity, originalLearningDesignId, uiidOffset, customCSV); + while (childIterator.hasNext()) { + processActivity((Activity) childIterator.next(), newLearningDesign, newActivities, newGroupings, newActivity, + originalLearningDesignId, uiidOffset, customCSV); } } - } + } /** - * Updates the Transition information in the newLearningDesign based - * on the originalLearningDesign - * - * @param originalLearningDesign The LearningDesign to be copied - * @param newLearningDesign The copy of the originalLearningDesign - */ - public void updateDesignTransitions(LearningDesign originalLearningDesign, LearningDesign newLearningDesign, HashMap newActivities, int uiidOffset){ - HashSet newTransitions = new HashSet(); - Set oldTransitions = originalLearningDesign.getTransitions(); - Iterator iterator = oldTransitions.iterator(); - while(iterator.hasNext()){ - Transition transition = (Transition)iterator.next(); - Transition newTransition = Transition.createCopy(transition, uiidOffset); - Activity toActivity = null; - Activity fromActivity=null; - if(newTransition.getToUIID()!=null) { - toActivity = newActivities.get(newTransition.getToUIID()); - toActivity.setTransitionTo(newTransition); - } - if(newTransition.getFromUIID()!=null) { - fromActivity = newActivities.get(newTransition.getFromUIID()); - fromActivity.setTransitionFrom(newTransition); - } - newTransition.setToActivity(toActivity); - newTransition.setFromActivity(fromActivity); - newTransition.setLearningDesign(newLearningDesign); - transitionDAO.insert(newTransition); - newTransitions.add(newTransition); - } - - // The transitions collection in the learning design may already exist (as we have already done a save on the design). - // If so, we can't just override the existing collection as the cascade causes an error. - // If the uiidOffset is > 0, then we are adding transitions (rather than replacing), so we don't want to clear first. - if ( newLearningDesign.getTransitions() != null ) { - if ( uiidOffset == 0 ) { - newLearningDesign.getTransitions().clear(); - } - newLearningDesign.getTransitions().addAll(newTransitions); - } else { - newLearningDesign.setTransitions(newTransitions); - } + * Updates the Transition information in the newLearningDesign based + * on the originalLearningDesign + * + * @param originalLearningDesign The LearningDesign to be copied + * @param newLearningDesign The copy of the originalLearningDesign + */ + public void updateDesignTransitions(LearningDesign originalLearningDesign, LearningDesign newLearningDesign, + HashMap newActivities, int uiidOffset) { + HashSet newTransitions = new HashSet(); + Set oldTransitions = originalLearningDesign.getTransitions(); + Iterator iterator = oldTransitions.iterator(); + while (iterator.hasNext()) { + Transition transition = (Transition) iterator.next(); + Transition newTransition = Transition.createCopy(transition, uiidOffset); + Activity toActivity = null; + Activity fromActivity = null; + if (newTransition.getToUIID() != null) { + toActivity = newActivities.get(newTransition.getToUIID()); + toActivity.setTransitionTo(newTransition); + } + if (newTransition.getFromUIID() != null) { + fromActivity = newActivities.get(newTransition.getFromUIID()); + fromActivity.setTransitionFrom(newTransition); + } + newTransition.setToActivity(toActivity); + newTransition.setFromActivity(fromActivity); + newTransition.setLearningDesign(newLearningDesign); + transitionDAO.insert(newTransition); + newTransitions.add(newTransition); + } - } - /** - * Determines the type of activity and returns a deep-copy of the same - * - * @param activity The object to be deep-copied - * @param newGroupings Temporary set of new groupings. Key is the grouping UUID. May not be null. - * @return Activity The new deep-copied Activity object - */ - private Activity getActivityCopy(final Activity activity, Map newGroupings, int uiidOffset){ - if ( Activity.GROUPING_ACTIVITY_TYPE == activity.getActivityTypeId().intValue() ) { - GroupingActivity newGroupingActivity = (GroupingActivity) activity.createCopy(uiidOffset); - // now we need to manually add the grouping to the session, as we can't easily - // set up a cascade - Grouping grouping = newGroupingActivity.getCreateGrouping(); - grouping.setGroupingUIID(grouping.getGroupingUIID()); - if ( grouping != null ) { - groupingDAO.insert(grouping); - newGroupings.put(grouping.getGroupingUIID(), grouping); - } - return newGroupingActivity; - } - else - return activity.createCopy(uiidOffset); - } - /** - * Returns a set of child activities for the given parent activity - * - * @param parentActivity The parent activity - * @return HashSet Set of the activities that belong to the parentActivity - */ - private HashSet getChildActivities(Activity parentActivity){ - HashSet childActivities = new HashSet(); - List list = activityDAO.getActivitiesByParentActivityId(parentActivity.getActivityId()); - if(list!=null) - childActivities.addAll(list); - return childActivities; - } + // The transitions collection in the learning design may already exist (as we have already done a save on the design). + // If so, we can't just override the existing collection as the cascade causes an error. + // If the uiidOffset is > 0, then we are adding transitions (rather than replacing), so we don't want to clear first. + if (newLearningDesign.getTransitions() != null) { + if (uiidOffset == 0) { + newLearningDesign.getTransitions().clear(); + } + newLearningDesign.getTransitions().addAll(newTransitions); + } + else { + newLearningDesign.setTransitions(newTransitions); + } + + } + /** + * Determines the type of activity and returns a deep-copy of the same + * + * @param activity The object to be deep-copied + * @param newGroupings Temporary set of new groupings. Key is the grouping UUID. May not be null. + * @return Activity The new deep-copied Activity object + */ + private Activity getActivityCopy(final Activity activity, Map newGroupings, int uiidOffset) { + if (Activity.GROUPING_ACTIVITY_TYPE == activity.getActivityTypeId().intValue()) { + GroupingActivity newGroupingActivity = (GroupingActivity) activity.createCopy(uiidOffset); + // now we need to manually add the grouping to the session, as we can't easily + // set up a cascade + Grouping grouping = newGroupingActivity.getCreateGrouping(); + grouping.setGroupingUIID(grouping.getGroupingUIID()); + if (grouping != null) { + groupingDAO.insert(grouping); + newGroupings.put(grouping.getGroupingUIID(), grouping); + } + return newGroupingActivity; + } + else { + return activity.createCopy(uiidOffset); + } + } + + /** + * Returns a set of child activities for the given parent activity + * + * @param parentActivity The parent activity + * @return HashSet Set of the activities that belong to the parentActivity + */ + private HashSet getChildActivities(Activity parentActivity) { + HashSet childActivities = new HashSet(); + List list = activityDAO.getActivitiesByParentActivityId(parentActivity.getActivityId()); + if (list != null) { + childActivities.addAll(list); + } + return childActivities; + } + + /** * This method saves a new Learning Design to the database. * It received a WDDX packet from flash, deserializes it * and then finally persists it to the database. @@ -1117,44 +1206,46 @@ */ public Long storeLearningDesignDetails(String wddxPacket) throws Exception { - Hashtable table = (Hashtable)WDDXProcessor.deserialize(wddxPacket); + Hashtable table = (Hashtable) WDDXProcessor.deserialize(wddxPacket); Integer workspaceFolderID = WDDXProcessor.convertToInteger(table, WDDXTAGS.WORKSPACE_FOLDER_ID); User user = null; Integer userID = getUserId(); - if( userID != null ) { - user = (User)baseDAO.find(User.class,userID); + if (userID != null) { + user = (User) baseDAO.find(User.class, userID); } - if ( user == null ) { + if (user == null) { throw new UserException("UserID missing or user not found."); } WorkspaceFolder workspaceFolder = null; boolean authorised = false; - if (workspaceFolderID != null ) { - workspaceFolder = (WorkspaceFolder)baseDAO.find(WorkspaceFolder.class,workspaceFolderID); + if (workspaceFolderID != null) { + workspaceFolder = (WorkspaceFolder) baseDAO.find(WorkspaceFolder.class, workspaceFolderID); authorised = workspaceManagementService.isUserAuthorizedToModifyFolderContents(workspaceFolderID, userID); } - + Long learningDesignId = WDDXProcessor.convertToLong(table, "learningDesignID"); - LearningDesign existingLearningDesign = learningDesignId != null ? learningDesignDAO.getLearningDesignById(learningDesignId) : null; - if ( ! authorised && existingLearningDesign != null && Boolean.TRUE.equals(existingLearningDesign.getEditOverrideLock())) { - authorised = userID.equals(existingLearningDesign.getEditOverrideUser().getUserId()); + LearningDesign existingLearningDesign = learningDesignId != null ? learningDesignDAO + .getLearningDesignById(learningDesignId) : null; + if (!authorised && existingLearningDesign != null && Boolean.TRUE.equals(existingLearningDesign.getEditOverrideLock())) { + authorised = userID.equals(existingLearningDesign.getEditOverrideUser().getUserId()); } - if ( ! authorised ) { - throw new UserException("User with user_id of " + userID +" is not authorized to store a design in this workspace folder "+workspaceFolderID); + if (!authorised) { + throw new UserException("User with user_id of " + userID + + " is not authorized to store a design in this workspace folder " + workspaceFolderID); } IObjectExtractor extractor = (IObjectExtractor) beanFactory.getBean(IObjectExtractor.OBJECT_EXTRACTOR_SPRING_BEANNAME); - LearningDesign design = extractor.extractSaveLearningDesign(table, existingLearningDesign, workspaceFolder, user); - - if(extractor.getMode().intValue() == 1) + LearningDesign design = extractor.extractSaveLearningDesign(table, existingLearningDesign, workspaceFolder, user); + + if (extractor.getMode().intValue() == 1) { copyLearningDesignToolContent(design, design, design.getCopyTypeID()); - + } + return design.getLearningDesignId(); } - /** * Validate the learning design, updating the valid flag appropriately. * @@ -1173,45 +1264,45 @@ learningDesignDAO.insertOrUpdate(learningDesign); return listOfValidationErrorDTOs; } - + public Vector getToolActivities(Long learningDesignId, String languageCode) { LearningDesign learningDesign = learningDesignDAO.getLearningDesignById(learningDesignId); Vector listOfAuthoringActivityDTOs = new Vector(); - - for (Iterator i = learningDesign.getActivities().iterator(); i.hasNext();) - { - Activity currentActivity = (Activity) i.next(); - if (currentActivity.isToolActivity()) - { - try { - // Normally we pass in an array for the branch mappings as the second parameter to new AuthoringActivityDTO() - // but we don't need to in this case as it is only doing it for tool activities, and the extra parameter is only - // used for branching activities - ToolActivity toolActivity = (ToolActivity) activityDAO.getActivityByActivityId(currentActivity.getActivityId()); - AuthoringActivityDTO activityDTO = new AuthoringActivityDTO(toolActivity, null, languageCode); - listOfAuthoringActivityDTOs.add(activityDTO); - } catch (ToolException e) { - String error = "" - +e.getMessage(); - log.error(error,e); - throw new LearningDesignException(error,e); - } - } - } - + + for (Iterator i = learningDesign.getActivities().iterator(); i.hasNext();) { + Activity currentActivity = (Activity) i.next(); + if (currentActivity.isToolActivity()) { + try { + // Normally we pass in an array for the branch mappings as the second parameter to new AuthoringActivityDTO() + // but we don't need to in this case as it is only doing it for tool activities, and the extra parameter is only + // used for branching activities + ToolActivity toolActivity = (ToolActivity) activityDAO.getActivityByActivityId(currentActivity + .getActivityId()); + AuthoringActivityDTO activityDTO = new AuthoringActivityDTO(toolActivity, null, languageCode); + listOfAuthoringActivityDTOs.add(activityDTO); + } + catch (ToolException e) { + String error = "" + e.getMessage(); + log.error(error, e); + throw new LearningDesignException(error, e); + } + } + } + return listOfAuthoringActivityDTOs; } - + /** * (non-Javadoc) * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#getAllLearningDesignDetails() */ - public String getAllLearningDesignDetails()throws IOException{ - Iterator iterator= getAllLearningDesigns().iterator(); + public String getAllLearningDesignDetails() throws IOException { + Iterator iterator = getAllLearningDesigns().iterator(); ArrayList arrayList = createDesignDetailsPacket(iterator); - FlashMessage flashMessage = new FlashMessage("getAllLearningDesignDetails",arrayList); + FlashMessage flashMessage = new FlashMessage("getAllLearningDesignDetails", arrayList); return flashMessage.serializeMessage(); } + /** * This is a utility method used by the method * getAllLearningDesignDetails to pack the @@ -1220,54 +1311,55 @@ * @param iterator * @return Hashtable The required information in a Hashtable */ - private ArrayList createDesignDetailsPacket(Iterator iterator){ - ArrayList arrayList = new ArrayList(); - while(iterator.hasNext()){ - LearningDesign learningDesign = (LearningDesign)iterator.next(); + private ArrayList createDesignDetailsPacket(Iterator iterator) { + ArrayList arrayList = new ArrayList(); + while (iterator.hasNext()) { + LearningDesign learningDesign = (LearningDesign) iterator.next(); DesignDetailDTO designDetailDTO = learningDesign.getDesignDetailDTO(); arrayList.add(designDetailDTO); } return arrayList; } + /** * (non-Javadoc) * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#getLearningDesignsForUser(java.lang.Long) */ - public String getLearningDesignsForUser(Long userID) throws IOException{ + public String getLearningDesignsForUser(Long userID) throws IOException { List list = learningDesignDAO.getLearningDesignByUserId(userID); ArrayList arrayList = createDesignDetailsPacket(list.iterator()); - FlashMessage flashMessage = new FlashMessage("getLearningDesignsForUser",arrayList); + FlashMessage flashMessage = new FlashMessage("getLearningDesignsForUser", arrayList); return flashMessage.serializeMessage(); - } + } + /** * (non-Javadoc) * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#getAllLearningLibraryDetails() */ - public String getAllLearningLibraryDetails(String languageCode)throws IOException{ - FlashMessage flashMessage = new FlashMessage("getAllLearningLibraryDetails",learningDesignService.getAllLearningLibraryDetails(languageCode)); + public String getAllLearningLibraryDetails(String languageCode) throws IOException { + FlashMessage flashMessage = new FlashMessage("getAllLearningLibraryDetails", learningDesignService + .getAllLearningLibraryDetails(languageCode)); return flashMessage.serializeMessage(); } - + /** @see org.lamsfoundation.lams.authoring.service.IAuthoringService#getToolContentID(java.lang.Long) */ - public String getToolContentID(Long toolID) throws IOException - { - Tool tool = toolDAO.getToolByID(toolID); - if (tool == null) - { - log.error("The toolID "+ toolID + " is not valid. A Tool with tool id " + toolID + " does not exist on the database."); - return FlashMessage.getNoSuchTool("getToolContentID", toolID).serializeMessage(); - } - - Long newContentID = contentIDGenerator.getNextToolContentIDFor(tool); - FlashMessage flashMessage = new FlashMessage("getToolContentID", newContentID); - - return flashMessage.serializeMessage(); + public String getToolContentID(Long toolID) throws IOException { + Tool tool = toolDAO.getToolByID(toolID); + if (tool == null) { + log.error("The toolID " + toolID + " is not valid. A Tool with tool id " + toolID + + " does not exist on the database."); + return FlashMessage.getNoSuchTool("getToolContentID", toolID).serializeMessage(); + } + + Long newContentID = contentIDGenerator.getNextToolContentIDFor(tool); + FlashMessage flashMessage = new FlashMessage("getToolContentID", newContentID); + + return flashMessage.serializeMessage(); } - + /** @see org.lamsfoundation.lams.authoring.service.IAuthoringService#copyToolContent(java.lang.Long) */ - public String copyToolContent(Long toolContentID, String customCSV) throws IOException - { + public String copyToolContent(Long toolContentID, String customCSV) throws IOException { Long newContentID = lamsCoreToolService.notifyToolToCopyContent(toolContentID, customCSV); FlashMessage flashMessage = new FlashMessage("copyToolContent", newContentID); return flashMessage.serializeMessage(); @@ -1278,8 +1370,8 @@ */ public String copyMultipleToolContent(Integer userId, List toolContentIds, String customCSV) { StringBuffer idMap = new StringBuffer(); - for ( Long oldToolContentId : toolContentIds) { - if ( oldToolContentId != null ) { + for (Long oldToolContentId : toolContentIds) { + if (oldToolContentId != null) { Long newToolContentId = lamsCoreToolService.notifyToolToCopyContent(oldToolContentId, customCSV); idMap.append(oldToolContentId); idMap.append('='); @@ -1288,15 +1380,15 @@ } } // return the id list, stripping off the trailing , - return idMap.length() > 0 ? idMap.substring(0, idMap.length()-1) : ""; + return idMap.length() > 0 ? idMap.substring(0, idMap.length() - 1) : ""; } - + /** @see org.lamsfoundation.lams.authoring.service.IAuthoringService#getAvailableLicenses() */ public Vector getAvailableLicenses() { List licenses = licenseDAO.findAll(License.class); Vector licenseDTOList = new Vector(licenses.size()); - Iterator iter = licenses.iterator(); - while ( iter.hasNext() ) { + Iterator iter = licenses.iterator(); + while (iter.hasNext()) { License element = (License) iter.next(); licenseDTOList.add(element.getLicenseDTO(Configuration.get(ConfigurationKeys.SERVER_URL))); } @@ -1306,56 +1398,57 @@ /** Delete a learning design from the database. Does not remove any content stored in tools - * that is done by the LamsCoreToolService */ public void deleteLearningDesign(LearningDesign design) { - if ( design == null ) { + if (design == null) { log.error("deleteLearningDesign: unable to delete learning design as design is null."); return; } - + // remove all the tool content for the learning design Set acts = design.getActivities(); Iterator iter = acts.iterator(); while (iter.hasNext()) { Activity activity = (Activity) iter.next(); - if (activity.isToolActivity()) - { - try { - ToolActivity toolActivity = (ToolActivity) activityDAO.getActivityByActivityId(activity.getActivityId()); + if (activity.isToolActivity()) { + try { + ToolActivity toolActivity = (ToolActivity) activityDAO.getActivityByActivityId(activity.getActivityId()); lamsCoreToolService.notifyToolToDeleteContent(toolActivity); - } catch (ToolException e) { - log.error("Unable to delete tool content for activity"+activity - +" as activity threw an exception",e); } + catch (ToolException e) { + log.error("Unable to delete tool content for activity" + activity + " as activity threw an exception", e); + } } } - + // remove the learning design learningDesignDAO.delete(design); } - + /** @see org.lamsfoundation.lams.authoring.service.IAuthoringService#generateUniqueContentFolder() */ public String generateUniqueContentFolder() throws FileUtilException, IOException { - + String newUniqueContentFolderID = FileUtil.generateUniqueContentFolderID(); - + FlashMessage flashMessage = new FlashMessage("createUniqueContentFolder", newUniqueContentFolderID); - + return flashMessage.serializeMessage(); } - + /** @see org.lamsfoundation.lams.authoring.service.IAuthoringService#getHelpURL() */ public String getHelpURL() throws Exception { - - FlashMessage flashMessage =null; - + + FlashMessage flashMessage = null; + String helpURL = Configuration.get(ConfigurationKeys.HELP_URL); - if(helpURL != null) + if (helpURL != null) { flashMessage = new FlashMessage("getHelpURL", helpURL); - else + } + else { throw new Exception(); - + } + return flashMessage.serializeMessage(); } - + /** * Get a unique name for a learning design, based on the names of the learning designs in the folder. * If the learning design has duplicated name in same folder, then the new name will have a timestamp. @@ -1369,27 +1462,28 @@ public String getUniqueNameForLearningDesign(String originalTitle, Integer workspaceFolderId) { String newName = originalTitle; - if(workspaceFolderId != null ){ + if (workspaceFolderId != null) { List ldTitleList = learningDesignDAO.getLearningDesignTitlesByWorkspaceFolder(workspaceFolderId); int idx = 1; - + Calendar calendar = Calendar.getInstance(); int mth = calendar.get(Calendar.MONTH) + 1; String mthStr = new Integer(mth).toString(); - if(mth < 10) + if (mth < 10) { mthStr = "0" + mthStr; + } int day = calendar.get(Calendar.DAY_OF_MONTH); String dayStr = new Integer(day).toString(); - if(day < 10) + if (day < 10) { dayStr = "0" + dayStr; + } String nameMid = dayStr + mthStr + calendar.get(Calendar.YEAR); - while ( ldTitleList.contains(newName) ) { + while (ldTitleList.contains(newName)) { newName = originalTitle + "_" + nameMid + "_" + idx; idx++; } - } + } return newName; } - } \ No newline at end of file Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/learningdesign/Activity.hbm.xml =================================================================== diff -u -r418a30a76094c56762b5beb23cb2dd72619e316c -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/learningdesign/Activity.hbm.xml (.../Activity.hbm.xml) (revision 418a30a76094c56762b5beb23cb2dd72619e316c) +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/learningdesign/Activity.hbm.xml (.../Activity.hbm.xml) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -237,8 +237,18 @@ @hibernate.class - - + + @hibernate.class + + @hibernate.set lazy="true" inverse="true" cascade="all-delete-orphan" + @hibernate.collection-key column="branch_activity_id" + @hibernate.collection-one-to-many class="org.lamsfoundation.lams.learningdesign.BranchActivityEntry" + + + + + + Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/learningdesign/BranchActivityEntry.hbm.xml =================================================================== diff -u -r87ec6bd0708e9da634182eacca8c74e442bc748f -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/learningdesign/BranchActivityEntry.hbm.xml (.../BranchActivityEntry.hbm.xml) (revision 87ec6bd0708e9da634182eacca8c74e442bc748f) +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/learningdesign/BranchActivityEntry.hbm.xml (.../BranchActivityEntry.hbm.xml) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -34,7 +34,7 @@ - + Index: lams_common/conf/language/lams/ApplicationResources.properties =================================================================== diff -u -r6e4ed3724bd76354c2ee43c88979385c4a162a0e -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_common/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 6e4ed3724bd76354c2ee43c88979385c4a162a0e) +++ lams_common/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -49,6 +49,8 @@ validation.error.toolBranchingMustHaveACondition = Learner's Output Branching Activity must have at least one condition. validation.error.toolBranchingMustHaveDefaultBranch =A Learner's Output Branching Activity must have a Default Branch. validation.error.toolBranchingMustHaveAnInputToolActivity =A Learner's Output Branching Activity must have an Input Tool. +validation.error.conditionGateMustHaveACondition =A Condition Gate must have at least one condition. +validation.error.conditionGateMustHaveAnInputToolActivity =A Condition Gate must have an Input Tool. mail.resend.abandon.subject =LAMS: Message delivery failed mail.resend.abandon.body1=LAMS was resending a message to users, but eventually it gave up. The message was:\n Index: lams_common/conf/language/lams/ApplicationResources_en_AU.properties =================================================================== diff -u -rdb3b153522421c748da5d7a67df4fcdf0652cbc7 -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_common/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision db3b153522421c748da5d7a67df4fcdf0652cbc7) +++ lams_common/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -49,6 +49,11 @@ validation.error.toolBranchingMustHaveACondition = Learner's Output Branching Activity must have at least one condition. validation.error.toolBranchingMustHaveDefaultBranch =A Learner's Output Branching Activity must have a Default Branch. validation.error.toolBranchingMustHaveAnInputToolActivity =A Learner's Output Branching Activity must have an Input Tool. +validation.error.conditionGateMustHaveACondition =A Condition Gate must have at least one condition. +validation.error.conditionGateMustHaveAnInputToolActivity =A Condition Gate must have an Input Tool. +mail.resend.abandon.subject =LAMS: Message delivery failed +mail.resend.abandon.body1=LAMS was resending a message to users, but eventually it gave up. The message was:\n +mail.resend.abandon.body2=\nUsers' login names:\n #======= End labels: Exported 43 labels for en AU ===== Index: lams_common/db/model/lams_11.clay =================================================================== diff -u -r418a30a76094c56762b5beb23cb2dd72619e316c -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_common/db/model/lams_11.clay (.../lams_11.clay) (revision 418a30a76094c56762b5beb23cb2dd72619e316c) +++ lams_common/db/model/lams_11.clay (.../lams_11.clay) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -5530,11 +5530,11 @@ - + - + Index: lams_common/db/sql/create_lams_11_tables.sql =================================================================== diff -u -r418a30a76094c56762b5beb23cb2dd72619e316c -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_common/db/sql/create_lams_11_tables.sql (.../create_lams_11_tables.sql) (revision 418a30a76094c56762b5beb23cb2dd72619e316c) +++ lams_common/db/sql/create_lams_11_tables.sql (.../create_lams_11_tables.sql) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -602,7 +602,7 @@ entry_id BIGINT(20) NOT NULL AUTO_INCREMENT , entry_ui_id INT(11) , group_id BIGINT(20) - , sequence_activity_id BIGINT(20) NOT NULL + , sequence_activity_id BIGINT(20) , branch_activity_id BIGINT(20) NOT NULL , condition_id BIGINT(20) , PRIMARY KEY (entry_id) Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/Activity.java =================================================================== diff -u -rfdca3605f0b782b19e214abbe94df6f4a457b88e -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/Activity.java (.../Activity.java) (revision fdca3605f0b782b19e214abbe94df6f4a457b88e) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/Activity.java (.../Activity.java) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -52,11 +52,11 @@ * * @hibernate.class table="lams_learning_activity" */ -public abstract class Activity implements Serializable,Nullable { +public abstract class Activity implements Serializable, Nullable { - //--------------------------------------------------------------------- - // Class Level Constants - //--------------------------------------------------------------------- + //--------------------------------------------------------------------- + // Class Level Constants + //--------------------------------------------------------------------- /* * static final variables indicating the type of activities * available for a LearningDesign. As new types of activities @@ -81,42 +81,41 @@ public static final int GROUP_BRANCHING_ACTIVITY_TYPE = 11; public static final int TOOL_BRANCHING_ACTIVITY_TYPE = 12; public static final int OPTIONS_WITH_SEQUENCES_TYPE = 13; + public static final int CONDITION_GATE_ACTIVITY_TYPE = 14; /******************************************************************/ - + /** * static final variables indicating the the category of activities - *******************************************************************/ + *******************************************************************/ public static final int CATEGORY_SYSTEM = 1; public static final int CATEGORY_COLLABORATION = 2; public static final int CATEGORY_ASSESSMENT = 3; public static final int CATEGORY_CONTENT = 4; public static final int CATEGORY_SPLIT = 5; public static final int CATEGORY_RESPONSE = 6; /******************************************************************/ - + /** * static final variables indicating the grouping_support of activities *******************************************************************/ public static final int GROUPING_SUPPORT_NONE = 1; public static final int GROUPING_SUPPORT_OPTIONAL = 2; public static final int GROUPING_SUPPORT_REQUIRED = 3; /******************************************************************/ - - + /** * Entries for an activity in a language property file */ public static final String I18N_TITLE = "activity.title"; public static final String I18N_DESCRIPTION = "activity.description"; public static final String I18N_HELP_TEXT = "activity.helptext"; - - //--------------------------------------------------------------------- - // Instance variables - //--------------------------------------------------------------------- + //--------------------------------------------------------------------- + // Instance variables + //--------------------------------------------------------------------- /** WDDX packet specific attribute created to identify the * type of object being passed.*/ - public static final String OBJECT_TYPE ="Activity"; + public static final String OBJECT_TYPE = "Activity"; /** identifier field */ private Long activityId; @@ -130,7 +129,7 @@ /** Title of the activity*/ private String title; - + /** Help text for the activity*/ private String helpText; @@ -150,7 +149,7 @@ /** Indicates whether the content of this activity * would be defined later in the monitoring environment or not.*/ private Boolean defineLater; - + /** Indicates whether this activity is available offline*/ private Boolean runOffline; @@ -169,7 +168,7 @@ * complex activities which have child activities * defined inside them. */ private Activity parentActivity; - + /** Single Library can have one or more activities * defined inside it. This field indicates which * activity is this.*/ @@ -180,29 +179,29 @@ /** The Grouping that applies to this activity*/ private Grouping grouping; - + /** The grouping_ui_id of the Grouping that * applies that to this activity * */ private Integer groupingUIID; /** The type of activity */ private Integer activityTypeId; - + /** The category of activity */ private Integer activityCategoryID; /** persistent field */ - private Transition transitionTo; - + private Transition transitionTo; + /** persistent field */ private Transition transitionFrom; - + /** the activity_ui_id of the parent activity */ private Integer parentUIID; - + private Boolean applyGrouping; - + private Integer groupingSupportType; /** Name of the file (including the package) that contains the text strings for @@ -223,46 +222,28 @@ * final activity of a design does not necessarily have this set - the progress engine will just * stop when it runs out of transitions to follow. */ private Boolean stopAfterActivity; - - /** - * The activities that supplied inputs to this activity. - */ - private Set inputActivities; - - - //--------------------------------------------------------------------- - // Object constructors - //--------------------------------------------------------------------- - + + /** + * The activities that supplied inputs to this activity. + */ + private Set inputActivities; + + //--------------------------------------------------------------------- + // Object constructors + //--------------------------------------------------------------------- + /* For the createDateTime fields, if the value is null, then it will default * to the current time. */ - + /** full constructor */ - public Activity( - Long activityId, - Integer id, - String description, - String title, - Integer xcoord, - Integer ycoord, - Integer orderId, - Boolean defineLater, - Date createDateTime, - LearningLibrary learningLibrary, - Activity parentActivity, - Activity libraryActivity, - Integer parentUIID, - LearningDesign learningDesign, - Grouping grouping, - Integer activityTypeId, - Transition transitionTo, - Transition transitionFrom, - String languageFile, - Boolean stopAfterActivity, - Set inputActivities) { + public Activity(Long activityId, Integer id, String description, String title, Integer xcoord, Integer ycoord, + Integer orderId, Boolean defineLater, Date createDateTime, LearningLibrary learningLibrary, Activity parentActivity, + Activity libraryActivity, Integer parentUIID, LearningDesign learningDesign, Grouping grouping, + Integer activityTypeId, Transition transitionTo, Transition transitionFrom, String languageFile, + Boolean stopAfterActivity, Set inputActivities) { this.activityId = activityId; - this.activityUIID = id; + activityUIID = id; this.description = description; this.title = title; this.xcoord = xcoord; @@ -280,32 +261,25 @@ this.transitionTo = transitionTo; this.transitionFrom = transitionFrom; this.languageFile = languageFile; - this.readOnly = false; - this.initialised = false; + readOnly = false; + initialised = false; this.stopAfterActivity = stopAfterActivity; this.inputActivities = inputActivities; - } + } + /** default constructor */ public Activity() { - this.grouping = null; - this.createDateTime = new Date(); //default value is set to when the object is created - this.readOnly = false; - this.initialised = false; - this.stopAfterActivity = false; + grouping = null; + createDateTime = new Date(); //default value is set to when the object is created + readOnly = false; + initialised = false; + stopAfterActivity = false; } /** minimal constructor */ - public Activity( - Long activityId, - Boolean defineLater, - Date createDateTime, - LearningLibrary learningLibrary, - Activity parentActivity, - LearningDesign learningDesign, - Grouping grouping, - Integer activityTypeId, - Transition transitionTo, - Transition transitionFrom) { + public Activity(Long activityId, Boolean defineLater, Date createDateTime, LearningLibrary learningLibrary, + Activity parentActivity, LearningDesign learningDesign, Grouping grouping, Integer activityTypeId, + Transition transitionTo, Transition transitionFrom) { this.activityId = activityId; this.defineLater = defineLater; this.createDateTime = createDateTime != null ? createDateTime : new Date(); @@ -316,84 +290,83 @@ this.activityTypeId = activityTypeId; this.transitionTo = transitionTo; this.transitionFrom = transitionFrom; - this.readOnly = false; - this.initialised = false; - this.stopAfterActivity = false; + readOnly = false; + initialised = false; + stopAfterActivity = false; } - - public static Activity getActivityInstance(int activityType) - { + + public static Activity getActivityInstance(int activityType) { // the default constructors don't set up the activity type // so we need to do that manually // also default to a sensible category type Activity activity = null; - switch(activityType){ + switch (activityType) { case TOOL_ACTIVITY_TYPE: activity = new ToolActivity(); - activity.setActivityCategoryID(CATEGORY_CONTENT); + activity.setActivityCategoryID(Activity.CATEGORY_CONTENT); break; case OPTIONS_ACTIVITY_TYPE: activity = new OptionsActivity(); - activity.setActivityCategoryID(CATEGORY_SYSTEM); + activity.setActivityCategoryID(Activity.CATEGORY_SYSTEM); break; case PARALLEL_ACTIVITY_TYPE: activity = new ParallelActivity(); - activity.setActivityCategoryID(CATEGORY_SPLIT); + activity.setActivityCategoryID(Activity.CATEGORY_SPLIT); break; case SEQUENCE_ACTIVITY_TYPE: activity = new SequenceActivity(); - activity.setActivityCategoryID(CATEGORY_SYSTEM); + activity.setActivityCategoryID(Activity.CATEGORY_SYSTEM); break; case SYNCH_GATE_ACTIVITY_TYPE: activity = new SynchGateActivity(); - activity.setActivityCategoryID(CATEGORY_SYSTEM); + activity.setActivityCategoryID(Activity.CATEGORY_SYSTEM); break; case SCHEDULE_GATE_ACTIVITY_TYPE: activity = new ScheduleGateActivity(); - activity.setActivityCategoryID(CATEGORY_SYSTEM); + activity.setActivityCategoryID(Activity.CATEGORY_SYSTEM); break; case PERMISSION_GATE_ACTIVITY_TYPE: activity = new PermissionGateActivity(); - activity.setActivityCategoryID(CATEGORY_SYSTEM); + activity.setActivityCategoryID(Activity.CATEGORY_SYSTEM); break; case SYSTEM_GATE_ACTIVITY_TYPE: activity = new SystemGateActivity(); - activity.setActivityCategoryID(CATEGORY_SYSTEM); + activity.setActivityCategoryID(Activity.CATEGORY_SYSTEM); break; case CHOSEN_BRANCHING_ACTIVITY_TYPE: activity = new ChosenBranchingActivity(); - activity.setActivityCategoryID(CATEGORY_SYSTEM); + activity.setActivityCategoryID(Activity.CATEGORY_SYSTEM); break; case GROUP_BRANCHING_ACTIVITY_TYPE: activity = new GroupBranchingActivity(); - activity.setActivityCategoryID(CATEGORY_SYSTEM); + activity.setActivityCategoryID(Activity.CATEGORY_SYSTEM); break; case TOOL_BRANCHING_ACTIVITY_TYPE: activity = new ToolBranchingActivity(); - activity.setActivityCategoryID(CATEGORY_SYSTEM); + activity.setActivityCategoryID(Activity.CATEGORY_SYSTEM); break; case OPTIONS_WITH_SEQUENCES_TYPE: activity = new OptionsWithSequencesActivity(); - activity.setActivityCategoryID(CATEGORY_SYSTEM); + activity.setActivityCategoryID(Activity.CATEGORY_SYSTEM); break; default: activity = new GroupingActivity(); - activity.setActivityCategoryID(CATEGORY_SYSTEM); + activity.setActivityCategoryID(Activity.CATEGORY_SYSTEM); break; } activity.setActivityTypeId(new Integer(activityType)); return activity; } - - //--------------------------------------------------------------------- - // Getters and Setters - //--------------------------------------------------------------------- + + //--------------------------------------------------------------------- + // Getters and Setters + //--------------------------------------------------------------------- /** * @hibernate.activityUIID generator-class="native" type="java.lang.Long" * column="activity_id" */ public Long getActivityId() { - return this.activityId; + return activityId; } public void setActivityId(Long activityId) { @@ -404,18 +377,18 @@ * @hibernate.property column="activityUIID" length="11" */ public Integer getActivityUIID() { - return this.activityUIID; + return activityUIID; } public void setActivityUIID(Integer id) { - this.activityUIID = id; + activityUIID = id; } /** * @hibernate.property column="description" length="65535" */ public String getDescription() { - return this.description; + return description; } public void setDescription(String description) { @@ -426,7 +399,7 @@ * @hibernate.property column="title" length="255" */ public String getTitle() { - return this.title; + return title; } public void setTitle(String title) { @@ -437,7 +410,7 @@ * @hibernate.property column="xcoord" length="11" */ public Integer getXcoord() { - return this.xcoord; + return xcoord; } public void setXcoord(Integer xcoord) { @@ -448,7 +421,7 @@ * @hibernate.property column="ycoord" length="11" */ public Integer getYcoord() { - return this.ycoord; + return ycoord; } public void setYcoord(Integer ycoord) { @@ -459,7 +432,7 @@ * @hibernate.property column="order_id" length="11" */ public Integer getOrderId() { - return this.orderId; + return orderId; } public void setOrderId(Integer orderId) { @@ -470,7 +443,7 @@ * @hibernate.property column="define_later_flag" length="4" not-null="true" */ public Boolean getDefineLater() { - return this.defineLater; + return defineLater; } public void setDefineLater(Boolean defineLater) { @@ -481,7 +454,7 @@ * @hibernate.property column="create_date_time" length="19" not-null="true" */ public Date getCreateDateTime() { - return this.createDateTime; + return createDateTime; } /* If createDateTime is null, then it will default to the current date/time */ @@ -495,11 +468,10 @@ * */ public org.lamsfoundation.lams.learningdesign.LearningLibrary getLearningLibrary() { - return this.learningLibrary; + return learningLibrary; } - public void setLearningLibrary( - org.lamsfoundation.lams.learningdesign.LearningLibrary learningLibrary) { + public void setLearningLibrary(org.lamsfoundation.lams.learningdesign.LearningLibrary learningLibrary) { this.learningLibrary = learningLibrary; } @@ -509,7 +481,7 @@ * */ public org.lamsfoundation.lams.learningdesign.Activity getParentActivity() { - return this.parentActivity; + return parentActivity; } public void setParentActivity(Activity parentActivity) { @@ -522,11 +494,10 @@ * */ public org.lamsfoundation.lams.learningdesign.LearningDesign getLearningDesign() { - return this.learningDesign; + return learningDesign; } - public void setLearningDesign( - org.lamsfoundation.lams.learningdesign.LearningDesign learningDesign) { + public void setLearningDesign(org.lamsfoundation.lams.learningdesign.LearningDesign learningDesign) { this.learningDesign = learningDesign; } @@ -536,11 +507,10 @@ * */ public org.lamsfoundation.lams.learningdesign.Grouping getGrouping() { - return this.grouping; + return grouping; } - public void setGrouping( - org.lamsfoundation.lams.learningdesign.Grouping grouping) { + public void setGrouping(org.lamsfoundation.lams.learningdesign.Grouping grouping) { this.grouping = grouping; } @@ -550,7 +520,7 @@ * */ public Integer getActivityTypeId() { - return this.activityTypeId; + return activityTypeId; } public void setActivityTypeId(Integer activityTypeId) { @@ -563,106 +533,109 @@ public Boolean getApplyGrouping() { return applyGrouping; } + /** * @param applyGrouping The applyGrouping to set. */ public void setApplyGrouping(Boolean applyGrouping) { this.applyGrouping = applyGrouping; } + /** * @return Returns the groupingSupportType. */ public Integer getGroupingSupportType() { return groupingSupportType; } + /** * @param groupingSupportType The groupingSupportType to set. */ public void setGroupingSupportType(Integer groupingSupportType) { this.groupingSupportType = groupingSupportType; - } - + } + /** * @return Returns the readOnly. */ public Boolean getReadOnly() { return readOnly; } + /** * @param readOnly The readOnly to set. */ public void setReadOnly(Boolean readOnly) { this.readOnly = readOnly; - } + } /** * @return Returns the initialised flag. */ public Boolean isInitialised() { return initialised; } + /** * @param readOnly The readOnly to set. */ public void setInitialised(Boolean initialised) { this.initialised = initialised; - } + } /** * @return Returns the stopAfterActivity flag. */ public Boolean isStopAfterActivity() { return stopAfterActivity; } + /** * @param readOnly The stopAfterActivity to set. */ public void setStopAfterActivity(Boolean stopAfterActivity) { this.stopAfterActivity = stopAfterActivity; - } + } - /** - * @return Returns the inputActivities. - */ - public Set getInputActivities() - { - if(this.inputActivities == null) - this.setInputActivities(new HashSet()); - return inputActivities; - } - /** - * @param InputActivities The InputActivities to set. - */ - public void setInputActivities(Set inputActivities) - { - this.inputActivities = inputActivities; - } + /** + * @return Returns the inputActivities. + */ + public Set getInputActivities() { + if (inputActivities == null) { + this.setInputActivities(new HashSet()); + } + return inputActivities; + } + /** + * @param InputActivities The InputActivities to set. + */ + public void setInputActivities(Set inputActivities) { + this.inputActivities = inputActivities; + } + + @Override public String toString() { - return new ToStringBuilder(this) - .append("activityId", activityId) - .append("activityUIID", activityUIID) - .append("description", description) - .toString(); + return new ToStringBuilder(this).append("activityId", activityId).append("activityUIID", activityUIID).append( + "description", description).toString(); } + @Override public boolean equals(Object other) { - if ((this == other)) + if (this == other) { return true; - if (!(other instanceof Activity)) + } + if (!(other instanceof Activity)) { return false; + } Activity castOther = (Activity) other; - return new EqualsBuilder() - .append(this.getActivityId(),castOther.getActivityId()) - .append(this.getActivityUIID(),castOther.getActivityUIID()) - .isEquals(); + return new EqualsBuilder().append(this.getActivityId(), castOther.getActivityId()).append(this.getActivityUIID(), + castOther.getActivityUIID()).isEquals(); } + @Override public int hashCode() { - return new HashCodeBuilder() - .append(getActivityId()) - .append(getActivityUIID()) - .toHashCode(); + return new HashCodeBuilder().append(getActivityId()).append(getActivityUIID()).toHashCode(); } /** @@ -679,8 +652,8 @@ */ public void setLibraryActivityUiImage(String libraryActivityUiImage) { this.libraryActivityUiImage = libraryActivityUiImage; - } - + } + /** * This function returns the Transition that * STARTS FROM THIS ACTIVITY. In simpler words the @@ -695,12 +668,14 @@ public Transition getTransitionFrom() { return transitionFrom; } + /** * @param transitionFrom The transitionFrom to set. */ public void setTransitionFrom(Transition transitionFrom) { this.transitionFrom = transitionFrom; } + /** * This function returns the Transition that * POINTS TO THIS ACTIVITY and NOT the transition @@ -716,63 +691,74 @@ public Transition getTransitionTo() { return transitionTo; } + /** * @param transitionTo The transitionTo to set. */ public void setTransitionTo(Transition transitionTo) { this.transitionTo = transitionTo; - } + } + public Integer getParentUIID() { return parentUIID; } + public void setParentUIID(Integer parent_ui_id) { - this.parentUIID = parent_ui_id; - } + parentUIID = parent_ui_id; + } + public Activity getLibraryActivity() { return libraryActivity; } + public void setLibraryActivity(Activity libraryActivity) { this.libraryActivity = libraryActivity; } + public String getHelpText() { return helpText; } + public void setHelpText(String helpText) { this.helpText = helpText; } + public Integer getGroupingUIID() { return groupingUIID; } + public void setGroupingUIID(Integer groupingUIID) { this.groupingUIID = groupingUIID; } + public Boolean getRunOffline() { return runOffline; } + public void setRunOffline(Boolean runOffline) { this.runOffline = runOffline; } - - public Integer getActivityCategoryID() - { + + public Integer getActivityCategoryID() { return activityCategoryID; } - public void setActivityCategoryID(Integer activityCategoryID) - { + + public void setActivityCategoryID(Integer activityCategoryID) { this.activityCategoryID = activityCategoryID; } - + public String getLanguageFile() { return languageFile; } + public void setLanguageFile(String languageFile) { this.languageFile = languageFile; } - - //--------------------------------------------------------------------- - // Service Methods - //--------------------------------------------------------------------- - + + //--------------------------------------------------------------------- + // Service Methods + //--------------------------------------------------------------------- + /** * This method that get all tool activities belong to the current activity. * @@ -785,30 +771,28 @@ * * @return the set of all tool activities. */ - public Set getAllToolActivities() - { - SortedSet toolActivities = new TreeSet(new ActivityOrderComparator()); - getToolActivitiesInActivity(toolActivities); - return toolActivities; + public Set getAllToolActivities() { + SortedSet toolActivities = new TreeSet(new ActivityOrderComparator()); + getToolActivitiesInActivity(toolActivities); + return toolActivities; } - + protected void getToolActivitiesInActivity(SortedSet toolActivities) { - + // a simple activity doesn't have any tool activities - + } - + /** * Return the group information for the requested user when he is running * current activity instance, based on the grouping data in the activity. * @param learner the requested user * @return the group that this user belongs to. */ - public Group getGroupFor(User learner) - { + public Group getGroupFor(User learner) { return getGroupFor(learner, this.getGrouping()); } - + /** * Return the group information for the requested user when he is running * current activity instance, based on the given grouping. @@ -820,258 +804,242 @@ * @param learner the requested user * @return the group that this user belongs to. */ - protected Group getGroupFor(User learner, Grouping inGrouping) - { - if(inGrouping==null) - throw new IllegalArgumentException("Exception occured in " + - "getGroupFor, no grouping has been defined"); - - for(Iterator i=inGrouping.getGroups().iterator();i.hasNext();) - { - Group group = (Group)i.next(); - if(inGrouping.isLearnerGroup(group)&&group.hasLearner(learner)) - return group; - } - - return new NullGroup(); + protected Group getGroupFor(User learner, Grouping inGrouping) { + if (inGrouping == null) { + throw new IllegalArgumentException("Exception occured in " + "getGroupFor, no grouping has been defined"); + } + + for (Iterator i = inGrouping.getGroups().iterator(); i.hasNext();) { + Group group = (Group) i.next(); + if (inGrouping.isLearnerGroup(group) && group.hasLearner(learner)) { + return group; + } + } + + return new NullGroup(); } - //--------------------------------------------------------------------- - // Activity Type checking methods - //--------------------------------------------------------------------- + + //--------------------------------------------------------------------- + // Activity Type checking methods + //--------------------------------------------------------------------- /** * Check up whether an activity is tool activity or not. * @return is this activity a tool activity? */ - public boolean isToolActivity() - { - return getActivityTypeId().intValue()==TOOL_ACTIVITY_TYPE; + public boolean isToolActivity() { + return getActivityTypeId().intValue() == Activity.TOOL_ACTIVITY_TYPE; } - + /** * Check up whether an activity is sequence activity or not. * @return is this activity a sequence activity? */ - public boolean isSequenceActivity() - { - return getActivityTypeId().intValue()==SEQUENCE_ACTIVITY_TYPE; + public boolean isSequenceActivity() { + return getActivityTypeId().intValue() == Activity.SEQUENCE_ACTIVITY_TYPE; } - - public boolean isParallelActivity() - { - return getActivityTypeId().intValue()== PARALLEL_ACTIVITY_TYPE; + + public boolean isParallelActivity() { + return getActivityTypeId().intValue() == Activity.PARALLEL_ACTIVITY_TYPE; } - public boolean isOptionsActivity() - { - return getActivityTypeId().intValue()== OPTIONS_ACTIVITY_TYPE || getActivityTypeId().intValue()==OPTIONS_WITH_SEQUENCES_TYPE ; + public boolean isOptionsActivity() { + return getActivityTypeId().intValue() == Activity.OPTIONS_ACTIVITY_TYPE + || getActivityTypeId().intValue() == Activity.OPTIONS_WITH_SEQUENCES_TYPE; } - public boolean isComplexActivity() - { - return getActivityTypeId().intValue()== SEQUENCE_ACTIVITY_TYPE || - getActivityTypeId().intValue()== PARALLEL_ACTIVITY_TYPE || - getActivityTypeId().intValue()== OPTIONS_ACTIVITY_TYPE || - getActivityTypeId().intValue()== OPTIONS_WITH_SEQUENCES_TYPE || - getActivityTypeId().intValue()== CHOSEN_BRANCHING_ACTIVITY_TYPE || - getActivityTypeId().intValue()== GROUP_BRANCHING_ACTIVITY_TYPE || - getActivityTypeId().intValue()== TOOL_BRANCHING_ACTIVITY_TYPE; + public boolean isComplexActivity() { + return getActivityTypeId().intValue() == Activity.SEQUENCE_ACTIVITY_TYPE + || getActivityTypeId().intValue() == Activity.PARALLEL_ACTIVITY_TYPE + || getActivityTypeId().intValue() == Activity.OPTIONS_ACTIVITY_TYPE + || getActivityTypeId().intValue() == Activity.OPTIONS_WITH_SEQUENCES_TYPE + || getActivityTypeId().intValue() == Activity.CHOSEN_BRANCHING_ACTIVITY_TYPE + || getActivityTypeId().intValue() == Activity.GROUP_BRANCHING_ACTIVITY_TYPE + || getActivityTypeId().intValue() == Activity.TOOL_BRANCHING_ACTIVITY_TYPE; } - - public boolean isSystemToolActivity() - { + + public boolean isSystemToolActivity() { return ISystemToolActivity.class.isInstance(this); } - public boolean isGateActivity() - { - return getActivityTypeId().intValue()== SCHEDULE_GATE_ACTIVITY_TYPE || - getActivityTypeId().intValue()== PERMISSION_GATE_ACTIVITY_TYPE || - getActivityTypeId().intValue()== SYNCH_GATE_ACTIVITY_TYPE || - getActivityTypeId().intValue() == SYSTEM_GATE_ACTIVITY_TYPE; + public boolean isGateActivity() { + return getActivityTypeId().intValue() == Activity.SCHEDULE_GATE_ACTIVITY_TYPE + || getActivityTypeId().intValue() == Activity.PERMISSION_GATE_ACTIVITY_TYPE + || getActivityTypeId().intValue() == Activity.SYNCH_GATE_ACTIVITY_TYPE + || getActivityTypeId().intValue() == Activity.SYSTEM_GATE_ACTIVITY_TYPE; } - + /** * Check up whether an activity is synch gate activity or not. * @return is this activity a synch gate activity? */ - public boolean isSynchGate() - { - return getActivityTypeId().intValue() == SYNCH_GATE_ACTIVITY_TYPE; + public boolean isSynchGate() { + return getActivityTypeId().intValue() == Activity.SYNCH_GATE_ACTIVITY_TYPE; } - + /** * Check up whether an activity is permission gate activity or not. * @return is this activity a permission gate activity. */ - public boolean isPermissionGate() - { - return getActivityTypeId().intValue() == PERMISSION_GATE_ACTIVITY_TYPE; + public boolean isPermissionGate() { + return getActivityTypeId().intValue() == Activity.PERMISSION_GATE_ACTIVITY_TYPE; } - + /** * Check up whether an activity is schedule gate activity or not. * @return is this activity a schedule gate activity. */ - public boolean isScheduleGate() - { - return getActivityTypeId().intValue() == SCHEDULE_GATE_ACTIVITY_TYPE; + public boolean isScheduleGate() { + return getActivityTypeId().intValue() == Activity.SCHEDULE_GATE_ACTIVITY_TYPE; } - + + public boolean isConditionGate() { + return getActivityTypeId().intValue() == Activity.CONDITION_GATE_ACTIVITY_TYPE; + } + /** * Check up whether an activity is schedule gate activity or not. * @return is this activity a schedule gate activity. */ - public boolean isSystemGate() - { - return getActivityTypeId().intValue() == SYSTEM_GATE_ACTIVITY_TYPE; + public boolean isSystemGate() { + return getActivityTypeId().intValue() == Activity.SYSTEM_GATE_ACTIVITY_TYPE; } - + /** * /** * Check up whether an activity is grouping activity or not. * @return is this activity a grouping activity */ - public boolean isGroupingActivity() - { - return getActivityTypeId().intValue()== GROUPING_ACTIVITY_TYPE; + public boolean isGroupingActivity() { + return getActivityTypeId().intValue() == Activity.GROUPING_ACTIVITY_TYPE; } - + /** * Check up whether an activity is some sort of branching activity or not * @return is this activity a branching activity */ - public boolean isBranchingActivity() - { - return getActivityTypeId().intValue()== CHOSEN_BRANCHING_ACTIVITY_TYPE || - getActivityTypeId().intValue()== GROUP_BRANCHING_ACTIVITY_TYPE || - getActivityTypeId().intValue()== TOOL_BRANCHING_ACTIVITY_TYPE; + public boolean isBranchingActivity() { + return getActivityTypeId().intValue() == Activity.CHOSEN_BRANCHING_ACTIVITY_TYPE + || getActivityTypeId().intValue() == Activity.GROUP_BRANCHING_ACTIVITY_TYPE + || getActivityTypeId().intValue() == Activity.TOOL_BRANCHING_ACTIVITY_TYPE; } - /** * Check up whether an activity is branching activity based on the monitor choice or not. * @return is this activity a branching activity */ - public boolean isChosenBranchingActivity() - { - return getActivityTypeId().intValue()== CHOSEN_BRANCHING_ACTIVITY_TYPE; + public boolean isChosenBranchingActivity() { + return getActivityTypeId().intValue() == Activity.CHOSEN_BRANCHING_ACTIVITY_TYPE; } /** * Check up whether an activity is branching activity based on an existing group or not. * @return is this activity a branching activity */ - public boolean isGroupBranchingActivity() - { - return getActivityTypeId().intValue()== GROUP_BRANCHING_ACTIVITY_TYPE; + public boolean isGroupBranchingActivity() { + return getActivityTypeId().intValue() == Activity.GROUP_BRANCHING_ACTIVITY_TYPE; } /** * Check up whether an activity is branching activity based on another activity's output or not. * @return is this activity a branching activity */ - public boolean isToolBranchingActivity() - { - return getActivityTypeId().intValue()== TOOL_BRANCHING_ACTIVITY_TYPE; + public boolean isToolBranchingActivity() { + return getActivityTypeId().intValue() == Activity.TOOL_BRANCHING_ACTIVITY_TYPE; } - public boolean isActivityReadOnly() - { + public boolean isActivityReadOnly() { return readOnly.equals(Boolean.TRUE); } - - //--------------------------------------------------------------------- - // Data Transfer object creation methods - //--------------------------------------------------------------------- + + //--------------------------------------------------------------------- + // Data Transfer object creation methods + //--------------------------------------------------------------------- /** * Return the activity dto for progress view. * @return the activity dto. */ - public ProgressActivityDTO getProgressActivityData() - { - return new ProgressActivityDTO(this.activityId); + public ProgressActivityDTO getProgressActivityData() { + return new ProgressActivityDTO(activityId); } - /** Get the authoring DTO for this activity. Overidden by ComplexActivity. */ - public Set getAuthoringActivityDTOSet(ArrayList branchMappings, String languageCode) - { + public Set getAuthoringActivityDTOSet(ArrayList branchMappings, + String languageCode) { Set dtoSet = new TreeSet(new ActivityDTOOrderComparator()); dtoSet.add(new AuthoringActivityDTO(this, branchMappings, languageCode)); return dtoSet; } - - public LibraryActivityDTO getLibraryActivityDTO(String languageCode){ + + public LibraryActivityDTO getLibraryActivityDTO(String languageCode) { return new LibraryActivityDTO(this, languageCode); } - + /** Create a deep copy of the this activity. It should return the same * subclass as the activity being copied. Generally doesn't copy the "link" type * fields like transitions, learning design, etc. * @param uiidOffset - this should be added to UIID fields in any new objects. Used * when importing a design into another design. * @return deep copy of this object */ - public abstract Activity createCopy(int uiidOffset); + public abstract Activity createCopy(int uiidOffset); - protected void copyToNewActivity(Activity newActivity, int uiidOffset ) { + protected void copyToNewActivity(Activity newActivity, int uiidOffset) { - newActivity.setActivityUIID(LearningDesign.addOffset(this.getActivityUIID(),uiidOffset)); - newActivity.setDescription(this.getDescription()); - newActivity.setTitle(this.getTitle()); - newActivity.setHelpText(this.getHelpText()); - newActivity.setXcoord(this.getXcoord()); - newActivity.setYcoord(this.getYcoord()); - newActivity.setActivityTypeId(this.getActivityTypeId()); - - newActivity.setGroupingSupportType(this.getGroupingSupportType()); - newActivity.setApplyGrouping(this.getApplyGrouping()); - newActivity.setActivityCategoryID(this.getActivityCategoryID()); - - newActivity.setGrouping(this.getGrouping()); - newActivity.setGroupingUIID(LearningDesign.addOffset(this.getGroupingUIID(),uiidOffset)); - - newActivity.setDefineLater(this.getDefineLater()); - newActivity.setCreateDateTime(new Date()); - newActivity.setRunOffline(this.getRunOffline()); - newActivity.setLearningLibrary(this.getLearningLibrary()); - newActivity.setLibraryActivity(this.getLibraryActivity()); - newActivity.setLibraryActivityUiImage(this.getLibraryActivityUiImage()); - newActivity.setLanguageFile(this.getLanguageFile()); - - newActivity.setOrderId(this.getOrderId()); - newActivity.setReadOnly(this.getReadOnly()); - newActivity.setStopAfterActivity(this.isStopAfterActivity()); + newActivity.setActivityUIID(LearningDesign.addOffset(this.getActivityUIID(), uiidOffset)); + newActivity.setDescription(this.getDescription()); + newActivity.setTitle(this.getTitle()); + newActivity.setHelpText(this.getHelpText()); + newActivity.setXcoord(this.getXcoord()); + newActivity.setYcoord(this.getYcoord()); + newActivity.setActivityTypeId(this.getActivityTypeId()); - newActivity.setParentActivity(this.getParentActivity()); - newActivity.setParentUIID(LearningDesign.addOffset(this.getParentUIID(), uiidOffset)); + newActivity.setGroupingSupportType(this.getGroupingSupportType()); + newActivity.setApplyGrouping(this.getApplyGrouping()); + newActivity.setActivityCategoryID(this.getActivityCategoryID()); - if ( this.getInputActivities()!=null && this.getInputActivities().size() > 0 ) { - newActivity.setInputActivities(new HashSet()); - newActivity.getInputActivities().addAll(this.getInputActivities()); - } - } - - - // --------------------------------------------------------------------- - // Data Validation methods - //--------------------------------------------------------------------- - - /** + newActivity.setGrouping(this.getGrouping()); + newActivity.setGroupingUIID(LearningDesign.addOffset(this.getGroupingUIID(), uiidOffset)); + + newActivity.setDefineLater(this.getDefineLater()); + newActivity.setCreateDateTime(new Date()); + newActivity.setRunOffline(this.getRunOffline()); + newActivity.setLearningLibrary(this.getLearningLibrary()); + newActivity.setLibraryActivity(this.getLibraryActivity()); + newActivity.setLibraryActivityUiImage(this.getLibraryActivityUiImage()); + newActivity.setLanguageFile(this.getLanguageFile()); + + newActivity.setOrderId(this.getOrderId()); + newActivity.setReadOnly(this.getReadOnly()); + newActivity.setStopAfterActivity(this.isStopAfterActivity()); + + newActivity.setParentActivity(this.getParentActivity()); + newActivity.setParentUIID(LearningDesign.addOffset(this.getParentUIID(), uiidOffset)); + + if (this.getInputActivities() != null && this.getInputActivities().size() > 0) { + newActivity.setInputActivities(new HashSet()); + newActivity.getInputActivities().addAll(this.getInputActivities()); + } + } + + // --------------------------------------------------------------------- + // Data Validation methods + //--------------------------------------------------------------------- + + /** * Validate activity * */ - public Vector validateActivity(MessageService messageService) { - return null; + public Vector validateActivity(MessageService messageService) { + return null; } /** Get the input activity UIIDs in a format suitable for Flash. See also getToolInputActivityID */ public ArrayList getInputActivityUIIDs() { ArrayList list = new ArrayList(); - if ( getInputActivities() != null && getInputActivities().size() > 0 ) { + if (getInputActivities() != null && getInputActivities().size() > 0) { Iterator iter = getInputActivities().iterator(); - while ( iter.hasNext() ) { + while (iter.hasNext()) { Activity inputAct = (Activity) iter.next(); list.add(inputAct.getActivityUIID()); } @@ -1084,46 +1052,50 @@ * activities, but at present we only support one. See also getInputActivityUIIDs. */ public Integer getToolInputActivityUIID() { - if ( getInputActivities() != null ) { + if (getInputActivities() != null) { Iterator iter = getInputActivities().iterator(); - if ( iter.hasNext() ) { - return ((Activity)iter.next()).getActivityUIID(); + if (iter.hasNext()) { + return ((Activity) iter.next()).getActivityUIID(); } } return null; } - - /** - * Is this activity inside a branch? If so, return turn branch activity (ie the sequence, not the - * branching activity. Returns null if not in a branch. - */ - public Activity getParentBranch() { - if ( isSequenceActivity() && getParentActivity() != null && getParentActivity().isBranchingActivity()) { - // I'm a branch, so start the process off with my parent! - return getParentBranch(getParentActivity(), new HashSet()); - } else { - return getParentBranch(this, new HashSet()); - } - } - private Activity getParentBranch(Activity activity, Set processedActivityIds) { - - Activity parent = activity.getParentActivity(); + /** + * Is this activity inside a branch? If so, return turn branch activity (ie the sequence, not the + * branching activity. Returns null if not in a branch. + */ + public Activity getParentBranch() { + if (isSequenceActivity() && getParentActivity() != null && getParentActivity().isBranchingActivity()) { + // I'm a branch, so start the process off with my parent! + return getParentBranch(getParentActivity(), new HashSet()); + } + else { + return getParentBranch(this, new HashSet()); + } + } - if ( parent == null ) - return null; - - if ( parent.isBranchingActivity() ) - return activity; - - // double check that we haven't already processed this activity. Should never happen but if it does it - // would cause an infinite loop. - if ( processedActivityIds.contains(activity.getActivityId())) - return null; + private Activity getParentBranch(Activity activity, Set processedActivityIds) { - processedActivityIds.add(activity.getActivityId()); - - return getParentBranch(parent, processedActivityIds); - } + Activity parent = activity.getParentActivity(); + if (parent == null) { + return null; + } + + if (parent.isBranchingActivity()) { + return activity; + } + + // double check that we haven't already processed this activity. Should never happen but if it does it + // would cause an infinite loop. + if (processedActivityIds.contains(activity.getActivityId())) { + return null; + } + + processedActivityIds.add(activity.getActivityId()); + + return getParentBranch(parent, processedActivityIds); + } + } \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/BranchActivityEntry.java =================================================================== diff -u -r039707d1e936b6be92842a45e442d37db9886513 -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/BranchActivityEntry.java (.../BranchActivityEntry.java) (revision 039707d1e936b6be92842a45e442d37db9886513) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/BranchActivityEntry.java (.../BranchActivityEntry.java) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -52,10 +52,10 @@ /** persistent field */ protected SequenceActivity branchSequenceActivity; /** persistent field */ - protected BranchingActivity branchingActivity; - /** persistent field */ - private Group group; - /** persistent field */ + protected Activity branchingActivity; + /** persistent field */ + private Group group; + /** persistent field */ private BranchCondition condition; /** @@ -67,31 +67,30 @@ /** * Constructor for group based linking */ - public BranchActivityEntry(Long entryId, Integer entryUIID, SequenceActivity branchSequenceActivity, - BranchingActivity branchingActivity, Group group) { - + public BranchActivityEntry(Long entryId, Integer entryUIID, SequenceActivity branchSequenceActivity, + Activity branchingActivity, Group group) { + this.entryId = entryId; this.entryUIID = entryUIID; this.branchSequenceActivity = branchSequenceActivity; this.branchingActivity = branchingActivity; this.group = group; - this.condition = null; + condition = null; } - + /** * Constructor for tool output based linking */ - public BranchActivityEntry(Long entryId, Integer entryUIID, SequenceActivity branchSequenceActivity, - BranchingActivity branchingActivity, BranchCondition condition) { - + public BranchActivityEntry(Long entryId, Integer entryUIID, SequenceActivity branchSequenceActivity, + Activity branchingActivity, BranchCondition condition) { + this.entryId = entryId; this.entryUIID = entryUIID; this.branchSequenceActivity = branchSequenceActivity; this.branchingActivity = branchingActivity; - this.group = null; + group = null; this.condition = condition; } - /** * @hibernate.id @@ -101,7 +100,7 @@ * */ public Long getEntryId() { - return this.entryId; + return entryId; } public void setEntryId(Long id) { @@ -112,7 +111,7 @@ * @hibernate.property column="entry_ui_id" length="11" */ public Integer getEntryUIID() { - return this.entryUIID; + return entryUIID; } public void setEntryUIID(Integer entryUIID) { @@ -126,11 +125,11 @@ * */ public org.lamsfoundation.lams.learningdesign.SequenceActivity getBranchSequenceActivity() { - return this.branchSequenceActivity; + return branchSequenceActivity; } public void setBranchSequenceActivity(org.lamsfoundation.lams.learningdesign.SequenceActivity branchSequenceActivity) { - this.branchSequenceActivity = branchSequenceActivity; + this.branchSequenceActivity = branchSequenceActivity; } /** @@ -139,28 +138,28 @@ * @hibernate.column name="branch_activity_id" * */ - public org.lamsfoundation.lams.learningdesign.BranchingActivity getBranchingActivity() { - return this.branchingActivity; + public org.lamsfoundation.lams.learningdesign.Activity getBranchingActivity() { + return branchingActivity; } - public void setBranchingActivity(org.lamsfoundation.lams.learningdesign.BranchingActivity branchingActivity) { - this.branchingActivity = branchingActivity; + public void setBranchingActivity(Activity branchingActivity) { + this.branchingActivity = branchingActivity; } - /** - * @hibernate.many-to-one - * not-null="true" - * @hibernate.column name="group_id" - * - */ - public org.lamsfoundation.lams.learningdesign.Group getGroup() { - return this.group; - } + /** + * @hibernate.many-to-one + * not-null="true" + * @hibernate.column name="group_id" + * + */ + public org.lamsfoundation.lams.learningdesign.Group getGroup() { + return group; + } - public void setGroup(org.lamsfoundation.lams.learningdesign.Group group) { - this.group = group; - } - + public void setGroup(org.lamsfoundation.lams.learningdesign.Group group) { + this.group = group; + } + /** * Used for tool output based branching only * @@ -177,61 +176,57 @@ this.condition = condition; } - public BranchActivityEntryDTO getBranchActivityEntryDTO(Integer toolActivityUIID) { BranchActivityEntryDTO entryDTO = null; - if ( getCondition() != null ) { + if (getCondition() != null) { ToolOutputBranchActivityEntryDTO toolEntryDTO = new ToolOutputBranchActivityEntryDTO(); toolEntryDTO.setCondition(getCondition().getBranchConditionDTO(toolActivityUIID)); entryDTO = toolEntryDTO; - } else { + } + else { entryDTO = new BranchActivityEntryDTO(); } entryDTO.setEntryID(getEntryId()); entryDTO.setEntryUIID(getEntryUIID()); - if ( getGroup() != null ) { + if (getGroup() != null) { entryDTO.setGroupUIID(getGroup().getGroupUIID()); } entryDTO.setSequenceActivityUIID(getBranchSequenceActivity().getActivityUIID()); entryDTO.setBranchingActivityUIID(getBranchingActivity().getActivityUIID()); return entryDTO; } + @Override public boolean equals(Object other) { - if ( (this == other ) ) return true; - if ( !(other instanceof BranchActivityEntry) ) return false; - BranchActivityEntry castOther = (BranchActivityEntry) other; - return new EqualsBuilder() - .append(this.getEntryId(), castOther.getEntryId()) - .append(this.getEntryUIID(), castOther.getEntryUIID()) - .isEquals(); + if (this == other) { + return true; + } + if (!(other instanceof BranchActivityEntry)) { + return false; + } + BranchActivityEntry castOther = (BranchActivityEntry) other; + return new EqualsBuilder().append(this.getEntryId(), castOther.getEntryId()).append(this.getEntryUIID(), + castOther.getEntryUIID()).isEquals(); } + @Override public int hashCode() { - return new HashCodeBuilder() - .append(getEntryId()) - .append(getEntryUIID()) - .toHashCode(); + return new HashCodeBuilder().append(getEntryId()).append(getEntryUIID()).toHashCode(); } public int compareTo(Object other) { BranchActivityEntry castOther = (BranchActivityEntry) other; - return new CompareToBuilder() - .append(this.getEntryId(), castOther.getEntryId()) - .append(this.getEntryUIID(), castOther.getEntryUIID()) - .toComparison(); + return new CompareToBuilder().append(this.getEntryId(), castOther.getEntryId()).append(this.getEntryUIID(), + castOther.getEntryUIID()).toComparison(); } - - public String toString() { - return new ToStringBuilder(this) - .append("entryId", getEntryId()) - .append("entryUIID", getEntryUIID()) - .append("group", getGroup() != null ? getGroup().getGroupId().toString() : "") - .append("sequence activity", getBranchSequenceActivity() != null ? getBranchSequenceActivity().getActivityId().toString() : "") - .toString(); - } + @Override + public String toString() { + return new ToStringBuilder(this).append("entryId", getEntryId()).append("entryUIID", getEntryUIID()).append("group", + getGroup() != null ? getGroup().getGroupId().toString() : "").append("sequence activity", + getBranchSequenceActivity() != null ? getBranchSequenceActivity().getActivityId().toString() : "").toString(); + } } \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/BranchCondition.java =================================================================== diff -u -r09c0d59c407945da73dfb89b33ec63f63fe18c77 -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/BranchCondition.java (.../BranchCondition.java) (revision 09c0d59c407945da73dfb89b33ec63f63fe18c77) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/BranchCondition.java (.../BranchCondition.java) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -23,8 +23,6 @@ /* $Id$ */ package org.lamsfoundation.lams.learningdesign; -import java.util.HashSet; - import org.apache.commons.lang.builder.CompareToBuilder; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; @@ -34,7 +32,6 @@ import org.lamsfoundation.lams.tool.ToolOutput; import org.lamsfoundation.lams.tool.ToolOutputValue; - /** * The ToolOutputBranchActivityEntries record the branch selection details for tool output based branching. During * authoring, the tool will have supplied a ToolOutputDefinition object and this will have been used to configure @@ -48,324 +45,335 @@ private Long conditionId; private Integer conditionUIID; - private Integer orderId; - private String name; - private String displayName; - private String type; - private String startValue; - private String endValue; - private String exactMatchValue; - - /** default constructor */ - public BranchCondition() { - } + private Integer orderId; + private String name; + private String displayName; + private String type; + private String startValue; + private String endValue; + private String exactMatchValue; - /** full constructor */ - public BranchCondition(Long conditionId, Integer conditionUIID, Integer orderId, - String name, String displayName, String type, String startValue, String endValue, String exactMatchValue) { - this.conditionId = conditionId; - this.conditionUIID = conditionUIID; - this.orderId = orderId; - this.name = name; - this.displayName = displayName; - this.type = type; - this.startValue = startValue; - this.endValue = endValue; - this.exactMatchValue = exactMatchValue; - } + /** default constructor */ + public BranchCondition() { + } - /** Create a condition object based on an existing DTO object. Copies all fields including the id field */ - public BranchCondition(BranchConditionDTO conditionDTO) { - this(conditionDTO.getConditionId(), - conditionDTO.getConditionUIID(), - conditionDTO.getOrderID(), - conditionDTO.getName(), - conditionDTO.getDisplayName(), - conditionDTO.getType(), - conditionDTO.getStartValue(), - conditionDTO.getEndValue(), - conditionDTO.getExactMatchValue()); - } - - /** - * @hibernate.id - * generator-class="native" - * type="java.lang.Long" - * column="condition_id" - * - */ + /** full constructor */ + public BranchCondition(Long conditionId, Integer conditionUIID, Integer orderId, String name, String displayName, + String type, String startValue, String endValue, String exactMatchValue) { + this.conditionId = conditionId; + this.conditionUIID = conditionUIID; + this.orderId = orderId; + this.name = name; + this.displayName = displayName; + this.type = type; + this.startValue = startValue; + this.endValue = endValue; + this.exactMatchValue = exactMatchValue; + } + + /** Create a condition object based on an existing DTO object. Copies all fields including the id field */ + public BranchCondition(BranchConditionDTO conditionDTO) { + this(conditionDTO.getConditionId(), conditionDTO.getConditionUIID(), conditionDTO.getOrderID(), conditionDTO.getName(), + conditionDTO.getDisplayName(), conditionDTO.getType(), conditionDTO.getStartValue(), conditionDTO.getEndValue(), + conditionDTO.getExactMatchValue()); + } + + /** + * @hibernate.id + * generator-class="native" + * type="java.lang.Long" + * column="condition_id" + * + */ public Long getConditionId() { return conditionId; } + public void setConditionId(Long conditionId) { this.conditionId = conditionId; } - + /** * @hibernate.property column="condition_ui_id" length="11" * */ public Integer getConditionUIID() { return conditionUIID; } + public void setConditionUIID(Integer conditionUIID) { this.conditionUIID = conditionUIID; } - + /** * @hibernate.property column="order_id" length="11" */ public Integer getOrderId() { return orderId; } + public void setOrderId(Integer orderId) { this.orderId = orderId; } + /** * @hibernate.property column="name" length="255" */ public String getName() { return name; } + public void setName(String name) { this.name = name; } + /** * The display name is a name shown to the user so they can link a condition to a branch. * @hibernate.property column="display_name" length="255" */ public String getDisplayName() { return displayName; } + public void setDisplayName(String displayName) { this.displayName = displayName; } + /** * @hibernate.property column="type" length="255" */ public String getType() { return type; } + public void setType(String type) { this.type = type; } + /** * @hibernate.property column="start_value" length="255" */ public String getStartValue() { return startValue; } + public void setStartValue(String startValue) { this.startValue = startValue; } + /** * @hibernate.property column="end_value" length="255" */ public String getEndValue() { return endValue; } + public void setEndValue(String endValue) { this.endValue = endValue; } + /** * @hibernate.property column="exact_match_value" length="255" */ public String getExactMatchValue() { return exactMatchValue; } + public void setExactMatchValue(String exactMatchValue) { this.exactMatchValue = exactMatchValue; - } + } public BranchConditionDTO getBranchConditionDTO(Integer toolActivityUIID) { return new BranchConditionDTO(this, toolActivityUIID); } - public String toString() { - return new ToStringBuilder(this) - .append("conditionId", conditionId) - .append("conditionUIID", conditionUIID) - .append("orderId", orderId) - .append("name", name) - .append("displayName", displayName) - .append("type", type) - .append("startValue", startValue) - .append("endValue", endValue) - .append("exactMatchValue", exactMatchValue) - .toString(); - } - - /** Allocate this condition to the given branch, in a branching activity. This creates the BranchActivityEntry record and adds it - * to the branchActivities set. EntryUIID will only be populated if this is called from authoring - */ - public BranchActivityEntry allocateBranchToCondition(Integer entryUIID, SequenceActivity branch, BranchingActivity branchingActivity) { - BranchActivityEntry entry = new BranchActivityEntry(null, entryUIID, branch, (BranchingActivity) branchingActivity, this); + @Override + public String toString() { + return new ToStringBuilder(this).append("conditionId", conditionId).append("conditionUIID", conditionUIID).append( + "orderId", orderId).append("name", name).append("displayName", displayName).append("type", type).append( + "startValue", startValue).append("endValue", endValue).append("exactMatchValue", exactMatchValue).toString(); + } + + /** Allocate this condition to the given branch, in a branching activity. This creates the BranchActivityEntry record and adds it + * to the branchActivities set. EntryUIID will only be populated if this is called from authoring + */ + public BranchActivityEntry allocateBranchToCondition(Integer entryUIID, SequenceActivity branch, Activity branchingActivity) { + BranchActivityEntry entry = new BranchActivityEntry(null, entryUIID, branch, branchingActivity, this); return entry; - } - - /** Create a new BranchCondition based on itself, leaving conditionId as null */ - public BranchCondition clone(int uiidOffset) { - Integer newConditionUIID = LearningDesign.addOffset(conditionUIID, uiidOffset); - return new BranchCondition(null, newConditionUIID, orderId, name, displayName, type, startValue, endValue, exactMatchValue); - } + } + /** Create a new BranchCondition based on itself, leaving conditionId as null */ + public BranchCondition clone(int uiidOffset) { + Integer newConditionUIID = LearningDesign.addOffset(conditionUIID, uiidOffset); + return new BranchCondition(null, newConditionUIID, orderId, name, displayName, type, startValue, endValue, + exactMatchValue); + } + public int compareTo(Object arg0) { BranchCondition other = (BranchCondition) arg0; - return new CompareToBuilder() - .append(orderId, other.getOrderId()) - .append(conditionId, other.getConditionId()) - .append(name, other.getName()) - .append(conditionUIID, other.getConditionUIID()) - .toComparison(); + return new CompareToBuilder().append(orderId, other.getOrderId()).append(conditionId, other.getConditionId()).append( + name, other.getName()).append(conditionUIID, other.getConditionUIID()).toComparison(); } + @Override public int hashCode() { - return new HashCodeBuilder() - .append(orderId) - .append(conditionId) - .append(name) - .append(conditionUIID) - .toHashCode(); + return new HashCodeBuilder().append(orderId).append(conditionId).append(name).append(conditionUIID).toHashCode(); } + @Override public boolean equals(Object arg0) { BranchCondition other = (BranchCondition) arg0; - return new EqualsBuilder() - .append(orderId, other.getOrderId()) - .append(conditionId, other.getConditionId()) - .append(name, other.getName()) - .append(conditionUIID, other.getConditionUIID()) - .isEquals(); + return new EqualsBuilder().append(orderId, other.getOrderId()).append(conditionId, other.getConditionId()).append(name, + other.getName()).append(conditionUIID, other.getConditionUIID()).isEquals(); } - + /** Is this condition met? */ public boolean isMet(ToolOutput output) { - if ( output != null ) { - if ( exactMatchValue != null ) { + if (output != null) { + if (exactMatchValue != null) { return exactMatchMet(output.getValue()); - } else if ( startValue != null || endValue != null) { + } + else if (startValue != null || endValue != null) { return inRange(output.getValue()); } } return false; } - + public boolean exactMatchMet(ToolOutputValue outputValue) { - if ( "OUTPUT_LONG".equals(type) ) { + if ("OUTPUT_LONG".equals(type)) { Long exactMatchObj = exactMatchValue != null ? convertToLong(exactMatchValue) : null; Long actualValue = outputValue.getLong(); - return ( actualValue != null && actualValue.equals(exactMatchObj)); - } else if ( "OUTPUT_DOUBLE".equals(type) ) { + return actualValue != null && actualValue.equals(exactMatchObj); + } + else if ("OUTPUT_DOUBLE".equals(type)) { Double exactMatchObj = exactMatchValue != null ? Double.parseDouble(exactMatchValue) : null; Double actualValue = outputValue.getDouble(); - return ( actualValue != null && actualValue.equals(exactMatchObj)); - } else if ( "OUTPUT_BOOLEAN".equals(type) ) { + return actualValue != null && actualValue.equals(exactMatchObj); + } + else if ("OUTPUT_BOOLEAN".equals(type)) { Boolean exactMatchObj = exactMatchValue != null ? Boolean.parseBoolean(exactMatchValue) : null; Boolean actualValue = outputValue.getBoolean(); - return ( actualValue != null && actualValue.equals(exactMatchObj)); - } else if ( "OUTPUT_STRING".equals(type) ) { + return actualValue != null && actualValue.equals(exactMatchObj); + } + else if ("OUTPUT_STRING".equals(type)) { Double actualValue = outputValue.getDouble(); - return ( actualValue != null && actualValue.equals(exactMatchValue)); - } - return false; + return actualValue != null && actualValue.equals(exactMatchValue); + } + return false; } - + public boolean inRange(ToolOutputValue outputValue) { - if ( "OUTPUT_LONG".equals(type) ) { + if ("OUTPUT_LONG".equals(type)) { Long startValueLong = startValue != null ? convertToLong(startValue) : null; Long endValueLong = endValue != null ? convertToLong(endValue) : null; Long actualValue = outputValue.getLong(); - return ( actualValue != null && - ( startValueLong==null || actualValue.compareTo(startValueLong) >= 0 ) && - ( endValueLong==null || actualValue.compareTo(endValueLong) <= 0 )) ; - } else if ( "OUTPUT_DOUBLE".equals(type) ) { + return actualValue != null && (startValueLong == null || actualValue.compareTo(startValueLong) >= 0) + && (endValueLong == null || actualValue.compareTo(endValueLong) <= 0); + } + else if ("OUTPUT_DOUBLE".equals(type)) { Double startValueDouble = startValue != null ? Double.parseDouble(startValue) : null; Double endValueDouble = endValue != null ? Double.parseDouble(endValue) : null; Double actualValue = outputValue.getDouble(); - return ( actualValue != null && - ( startValueDouble==null || actualValue.compareTo(startValueDouble) >= 0 ) && - ( endValueDouble==null || actualValue.compareTo(endValueDouble) <= 0 )); - } else if ( "OUTPUT_BOOLEAN".equals(type) ) { + return actualValue != null && (startValueDouble == null || actualValue.compareTo(startValueDouble) >= 0) + && (endValueDouble == null || actualValue.compareTo(endValueDouble) <= 0); + } + else if ("OUTPUT_BOOLEAN".equals(type)) { // this is a nonsense, but we'll code it just in case. What order is a boolean? True greater than false? Boolean startValueBoolean = startValue != null ? Boolean.parseBoolean(startValue) : null; Boolean endValueBoolean = endValue != null ? Boolean.parseBoolean(endValue) : null; Boolean actualValue = outputValue.getBoolean(); - return ( actualValue != null && - ( startValueBoolean==null || actualValue.compareTo(startValueBoolean) >= 0 ) && - ( endValueBoolean==null || actualValue.compareTo(endValueBoolean) <= 0 )); - - } else if ( "OUTPUT_STRING".equals(type) ) { + return actualValue != null && (startValueBoolean == null || actualValue.compareTo(startValueBoolean) >= 0) + && (endValueBoolean == null || actualValue.compareTo(endValueBoolean) <= 0); + + } + else if ("OUTPUT_STRING".equals(type)) { String actualValue = outputValue.getString(); - return ( actualValue != null && - ( startValue==null || actualValue.compareTo(startValue) >= 0 ) && - ( endValue==null || actualValue.compareTo(endValue) <= 0 )); - } + return actualValue != null && (startValue == null || actualValue.compareTo(startValue) >= 0) + && (endValue == null || actualValue.compareTo(endValue) <= 0); + } return false; } /** The data may have come in from WDDX and have .0 on the end of Longs, so eliminate that */ - private Long convertToLong( String textValue ) { - if ( textValue.length() == 0 ) + private Long convertToLong(String textValue) { + if (textValue.length() == 0) { return null; + } int posPeriod = textValue.indexOf('.'); - if ( posPeriod > 0 ) { - textValue = textValue.substring(0,posPeriod); + if (posPeriod > 0) { + textValue = textValue.substring(0, posPeriod); } - return new Long (textValue); + return new Long(textValue); } /** All conditions must have either (a) an exact match value or (b) a start value and no end value * or (c) start value and an end value and the end value must be >= start value. */ protected boolean isValid() { - if ( exactMatchValue != null ) { + if (exactMatchValue != null) { try { - if ( getTypedValue(exactMatchValue) != null ) + if (getTypedValue(exactMatchValue) != null) { return true; - } catch ( Exception e ) { } - log.error("Condition contains an unconvertible value for exactMatchValue. Type is "+type+" value "+exactMatchValue); + } + } + catch (Exception e) { + } + BranchCondition.log.error("Condition contains an unconvertible value for exactMatchValue. Type is " + type + + " value " + exactMatchValue); return false; - } else { + } + else { Comparable typedStartValue = null; Comparable typedEndValue = null; try { - if ( startValue != null ) + if (startValue != null) { typedStartValue = getTypedValue(startValue); - } catch ( Exception e ) { - log.error("Condition contains an unconvertible value for startValue. Type is "+type+" value "+startValue); + } + } + catch (Exception e) { + BranchCondition.log.error("Condition contains an unconvertible value for startValue. Type is " + type + " value " + + startValue); return false; } - + try { - if ( endValue != null ) + if (endValue != null) { typedEndValue = getTypedValue(endValue); - } catch ( Exception e ) { - log.error("Condition contains an unconvertible value for endValue. Type is "+type+" value "+endValue); - return false; + } } + catch (Exception e) { + BranchCondition.log.error("Condition contains an unconvertible value for endValue. Type is " + type + " value " + + endValue); + return false; + } - if ( typedStartValue == null && typedEndValue != null ) + if (typedStartValue == null && typedEndValue != null) { return true; - - else if ( typedEndValue == null || typedEndValue.compareTo(typedStartValue) >= 0 ) { + } + else if (typedEndValue == null || typedEndValue.compareTo(typedStartValue) >= 0) { return true; } } return false; } - - private Comparable getTypedValue( String untypedValue ) { - if ( "OUTPUT_LONG".equals(type) ) { + + private Comparable getTypedValue(String untypedValue) { + if ("OUTPUT_LONG".equals(type)) { return convertToLong(untypedValue); - } else if ( "OUTPUT_DOUBLE".equals(type) ) { + } + else if ("OUTPUT_DOUBLE".equals(type)) { return Double.parseDouble(untypedValue); - } else if ( "OUTPUT_BOOLEAN".equals(type) ) { + } + else if ("OUTPUT_BOOLEAN".equals(type)) { return Boolean.parseBoolean(untypedValue); - } else if ( "OUTPUT_STRING".equals(type) ) { + } + else if ("OUTPUT_STRING".equals(type)) { return untypedValue; - } else { + } + else { return null; } } Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/ConditionGateActivity.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/ConditionGateActivity.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/ConditionGateActivity.java (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -0,0 +1,144 @@ +/**************************************************************** + * 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 + * **************************************************************** + */ +/* $$Id$$ */ +package org.lamsfoundation.lams.learningdesign; + +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; +import java.util.Vector; + +import org.apache.commons.lang.builder.ToStringBuilder; +import org.lamsfoundation.lams.learningdesign.dto.ValidationErrorDTO; +import org.lamsfoundation.lams.learningdesign.strategy.ConditionGateActivityStrategy; +import org.lamsfoundation.lams.tool.SystemTool; +import org.lamsfoundation.lams.util.MessageService; + +/** + * Gate activity that is based on tools' output and conditions. + * @author Marcin Cieslak + * @hibernate.class + */ +public class ConditionGateActivity extends GateActivity implements Serializable { + /** + * List of the branch entries which open the gate. + */ + private Set openingGateBranchEntries = new HashSet(); + + /** full constructor */ + public ConditionGateActivity(Long activityId, Integer id, String description, String title, Integer xcoord, Integer ycoord, + Integer orderId, Boolean defineLater, java.util.Date createDateTime, LearningLibrary learningLibrary, + Activity parentActivity, Activity libraryActivity, Integer parentUIID, LearningDesign learningDesign, + Grouping grouping, Integer activityTypeId, Transition transitionTo, Transition transitionFrom, String languageFile, + Boolean stopAfterActivity, Set inputActivities, Integer gateActivityLevelId, Set waitingLearners, SystemTool sysTool) { + super(activityId, id, description, title, xcoord, ycoord, orderId, defineLater, createDateTime, learningLibrary, + parentActivity, libraryActivity, parentUIID, learningDesign, grouping, activityTypeId, transitionTo, + transitionFrom, languageFile, stopAfterActivity, inputActivities, gateActivityLevelId, waitingLearners, sysTool); + super.simpleActivityStrategy = new ConditionGateActivityStrategy(this); + } + + /** default constructor */ + public ConditionGateActivity() { + super.simpleActivityStrategy = new ConditionGateActivityStrategy(this); + } + + /** minimal constructor */ + public ConditionGateActivity(Long activityId, Boolean defineLater, java.util.Date createDateTime, + org.lamsfoundation.lams.learningdesign.LearningLibrary learningLibrary, + org.lamsfoundation.lams.learningdesign.Activity parentActivity, + org.lamsfoundation.lams.learningdesign.LearningDesign learningDesign, + org.lamsfoundation.lams.learningdesign.Grouping grouping, Integer activityTypeId, Transition transitionTo, + Transition transitionFrom, Integer gateActivityLevelId, Set waitingLearners) { + super(activityId, defineLater, createDateTime, learningLibrary, parentActivity, learningDesign, grouping, activityTypeId, + transitionTo, transitionFrom, gateActivityLevelId, waitingLearners); + super.simpleActivityStrategy = new ConditionGateActivityStrategy(this); + } + + /** + * Makes a copy of the PermissionGateActivity for authoring, preview and monitoring enviornment + * @return PermissionGateActivity Returns a deep-copy of the originalActivity + */ + @Override + public Activity createCopy(int uiidOffset) { + ConditionGateActivity newConditionGateActivity = new ConditionGateActivity(); + copyToNewActivity(newConditionGateActivity, uiidOffset); + newConditionGateActivity.setGateOpen(new Boolean(false)); + newConditionGateActivity.setGateActivityLevelId(this.getGateActivityLevelId()); + return newConditionGateActivity; + + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("activityId", getActivityId()).toString(); + } + + /** + * @see org.lamsfoundation.lams.util.Nullable#isNull() + */ + public boolean isNull() { + return false; + } + + public Set getOpeningGateBranchEntries() { + return openingGateBranchEntries; + } + + public void setOpeningGateBranchEntries(Set openingGateConditions) { + openingGateBranchEntries = openingGateConditions; + } + + @Override + public Vector validateActivity(MessageService messageService) { + Vector listOfValidationErrors = new Vector(); + + if (getInputActivities() == null || getInputActivities().size() == 0) { + listOfValidationErrors.add(new ValidationErrorDTO(ValidationErrorDTO.CONDITION_GATE_ACTVITY_TOOLINPUT_ERROR_CODE, + messageService.getMessage(ValidationErrorDTO.CONDITION_GATE_ACTVITY_TOOLINPUT), this.getActivityUIID())); + } + + boolean conditionsExist = false; + if (getOpeningGateBranchEntries() != null) { + for (BranchActivityEntry entry : getOpeningGateBranchEntries()) { + BranchCondition condition = entry.getCondition(); + if (condition == null) { + listOfValidationErrors.add(new ValidationErrorDTO(ValidationErrorDTO.BRANCH_CONDITION_INVALID_ERROR_CODE, + messageService.getMessage(ValidationErrorDTO.BRANCH_CONDITION_INVALID), this.getActivityUIID())); + } + else { + conditionsExist = true; + if (!condition.isValid()) { + listOfValidationErrors.add(new ValidationErrorDTO(ValidationErrorDTO.BRANCH_CONDITION_INVALID_ERROR_CODE, + messageService.getMessage(ValidationErrorDTO.BRANCH_CONDITION_INVALID), this.getActivityUIID())); + } + } + } + } + + if (!conditionsExist) { + listOfValidationErrors.add(new ValidationErrorDTO(ValidationErrorDTO.CONDITION_GATE_ACTVITY_CONDITION_ERROR_CODE, + messageService.getMessage(ValidationErrorDTO.CONDITION_GATE_ACTVITY_CONDITION), this.getActivityUIID())); + } + return listOfValidationErrors; + } +} \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/ContributionTypes.java =================================================================== diff -u -ra7351da17f548464a76295a73e9cc17450a6ff39 -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/ContributionTypes.java (.../ContributionTypes.java) (revision a7351da17f548464a76295a73e9cc17450a6ff39) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/ContributionTypes.java (.../ContributionTypes.java) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -26,17 +26,17 @@ public class ContributionTypes { - //--------------------------------------------------------------------- - // Class level constants - Contribution types - //--------------------------------------------------------------------- - public static final Integer MODERATION = new Integer(1); - public static final Integer DEFINE_LATER = new Integer(2); - public static final Integer PERMISSION_GATE = new Integer(3); - public static final Integer SYNC_GATE = new Integer(4); - public static final Integer SCHEDULE_GATE = new Integer(5); - public static final Integer CHOSEN_GROUPING = new Integer(6); - public static final Integer CONTRIBUTION = new Integer(7); - public static final Integer SYSTEM_GATE = new Integer(8); - public static final Integer CHOSEN_BRANCHING = new Integer(9); - + //--------------------------------------------------------------------- + // Class level constants - Contribution types + //--------------------------------------------------------------------- + public static final Integer MODERATION = new Integer(1); + public static final Integer DEFINE_LATER = new Integer(2); + public static final Integer PERMISSION_GATE = new Integer(3); + public static final Integer SYNC_GATE = new Integer(4); + public static final Integer SCHEDULE_GATE = new Integer(5); + public static final Integer CHOSEN_GROUPING = new Integer(6); + public static final Integer CONTRIBUTION = new Integer(7); + public static final Integer SYSTEM_GATE = new Integer(8); + public static final Integer CHOSEN_BRANCHING = new Integer(9); + public static final Integer CONDITION_GATE = new Integer(10); } Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/dao/hibernate/ActivityDAO.java =================================================================== diff -u -rac99dd8a79daaa42b1e6cdbe9b1a5fd197107b83 -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/dao/hibernate/ActivityDAO.java (.../ActivityDAO.java) (revision ac99dd8a79daaa42b1e6cdbe9b1a5fd197107b83) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/dao/hibernate/ActivityDAO.java (.../ActivityDAO.java) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -29,6 +29,7 @@ import org.lamsfoundation.lams.dao.hibernate.BaseDAO; import org.lamsfoundation.lams.learningdesign.Activity; import org.lamsfoundation.lams.learningdesign.ChosenBranchingActivity; +import org.lamsfoundation.lams.learningdesign.ConditionGateActivity; import org.lamsfoundation.lams.learningdesign.GroupBranchingActivity; import org.lamsfoundation.lams.learningdesign.GroupingActivity; import org.lamsfoundation.lams.learningdesign.LearningDesign; @@ -37,9 +38,9 @@ import org.lamsfoundation.lams.learningdesign.ParallelActivity; import org.lamsfoundation.lams.learningdesign.PermissionGateActivity; import org.lamsfoundation.lams.learningdesign.ScheduleGateActivity; -import org.lamsfoundation.lams.learningdesign.SystemGateActivity; import org.lamsfoundation.lams.learningdesign.SequenceActivity; import org.lamsfoundation.lams.learningdesign.SynchGateActivity; +import org.lamsfoundation.lams.learningdesign.SystemGateActivity; import org.lamsfoundation.lams.learningdesign.ToolActivity; import org.lamsfoundation.lams.learningdesign.ToolBranchingActivity; import org.lamsfoundation.lams.learningdesign.dao.IActivityDAO; @@ -49,72 +50,72 @@ * @author Manpreet Minhas */ public class ActivityDAO extends BaseDAO implements IActivityDAO { - - private static final String TABLENAME ="lams_learning_activity"; - - private static final String FIND_BY_PARENT = "from " + TABLENAME +" in class " + Activity.class.getName() + " where parent_activity_id=?" ; - - private static final String FIND_BY_LEARNING_DESIGN_ID = "from " + TABLENAME + - " in class " + Activity.class.getName() + - " where learning_design_id=?" ; - private static final String FIND_GROUPINGACTIVITY_TYPE_BY_LEARNING_DESIGN_ID = "from " + TABLENAME + - " in class " + GroupingActivity.class.getName() + - " where learning_design_id=?"; - private static final String FIND_BY_UI_ID ="from " + TABLENAME + - " in class " + Activity.class.getName() + - " where activity_ui_id=?" + " AND " + " learning_design_id=?" ; - private static final String FIND_BY_LIBRARY_ID = "from " + TABLENAME + - " in class " + Activity.class.getName() + - " where learning_library_id=?" + " AND learning_design_id IS NULL"; - + private static final String TABLENAME = "lams_learning_activity"; + + private static final String FIND_BY_PARENT = "from " + ActivityDAO.TABLENAME + " in class " + Activity.class.getName() + + " where parent_activity_id=?"; + + private static final String FIND_BY_LEARNING_DESIGN_ID = "from " + ActivityDAO.TABLENAME + " in class " + + Activity.class.getName() + " where learning_design_id=?"; + private static final String FIND_GROUPINGACTIVITY_TYPE_BY_LEARNING_DESIGN_ID = "from " + ActivityDAO.TABLENAME + " in class " + + GroupingActivity.class.getName() + " where learning_design_id=?"; + private static final String FIND_BY_UI_ID = "from " + ActivityDAO.TABLENAME + " in class " + Activity.class.getName() + + " where activity_ui_id=?" + " AND " + " learning_design_id=?"; + private static final String FIND_BY_LIBRARY_ID = "from " + ActivityDAO.TABLENAME + " in class " + Activity.class.getName() + + " where learning_library_id=?" + " AND learning_design_id IS NULL"; + /* * @see org.lamsfoundation.lams.learningdesign.dao.interfaces.IActivityDAO#getActivityById(java.lang.Long) */ public Activity getActivityByActivityId(Long activityId) { - Activity act = (Activity) super.find(Activity.class,activityId); - return getNonCGLibActivity(act); + Activity act = (Activity) super.find(Activity.class, activityId); + return getNonCGLibActivity(act); } /** we must return the real activity, not a Hibernate proxy. So relook * it up. This should be quick as it should be in the cache. */ private Activity getNonCGLibActivity(Activity act) { - if ( act != null ) { + if (act != null) { Integer activityType = act.getActivityTypeId(); Long activityId = act.getActivityId(); - if ( activityType != null ) { - switch ( activityType.intValue() ) { - case Activity.TOOL_ACTIVITY_TYPE: - return getActivityByActivityId(activityId,ToolActivity.class); - case Activity.GROUPING_ACTIVITY_TYPE: - return getActivityByActivityId(activityId,GroupingActivity.class); - case Activity.SYNCH_GATE_ACTIVITY_TYPE: - return getActivityByActivityId(activityId,SynchGateActivity.class); - case Activity.SCHEDULE_GATE_ACTIVITY_TYPE: - return getActivityByActivityId(activityId,ScheduleGateActivity.class); - case Activity.PERMISSION_GATE_ACTIVITY_TYPE: - return getActivityByActivityId(activityId,PermissionGateActivity.class); - case Activity.PARALLEL_ACTIVITY_TYPE: - return getActivityByActivityId(activityId,ParallelActivity.class); - case Activity.OPTIONS_ACTIVITY_TYPE: - return getActivityByActivityId(activityId,OptionsActivity.class); - case Activity.SEQUENCE_ACTIVITY_TYPE: - return getActivityByActivityId(activityId,SequenceActivity.class); - case Activity.SYSTEM_GATE_ACTIVITY_TYPE: - return getActivityByActivityId(activityId,SystemGateActivity.class); - case Activity.CHOSEN_BRANCHING_ACTIVITY_TYPE: - return getActivityByActivityId(activityId,ChosenBranchingActivity.class); - case Activity.GROUP_BRANCHING_ACTIVITY_TYPE: - return getActivityByActivityId(activityId,GroupBranchingActivity.class); - case Activity.TOOL_BRANCHING_ACTIVITY_TYPE: - return getActivityByActivityId(activityId,ToolBranchingActivity.class); - case Activity.OPTIONS_WITH_SEQUENCES_TYPE: - return getActivityByActivityId(activityId,OptionsWithSequencesActivity.class); - default: break; + if (activityType != null) { + switch (activityType.intValue()) { + case Activity.TOOL_ACTIVITY_TYPE: + return getActivityByActivityId(activityId, ToolActivity.class); + case Activity.GROUPING_ACTIVITY_TYPE: + return getActivityByActivityId(activityId, GroupingActivity.class); + case Activity.SYNCH_GATE_ACTIVITY_TYPE: + return getActivityByActivityId(activityId, SynchGateActivity.class); + case Activity.SCHEDULE_GATE_ACTIVITY_TYPE: + return getActivityByActivityId(activityId, ScheduleGateActivity.class); + case Activity.PERMISSION_GATE_ACTIVITY_TYPE: + return getActivityByActivityId(activityId, PermissionGateActivity.class); + case Activity.CONDITION_GATE_ACTIVITY_TYPE: + return getActivityByActivityId(activityId, ConditionGateActivity.class); + case Activity.PARALLEL_ACTIVITY_TYPE: + return getActivityByActivityId(activityId, ParallelActivity.class); + case Activity.OPTIONS_ACTIVITY_TYPE: + return getActivityByActivityId(activityId, OptionsActivity.class); + case Activity.SEQUENCE_ACTIVITY_TYPE: + return getActivityByActivityId(activityId, SequenceActivity.class); + case Activity.SYSTEM_GATE_ACTIVITY_TYPE: + return getActivityByActivityId(activityId, SystemGateActivity.class); + case Activity.CHOSEN_BRANCHING_ACTIVITY_TYPE: + return getActivityByActivityId(activityId, ChosenBranchingActivity.class); + case Activity.GROUP_BRANCHING_ACTIVITY_TYPE: + return getActivityByActivityId(activityId, GroupBranchingActivity.class); + case Activity.TOOL_BRANCHING_ACTIVITY_TYPE: + return getActivityByActivityId(activityId, ToolBranchingActivity.class); + case Activity.OPTIONS_WITH_SEQUENCES_TYPE: + return getActivityByActivityId(activityId, OptionsWithSequencesActivity.class); + default: + break; } } - throw new DataRetrievalFailureException("Unable to get activity as the activity type is unknown or missing. Activity type is "+activityType); + throw new DataRetrievalFailureException( + "Unable to get activity as the activity type is unknown or missing. Activity type is " + activityType); } return null; } @@ -123,51 +124,51 @@ * @see org.lamsfoundation.lams.learningdesign.dao.interfaces.IActivityDAO#getActivityById(java.lang.Long) */ public Activity getActivityByActivityId(Long activityId, Class clasz) { - return (Activity) super.find(clasz,activityId); + return (Activity) super.find(clasz, activityId); } /* * @see org.lamsfoundation.lams.learningdesign.dao.interfaces.IActivityDAO#getActivityByParentActivityId(java.lang.Long) */ public List getActivitiesByParentActivityId(Long parentActivityId) { - List list = this.getHibernateTemplate().find(FIND_BY_PARENT,parentActivityId); + List list = this.getHibernateTemplate().find(ActivityDAO.FIND_BY_PARENT, parentActivityId); return list; } /* * @see org.lamsfoundation.lams.learningdesign.dao.interfaces.IActivityDAO#getAllActivities() */ public List getAllActivities() { - return super.findAll(Activity.class); + return super.findAll(Activity.class); } /* * @see org.lamsfoundation.lams.learningdesign.dao.interfaces.IActivityDAO#getActivitiesByLearningDesignId(java.lang.Long) */ public List getActivitiesByLearningDesignId(Long learningDesignId) { - return this.getHibernateTemplate().find(FIND_BY_LEARNING_DESIGN_ID,learningDesignId); + return this.getHibernateTemplate().find(ActivityDAO.FIND_BY_LEARNING_DESIGN_ID, learningDesignId); } /** * Get all the grouping activities for this learning design. * @param learningDesignId The id of the learningDesign * @return List of GroupingActivity objects - */ + */ public List getGroupingActivitiesByLearningDesignId(Long learningDesignId) { - return this.getHibernateTemplate().find(FIND_GROUPINGACTIVITY_TYPE_BY_LEARNING_DESIGN_ID,learningDesignId); - } + return this.getHibernateTemplate().find(ActivityDAO.FIND_GROUPINGACTIVITY_TYPE_BY_LEARNING_DESIGN_ID, learningDesignId); + } /* * @see org.lamsfoundation.lams.learningdesign.dao.interfaces.IActivityDAO#insertActivity(org.lamsfoundation.lams.learningdesign.Activity) */ public void insertActivity(Activity activity) { this.getHibernateTemplate().save(activity); } + public void insertOptActivity(OptionsActivity activity) { this.getHibernateTemplate().save(activity); } - /* * @see org.lamsfoundation.lams.learningdesign.dao.interfaces.IActivityDAO#updateActivity(org.lamsfoundation.lams.learningdesign.Activity) */ @@ -186,27 +187,27 @@ * @see org.lamsfoundation.lams.learningdesign.dao.IActivityDAO#getActivityByUIID(java.lang.Integer, org.lamsfoundation.lams.learningdesign.LearningDesign) */ public Activity getActivityByUIID(Integer id, LearningDesign design) { - if ( id != null && design != null ) { + if (id != null && design != null) { Long designID = design.getLearningDesignId(); - Query query = this.getSession().createQuery(FIND_BY_UI_ID); - query.setInteger(0,id.intValue()); - query.setLong(1,designID.longValue()); + Query query = this.getSession().createQuery(ActivityDAO.FIND_BY_UI_ID); + query.setInteger(0, id.intValue()); + query.setLong(1, designID.longValue()); return getNonCGLibActivity((Activity) query.uniqueResult()); } return null; } + /** * @see org.lamsfoundation.lams.learningdesign.dao.IActivityDAO#getActivitiesByLibraryID(java.lang.Long) */ - public List getActivitiesByLibraryID(Long libraryID){ - List list = this.getHibernateTemplate().find(FIND_BY_LIBRARY_ID,libraryID); + public List getActivitiesByLibraryID(Long libraryID) { + List list = this.getHibernateTemplate().find(ActivityDAO.FIND_BY_LIBRARY_ID, libraryID); return list; } - + /** @see org.lamsfoundation.lams.learningdesign.dao.IActivityDAO#getTemplateActivityByLibraryID(java.lang.Long) */ - public Activity getTemplateActivityByLibraryID(Long libraryID) - { - List list = this.getHibernateTemplate().find(FIND_BY_LIBRARY_ID,libraryID); - return (list!= null && list.size()!=0) ? (Activity)list.get(0): null; + public Activity getTemplateActivityByLibraryID(Long libraryID) { + List list = this.getHibernateTemplate().find(ActivityDAO.FIND_BY_LIBRARY_ID, libraryID); + return list != null && list.size() != 0 ? (Activity) list.get(0) : null; } } Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/dto/AuthoringActivityDTO.java =================================================================== diff -u -r40fd34ca6bc3ae5e5466f8c9a17047427f9cd43b -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/dto/AuthoringActivityDTO.java (.../AuthoringActivityDTO.java) (revision 40fd34ca6bc3ae5e5466f8c9a17047427f9cd43b) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/dto/AuthoringActivityDTO.java (.../AuthoringActivityDTO.java) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -31,6 +31,7 @@ import org.lamsfoundation.lams.learningdesign.BranchActivityEntry; import org.lamsfoundation.lams.learningdesign.BranchingActivity; import org.lamsfoundation.lams.learningdesign.ComplexActivity; +import org.lamsfoundation.lams.learningdesign.ConditionGateActivity; import org.lamsfoundation.lams.learningdesign.GateActivity; import org.lamsfoundation.lams.learningdesign.Grouping; import org.lamsfoundation.lams.learningdesign.GroupingActivity; @@ -44,16 +45,16 @@ import org.lamsfoundation.lams.learningdesign.ToolActivity; import org.lamsfoundation.lams.util.HelpUtil; import org.lamsfoundation.lams.util.wddx.WDDXTAGS; + /** * @author Manpreet Minhas */ -public class AuthoringActivityDTO extends BaseDTO{ - +public class AuthoringActivityDTO extends BaseDTO { /***************************************************************************** * Attributes *****************************************************************************/ - + /** identifier field */ private Long activityID; @@ -66,41 +67,41 @@ /** Title of the activity*/ private String activityTitle; - + /** Help text for the activity*/ private String helpText; /** Help URL for the activity */ private String helpURL; - + /** UI specific attribute indicating the * position of the activity*/ private Integer xCoord; /** UI specific attribute indicating the * position of the activity*/ private Integer yCoord; - + /** The activity that acts as a container/parent for * this activity. Normally would be one of the * complex activities which have child activities * defined inside them. */ private Long parentActivityID; - + /** the activity_ui_id of the parent activity */ private Integer parentUIID; - + /** The type of activity */ private Integer activityTypeID; - + /** The Grouping that applies to this activity*/ private Long groupingID; - + /** The grouping_ui_id of the Grouping that * applies that to this activity * */ private Integer groupingUIID; - + /** Indicates the order in which the activities * appear inside complex activities. Starts from * 0, 1 and so on.*/ @@ -109,46 +110,46 @@ /** Indicates whether the content of this activity * would be defined later in the monitoring environment or not.*/ private Boolean defineLater; - + /** The LearningDesign to which this activity belongs*/ private Long learningDesignID; - + /** The LearningLibrary of which this activity is a part*/ private Long learningLibraryID; - + /** Date this activity was created */ private Date createDateTime; - + /** Indicates whether this activity is available offline*/ private Boolean runOffline; /** Maximum number of activities to be attempted */ private Integer maxOptions; - + /** Minimum number of activities to be attempted */ private Integer minOptions; - + /** Instructions for OptionsActivity*/ private String optionsInstructions; - + /** The tool_signature of the activity */ private String toolSignature; - + /** The tool_id of the activity */ private Long toolID; - + /** The tool_content_id of the tool */ private Long toolContentID; - + /** The tool's display name */ private String toolDisplayName; - + /** The tool's version */ private String toolVersion; /** The url of the tool's authoring screen. */ private String authoringURL; - + /** The url of the tool's monitoring screen. */ private String monitoringURL; @@ -163,33 +164,33 @@ /** The category of activity */ private Integer activityCategoryID; - + private Integer gateActivityLevelID; - + private Boolean gateOpen; - + private Long gateStartTimeOffset; - + private Long gateEndTimeOffset; - + private Date gateStartDateTime; - + private Date gateEndDateTime; - + private Boolean applyGrouping; - + private Integer groupingSupportType; - + private Integer groupingType; - + /** The image that represents the icon of this * activity in the UI*/ private String libraryActivityUIImage; - + private Long createGroupingID; - + private Integer createGroupingUIID; - + private Boolean readOnly; /** An activity is initialised if it is ready to be used in lesson ie the tool content @@ -202,23 +203,22 @@ * final activity of a design does not necessarily have this set - the progress engine will just * stop when it runs out of transitions to follow. */ private Boolean stopAfterActivity; - + /* Server will send Grouping objects as an array (in the Groupings array) * rather than being part of the GroupingActivity. For the groupings array * see LearningDesignDTO. */ //private GroupingDTO groupingDTO; - - + /** Single Library can have one or more activities * defined inside it. This field indicates which * activity is this.*/ private Long libraryActivityID; - + /** Name of the file (including the package) that contains the text strings for * this activity. e.g. org.lamsfoundation.lams.tool.sbmt.SbmtResources.properties. */ private String languageFile; - + /** List of the UIIDs of the activities that are input activities for this activity. This array * will only contain integers. We can't type the get method as that breaks WDDX. */ private ArrayList inputActivities; @@ -229,829 +229,1000 @@ /** Used by a sequence activity to determine the start of the transition based sequence and used by tool * based branching to determine the default branch. */ private Integer defaultActivityUIID; - + private Integer startXCoord; private Integer startYCoord; private Integer endXCoord; private Integer endYCoord; - + /** Used for I18N the URLS. Does not need to be sent to clients, so no getter exists. */ - private String languageCode; - + private String languageCode; + private Boolean supportsOutputs; - + /** * This string identifies the tool as a tool adapter tool, null otherwise */ private String extLmsId; - + /***************************************************************************** * Constructors *****************************************************************************/ - public AuthoringActivityDTO(Activity activity, ArrayList branchMappings, String languageCode){ - this.activityID = activity.getActivityId(); - this.activityUIID = activity.getActivityUIID(); - this.description = activity.getDescription(); - this.activityTitle = activity.getTitle(); - this.helpText = activity.getHelpText(); - this.xCoord = activity.getXcoord(); - this.yCoord = activity.getYcoord(); - this.parentActivityID = activity.getParentActivity()!=null? - activity.getParentActivity().getActivityId(): - null; - this.parentUIID = activity.getParentUIID(); - this.activityTypeID = activity.getActivityTypeId(); - - this.groupingID = activity.getGrouping()!=null? - activity.getGrouping().getGroupingId(): - null; - - this.groupingUIID = activity.getGroupingUIID(); - this.orderID = activity.getOrderId(); - this.defineLater = activity.getDefineLater(); - this.learningDesignID = activity.getLearningDesign()!=null? - activity.getLearningDesign().getLearningDesignId(): - null; - this.learningLibraryID = activity.getLearningLibrary()!=null? - activity.getLearningLibrary().getLearningLibraryId(): - null; - this.createDateTime = activity.getCreateDateTime(); - this.runOffline = activity.getRunOffline(); - this.languageFile = activity.getLanguageFile(); - this.activityCategoryID = activity.getActivityCategoryID(); - this.libraryActivityUIImage = activity.getLibraryActivityUiImage(); - this.libraryActivityID = activity.getLibraryActivity()!=null? - activity.getLibraryActivity().getActivityId(): - null; - this.applyGrouping = activity.getApplyGrouping(); - this.groupingSupportType = activity.getGroupingSupportType(); - this.readOnly = activity.getReadOnly(); - this.initialised = activity.isInitialised(); - this.stopAfterActivity = activity.isStopAfterActivity(); - - this.inputActivities = activity.getInputActivityUIIDs(); - this.toolActivityUIID = activity.getToolInputActivityUIID(); + public AuthoringActivityDTO(Activity activity, ArrayList branchMappings, String languageCode) { + activityID = activity.getActivityId(); + activityUIID = activity.getActivityUIID(); + description = activity.getDescription(); + activityTitle = activity.getTitle(); + helpText = activity.getHelpText(); + xCoord = activity.getXcoord(); + yCoord = activity.getYcoord(); + parentActivityID = activity.getParentActivity() != null ? activity.getParentActivity().getActivityId() : null; + parentUIID = activity.getParentUIID(); + activityTypeID = activity.getActivityTypeId(); + groupingID = activity.getGrouping() != null ? activity.getGrouping().getGroupingId() : null; + + groupingUIID = activity.getGroupingUIID(); + orderID = activity.getOrderId(); + defineLater = activity.getDefineLater(); + learningDesignID = activity.getLearningDesign() != null ? activity.getLearningDesign().getLearningDesignId() : null; + learningLibraryID = activity.getLearningLibrary() != null ? activity.getLearningLibrary().getLearningLibraryId() : null; + createDateTime = activity.getCreateDateTime(); + runOffline = activity.getRunOffline(); + languageFile = activity.getLanguageFile(); + activityCategoryID = activity.getActivityCategoryID(); + libraryActivityUIImage = activity.getLibraryActivityUiImage(); + libraryActivityID = activity.getLibraryActivity() != null ? activity.getLibraryActivity().getActivityId() : null; + applyGrouping = activity.getApplyGrouping(); + groupingSupportType = activity.getGroupingSupportType(); + readOnly = activity.getReadOnly(); + initialised = activity.isInitialised(); + stopAfterActivity = activity.isStopAfterActivity(); + + inputActivities = activity.getInputActivityUIIDs(); + toolActivityUIID = activity.getToolInputActivityUIID(); + this.languageCode = languageCode; - + processActivityType(activity, branchMappings); } - - - private void processActivityType(Activity activity, ArrayList branchMappings){ - if(activity.isGroupingActivity()) - addGroupingActivityAttributes((GroupingActivity)activity); - else if(activity.isToolActivity()) - addToolActivityAttributes((ToolActivity)activity); - else if(activity.isGateActivity()) - addGateActivityAttributes(activity); - else - addComplexActivityAttributes(activity, branchMappings); + private void processActivityType(Activity activity, ArrayList branchMappings) { + if (activity.isGroupingActivity()) { + addGroupingActivityAttributes((GroupingActivity) activity); + } + else if (activity.isToolActivity()) { + addToolActivityAttributes((ToolActivity) activity); + } + else if (activity.isGateActivity()) { + addGateActivityAttributes(activity); + } + else { + addComplexActivityAttributes(activity, branchMappings); + } } - private void addComplexActivityAttributes(Activity activity, ArrayList branchMappings){ + + private void addComplexActivityAttributes(Activity activity, ArrayList branchMappings) { ComplexActivity complex = (ComplexActivity) activity; - if ( complex.getDefaultActivity() != null ) { + if (complex.getDefaultActivity() != null) { defaultActivityUIID = complex.getDefaultActivity().getActivityUIID(); } - - if(activity.isOptionsActivity()) - addOptionsActivityAttributes((OptionsActivity)activity); - else if (activity.isParallelActivity()) - addParallelActivityAttributes((ParallelActivity)activity); - else if(activity.isBranchingActivity()) - addBranchingActivityAttributes((BranchingActivity)activity); - else - addSequenceActivityAttributes((SequenceActivity)activity, branchMappings); - + + if (activity.isOptionsActivity()) { + addOptionsActivityAttributes((OptionsActivity) activity); + } + else if (activity.isParallelActivity()) { + addParallelActivityAttributes((ParallelActivity) activity); + } + else if (activity.isBranchingActivity()) { + addBranchingActivityAttributes((BranchingActivity) activity); + } + else { + addSequenceActivityAttributes((SequenceActivity) activity, branchMappings); + } + } - private void addGroupingActivityAttributes(GroupingActivity groupingActivity){ + + private void addGroupingActivityAttributes(GroupingActivity groupingActivity) { Grouping grouping = groupingActivity.getCreateGrouping(); - + //this.groupingDTO = grouping.getGroupingDTO(); - this.createGroupingID = grouping.getGroupingId(); - this.createGroupingUIID = grouping.getGroupingUIID(); + createGroupingID = grouping.getGroupingId(); + createGroupingUIID = grouping.getGroupingUIID(); //this.groupingType = grouping.getGroupingTypeId(); - this.adminURL = groupingActivity.getSystemTool().getAdminUrl(); + adminURL = groupingActivity.getSystemTool().getAdminUrl(); } - private void addOptionsActivityAttributes(OptionsActivity optionsActivity){ - this.maxOptions = optionsActivity.getMaxNumberOfOptions(); - this.minOptions = optionsActivity.getMinNumberOfOptions(); - this.optionsInstructions = optionsActivity.getOptionsInstructions(); + + private void addOptionsActivityAttributes(OptionsActivity optionsActivity) { + maxOptions = optionsActivity.getMaxNumberOfOptions(); + minOptions = optionsActivity.getMinNumberOfOptions(); + optionsInstructions = optionsActivity.getOptionsInstructions(); } - private void addParallelActivityAttributes(ParallelActivity activity){ + + private void addParallelActivityAttributes(ParallelActivity activity) { } - private void addBranchingActivityAttributes(BranchingActivity activity){ - this.startXCoord = activity.getStartXcoord(); - this.startYCoord = activity.getStartYcoord(); - this.endXCoord = activity.getEndXcoord(); - this.endYCoord = activity.getEndYcoord(); + + private void addBranchingActivityAttributes(BranchingActivity activity) { + startXCoord = activity.getStartXcoord(); + startYCoord = activity.getStartYcoord(); + endXCoord = activity.getEndXcoord(); + endYCoord = activity.getEndYcoord(); } - private void addSequenceActivityAttributes(SequenceActivity activity, ArrayList branchMappings){ - + + private void addSequenceActivityAttributes(SequenceActivity activity, ArrayList branchMappings) { + Activity parentActivity = activity.getParentActivity(); Integer toolActivityUIID = parentActivity != null ? parentActivity.getToolInputActivityUIID() : null; Iterator iter = activity.getBranchEntries().iterator(); - while ( iter.hasNext() ) { + while (iter.hasNext()) { BranchActivityEntry ba = (BranchActivityEntry) iter.next(); branchMappings.add(ba.getBranchActivityEntryDTO(toolActivityUIID)); } } - - private void addToolActivityAttributes(ToolActivity toolActivity){ - this.toolContentID = toolActivity.getToolContentId(); - this.toolID = toolActivity.getTool().getToolId(); - this.toolSignature = toolActivity.getTool().getToolSignature(); - this.authoringURL = toolActivity.getTool().getAuthorUrl(); - this.monitoringURL = toolActivity.getTool().getMonitorUrl(); - this.contributeURL = toolActivity.getTool().getContributeUrl(); - this.moderationURL = toolActivity.getTool().getModerationUrl(); - this.adminURL = toolActivity.getTool().getAdminUrl(); - this.toolDisplayName = toolActivity.getTool().getToolDisplayName(); - this.toolVersion = toolActivity.getTool().getToolVersion(); - this.supportsOutputs = toolActivity.getTool().getSupportsOutputs(); - this.extLmsId = toolActivity.getTool().getExtLmsId(); - this.helpURL = HelpUtil.constructToolURL(toolActivity.getTool().getHelpUrl(), toolSignature, "", languageCode); + private void addToolActivityAttributes(ToolActivity toolActivity) { + toolContentID = toolActivity.getToolContentId(); + toolID = toolActivity.getTool().getToolId(); + toolSignature = toolActivity.getTool().getToolSignature(); + authoringURL = toolActivity.getTool().getAuthorUrl(); + monitoringURL = toolActivity.getTool().getMonitorUrl(); + contributeURL = toolActivity.getTool().getContributeUrl(); + moderationURL = toolActivity.getTool().getModerationUrl(); + adminURL = toolActivity.getTool().getAdminUrl(); + toolDisplayName = toolActivity.getTool().getToolDisplayName(); + toolVersion = toolActivity.getTool().getToolVersion(); + supportsOutputs = toolActivity.getTool().getSupportsOutputs(); + extLmsId = toolActivity.getTool().getExtLmsId(); + helpURL = HelpUtil.constructToolURL(toolActivity.getTool().getHelpUrl(), toolSignature, "", languageCode); + } - private void addGateActivityAttributes(Object activity){ - if(activity instanceof SynchGateActivity) - addSynchGateActivityAttributes((SynchGateActivity)activity); - else if (activity instanceof PermissionGateActivity) - addPermissionGateActivityAttributes((PermissionGateActivity)activity); - else if(activity instanceof SystemGateActivity) - addSystemGateActivityAttributes((SystemGateActivity)activity); - else - addScheduleGateActivityAttributes((ScheduleGateActivity)activity); - GateActivity gateActivity = (GateActivity)activity ; - this.gateActivityLevelID = gateActivity.getGateActivityLevelId(); - this.gateOpen = gateActivity.getGateOpen(); - this.adminURL = gateActivity.getSystemTool().getAdminUrl(); - + + private void addGateActivityAttributes(Object activity) { + if (activity instanceof SynchGateActivity) { + addSynchGateActivityAttributes((SynchGateActivity) activity); + } + else if (activity instanceof PermissionGateActivity) { + addPermissionGateActivityAttributes((PermissionGateActivity) activity); + } + else if (activity instanceof ConditionGateActivity) { + addConditionGateActivityAttributes((ConditionGateActivity) activity); + } + else if (activity instanceof SystemGateActivity) { + addSystemGateActivityAttributes((SystemGateActivity) activity); + } + else { + addScheduleGateActivityAttributes((ScheduleGateActivity) activity); + } + GateActivity gateActivity = (GateActivity) activity; + gateActivityLevelID = gateActivity.getGateActivityLevelId(); + gateOpen = gateActivity.getGateOpen(); + adminURL = gateActivity.getSystemTool().getAdminUrl(); + } - private void addSynchGateActivityAttributes(SynchGateActivity activity){ + + private void addConditionGateActivityAttributes(ConditionGateActivity activity) { } - private void addPermissionGateActivityAttributes(PermissionGateActivity activity){ + + private void addSynchGateActivityAttributes(SynchGateActivity activity) { } - private void addSystemGateActivityAttributes(SystemGateActivity activity){ + + private void addPermissionGateActivityAttributes(PermissionGateActivity activity) { } - private void addScheduleGateActivityAttributes(ScheduleGateActivity activity){ - this.gateStartDateTime = activity.getGateStartDateTime(); - this.gateStartTimeOffset = activity.getGateStartTimeOffset(); - this.gateEndDateTime = activity.getGateEndDateTime(); - this.gateEndTimeOffset = activity.getGateEndTimeOffset(); + + private void addSystemGateActivityAttributes(SystemGateActivity activity) { } - + + private void addScheduleGateActivityAttributes(ScheduleGateActivity activity) { + gateStartDateTime = activity.getGateStartDateTime(); + gateStartTimeOffset = activity.getGateStartTimeOffset(); + gateEndDateTime = activity.getGateEndDateTime(); + gateEndTimeOffset = activity.getGateEndTimeOffset(); + } + /***************************************************************************** * Getters *****************************************************************************/ - + /** * @return Returns the activityCategoryID. */ public Integer getActivityCategoryID() { return activityCategoryID; } + /** * @return Returns the activityID. */ public Long getActivityID() { return activityID; } + /** * @return Returns the activityTypeID. */ public Integer getActivityTypeID() { return activityTypeID; } + /** * @return Returns the activityUIID. */ public Integer getActivityUIID() { return activityUIID; } + /** * @return Returns the createDateTime. */ public Date getCreateDateTime() { return createDateTime; } + /** * @return Returns the createGroupingID. */ public Long getCreateGroupingID() { return createGroupingID; } + /** * @return Returns the createGroupingUIID. */ public Integer getCreateGroupingUIID() { return createGroupingUIID; } + /** * @return Returns the defineLater. */ public Boolean getDefineLater() { return defineLater; } + /** * @return Returns the description. */ public String getDescription() { return description; } + /** * @return Returns the gateActivityLevelID. */ public Integer getGateActivityLevelID() { return gateActivityLevelID; } + /** * @return Returns the gateEndDateTime. */ public Date getGateEndDateTime() { return gateEndDateTime; } + /** * @return Returns the gateEndTimeOffset. */ public Long getGateEndTimeOffset() { return gateEndTimeOffset; } + /** * @return Returns the gateOpen. */ public Boolean getGateOpen() { return gateOpen; } + /** * @return Returns the gateStartDateTime. */ public Date getGateStartDateTime() { return gateStartDateTime; } + /** * @return Returns the gateStartTimeOffset. */ public Long getGateStartTimeOffset() { return gateStartTimeOffset; } + /** * @return Returns the groupingID. */ public Long getGroupingID() { return groupingID; } + /** * @return Returns the groupingUIID. */ public Integer getGroupingUIID() { return groupingUIID; } + /** * @return Returns the helpText. */ public String getHelpText() { return helpText; } + /** * @return Returns the learningDesignID. */ public Long getLearningDesignID() { return learningDesignID; } + /** * @return Returns the learningLibraryID. */ public Long getLearningLibraryID() { return learningLibraryID; } + /** * @return Returns the libraryActivityID. */ public Long getLibraryActivityID() { return libraryActivityID; } + /** * @return Returns the libraryActivityUiImage. */ public String getLibraryActivityUIImage() { return libraryActivityUIImage; } + /** * @return Returns the maxOptions. */ public Integer getMaxOptions() { return maxOptions; } + /** * @return Returns the minOptions. */ public Integer getMinOptions() { return minOptions; } + /** * @return Returns the optionsInstructions. */ public String getOptionsInstructions() { return optionsInstructions; } + /** * @return Returns the orderID. */ public Integer getOrderID() { return orderID; } + /** * @return Returns the parentActivityID. */ public Long getParentActivityID() { return parentActivityID; } + /** * @return Returns the parentUIID. */ public Integer getParentUIID() { return parentUIID; } + /** * @return Returns the runOffline. */ public Boolean getRunOffline() { return runOffline; } + /** * @return Returns the title. */ public String getActivityTitle() { return activityTitle; } + /** * @return Returns the toolContentID. */ public Long getToolContentID() { return toolContentID; } + /** * @return Returns the toolID. */ public Long getToolID() { return toolID; } + /** * @return Returns the xcoord. */ public Integer getxCoord() { return xCoord; } + /** * @return Returns the ycoord. */ public Integer getyCoord() { return yCoord; - } + } + /** Get the authoring url related to this tool */ public String getAuthoringURL() { return authoringURL; } + /** * @return Returns the readOnly. */ public Boolean getReadOnly() { return readOnly; } + /** * Name of the file (including the package) that contains the text strings for * this activity. e.g. org.lamsfoundation.lams.tool.sbmt.SbmtResources.properties. */ public String getLanguageFile() { return languageFile; } + /** Get the tool's display name */ public String getToolDisplayName() { return toolDisplayName; } + /** Get the contribution url related to this tool */ public String getContributeURL() { return contributeURL; } + /** Get the monitoring url related to this tool */ public String getMonitoringURL() { return monitoringURL; } + public String getModerationURL() { return moderationURL; } - public String getHelpURL(){ + + public String getHelpURL() { return helpURL; } + public String getToolSignature() { return toolSignature; } + public String getToolVersion() { return toolVersion; } + public Boolean getInitialised() { return initialised; } + public Boolean getStopAfterActivity() { return stopAfterActivity; } + /** * @return Returns the applyGrouping. */ public Boolean getApplyGrouping() { return applyGrouping; } + /** * @return Returns the groupingSupportType. */ public Integer getGroupingSupportType() { return groupingSupportType; } + /** * @return Returns the groupingType. */ public Integer getGroupingType() { return groupingType; } + /** Get the UI ID of the first activity within a sequence activity or default branch in tool based branching */ public Integer getDefaultActivityUIID() { return defaultActivityUIID; } + /** * @return Returns the xcoord of the end hub for a branching activity */ public Integer getEndXCoord() { return endXCoord; } + /** * @return Returns the tcoord of the end hub for a branching activity */ public Integer getEndYCoord() { return endYCoord; } + /** * @return Returns the xcoord of the start hub for a branching activity */ public Integer getStartXCoord() { return startXCoord; } + /** * @return Returns the ycoord of the start hub for a branching activity */ public Integer getStartYCoord() { return startYCoord; } + /************************************************* * Setters ************************************************/ /** * @param activityCategoryID The activityCategoryID to set. */ public void setActivityCategoryID(Integer activityCategoryID) { - if(!activityCategoryID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) + if (!activityCategoryID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) { this.activityCategoryID = activityCategoryID; + } } + /** * @param activityID The activityID to set. */ public void setActivityID(Long activityId) { - if(!activityId.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) - this.activityID = activityId; + if (!activityId.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) { + activityID = activityId; + } } + /** * @param activityTypeID The activityTypeID to set. */ public void setActivityTypeID(Integer activityTypeId) { - if(!activityTypeId.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) - this.activityTypeID = activityTypeId; + if (!activityTypeId.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) { + activityTypeID = activityTypeId; + } } /** * @param activityUIID The activityUIID to set. */ public void setActivityUIID(Integer activityUIID) { - if(!activityUIID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) + if (!activityUIID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) { this.activityUIID = activityUIID; + } } + /** * @param createDateTime The createDateTime to set. */ public void setCreateDateTime(Date createDateTime) { - if(!createDateTime.equals(WDDXTAGS.DATE_NULL_VALUE)) + if (!createDateTime.equals(WDDXTAGS.DATE_NULL_VALUE)) { this.createDateTime = createDateTime; + } } + /** * @param createGroupingID The createGroupingID to set. */ public void setCreateGroupingID(Long createGroupingID) { - if(!createGroupingID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) + if (!createGroupingID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) { this.createGroupingID = createGroupingID; + } } + /** * @param createGroupingUIID The createGroupingUIID to set. */ public void setCreateGroupingUIID(Integer createGroupingUIID) { - if(!createGroupingUIID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) + if (!createGroupingUIID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) { this.createGroupingUIID = createGroupingUIID; + } } + /** * @param defineLater The defineLater to set. */ - public void setDefineLater(Boolean defineLater) { + public void setDefineLater(Boolean defineLater) { this.defineLater = defineLater; } + /** * @param description The description to set. */ public void setDescription(String description) { - if(!description.equals(WDDXTAGS.STRING_NULL_VALUE)) + if (!description.equals(WDDXTAGS.STRING_NULL_VALUE)) { this.description = description; + } } + /** * @param gateActivityLevelID The gateActivityLevelID to set. */ public void setGateActivityLevelID(Integer gateActivityLevelID) { - if(!gateActivityLevelID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) + if (!gateActivityLevelID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) { this.gateActivityLevelID = gateActivityLevelID; + } } + /** * @param gateEndDateTime The gateEndDateTime to set. */ public void setGateEndDateTime(Date gateEndDateTime) { - if(!gateEndDateTime.equals(WDDXTAGS.DATE_NULL_VALUE)) + if (!gateEndDateTime.equals(WDDXTAGS.DATE_NULL_VALUE)) { this.gateEndDateTime = gateEndDateTime; + } } + /** * @param gateEndTimeOffset The gateEndTimeOffset to set. */ public void setGateEndTimeOffset(Long gateEndTimeOffset) { - if(!gateEndTimeOffset.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) + if (!gateEndTimeOffset.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) { this.gateEndTimeOffset = gateEndTimeOffset; + } } + /** * @param gateOpen The gateOpen to set. */ public void setGateOpen(Boolean gateOpen) { this.gateOpen = gateOpen; } + /** * @param gateStartDateTime The gateStartDateTime to set. */ public void setGateStartDateTime(Date gateStartDateTime) { - if(!gateStartDateTime.equals(WDDXTAGS.DATE_NULL_VALUE)) + if (!gateStartDateTime.equals(WDDXTAGS.DATE_NULL_VALUE)) { this.gateStartDateTime = gateStartDateTime; + } } + /** * @param gateStartTimeOffset The gateStartTimeOffset to set. */ public void setGateStartTimeOffset(Long gateStartTimeOffset) { - if(!gateStartTimeOffset.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) + if (!gateStartTimeOffset.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) { this.gateStartTimeOffset = gateStartTimeOffset; + } } + /** * @param groupingID The groupingID to set. */ public void setGroupingID(Long groupingID) { - if(!groupingID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) + if (!groupingID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) { this.groupingID = groupingID; + } } + /** * @param groupingUIID The groupingUIID to set. */ public void setGroupingUIID(Integer groupingUIID) { - if(!groupingUIID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) + if (!groupingUIID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) { this.groupingUIID = groupingUIID; + } } + /** * @param helpText The helpText to set. */ public void setHelpText(String helpText) { - if(!helpText.equals(WDDXTAGS.STRING_NULL_VALUE)) + if (!helpText.equals(WDDXTAGS.STRING_NULL_VALUE)) { this.helpText = helpText; + } } + /** * @param learningDesignID The learningDesignID to set. */ public void setLearningDesignID(Long learningDesignID) { - if(!learningDesignID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) + if (!learningDesignID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) { this.learningDesignID = learningDesignID; + } } + /** * @param learningLibraryID The learningLibraryID to set. */ public void setLearningLibraryID(Long learningLibraryID) { - if(!learningLibraryID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) + if (!learningLibraryID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) { this.learningLibraryID = learningLibraryID; + } } + /** * @param libraryActivityID The libraryActivityID to set. */ public void setLibraryActivityID(Long libraryActivityID) { - if(!libraryActivityID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) + if (!libraryActivityID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) { this.libraryActivityID = libraryActivityID; + } } + /** * @param libraryActivityUiImage The libraryActivityUiImage to set. */ public void setLibraryActivityUIImage(String libraryActivityUiImage) { - if(!libraryActivityUiImage.equals(WDDXTAGS.STRING_NULL_VALUE)) - this.libraryActivityUIImage = libraryActivityUiImage; + if (!libraryActivityUiImage.equals(WDDXTAGS.STRING_NULL_VALUE)) { + libraryActivityUIImage = libraryActivityUiImage; + } } + /** * @param maxOptions The maxOptions to set. */ public void setMaxOptions(Integer maxOptions) { - if(!maxOptions.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) + if (!maxOptions.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) { this.maxOptions = maxOptions; + } } + /** * @param minOptions The minOptions to set. */ public void setMinOptions(Integer minOptions) { - if(!minOptions.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) + if (!minOptions.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) { this.minOptions = minOptions; + } } + /** * @param optionsInstructions The optionsInstructions to set. */ public void setOptionsInstructions(String optionsInstructions) { - if(!optionsInstructions.equals(WDDXTAGS.STRING_NULL_VALUE)) + if (!optionsInstructions.equals(WDDXTAGS.STRING_NULL_VALUE)) { this.optionsInstructions = optionsInstructions; + } } + /** * @param orderID The orderID to set. */ public void setOrderID(Integer orderID) { - if(!orderID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) + if (!orderID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) { this.orderID = orderID; + } } + /** * @param parentActivityID The parentActivityID to set. */ public void setParentActivityID(Long parentActivityID) { - if(!parentActivityID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) + if (!parentActivityID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) { this.parentActivityID = parentActivityID; + } } + /** * @param parentUIID The parentUIID to set. */ public void setParentUIID(Integer parentUIID) { - if(!parentUIID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) + if (!parentUIID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) { this.parentUIID = parentUIID; + } } + /** * @param runOffline The runOffline to set. */ public void setRunOffline(Boolean runOffline) { this.runOffline = runOffline; } + /** * @param title The title to set. */ public void setActivityTitle(String title) { - if(!title.equals(WDDXTAGS.STRING_NULL_VALUE)) - this.activityTitle = title; + if (!title.equals(WDDXTAGS.STRING_NULL_VALUE)) { + activityTitle = title; + } } + /** * @param toolContentID The toolContentID to set. */ public void setToolContentID(Long toolContentID) { - if(!toolContentID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) + if (!toolContentID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) { this.toolContentID = toolContentID; + } } + /** * @param toolID The toolID to set. */ public void setToolID(Long toolID) { - if(!toolID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) + if (!toolID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) { this.toolID = toolID; + } } + /** * @param xcoord The xcoord to set. */ public void setxCoord(Integer xcoord) { - if(!xcoord.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) - this.xCoord = xcoord; + if (!xcoord.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) { + xCoord = xcoord; + } } + /** * @param ycoord The ycoord to set. */ public void setyCoord(Integer ycoord) { - if(!xCoord.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) - this.yCoord = ycoord; - } + if (!xCoord.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) { + yCoord = ycoord; + } + } + /** * @param applyGrouping The applyGrouping to set. */ public void setApplyGrouping(Boolean applyGrouping) { this.applyGrouping = applyGrouping; } + /** * @param groupingSupportType The groupingSupportType to set. */ public void setGroupingSupportType(Integer groupingSupportType) { - if(!groupingSupportType.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) + if (!groupingSupportType.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) { this.groupingSupportType = groupingSupportType; + } } + /** * @param groupingType The groupingType to set. */ public void setGroupingType(Integer groupingType) { - if(!groupingType.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) + if (!groupingType.equals(WDDXTAGS.NUMERIC_NULL_VALUE_INTEGER)) { this.groupingType = groupingType; + } } + /** * * @param readOnly The readOnly to set. */ public void setReadOnly(Boolean readOnly) { - if(!readOnly.equals(WDDXTAGS.BOOLEAN_NULL_VALUE)) + if (!readOnly.equals(WDDXTAGS.BOOLEAN_NULL_VALUE)) { this.readOnly = readOnly; + } } - + public void setAuthoringURL(String toolAuthoringURL) { - this.authoringURL = toolAuthoringURL; + authoringURL = toolAuthoringURL; } + public void setToolDisplayName(String toolDisplayName) { this.toolDisplayName = toolDisplayName; } + public void setLanguageFile(String languageFile) { this.languageFile = languageFile; } + public void setContributeURL(String contributeURL) { this.contributeURL = contributeURL; } + public void setMonitoringURL(String monitoringURL) { this.monitoringURL = monitoringURL; } + public void setModerationURL(String moderationURL) { this.moderationURL = moderationURL; } + public void setHelpURL(String helpURL) { this.helpURL = helpURL; } + public void setToolSignature(String toolSignature) { this.toolSignature = toolSignature; } + public void setToolVersion(String toolVersion) { this.toolVersion = toolVersion; } + public void setInitialised(Boolean initialised) { this.initialised = initialised; } + public void setStopAfterActivity(Boolean stopAfterActivity) { this.stopAfterActivity = stopAfterActivity; } + public void setDefaultActivityUIID(Integer defaultActivityUIID) { - if(!defaultActivityUIID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) + if (!defaultActivityUIID.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) { this.defaultActivityUIID = defaultActivityUIID; + } } + public void setEndXCoord(Integer endXCoord) { - if(!endXCoord.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) + if (!endXCoord.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) { this.endXCoord = endXCoord; + } } + public void setEndYCoord(Integer endYCoord) { - if(!endYCoord.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) + if (!endYCoord.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) { this.endYCoord = endYCoord; + } } + public void setStartXCoord(Integer startXCoord) { - if(!startXCoord.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) + if (!startXCoord.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) { this.startXCoord = startXCoord; + } } + public void setStartYCoord(Integer startYCoord) { - if(!startYCoord.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) + if (!startYCoord.equals(WDDXTAGS.NUMERIC_NULL_VALUE_LONG)) { this.startYCoord = startYCoord; + } } + public String getAdminURL() { return adminURL; } + public void setAdminURL(String adminURL) { this.adminURL = adminURL; } + public ArrayList getInputActivities() { return inputActivities; } + public void setInputActivities(ArrayList inputActivities) { this.inputActivities = inputActivities; } + public Integer getToolActivityUIID() { return toolActivityUIID; } + public void setToolActivityUIID(Integer toolActivityUIID) { this.toolActivityUIID = toolActivityUIID; } + public Boolean getSupportsOutputs() { return supportsOutputs; } + public void setSupportsOutputs(Boolean supportsOutputs) { this.supportsOutputs = supportsOutputs; } + public String getExtLmsId() { return extLmsId; } + public void setExtLmsId(String extLmsId) { this.extLmsId = extLmsId; } Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/dto/LibraryActivityDTO.java =================================================================== diff -u -r40fd34ca6bc3ae5e5466f8c9a17047427f9cd43b -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/dto/LibraryActivityDTO.java (.../LibraryActivityDTO.java) (revision 40fd34ca6bc3ae5e5466f8c9a17047427f9cd43b) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/dto/LibraryActivityDTO.java (.../LibraryActivityDTO.java) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -27,6 +27,7 @@ import org.lamsfoundation.lams.learningdesign.Activity; import org.lamsfoundation.lams.learningdesign.BranchingActivity; +import org.lamsfoundation.lams.learningdesign.ConditionGateActivity; import org.lamsfoundation.lams.learningdesign.GateActivity; import org.lamsfoundation.lams.learningdesign.GroupingActivity; import org.lamsfoundation.lams.learningdesign.OptionsActivity; @@ -39,16 +40,15 @@ import org.lamsfoundation.lams.tool.Tool; import org.lamsfoundation.lams.util.HelpUtil; -public class LibraryActivityDTO extends BaseDTO -{ - private Integer activityTypeID; - private Long activityID; - private Integer activityCategoryID; - private Integer activityUIID; - private Long learningLibraryID; //not sure if this is needed - private Long learningDesignID; - private Long libraryActivityID; - private Long parentActivityID; +public class LibraryActivityDTO extends BaseDTO { + private Integer activityTypeID; + private Long activityID; + private Integer activityCategoryID; + private Integer activityUIID; + private Long learningLibraryID; //not sure if this is needed + private Long learningDesignID; + private Long libraryActivityID; + private Long parentActivityID; private Integer parentUIID; private Integer orderID; private Long groupingID; @@ -68,7 +68,7 @@ /** Name of the file (including the package) that contains the text strings for * this activity. e.g. org.lamsfoundation.lams.tool.sbmt.SbmtResources.properties. */ private String languageFile; - + /* Properties Specific to ToolActivity */ private Long toolID; private Long toolContentID; @@ -78,429 +78,490 @@ private Boolean supportsDefineLater; private Boolean supportsRunOffline; private Boolean supportsModeration; - private Boolean supportsContribute; + private Boolean supportsContribute; private String authoringURL; private String adminURL; private Boolean supportsOutputs; private String extLmsId; - + /* Grouping Activities */ - + /* Optional Activities */ private Integer maxOptions; private Integer minOptions; private String optionsInstructions; - + /* Sequence Activities */ - + /* Gate Activities */ - private Integer gateActivityLevelID; - private Boolean gateOpen; - private Long gateStartTimeOffset; - private Long gateEndTimeOffset; - private Date gateStartDateTime; + private Integer gateActivityLevelID; + private Boolean gateOpen; + private Long gateStartTimeOffset; + private Long gateEndTimeOffset; + private Date gateStartDateTime; private Date gateEndDateTime; - + /** Used for I18N the URLS. Does not need to be sent to clients, so no getter exists. */ - private String languageCode; - + private String languageCode; + private Boolean toolAdapter; - public LibraryActivityDTO (Activity activity, String languageCode) - { - this.activityTypeID = activity.getActivityTypeId(); - this.activityID = activity.getActivityId(); - this.activityCategoryID = activity.getActivityCategoryID(); - this.activityUIID = activity.getActivityUIID(); - this.learningLibraryID = activity.getLearningLibrary() != null ? activity.getLearningLibrary().getLearningLibraryId() : null; - this.learningDesignID = activity.getLearningDesign() != null ? activity.getLearningDesign().getLearningDesignId() : null; - this.libraryActivityID = activity.getLibraryActivity() != null ? activity.getLibraryActivity().getActivityId() : null; - this.parentActivityID = activity.getParentActivity() != null ? activity.getParentActivity().getActivityId() : null; - this.parentUIID = activity.getParentUIID(); - this.orderID = activity.getOrderId(); - this.groupingID = activity.getGrouping()!= null? activity.getGrouping().getGroupingId(): null; - this.groupingUIID = activity.getGroupingUIID(); - this.description = activity.getDescription(); - this.activityTitle = activity.getTitle(); - this.helpText = activity.getHelpText(); - this.xCoord = activity.getXcoord(); - this.yCoord = activity.getYcoord(); - this.libraryActivityUIImage = activity.getLibraryActivityUiImage(); - this.applyGrouping = activity.getApplyGrouping(); - this.runOffline = activity.getRunOffline(); - this.defineLater = activity.getDefineLater(); - this.createDateTime = activity.getCreateDateTime(); - this.groupingSupportType = activity.getGroupingSupportType(); - this.languageFile = activity.getLanguageFile(); - - this.languageCode = languageCode; - processActivityType(activity); - + public LibraryActivityDTO(Activity activity, String languageCode) { + activityTypeID = activity.getActivityTypeId(); + activityID = activity.getActivityId(); + activityCategoryID = activity.getActivityCategoryID(); + activityUIID = activity.getActivityUIID(); + learningLibraryID = activity.getLearningLibrary() != null ? activity.getLearningLibrary().getLearningLibraryId() : null; + learningDesignID = activity.getLearningDesign() != null ? activity.getLearningDesign().getLearningDesignId() : null; + libraryActivityID = activity.getLibraryActivity() != null ? activity.getLibraryActivity().getActivityId() : null; + parentActivityID = activity.getParentActivity() != null ? activity.getParentActivity().getActivityId() : null; + parentUIID = activity.getParentUIID(); + orderID = activity.getOrderId(); + groupingID = activity.getGrouping() != null ? activity.getGrouping().getGroupingId() : null; + groupingUIID = activity.getGroupingUIID(); + description = activity.getDescription(); + activityTitle = activity.getTitle(); + helpText = activity.getHelpText(); + xCoord = activity.getXcoord(); + yCoord = activity.getYcoord(); + libraryActivityUIImage = activity.getLibraryActivityUiImage(); + applyGrouping = activity.getApplyGrouping(); + runOffline = activity.getRunOffline(); + defineLater = activity.getDefineLater(); + createDateTime = activity.getCreateDateTime(); + groupingSupportType = activity.getGroupingSupportType(); + languageFile = activity.getLanguageFile(); + + this.languageCode = languageCode; + processActivityType(activity); + } - - private void processActivityType(Activity activity){ - if(activity.isGroupingActivity()) - addGroupingActivityAttributes((GroupingActivity)activity); - else if(activity.isToolActivity()) - addToolActivityAttributes((ToolActivity)activity); - else if(activity.isGateActivity()) - addGateActivityAttributes(activity); - else - addComplexActivityAttributes(activity); + + private void processActivityType(Activity activity) { + if (activity.isGroupingActivity()) { + addGroupingActivityAttributes((GroupingActivity) activity); + } + else if (activity.isToolActivity()) { + addToolActivityAttributes((ToolActivity) activity); + } + else if (activity.isGateActivity()) { + addGateActivityAttributes(activity); + } + else { + addComplexActivityAttributes(activity); + } } - - private void addComplexActivityAttributes(Activity activity){ - if(activity.isOptionsActivity()) - addOptionsActivityAttributes((OptionsActivity)activity); - else if (activity.isParallelActivity()) - addParallelActivityAttributes((ParallelActivity)activity); - else if (activity.isBranchingActivity()) - addBranchingActivityAttributes((BranchingActivity)activity); - else - addSequenceActivityAttributes((SequenceActivity)activity); - - + + private void addComplexActivityAttributes(Activity activity) { + if (activity.isOptionsActivity()) { + addOptionsActivityAttributes((OptionsActivity) activity); + } + else if (activity.isParallelActivity()) { + addParallelActivityAttributes((ParallelActivity) activity); + } + else if (activity.isBranchingActivity()) { + addBranchingActivityAttributes((BranchingActivity) activity); + } + else { + addSequenceActivityAttributes((SequenceActivity) activity); + } + } - private void addGroupingActivityAttributes(GroupingActivity groupingActivity){ + + private void addGroupingActivityAttributes(GroupingActivity groupingActivity) { /* Grouping grouping = groupingActivity.getCreateGrouping(); this.groupingDTO = grouping.getGroupingDTO(); this.createGroupingID = grouping.getGroupingId(); this.createGroupingUIID = grouping.getGroupingUIID(); this.groupingType = grouping.getGroupingTypeId(); */ } - private void addOptionsActivityAttributes(OptionsActivity optionsActivity){ - this.maxOptions = optionsActivity.getMaxNumberOfOptions(); - this.minOptions = optionsActivity.getMinNumberOfOptions(); - this.optionsInstructions = optionsActivity.getOptionsInstructions(); + + private void addOptionsActivityAttributes(OptionsActivity optionsActivity) { + maxOptions = optionsActivity.getMaxNumberOfOptions(); + minOptions = optionsActivity.getMinNumberOfOptions(); + optionsInstructions = optionsActivity.getOptionsInstructions(); } - private void addParallelActivityAttributes(ParallelActivity activity){ - + + private void addParallelActivityAttributes(ParallelActivity activity) { + } - private void addBranchingActivityAttributes(BranchingActivity activity){ - + + private void addBranchingActivityAttributes(BranchingActivity activity) { + } - private void addSequenceActivityAttributes(SequenceActivity activity){ + + private void addSequenceActivityAttributes(SequenceActivity activity) { } - private void addToolActivityAttributes(ToolActivity toolActivity){ - Tool tool = toolActivity.getTool(); - if (tool != null) - { - this.toolID = tool.getToolId(); - this.toolContentID = new Long(tool.getDefaultToolContentId()); - this.toolDisplayName = tool.getToolDisplayName(); - this.toolLanguageFile = tool.getLanguageFile(); - this.toolSignature = tool.getToolSignature(); - this.supportsDefineLater = new Boolean(tool.getSupportsDefineLater()); - this.supportsRunOffline = new Boolean(tool.getSupportsRunOffline()); - this.supportsModeration = new Boolean(tool.getSupportsModeration()); - this.supportsContribute = new Boolean(tool.getSupportsContribute()); - this.authoringURL = tool.getAuthorUrl(); - this.adminURL = tool.getAdminUrl(); - this.supportsOutputs = tool.getSupportsOutputs(); - this.extLmsId = tool.getExtLmsId(); - this.helpURL = HelpUtil.constructToolURL(tool.getHelpUrl(), toolSignature, "", languageCode); - } - + + private void addToolActivityAttributes(ToolActivity toolActivity) { + Tool tool = toolActivity.getTool(); + if (tool != null) { + toolID = tool.getToolId(); + toolContentID = new Long(tool.getDefaultToolContentId()); + toolDisplayName = tool.getToolDisplayName(); + toolLanguageFile = tool.getLanguageFile(); + toolSignature = tool.getToolSignature(); + supportsDefineLater = new Boolean(tool.getSupportsDefineLater()); + supportsRunOffline = new Boolean(tool.getSupportsRunOffline()); + supportsModeration = new Boolean(tool.getSupportsModeration()); + supportsContribute = new Boolean(tool.getSupportsContribute()); + authoringURL = tool.getAuthorUrl(); + adminURL = tool.getAdminUrl(); + supportsOutputs = tool.getSupportsOutputs(); + extLmsId = tool.getExtLmsId(); + helpURL = HelpUtil.constructToolURL(tool.getHelpUrl(), toolSignature, "", languageCode); + } + } - private void addGateActivityAttributes(Object activity){ - if(activity instanceof SynchGateActivity) - addSynchGateActivityAttributes((SynchGateActivity)activity); - else if (activity instanceof PermissionGateActivity) - addPermissionGateActivityAttributes((PermissionGateActivity)activity); - else - addScheduleGateActivityAttributes((ScheduleGateActivity)activity); - GateActivity gateActivity = (GateActivity)activity ; - this.gateActivityLevelID = gateActivity.getGateActivityLevelId(); - this.gateOpen = gateActivity.getGateOpen(); - + + private void addGateActivityAttributes(Object activity) { + if (activity instanceof SynchGateActivity) { + addSynchGateActivityAttributes((SynchGateActivity) activity); + } + else if (activity instanceof PermissionGateActivity) { + addPermissionGateActivityAttributes((PermissionGateActivity) activity); + } + else if (activity instanceof ConditionGateActivity) { + addConditionGateActivityAttributes((ConditionGateActivity) activity); + } + else { + addScheduleGateActivityAttributes((ScheduleGateActivity) activity); + } + GateActivity gateActivity = (GateActivity) activity; + gateActivityLevelID = gateActivity.getGateActivityLevelId(); + gateOpen = gateActivity.getGateOpen(); + } - private void addSynchGateActivityAttributes(SynchGateActivity activity){ + + private void addSynchGateActivityAttributes(SynchGateActivity activity) { } - private void addPermissionGateActivityAttributes(PermissionGateActivity activity){ + + private void addPermissionGateActivityAttributes(PermissionGateActivity activity) { } - private void addScheduleGateActivityAttributes(ScheduleGateActivity activity){ - this.gateStartDateTime = activity.getGateStartDateTime(); - this.gateStartTimeOffset = activity.getGateStartTimeOffset(); - this.gateEndDateTime = activity.getGateEndDateTime(); - this.gateEndTimeOffset = activity.getGateEndTimeOffset(); + + private void addScheduleGateActivityAttributes(ScheduleGateActivity activity) { + gateStartDateTime = activity.getGateStartDateTime(); + gateStartTimeOffset = activity.getGateStartTimeOffset(); + gateEndDateTime = activity.getGateEndDateTime(); + gateEndTimeOffset = activity.getGateEndTimeOffset(); } - - /** - * @return Returns the activityCategoryID. - */ - public Integer getActivityCategoryID() { - return activityCategoryID; - } - /** - * @return Returns the activityID. - */ - public Long getActivityID() { - return activityID; - } - /** - * @return Returns the activityTypeID. - */ - public Integer getActivityTypeID() { - return activityTypeID; - } - /** - * @return Returns the activityUIID. - */ - public Integer getActivityUIID() { - return activityUIID; - } - /** - * @return Returns the applyGrouping. - */ - public Boolean getApplyGrouping() { - return applyGrouping; - } - /** - * @return Returns the createDateTime. - */ - public Date getCreateDateTime() { - return createDateTime; - } - /** - * @return Returns the defineLater. - */ - public Boolean getDefineLater() { - return defineLater; - } - /** - * @return Returns the description. - */ - public String getDescription() { - return description; - } - /** - * @return Returns the groupingID. - */ - public Long getGroupingID() { - return groupingID; - } - /** - * @return Returns the groupingSupportType. - */ - public Integer getGroupingSupportType() { - return groupingSupportType; - } - /** - * @return Returns the groupingUIID. - */ - public Integer getGroupingUIID() { - return groupingUIID; - } - /** - * @return Returns the helpText. - */ - public String getHelpText() { - return helpText; - } - /** - * - * @return Return the helpURL - */ - public String getHelpURL() { - return helpURL; - } - /** - * @return Returns the learningDesignID. - */ - public Long getLearningDesignID() { - return learningDesignID; - } - /** - * @return Returns the learningLibraryID. - */ - public Long getLearningLibraryID() { - return learningLibraryID; - } - /** - * @return Returns the libraryActivityID. - */ - public Long getLibraryActivityID() { - return libraryActivityID; - } - /** - * @return Returns the libraryActivityUIImage. - */ - public String getLibraryActivityUIImage() { - return libraryActivityUIImage; - } - /** - * @return Returns the orderID. - */ - public Integer getOrderID() { - return orderID; - } - /** - * @return Returns the parentActivityID. - */ - public Long getParentActivityID() { - return parentActivityID; - } - /** - * @return Returns the parentUIID. - */ - public Integer getParentUIID() { - return parentUIID; - } - /** - * @return Returns the runOffline. - */ - public Boolean getRunOffline() { - return runOffline; - } - /** - * @return Returns the title. - */ - public String getActivityTitle() { - return activityTitle; - } - - /** - * @return Returns the xCoord. - */ - public Integer getxCoord() { - return xCoord; - } - /** - * @return Returns the yCoord. - */ - public Integer getyCoord() { - return yCoord; - } - - /** - * @return Returns the authoringURL. - */ - public String getAuthoringURL() { - return authoringURL; - } - /** - * @return Returns the adminURL. - */ - public String getAdminURL() { - return adminURL; - } - /** - * @return Returns the supportsContribute. - */ - public Boolean getSupportsContribute() { - return supportsContribute; - } - /** - * @return Returns the supportsDefineLater. - */ - public Boolean getSupportsDefineLater() { - return supportsDefineLater; - } - /** - * @return Returns the supportsModeration. - */ - public Boolean getSupportsModeration() { - return supportsModeration; - } - /** - * @return Returns the supportsRunOffline. - */ - public Boolean getSupportsRunOffline() { - return supportsRunOffline; - } - /** - * @return Returns the toolContentID. - */ - public Long getToolContentID() { - return toolContentID; - } - /** - * @return Returns the toolDisplayName. - */ - public String getToolDisplayName() { - return toolDisplayName; - } - /** - * @return Returns the toolID. - */ - public Long getToolID() { - return toolID; - } - - /** - * - * @return Returns the toolSignature - */ - public String getToolSignature() { + + private void addConditionGateActivityAttributes(ConditionGateActivity activity) { + } + + /** + * @return Returns the activityCategoryID. + */ + public Integer getActivityCategoryID() { + return activityCategoryID; + } + + /** + * @return Returns the activityID. + */ + public Long getActivityID() { + return activityID; + } + + /** + * @return Returns the activityTypeID. + */ + public Integer getActivityTypeID() { + return activityTypeID; + } + + /** + * @return Returns the activityUIID. + */ + public Integer getActivityUIID() { + return activityUIID; + } + + /** + * @return Returns the applyGrouping. + */ + public Boolean getApplyGrouping() { + return applyGrouping; + } + + /** + * @return Returns the createDateTime. + */ + public Date getCreateDateTime() { + return createDateTime; + } + + /** + * @return Returns the defineLater. + */ + public Boolean getDefineLater() { + return defineLater; + } + + /** + * @return Returns the description. + */ + public String getDescription() { + return description; + } + + /** + * @return Returns the groupingID. + */ + public Long getGroupingID() { + return groupingID; + } + + /** + * @return Returns the groupingSupportType. + */ + public Integer getGroupingSupportType() { + return groupingSupportType; + } + + /** + * @return Returns the groupingUIID. + */ + public Integer getGroupingUIID() { + return groupingUIID; + } + + /** + * @return Returns the helpText. + */ + public String getHelpText() { + return helpText; + } + + /** + * + * @return Return the helpURL + */ + public String getHelpURL() { + return helpURL; + } + + /** + * @return Returns the learningDesignID. + */ + public Long getLearningDesignID() { + return learningDesignID; + } + + /** + * @return Returns the learningLibraryID. + */ + public Long getLearningLibraryID() { + return learningLibraryID; + } + + /** + * @return Returns the libraryActivityID. + */ + public Long getLibraryActivityID() { + return libraryActivityID; + } + + /** + * @return Returns the libraryActivityUIImage. + */ + public String getLibraryActivityUIImage() { + return libraryActivityUIImage; + } + + /** + * @return Returns the orderID. + */ + public Integer getOrderID() { + return orderID; + } + + /** + * @return Returns the parentActivityID. + */ + public Long getParentActivityID() { + return parentActivityID; + } + + /** + * @return Returns the parentUIID. + */ + public Integer getParentUIID() { + return parentUIID; + } + + /** + * @return Returns the runOffline. + */ + public Boolean getRunOffline() { + return runOffline; + } + + /** + * @return Returns the title. + */ + public String getActivityTitle() { + return activityTitle; + } + + /** + * @return Returns the xCoord. + */ + public Integer getxCoord() { + return xCoord; + } + + /** + * @return Returns the yCoord. + */ + public Integer getyCoord() { + return yCoord; + } + + /** + * @return Returns the authoringURL. + */ + public String getAuthoringURL() { + return authoringURL; + } + + /** + * @return Returns the adminURL. + */ + public String getAdminURL() { + return adminURL; + } + + /** + * @return Returns the supportsContribute. + */ + public Boolean getSupportsContribute() { + return supportsContribute; + } + + /** + * @return Returns the supportsDefineLater. + */ + public Boolean getSupportsDefineLater() { + return supportsDefineLater; + } + + /** + * @return Returns the supportsModeration. + */ + public Boolean getSupportsModeration() { + return supportsModeration; + } + + /** + * @return Returns the supportsRunOffline. + */ + public Boolean getSupportsRunOffline() { + return supportsRunOffline; + } + + /** + * @return Returns the toolContentID. + */ + public Long getToolContentID() { + return toolContentID; + } + + /** + * @return Returns the toolDisplayName. + */ + public String getToolDisplayName() { + return toolDisplayName; + } + + /** + * @return Returns the toolID. + */ + public Long getToolID() { + return toolID; + } + + /** + * + * @return Returns the toolSignature + */ + public String getToolSignature() { return toolSignature; } - - /** - * @return Returns the gateActivityLevelID. - */ - public Integer getGateActivityLevelID() { - return gateActivityLevelID; - } - /** - * @return Returns the gateEndDateTime. - */ - public Date getGateEndDateTime() { - return gateEndDateTime; - } - /** - * @return Returns the gateEndTimeOffset. - */ - public Long getGateEndTimeOffset() { - return gateEndTimeOffset; - } - /** - * @return Returns the gateOpen. - */ - public Boolean getGateOpen() { - return gateOpen; - } - /** - * @return Returns the gateStartDateTime. - */ - public Date getGateStartDateTime() { - return gateStartDateTime; - } - /** - * @return Returns the gateStartTimeOffset. - */ - public Long getGateStartTimeOffset() { - return gateStartTimeOffset; - } - - /** - * @return Returns the maxOptions. - */ - public Integer getMaxOptions() { - return maxOptions; - } - /** - * @return Returns the minOptions. - */ - public Integer getMinOptions() { - return minOptions; - } - /** - * @return Returns the optionsInstructions. - */ - public String getOptionsInstructions() { - return optionsInstructions; - } - /** - * @return Returns the languge file for the activity (for I8N). - */ - public String getLanguageFile() { + /** + * @return Returns the gateActivityLevelID. + */ + public Integer getGateActivityLevelID() { + return gateActivityLevelID; + } + + /** + * @return Returns the gateEndDateTime. + */ + public Date getGateEndDateTime() { + return gateEndDateTime; + } + + /** + * @return Returns the gateEndTimeOffset. + */ + public Long getGateEndTimeOffset() { + return gateEndTimeOffset; + } + + /** + * @return Returns the gateOpen. + */ + public Boolean getGateOpen() { + return gateOpen; + } + + /** + * @return Returns the gateStartDateTime. + */ + public Date getGateStartDateTime() { + return gateStartDateTime; + } + + /** + * @return Returns the gateStartTimeOffset. + */ + public Long getGateStartTimeOffset() { + return gateStartTimeOffset; + } + + /** + * @return Returns the maxOptions. + */ + public Integer getMaxOptions() { + return maxOptions; + } + + /** + * @return Returns the minOptions. + */ + public Integer getMinOptions() { + return minOptions; + } + + /** + * @return Returns the optionsInstructions. + */ + public String getOptionsInstructions() { + return optionsInstructions; + } + + /** + * @return Returns the languge file for the activity (for I8N). + */ + public String getLanguageFile() { return languageFile; } - /** - * @return Returns the languge file for the tool (for I8N). - */ + /** + * @return Returns the languge file for the tool (for I8N). + */ public String getToolLanguageFile() { return toolLanguageFile; } @@ -514,7 +575,7 @@ public void setHelpText(String helpText) { this.helpText = helpText; } - + /** * Set the activity's help url * @param helpURL @@ -525,18 +586,18 @@ /** Set the activity's title */ public void setActivityTitle(String title) { - this.activityTitle = title; + activityTitle = title; } /** Set the tool's display name (similar to title) */ public void setToolDisplayName(String toolDisplayName) { this.toolDisplayName = toolDisplayName; } - + /** Set the tool's signature * @param toolSignature */ - + public void setToolSignature(String toolSignature) { this.toolSignature = toolSignature; } Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/dto/ValidationErrorDTO.java =================================================================== diff -u -rc209be8131f22f6fe37bd8d6c14b56425a78b766 -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/dto/ValidationErrorDTO.java (.../ValidationErrorDTO.java) (revision c209be8131f22f6fe37bd8d6c14b56425a78b766) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/dto/ValidationErrorDTO.java (.../ValidationErrorDTO.java) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -44,6 +44,8 @@ public static final String OPTIONAL_ACTIVITY_ORDER_ID_INVALID_ERROR_KEY = "validation.error.OptionalActivityOrderId"; // OAOI public static final String SCHEDULE_GATE_ERROR_TYPE1_KEY = "validation.error.illegalScheduleGateOffsetsType1"; // SG public static final String SCHEDULE_GATE_ERROR_TYPE2_KEY = "validation.error.illegalScheduleGateOffsetsType2"; + public static final String CONDITION_GATE_ACTVITY_CONDITION = "validation.error.conditionGateMustHaveACondition"; // CGC + public static final String CONDITION_GATE_ACTVITY_TOOLINPUT = "validation.error.conditionGateMustHaveAnInputToolActivity"; // CGI public static final String GROUPING_ACTIVITY_MISSING_GROUPING_KEY = "validation.error.grouping.missing"; // GM public static final String GROUPING_ACTIVITY_GROUP_COUNT_MISMATCH_KEY = "validation.error.group.count.mismatch"; // GC @@ -67,6 +69,8 @@ public static final String OPTIONAL_ACTIVITY_ERROR_CODE = "OA"; public static final String OPTIONAL_ACTIVITY_ORDER_ID_INVALID_ERROR_CODE = "OAOI"; public static final String SCHEDULE_GATE_ERROR_CODE = "SG1"; + public static final String CONDITION_GATE_ACTVITY_CONDITION_ERROR_CODE = "CGC"; + public static final String CONDITION_GATE_ACTVITY_TOOLINPUT_ERROR_CODE = "CGI"; public static final String GROUPING_ACTIVITY_MISSING_GROUPING_ERROR_CODE = "GM"; public static final String GROUPING_ACTIVITY_GROUP_COUNT_MISMATCH_ERROR_CODE = "GC"; public static final String BRANCHING_ACTIVITY_MUST_HAVE_A_BRANCH_ERROR_CODE = "BB"; @@ -161,6 +165,16 @@ */ public static final String SCHEDULE_GATE_ERROR_TYPE1 = ValidationErrorDTO.resources .getMessage(ValidationErrorDTO.SCHEDULE_GATE_ERROR_TYPE1_KEY); + /** + * Rule: A condition gate must have at least condition defined. + */ + public static final String CONDITION_GATE_CONDITION_ERROR = ValidationErrorDTO.resources + .getMessage(ValidationErrorDTO.CONDITION_GATE_ACTVITY_CONDITION_ERROR_CODE); + /** + * Rule: A condition gate must have an input tool. + */ + public static final String CONDITION_GATE_TOOLINPUT_ERROR = ValidationErrorDTO.resources + .getMessage(ValidationErrorDTO.CONDITION_GATE_ACTVITY_TOOLINPUT_ERROR_CODE); /** * Rule: For Schedule Gates (Activity) if start and end time offsets are set then the start time offset should be Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/ExportToolContentService.java =================================================================== diff -u -rc209be8131f22f6fe37bd8d6c14b56425a78b766 -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/ExportToolContentService.java (.../ExportToolContentService.java) (revision c209be8131f22f6fe37bd8d6c14b56425a78b766) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/ExportToolContentService.java (.../ExportToolContentService.java) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -84,6 +84,7 @@ import org.lamsfoundation.lams.learningdesign.BranchingActivity; import org.lamsfoundation.lams.learningdesign.ChosenGrouping; import org.lamsfoundation.lams.learningdesign.ComplexActivity; +import org.lamsfoundation.lams.learningdesign.ConditionGateActivity; import org.lamsfoundation.lams.learningdesign.Group; import org.lamsfoundation.lams.learningdesign.Grouping; import org.lamsfoundation.lams.learningdesign.GroupingActivity; @@ -659,7 +660,8 @@ else if (actDto.getActivityTypeID().equals(Activity.SCHEDULE_GATE_ACTIVITY_TYPE) || actDto.getActivityTypeID().equals(Activity.PERMISSION_GATE_ACTIVITY_TYPE) || actDto.getActivityTypeID().equals(Activity.SYNCH_GATE_ACTIVITY_TYPE) - || actDto.getActivityTypeID().equals(Activity.SYSTEM_GATE_ACTIVITY_TYPE)) { + || actDto.getActivityTypeID().equals(Activity.SYSTEM_GATE_ACTIVITY_TYPE) + || actDto.getActivityTypeID().equals(Activity.CONDITION_GATE_ACTIVITY_TYPE)) { att = new Attribute(ExportToolContentService.IMS_ATTR_REF, ExportToolContentService.IMS_PREFIX_ACTIVITY_REF + ExportToolContentService.IMS_TAG_GATE + "-" + actDto.getActivityID()); } @@ -2201,7 +2203,7 @@ BranchActivityEntry entry = null; if (condition != null) { - entry = condition.allocateBranchToCondition(entryDto.getEntryUIID(), branch, (BranchingActivity) branchingActivity); + entry = condition.allocateBranchToCondition(entryDto.getEntryUIID(), branch, branchingActivity); } else if (group != null) { entry = group.allocateBranchToGroup(entryDto.getEntryUIID(), branch, (BranchingActivity) branchingActivity); @@ -2311,6 +2313,12 @@ ((PermissionGateActivity) act).setWaitingLearners(null); ((PermissionGateActivity) act).setSystemTool(systemToolDAO.getSystemToolByID(SystemTool.PERMISSION_GATE)); break; + case Activity.CONDITION_GATE_ACTIVITY_TYPE: + ((ConditionGateActivity) act).setGateActivityLevelId(actDto.getGateActivityLevelID()); + ((ConditionGateActivity) act).setGateOpen(false); + ((ConditionGateActivity) act).setWaitingLearners(null); + ((ConditionGateActivity) act).setSystemTool(systemToolDAO.getSystemToolByID(SystemTool.PERMISSION_GATE)); + break; case Activity.PARALLEL_ACTIVITY_TYPE: break; case Activity.OPTIONS_ACTIVITY_TYPE: Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/ConditionGateActivityStrategy.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/ConditionGateActivityStrategy.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/ConditionGateActivityStrategy.java (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -0,0 +1,63 @@ +/**************************************************************** + * 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 + * **************************************************************** + */ +/* $$Id$$ */ +package org.lamsfoundation.lams.learningdesign.strategy; + +import java.util.ArrayList; +import java.util.List; + +import org.lamsfoundation.lams.learningdesign.ContributionTypes; +import org.lamsfoundation.lams.learningdesign.GateActivity; + +/** + * Gate activity strategy that is based on tools' output and conditions. + * + * @author Marcin Cieslak + */ +public class ConditionGateActivityStrategy extends GateActivityStrategy { + + public ConditionGateActivityStrategy(GateActivity gateActivity) { + super(gateActivity); + } + + //--------------------------------------------------------------------- + // Overriden methods + //--------------------------------------------------------------------- + /** + * @see org.lamsfoundation.lams.learningdesign.strategy.GateActivityStrategy#setUpContributionType(org.lamsfoundation.lams.learningdesign.Activity, java.util.ArrayList) + */ + @Override + protected void setUpContributionType(ArrayList contributionTypes) { + contributionTypes.add(ContributionTypes.CONDITION_GATE); + } + + /** + * Since the gate is open only for individuals and never for the whole class, this method returns false. + * + * @see org.lamsfoundation.lams.learningdesign.strategy.GateActivityStrategy#isOpenConditionMet() + */ + @Override + protected boolean isOpenConditionMet(List lessonLearners) { + return false; + } +} Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/GateActivityStrategy.java =================================================================== diff -u -r418a30a76094c56762b5beb23cb2dd72619e316c -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/GateActivityStrategy.java (.../GateActivityStrategy.java) (revision 418a30a76094c56762b5beb23cb2dd72619e316c) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/GateActivityStrategy.java (.../GateActivityStrategy.java) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -71,8 +71,8 @@ gateActivity.getWaitingLearners().clear(); gateActivity.getAllowedToPassLearners().clear(); } - else if (gateActivity.getAllowedToPassLearners().contains(learner)) { - return true; + else { + return gateActivity.getAllowedToPassLearners().contains(learner); } } //always clear all lists if the gate is already opened. @@ -110,5 +110,4 @@ protected Activity getActivity() { return gateActivity; } - } Index: lams_common/src/java/org/lamsfoundation/lams/tool/SystemTool.java =================================================================== diff -u -r3fd86a5918d046985d4fb7053d30d208bc35f4f6 -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_common/src/java/org/lamsfoundation/lams/tool/SystemTool.java (.../SystemTool.java) (revision 3fd86a5918d046985d4fb7053d30d208bc35f4f6) +++ lams_common/src/java/org/lamsfoundation/lams/tool/SystemTool.java (.../SystemTool.java) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -30,7 +30,6 @@ import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; - /** * Represents the URLs for the internal functionality such as grouping and gates. * Eventually these will become "pluggable" tools, so that we can have other @@ -50,312 +49,293 @@ public static final Long GROUP_BASED_BRANCHING = new Long(7); public static final Long TOOL_BASED_BRANCHING = new Long(8); public static final Long SEQUENCE = new Long(9); - - /** identifier field */ - private Long systemToolId; + public static final Long CONDITION_GATE = new Long(9); - /** persistent field - the type of activity */ + /** identifier field */ + private Long systemToolId; + + /** persistent field - the type of activity */ private Integer activityTypeId; - /** persistent field */ - private String toolDisplayName; + /** persistent field */ + private String toolDisplayName; - /** nullable persistent field */ - private String description; + /** nullable persistent field */ + private String description; - /** persistent field */ - private String learnerUrl; + /** persistent field */ + private String learnerUrl; - /** persistent field */ - private String learnerPreviewUrl; + /** persistent field */ + private String learnerPreviewUrl; - /** persistent field */ - private String learnerProgressUrl; + /** persistent field */ + private String learnerProgressUrl; - /** persistent field */ - private String exportPortfolioLearnerUrl; + /** persistent field */ + private String exportPortfolioLearnerUrl; - /** persistent field */ - private String exportPortfolioClassUrl; + /** persistent field */ + private String exportPortfolioClassUrl; - /** persistent field */ - private String monitorUrl; - - /** persistent field */ - private String contributeUrl; - - /** persistent field */ - private String helpUrl; - - /** persistent field */ - private String adminUrl; - - /** persistent field */ - private Date createDateTime; - + /** persistent field */ + private String monitorUrl; + + /** persistent field */ + private String contributeUrl; + + /** persistent field */ + private String helpUrl; + + /** persistent field */ + private String adminUrl; + + /** persistent field */ + private Date createDateTime; + /** * Entries for an tool in a language property file */ public static final String I18N_DISPLAY_NAME = "tool.display.name"; public static final String I18N_DESCRIPTION = "tool.description"; - /** full constructor */ - public SystemTool(Long systemToolId, - Integer activityTypeId, - String displayName, - String description, - String learnerUrl, - String learnerPreviewUrl, - String learnerProgressUrl, - String exportPortfolioLearnerUrl, - String exportPortfolioClassUrl, - String monitorUrl, - String contributeUrl, - String helpUrl, - Date createDateTime) - { - this.systemToolId = systemToolId; - this.activityTypeId = activityTypeId; - this.toolDisplayName = displayName; - this.description = description; - - this.learnerUrl = learnerUrl; - this.learnerPreviewUrl = learnerPreviewUrl; - this.learnerProgressUrl = learnerProgressUrl; - this.exportPortfolioLearnerUrl = exportPortfolioLearnerUrl; - this.exportPortfolioClassUrl = exportPortfolioClassUrl; - this.monitorUrl = monitorUrl; - this.contributeUrl = contributeUrl; - this.helpUrl = helpUrl; + /** full constructor */ + public SystemTool(Long systemToolId, Integer activityTypeId, String displayName, String description, String learnerUrl, + String learnerPreviewUrl, String learnerProgressUrl, String exportPortfolioLearnerUrl, + String exportPortfolioClassUrl, String monitorUrl, String contributeUrl, String helpUrl, Date createDateTime) { + this.systemToolId = systemToolId; + this.activityTypeId = activityTypeId; + toolDisplayName = displayName; + this.description = description; - this.createDateTime = createDateTime; - } + this.learnerUrl = learnerUrl; + this.learnerPreviewUrl = learnerPreviewUrl; + this.learnerProgressUrl = learnerProgressUrl; + this.exportPortfolioLearnerUrl = exportPortfolioLearnerUrl; + this.exportPortfolioClassUrl = exportPortfolioClassUrl; + this.monitorUrl = monitorUrl; + this.contributeUrl = contributeUrl; + this.helpUrl = helpUrl; - /** default constructor */ - public SystemTool() { - } + this.createDateTime = createDateTime; + } - /** - * @hibernate.id generator-class="native" type="java.lang.Long" - * column="system_tool_id" - */ - public Long getSystemToolId() { - return this.systemToolId; - } + /** default constructor */ + public SystemTool() { + } - public void setSystemToolId(Long systemToolId) { - this.systemToolId = systemToolId; - } + /** + * @hibernate.id generator-class="native" type="java.lang.Long" + * column="system_tool_id" + */ + public Long getSystemToolId() { + return systemToolId; + } - - /** - * @hibernate.property column="learning_activity_type_id" type="java.lang.Integer" - * not-null="true" - */ - public Integer getActivityTypeId() { - return this.activityTypeId; - } + public void setSystemToolId(Long systemToolId) { + this.systemToolId = systemToolId; + } - public void setActivityTypeId(Integer activityTypeId) { - this.activityTypeId = activityTypeId; - } + /** + * @hibernate.property column="learning_activity_type_id" type="java.lang.Integer" + * not-null="true" + */ + public Integer getActivityTypeId() { + return activityTypeId; + } - /** - * @hibernate.property column="tool_display_name" length="255" - * not-null="true" - */ - public String getToolDisplayName() { - return this.toolDisplayName; - } + public void setActivityTypeId(Integer activityTypeId) { + this.activityTypeId = activityTypeId; + } - public void setToolDisplayName(String toolDisplayName) { - this.toolDisplayName = toolDisplayName; - } + /** + * @hibernate.property column="tool_display_name" length="255" + * not-null="true" + */ + public String getToolDisplayName() { + return toolDisplayName; + } - /** - * @hibernate.property column="description" length="65535" - */ - public String getDescription() { - return this.description; - } + public void setToolDisplayName(String toolDisplayName) { + this.toolDisplayName = toolDisplayName; + } - public void setDescription(String description) { - this.description = description; - } + /** + * @hibernate.property column="description" length="65535" + */ + public String getDescription() { + return description; + } - /** - * @hibernate.property column="learner_url" length="65535" - * not-null="true" - */ - public String getLearnerUrl() { - return this.learnerUrl; - } + public void setDescription(String description) { + this.description = description; + } - public void setLearnerUrl(String learnerUrl) { - this.learnerUrl = learnerUrl; - } + /** + * @hibernate.property column="learner_url" length="65535" + * not-null="true" + */ + public String getLearnerUrl() { + return learnerUrl; + } - /** - * @hibernate.property column="learner_preview_url" length="65535" - * not-null="false" - */ - public String getLearnerPreviewUrl() { - return this.learnerPreviewUrl; - } + public void setLearnerUrl(String learnerUrl) { + this.learnerUrl = learnerUrl; + } - public void setLearnerPreviewUrl(String learnerPreviewUrl) { - this.learnerPreviewUrl = learnerPreviewUrl; - } + /** + * @hibernate.property column="learner_preview_url" length="65535" + * not-null="false" + */ + public String getLearnerPreviewUrl() { + return learnerPreviewUrl; + } - /** - * @hibernate.property column="learner_progress_url" length="65535" - * not-null="false" - */ - public String getLearnerProgressUrl() { - return this.learnerProgressUrl; - } + public void setLearnerPreviewUrl(String learnerPreviewUrl) { + this.learnerPreviewUrl = learnerPreviewUrl; + } - public void setLearnerProgressUrl(String learnerProgressUrl) { - this.learnerProgressUrl = learnerProgressUrl; - } + /** + * @hibernate.property column="learner_progress_url" length="65535" + * not-null="false" + */ + public String getLearnerProgressUrl() { + return learnerProgressUrl; + } - /** - * @hibernate.property column="export_pfolio_learner_url" length="65535" - * not-null="false" - */ - public String getExportPortfolioLearnerUrl() { - return this.exportPortfolioLearnerUrl; - } + public void setLearnerProgressUrl(String learnerProgressUrl) { + this.learnerProgressUrl = learnerProgressUrl; + } - public void setExportPortfolioLearnerUrl(String exportPortfolioLearnerUrl) { - this.exportPortfolioLearnerUrl = exportPortfolioLearnerUrl; - } + /** + * @hibernate.property column="export_pfolio_learner_url" length="65535" + * not-null="false" + */ + public String getExportPortfolioLearnerUrl() { + return exportPortfolioLearnerUrl; + } - /** - * @hibernate.property column="export_pfolio_class_url" length="65535" - * not-null="false" - */ - public String getExportPortfolioClassUrl() { - return this.exportPortfolioClassUrl; - } + public void setExportPortfolioLearnerUrl(String exportPortfolioLearnerUrl) { + this.exportPortfolioLearnerUrl = exportPortfolioLearnerUrl; + } - public void setExportPortfolioClassUrl(String exportPortfolioClassUrl) { - this.exportPortfolioClassUrl = exportPortfolioClassUrl; - } + /** + * @hibernate.property column="export_pfolio_class_url" length="65535" + * not-null="false" + */ + public String getExportPortfolioClassUrl() { + return exportPortfolioClassUrl; + } - /** - * @hibernate.property column="admin_url" length="65535" not-null="false" - * @return Returns the helpUrl. - */ - public String getAdminUrl() - { - return adminUrl; - } - /** - * @param helpUrl The helpUrl to set. - */ - public void setAdminUrl(String adminUrl) - { - this.adminUrl = adminUrl; - } + public void setExportPortfolioClassUrl(String exportPortfolioClassUrl) { + this.exportPortfolioClassUrl = exportPortfolioClassUrl; + } - /** - * @hibernate.property column="create_date_time" + /** + * @hibernate.property column="admin_url" length="65535" not-null="false" + * @return Returns the helpUrl. + */ + public String getAdminUrl() { + return adminUrl; + } + + /** + * @param helpUrl The helpUrl to set. + */ + public void setAdminUrl(String adminUrl) { + this.adminUrl = adminUrl; + } + + /** + * @hibernate.property column="create_date_time" length="19" not-null="true" - * @return Returns the createDateTime. - */ - public Date getCreateDateTime() - { - return createDateTime; - } - /** - * @param createDateTime The createDateTime to set. - */ - public void setCreateDateTime(Date createDateTime) - { - this.createDateTime = createDateTime; - } - + * @return Returns the createDateTime. + */ + public Date getCreateDateTime() { + return createDateTime; + } - /** - * Does this tool support contribute? Will be true if the contributeURL is not null/empty string. - */ - public boolean getSupportsContribute() - { - String contributeURL = getContributeUrl(); - return ( contributeURL != null && contributeURL.trim().length() > 0); - } - + /** + * @param createDateTime The createDateTime to set. + */ + public void setCreateDateTime(Date createDateTime) { + this.createDateTime = createDateTime; + } - /** - * @hibernate.property column="contribute_url" length="65535" not-null="false" - * @return Returns the contributeUrl. - */ - public String getContributeUrl() - { - return contributeUrl; - } - /** - * @param contributeUrl The contributUrl to set. - */ - public void setContributeUrl(String contributeUrl) - { - this.contributeUrl = contributeUrl; - } + /** + * Does this tool support contribute? Will be true if the contributeURL is not null/empty string. + */ + public boolean getSupportsContribute() { + String contributeURL = getContributeUrl(); + return contributeURL != null && contributeURL.trim().length() > 0; + } - /** - * @hibernate.property column="monitor_url" length="65535" not-null="false" - * @return Returns the monitorUrl. - */ - public String getMonitorUrl() - { - return monitorUrl; - } - /** - * @param monitorUrl The monitorUrl to set. - */ - public void setMonitorUrl(String monitorUrl) - { - this.monitorUrl = monitorUrl; - } - - /** - * @hibernate.property column="help_url" length="65535" not-null="false" - * @return Returns the helpUrl. - */ - public String getHelpUrl() - { - return helpUrl; - } - /** - * @param helpUrl The helpUrl to set. - */ - public void setHelpUrl(String helpUrl) - { - this.helpUrl = helpUrl; - } - - - public String toString() { - return new ToStringBuilder(this) - .append("systemToolId", getSystemToolId()) - .append("activityTypeId",getActivityTypeId()) - .toString(); - } + /** + * @hibernate.property column="contribute_url" length="65535" not-null="false" + * @return Returns the contributeUrl. + */ + public String getContributeUrl() { + return contributeUrl; + } - public boolean equals(Object other) { - if ( (this == other ) ) return true; - if ( !(other instanceof SystemTool) ) return false; - SystemTool castOther = (SystemTool) other; - return new EqualsBuilder() - .append(this.getSystemToolId(), castOther.getSystemToolId()) - .isEquals(); - } + /** + * @param contributeUrl The contributUrl to set. + */ + public void setContributeUrl(String contributeUrl) { + this.contributeUrl = contributeUrl; + } - public int hashCode() { - return new HashCodeBuilder() - .append(getSystemToolId()) - .toHashCode(); - } + /** + * @hibernate.property column="monitor_url" length="65535" not-null="false" + * @return Returns the monitorUrl. + */ + public String getMonitorUrl() { + return monitorUrl; + } + /** + * @param monitorUrl The monitorUrl to set. + */ + public void setMonitorUrl(String monitorUrl) { + this.monitorUrl = monitorUrl; + } + + /** + * @hibernate.property column="help_url" length="65535" not-null="false" + * @return Returns the helpUrl. + */ + public String getHelpUrl() { + return helpUrl; + } + + /** + * @param helpUrl The helpUrl to set. + */ + public void setHelpUrl(String helpUrl) { + this.helpUrl = helpUrl; + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("systemToolId", getSystemToolId()).append("activityTypeId", getActivityTypeId()) + .toString(); + } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (!(other instanceof SystemTool)) { + return false; + } + SystemTool castOther = (SystemTool) other; + return new EqualsBuilder().append(this.getSystemToolId(), castOther.getSystemToolId()).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(getSystemToolId()).toHashCode(); + } + } Index: lams_learning/conf/language/lams/ApplicationResources.properties =================================================================== diff -u -rc209be8131f22f6fe37bd8d6c14b56425a78b766 -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_learning/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision c209be8131f22f6fe37bd8d6c14b56425a78b766) +++ lams_learning/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -24,6 +24,8 @@ label.synch.gate.title =Synch Gate label.permission.gate.title =Permission Gate label.schedule.gate.title =Schedule Gate +label.condition.gate.title =Conditional Gate +label.condition.gate.close.message=You have reached a conditional gate. You have not satisfied the required condtions and you may not pass. Please return to previous activities. label.schedule.gate.open.message =Schedule Gate will be opened at: label.schedule.gate.close.message =Schedule Gate will be closed at: label.gate.waiting.learners ={0} out of {1} are waiting in front of the gate. Index: lams_learning/conf/language/lams/ApplicationResources_en_AU.properties =================================================================== diff -u -rc209be8131f22f6fe37bd8d6c14b56425a78b766 -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_learning/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision c209be8131f22f6fe37bd8d6c14b56425a78b766) +++ lams_learning/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -24,6 +24,8 @@ label.synch.gate.title =Synch Gate label.permission.gate.title =Permission Gate label.schedule.gate.title =Schedule Gate +label.condition.gate.title =Conditional Gate +label.condition.gate.close.message=You have reached a conditional gate. You have not satisfied the required condtions and you may not pass. Please return to previous activities. label.schedule.gate.open.message =Schedule Gate will be opened at: label.schedule.gate.close.message =Schedule Gate will be closed at: label.gate.waiting.learners ={0} out of {1} are waiting in front of the gate. Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java =================================================================== diff -u -r418a30a76094c56762b5beb23cb2dd72619e316c -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java (.../LearnerService.java) (revision 418a30a76094c56762b5beb23cb2dd72619e316c) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java (.../LearnerService.java) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -45,6 +45,7 @@ import org.lamsfoundation.lams.learningdesign.BranchActivityEntry; import org.lamsfoundation.lams.learningdesign.BranchCondition; import org.lamsfoundation.lams.learningdesign.BranchingActivity; +import org.lamsfoundation.lams.learningdesign.ConditionGateActivity; import org.lamsfoundation.lams.learningdesign.GateActivity; import org.lamsfoundation.lams.learningdesign.Group; import org.lamsfoundation.lams.learningdesign.Grouping; @@ -704,6 +705,10 @@ if (!gateOpen) { // normal case - knock the gate. gateOpen = gate.shouldOpenGateFor(knocker, lessonLearners); + if (!gateOpen) { + //only for a condition gate + gateOpen = determineConditionGateStatus(gate, knocker); + } } //update gate including updating the waiting list and gate status in @@ -1005,6 +1010,58 @@ } /** + * Checks if any of the conditions that open the gate is met. + * @param gate gate to check + * @param learner learner who is knocking to the gate + * @return true if learner satisfied any of the conditions and is allowed to pass + */ + private boolean determineConditionGateStatus(GateActivity gate, User learner) { + boolean shouldOpenGate = false; + if (gate instanceof ConditionGateActivity) { + ConditionGateActivity conditionGate = (ConditionGateActivity) gate; + + // Work out the tool session appropriate for this user and gate activity. We expect there to be only one at this point. + ToolSession toolSession = null; + for (Activity inputActivity : (Set) conditionGate.getInputActivities()) { + toolSession = lamsCoreToolService.getToolSessionByLearner(learner, inputActivity); + } + + if (toolSession != null) { + + Set openingGateConditions = conditionGate.getOpeningGateBranchEntries(); + + // Go through each condition until we find one that passes and that opens the gate. + // Cache the tool output so that we aren't calling it over an over again. + Map toolOutputMap = new HashMap(); + Iterator conditionIterator = openingGateConditions.iterator(); + + while (!shouldOpenGate && conditionIterator.hasNext()) { + BranchCondition condition = conditionIterator.next().getCondition(); + String conditionName = condition.getName(); + ToolOutput toolOutput = toolOutputMap.get(conditionName); + if (toolOutput == null) { + toolOutput = lamsCoreToolService.getOutputFromTool(conditionName, toolSession, learner.getUserId()); + if (toolOutput == null) { + LearnerService.log.warn("Condition " + condition + " refers to a tool output " + conditionName + + " but tool doesn't return any tool output for that name. Skipping this condition."); + } + else { + toolOutputMap.put(conditionName, toolOutput); + } + } + + if (toolOutput != null && condition.isMet(toolOutput)) { + shouldOpenGate = true; + //save the learner to the "allowed to pass" list so we don't check the conditions over and over again (maybe we should??) + conditionGate.addLeaner(learner, true); + } + } + } + } + return shouldOpenGate; + } + + /** * Select a particular branch - we are in preview mode and the author has selected a particular activity. * * @throws LearnerServiceException Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/GateAction.java =================================================================== diff -u -r418a30a76094c56762b5beb23cb2dd72619e316c -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/GateAction.java (.../GateAction.java) (revision 418a30a76094c56762b5beb23cb2dd72619e316c) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/GateAction.java (.../GateAction.java) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -78,6 +78,7 @@ * @struts:action-forward name="permissionGate" path=".permissionGate" * @struts:action-forward name="scheduleGate" path=".scheduleGate" * @struts:action-forward name="synchGate" path=".synchGate" + * @struts:action-forward name="conditionGate" path=".conditionGate" * ----------------XDoclet Tags-------------------- */ public class GateAction extends LamsDispatchAction { @@ -93,6 +94,7 @@ private static final String VIEW_PERMISSION_GATE = "permissionGate"; private static final String VIEW_SCHEDULE_GATE = "scheduleGate"; private static final String VIEW_SYNCH_GATE = "synchGate"; + private static final String VIEW_CONDITION_GATE = "conditionGate"; /** Input parameter. Boolean value */ public static final String PARAM_FORCE_GATE_OPEN = "force"; @@ -185,6 +187,9 @@ gateForm.set("endingTime", scheduleGate.getGateEndDateTime()); return mapping.findForward(GateAction.VIEW_SCHEDULE_GATE); } + else if (gate.isConditionGate()) { + return mapping.findForward(GateAction.VIEW_CONDITION_GATE); + } else if (gate.isPermissionGate() || gate.isSystemGate()) { return mapping.findForward(GateAction.VIEW_PERMISSION_GATE); } Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/bean/GateActivityDTO.java =================================================================== diff -u -r418a30a76094c56762b5beb23cb2dd72619e316c -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/bean/GateActivityDTO.java (.../GateActivityDTO.java) (revision 418a30a76094c56762b5beb23cb2dd72619e316c) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/bean/GateActivityDTO.java (.../GateActivityDTO.java) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -287,6 +287,10 @@ return gateActivity.isSynchGate(); } + public boolean isConditionGate() { + return gateActivity.isConditionGate(); + } + public boolean isSystemGate() { return gateActivity.isSystemGate(); } Index: lams_learning/web/WEB-INF/struts/struts-config.xml =================================================================== diff -u -rc209be8131f22f6fe37bd8d6c14b56425a78b766 -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_learning/web/WEB-INF/struts/struts-config.xml (.../struts-config.xml) (revision c209be8131f22f6fe37bd8d6c14b56425a78b766) +++ lams_learning/web/WEB-INF/struts/struts-config.xml (.../struts-config.xml) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -116,6 +116,11 @@ path=".synchGate" redirect="false" /> + + + + + Index: lams_learning/web/gate/conditionGateContent.jsp =================================================================== diff -u --- lams_learning/web/gate/conditionGateContent.jsp (revision 0) +++ lams_learning/web/gate/conditionGateContent.jsp (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -0,0 +1,24 @@ + <%-- + 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 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 + --%> + + <%@ taglib uri="tags-fmt" prefix="fmt" %> + +

\ No newline at end of file Index: lams_monitoring/conf/language/lams/ApplicationResources.properties =================================================================== diff -u -r418a30a76094c56762b5beb23cb2dd72619e316c -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_monitoring/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 418a30a76094c56762b5beb23cb2dd72619e316c) +++ lams_monitoring/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -15,6 +15,7 @@ label.synch.gate.title =Synch Gate label.permission.gate.title =Permission Gate label.schedule.gate.title =Schedule Gate +label.condtion.gate.title =Conditional Gate label.schedule.gate.open.message =Schedule Gate will be opened at: label.schedule.gate.close.message =Schedule Gate will be closed at: label.gate.you.open.message =You may open the gate for the whole class Index: lams_monitoring/conf/language/lams/ApplicationResources_en_AU.properties =================================================================== diff -u -r418a30a76094c56762b5beb23cb2dd72619e316c -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_monitoring/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision 418a30a76094c56762b5beb23cb2dd72619e316c) +++ lams_monitoring/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -15,6 +15,7 @@ label.synch.gate.title =Synch Gate label.permission.gate.title =Permission Gate label.schedule.gate.title =Schedule Gate +label.condtion.gate.title =Conditional Gate label.schedule.gate.open.message =Schedule Gate will be opened at: label.schedule.gate.close.message =Schedule Gate will be closed at: label.gate.you.open.message =You may open the gate for the whole class Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java =================================================================== diff -u -r418a30a76094c56762b5beb23cb2dd72619e316c -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 418a30a76094c56762b5beb23cb2dd72619e316c) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -1014,7 +1014,7 @@ public GateActivity openGateForSingleUser(Long gateId, Integer userId) { GateActivity gate = (GateActivity) activityDAO.getActivityByActivityId(gateId); - if (gate != null && gate.isPermissionGate() && userId != null && userId >= 0) { + if (gate != null && userId != null && userId >= 0) { User user = (User) baseDAO.find(User.class, userId); gate.addLeaner(user, true); activityDAO.update(gate); @@ -1134,7 +1134,7 @@ else if (activity.isGateActivity()) { GateActivity gate = (GateActivity) activity; GateActivityDTO dto = learnerService.knockGate(gate, learner, false); - if (dto.getGateOpen()) { + if (dto.getAllowToPass()) { //the gate is opened, continue to next activity to complete learnerService.completeActivity(learner.getUserId(), activity, lessonId); if (MonitoringService.log.isDebugEnabled()) { @@ -1856,6 +1856,9 @@ table.put("gateStartTime", scheduleGate.getGateStartDateTime()); table.put("gateEndTime", scheduleGate.getGateEndDateTime()); } + else if (gate.isPermissionGate() || gate.isConditionGate()) { + table.put("allowedToPassLearnerList", gate.getAllowedToPassLearners()); + } return table; } Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/GateAction.java =================================================================== diff -u -r418a30a76094c56762b5beb23cb2dd72619e316c -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/GateAction.java (.../GateAction.java) (revision 418a30a76094c56762b5beb23cb2dd72619e316c) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/GateAction.java (.../GateAction.java) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -94,6 +94,7 @@ private static final String VIEW_SYNCH_GATE = "viewSynchGate"; private static final String VIEW_PERMISSION_GATE = "viewPermissionGate"; private static final String VIEW_SCHEDULE_GATE = "viewScheduleGate"; + private static final String VIEW_CONDITION_GATE = "viewConditionGate"; // Gate Form fields private static final String ACTIVITY_FORM_FIELD = "activityId"; @@ -261,6 +262,11 @@ else if (gate.isScheduleGate()) { return viewScheduleGate(mapping, gateForm, (ScheduleGateActivity) gate); } + else if (gate.isConditionGate()) { + gateForm.set("allowedToPassLearnerList", gate.getAllowedToPassLearners()); + gateForm.set(GateAction.READ_ONLY, Boolean.TRUE); + return mapping.findForward(GateAction.VIEW_CONDITION_GATE); + } else if (gate.isPermissionGate() || gate.isSystemGate()) { gateForm.set("waitingLearnerList", waitingLearnersList); gateForm.set("allowedToPassLearnerList", gate.getAllowedToPassLearners()); Index: lams_monitoring/test/web/WEB-INF/struts/tiles-defs.xml =================================================================== diff -u -r08950e1090443c3423a3d1c587416a2fccd8bbdf -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_monitoring/test/web/WEB-INF/struts/tiles-defs.xml (.../tiles-defs.xml) (revision 08950e1090443c3423a3d1c587416a2fccd8bbdf) +++ lams_monitoring/test/web/WEB-INF/struts/tiles-defs.xml (.../tiles-defs.xml) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -52,6 +52,11 @@
+ + + + + Index: lams_monitoring/web/WEB-INF/struts/struts-config.xml =================================================================== diff -u -rc209be8131f22f6fe37bd8d6c14b56425a78b766 -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_monitoring/web/WEB-INF/struts/struts-config.xml (.../struts-config.xml) (revision c209be8131f22f6fe37bd8d6c14b56425a78b766) +++ lams_monitoring/web/WEB-INF/struts/struts-config.xml (.../struts-config.xml) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -22,6 +22,10 @@ + + + + Index: lams_monitoring/web/WEB-INF/struts/tiles-defs.xml =================================================================== diff -u -r3bfbf85ce0639b4cd2957e34a978a22da5e7d66f -r209087915bc219f430c282ad00e5d1e6462f9b5f --- lams_monitoring/web/WEB-INF/struts/tiles-defs.xml (.../tiles-defs.xml) (revision 3bfbf85ce0639b4cd2957e34a978a22da5e7d66f) +++ lams_monitoring/web/WEB-INF/struts/tiles-defs.xml (.../tiles-defs.xml) (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -41,6 +41,9 @@ + + + Index: lams_monitoring/web/gate/conditionGateContent.jsp =================================================================== diff -u --- lams_monitoring/web/gate/conditionGateContent.jsp (revision 0) +++ lams_monitoring/web/gate/conditionGateContent.jsp (revision 209087915bc219f430c282ad00e5d1e6462f9b5f) @@ -0,0 +1,39 @@ + <%-- + 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 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 + --%> + + <%@ taglib uri="tags-html" prefix="html" %> + <%@ taglib uri="tags-bean" prefix="bean" %> + <%@ taglib uri="tags-logic" prefix="logic" %> + <%@ taglib uri="tags-core" prefix="c" %> + <%@ taglib uri="tags-fmt" prefix="fmt" %> + +
+

+ + <%@ include file="gateInfo.jsp" %> + +

+ +
\ No newline at end of file