Index: lams_central/src/java/org/lamsfoundation/lams/authoring/ObjectExtractor.java =================================================================== diff -u -rbdfb58d0bbf6d0bbaae0f5ef1b3c599f4f78d5ed -rf68119fe9c6926dfc9b1697ce031a6fb56a39a60 --- lams_central/src/java/org/lamsfoundation/lams/authoring/ObjectExtractor.java (.../ObjectExtractor.java) (revision bdfb58d0bbf6d0bbaae0f5ef1b3c599f4f78d5ed) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/ObjectExtractor.java (.../ObjectExtractor.java) (revision f68119fe9c6926dfc9b1697ce031a6fb56a39a60) @@ -24,6 +24,7 @@ package org.lamsfoundation.lams.authoring; import java.util.HashMap; +import java.util.HashSet; import java.util.Hashtable; import java.util.Iterator; import java.util.List; @@ -105,8 +106,11 @@ * 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 HashMap newActivityMap = new HashMap(); + // cache of groupings - too hard to get them from the db protected HashMap groupings = new HashMap(); + // can't delete as we go as they are linked to other items - keep a list and delete at the end. + protected Set groupingsToDelete = new HashSet(); protected LearningDesign learningDesign = null; protected Logger log = Logger.getLogger(ObjectExtractor.class); @@ -348,6 +352,7 @@ learningDesign.setFirstActivity(learningDesign.calculateFirstActivity()); learningDesignDAO.insertOrUpdate(learningDesign); + deleteUnwantedGroupings(); return learningDesign; } @@ -364,7 +369,13 @@ groupings.put(grouping.getGroupingUIID(), grouping); } } - + + /** Delete the old unneeded groupings. Won't be done via a cascase */ + private void deleteUnwantedGroupings() { + for ( Grouping grouping: groupingsToDelete) { + groupingDAO.delete(grouping); + } + } /** * Parses the groupings array sent from the WDDX packet. It will create * the groupings object (ChosenGrouping, RandomGrouping) so that when the @@ -409,6 +420,13 @@ } Grouping grouping = groupings.get(groupingUUID); + // check that the grouping type is still okay - if not get rid of the old hibernate object. + if ( grouping != null && ! grouping.getGroupingTypeId().equals(groupingTypeID) ) { + groupings.remove(grouping.getGroupingUIID()); + groupingsToDelete.add(grouping); + grouping = null; + } + if (grouping == null) { Object object = Grouping.getGroupingInstance(groupingTypeID); grouping = (Grouping)object; @@ -417,7 +435,7 @@ grouping.setGroupingId(WDDXProcessor.convertToLong(groupingDetails,WDDXTAGS.GROUPING_ID)); if (keyExists(groupingDetails, WDDXTAGS.GROUPING_UIID)) grouping.setGroupingUIID(WDDXProcessor.convertToInteger(groupingDetails,WDDXTAGS.GROUPING_UIID)); - } + } if(grouping.isRandomGrouping()) createRandomGrouping((RandomGrouping)grouping,groupingDetails); @@ -576,22 +594,22 @@ //it is assumed that the activityUUID will always be sent by flash. Integer activityUUID = WDDXProcessor.convertToInteger(activityDetails,WDDXTAGS.ACTIVITY_UIID); Activity activity = null; - //get the activity with the particular activity uuid, if null, then new object needs to be created. + Integer activityTypeID = WDDXProcessor.convertToInteger(activityDetails, WDDXTAGS.ACTIVITY_TYPE_ID); + if ( activityTypeID == null ) { + throw new ObjectExtractorException("activityTypeID missing"); + } + + //get the activity with the particular activity uuid, if null, then new object needs to be created. Activity existingActivity = activityDAO.getActivityByUIID(activityUUID, learningDesign); - if (existingActivity == null) - { - Integer activityTypeID = WDDXProcessor.convertToInteger(activityDetails, WDDXTAGS.ACTIVITY_TYPE_ID); - if ( activityTypeID == null ) { - throw new ObjectExtractorException("activityTypeID missing"); - } - - Activity activityObject = Activity.getActivityInstance(activityTypeID.intValue()); - activity =(Activity)activityObject; + if (existingActivity != null && ! existingActivity.getActivityTypeId().equals(activityTypeID) ) { + existingActivity = null; + } + + if ( existingActivity != null ) { + activity = existingActivity; + } else { + activity = Activity.getActivityInstance(activityTypeID.intValue()); } - else - { - activity = existingActivity; //otherwise load existing activity - } processActivityType(activity,activityDetails);