Index: lams_central/src/java/org/lamsfoundation/lams/authoring/ObjectExtractor.java =================================================================== diff -u -r56f0a9dbc1b2eab52b3b798c891b4bb5794d4f0d -rbfa0d6c3a6e19b01dffc488bcc18c8d0ed2cfdaf --- lams_central/src/java/org/lamsfoundation/lams/authoring/ObjectExtractor.java (.../ObjectExtractor.java) (revision 56f0a9dbc1b2eab52b3b798c891b4bb5794d4f0d) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/ObjectExtractor.java (.../ObjectExtractor.java) (revision bfa0d6c3a6e19b01dffc488bcc18c8d0ed2cfdaf) @@ -149,8 +149,9 @@ protected HashMap groups = new HashMap(); protected HashMap branchEntries = new HashMap(); protected HashMap defaultActivityMap = 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(); + /* can't delete as we go as they are linked to other items and have no way of knowing from the packet which ones + * will need to be deleted, so start off assuming all need to be deleted and remove the ones we want to keep. */ + protected HashMap groupingsToDelete = new HashMap(); protected LearningDesign learningDesign = null; protected Date modificationDate = null; /* cache of system tools so we aren't going back to the db all the time */ @@ -448,6 +449,7 @@ while (iter.hasNext()) { Grouping grouping = (Grouping) iter.next(); groupings.put(grouping.getGroupingUIID(), grouping); + groupingsToDelete.put(grouping.getGroupingUIID(),grouping); } } @@ -474,7 +476,7 @@ /** Delete the old unneeded groupings. Won't be done via a cascade */ private void deleteUnwantedGroupings() { - for ( Grouping grouping: groupingsToDelete) { + for ( Grouping grouping: groupingsToDelete.values()) { groupingDAO.delete(grouping); } } @@ -555,13 +557,17 @@ } 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; + // check that the grouping type is still okay - if it is we keep the grouping otherwise + // we get rid of the old hibernate object. + if ( grouping != null ) { + if ( grouping.getGroupingTypeId().equals(groupingTypeID) ) { + groupingsToDelete.remove(groupingUUID); + } else { + groupings.remove(grouping.getGroupingUIID()); + grouping = null; + } } - + if (grouping == null) { Object object = Grouping.getGroupingInstance(groupingTypeID); grouping = (Grouping)object;