From 56f79282b6623cd1385c5e7982ba2219ab7d2f57 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 28 Sep 2009 22:29:06 +0000 Subject: [PATCH] fixing RPs deletion git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Collector@15599 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../AggregatorPersistentResource.java | 7 ++--- .../xmlstorage/exist/XMLStorageManager.java | 31 ++++++++++--------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/org/gcube/informationsystem/collector/impl/persistence/AggregatorPersistentResource.java b/src/org/gcube/informationsystem/collector/impl/persistence/AggregatorPersistentResource.java index a248876..37ae9c3 100755 --- a/src/org/gcube/informationsystem/collector/impl/persistence/AggregatorPersistentResource.java +++ b/src/org/gcube/informationsystem/collector/impl/persistence/AggregatorPersistentResource.java @@ -127,7 +127,7 @@ public class AggregatorPersistentResource extends PersistentResource { } } else { //it's a RP doc //we need to replace the schema and colons in order to make it an ID accepted by eXist - this.resourceID = this.source.replace("http://", "").replace(":", "") + "-" + this.sourceKey;//this.getGroupKey() + this.getEntryKey(); + this.resourceID = this.source.replace("http://", "").replace(":", "").replace("/", "-") + "-" + this.sourceKey.replace("http://", "").replace(":", "").replace("/", "-"); } } /** @@ -180,10 +180,7 @@ public class AggregatorPersistentResource extends PersistentResource { * * @return the ID */ - public String getID() { - // create a unique ID unless the resource contains a profile - //if (this.resourceID == null) - // this.resourceID = this.source + this.sourceKey;//this.getGroupKey() + this.getEntryKey(); + public String getID() { return this.resourceID; } diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorageManager.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorageManager.java index f5d1b0e..2d6e8a2 100755 --- a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorageManager.java +++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorageManager.java @@ -445,7 +445,7 @@ public class XMLStorageManager { logger.warn("Invalid resource ID"); return; } - + this.lock(); Collection propCollection = this.loadPropertiesCollection(); if (propCollection == null) { @@ -454,13 +454,14 @@ public class XMLStorageManager { } try { logger.info("Trying to remove resource " + resourceID + " from collection " + propCollection.getName()); - deleteResource(resourceID, propCollection); + deleteResource(resourceID, propCollection, false); } catch (XMLDBException edb) { logger.error("Failed to remove the resource from the storage! "); logger.error("", edb); throw new Exception(); } finally { this.resetCollection(propCollection); + this.unlock(); } } @@ -474,21 +475,22 @@ public class XMLStorageManager { logger.warn("Invalid profile ID"); return; } + this.lock(); Collection profileCollection = this.loadProfileCollection(profileType); - if (profileCollection == null) { - logger.error("Uunable to load collection Profile!"); + logger.error("Unable to load collection Profile!"); + this.unlock(); throw new Exception("unable to load collection Profile"); } try { logger.info("Trying to remove profile '" + profileID + "' from collection " + profileCollection.getName()); - deleteResource(profileID, profileCollection); - } catch (XMLDBException edb) { + deleteResource(profileID, profileCollection, false); + } catch (Exception edb) { logger.error("Failed to remove the profile from the storage! "); - logger.error("", edb); - throw new Exception(); - } finally { + throw new Exception(edb); + } finally { this.resetCollection(profileCollection); + this.unlock(); } } @@ -502,11 +504,12 @@ public class XMLStorageManager { * - the collection from which the resource has to be removed * @throws Exception */ - private void deleteResource(String resourceID, Collection col) throws Exception { + private void deleteResource(String resourceID, Collection col, boolean ... lock) throws Exception { XMLResource res = null; // lock the instance - this.lock(); + if (lock != null && lock.length > 0 && lock[0]) + this.lock(); try { res = (XMLResource) col.getResource(resourceID); if (res == null) @@ -517,11 +520,11 @@ public class XMLStorageManager { } } catch (XMLDBException edb) { logger.error("Failed to retrieve resource " + resourceID); - logger.error("", edb); - throw new Exception(); + throw new Exception(edb); } finally { this.resetCollection(col); - this.unlock(); + if (lock != null && lock.length > 0 && lock[0]) + this.unlock(); } }