Index: lams_build/lib/lams/lams-central.jar =================================================================== diff -u -r1dc37842a92ae51d781a8ec18f6d9fc28f00d568 -r01a4035d52575ebe0a8467b4e589998196353962 Binary files differ Index: lams_build/lib/lams/lams-learning.jar =================================================================== diff -u -r9caa0418dd527221031dd5828fa3b3e32da2a7fc -r01a4035d52575ebe0a8467b4e589998196353962 Binary files differ Index: lams_build/lib/lams/lams-monitoring.jar =================================================================== diff -u -rd2c7363ac0242caa259b49112d85ffa9671c30e6 -r01a4035d52575ebe0a8467b4e589998196353962 Binary files differ Index: lams_build/lib/lams/lams.jar =================================================================== diff -u -rb6c2c2e56b1dbcc7e995976be7b57bd2475cbeff -r01a4035d52575ebe0a8467b4e589998196353962 Binary files differ Index: lams_central/src/java/org/lamsfoundation/lams/authoring/IObjectExtractor.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/authoring/IObjectExtractor.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/IObjectExtractor.java (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -0,0 +1,39 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id$ */ +package org.lamsfoundation.lams.authoring; + +import java.util.Hashtable; + +import org.lamsfoundation.lams.learningdesign.LearningDesign; +import org.lamsfoundation.lams.util.wddx.WDDXProcessorConversionException; + +public interface IObjectExtractor { + + public static final String OBJECT_EXTRACTOR_SPRING_BEANNAME = "ObjectExtractor"; + + public abstract LearningDesign extractSaveLearningDesign(Hashtable table) + throws WDDXProcessorConversionException, ObjectExtractorException; + +} \ No newline at end of file Index: lams_central/src/java/org/lamsfoundation/lams/authoring/ObjectExtractor.java =================================================================== diff -u -rdc843033407c7ce39890683caf05ee91daa3ee82 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_central/src/java/org/lamsfoundation/lams/authoring/ObjectExtractor.java (.../ObjectExtractor.java) (revision dc843033407c7ce39890683caf05ee91daa3ee82) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/ObjectExtractor.java (.../ObjectExtractor.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -22,7 +22,7 @@ */ package org.lamsfoundation.lams.authoring; -import java.util.HashSet; +import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.List; @@ -82,8 +82,10 @@ * If the value of a field is one of the special null values, then null * should be persisted. * + * Object extractor has member data, so it should not be used as a singleton. + * */ -public class ObjectExtractor { +public class ObjectExtractor implements IObjectExtractor { protected UserDAO userDAO = null; protected LearningDesignDAO learningDesignDAO = null; @@ -95,10 +97,21 @@ protected GroupingDAO groupingDAO = null; protected ToolDAO toolDAO = null; protected GroupDAO groupDAO = null; - + + /** The newActivityMap is a local copy of all the current activities. This will include + * the "top level" activities and subactivities. It is used to "crossreference" activities + * as we go, without having to repull them from the database. The keys are the UIIDs + * of the activities, not the IDs. It is important that the values in this map are the Activity + * objects related to the Hibernate session as they are updated by the parseTransitions code. + */ + protected HashMap newActivityMap = new HashMap(); protected Logger log = Logger.getLogger(ObjectExtractor.class); - + /** Constructor to be used if Spring method injection is used */ + public ObjectExtractor() { + } + + /** Constructor to be used if Spring method injection is not used */ public ObjectExtractor(UserDAO userDAO, LearningDesignDAO learningDesignDAO, ActivityDAO activityDAO, WorkspaceFolderDAO workspaceFolderDAO, @@ -116,17 +129,108 @@ this.groupDAO = groupDAO; this.transitionDAO = transitionDAO; } - public LearningDesign extractLearningDesign(Hashtable table) throws WDDXProcessorConversionException, ObjectExtractorException { + + /** Spring injection methods */ + public ActivityDAO getActivityDAO() { + return activityDAO; + } + public void setActivityDAO(ActivityDAO activityDAO) { + this.activityDAO = activityDAO; + } + + public GroupDAO getGroupDAO() { + return groupDAO; + } + + public void setGroupDAO(GroupDAO groupDAO) { + this.groupDAO = groupDAO; + } + + public GroupingDAO getGroupingDAO() { + return groupingDAO; + } + + public void setGroupingDAO(GroupingDAO groupingDAO) { + this.groupingDAO = groupingDAO; + } + + public LearningDesignDAO getLearningDesignDAO() { + return learningDesignDAO; + } + + public void setLearningDesignDAO(LearningDesignDAO learningDesignDAO) { + this.learningDesignDAO = learningDesignDAO; + } + + public LearningLibraryDAO getLearningLibraryDAO() { + return learningLibraryDAO; + } + + public void setLearningLibraryDAO(LearningLibraryDAO learningLibraryDAO) { + this.learningLibraryDAO = learningLibraryDAO; + } + + public LicenseDAO getLicenseDAO() { + return licenseDAO; + } + + public void setLicenseDAO(LicenseDAO licenseDAO) { + this.licenseDAO = licenseDAO; + } + + public HashMap getNewActivityMap() { + return newActivityMap; + } + + public void setNewActivityMap(HashMap newActivityMap) { + this.newActivityMap = newActivityMap; + } + + public ToolDAO getToolDAO() { + return toolDAO; + } + + public void setToolDAO(ToolDAO toolDAO) { + this.toolDAO = toolDAO; + } + + public TransitionDAO getTransitionDAO() { + return transitionDAO; + } + + public void setTransitionDAO(TransitionDAO transitionDAO) { + this.transitionDAO = transitionDAO; + } + + public UserDAO getUserDAO() { + return userDAO; + } + + public void setUserDAO(UserDAO userDAO) { + this.userDAO = userDAO; + } + + public WorkspaceFolderDAO getWorkspaceFolderDAO() { + return workspaceFolderDAO; + } + + public void setWorkspaceFolderDAO(WorkspaceFolderDAO workspaceFolderDAO) { + this.workspaceFolderDAO = workspaceFolderDAO; + } + + /* (non-Javadoc) + * @see org.lamsfoundation.lams.authoring.IObjectExtractor#extractSaveLearningDesign(java.util.Hashtable) + */ + public LearningDesign extractSaveLearningDesign(Hashtable table) throws WDDXProcessorConversionException, ObjectExtractorException { + LearningDesign learningDesign = null; Long learningDesignId = WDDXProcessor.convertToLong(table, "learningDesignID"); //if the learningDesignID is not null, load the existing LearningDesign object from the database, otherwise create a new one. learningDesign = learningDesignId!= null ? learningDesignDAO.getLearningDesignById(learningDesignId) : new LearningDesign(); //get the core learning design stuff - //LearningDesign learningDesign = new LearningDesign(); - if (keyExists(table, WDDXTAGS.LEARNING_DESIGN_UIID)) learningDesign.setLearningDesignUIID(WDDXProcessor.convertToInteger(table,WDDXTAGS.LEARNING_DESIGN_UIID)); if (keyExists(table, WDDXTAGS.DESCRIPTION)) @@ -224,7 +328,7 @@ } - learningDesignDAO.insert(learningDesign); + learningDesignDAO.insertOrUpdate(learningDesign); // now process the "parts" of the learning design //Vector v = (Vector)table.get(WDDXTAGS.GROUPINGS); @@ -234,7 +338,7 @@ parseTransitions((Vector)table.get(WDDXTAGS.TRANSITIONS),learningDesign); learningDesign.setFirstActivity(learningDesign.calculateFirstActivity()); - learningDesignDAO.update(learningDesign); + learningDesignDAO.insertOrUpdate(learningDesign); return learningDesign; } @@ -246,11 +350,10 @@ * @param groupingsList * @param learningDesign * @throws WDDXProcessorConversionException - * @throws ObjectExtractorException */ private void parseGroupings(List groupingsList, LearningDesign learningDesign) - throws WDDXProcessorConversionException, ObjectExtractorException + throws WDDXProcessorConversionException { //iterate through the list of groupings objects //each object should contain information groupingUUID, groupingID, groupingTypeID @@ -263,7 +366,7 @@ if( groupingDetails != null ) { Grouping grouping = extractGroupingObject(groupingDetails); - groupingDAO.insert(grouping); + groupingDAO.insertOrUpdate(grouping); } } @@ -289,35 +392,28 @@ */ private void parseActivities(List activitiesList, LearningDesign learningDesign) throws WDDXProcessorConversionException, ObjectExtractorException { - HashSet updatedSet = new HashSet(); - Set currentActivities = learningDesign.getActivities(); + if(activitiesList!=null){ Iterator iterator = activitiesList.iterator(); while(iterator.hasNext()){ Hashtable activityDetails = (Hashtable)iterator.next(); Activity activity = extractActivityObject(activityDetails,learningDesign); - activityDAO.insert(activity); - currentActivities.add(activity); - updatedSet.add(activity); //used to keep track of which ids that are still in use + activityDAO.insertOrUpdate(activity); + newActivityMap.put(activity.getActivityUIID(), activity); } } + + // clear the transitions + // clear the old set and reset up the activities set. Done this way to keep the Hibernate cascading happy. + // this means we don't have to manually remove the transition object. + // Note: This will leave orphan content in the tool tables. It can be removed by the tool content cleaning job, + // which may be run from the admin screen or via a cron job. + + learningDesign.getActivities().clear(); + learningDesign.getActivities().addAll(newActivityMap.values()); - - /* Iterate through currentActivities, any activities that arent present in the updatedSet will be deleted */ - Iterator itr = currentActivities.iterator(); - - while (itr.hasNext()) - { - Activity activity = (Activity)itr.next(); - if (!updatedSet.contains(activity)) - { - itr.remove(); //removes object from collection; - deleteActivity(activity, learningDesign); - } - } //TODO: Need to double check that the toolID/toolContentID combinations match entries in lams_tool_content table, or put FK on table. - learningDesign.setActivities(currentActivities); - learningDesignDAO.update(learningDesign); + learningDesignDAO.insertOrUpdate(learningDesign); } /** @@ -341,14 +437,14 @@ Hashtable activityDetails = (Hashtable)iterator.next(); Integer activityUUID = WDDXProcessor.convertToInteger(activityDetails,WDDXTAGS.ACTIVITY_UIID); - Activity existingActivity = activityDAO.getActivityByUIID(activityUUID, learningDesign); + Activity existingActivity = newActivityMap.get(activityUUID); //match up id to parent based on UIID if (keyExists(activityDetails, WDDXTAGS.PARENT_UIID)) { Integer parentUIID = WDDXProcessor.convertToInteger(activityDetails, WDDXTAGS.PARENT_UIID); if( parentUIID!=null ) { - Activity parentActivity = activityDAO.getActivityByUIID(parentUIID,learningDesign); + Activity parentActivity = newActivityMap.get(parentUIID); existingActivity.setParentActivity(parentActivity); existingActivity.setParentUIID(parentUIID); } else { @@ -375,41 +471,41 @@ */ private void parseTransitions(List transitionsList, LearningDesign learningDesign) throws WDDXProcessorConversionException{ - HashSet updatedSet = new HashSet(); - Set currentTransitions = learningDesign.getTransitions(); - if (currentTransitions == null) - currentTransitions = new HashSet(); + HashMap newMap = new HashMap(); if(transitionsList!=null){ Iterator iterator= transitionsList.iterator(); while(iterator.hasNext()){ Hashtable transitionDetails = (Hashtable)iterator.next(); Transition transition = extractTransitionObject(transitionDetails,learningDesign); - transitionDAO.insert(transition); - currentTransitions.add(transition); - updatedSet.add(transition); + // Check if transition actually exists. extractTransitionObject returns null + // if neither the to/from activity exists. + if ( transition != null ) { + transitionDAO.insertOrUpdate(transition); + newMap.put(transition.getTransitionUIID(),transition); + } } } - - Iterator itr = currentTransitions.iterator(); - - while (itr.hasNext()) - { - Transition transition = (Transition)itr.next(); - if (!updatedSet.contains(transition)) - { - /* This will leave orphan content in the tool tables. It can be removed by the tool content cleaning job, - which may be run from the admin screen or via a cron job. However, the transitionDAO.delete() method is - called to actually delete the object */ - - itr.remove(); - transitionDAO.delete(transition); - - } + + // clean up the links for any old transitions. + Iterator iter = learningDesign.getTransitions().iterator(); + while (iter.hasNext()) { + Transition element = (Transition) iter.next(); + Integer uiID = element.getTransitionUIID(); + Transition match = newMap.get(uiID); + if ( match == null ) { + // transition is no more, clean up the old activity links + cleanupTransition(element); + } } + // clear the old set and reset up the transition set. Done this way to keep the Hibernate cascading happy. + // this means we don't have to manually remove the transition object. + // Note: This will leave orphan content in the tool tables. It can be removed by the tool content cleaning job, + // which may be run from the admin screen or via a cron job. + learningDesign.getTransitions().clear(); + learningDesign.getTransitions().addAll(newMap.values()); - learningDesign.setTransitions(currentTransitions); - learningDesignDAO.update(learningDesign); + learningDesignDAO.insertOrUpdate(learningDesign); } @@ -452,19 +548,6 @@ if (keyExists(activityDetails, WDDXTAGS.YCOORD)) activity.setYcoord(WDDXProcessor.convertToInteger(activityDetails, WDDXTAGS.YCOORD)); - if (keyExists(activityDetails, WDDXTAGS.PARENT_UIID)) - { - Integer parentUIID = WDDXProcessor.convertToInteger(activityDetails, WDDXTAGS.PARENT_UIID); - if( parentUIID!=null ) { - Activity parentActivity = activityDAO.getActivityByUIID(parentUIID,design); - activity.setParentActivity(parentActivity); - activity.setParentUIID(parentUIID); - } else { - activity.setParentActivity(null); - activity.setParentUIID(null); - } - } - if (keyExists(activityDetails, WDDXTAGS.GROUPING_ID)) { Long groupingID = WDDXProcessor.convertToLong(activityDetails,WDDXTAGS.GROUPING_ID); @@ -506,17 +589,6 @@ if (keyExists(activityDetails, WDDXTAGS.LIBRARY_IMAGE)) activity.setLibraryActivityUiImage(WDDXProcessor.convertToString(activityDetails,WDDXTAGS.LIBRARY_IMAGE)); - if (keyExists(activityDetails, WDDXTAGS.LIBRARY_ACTIVITY)) - { - Long libraryActivityID = WDDXProcessor.convertToLong(activityDetails,WDDXTAGS.LIBRARY_ACTIVITY); - if( libraryActivityID != null ){ - Activity libraryActivity = activityDAO.getActivityByActivityId(libraryActivityID); - activity.setLibraryActivity(libraryActivity); - } else { - activity.setLibraryActivity(null); - } - } - if (keyExists(activityDetails, WDDXTAGS.APPLY_GROUPING)) activity.setApplyGrouping(WDDXProcessor.convertToBoolean(activityDetails,WDDXTAGS.APPLY_GROUPING)); if (keyExists(activityDetails, WDDXTAGS.GROUPING_SUPPORT_TYPE)) @@ -613,14 +685,14 @@ } - public Grouping extractGroupingObject(Hashtable groupingDetails) throws WDDXProcessorConversionException, ObjectExtractorException{ + public Grouping extractGroupingObject(Hashtable groupingDetails) throws WDDXProcessorConversionException{ //get grouping by uuid Grouping grouping; Integer groupingUUID = WDDXProcessor.convertToInteger(groupingDetails, WDDXTAGS.GROUPING_UIID); Integer groupingTypeID=WDDXProcessor.convertToInteger(groupingDetails,WDDXTAGS.GROUPING_TYPE_ID); if (groupingTypeID== null) { - throw new ObjectExtractorException("groupingTypeID is missing"); + throw new WDDXProcessorConversionException("groupingTypeID is missing"); } Grouping existingGrouping = groupingDAO.getGroupingByUIID(groupingUUID); if (existingGrouping != null) @@ -671,24 +743,32 @@ * straight to the data object rather than going via the DTO, as the DTO * returns the special null values from the getter methods. This makes it * hard to set up the transaction object from the transitionDTO. + *

+ * Assumes that all the activities have been read and are in the newActivityMap. + * The toActivity and fromActivity are only set if the activity exists in the + * newActivityMap. If this leaves the transition with no to/from activities + * then null is returned. * * @param transitionDetails * @throws WDDXProcessorConversionException */ private Transition extractTransitionObject(Hashtable transitionDetails, LearningDesign learningDesign) throws WDDXProcessorConversionException{ Integer transitionUUID = WDDXProcessor.convertToInteger(transitionDetails,WDDXTAGS.TRANSITION_UIID); + if ( transitionUUID == null ) { + throw new WDDXProcessorConversionException("Transition is missing its UUID"); + } + Transition transition = null; - /* It is assumed that the transitionUUID will always be sent */ - Transition existingTransition = transitionDAO.getTransitionByUUID(transitionUUID, learningDesign); - - if (existingTransition == null) - transition = new Transition(); - else + Transition existingTransition = findTransition(learningDesign, transitionUUID); + + if (existingTransition == null) { + transition = new Transition(); + transition.setTransitionUIID(transitionUUID); + } else { transition = existingTransition; + } - transition.setTransitionUIID(transitionUUID); - if (keyExists(transitionDetails, WDDXTAGS.TRANSITION_ID)) { Long transitionID= WDDXProcessor.convertToLong(transitionDetails,WDDXTAGS.TRANSITION_ID); @@ -700,27 +780,33 @@ { Integer toUIID=WDDXProcessor.convertToInteger(transitionDetails,WDDXTAGS.TO_ACTIVITY_UIID); if(toUIID!=null){ - Activity toActivity = activityDAO.getActivityByUIID(toUIID, learningDesign); - transition.setToActivity(toActivity); - transition.setToUIID(toUIID); - //update the transitionTo property for the activity - toActivity.setTransitionTo(transition); - activityDAO.update(toActivity); - + Activity toActivity = newActivityMap.get(toUIID); + if ( toActivity != null ) { + transition.setToActivity(toActivity); + transition.setToUIID(toUIID); + //update the transitionTo property for the activity + toActivity.setTransitionTo(transition); + } else { + transition.setToActivity(null); + transition.setToUIID(null); + } } } if (keyExists(transitionDetails, WDDXTAGS.FROM_ACTIVITY_UIID)) { Integer fromUIID=WDDXProcessor.convertToInteger(transitionDetails,WDDXTAGS.FROM_ACTIVITY_UIID); if(fromUIID!=null){ - Activity fromActivity = activityDAO.getActivityByUIID(fromUIID, learningDesign); - transition.setFromActivity(fromActivity); - transition.setFromUIID(fromUIID); - //update the transitionFrom property for the activity - fromActivity.setTransitionFrom(transition); - activityDAO.update(fromActivity); - + Activity fromActivity = newActivityMap.get(fromUIID); + if ( fromActivity != null ) { + transition.setFromActivity(fromActivity); + transition.setFromUIID(fromUIID); + //update the transitionFrom property for the activity + fromActivity.setTransitionFrom(transition); + } else { + transition.setFromActivity(null); + transition.setFromUIID(null); + } } } @@ -730,9 +816,46 @@ transition.setTitle(WDDXProcessor.convertToString(transitionDetails,WDDXTAGS.TITLE)); if(keyExists(transitionDetails, WDDXTAGS.CREATION_DATE)) transition.setCreateDateTime(WDDXProcessor.convertToDate(transitionDetails,WDDXTAGS.CREATION_DATE)); - - transition.setLearningDesign(learningDesign); - return transition; + + if ( transition.getToActivity() != null && transition.getFromActivity() != null ) { + transition.setLearningDesign(learningDesign); + return transition; + } else { + // One of the to/from is missing, can't store this transition. Make sure we clean up the related activities + cleanupTransition(transition); + transition.setLearningDesign(null); + return null; + } + } + + /** + * Wipe out any links fromany activities that may be linked to it (e.g. the case where a transition has an from activity + * but not a too activity. These cases should be picked up by Flash, but just in case. + */ + private void cleanupTransition(Transition transition) { + if ( transition.getFromActivity() != null ) { + transition.getFromActivity().setTransitionFrom(null); + } + if ( transition.getToActivity() != null ) { + transition.getToActivity().setTransitionTo(null); + } + } + + /** Search in learning design for existing object. Can't go to database as that will trigger + * a Flush, and we haven't updated the rest of the design, so this would trigger a + * "deleted object would be re-saved by cascade" error. + */ + private Transition findTransition(LearningDesign learningDesign, Integer transitionUUID) { + Transition existingTransition = null; + Set transitions = learningDesign.getTransitions(); + Iterator iter = transitions.iterator(); + while (existingTransition==null && iter.hasNext()) { + Transition element = (Transition) iter.next(); + if ( transitionUUID.equals(element.getTransitionUIID()) ) { + existingTransition = element; + } + } + return existingTransition; } /** @@ -757,7 +880,7 @@ * @param activityToDelete * @param design */ - private void deleteActivity(Activity activityToDelete, LearningDesign design) + private void clearTransition(Activity activityToDelete, LearningDesign design) { Transition transitionFrom = activityToDelete.getTransitionFrom(); @@ -766,10 +889,8 @@ Transition transitionTo = activityToDelete.getTransitionTo(); if (transitionTo != null) - deleteTransition(transitionTo, design); - - activityDAO.delete(activityToDelete); - + deleteTransition(transitionTo, design); + } /** @@ -782,18 +903,13 @@ { Activity fromActivity = transition.getFromActivity(); fromActivity.setTransitionFrom(null); - activityDAO.update(fromActivity); Activity toActivity = transition.getToActivity(); toActivity.setTransitionTo(null); - activityDAO.update(toActivity); //This will leave orphan content in the tool tables. It will be removed by the tool content cleaning job, //which may be run from the admin screen or via a cron job design.getTransitions().remove(transition); - - //actually delete the object from the table. - transitionDAO.delete(transition); } } Index: lams_central/src/java/org/lamsfoundation/lams/authoring/authoringApplicationContext.xml =================================================================== diff -u -r25ca503e49d83e167cf7661d8b67b4547ee0cb87 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_central/src/java/org/lamsfoundation/lams/authoring/authoringApplicationContext.xml (.../authoringApplicationContext.xml) (revision 25ca503e49d83e167cf7661d8b67b4547ee0cb87) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/authoringApplicationContext.xml (.../authoringApplicationContext.xml) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -21,6 +21,19 @@ + + + + + + + + + + + + + Index: lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java =================================================================== diff -u -r6eeaebc91f39f81fc4efac62377a7235184e7259 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java (.../AuthoringService.java) (revision 6eeaebc91f39f81fc4efac62377a7235184e7259) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java (.../AuthoringService.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -35,7 +35,7 @@ import java.util.Vector; import org.apache.log4j.Logger; -import org.lamsfoundation.lams.authoring.ObjectExtractor; +import org.lamsfoundation.lams.authoring.IObjectExtractor; import org.lamsfoundation.lams.authoring.ObjectExtractorException; import org.lamsfoundation.lams.authoring.dto.StoreLearningDesignResultsDTO; import org.lamsfoundation.lams.learningdesign.Activity; @@ -77,14 +77,16 @@ import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.wddx.FlashMessage; import org.lamsfoundation.lams.util.wddx.WDDXProcessor; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; /** * @author Manpreet Minhas */ -public class AuthoringService implements IAuthoringService { +public class AuthoringService implements IAuthoringService, BeanFactoryAware { protected Logger log = Logger.getLogger(AuthoringService.class); @@ -106,6 +108,9 @@ protected ToolContentIDGenerator contentIDGenerator; + /** The bean factory is used to create ObjectExtractor objects */ + protected BeanFactory beanFactory; + public AuthoringService(){ } @@ -233,7 +238,7 @@ * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#saveLearningDesign(org.lamsfoundation.lams.learningdesign.LearningDesign) */ public void saveLearningDesign(LearningDesign learningDesign){ - learningDesignDAO.insert(learningDesign); + learningDesignDAO.insertOrUpdate(learningDesign); } /** * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#getAllLearningDesigns() @@ -243,20 +248,20 @@ } /** - * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#updateLearningDesign(org.lamsfoundation.lams.learningdesign.LearningDesign) - */ - public void updateLearningDesign(LearningDesign learningDesign) { - learningDesignDAO.update(learningDesign); - } - - /** * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#getAllLearningLibraries() */ public List getAllLearningLibraries(){ return learningLibraryDAO.getAllLearningLibraries(); } - + public BeanFactory getBeanFactory() { + return beanFactory; + } + + public void setBeanFactory(BeanFactory beanFactory) { + this.beanFactory = beanFactory; + } + /********************************************** * Utility/Service Methods * *******************************************/ @@ -265,7 +270,6 @@ * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#getLearningDesignDetails(java.lang.Long) */ public String getLearningDesignDetails(Long learningDesignID)throws IOException{ - String wddxPacket = null; LearningDesign design = learningDesignDAO.getLearningDesignById(learningDesignID); if(design==null) flashMessage = FlashMessage.getNoSuchLearningDesignExists("getLearningDesignDetails",learningDesignID); @@ -305,67 +309,57 @@ newLearningDesign.setWorkspaceFolder(workspaceFolder); learningDesignDAO.insert(newLearningDesign); updateDesignActivities(originalLearningDesign,newLearningDesign); - calculateFirstActivity(originalLearningDesign,newLearningDesign); updateDesignTransitions(originalLearningDesign,newLearningDesign); + // set first activity assumes that the transitions are all set up correctly. + newLearningDesign.setFirstActivity(newLearningDesign.calculateFirstActivity()); + newLearningDesign.setLearningDesignUIID(originalLearningDesign.getLearningDesignUIID()); return newLearningDesign; } /** - * Calculates the First activity of the LearningDesign. - *

- * The activity_ui_id is unique per LearningDesign. So when a LearningDesign is deep-copied - * all the activities in the newDesign would have the same activity_ui_id as the oldDesign. - * This mean that the firstActivity of the newDesign would have the same activity_ui_id - * as the oldDesign.So in order to determine the firstActivity of the newDesign we look for an - * activity which has an activity_ui_id same as that of the oldDesign and - * learning_design_id as the newDesign - *

- * - * @param oldDesign The LearningDesign to be copied - * @param newDesign The copy of the originalLearningDesign - */ - private void calculateFirstActivity(LearningDesign oldDesign,LearningDesign newDesign){ - Integer oldUIID = oldDesign.getFirstActivity().getActivityUIID(); - Activity firstActivity = activityDAO.getActivityByUIID(oldUIID,newDesign); - newDesign.setFirstActivity(firstActivity); - Integer learning_design_ui_id = newDesign.getLearningDesignUIID(); - newDesign.setLearningDesignUIID(learning_design_ui_id); - } - - /** * Updates the Activity information in the newLearningDesign based * on the originalLearningDesign * * @param originalLearningDesign The LearningDesign to be copied * @param newLearningDesign The copy of the originalLearningDesign */ private void updateDesignActivities(LearningDesign originalLearningDesign, LearningDesign newLearningDesign){ - HashSet newActivities = new HashSet(); - TreeSet oldParentActivities = new TreeSet(new ActivityOrderComparator()); - oldParentActivities.addAll(originalLearningDesign.getParentActivities()); - Iterator iterator = oldParentActivities.iterator(); - while(iterator.hasNext()){ - Activity parentActivity = (Activity)iterator.next(); - Activity newParentActivity = getActivityCopy(parentActivity); - newParentActivity.setLearningDesign(newLearningDesign); - activityDAO.insert(newParentActivity); - newActivities.add(newParentActivity); - - TreeSet oldChildActivities = new TreeSet(new ActivityOrderComparator()); - oldChildActivities.addAll(getChildActivities((Activity)parentActivity)); - Iterator childIterator = oldChildActivities.iterator(); - - while(childIterator.hasNext()){ - Activity childActivity = (Activity)childIterator.next(); - Activity newChildActivity = getActivityCopy(childActivity); - newChildActivity.setParentActivity(newParentActivity); - newChildActivity.setParentUIID(newParentActivity.getActivityUIID()); - newChildActivity.setLearningDesign(newLearningDesign); - activityDAO.insert(newChildActivity); - newActivities.add(newChildActivity); - } + TreeSet newActivities = new TreeSet(new ActivityOrderComparator()); + + Set oldParentActivities = originalLearningDesign.getParentActivities(); + if ( oldParentActivities != null ) { + Iterator iterator = oldParentActivities.iterator(); + while(iterator.hasNext()){ + Activity parentActivity = (Activity)iterator.next(); + Activity newParentActivity = getActivityCopy(parentActivity); + newParentActivity.setLearningDesign(newLearningDesign); + activityDAO.insert(newParentActivity); + newActivities.add(newParentActivity); + + Set oldChildActivities = getChildActivities((Activity)parentActivity); + if ( oldChildActivities != null ) { + Iterator childIterator = oldChildActivities.iterator(); + while(childIterator.hasNext()){ + Activity childActivity = (Activity)childIterator.next(); + Activity newChildActivity = getActivityCopy(childActivity); + newChildActivity.setParentActivity(newParentActivity); + newChildActivity.setParentUIID(newParentActivity.getActivityUIID()); + newChildActivity.setLearningDesign(newLearningDesign); + activityDAO.insert(newChildActivity); + newActivities.add(newChildActivity); + } + } + } } - newLearningDesign.setActivities(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. + if ( newLearningDesign.getActivities() != null ) { + newLearningDesign.getActivities().clear(); + newLearningDesign.getActivities().addAll(newActivities); + } else { + newLearningDesign.setActivities(newActivities); + } } /** @@ -384,25 +378,38 @@ Transition newTransition = Transition.createCopy(transition); Activity toActivity = null; Activity fromActivity=null; - if(newTransition.getToUIID()!=null) + if(newTransition.getToUIID()!=null) { toActivity = activityDAO.getActivityByUIID(newTransition.getToUIID(),newLearningDesign); - if(newTransition.getFromUIID()!=null) + toActivity.setTransitionTo(newTransition); + } + if(newTransition.getFromUIID()!=null) { fromActivity = activityDAO.getActivityByUIID(newTransition.getFromUIID(),newLearningDesign); + fromActivity.setTransitionFrom(newTransition); + } newTransition.setToActivity(toActivity); newTransition.setFromActivity(fromActivity); newTransition.setLearningDesign(newLearningDesign); transitionDAO.insert(newTransition); newTransitions.add(newTransition); } - newLearningDesign.setTransitions(newTransitions); + + // 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 ( newLearningDesign.getTransitions() != null ) { + 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 * @return Activity The new deep-copied Activity object */ - private Activity getActivityCopy(Activity activity){ + private Activity getActivityCopy(final Activity activity){ if ( Activity.GROUPING_ACTIVITY_TYPE == activity.getActivityTypeId().intValue() ) { GroupingActivity newGroupingActivity = (GroupingActivity) activity.createCopy(); // now we need to manually add the grouping to the session, as we can't easily @@ -439,32 +446,29 @@ * @throws Exception */ public String storeLearningDesignDetails(String wddxPacket) throws Exception{ - LearningDesignDTO learningDesignDTO = null; Vector listOfValidationErrorDTOs = null; boolean valid = true; Hashtable table = (Hashtable)WDDXProcessor.deserialize(wddxPacket); - ObjectExtractor extractor = new ObjectExtractor(userDAO,learningDesignDAO, - activityDAO,workspaceFolderDAO, - learningLibraryDAO,licenseDAO, - groupingDAO,toolDAO,groupDAO,transitionDAO); + IObjectExtractor extractor = (IObjectExtractor) beanFactory.getBean(IObjectExtractor.OBJECT_EXTRACTOR_SPRING_BEANNAME); try { - LearningDesign design = extractor.extractLearningDesign(table); - learningDesignDAO.insert(design); + LearningDesign design = extractor.extractSaveLearningDesign(table); listOfValidationErrorDTOs = (Vector)learningDesignService.validateLearningDesign(design); if (listOfValidationErrorDTOs.size() > 0) { - valid = false; + valid = Boolean.FALSE; flashMessage = new FlashMessage("storeLearningDesignDetails", new StoreLearningDesignResultsDTO(valid,listOfValidationErrorDTOs, design.getLearningDesignId()), FlashMessage.OBJECT_MESSAGE); } else { - design.setValidDesign(new Boolean(valid)); - learningDesignDAO.update(design); + valid = Boolean.TRUE; flashMessage = new FlashMessage("storeLearningDesignDetails", new StoreLearningDesignResultsDTO(valid, design.getLearningDesignId())); } + + design.setValidDesign(valid); + learningDesignDAO.insertOrUpdate(design); //flashMessage = new FlashMessage(IAuthoringService.STORE_LD_MESSAGE_KEY,design.getLearningDesignId()); } catch ( ObjectExtractorException e ) { @@ -629,4 +633,5 @@ learningDesignDAO.delete(design); } + } \ No newline at end of file Index: lams_central/src/java/org/lamsfoundation/lams/authoring/service/IAuthoringService.java =================================================================== diff -u -rda6cbb5f4783fb429592a0010961e8666c90ffb0 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_central/src/java/org/lamsfoundation/lams/authoring/service/IAuthoringService.java (.../IAuthoringService.java) (revision da6cbb5f4783fb429592a0010961e8666c90ffb0) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/service/IAuthoringService.java (.../IAuthoringService.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -53,7 +53,6 @@ /** * Create a copy of learning design as per the requested learning design * and saves it in the given workspacefolder. Does not set the original - * learning design field, so it should not be used for creating lesson learning designs. * * @param originalLearningDesign The source learning design id. * @param copyType purpose of copying the design. Can have one of the follwing values @@ -94,15 +93,10 @@ * */ public List getAllLearningDesigns(); /** - * Saves the LearningDesign to the database + * Saves the LearningDesign to the database. Will update if already saved. * @param learningDesign The LearningDesign to be saved * */ public void saveLearningDesign(LearningDesign learningDesign); - /** - * Updates and existing LearningDesign in the database - * @param learningDesign The learningDesign to be updated - **/ - public void updateLearningDesign(LearningDesign learningDesign); /** * @return List Returns a list of all available Learning Libraries Index: lams_central/src/java/org/lamsfoundation/lams/workspace/service/IWorkspaceManagementService.java =================================================================== diff -u -rfc0a85ca7a12cd69d71d582eb17c62fc8d27101c -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_central/src/java/org/lamsfoundation/lams/workspace/service/IWorkspaceManagementService.java (.../IWorkspaceManagementService.java) (revision fc0a85ca7a12cd69d71d582eb17c62fc8d27101c) +++ lams_central/src/java/org/lamsfoundation/lams/workspace/service/IWorkspaceManagementService.java (.../IWorkspaceManagementService.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -40,7 +40,17 @@ public static final String REPOSITORY_USERNAME ="workspaceManager"; public static final String REPOSITORY_PASSWORD ="flashClient"; public static final String REPOSITORY_WORKSPACE="FlashClientsWorkspace"; - + + /* Message keys used for Flash packets. */ + public static final String MSG_KEY_MOVE = "moveResource"; + public static final String MSG_KEY_COPY = "copyResource"; + public static final String MSG_KEY_RENAME = "renameResource"; + public static final String MSG_KEY_DELETE = "deleteResource"; + public static final String MSG_KEY_CREATE_WKF_CONTENT = "createWorkspaceFolderContent"; + public static final String MSG_KEY_UPDATE_WKF_CONTENT = "updateWorkspaceFolderContent"; + public static final String MSG_KEY_DELETE_VERSION = "deleteContentWithVersion"; + public static final String MSG_KEY_ORG_BY_ROLE = "getOrganisationsByUserRole"; + public static final String MSG_KEY_USER_BY_ROLE = "getUsersFromOrganisationByRole"; /** * Get the workspace folder for a particular id. Does not check the user permissions - that will be checked if you try to get * anything from the folder. @@ -102,7 +112,7 @@ * @return A list of the FolderContentDTOs in a format suitable for WDDX * @throws Exception */ - public Vector getFolderContentsExcludeHome(Integer userID, WorkspaceFolder workspaceFolder, Integer mode)throws UserAccessDeniedException, RepositoryCheckedException ; + public Vector getFolderContentsExcludeHome(Integer userID, WorkspaceFolder workspaceFolder, Integer mode)throws UserAccessDeniedException, RepositoryCheckedException ; /** * This method creates a new folder under the given parentFolder Index: lams_central/src/java/org/lamsfoundation/lams/workspace/service/WorkspaceManagementService.java =================================================================== diff -u -r43c1735264f0b042ab12a098847f358e4fcafe99 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_central/src/java/org/lamsfoundation/lams/workspace/service/WorkspaceManagementService.java (.../WorkspaceManagementService.java) (revision 43c1735264f0b042ab12a098847f358e4fcafe99) +++ lams_central/src/java/org/lamsfoundation/lams/workspace/service/WorkspaceManagementService.java (.../WorkspaceManagementService.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -63,6 +63,7 @@ import org.lamsfoundation.lams.usermanagement.dao.IUserOrganisationDAO; import org.lamsfoundation.lams.usermanagement.dao.IWorkspaceDAO; import org.lamsfoundation.lams.usermanagement.dao.IWorkspaceFolderDAO; +import org.lamsfoundation.lams.usermanagement.dto.OrganisationDTO; import org.lamsfoundation.lams.usermanagement.exception.UserAccessDeniedException; import org.lamsfoundation.lams.usermanagement.exception.UserException; import org.lamsfoundation.lams.usermanagement.exception.WorkspaceFolderException; @@ -83,10 +84,6 @@ private FlashMessage flashMessage; - private static final String MSG_KEY_MOVE = "moveResource"; - private static final String MSG_KEY_COPY = "copyResource"; - private static final String MSG_KEY_RENAME = "renameResource"; - private static final String MSG_KEY_DELETE = "deleteResource"; public static final Integer AUTHORING = new Integer(1); public static final Integer MONITORING = new Integer(2); @@ -357,7 +354,7 @@ * (non-Javadoc) * @see org.lamsfoundation.lams.workspace.service.IWorkspaceManagementService#getFolderContentsExcludeHome(java.lang.Integer, java.lang.Integer, java.lang.Integer) */ - public Vector getFolderContentsExcludeHome(Integer userID, WorkspaceFolder folder, Integer mode)throws UserAccessDeniedException, RepositoryCheckedException { + public Vector getFolderContentsExcludeHome(Integer userID, WorkspaceFolder folder, Integer mode)throws UserAccessDeniedException, RepositoryCheckedException { User user = userDAO.getUserById(userID); return getFolderContentsInternal(user, folder, mode, "getFolderContentsExcludeHome", user.getWorkspace().getRootFolder()); } @@ -367,7 +364,7 @@ * (non-Javadoc) * @see org.lamsfoundation.lams.workspace.service.IWorkspaceManagementService#getFolderContents(java.lang.Integer, java.lang.Integer, java.lang.Integer) */ - public Vector getFolderContents(Integer userID, WorkspaceFolder folder, Integer mode)throws UserAccessDeniedException, RepositoryCheckedException { + public Vector getFolderContents(Integer userID, WorkspaceFolder folder, Integer mode)throws UserAccessDeniedException, RepositoryCheckedException { User user = userDAO.getUserById(userID); return getFolderContentsInternal(user, folder, mode, "getFolderContents", null); } @@ -379,15 +376,15 @@ * @throws UserAccessDeniedException * @throws RepositoryCheckedException */ - public Vector getFolderContentsInternal(User user, WorkspaceFolder workspaceFolder, Integer mode, String methodName, WorkspaceFolder skipFolder)throws UserAccessDeniedException, RepositoryCheckedException { - Vector contentDTO = new Vector(); + public Vector getFolderContentsInternal(User user, WorkspaceFolder workspaceFolder, Integer mode, String methodName, WorkspaceFolder skipFolder)throws UserAccessDeniedException, RepositoryCheckedException { + Vector contentDTO = new Vector(); if(user!=null){ Integer permissions = getPermissions(workspaceFolder,user); if(permissions!=WorkspaceFolder.NO_ACCESS){ getFolderContent(workspaceFolder,permissions,mode,contentDTO); if(workspaceFolder.hasSubFolders()) getSubFolderDetails(workspaceFolder,user,contentDTO, skipFolder); - Vector repositoryContent = getContentsFromRepository(workspaceFolder.getWorkspaceFolderId(),permissions); + Vector repositoryContent = getContentsFromRepository(workspaceFolder,permissions); if(repositoryContent!=null) contentDTO.addAll(repositoryContent); } else { @@ -399,7 +396,7 @@ return contentDTO; } - private void getFolderContent(WorkspaceFolder workspaceFolder, Integer permissions, Integer mode,Vector contentDTO){ + private void getFolderContent(WorkspaceFolder workspaceFolder, Integer permissions, Integer mode,Vector contentDTO){ List designs = null; @@ -413,7 +410,7 @@ /** * Get the folders in the given workspaceFolder. If skipContentId is not null, then skip any contents found with this id. */ - private void getSubFolderDetails(WorkspaceFolder workspaceFolder,User user, Vector subFolderContent, WorkspaceFolder skipFolder){ + private void getSubFolderDetails(WorkspaceFolder workspaceFolder,User user, Vector subFolderContent, WorkspaceFolder skipFolder){ Integer skipFolderID = skipFolder != null ? skipFolder.getWorkspaceFolderId() : null; Iterator iterator = workspaceFolder.getChildWorkspaceFolders().iterator(); while(iterator.hasNext()){ @@ -436,13 +433,16 @@ */ public Integer getPermissions(WorkspaceFolder workspaceFolder, User user){ Integer permission = null; + WorkspaceFolder userRootFolder = user.getWorkspace().getRootFolder(); - - if(isUserOwner(workspaceFolder,user)) + + if ( workspaceFolder==null || user==null ) { + permission = WorkspaceFolder.NO_ACCESS; + } else if (workspaceFolder.getUserID().equals(user.getUserId())) permission = WorkspaceFolder.OWNER_ACCESS; else if (isSubFolder(workspaceFolder,userRootFolder)) { - if(isRunSequencesFolder(workspaceFolder,user)) + if(workspaceFolder.isRunSequencesFolder()) permission = WorkspaceFolder.READ_ACCESS; else permission = WorkspaceFolder.OWNER_ACCESS; @@ -459,49 +459,34 @@ /** This method checks if the given workspaceFolder is a subFolder of the * given rootFolder*/ private boolean isSubFolder(WorkspaceFolder workspaceFolder,WorkspaceFolder rootFolder){ - List subFolders = workspaceFolderDAO.getWorkspaceFolderByParentFolder(rootFolder.getWorkspaceFolderId()); - Iterator iterator = subFolders.iterator(); - while(iterator.hasNext()){ - WorkspaceFolder subFolder = (WorkspaceFolder)iterator.next(); - if(subFolder.getWorkspaceFolderId()==workspaceFolder.getWorkspaceFolderId()) - return true; + if ( workspaceFolder != null ) { + WorkspaceFolder parent = null; + do { + parent = workspaceFolder.getParentWorkspaceFolder(); + } while ( parent != null && ! rootFolder.getWorkspaceFolderId().equals(parent.getWorkspaceFolderId())); + return ( parent != null ); } return false; } /** - * Assuming that there is ONLY ONE runSequences folder per user, - * which is created at the time the User is created, this method - * checks if the given workspaceFolder is the runSequences folder - * for the given user. - * - * @param workspaceFolder - * @param user - * @return - */ - public boolean isRunSequencesFolder(WorkspaceFolder workspaceFolder, User user){ - WorkspaceFolder runSequencesFolder = workspaceFolderDAO.getRunSequencesFolderForUser(user.getUserId()); - if(workspaceFolder.getWorkspaceFolderId()==runSequencesFolder.getWorkspaceFolderId()) - return true; - else - return false; - } - /** * This method checks if the given workspaceFolder is the * workspaceFolder of the parentOrganisation of which the user is a member. * * @param workspaceFolder * @param user - * @return + * @return true/false */ - public boolean isParentOrganisationFolder(WorkspaceFolder workspaceFolder, User user){ - WorkspaceFolder parentOrganisationFolder = user.getBaseOrganisation().getWorkspace().getRootFolder(); - if(parentOrganisationFolder.getWorkspaceFolderId()==workspaceFolder.getWorkspaceFolderId()) - return true; - else - return false; + private boolean isParentOrganisationFolder(WorkspaceFolder workspaceFolder, User user){ + Integer workspaceFolderID = workspaceFolder != null ? workspaceFolder.getWorkspaceFolderId() : null; + if ( workspaceFolderID != null ) { + WorkspaceFolder parentOrganisationFolder = user.getBaseOrganisation().getWorkspace().getRootFolder(); + return (parentOrganisationFolder!=null && workspaceFolderID.equals(parentOrganisationFolder.getWorkspaceFolderId()) ); + } + return false; } - private Vector getFolderContentDTO(List designs, Integer permissions,Vector folderContent){ + + private Vector getFolderContentDTO(List designs, Integer permissions,Vector folderContent){ Iterator iterator = designs.iterator(); while(iterator.hasNext()){ LearningDesign design = (LearningDesign)iterator.next(); @@ -643,24 +628,7 @@ return authorized; } - private Hashtable createCopyFolderPacket(Long newResourceID, Integer targetFolderID){ - Hashtable packet = new Hashtable(); - packet.put("newResourceID", newResourceID); - packet.put("targetFolderID",targetFolderID); - return packet; - } - public boolean isUserOwner(WorkspaceFolder workspaceFolder, User user){ - List folders = workspaceFolderDAO.getWorkspaceFolderByUser(user.getUserId()); - if(folders!=null && folders.size()!=0){ - Iterator iterator =folders.iterator(); - while(iterator.hasNext()){ - WorkspaceFolder folder = (WorkspaceFolder)iterator.next(); - if(folder.getWorkspaceFolderId()==workspaceFolder.getWorkspaceFolderId()) - return true; - } - } - return false; - } + public void copyRootContent(WorkspaceFolder workspaceFolder,WorkspaceFolder targetWorkspaceFolder, Integer userID)throws UserException{ User user = userDAO.getUserById(userID); if(user==null) @@ -720,7 +688,7 @@ public String createFolderForFlash(Integer parentFolderID, String name, Integer userID)throws IOException{ try{ WorkspaceFolder newFolder = createFolder(parentFolderID,name,userID); - Hashtable table = new Hashtable(); + Hashtable table = new Hashtable(); table.put("folderID",newFolder.getWorkspaceFolderId()); table.put("name",newFolder.getName()); flashMessage = new FlashMessage("createFolderForFlash",table); @@ -943,32 +911,32 @@ workspaceFolderContentDAO.update(workspaceFolderContent); UpdateContentDTO contentDTO = new UpdateContentDTO(nodeKey.getUuid(), nodeKey.getVersion(),workspaceFolderContent.getFolderContentID()); - flashMessage = new FlashMessage("createWorkspaceFolderContent",contentDTO); + flashMessage = new FlashMessage(MSG_KEY_CREATE_WKF_CONTENT,contentDTO); }catch(AccessDeniedException ae){ - flashMessage = new FlashMessage("createWorkspaceFolderContent", + flashMessage = new FlashMessage(MSG_KEY_CREATE_WKF_CONTENT, messageService.getMessage("creating.workspace.folder.error",new Object[]{ae.getMessage()}), FlashMessage.CRITICAL_ERROR); }catch(FileException fe){ - flashMessage = new FlashMessage("createWorkspaceFolderContent", + flashMessage = new FlashMessage(MSG_KEY_CREATE_WKF_CONTENT, messageService.getMessage("creating.workspace.folder.error",new Object[]{fe.getMessage()}), FlashMessage.CRITICAL_ERROR); }catch(InvalidParameterException ip){ - flashMessage = new FlashMessage("createWorkspaceFolderContent", + flashMessage = new FlashMessage(MSG_KEY_CREATE_WKF_CONTENT, messageService.getMessage("creating.workspace.folder.error",new Object[]{ip.getMessage()}), FlashMessage.CRITICAL_ERROR); } } else { - flashMessage = new FlashMessage("createWorkspaceFolderContent", + flashMessage = new FlashMessage(MSG_KEY_CREATE_WKF_CONTENT, messageService.getMessage("resource.already.exist",new Object[]{name,workspaceFolderID}), FlashMessage.ERROR); } } else - flashMessage = FlashMessage.getNoSuchWorkspaceFolderExsists("createWorkspaceFolderContent",workspaceFolderID); + flashMessage = FlashMessage.getNoSuchWorkspaceFolderExsists(MSG_KEY_CREATE_WKF_CONTENT,workspaceFolderID); return flashMessage.serializeMessage(); } @@ -1008,9 +976,9 @@ if(workspaceFolderContent!=null){ NodeKey nodeKey = updateFileInRepository(workspaceFolderContent,stream); UpdateContentDTO contentDTO = new UpdateContentDTO(nodeKey.getUuid(), nodeKey.getVersion(),folderContentID); - flashMessage = new FlashMessage("updateWorkspaceFolderContent",contentDTO); + flashMessage = new FlashMessage(MSG_KEY_UPDATE_WKF_CONTENT,contentDTO); }else - flashMessage = FlashMessage.getNoSuchWorkspaceFolderContentExsists("updateWorkspaceFolderContent",folderContentID); + flashMessage = FlashMessage.getNoSuchWorkspaceFolderContentExsists(MSG_KEY_UPDATE_WKF_CONTENT,folderContentID); return flashMessage.serializeMessage(); } @@ -1072,8 +1040,15 @@ String files[]=null; try{ files = repositoryService.deleteVersion(ticket,uuid,versionToBeDeleted); + if ( files != null && files.length > 0 ) { + String error = "Trying to delete content uuid="+uuid+" unable to delete files "; + for ( String filename : files ) { + error = error + " " + filename; + } + log.warn(error); + } }catch(ItemNotFoundException ie){ - flashMessage = new FlashMessage("deleteContentWithVersion", + flashMessage = new FlashMessage(MSG_KEY_DELETE_VERSION, messageService.getMessage("no.such.content",new Object[]{versionToBeDeleted,folderContentID}), FlashMessage.ERROR); return flashMessage.serializeMessage(); @@ -1101,15 +1076,15 @@ workspaceFolderContent.setVersionID(latestAvailableVersion); workspaceFolderContentDAO.update(workspaceFolderContent); } - flashMessage = new FlashMessage("deleteContentWithVersion",messageService.getMessage("content.delete.success")); + flashMessage = new FlashMessage(MSG_KEY_DELETE_VERSION,messageService.getMessage("content.delete.success")); }catch(ItemNotFoundException ie){ workspaceFolderContentDAO.delete(workspaceFolderContent); - flashMessage = new FlashMessage("deleteContentWithVersion",messageService.getMessage("content.delete.success")); + flashMessage = new FlashMessage(MSG_KEY_DELETE_VERSION,messageService.getMessage("content.delete.success")); } } else { - flashMessage = new FlashMessage("deleteContentWithVersion",messageService.getMessage("content.delete.success")); + flashMessage = new FlashMessage(MSG_KEY_DELETE_VERSION,messageService.getMessage("content.delete.success")); } return flashMessage.serializeMessage(); } @@ -1151,13 +1126,13 @@ * @throws RepositoryCheckedException * @throws Exception */ - private Vector getContentsFromRepository(Integer workspaceFolderID, Integer permissions) throws RepositoryCheckedException{ - List content = workspaceFolderContentDAO.getContentByWorkspaceFolder(new Long(workspaceFolderID.longValue())); + private Vector getContentsFromRepository(WorkspaceFolder workspaceFolder, Integer permissions) throws RepositoryCheckedException{ + Set content = workspaceFolder.getFolderContent(); if(content.size()==0) return null; else{ ITicket ticket = getRepositoryLoginTicket(); - Vector repositoryContent = new Vector(); + Vector repositoryContent = new Vector(); Iterator contentIterator = content.iterator(); while(contentIterator.hasNext()){ WorkspaceFolderContent workspaceFolderContent = (WorkspaceFolderContent)contentIterator.next(); @@ -1174,7 +1149,7 @@ */ public Vector getAccessibleOrganisationWorkspaceFolders(Integer userID) throws IOException { User user = userDAO.getUserById(userID); - Vector folders = new Vector(); + Vector folders = new Vector(); if (user != null) { // Get a list of organisations of which the given user is a member @@ -1196,10 +1171,10 @@ } } } else { - log.warn("getAccessibleWorkspaceFolders: Trying to get user memberships for user "+userID+". User doesn't belong to any organisations. Returning no folders."); + log.warn("getAccessibleOrganisationWorkspaceFolders: Trying to get user memberships for user "+userID+". User doesn't belong to any organisations. Returning no folders."); } } else { - log.warn("getAccessibleWorkspaceFolders: User "+userID+" does not exist. Returning no folders."); + log.warn("getAccessibleOrganisationWorkspaceFolders: User "+userID+" does not exist. Returning no folders."); } return folders; @@ -1410,7 +1385,7 @@ public String getOrganisationsByUserRole(Integer userID, String role) throws IOException { User user = userDAO.getUserById(userID); - Vector organisations = new Vector(); + Vector organisations = new Vector(); if (user!=null) { Iterator iterator = userMgmtService.getOrganisationsForUserByRole(user, role).iterator(); @@ -1420,10 +1395,10 @@ organisations.add(organisation.getOrganisationDTO()); } flashMessage = new FlashMessage( - "getOrganisationsByUserRole", organisations); + MSG_KEY_ORG_BY_ROLE, organisations); } else flashMessage = FlashMessage.getNoSuchUserExists( - "getOrganisationsByUserRole", userID); + MSG_KEY_ORG_BY_ROLE, userID); return flashMessage.serializeMessage(); Index: lams_central/src/java/org/lamsfoundation/lams/workspace/web/WorkspaceAction.java =================================================================== diff -u -rfc0a85ca7a12cd69d71d582eb17c62fc8d27101c -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_central/src/java/org/lamsfoundation/lams/workspace/web/WorkspaceAction.java (.../WorkspaceAction.java) (revision fc0a85ca7a12cd69d71d582eb17c62fc8d27101c) +++ lams_central/src/java/org/lamsfoundation/lams/workspace/web/WorkspaceAction.java (.../WorkspaceAction.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -72,13 +72,6 @@ */ public static final Integer ORG_FOLDER_ID = new Integer(-2); - /** If you want the output given as a jsp, set the request parameter "jspoutput" to - * some value other than an empty string (e.g. 1, true, 0, false, blah). - * If you want it returned as a stream (ie for Flash), do not define this parameter - */ - public static String USE_JSP_OUTPUT = "jspoutput"; - - /** * @return */ @@ -87,35 +80,17 @@ return (IWorkspaceManagementService) webContext.getBean("workspaceManagementService"); } - /** Output the supplied WDDX packet. If the request parameter USE_JSP_OUTPUT - * is set, then it sets the session attribute "parameterName" to the wddx packet string. - * If USE_JSP_OUTPUT is not set, then the packet is written out to the - * request's PrintWriter. - * - * @param mapping action mapping (for the forward to the success jsp) - * @param request needed to check the USE_JSP_OUTPUT parameter - * @param response to write out the wddx packet if not using the jsp - * @param wddxPacket wddxPacket or message to be sent/displayed - * @param parameterName session attribute to set if USE_JSP_OUTPUT is set - * @throws IOException - */ - private ActionForward outputPacket(ActionMapping mapping, HttpServletRequest request, HttpServletResponse response, - String wddxPacket, String parameterName) throws IOException { - String useJSP = WebUtil.readStrParam(request, USE_JSP_OUTPUT, true); - if ( useJSP != null && useJSP.length() >= 0 ) { - request.getSession().setAttribute(parameterName,wddxPacket); - return mapping.findForward("success"); - } else { + /** Send the flash message back to Flash */ + private ActionForward returnWDDXPacket(FlashMessage flashMessage, HttpServletResponse response) throws IOException { PrintWriter writer = response.getWriter(); - writer.println(wddxPacket); + writer.println(flashMessage.serializeMessage()); return null; - } } - + /** Send the flash message back to Flash */ - private ActionForward returnWDDXPacket(FlashMessage flashMessage, HttpServletResponse response) throws IOException { + private ActionForward returnWDDXPacket(String serializedFlashMessage, HttpServletResponse response) throws IOException { PrintWriter writer = response.getWriter(); - writer.println(flashMessage.serializeMessage()); + writer.println(serializedFlashMessage); return null; } @@ -156,13 +131,13 @@ Integer parentFolderID = new Integer(WebUtil.readIntParam(request,"parentFolderID")); String errorPacket = checkResourceNotDummyValue("createFolderForFlash", parentFolderID, FolderContentDTO.FOLDER); if ( errorPacket != null) - return outputPacket(mapping, request, response, errorPacket, "details"); + return returnWDDXPacket(errorPacket, response); String folderName = (String)WebUtil.readStrParam(request,"name"); Integer userID = new Integer(WebUtil.readIntParam(request,AttributeNames.PARAM_USER_ID)); IWorkspaceManagementService workspaceManagementService = getWorkspaceManagementService(); String wddxPacket = workspaceManagementService.createFolderForFlash(parentFolderID,folderName,userID); - return outputPacket(mapping, request, response, wddxPacket, "details"); + return returnWDDXPacket(wddxPacket, response); } /** @@ -208,7 +183,7 @@ try { if ( BOOTSTRAP_FOLDER_ID.equals(folderID )) { // return back the dummy org DTO and the user's workspace folder - Vector folders = new Vector(); + Vector folders = new Vector(); FolderContentDTO userFolder = workspaceManagementService.getUserWorkspaceFolder(userID); if ( userFolder != null ) folders.add(userFolder); @@ -245,14 +220,15 @@ } catch (UserAccessDeniedException e) { return returnWDDXPacket(FlashMessage.getUserNotAuthorized(methodKey, userID), response); } catch (Exception e) { + log.error("getFolderContents: Exception occured. userID "+userID+" folderID "+folderID, e); return returnWDDXPacket(FlashMessage.getExceptionOccured(methodKey, e.getMessage()), response); } return returnWDDXPacket(new FlashMessage(methodKey,packet), response); } - private Hashtable createFolderContentPacket(Integer parentWorkspaceFolderID, Integer workspaceFolderID, Vector contents){ - Hashtable packet = new Hashtable(); + private Hashtable createFolderContentPacket(Integer parentWorkspaceFolderID, Integer workspaceFolderID, Vector contents){ + Hashtable packet = new Hashtable(); if ( parentWorkspaceFolderID != null ) packet.put("parentWorkspaceFolderID", parentWorkspaceFolderID); @@ -286,14 +262,22 @@ String resourceType = WebUtil.readStrParam(request,RESOURCE_TYPE); String errorPacket = checkResourceNotDummyValue("deleteResource", resourceID, FolderContentDTO.FOLDER); if ( errorPacket != null) - return outputPacket(mapping, request, response, errorPacket, "details"); + return returnWDDXPacket(errorPacket, response); Integer userID = new Integer(WebUtil.readIntParam(request,AttributeNames.PARAM_USER_ID)); - IWorkspaceManagementService workspaceManagementService = getWorkspaceManagementService(); - String wddxPacket = workspaceManagementService.deleteResource(resourceID,resourceType,userID); + String wddxPacket = null; + try { + IWorkspaceManagementService workspaceManagementService = getWorkspaceManagementService(); + wddxPacket = workspaceManagementService.deleteResource(resourceID,resourceType,userID); + } catch (Exception e) { + log.error("deleteResource: Exception occured. userID "+userID+" folderID "+resourceID, e); + FlashMessage flashMessage = FlashMessage.getExceptionOccured(IWorkspaceManagementService.MSG_KEY_DELETE, e.getMessage()); + wddxPacket = flashMessage.serializeMessage(); + } PrintWriter writer = response.getWriter(); writer.println(wddxPacket); return null; + } /** @@ -317,13 +301,20 @@ Integer targetFolderID = new Integer(WebUtil.readIntParam(request,"targetFolderID")); String errorPacket = checkResourceNotDummyValue("copyResource", targetFolderID, FolderContentDTO.FOLDER); if ( errorPacket != null) - return outputPacket(mapping, request, response, errorPacket, "details"); + return returnWDDXPacket(errorPacket, response); + String wddxPacket = null; Integer copyType = WebUtil.readIntParam(request, "copyType", true); Integer userID = new Integer(WebUtil.readIntParam(request,AttributeNames.PARAM_USER_ID)); - IWorkspaceManagementService workspaceManagementService = getWorkspaceManagementService(); - String wddxPacket = workspaceManagementService.copyResource(resourceID,resourceType,copyType,targetFolderID,userID); - return outputPacket(mapping, request, response, wddxPacket, "details"); + try { + IWorkspaceManagementService workspaceManagementService = getWorkspaceManagementService(); + wddxPacket = workspaceManagementService.copyResource(resourceID,resourceType,copyType,targetFolderID,userID); + } catch (Exception e) { + log.error("deleteResource: Exception occured. userID "+userID+" folderID "+resourceID, e); + FlashMessage flashMessage = FlashMessage.getExceptionOccured(IWorkspaceManagementService.MSG_KEY_DELETE, e.getMessage()); + wddxPacket = flashMessage.serializeMessage(); + } + return returnWDDXPacket(wddxPacket, response); } /** @@ -349,7 +340,7 @@ String errorPacket = checkResourceNotDummyValue("copyResource", targetFolderID, FolderContentDTO.FOLDER); if ( errorPacket != null) - return outputPacket(mapping, request, response, errorPacket, "details"); + return returnWDDXPacket(errorPacket, response); IWorkspaceManagementService workspaceManagementService = getWorkspaceManagementService(); String wddxPacket = workspaceManagementService.moveResource(resourceID,targetFolderID,resourceType,userID); @@ -385,13 +376,20 @@ String errorPacket = checkResourceNotDummyValue("createWorkspaceFolderContent", workspaceFolderID, FolderContentDTO.FOLDER); if ( errorPacket != null) - return outputPacket(mapping, request, response, errorPacket, "details"); + return returnWDDXPacket(errorPacket, response); - IWorkspaceManagementService workspaceManagementService = getWorkspaceManagementService(); - String wddxPacket = workspaceManagementService.createWorkspaceFolderContent(contentTypeID,name,description, + String wddxPacket = null; + try { + IWorkspaceManagementService workspaceManagementService = getWorkspaceManagementService(); + wddxPacket = workspaceManagementService.createWorkspaceFolderContent(contentTypeID,name,description, workspaceFolderID, mimeType,path); - return outputPacket(mapping, request, response, wddxPacket, "details"); + } catch (Exception e) { + log.error("createWorkspaceFolderContent: Exception occured. contentTypeID "+contentTypeID+" name "+name+" workspaceFolderID "+workspaceFolderID, e); + FlashMessage flashMessage = FlashMessage.getExceptionOccured(IWorkspaceManagementService.MSG_KEY_CREATE_WKF_CONTENT, e.getMessage()); + wddxPacket = flashMessage.serializeMessage(); + } + return returnWDDXPacket(wddxPacket, response); } /** * For details please refer to @@ -412,9 +410,16 @@ Long folderContentID = new Long(WebUtil.readLongParam(request,"folderContentID")); String path = WebUtil.readStrParam(request,"path"); - IWorkspaceManagementService workspaceManagementService = getWorkspaceManagementService(); - String wddxPacket = workspaceManagementService.updateWorkspaceFolderContent(folderContentID,path); - return outputPacket(mapping, request, response, wddxPacket, "details"); + String wddxPacket = null; + try { + IWorkspaceManagementService workspaceManagementService = getWorkspaceManagementService(); + wddxPacket = workspaceManagementService.updateWorkspaceFolderContent(folderContentID,path); + } catch (Exception e) { + log.error("updateWorkspaceFolderContent: Exception occured. path "+path+" folderContentID "+folderContentID, e); + FlashMessage flashMessage = FlashMessage.getExceptionOccured(IWorkspaceManagementService.MSG_KEY_UPDATE_WKF_CONTENT, e.getMessage()); + wddxPacket = flashMessage.serializeMessage(); + } + return returnWDDXPacket(wddxPacket, response); } /** * For details please refer to @@ -437,14 +442,19 @@ String errorPacket = checkResourceNotDummyValue("renameResource", resourceID, resourceType); if ( errorPacket != null) - return outputPacket(mapping, request, response, errorPacket, "details"); + return returnWDDXPacket(errorPacket, response); String name = WebUtil.readStrParam(request,"name"); - IWorkspaceManagementService workspaceManagementService = getWorkspaceManagementService(); - String wddxPacket = workspaceManagementService.renameResource(resourceID,resourceType,name,userID); - PrintWriter writer = response.getWriter(); - writer.println(wddxPacket); - return null; + String wddxPacket = null; + try { + IWorkspaceManagementService workspaceManagementService = getWorkspaceManagementService(); + wddxPacket = workspaceManagementService.renameResource(resourceID,resourceType,name,userID); + } catch (Exception e) { + log.error("renameResource: Exception occured. userID "+userID+" resourceID "+resourceID+" resourceType "+resourceType, e); + FlashMessage flashMessage = FlashMessage.getExceptionOccured(IWorkspaceManagementService.MSG_KEY_RENAME, e.getMessage()); + wddxPacket = flashMessage.serializeMessage(); + } + return returnWDDXPacket(wddxPacket, response); } /** @@ -468,11 +478,18 @@ String errorPacket = checkResourceNotDummyValue("deleteContentWithVersion", folderContentID, FolderContentDTO.FOLDER); if ( errorPacket != null) - return outputPacket(mapping, request, response, errorPacket, "details"); + return returnWDDXPacket(errorPacket, response); - IWorkspaceManagementService workspaceManagementService = getWorkspaceManagementService(); - String wddxPacket = workspaceManagementService.deleteContentWithVersion(uuID,versionID,folderContentID); - return outputPacket(mapping, request, response, wddxPacket, "details"); + String wddxPacket = null; + try { + IWorkspaceManagementService workspaceManagementService = getWorkspaceManagementService(); + wddxPacket = workspaceManagementService.deleteContentWithVersion(uuID,versionID,folderContentID); + } catch (Exception e) { + log.error("deleteContentWithVersion: Exception occured. uuID "+uuID+" versionID "+versionID+" folderContentID "+folderContentID, e); + FlashMessage flashMessage = FlashMessage.getExceptionOccured(IWorkspaceManagementService.MSG_KEY_DELETE_VERSION, e.getMessage()); + wddxPacket = flashMessage.serializeMessage(); + } + return returnWDDXPacket(wddxPacket, response); } @@ -482,9 +499,16 @@ HttpServletResponse response)throws Exception{ Integer userID = new Integer(WebUtil.readIntParam(request,AttributeNames.PARAM_USER_ID)); String role = WebUtil.readStrParam(request, "role"); - IWorkspaceManagementService workspaceManagementService = getWorkspaceManagementService(); - String wddxPacket = workspaceManagementService.getOrganisationsByUserRole(userID, role); - return outputPacket(mapping, request, response, wddxPacket, "details"); + String wddxPacket = null; + try { + IWorkspaceManagementService workspaceManagementService = getWorkspaceManagementService(); + wddxPacket = workspaceManagementService.getOrganisationsByUserRole(userID, role); + } catch (Exception e) { + log.error("getOrganisationsByUserRole: Exception occured. userID "+userID+" role "+role, e); + FlashMessage flashMessage = FlashMessage.getExceptionOccured(IWorkspaceManagementService.MSG_KEY_ORG_BY_ROLE, e.getMessage()); + wddxPacket = flashMessage.serializeMessage(); + } + return returnWDDXPacket(wddxPacket, response); } public ActionForward getUsersFromOrganisationByRole(ActionMapping mapping, @@ -493,9 +517,16 @@ HttpServletResponse response)throws Exception{ Integer organisationID = new Integer(WebUtil.readIntParam(request,"organisationID")); String role = WebUtil.readStrParam(request, "role"); - IWorkspaceManagementService workspaceManagementService = getWorkspaceManagementService(); - String wddxPacket = workspaceManagementService.getUsersFromOrganisationByRole(organisationID, role); - return outputPacket(mapping, request, response, wddxPacket, "details"); + String wddxPacket = null; + try { + IWorkspaceManagementService workspaceManagementService = getWorkspaceManagementService(); + wddxPacket = workspaceManagementService.getUsersFromOrganisationByRole(organisationID, role); + } catch (Exception e) { + log.error("getUsersFromOrganisationByRole: Exception occured. organisationID "+organisationID+" role "+role, e); + FlashMessage flashMessage = FlashMessage.getExceptionOccured(IWorkspaceManagementService.MSG_KEY_USER_BY_ROLE, e.getMessage()); + wddxPacket = flashMessage.serializeMessage(); + } + return returnWDDXPacket(wddxPacket, response); } } Index: lams_central/test/java/org/lamsfoundation/lams/authoring/service/TestAuthoringService.java =================================================================== diff -u -r0effee9214fcf8b34e1361b0bec6afe3b4f5c12b -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_central/test/java/org/lamsfoundation/lams/authoring/service/TestAuthoringService.java (.../TestAuthoringService.java) (revision 0effee9214fcf8b34e1361b0bec6afe3b4f5c12b) +++ lams_central/test/java/org/lamsfoundation/lams/authoring/service/TestAuthoringService.java (.../TestAuthoringService.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -22,21 +22,15 @@ */ package org.lamsfoundation.lams.authoring.service; - - import java.io.IOException; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.Vector; -import org.lamsfoundation.lams.learningdesign.LearningDesign; -import org.lamsfoundation.lams.learningdesign.dao.hibernate.LearningDesignDAO; import org.lamsfoundation.lams.learningdesign.dto.LicenseDTO; import org.lamsfoundation.lams.learningdesign.exception.LearningDesignException; import org.lamsfoundation.lams.test.AbstractLamsTestCase; -import org.lamsfoundation.lams.usermanagement.dao.hibernate.UserDAO; -import org.lamsfoundation.lams.usermanagement.dao.hibernate.WorkspaceFolderDAO; import org.lamsfoundation.lams.usermanagement.exception.UserException; import org.lamsfoundation.lams.usermanagement.exception.WorkspaceFolderException; @@ -46,11 +40,7 @@ public class TestAuthoringService extends AbstractLamsTestCase { private IAuthoringService authService; - private LearningDesignDAO learningDesignDAO; - private UserDAO userDAO; - private WorkspaceFolderDAO workspaceFolderDAO; - private static final Long TEST_THEME_ID = new Long(1); public TestAuthoringService(String name) { super(name); } @@ -59,9 +49,6 @@ protected void setUp()throws Exception{ super.setUp(); authService =(IAuthoringService)context.getBean("authoringService"); - learningDesignDAO = (LearningDesignDAO)context.getBean("learningDesignDAO"); - userDAO = (UserDAO)context.getBean("userDAO"); - workspaceFolderDAO =(WorkspaceFolderDAO)context.getBean("workspaceFolderDAO"); } protected String getHibernateSessionFactoryName() { return "coreSessionFactory"; @@ -71,11 +58,11 @@ "org/lamsfoundation/lams/authoring/authoringApplicationContext.xml"}; } public void testCopyLearningdesign()throws UserException, WorkspaceFolderException, LearningDesignException, IOException{ - LearningDesign design = authService.copyLearningDesign(new Long(1), - new Integer(1), - new Integer(1), - new Integer(1), - true); + authService.copyLearningDesign(new Long(1), + new Integer(1), + new Integer(1), + new Integer(1), + true); } // TODO Check that this packet structure is still what is coming from Flash, and change test case to actually check the values are updated. public void testGetLearningDesignDetails()throws Exception{ @@ -107,38 +94,9 @@ assertEquals("Second store has updated as expected", id, id2); } - public void testStoreTheme() throws Exception{ - String str = authService.storeTheme(TEST_NEW_THEME_WDDX); - assertTrue("storeTheme returned WDDX packet", str!=null && str.startsWith(" NO_THEME_RESPONSE.length()); - - } - - public void testGetTheme() throws Exception{ - String str = authService.getTheme(TEST_THEME_ID); - System.out.println(str); - assertTrue("Finds ruby theme", str.indexOf("ruby") != -1); - } - public void testGetAvailableLicenses() throws Exception{ String otherLicenseCode = "other"; - Set ccCodes = new HashSet(); // creative commons codes + Set ccCodes = new HashSet(); // creative commons codes ccCodes.add("by-nc-sa"); ccCodes.add("by-nd"); ccCodes.add("by-nc-nd"); @@ -355,104 +313,7 @@ +"1" +"-111111" +"1"; - private static final String TEST_NEW_THEME_WDDX = - "
"+ - ""+ - ""+ - ""+ - "outset"+ - "16711680"+ - "16711680"+ - "16711680"+ - ""+ - ""+ - "_sans"+ - "10"+ - "12452097"+ - "block"+ - ""+ - ""+ - ""+ - ""+ - "AuthoringTestTheme"+ - "theme used for TestAuthoringService"+ - ""+ - ""+ - ""+ - "button"+ - ""+ - ""+ - "outset"+ - "16711680"+ - "16711680"+ - "16711680"+ - ""+ - ""+ - "7174353"+ - "block"+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""; - private static final String TEST_NEW_THEME_WDDX2_PART1 = - "
"+ - ""+ - ""+ - ""+ - "outset2"+ - "16711681"+ - "16711681"+ - "16711681"+ - ""+ - ""+ - "_sans"+ - "11"+ - "12452098"+ - "block2"+ - ""+ - ""+ - ""+ - ""+ - ""; - private static final String TEST_NEW_THEME_WDDX2_PART2 = - ""+ - "AuthoringTestTheme2"+ - "theme used for TestAuthoringService2"+ - ""+ - ""+ - ""+ - "button"+ - ""+ - ""+ - "outset2"+ - "16711681"+ - "16711681"+ - "16711681"+ - ""+ - ""+ - "7174354"+ - "block2"+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""; - - private static final String NO_THEME_RESPONSE = - "
" - +"getThemes" - +"3.0" - +""; - - } Index: lams_central/test/java/org/lamsfoundation/lams/workspace/dao/TestWorkspaceFolderContentDAO.java =================================================================== diff -u -r9bef1de27d0d527d75191115a535bc2c4311ade9 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_central/test/java/org/lamsfoundation/lams/workspace/dao/TestWorkspaceFolderContentDAO.java (.../TestWorkspaceFolderContentDAO.java) (revision 9bef1de27d0d527d75191115a535bc2c4311ade9) +++ lams_central/test/java/org/lamsfoundation/lams/workspace/dao/TestWorkspaceFolderContentDAO.java (.../TestWorkspaceFolderContentDAO.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -24,7 +24,6 @@ import java.io.FileInputStream; import java.util.Date; -import java.util.List; import org.lamsfoundation.lams.contentrepository.ICredentials; import org.lamsfoundation.lams.contentrepository.ITicket; @@ -62,14 +61,6 @@ workspaceFolderContentDAO.insert(workspaceFolderContent); assertNotNull(workspaceFolderContent.getFolderContentID()); } - public void testGetContentByWorkspaceFolder(){ - List list = workspaceFolderContentDAO.getContentByWorkspaceFolder(new Long(3)); - assertEquals(list.size(),4); - } - public void testGetContentByTypeFromWorkspaceFolder(){ - List list = workspaceFolderContentDAO.getContentByTypeFromWorkspaceFolder(new Long(3),"TXT"); - assertEquals(list.size(),2); - } public void testAddFlashClientWorkspaceCredentials()throws Exception{ credentials = new SimpleCredentials(workspaceUser,password.toCharArray()); //repositoryService.createCredentials(credentials); Index: lams_central/test/java/org/lamsfoundation/lams/workspace/service/TestWorkspaceManagement.java =================================================================== diff -u -r24e81813a7f7ce5a240c6bf7f4e3b70d55ce2f56 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_central/test/java/org/lamsfoundation/lams/workspace/service/TestWorkspaceManagement.java (.../TestWorkspaceManagement.java) (revision 24e81813a7f7ce5a240c6bf7f4e3b70d55ce2f56) +++ lams_central/test/java/org/lamsfoundation/lams/workspace/service/TestWorkspaceManagement.java (.../TestWorkspaceManagement.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -1,10 +1,10 @@ package org.lamsfoundation.lams.workspace.service; import java.io.IOException; -import java.util.Date; import java.util.Iterator; -import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.Vector; import org.lamsfoundation.lams.contentrepository.NodeKey; import org.lamsfoundation.lams.usermanagement.WorkspaceFolder; @@ -20,27 +20,27 @@ private static final Integer MELCOE_WORKSPACE_FOLDER = new Integer(3); private static final Integer LAMS_WORKSPACE_FOLDER = new Integer(4); private static final Integer MANPREETS_WORKSPACE_FOLDER = new Integer(6); - private static final Integer TO_DELETE_WORKSPACE_FOLDER = new Integer(7); - private static final Long LONG_DELETE_WORKSPACE_FOLDER = new Long(7); + //private static final Integer TO_DELETE_WORKSPACE_FOLDER = new Integer(7); + //private static final Long LONG_DELETE_WORKSPACE_FOLDER = new Long(7); private static final Integer DOCUMENTS_WORKSPACE_FOLDER = new Integer(8); - private static final Long LONG_DOCUMENTS_WORKSPACE_FOLDER = new Long(8); + private static final Integer LONG_DOCUMENTS_WORKSPACE_FOLDER = new Integer(8); private static final Integer PICTURES_WORKSPACE_FOLDER = new Integer(9); private static final Integer MANPREETS_WORKSPACE = new Integer(6); private static final Integer USER_ID = new Integer(4); - private static final Long LD_ID = new Long(2); public TestWorkspaceManagement(String name){ super(name); } public void testGetAccessibleWorkspaceFolders()throws IOException{ - String packet = workspaceManagementService.getAccessibleWorkspaceFolders(USER_ID); - System.out.println("User Accessible folders: " + packet); + Vector vector = workspaceManagementService.getAccessibleOrganisationWorkspaceFolders(USER_ID); + assertTrue("Accessible workspace folders exists",vector!=null && vector.size()>0); } public void testGetFolderContents()throws Exception{ - String packet = workspaceManagementService.getFolderContents(USER_ID,LAMS_WORKSPACE_FOLDER,WorkspaceManagementService.AUTHORING); - System.out.println("FolderContents:" + packet); + WorkspaceFolder folder = workspaceFolderDAO.getWorkspaceFolderByID(LAMS_WORKSPACE_FOLDER); + Vector vector = workspaceManagementService.getFolderContents(USER_ID,folder,WorkspaceManagementService.AUTHORING); + assertTrue("FolderContents exist",vector!=null && vector.size()>0); } // TODO why does copyfolder seem to take so long @@ -71,7 +71,7 @@ // okay - got the right folder. now delete it. Integer folderId = new Integer(id.intValue()); - String message = workspaceManagementService.deleteFolder(folderId, USER_ID); + workspaceManagementService.deleteFolder(folderId, USER_ID); try{ workspaceFolderDAO.getWorkspaceFolderByID(folderId); fail("Exception should be raised because this object has already been deleted"); @@ -92,7 +92,7 @@ newWorkspaceFolderId = MACQ_UNI_WORKSPACE_FOLDER.intValue(); } - String message = workspaceManagementService.moveFolder(MANPREETS_WORKSPACE_FOLDER,new Integer(newWorkspaceFolderId), USER_ID); + workspaceManagementService.moveFolder(MANPREETS_WORKSPACE_FOLDER,new Integer(newWorkspaceFolderId), USER_ID); WorkspaceFolder workspaceFolder = workspaceFolderDAO.getWorkspaceFolderByID(MANPREETS_WORKSPACE_FOLDER); assertEquals(workspaceFolder.getParentWorkspaceFolder().getWorkspaceFolderId().intValue(), newWorkspaceFolderId); } @@ -112,6 +112,7 @@ /**This method just creates different versions of the given file. Checks the version in both * the wddx packet and the database object. */ public void testUpdateWorkspaceFolderContent() throws Exception{ + // create some content to play with. name must be unique or it will throw a key error. String name = "testUpdateWorkspaceFolderContent"+System.currentTimeMillis(); String message = workspaceManagementService.createWorkspaceFolderContent( @@ -152,7 +153,7 @@ assertEquals("packet version matches content value", content2.getVersionID(), nk.getVersion()); // delete a version and make sure previous version is picked up. - String message2 = workspaceManagementService.deleteContentWithVersion(nk.getUuid(),nk.getVersion(),folderContentId); + workspaceManagementService.deleteContentWithVersion(nk.getUuid(),nk.getVersion(),folderContentId); nk = extractNodeKeyFromWDDXPacket(message); assertEquals("packet has deleted version 5", nk.getVersion().longValue(), 5); @@ -183,7 +184,7 @@ // okay, we found the content, so now we can delete it. Long folderContentId = content.getFolderContentID(); - String deleteMessage = workspaceManagementService.deleteWorkspaceFolderContent(folderContentId); + workspaceManagementService.deleteWorkspaceFolderContent(folderContentId); try{ workspaceFolderContentDAO.getWorkspaceFolderContentByID(folderContentId); fail("Exception should be raised because this object has already been deleted"); @@ -199,12 +200,13 @@ * @param content * @return */ - private WorkspaceFolderContent getMatchingContent(NodeKey nk, Long folderId) { + private WorkspaceFolderContent getMatchingContent(NodeKey nk, Integer folderId) { assertNotNull(nk); assertNotNull(folderId); - List contentList = workspaceFolderContentDAO.getContentByWorkspaceFolder(folderId); - assertNotNull(contentList); - Iterator iter = contentList.iterator(); + WorkspaceFolder folder = workspaceFolderDAO.getWorkspaceFolderByID(folderId); + Set content = folder.getFolderContent(); + assertNotNull(content); + Iterator iter = content.iterator(); while (iter.hasNext()) { WorkspaceFolderContent element = (WorkspaceFolderContent) iter.next(); if ( element.getUuid().equals(nk.getUuid())) { Index: lams_central/web/WEB-INF/lams.tld =================================================================== diff -u -rdad7ee6473474be755626f415cd0cae6b2ecf825 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_central/web/WEB-INF/lams.tld (.../lams.tld) (revision dad7ee6473474be755626f415cd0cae6b2ecf825) +++ lams_central/web/WEB-INF/lams.tld (.../lams.tld) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -33,6 +33,7 @@ empty + Output details from the shared session UserDTO object property true @@ -63,6 +64,7 @@ empty + Output stylesheet based on the user preferences. localLink false Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/learningdesign/Activity.hbm.xml =================================================================== diff -u -r57fbfc34b82cddfb18fc2022aa1cedaf09fa8759 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/learningdesign/Activity.hbm.xml (.../Activity.hbm.xml) (revision 57fbfc34b82cddfb18fc2022aa1cedaf09fa8759) +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/learningdesign/Activity.hbm.xml (.../Activity.hbm.xml) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -213,8 +213,8 @@ public abstract - - @hibernate.set lazy="false" inverse="true" cascade="none" + + @hibernate.set lazy="false" inverse="true" cascade="all-delete-orphan" sort="org.lamsfoundation.lams.learningdesign.ActivityOrderComparator" @hibernate.collection-key column="parent_activity_id" @hibernate.collection-one-to-many class="org.lamsfoundation.lams.learningdesign.Activity" Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/learningdesign/LearningDesign.hbm.xml =================================================================== diff -u -r661b2423ae0cf4ff292bb6052434e14174858383 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/learningdesign/LearningDesign.hbm.xml (.../LearningDesign.hbm.xml) (revision 661b2423ae0cf4ff292bb6052434e14174858383) +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/learningdesign/LearningDesign.hbm.xml (.../LearningDesign.hbm.xml) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -211,16 +211,15 @@ - + - - - + + + - Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/usermanagement/WorkspaceFolder.hbm.xml =================================================================== diff -u -r42ddbd4c509c956cc9f5328cea8d45d6e593e796 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/usermanagement/WorkspaceFolder.hbm.xml (.../WorkspaceFolder.hbm.xml) (revision 42ddbd4c509c956cc9f5328cea8d45d6e593e796) +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/usermanagement/WorkspaceFolder.hbm.xml (.../WorkspaceFolder.hbm.xml) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -147,7 +147,7 @@ - + @hibernate.set lazy="false" inverse="true" cascade="none" @hibernate.collection-key column="user_id" @hibernate.collection-one-to-many class="org.lamsfoundation.lams.learningdesign.LearningDesign" Index: lams_common/src/java/org/lamsfoundation/lams/dao/IBaseDAO.java =================================================================== diff -u -r0df1c403ef3f6ce1360f852afd55ae847409f65a -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_common/src/java/org/lamsfoundation/lams/dao/IBaseDAO.java (.../IBaseDAO.java) (revision 0df1c403ef3f6ce1360f852afd55ae847409f65a) +++ lams_common/src/java/org/lamsfoundation/lams/dao/IBaseDAO.java (.../IBaseDAO.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -31,14 +31,25 @@ public interface IBaseDAO { /** + * Insert an object into the database. Should only be used if the object has not + * been persisted previously. + * * @param object The object to be inserted */ public void insert(Object object); /** + * Update a previously inserted object into the database. * @param object The object to be updated */ public void update(Object object); /** + * Insert or update an object into the database. It is up to the persistence + * engine to decide whether to insert or update. + * @param object The object to be inserted/updated + */ + public void insertOrUpdate(Object object); + /** + * Remove an object from the database. * @param object The object to be deleted */ public void delete(Object object); Index: lams_common/src/java/org/lamsfoundation/lams/dao/hibernate/BaseDAO.java =================================================================== diff -u -r0df1c403ef3f6ce1360f852afd55ae847409f65a -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_common/src/java/org/lamsfoundation/lams/dao/hibernate/BaseDAO.java (.../BaseDAO.java) (revision 0df1c403ef3f6ce1360f852afd55ae847409f65a) +++ lams_common/src/java/org/lamsfoundation/lams/dao/hibernate/BaseDAO.java (.../BaseDAO.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -39,23 +39,27 @@ */ public void insert(Object object) { this.getHibernateTemplate().save(object); - this.getHibernateTemplate().flush(); } /** * @see org.lamsfoundation.lams.learningdesign.dao.interfaces.IBaseDAO#update(java.lang.Object) */ public void update(Object object) { this.getHibernateTemplate().update(object); - this.getHibernateTemplate().flush(); } + /** + * @see org.lamsfoundation.lams.learningdesign.dao.interfaces.IBaseDAO#insertOrUpdate(java.lang.Object) + */ + public void insertOrUpdate(Object object) { + this.getHibernateTemplate().saveOrUpdate(object); + } + /** * @see org.lamsfoundation.lams.learningdesign.dao.interfaces.IBaseDAO#delete(java.lang.Object) */ public void delete(Object object) { this.getHibernateTemplate().delete(object); - this.getHibernateTemplate().flush(); } /** Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/ComplexActivity.java =================================================================== diff -u -r57fbfc34b82cddfb18fc2022aa1cedaf09fa8759 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/ComplexActivity.java (.../ComplexActivity.java) (revision 57fbfc34b82cddfb18fc2022aa1cedaf09fa8759) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/ComplexActivity.java (.../ComplexActivity.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -103,21 +103,16 @@ } /** - * @hibernate.set lazy="true" inverse="true" cascade="none" + * @hibernate.set lazy="true" inverse="true" cascade="all-delete-orphan" sort="org.lamsfoundation.lams.learningdesign.ActivityOrderComparator" * @hibernate.collection-key column="parent_activity_id" * @hibernate.collection-one-to-many class="org.lamsfoundation.lams.learningdesign.Activity" * */ public Set getActivities() { - if(this.activities==null){ + if(this.activities==null){ setActivities(new TreeSet(new ActivityOrderComparator())); - return this.activities; } - else{ - TreeSet sortedActivities = new TreeSet(new ActivityOrderComparator()); - sortedActivities.addAll(this.activities); - return sortedActivities; - } + return this.activities; } public void setActivities(Set activities) { Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/LearningDesign.java =================================================================== diff -u -r661b2423ae0cf4ff292bb6052434e14174858383 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/LearningDesign.java (.../LearningDesign.java) (revision 661b2423ae0cf4ff292bb6052434e14174858383) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/LearningDesign.java (.../LearningDesign.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -22,23 +22,23 @@ */ package org.lamsfoundation.lams.learningdesign; -import org.lamsfoundation.lams.learningdesign.dto.DesignDetailDTO; -import org.lamsfoundation.lams.learningdesign.dto.LearningDesignDTO; -import org.lamsfoundation.lams.usermanagement.User; -import org.lamsfoundation.lams.usermanagement.WorkspaceFolder; -import org.lamsfoundation.lams.workspace.dto.FolderContentDTO; - import java.io.Serializable; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import java.util.SortedSet; import java.util.TreeSet; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; +import org.lamsfoundation.lams.learningdesign.dto.DesignDetailDTO; +import org.lamsfoundation.lams.learningdesign.dto.LearningDesignDTO; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.WorkspaceFolder; +import org.lamsfoundation.lams.workspace.dto.FolderContentDTO; /** @@ -179,7 +179,7 @@ User user, LearningDesign originalLearningDesign, Set childLearningDesigns, Set lessons, Set transitions, - Set activities, + SortedSet activities, Long duration, String licenseText, License license, @@ -230,7 +230,7 @@ User user, org.lamsfoundation.lams.learningdesign.LearningDesign originalLearningDesign, Set childLearningDesigns, Set lessons, Set transitions, - Set activities) { + SortedSet activities) { this.learningDesignId = learningDesignId; this.validDesign = validDesign; this.readOnly = readOnly; @@ -383,6 +383,9 @@ this.lessons = lessons; } public Set getTransitions() { + if ( this.transitions==null) { + setTransitions(new HashSet()); + } return this.transitions; } public void setTransitions(Set transitions) { @@ -391,13 +394,8 @@ public Set getActivities() { if(this.activities==null){ setActivities(new TreeSet(new ActivityOrderComparator())); - return this.activities; } - else{ - TreeSet sortedActivities = new TreeSet(new ActivityOrderComparator()); - sortedActivities.addAll(this.activities); - return sortedActivities; - } + return this.activities; } public void setActivities(Set activities) { this.activities = activities; Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/OptionsActivity.java =================================================================== diff -u -r57fbfc34b82cddfb18fc2022aa1cedaf09fa8759 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/OptionsActivity.java (.../OptionsActivity.java) (revision 57fbfc34b82cddfb18fc2022aa1cedaf09fa8759) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/OptionsActivity.java (.../OptionsActivity.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -24,6 +24,8 @@ import java.io.Serializable; import java.util.Date; +import java.util.Set; + import org.apache.commons.lang.builder.ToStringBuilder; import org.lamsfoundation.lams.learningdesign.strategy.OptionsActivityStrategy; @@ -63,7 +65,7 @@ Transition transitionTo, Transition transitionFrom, String languageFile, - java.util.Set activities, + Set activities, Integer maxNumberOfOptions, Integer minNumberOfOptions, String options_instructions) { @@ -109,7 +111,7 @@ Integer activityTypeId, Transition transitionTo, Transition transitionFrom, - java.util.Set activities) { + Set activities) { super(activityId, defineLater, createDateTime, Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/ParallelActivity.java =================================================================== diff -u -r57fbfc34b82cddfb18fc2022aa1cedaf09fa8759 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/ParallelActivity.java (.../ParallelActivity.java) (revision 57fbfc34b82cddfb18fc2022aa1cedaf09fa8759) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/ParallelActivity.java (.../ParallelActivity.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -24,6 +24,7 @@ import java.io.Serializable; import java.util.Date; +import java.util.Set; import org.apache.commons.lang.builder.ToStringBuilder; import org.lamsfoundation.lams.learningdesign.strategy.ParallelActivityStrategy; @@ -54,7 +55,7 @@ Transition transitionTo, Transition transitionFrom, String languageFile, - java.util.Set activities) { + Set activities) { super(activityId, id, description, @@ -94,7 +95,7 @@ Integer activityTypeId, Transition transitionTo, Transition transitionFrom, - java.util.Set activities) { + Set activities) { super(activityId, defineLater, createDateTime, Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/SequenceActivity.java =================================================================== diff -u -r57fbfc34b82cddfb18fc2022aa1cedaf09fa8759 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/SequenceActivity.java (.../SequenceActivity.java) (revision 57fbfc34b82cddfb18fc2022aa1cedaf09fa8759) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/SequenceActivity.java (.../SequenceActivity.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -24,6 +24,7 @@ import java.io.Serializable; import java.util.Date; +import java.util.SortedSet; import org.apache.commons.lang.builder.ToStringBuilder; import org.lamsfoundation.lams.learningdesign.strategy.SequenceActivityStrategy; @@ -55,7 +56,7 @@ Transition transitionTo, Transition transitionFrom, String languageFile, - java.util.Set activities) { + SortedSet activities) { super(activityId, id, description, @@ -96,7 +97,7 @@ Integer activityTypeId, Transition transitionTo, Transition transitionFrom, - java.util.Set activities) { + SortedSet activities) { super(activityId, defineLater, createDateTime, Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/ToolActivity.java =================================================================== diff -u -r57fbfc34b82cddfb18fc2022aa1cedaf09fa8759 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/ToolActivity.java (.../ToolActivity.java) (revision 57fbfc34b82cddfb18fc2022aa1cedaf09fa8759) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/ToolActivity.java (.../ToolActivity.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -26,6 +26,7 @@ import java.util.Date; import java.util.Set; import java.util.SortedSet; +import java.util.TreeSet; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.log4j.Logger; @@ -304,6 +305,9 @@ * @return Returns the toolSessions. */ public Set getToolSessions() { + if ( toolSessions == null ) { + setToolSessions(new TreeSet(new ActivityOrderComparator())); + } return toolSessions; } /** Index: lams_common/src/java/org/lamsfoundation/lams/tool/service/LamsCoreToolService.java =================================================================== diff -u -r99afcd5c1bc96c9655c1bc463318dbcb322f49cd -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_common/src/java/org/lamsfoundation/lams/tool/service/LamsCoreToolService.java (.../LamsCoreToolService.java) (revision 99afcd5c1bc96c9655c1bc463318dbcb322f49cd) +++ lams_common/src/java/org/lamsfoundation/lams/tool/service/LamsCoreToolService.java (.../LamsCoreToolService.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -105,6 +105,13 @@ // if haven't found an existing tool session then create one if( toolSession == null ) { + + if ( log.isDebugEnabled() ) { + log.debug("Creating tool session for ["+activity.getActivityId()+","+activity.getTitle() + +"] for learner ["+learner.getLogin() + +"] lesson ["+lesson.getLessonId()+","+lesson.getLessonName()+"]."); + } + toolSession = activity.createToolSessionForActivity(learner,lesson); toolSessionDAO.saveToolSession(toolSession); return toolSession; Index: lams_common/src/java/org/lamsfoundation/lams/usermanagement/User.java =================================================================== diff -u -r68fdd810d9d632c62421bc5e67b87f054ce2337f -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_common/src/java/org/lamsfoundation/lams/usermanagement/User.java (.../User.java) (revision 68fdd810d9d632c62421bc5e67b87f054ce2337f) +++ lams_common/src/java/org/lamsfoundation/lams/usermanagement/User.java (.../User.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -688,13 +688,15 @@ * has read and write access but cannot modify anybody else's content/stuff **/ public boolean hasMemberAccess(WorkspaceFolder workspaceFolder){ - Iterator iterator = this.userOrganisations.iterator(); - while(iterator.hasNext()){ - UserOrganisation userOrganisation = (UserOrganisation)iterator.next(); - Integer folderID = userOrganisation.getOrganisation().getWorkspace().getRootFolder().getWorkspaceFolderId(); - if(folderID==workspaceFolder.getWorkspaceFolderId()) - return true; - } + Integer workspaceFolderID = workspaceFolder != null ? workspaceFolder.getWorkspaceFolderId() : null; + if ( workspaceFolderID != null ) { + Iterator iterator = this.userOrganisations.iterator(); + while(iterator.hasNext()){ + UserOrganisation userOrganisation = (UserOrganisation)iterator.next(); + Integer folderID = userOrganisation.getOrganisation().getWorkspace().getRootFolder().getWorkspaceFolderId(); + return ( workspaceFolderID.equals(folderID) ); + } + } return false; } Index: lams_common/src/java/org/lamsfoundation/lams/usermanagement/WorkspaceFolder.java =================================================================== diff -u -r55901923afea1cbd769d8daa05051aa050bb99b6 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_common/src/java/org/lamsfoundation/lams/usermanagement/WorkspaceFolder.java (.../WorkspaceFolder.java) (revision 55901923afea1cbd769d8daa05051aa050bb99b6) +++ lams_common/src/java/org/lamsfoundation/lams/usermanagement/WorkspaceFolder.java (.../WorkspaceFolder.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -376,4 +376,9 @@ this.folderContent.add(workspaceFolderContent); } + + /** Is this folder a run sequences folder? */ + public boolean isRunSequencesFolder() { + return workspaceFolderType.equals(RUN_SEQUENCES); + } } Index: lams_common/src/java/org/lamsfoundation/lams/workspace/dao/IWorkspaceFolderContentDAO.java =================================================================== diff -u -r0df1c403ef3f6ce1360f852afd55ae847409f65a -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_common/src/java/org/lamsfoundation/lams/workspace/dao/IWorkspaceFolderContentDAO.java (.../IWorkspaceFolderContentDAO.java) (revision 0df1c403ef3f6ce1360f852afd55ae847409f65a) +++ lams_common/src/java/org/lamsfoundation/lams/workspace/dao/IWorkspaceFolderContentDAO.java (.../IWorkspaceFolderContentDAO.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -42,25 +42,6 @@ public WorkspaceFolderContent getWorkspaceFolderContentByID(Long folderContentID); /** - * This method returns the content for the given WorkspaceFolder - * with given workspaceFolderID. - * - * @param workspaceFolderID The WorkspaceFolder whose content is requested - * @return List The requested content - */ - public List getContentByWorkspaceFolder(Long workspaceFolderID); - - /** - * This method returns the content of the WorkspaceFolder - * with given workspaceFolderID, which is of requested mimeType - * - * @param workspaceFolderID The WorkspaceFolder whose content is requested - * @param mimeType The mimeType of the requested content - * @return List The requested content - */ - public List getContentByTypeFromWorkspaceFolder(Long workspaceFolderID, String mimeType); - - /** * This method deletes the content with the given UUID, versionID * from the content table. * Index: lams_common/src/java/org/lamsfoundation/lams/workspace/dao/hibernate/WorkspaceFolderContentDAO.java =================================================================== diff -u -r0df1c403ef3f6ce1360f852afd55ae847409f65a -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_common/src/java/org/lamsfoundation/lams/workspace/dao/hibernate/WorkspaceFolderContentDAO.java (.../WorkspaceFolderContentDAO.java) (revision 0df1c403ef3f6ce1360f852afd55ae847409f65a) +++ lams_common/src/java/org/lamsfoundation/lams/workspace/dao/hibernate/WorkspaceFolderContentDAO.java (.../WorkspaceFolderContentDAO.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -36,10 +36,6 @@ private static final String TABLENAME ="lams_workspace_folder_content"; - private static final String FIND_BY_FOLDER ="from " + TABLENAME +" in class " + - WorkspaceFolderContent.class.getName() + - " where workspace_folder_id=?"; - private static final String FIND_BY_TYPE_IN_FOLDER = "from " + TABLENAME +" in class " + WorkspaceFolderContent.class.getName() + " where workspace_folder_id=? AND mime_type=?"; @@ -58,27 +54,6 @@ /** * (non-Javadoc) - * @see org.lamsfoundation.lams.workspace.dao.IWorkspaceFolderContentDAO#getContentByWorkspaceFolder(java.lang.Long) - */ - public List getContentByWorkspaceFolder(Long workspaceFolderID) { - return this.getHibernateTemplate().find(FIND_BY_FOLDER,workspaceFolderID); - } - - /** - * (non-Javadoc) - * @see org.lamsfoundation.lams.workspace.dao.IWorkspaceFolderContentDAO#getContentByTypeFromWorkspaceFolder(java.lang.Long, java.lang.String) - */ - public List getContentByTypeFromWorkspaceFolder(Long workspaceFolderID,String mimeType) { - if ( workspaceFolderID !=null ) { - return this.getSession().createQuery(FIND_BY_TYPE_IN_FOLDER) - .setLong(0,workspaceFolderID.longValue()) - .setString(1,mimeType) - .list(); - } - return null; - } - /** - * (non-Javadoc) * @see org.lamsfoundation.lams.workspace.dao.IWorkspaceFolderContentDAO#deleteContentWithVersion(java.lang.Long, java.lang.Long, java.lang.Long) */ public int deleteContentWithVersion(Long uuid, Long versionID, Long folderContentID){ Index: lams_common/test/java/org/lamsfoundation/lams/theme/service/TestThemeService.java =================================================================== diff -u --- lams_common/test/java/org/lamsfoundation/lams/theme/service/TestThemeService.java (revision 0) +++ lams_common/test/java/org/lamsfoundation/lams/theme/service/TestThemeService.java (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -0,0 +1,177 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ +package org.lamsfoundation.lams.theme.service; + +import org.lamsfoundation.lams.test.AbstractLamsTestCase; +import org.lamsfoundation.lams.themes.service.IThemeService; + +public class TestThemeService extends AbstractLamsTestCase { + + private IThemeService themeService; + + private static final Long TEST_THEME_ID = new Long(1); + public TestThemeService(String name) { + super(name); + } + + protected void setUp()throws Exception{ + super.setUp(); + themeService =(IThemeService)context.getBean("themeService"); + } + protected String getHibernateSessionFactoryName() { + return "coreSessionFactory"; + } + protected String[] getContextConfigLocation() { + return new String[] {"org/lamsfoundation/lams/localApplicationContext.xml" }; + } + + public void testStoreTheme() throws Exception{ + String str = themeService.storeTheme(TEST_NEW_THEME_WDDX); + assertTrue("storeTheme returned WDDX packet", str!=null && str.startsWith(" NO_THEME_RESPONSE.length()); + + } + + public void testGetTheme() throws Exception{ + String str = themeService.getTheme(TEST_THEME_ID); + System.out.println(str); + assertTrue("Finds ruby theme", str.indexOf("ruby") != -1); + } + + /* ******* WDDX Packets **************************************/ + + private static final String TEST_NEW_THEME_WDDX = + "
"+ + ""+ + ""+ + ""+ + "outset"+ + "16711680"+ + "16711680"+ + "16711680"+ + ""+ + ""+ + "_sans"+ + "10"+ + "12452097"+ + "block"+ + ""+ + ""+ + ""+ + ""+ + "AuthoringTestTheme"+ + "theme used for TestAuthoringService"+ + ""+ + ""+ + ""+ + "button"+ + ""+ + ""+ + "outset"+ + "16711680"+ + "16711680"+ + "16711680"+ + ""+ + ""+ + "7174353"+ + "block"+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""; + + private static final String TEST_NEW_THEME_WDDX2_PART1 = + "
"+ + ""+ + ""+ + ""+ + "outset2"+ + "16711681"+ + "16711681"+ + "16711681"+ + ""+ + ""+ + "_sans"+ + "11"+ + "12452098"+ + "block2"+ + ""+ + ""+ + ""+ + ""+ + ""; + + private static final String TEST_NEW_THEME_WDDX2_PART2 = + ""+ + "AuthoringTestTheme2"+ + "theme used for TestAuthoringService2"+ + ""+ + ""+ + ""+ + "button"+ + ""+ + ""+ + "outset2"+ + "16711681"+ + "16711681"+ + "16711681"+ + ""+ + ""+ + "7174354"+ + "block2"+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""; + + private static final String NO_THEME_RESPONSE = + "
" + +"getThemes" + +"3.0" + +""; + + +} Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/ILearnerService.java =================================================================== diff -u -r29cf7c9f1421fde2bc6a38c5f56632b5acc11d70 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_learning/src/java/org/lamsfoundation/lams/learning/service/ILearnerService.java (.../ILearnerService.java) (revision 29cf7c9f1421fde2bc6a38c5f56632b5acc11d70) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/ILearnerService.java (.../ILearnerService.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -52,7 +52,7 @@ * @param lessionID identifies the Lesson to start * @throws LearnerServiceException in case of problems. */ - public LearnerProgress joinLesson(User learner, Lesson lesson) ; + public LearnerProgress joinLesson(User learner, Long lessonID) ; /** Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java =================================================================== diff -u -r0d77512288c6e2c920406ae8f3fe546bf0d93c1a -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java (.../LearnerService.java) (revision 0d77512288c6e2c920406ae8f3fe546bf0d93c1a) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java (.../LearnerService.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -197,8 +197,9 @@ * @throws LamsToolServiceException * @throws LearnerServiceException in case of problems. */ - public LearnerProgress joinLesson(User learner, Lesson lesson) + public LearnerProgress joinLesson(User learner, Long lessonID) { + Lesson lesson = getLesson(lessonID); LearnerProgress learnerProgress = learnerProgressDAO.getLearnerProgressByLearner(learner,lesson); if(learnerProgress==null) @@ -288,7 +289,7 @@ learnerProgress = progressEngine.calculateProgress(learner, lesson, completedActivity,learnerProgress); learnerProgressDAO.updateLearnerProgress(learnerProgress); - // createToolSessionsIfNecessary(learnerProgress); + createToolSessionsIfNecessary(learnerProgress); } catch (ProgressException e) { Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/LearnerAction.java =================================================================== diff -u -ra068098703ce1ee36cc9e8dcf92165ab5c1be2e7 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/LearnerAction.java (.../LearnerAction.java) (revision a068098703ce1ee36cc9e8dcf92165ab5c1be2e7) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/LearnerAction.java (.../LearnerAction.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -170,23 +170,24 @@ //get user and lesson based on request. User learner = LearningWebUtil.getUserData(getServlet().getServletContext()); - Lesson lesson = LearningWebUtil.getLessonData(request,getServlet().getServletContext()); + long lessonID = WebUtil.readLongParam(request,LearningWebUtil.PARAM_LESSON_ID); if(log.isDebugEnabled()) log.debug("The learner ["+learner.getUserId()+"],["+learner.getFullName() - +"is joining the lesson ["+lesson.getLessonId()+"],["+lesson.getLessonName()+"]"); + +"is joining the lesson ["+lessonID+"]"); //join user to the lesson on the server - LearnerProgress learnerProgress = learnerService.joinLesson(learner,lesson); + LearnerProgress learnerProgress = learnerService.joinLesson(learner,lessonID); if(log.isDebugEnabled()) log.debug("The learner ["+learner.getUserId()+"] joined lesson. The" +"porgress data is:"+learnerProgress.toString()); + // TODO replace with JBOSS cache + //LessonLearnerDataManager.cacheLessonUser(getServlet().getServletContext(), + // lesson,learner); - LessonLearnerDataManager.cacheLessonUser(getServlet().getServletContext(), - lesson,learner); //setup session attributes //request.getSession().setAttribute(SessionBean.NAME,new SessionBean(learner, // lesson, Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LearningWebUtil.java =================================================================== diff -u -ra068098703ce1ee36cc9e8dcf92165ab5c1be2e7 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LearningWebUtil.java (.../LearningWebUtil.java) (revision a068098703ce1ee36cc9e8dcf92165ab5c1be2e7) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LearningWebUtil.java (.../LearningWebUtil.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -106,7 +106,8 @@ ILearnerService learnerService = LearnerServiceProxy.getLearnerService(servletContext); long lessonId = WebUtil.readLongParam(request,PARAM_LESSON_ID); lesson = learnerService.getLesson(new Long(lessonId)); - request.getSession().setAttribute(ATTR_LESSON_DATA,lesson); +// TODO don't cache it currently - would do it via jboss cache! +// request.getSession().setAttribute(ATTR_LESSON_DATA,lesson); } return lesson; } @@ -133,8 +134,9 @@ LearnerProgress progress = learnerService.getProgress(currentLearner,lesson); bean = new SessionBean(currentLearner,lesson,progress); - request.getSession().setAttribute(SessionBean.NAME,bean); - request.getSession().setAttribute(ActivityAction.LEARNER_PROGRESS_REQUEST_ATTRIBUTE,progress); +// TODO don't cache it currently - would do it via jboss cache! +// request.getSession().setAttribute(SessionBean.NAME,bean); +// request.getSession().setAttribute(ActivityAction.LEARNER_PROGRESS_REQUEST_ATTRIBUTE,progress); } return bean; } @@ -158,7 +160,8 @@ learnerProgress = learnerService.getProgressById(new Long(learnerProgressId)); - request.getSession().setAttribute(ActivityAction.LEARNER_PROGRESS_REQUEST_ATTRIBUTE,learnerProgress); +// TODO don't cache it currently - would do it via jboss cache! +// request.getSession().setAttribute(ActivityAction.LEARNER_PROGRESS_REQUEST_ATTRIBUTE,learnerProgress); } return learnerProgress; } @@ -182,7 +185,8 @@ learnerProgress = learnerService.getProgress(currentLearner,lesson); - request.getSession().setAttribute(ActivityAction.LEARNER_PROGRESS_REQUEST_ATTRIBUTE,learnerProgress); +// TODO don't cache it currently - would do it via jboss cache! +// request.getSession().setAttribute(ActivityAction.LEARNER_PROGRESS_REQUEST_ATTRIBUTE,learnerProgress); } return learnerProgress; } Index: lams_learning/test/java/org/lamsfoundation/lams/learning/service/TestLearnerService.java =================================================================== diff -u -r29cf7c9f1421fde2bc6a38c5f56632b5acc11d70 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_learning/test/java/org/lamsfoundation/lams/learning/service/TestLearnerService.java (.../TestLearnerService.java) (revision 29cf7c9f1421fde2bc6a38c5f56632b5acc11d70) +++ lams_learning/test/java/org/lamsfoundation/lams/learning/service/TestLearnerService.java (.../TestLearnerService.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -152,7 +152,7 @@ public void testJoinLesson() throws ProgressException,LamsToolServiceException { - learnerService.joinLesson(testUser,testLesson); + learnerService.joinLesson(testUser,Test_Lesson_ID); testProgress=learnerProgressDao.getLearnerProgressByLearner(testUser,testLesson); assertNotNull(testProgress); Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java =================================================================== diff -u -r52f3ab1ab2051d0d28ca7d7f96dd28ed08624aa8 -r01a4035d52575ebe0a8467b4e589998196353962 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 52f3ab1ab2051d0d28ca7d7f96dd28ed08624aa8) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 01a4035d52575ebe0a8467b4e589998196353962) @@ -346,7 +346,7 @@ } } - authoringService.updateLearningDesign(copiedLearningDesign); + authoringService.saveLearningDesign(copiedLearningDesign); return createNewLesson(lessonName,lessonDescription,user,copiedLearningDesign);