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.Collections.Generic;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Services.Interfaces;
@ -39,6 +40,39 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
{
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>
/// Find a folder given a PATH_DELIMITER delimited path starting from this folder
/// </summary>
@ -92,6 +126,38 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
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>
/// 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.ID = item1Id;
InventoryFolderBase objsFolder
= InventoryArchiveUtils.FindFolderByPath(
scene.InventoryService, scene.InventoryService.GetRootFolder(userId), "Objects");
= InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects");
item1.Folder = objsFolder.ID;
scene.AddInventoryItem(userId, item1);
@ -267,10 +266,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
CachedUserInfo userInfo
= scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName);
//InventoryItemBase foundItem = userInfo.RootFolder.FindItemByPath(itemName);
InventoryItemBase foundItem
= InventoryArchiveUtils.FindItemByPath(
scene.InventoryService, scene.InventoryService.GetRootFolder(userInfo.UserProfile.ID), itemName);
= InventoryArchiveUtils.FindItemByPath( scene.InventoryService, userInfo.UserProfile.ID, itemName);
Assert.That(foundItem, Is.Not.Null, "Didn't find loaded item");
Assert.That(
foundItem.CreatorId, Is.EqualTo(item1.CreatorId),