Index: content-tool/tool/src/java/org/sakaiproject/content/tool/ResourcesAction.java =================================================================== --- content-tool/tool/src/java/org/sakaiproject/content/tool/ResourcesAction.java (revision 106157) +++ content-tool/tool/src/java/org/sakaiproject/content/tool/ResourcesAction.java (working copy) @@ -1518,13 +1518,7 @@ state.setAttribute (STATE_MODE, MODE_LIST); } - // try to expand the collection - SortedSet expandedCollections = (SortedSet) state.getAttribute(STATE_EXPANDED_COLLECTIONS); - if(expandedCollections == null) - { - expandedCollections = new TreeSet(); - state.setAttribute(STATE_EXPANDED_COLLECTIONS, expandedCollections); - } + SortedSet expandedCollections = setStateAttributeExpandedCollections(state); if(! expandedCollections.contains(collectionId)) { expandedCollections.add(collectionId); @@ -2555,12 +2549,7 @@ Comparator userSelectedSort = (Comparator) state.getAttribute(STATE_LIST_VIEW_SORT); - Map expandedFolderSortMap = (Map) state.getAttribute(STATE_EXPANDED_FOLDER_SORT_MAP); - if(expandedFolderSortMap == null) - { - expandedFolderSortMap = new HashMap(); - state.setAttribute(STATE_EXPANDED_FOLDER_SORT_MAP, expandedFolderSortMap); - } + Map expandedFolderSortMap = setStateAttributeExpandedFolderSortMap(state); SortedSet expandedCollections = (SortedSet) state.getAttribute(STATE_EXPANDED_COLLECTIONS); if(expandedCollections == null) @@ -5475,12 +5464,7 @@ { expandedItems = new TreeSet(); } - Map folderSortMap = (Map) state.getAttribute(STATE_EXPANDED_FOLDER_SORT_MAP); - if(folderSortMap == null) - { - folderSortMap = new HashMap(); - state.setAttribute(STATE_EXPANDED_FOLDER_SORT_MAP, folderSortMap); - } + Map folderSortMap = setStateAttributeExpandedFolderSortMap(state); //get the ParameterParser from RunData ParameterParser params = data.getParameters (); @@ -6232,12 +6216,7 @@ { logger.debug(this + ".doExpand_collection()"); SessionState state = ((JetspeedRunData)data).getPortletSessionState (((JetspeedRunData)data).getJs_peid ()); - SortedSet expandedItems = (SortedSet) state.getAttribute(STATE_EXPANDED_COLLECTIONS); - if(expandedItems == null) - { - expandedItems = new TreeSet(); - state.setAttribute(STATE_EXPANDED_COLLECTIONS, expandedItems); - } + SortedSet expandedItems = setStateAttributeExpandedCollections(state); //get the ParameterParser from RunData ParameterParser params = data.getParameters (); @@ -6725,29 +6704,37 @@ state.setAttribute(STATE_COLLECTION_ID, collectionId); - SortedSet currentMap = (SortedSet) state.getAttribute(STATE_EXPANDED_COLLECTIONS); - if(currentMap == null) - { - currentMap = new TreeSet(); - state.setAttribute(STATE_EXPANDED_COLLECTIONS, currentMap); - } + SortedSet currentMap = Collections.synchronizedSortedSet(setStateAttributeExpandedCollections(state)); - Map sortMap = (Map) state.getAttribute(STATE_EXPANDED_FOLDER_SORT_MAP); - if(sortMap == null) + Map sortMap = Collections.synchronizedMap(setStateAttributeExpandedFolderSortMap(state)); + + // sync over sortMap removal + Iterator it = currentMap.iterator(); + synchronized (sortMap) { - sortMap = new HashMap(); - state.setAttribute(STATE_EXPANDED_FOLDER_SORT_MAP, sortMap); + while(it.hasNext()) + { + String id = (String) it.next(); + if(id.startsWith(collectionId)) + { + sortMap.remove(id); + removeObservingPattern(id, state); + } + } } - Iterator it = currentMap.iterator(); - while(it.hasNext()) + // sync over currentMap removal + it = currentMap.iterator(); + synchronized (it) { - String id = (String) it.next(); - if(id.startsWith(collectionId)) + while(it.hasNext()) { - it.remove(); - sortMap.remove(id); - removeObservingPattern(id, state); + String id = (String) it.next(); + if(id.startsWith(collectionId)) + { + + it.remove(); + } } } @@ -6764,6 +6751,36 @@ } // doNavigate /** + * get/init state attribute STATE_EXPANDED_FOLDER_SORT_MAP + * @param state + * @return + */ + private static Map setStateAttributeExpandedFolderSortMap(SessionState state) { + Map sortMap = (Map) state.getAttribute(STATE_EXPANDED_FOLDER_SORT_MAP); + if(sortMap == null) + { + sortMap = new HashMap(); + state.setAttribute(STATE_EXPANDED_FOLDER_SORT_MAP, sortMap); + } + return sortMap; + } + + /** + * get/init state attribute STATE_EXPANDED_COLLECTIONS + * @param state + * @return + */ + private static SortedSet setStateAttributeExpandedCollections(SessionState state) { + SortedSet currentMap = (SortedSet) state.getAttribute(STATE_EXPANDED_COLLECTIONS); + if(currentMap == null) + { + currentMap = new TreeSet(); + state.setAttribute(STATE_EXPANDED_COLLECTIONS, currentMap); + } + return currentMap; + } + + /** * Fire up the permissions editor for the tool's permissions */ public void doPermissions(RunData data, Context context) @@ -7052,12 +7069,7 @@ expandedCollections.add(folderId); Comparator comparator = ContentHostingService.newContentHostingComparator(ResourceProperties.PROP_CONTENT_PRIORITY, true); - Map expandedFolderSortMap = (Map) state.getAttribute(STATE_EXPANDED_FOLDER_SORT_MAP); - if(expandedFolderSortMap == null) - { - expandedFolderSortMap = new HashMap(); - state.setAttribute(STATE_EXPANDED_FOLDER_SORT_MAP, expandedFolderSortMap); - } + Map expandedFolderSortMap = setStateAttributeExpandedFolderSortMap(state); expandedFolderSortMap.put(folderId, comparator); } catch(IdUnusedException e) Index: content-tool/tool/src/java/org/sakaiproject/content/tool/ListItem.java =================================================================== --- content-tool/tool/src/java/org/sakaiproject/content/tool/ListItem.java (revision 106157) +++ content-tool/tool/src/java/org/sakaiproject/content/tool/ListItem.java (working copy) @@ -158,6 +158,8 @@ */ public static ListItem getListItem(ContentEntity entity, ListItem parent, ResourceTypeRegistry registry, boolean expandAll, Set expandedFolders, List items_to_be_moved, List items_to_be_copied, int depth, Comparator userSelectedSort, boolean preventPublicDisplay, ContentResourceFilter addFilter) { + Set expandedFoldersSync = Collections.synchronizedSet(expandedFolders); + ListItem item = null; org.sakaiproject.content.api.ContentHostingService contentService = (org.sakaiproject.content.api.ContentHostingService) ComponentManager.get(org.sakaiproject.content.api.ContentHostingService.class); @@ -206,115 +208,118 @@ item.setPermissions(ResourcesAction.getPermissions(entity.getId(), null)); } - if(isCollection) + synchronized(expandedFoldersSync) { - ContentCollection collection = (ContentCollection) entity; - - if(item.isTooBig) - { - // do nothing - } - else if(expandAll) - { - String typeId = entity.getResourceType(); - if(typeId != null && registry != null) - { - ResourceType typeDef = registry.getType(typeId); - if(typeDef != null && typeDef.isExpandable()) + if(isCollection) + { + ContentCollection collection = (ContentCollection) entity; + + if(item.isTooBig) + { + // do nothing + } + else if(expandAll) + { + String typeId = entity.getResourceType(); + if(typeId != null && registry != null) { - ServiceLevelAction expandAction = ((ExpandableResourceType) typeDef).getExpandAction(); - if(expandAction != null && expandAction.available(entity)) + ResourceType typeDef = registry.getType(typeId); + if(typeDef != null && typeDef.isExpandable()) { - expandAction.initializeAction(item.m_reference); - - expandedFolders.add(entity.getId()); - - expandAction.finalizeAction(item.m_reference); + ServiceLevelAction expandAction = ((ExpandableResourceType) typeDef).getExpandAction(); + if(expandAction != null && expandAction.available(entity)) + { + expandAction.initializeAction(item.m_reference); + + expandedFoldersSync.add(entity.getId()); + + expandAction.finalizeAction(item.m_reference); + } } } - } - } - if(expandedFolders.contains(entity.getId())) - { - item.setExpanded(true); - - List children = collection.getMemberResources(); - - Comparator comparator = null; - if(userSelectedSort != null) + } + if(expandedFoldersSync.contains(entity.getId())) { - comparator = userSelectedSort; - } - else - { - boolean hasCustomSort = false; - try + item.setExpanded(true); + + List children = collection.getMemberResources(); + + Comparator comparator = null; + if(userSelectedSort != null) { - hasCustomSort = collection.getProperties().getBooleanProperty(ResourceProperties.PROP_HAS_CUSTOM_SORT); + comparator = userSelectedSort; } - catch(Exception e) - { - // ignore -- let value be false - } - if(hasCustomSort) - { - comparator = PRIORITY_SORT_COMPARATOR; - } else { - comparator = DEFAULT_COMPARATOR; + boolean hasCustomSort = false; + try + { + hasCustomSort = collection.getProperties().getBooleanProperty(ResourceProperties.PROP_HAS_CUSTOM_SORT); + } + catch(Exception e) + { + // ignore -- let value be false + } + if(hasCustomSort) + { + comparator = PRIORITY_SORT_COMPARATOR; + } + else + { + comparator = DEFAULT_COMPARATOR; + } } + Collections.sort(children, comparator); + + Iterator childIt = children.iterator(); + while(childIt.hasNext()) + { + ContentEntity childEntity = childIt.next(); + if(childEntity.getAccess() == AccessMode.GROUPED) + { + if(childEntity.isCollection()) + { + if(! contentService.allowGetCollection(childEntity.getId())) + { + continue; + } + } + else + { + if(!contentService.allowGetResource(childEntity.getId())) + { + continue; + } + } + } + + if(isAvailabilityEnabled && ! contentService.isAvailable(childEntity.getId())) + { + continue; + } + + ListItem child = getListItem(childEntity, item, registry, expandAll, expandedFoldersSync, items_to_be_moved, items_to_be_copied, depth + 1, userSelectedSort, preventPublicDisplay, addFilter); + if(items_to_be_copied != null && items_to_be_copied.contains(child.id)) + { + child.setSelectedForCopy(true); + } + if(items_to_be_moved != null && items_to_be_moved.contains(child.id)) + { + child.setSelectedForMove(true); + } + item.addMember(child); + } } - Collections.sort(children, comparator); - - Iterator childIt = children.iterator(); - while(childIt.hasNext()) - { - ContentEntity childEntity = childIt.next(); - if(childEntity.getAccess() == AccessMode.GROUPED) - { - if(childEntity.isCollection()) - { - if(! contentService.allowGetCollection(childEntity.getId())) - { - continue; - } - } - else - { - if(!contentService.allowGetResource(childEntity.getId())) - { - continue; - } - } - } - - if(isAvailabilityEnabled && ! contentService.isAvailable(childEntity.getId())) - { - continue; - } - - ListItem child = getListItem(childEntity, item, registry, expandAll, expandedFolders, items_to_be_moved, items_to_be_copied, depth + 1, userSelectedSort, preventPublicDisplay, addFilter); - if(items_to_be_copied != null && items_to_be_copied.contains(child.id)) - { - child.setSelectedForCopy(true); - } - if(items_to_be_moved != null && items_to_be_moved.contains(child.id)) - { - child.setSelectedForMove(true); - } - item.addMember(child); - } - } - - List myAddActions = ResourcesAction.getAddActions(entity, item.getPermissions(), registry); - if(addFilter != null) - { - myAddActions = addFilter.filterAllowedActions(myAddActions); - } - item.setAddActions(myAddActions ); - //this.members = coll.getMembers(); - item.setIconLocation( ContentTypeImageService.getContentTypeImage("folder")); + + List myAddActions = ResourcesAction.getAddActions(entity, item.getPermissions(), registry); + if(addFilter != null) + { + myAddActions = addFilter.filterAllowedActions(myAddActions); + } + item.setAddActions(myAddActions ); + //this.members = coll.getMembers(); + item.setIconLocation( ContentTypeImageService.getContentTypeImage("folder")); + } } List otherActions = ResourcesAction.getActions(entity, item.getPermissions(), registry); List pasteActions = ResourcesAction.getPasteActions(entity, item.getPermissions(), registry, items_to_be_moved, items_to_be_copied);