aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs')
-rw-r--r--OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs142
1 files changed, 122 insertions, 20 deletions
diff --git a/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs b/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs
index 87d9410..5a36332 100644
--- a/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs
+++ b/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs
@@ -45,6 +45,9 @@ namespace OpenSim.Tests.Common
45 /// <summary> 45 /// <summary>
46 /// Add an existing scene object as an item in the user's inventory. 46 /// Add an existing scene object as an item in the user's inventory.
47 /// </summary> 47 /// </summary>
48 /// <remarks>
49 /// Will be added to the system Objects folder.
50 /// </remarks>
48 /// <param name='scene'></param> 51 /// <param name='scene'></param>
49 /// <param name='so'></param> 52 /// <param name='so'></param>
50 /// <param name='inventoryIdTail'></param> 53 /// <param name='inventoryIdTail'></param>
@@ -63,7 +66,29 @@ namespace OpenSim.Tests.Common
63 } 66 }
64 67
65 /// <summary> 68 /// <summary>
66 /// Creates a notecard in the objects folder and specify an item id. 69 /// Add an existing scene object as an item in the user's inventory at the given path.
70 /// </summary>
71 /// <param name='scene'></param>
72 /// <param name='so'></param>
73 /// <param name='inventoryIdTail'></param>
74 /// <param name='assetIdTail'></param>
75 /// <returns>The inventory item created.</returns>
76 public static InventoryItemBase AddInventoryItem(
77 Scene scene, SceneObjectGroup so, int inventoryIdTail, int assetIdTail, string path)
78 {
79 return AddInventoryItem(
80 scene,
81 so.Name,
82 TestHelpers.ParseTail(inventoryIdTail),
83 InventoryType.Object,
84 AssetHelpers.CreateAsset(TestHelpers.ParseTail(assetIdTail), so),
85 so.OwnerID,
86 path);
87 }
88
89 /// <summary>
90 /// Adds the given item to the existing system folder for its type (e.g. an object will go in the "Objects"
91 /// folder).
67 /// </summary> 92 /// </summary>
68 /// <param name="scene"></param> 93 /// <param name="scene"></param>
69 /// <param name="itemName"></param> 94 /// <param name="itemName"></param>
@@ -75,6 +100,25 @@ namespace OpenSim.Tests.Common
75 private static InventoryItemBase AddInventoryItem( 100 private static InventoryItemBase AddInventoryItem(
76 Scene scene, string itemName, UUID itemId, InventoryType itemType, AssetBase asset, UUID userId) 101 Scene scene, string itemName, UUID itemId, InventoryType itemType, AssetBase asset, UUID userId)
77 { 102 {
103 return AddInventoryItem(
104 scene, itemName, itemId, itemType, asset, userId,
105 scene.InventoryService.GetFolderForType(userId, (FolderType)asset.Type).Name);
106 }
107
108 /// <summary>
109 /// Adds the given item to an inventory folder
110 /// </summary>
111 /// <param name="scene"></param>
112 /// <param name="itemName"></param>
113 /// <param name="itemId"></param>
114 /// <param name="itemType"></param>
115 /// <param name="asset">The serialized asset for this item</param>
116 /// <param name="userId"></param>
117 /// <param name="path">Existing inventory path at which to add.</param>
118 /// <returns></returns>
119 private static InventoryItemBase AddInventoryItem(
120 Scene scene, string itemName, UUID itemId, InventoryType itemType, AssetBase asset, UUID userId, string path)
121 {
78 scene.AssetService.Store(asset); 122 scene.AssetService.Store(asset);
79 123
80 InventoryItemBase item = new InventoryItemBase(); 124 InventoryItemBase item = new InventoryItemBase();
@@ -85,7 +129,7 @@ namespace OpenSim.Tests.Common
85 item.AssetType = asset.Type; 129 item.AssetType = asset.Type;
86 item.InvType = (int)itemType; 130 item.InvType = (int)itemType;
87 131
88 InventoryFolderBase folder = scene.InventoryService.GetFolderForType(userId, (AssetType)asset.Type); 132 InventoryFolderBase folder = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, userId, path)[0];
89 133
90 item.Folder = folder.ID; 134 item.Folder = folder.ID;
91 scene.AddInventoryItem(item); 135 scene.AddInventoryItem(item);
@@ -156,58 +200,116 @@ namespace OpenSim.Tests.Common
156 /// <summary> 200 /// <summary>
157 /// Create inventory folders starting from the user's root folder. 201 /// Create inventory folders starting from the user's root folder.
158 /// </summary> 202 /// </summary>
159 ///
160 /// Ignores any existing folders with the same name
161 ///
162 /// <param name="inventoryService"></param> 203 /// <param name="inventoryService"></param>
163 /// <param name="userId"></param> 204 /// <param name="userId"></param>
164 /// <param name="path"> 205 /// <param name="path">
165 /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER 206 /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER
166 /// </param> 207 /// </param>
208 /// <param name="useExistingFolders">
209 /// If true, then folders in the path which already the same name are
210 /// used. This applies to the terminal folder as well.
211 /// If false, then all folders in the path are created, even if there is already a folder at a particular
212 /// level with the same name.
213 /// </param>
167 /// <returns> 214 /// <returns>
168 /// The folder created. If the path contains multiple folders then the last one created is returned. 215 /// The folder created. If the path contains multiple folders then the last one created is returned.
169 /// Will return null if the root folder could not be found. 216 /// Will return null if the root folder could not be found.
170 /// </returns> 217 /// </returns>
171 public static InventoryFolderBase CreateInventoryFolder( 218 public static InventoryFolderBase CreateInventoryFolder(
172 IInventoryService inventoryService, UUID userId, string path) 219 IInventoryService inventoryService, UUID userId, string path, bool useExistingFolders)
220 {
221 return CreateInventoryFolder(inventoryService, userId, UUID.Random(), path, useExistingFolders);
222 }
223
224 /// <summary>
225 /// Create inventory folders starting from the user's root folder.
226 /// </summary>
227 /// <param name="inventoryService"></param>
228 /// <param name="userId"></param>
229 /// <param name="folderId"></param>
230 /// <param name="path">
231 /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER
232 /// </param>
233 /// <param name="useExistingFolders">
234 /// If true, then folders in the path which already the same name are
235 /// used. This applies to the terminal folder as well.
236 /// If false, then all folders in the path are created, even if there is already a folder at a particular
237 /// level with the same name.
238 /// </param>
239 /// <returns>
240 /// The folder created. If the path contains multiple folders then the last one created is returned.
241 /// Will return null if the root folder could not be found.
242 /// </returns>
243 public static InventoryFolderBase CreateInventoryFolder(
244 IInventoryService inventoryService, UUID userId, UUID folderId, string path, bool useExistingFolders)
173 { 245 {
174 InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId); 246 InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId);
175 247
176 if (null == rootFolder) 248 if (null == rootFolder)
177 return null; 249 return null;
178 250
179 return CreateInventoryFolder(inventoryService, rootFolder, path); 251 return CreateInventoryFolder(inventoryService, folderId, rootFolder, path, useExistingFolders);
180 } 252 }
181 253
182 /// <summary> 254 /// <summary>
183 /// Create inventory folders starting from a given parent folder 255 /// Create inventory folders starting from a given parent folder
184 /// </summary> 256 /// </summary>
185 /// 257 /// <remarks>
186 /// Ignores any existing folders with the same name 258 /// If any stem of the path names folders that already exist then these are not recreated. This includes the
187 /// 259 /// final folder.
260 /// TODO: May need to make it an option to create duplicate folders.
261 /// </remarks>
188 /// <param name="inventoryService"></param> 262 /// <param name="inventoryService"></param>
263 /// <param name="folderId">ID of the folder to create</param>
189 /// <param name="parentFolder"></param> 264 /// <param name="parentFolder"></param>
190 /// <param name="path"> 265 /// <param name="path">
191 /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER 266 /// The folder to create.
267 /// </param>
268 /// <param name="useExistingFolders">
269 /// If true, then folders in the path which already the same name are
270 /// used. This applies to the terminal folder as well.
271 /// If false, then all folders in the path are created, even if there is already a folder at a particular
272 /// level with the same name.
192 /// </param> 273 /// </param>
193 /// <returns> 274 /// <returns>
194 /// The folder created. If the path contains multiple folders then the last one created is returned. 275 /// The folder created. If the path contains multiple folders then the last one created is returned.
195 /// </returns> 276 /// </returns>
196 public static InventoryFolderBase CreateInventoryFolder( 277 public static InventoryFolderBase CreateInventoryFolder(
197 IInventoryService inventoryService, InventoryFolderBase parentFolder, string path) 278 IInventoryService inventoryService, UUID folderId, InventoryFolderBase parentFolder, string path, bool useExistingFolders)
198 { 279 {
199 string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); 280 string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None);
200 281
201 InventoryFolderBase newFolder 282 InventoryFolderBase folder = null;
202 = new InventoryFolderBase( 283
203 UUID.Random(), components[0], parentFolder.Owner, (short)AssetType.Unknown, parentFolder.ID, 0); 284 if (useExistingFolders)
204 285 folder = InventoryArchiveUtils.FindFolderByPath(inventoryService, parentFolder, components[0]);
205 inventoryService.AddFolder(newFolder); 286
287 if (folder == null)
288 {
289// Console.WriteLine("Creating folder {0} at {1}", components[0], parentFolder.Name);
290
291 UUID folderIdForCreate;
292
293 if (components.Length > 1)
294 folderIdForCreate = UUID.Random();
295 else
296 folderIdForCreate = folderId;
297
298 folder
299 = new InventoryFolderBase(
300 folderIdForCreate, components[0], parentFolder.Owner, (short)AssetType.Unknown, parentFolder.ID, 0);
301
302 inventoryService.AddFolder(folder);
303 }
304// else
305// {
306// Console.WriteLine("Found existing folder {0}", folder.Name);
307// }
206 308
207 if (components.Length > 1) 309 if (components.Length > 1)
208 return CreateInventoryFolder(inventoryService, newFolder, components[1]); 310 return CreateInventoryFolder(inventoryService, folderId, folder, components[1], useExistingFolders);
209 else 311 else
210 return newFolder; 312 return folder;
211 } 313 }
212 314
213 /// <summary> 315 /// <summary>
@@ -237,7 +339,7 @@ namespace OpenSim.Tests.Common
237 /// <returns>An empty list if no matching folders were found</returns> 339 /// <returns>An empty list if no matching folders were found</returns>
238 public static List<InventoryFolderBase> GetInventoryFolders(IInventoryService inventoryService, UUID userId, string path) 340 public static List<InventoryFolderBase> GetInventoryFolders(IInventoryService inventoryService, UUID userId, string path)
239 { 341 {
240 return InventoryArchiveUtils.FindFolderByPath(inventoryService, userId, path); 342 return InventoryArchiveUtils.FindFoldersByPath(inventoryService, userId, path);
241 } 343 }
242 344
243 /// <summary> 345 /// <summary>