From 5640cac8e09531437e1769f884d880ee49c19f02 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Sun, 6 Sep 2009 21:34:20 +0100
Subject: Add convenience functions to InventoryArchiveUtils for locating
folders by assuming we're starting from the root Change test methods to use
convenience functions
---
.../Inventory/Archiver/InventoryArchiveUtils.cs | 66 ++++++++++++++++++++++
.../Archiver/Tests/InventoryArchiverTests.cs | 8 +--
2 files changed, 69 insertions(+), 5 deletions(-)
(limited to 'OpenSim/Region/CoreModules/Avatar')
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs
index 6d598d1..2eeb637 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs
@@ -27,6 +27,7 @@
using System;
using System.Collections.Generic;
+using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Services.Interfaces;
@@ -38,6 +39,39 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
public static class InventoryArchiveUtils
{
public static readonly string PATH_DELIMITER = "/";
+
+ ///
+ /// Find a folder given a PATH_DELIMITER delimited path starting from a user's root folder
+ ///
+ ///
+ /// 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.
+ ///
+ ///
+ /// Inventory service to query
+ ///
+ ///
+ /// User id to search
+ ///
+ ///
+ /// The path to the required folder.
+ /// It this is empty or consists only of the PATH_DELIMTER then this folder itself is returned.
+ ///
+ /// null if the folder is not found
+ 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);
+ }
///
/// Find a folder given a PATH_DELIMITER delimited path starting from this folder
@@ -91,6 +125,38 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
// We didn't find a folder with the right name
return null;
}
+
+ ///
+ /// 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.
+ ///
+ ///
+ ///
+ /// Inventory service to query
+ ///
+ ///
+ /// The user to search
+ ///
+ ///
+ /// The path to the required item.
+ ///
+ /// null if the item is not found
+ 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);
+ }
///
/// Find an item given a PATH_DELIMITOR delimited path starting from this folder.
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
index bdc2802..50fd2b0 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
@@ -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),
--
cgit v1.1