[Registry-dev] svn commit r16608 - in
trunk/registry/modules/core/src: main/java/org/wso2/registry/jdbc
main/java/org/wso2/registry/jdbc/dao
main/java/org/wso2/registry/utils test/java/org/wso2/registry/utils
svn at wso2.org
svn at wso2.org
Wed May 7 02:24:32 PDT 2008
Author: chathura
Date: Wed May 7 02:23:57 2008
New Revision: 16608
Log:
Added support for version restore functionality after renaming parent collections.
Added:
trunk/registry/modules/core/src/test/java/org/wso2/registry/utils/
trunk/registry/modules/core/src/test/java/org/wso2/registry/utils/RegistryUtilsTest.java
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/VersionRepository.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/RestoreUtilDAO.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/RegistryUtils.java
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/VersionRepository.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/VersionRepository.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/VersionRepository.java Wed May 7 02:23:57 2008
@@ -142,10 +142,11 @@
String versionedResourcePath = versionedPath.getPath();
long snapshotID = versionedPath.getVersion();
String resourceID = resourceDAO.getResourceID(versionedResourcePath);
- restoreSnapshotNetwork(snapshotID, resourceID);
+ restoreSnapshotNetwork(
+ snapshotID, resourceID, RegistryUtils.getParentPath(versionedResourcePath));
}
- private void restoreSnapshotNetwork(long snapshotID, String resourceID)
+ private void restoreSnapshotNetwork(long snapshotID, String resourceID, String parentPath)
throws RegistryException {
// get the version number of resource for this snapshot
@@ -170,11 +171,15 @@
// call restoreSnapshotNetwork
// end for
+ String resourcePath;
+
ResourceDO resourceVersionDO =
resourceVersionDAO.getResourceVersionDO(resourceID, snapshotID);
ResourceDO resourceDO = resourceDAO.getResourceDO(resourceID);
if (resourceDO != null) {
+ resourcePath = resourceDO.getPath();
+
if (resourceDO.getEquivalentVersion() != resourceVersionDO.getVersion()) {
if (resourceVersionDO.getCollection() == 1) {
@@ -204,19 +209,24 @@
}
}
-
restoreUtilDAO.replaceProperties(resourceID, resourceVersionDO.getVersion());
}
} else {
+ // parents of this resource may have been renamed after deleting this resource. therefore,
+ // we can't restore the resource with its original name. we have append the parent name
+ // and resource's original name to construct the new path of the restored resource.
+ resourcePath = parentPath + RegistryConstants.PATH_SEPARATOR +
+ RegistryUtils.getResourceName(resourceVersionDO.getPath());
+
String contentID = null;
if (resourceVersionDO.getCollection() != 1) {
contentID = restoreUtilDAO.copyContentVersion(resourceVersionDO);
}
- restoreUtilDAO.copyResourceVersion(resourceVersionDO, contentID);
+ restoreUtilDAO.copyResourceVersion(resourceVersionDO, contentID, resourcePath);
restoreUtilDAO.copyProperties(resourceID, resourceVersionDO.getVersion());
}
@@ -237,7 +247,7 @@
Iterator <String> iVersionedChildIDs = versionedChildIDs.iterator();
while (iVersionedChildIDs.hasNext()) {
- restoreSnapshotNetwork(snapshotID, iVersionedChildIDs.next());
+ restoreSnapshotNetwork(snapshotID, iVersionedChildIDs.next(), resourcePath);
}
restoreUtilDAO.replaceDependencies(resourceID, versionedChildIDs);
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/RestoreUtilDAO.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/RestoreUtilDAO.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/RestoreUtilDAO.java Wed May 7 02:23:57 2008
@@ -17,6 +17,7 @@
package org.wso2.registry.jdbc.dao;
import org.wso2.registry.RegistryException;
+import org.wso2.registry.utils.RegistryUtils;
import org.wso2.registry.jdbc.dataobjects.ResourceDO;
import org.wso2.registry.jdbc.dataobjects.PropertyDO;
import org.wso2.registry.jdbc.utils.Transaction;
@@ -188,7 +189,8 @@
}
- public void copyResourceVersion(ResourceDO resourceVersionDO, String contentID)
+ public void copyResourceVersion(
+ ResourceDO resourceVersionDO, String contentID, String resourcePath)
throws RegistryException {
Connection conn = Transaction.getConnection();
@@ -201,7 +203,7 @@
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, resourceVersionDO.getID());
- ps.setString(2, resourceVersionDO.getPath());
+ ps.setString(2, resourcePath);
ps.setString(3, resourceVersionDO.getMediaType());
ps.setInt(4, resourceVersionDO.getCollection());
ps.setString(5, resourceVersionDO.getAuthor());
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/RegistryUtils.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/RegistryUtils.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/RegistryUtils.java Wed May 7 02:23:57 2008
@@ -109,6 +109,32 @@
return parentPath;
}
+ public static String getResourceName(String resourcePath) {
+
+ String resourceName;
+ if (resourcePath.equals(RegistryConstants.ROOT_PATH)) {
+ resourceName = RegistryConstants.ROOT_PATH;
+
+ } else {
+
+ String formattedPath = resourcePath;
+ if (resourcePath.endsWith(RegistryConstants.PATH_SEPARATOR)) {
+ formattedPath = resourcePath.substring(
+ 0, resourcePath.length() - RegistryConstants.PATH_SEPARATOR.length());
+ }
+
+ if (formattedPath.lastIndexOf(RegistryConstants.PATH_SEPARATOR) == 0) {
+ resourceName = formattedPath.substring(1, formattedPath.length());
+ } else {
+ resourceName = formattedPath.substring(
+ formattedPath.lastIndexOf(RegistryConstants.PATH_SEPARATOR) + 1,
+ formattedPath.length());
+ }
+ }
+
+ return resourceName;
+ }
+
/**
* Prepare the given path as a general resource path to be used in the registry. General
* resource paths may refer to pure resources or virtual resources.
Added: trunk/registry/modules/core/src/test/java/org/wso2/registry/utils/RegistryUtilsTest.java
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/test/java/org/wso2/registry/utils/RegistryUtilsTest.java Wed May 7 02:23:57 2008
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wso2.registry.utils;
+
+import junit.framework.TestCase;
+
+public class RegistryUtilsTest extends TestCase {
+
+ public void testGetResourceName() {
+
+ assertEquals("Resource name incorrect.", "/", RegistryUtils.getResourceName("/"));
+
+ assertEquals("Resource name incorrect.", "a", RegistryUtils.getResourceName("/a"));
+
+ assertEquals("Resource name incorrect.", "b", RegistryUtils.getResourceName("/a/b"));
+
+ assertEquals("Resource name incorrect.", "a.txt",
+ RegistryUtils.getResourceName("/a/a.txt"));
+
+ assertEquals("Resource name incorrect.", "a", RegistryUtils.getResourceName("/a/"));
+
+ assertEquals("Resource name incorrect.", "b", RegistryUtils.getResourceName("/a/b/"));
+ }
+}
More information about the Registry-dev
mailing list