Add convenience functions to InventoryArchiveUtils for locating folders by assuming we're starting from the root

Change test methods to use convenience functions
remotes/origin/0.6.7-post-fixes
Justin Clark-Casey (justincc) 2009-09-06 21:34:20 +01:00
parent a92afe8dca
commit 5640cac8e0
2 changed files with 69 additions and 5 deletions

View File

@ -27,6 +27,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using OpenMetaverse;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Services.Interfaces; using OpenSim.Services.Interfaces;
@ -39,6 +40,39 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
{ {
public static readonly string PATH_DELIMITER = "/"; public static readonly string PATH_DELIMITER = "/";
/// <summary>
/// Find a folder given a PATH_DELIMITER delimited path starting from a user's root folder
/// </summary>
///
/// This method does not handle paths that contain multiple delimitors
///
/// FIXME: We do not yet handle situations where folders have the same name. We could handle this by some
/// XPath like expression
///
/// FIXME: Delimitors which occur in names themselves are not currently escapable.
///
/// <param name="inventoryService">
/// Inventory service to query
/// </param>
/// <param name="userId">
/// User id to search
/// </param>
/// <param name="path">
/// The path to the required folder.
/// It this is empty or consists only of the PATH_DELIMTER then this folder itself is returned.
/// </param>
/// <returns>null if the folder is not found</returns>
public static InventoryFolderBase FindFolderByPath(
IInventoryService inventoryService, UUID userId, string path)
{
InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId);
if (null == rootFolder)
return null;
return FindFolderByPath(inventoryService, rootFolder, path);
}
/// <summary> /// <summary>
/// Find a folder given a PATH_DELIMITER delimited path starting from this folder /// Find a folder given a PATH_DELIMITER delimited path starting from this folder
/// </summary> /// </summary>
@ -92,6 +126,38 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
return null; return null;
} }
/// <summary>
/// Find an item given a PATH_DELIMITOR delimited path starting from the user's root folder.
///
/// This method does not handle paths that contain multiple delimitors
///
/// FIXME: We do not yet handle situations where folders or items have the same name. We could handle this by some
/// XPath like expression
///
/// FIXME: Delimitors which occur in names themselves are not currently escapable.
/// </summary>
///
/// <param name="inventoryService">
/// Inventory service to query
/// </param>
/// <param name="userId">
/// The user to search
/// </param>
/// <param name="path">
/// The path to the required item.
/// </param>
/// <returns>null if the item is not found</returns>
public static InventoryItemBase FindItemByPath(
IInventoryService inventoryService, UUID userId, string path)
{
InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId);
if (null == rootFolder)
return null;
return FindItemByPath(inventoryService, rootFolder, path);
}
/// <summary> /// <summary>
/// Find an item given a PATH_DELIMITOR delimited path starting from this folder. /// Find an item given a PATH_DELIMITOR delimited path starting from this folder.
/// ///

View File

@ -136,8 +136,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
item1.AssetID = asset1.FullID; item1.AssetID = asset1.FullID;
item1.ID = item1Id; item1.ID = item1Id;
InventoryFolderBase objsFolder InventoryFolderBase objsFolder
= InventoryArchiveUtils.FindFolderByPath( = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects");
scene.InventoryService, scene.InventoryService.GetRootFolder(userId), "Objects");
item1.Folder = objsFolder.ID; item1.Folder = objsFolder.ID;
scene.AddInventoryItem(userId, item1); scene.AddInventoryItem(userId, item1);
@ -267,10 +266,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
CachedUserInfo userInfo CachedUserInfo userInfo
= scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName); = scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName);
//InventoryItemBase foundItem = userInfo.RootFolder.FindItemByPath(itemName);
InventoryItemBase foundItem InventoryItemBase foundItem
= InventoryArchiveUtils.FindItemByPath( = InventoryArchiveUtils.FindItemByPath( scene.InventoryService, userInfo.UserProfile.ID, itemName);
scene.InventoryService, scene.InventoryService.GetRootFolder(userInfo.UserProfile.ID), itemName);
Assert.That(foundItem, Is.Not.Null, "Didn't find loaded item"); Assert.That(foundItem, Is.Not.Null, "Didn't find loaded item");
Assert.That( Assert.That(
foundItem.CreatorId, Is.EqualTo(item1.CreatorId), foundItem.CreatorId, Is.EqualTo(item1.CreatorId),