From 0d566aa3856f90bf6de13d206b85e1b6150ff70c Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Fri, 6 Apr 2012 21:52:48 -0700 Subject: Better Suitcase Inventory Service. --- .../HypergridService/HGSuitcaseInventoryService.cs | 103 +++++++++++---------- 1 file changed, 55 insertions(+), 48 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs b/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs index b6ec558..6a6181a 100644 --- a/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs +++ b/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs @@ -109,7 +109,7 @@ namespace OpenSim.Services.HypergridService XInventoryFolder suitcase = GetSuitcaseXFolder(principalID); XInventoryFolder root = GetRootXFolder(principalID); - List tree = GetFolderTree(suitcase.folderID); + List tree = GetFolderTree(principalID, suitcase.folderID); if (tree == null || (tree != null && tree.Count == 0)) return null; @@ -119,7 +119,7 @@ namespace OpenSim.Services.HypergridService folders.Add(ConvertToOpenSim(x)); } - SetAsRootFolder(suitcase, root); + SetAsNormalFolder(suitcase, root); folders.Add(ConvertToOpenSim(suitcase)); return folders; @@ -136,10 +136,10 @@ namespace OpenSim.Services.HypergridService XInventoryFolder suitcase = GetSuitcaseXFolder(userID); XInventoryFolder root = GetRootXFolder(userID); - List tree = GetFolderTree(suitcase.folderID); + List tree = GetFolderTree(userID, suitcase.folderID); if (tree == null || (tree != null && tree.Count == 0)) { - SetAsRootFolder(suitcase, root); + SetAsNormalFolder(suitcase, root); userInventory.Folders.Add(ConvertToOpenSim(suitcase)); return userInventory; } @@ -164,7 +164,7 @@ namespace OpenSim.Services.HypergridService userInventory.Items.AddRange(items); } - SetAsRootFolder(suitcase, root); + SetAsNormalFolder(suitcase, root); userInventory.Folders.Add(ConvertToOpenSim(suitcase)); m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetUserInventory for user {0} returning {1} folders and {2} items", @@ -175,8 +175,6 @@ namespace OpenSim.Services.HypergridService public override InventoryFolderBase GetRootFolder(UUID principalID) { m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetRootFolder for {0}", principalID); - if (m_Database == null) - m_log.ErrorFormat("[XXX]: m_Database is NULL!"); // Let's find out the local root folder XInventoryFolder root = GetRootXFolder(principalID); ; @@ -202,7 +200,7 @@ namespace OpenSim.Services.HypergridService CreateSystemFolders(principalID, suitcase.folderID); } - SetAsRootFolder(suitcase, root); + SetAsNormalFolder(suitcase, root); return ConvertToOpenSim(suitcase); } @@ -271,9 +269,8 @@ namespace OpenSim.Services.HypergridService public override InventoryCollection GetFolderContent(UUID principalID, UUID folderID) { InventoryCollection coll = null; - XInventoryFolder suitcase = GetSuitcaseXFolder(principalID); - if (!IsWithinSuitcaseTree(folderID, suitcase)) + if (!IsWithinSuitcaseTree(principalID, folderID)) return new InventoryCollection(); coll = base.GetFolderContent(principalID, folderID); @@ -290,9 +287,7 @@ namespace OpenSim.Services.HypergridService { // Let's do a bit of sanity checking, more than the base service does // make sure the given folder exists under the suitcase tree of this user - XInventoryFolder suitcase = GetSuitcaseXFolder(principalID); - - if (!IsWithinSuitcaseTree(folderID, suitcase)) + if (!IsWithinSuitcaseTree(principalID, folderID)) return new List(); return base.GetFolderItems(principalID, folderID); @@ -303,21 +298,27 @@ namespace OpenSim.Services.HypergridService m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: AddFolder {0} {1}", folder.Name, folder.ParentID); // Let's do a bit of sanity checking, more than the base service does // make sure the given folder's parent folder exists under the suitcase tree of this user - XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner); - if (!IsWithinSuitcaseTree(folder.ParentID, suitcase)) + if (!IsWithinSuitcaseTree(folder.Owner, folder.ParentID)) return false; // OK, it's legit - return base.AddFolder(folder); + if (base.AddFolder(folder)) + { + List tree; + if (m_SuitcaseTrees.TryGetValue(folder.Owner, out tree)) + tree.Add(ConvertFromOpenSim(folder)); + + return true; + } + + return false; } public override bool UpdateFolder(InventoryFolderBase folder) { - XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner); - m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Update folder {0}, version {1}", folder.ID, folder.Version); - if (!IsWithinSuitcaseTree(folder.ID, suitcase)) + if (!IsWithinSuitcaseTree(folder.Owner, folder.ID)) { m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: folder {0} not within Suitcase tree", folder.Name); return false; @@ -329,9 +330,8 @@ namespace OpenSim.Services.HypergridService public override bool MoveFolder(InventoryFolderBase folder) { - XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner); - - if (!IsWithinSuitcaseTree(folder.ID, suitcase) || !IsWithinSuitcaseTree(folder.ParentID, suitcase)) + if (!IsWithinSuitcaseTree(folder.Owner, folder.ID) || + !IsWithinSuitcaseTree(folder.Owner, folder.ParentID)) return false; return base.MoveFolder(folder); @@ -353,9 +353,7 @@ namespace OpenSim.Services.HypergridService { // Let's do a bit of sanity checking, more than the base service does // make sure the given folder's parent folder exists under the suitcase tree of this user - XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner); - - if (!IsWithinSuitcaseTree(item.Folder, suitcase)) + if (!IsWithinSuitcaseTree(item.Owner, item.Folder)) return false; // OK, it's legit @@ -365,9 +363,7 @@ namespace OpenSim.Services.HypergridService public override bool UpdateItem(InventoryItemBase item) { - XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner); - - if (!IsWithinSuitcaseTree(item.Folder, suitcase)) + if (!IsWithinSuitcaseTree(item.Owner, item.Folder)) return false; return base.UpdateItem(item); @@ -377,9 +373,7 @@ namespace OpenSim.Services.HypergridService { // Principal is b0rked. *sigh* - XInventoryFolder suitcase = GetSuitcaseXFolder(items[0].Owner); - - if (!IsWithinSuitcaseTree(items[0].Folder, suitcase)) + if (!IsWithinSuitcaseTree(items[0].Owner, items[0].Folder)) return false; return base.MoveItems(principalID, items); @@ -400,15 +394,8 @@ namespace OpenSim.Services.HypergridService item.Name, item.ID, item.Folder); return null; } - XInventoryFolder suitcase = GetSuitcaseXFolder(it.Owner); - if (suitcase == null) - { - m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Root or Suitcase are null for user {0}", - it.Owner); - return null; - } - if (!IsWithinSuitcaseTree(it.Folder, suitcase)) + if (!IsWithinSuitcaseTree(it.Owner, it.Folder)) { m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Item {0} (folder {1}) is not within Suitcase", it.Name, it.Folder); @@ -431,9 +418,7 @@ namespace OpenSim.Services.HypergridService if (f != null) { - XInventoryFolder suitcase = GetSuitcaseXFolder(f.Owner); - - if (!IsWithinSuitcaseTree(f.ID, suitcase)) + if (!IsWithinSuitcaseTree(f.Owner, f.ID)) return null; } @@ -481,22 +466,37 @@ namespace OpenSim.Services.HypergridService if (folders != null && folders.Length > 0) return folders[0]; + + // check to see if we have the old Suitcase folder + folders = m_Database.GetFolders( + new string[] { "agentID", "folderName", "parentFolderID" }, + new string[] { principalID.ToString(), "My Suitcase", UUID.Zero.ToString() }); + if (folders != null && folders.Length > 0) + { + // Move it to under the root folder + XInventoryFolder root = GetRootXFolder(principalID); + folders[0].parentFolderID = root.folderID; + folders[0].type = 100; + m_Database.StoreFolder(folders[0]); + return folders[0]; + } + return null; } - private void SetAsRootFolder(XInventoryFolder suitcase, XInventoryFolder root) + private void SetAsNormalFolder(XInventoryFolder suitcase, XInventoryFolder root) { suitcase.type = (short)AssetType.Folder; } - private List GetFolderTree(UUID folder) + private List GetFolderTree(UUID principalID, UUID folder) { List t = null; - if (m_SuitcaseTrees.TryGetValue(folder, out t)) + if (m_SuitcaseTrees.TryGetValue(principalID, out t)) return t; t = GetFolderTreeRecursive(folder); - m_SuitcaseTrees.AddOrUpdate(folder, t, 120); + m_SuitcaseTrees.AddOrUpdate(principalID, t, 5*60); // 5minutes return t; } @@ -528,11 +528,18 @@ namespace OpenSim.Services.HypergridService /// /// /// - private bool IsWithinSuitcaseTree(UUID folderID, XInventoryFolder suitcase) + private bool IsWithinSuitcaseTree(UUID principalID, UUID folderID) { + XInventoryFolder suitcase = GetSuitcaseXFolder(principalID); + if (suitcase == null) + { + m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder", principalID); + return false; + } + List tree = new List(); tree.Add(suitcase); // Warp! the tree is the real root folder plus the children of the suitcase folder - tree.AddRange(GetFolderTree(suitcase.folderID)); + tree.AddRange(GetFolderTree(principalID, suitcase.folderID)); XInventoryFolder f = tree.Find(delegate(XInventoryFolder fl) { if (fl.folderID == folderID) return true; -- cgit v1.1 From d4a370a5f2b010727b1a2fdcc6526b7b13c72962 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 7 Apr 2012 14:52:15 -0700 Subject: A few more minor improvements on Suitcase inventory service. --- .../Services/HypergridService/HGSuitcaseInventoryService.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs b/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs index 6a6181a..53fbea6 100644 --- a/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs +++ b/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs @@ -107,7 +107,6 @@ namespace OpenSim.Services.HypergridService public override List GetInventorySkeleton(UUID principalID) { XInventoryFolder suitcase = GetSuitcaseXFolder(principalID); - XInventoryFolder root = GetRootXFolder(principalID); List tree = GetFolderTree(principalID, suitcase.folderID); if (tree == null || (tree != null && tree.Count == 0)) @@ -119,7 +118,7 @@ namespace OpenSim.Services.HypergridService folders.Add(ConvertToOpenSim(x)); } - SetAsNormalFolder(suitcase, root); + SetAsNormalFolder(suitcase); folders.Add(ConvertToOpenSim(suitcase)); return folders; @@ -134,12 +133,11 @@ namespace OpenSim.Services.HypergridService userInventory.Items = new List(); XInventoryFolder suitcase = GetSuitcaseXFolder(userID); - XInventoryFolder root = GetRootXFolder(userID); List tree = GetFolderTree(userID, suitcase.folderID); if (tree == null || (tree != null && tree.Count == 0)) { - SetAsNormalFolder(suitcase, root); + SetAsNormalFolder(suitcase); userInventory.Folders.Add(ConvertToOpenSim(suitcase)); return userInventory; } @@ -164,7 +162,7 @@ namespace OpenSim.Services.HypergridService userInventory.Items.AddRange(items); } - SetAsNormalFolder(suitcase, root); + SetAsNormalFolder(suitcase); userInventory.Folders.Add(ConvertToOpenSim(suitcase)); m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetUserInventory for user {0} returning {1} folders and {2} items", @@ -181,6 +179,7 @@ namespace OpenSim.Services.HypergridService if (root == null) { m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve local root folder for user {0}", principalID); + return null; } // Warp! Root folder for travelers is the suitcase folder @@ -200,7 +199,7 @@ namespace OpenSim.Services.HypergridService CreateSystemFolders(principalID, suitcase.folderID); } - SetAsNormalFolder(suitcase, root); + SetAsNormalFolder(suitcase); return ConvertToOpenSim(suitcase); } @@ -484,7 +483,7 @@ namespace OpenSim.Services.HypergridService return null; } - private void SetAsNormalFolder(XInventoryFolder suitcase, XInventoryFolder root) + private void SetAsNormalFolder(XInventoryFolder suitcase) { suitcase.type = (short)AssetType.Folder; } -- cgit v1.1