Author: chathura
Date: Thu Jan 24 22:50:50 2008
New Revision: 12865
Log:
Fixed the resource versioning issue (raised by Mashup team) by Deepal and me.
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/VersionedResourceDAO.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/CommentTest.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/VersionedResourceDAO.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/VersionedResourceDAO.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/VersionedResourceDAO.java
Thu Jan 24 22:50:50 2008
@@ -308,7 +308,7 @@
String parentPath = RegistryConstants.ROOT_PATH;
long parentVersion = getLatestVersionNumber(
getResourceID(RegistryConstants.ROOT_PATH, conn),
conn);
- long childId = 0;
+ long childId = 1;
for (int i = 2; i < parts.length; i++) {
if (!resourceActive(parentPath, conn)) {
throw new RegistryException("Resource is not
active");
@@ -319,6 +319,10 @@
parentPath = currentPath;
currentPath = currentPath +
RegistryConstants.PATH_SEPARATOR + parts[i];
}
+ if (parts.length == 2) {
+ childId = getResourceID(parentPath ,conn);
+
+ }
long id = getResourceID(currentPath, conn);
return getChildVersion(conn, childId, parentVersion, id);
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java
Thu Jan 24 22:50:50 2008
@@ -121,6 +121,10 @@
Resource a = resourceDAO.getLatestVersion(path, conn);
if (a != null) {
+ // if the parent collections of this resource are in deleted
state, make them
+ // activated
+ activateParentCollections(path, conn);
+
// given resource already exist. update it.
resource.setId(a.getId());
@@ -128,7 +132,7 @@
if (resource.getAuthorUserName() == null) {
resource.setAuthorUserName(a.getAuthorUserName());
}
-
+ resource.setPath(path);
resource.setState(RegistryConstants.ACTIVE_STATE);
resource.setLastUpdaterUserName(userID);
resourceDAO.update(path, resource, conn);
@@ -220,12 +224,13 @@
if (currentCollection.getState() ==
RegistryConstants.DELETED_STATE) {
- currentCollection = new Resource();
- currentCollection.setPath(currentPath);
- currentCollection.setDirectory(true);
- currentCollection.setAuthorUserName(userID);
- currentCollection.setLastUpdaterUserName(userID);
- put(currentPath, currentCollection);
+ //currentCollection = new Resource();
+ //currentCollection.setPath(currentPath);
+ //currentCollection.setDirectory(true);
+ //currentCollection.setAuthorUserName(userID);
+ //currentCollection.setLastUpdaterUserName(userID);
+ resourceDAO.markActivated(currentCollection.getId(), conn);
+ //put(currentPath, currentCollection);
} else if (!currentCollection.isDirectory()) {
@@ -239,6 +244,39 @@
}
}
+ private void activateParentCollections(String path,
+ Connection conn) throws
SQLException, RegistryException {
+
+ String[] parts = path.split(RegistryConstants.PATH_SEPARATOR);
+
+ String currentPath = RegistryConstants.ROOT_PATH + parts[1];
+ for (int i = 2; i < parts.length; i++) {
+
+ Resource currentCollection =
resourceDAO.getLatestVersion(currentPath, conn);
+ if (currentCollection == null) {
+
+ String msg = "Parent collection: " + currentPath + " of the
exsiting resource:" + path + " cannot be null";
+ log.error(msg);
+ throw new RegistryException(msg);
+
+ } else {
+
+ if (currentCollection.getState() ==
RegistryConstants.DELETED_STATE) {
+
+ resourceDAO.markActivated(currentCollection.getId(),
conn);
+
+ } else if (!currentCollection.isDirectory()) {
+
+ String msg = "Parent : " + currentPath + " of the exsiting
resource:" + path + " should be a collection resource.";
+ log.error(msg);
+ throw new RegistryException(msg);
+ }
+ }
+
+ currentPath = currentPath + RegistryConstants.PATH_SEPARATOR +
parts[i];
+ }
+ }
+
public boolean importResource(String path, String sourceURL, Resource
metadata)
throws RegistryException {
Modified:
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/CommentTest.java
==============================================================================
---
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/CommentTest.java
(original)
+++
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/CommentTest.java
Thu Jan 24 22:50:50 2008
@@ -225,18 +225,6 @@
public void testAddCommenttoRoot() {
- try {
- Resource r1 = new Resource();
- r1.setAuthorUserName("Author q1");
- r1.setDescription("this is a collection to add comment");
- r1.setDirectory(true);
-
- registry.put("/", r1);
-
- } catch (RegistryException e) {
- fail("Failed to put collection.");
- }
-
String comment1 = "this is qa comment 1 for root";
String comment2 = "this is qa comment 2 for root";
Modified:
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
==============================================================================
---
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
(original)
+++
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
Thu Jan 24 22:50:50 2008
@@ -21,7 +21,9 @@
import junit.framework.TestCase;
import org.wso2.registry.*;
+import org.wso2.registry.jdbc.utils.RegistryDataSource;
+import javax.sql.DataSource;
import java.util.*;
public class JDBCRegistryTest extends TestCase {
@@ -35,8 +37,13 @@
public void setUp() {
try {
if (registry == null) {
- //Realm registryRealm =
+
+ //DataSource dataSource = new
RegistryDataSource("jdbc:derby:/home/chathura/test/regdb1",
+ // "org.apache.derby.jdbc.EmbeddedDriver",
+ // "cce", "cce");
+ //Realm registryRealm =
// RegistryRealmFactory.createInMemoryRegistryRealm();
+ //registry = new JDBCRegistry(dataSource);
registry = new InMemoryJDBCRegistry();
}
} catch (RegistryException e) {
Modified:
trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp
(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp
Thu Jan 24 22:50:50 2008
@@ -1,3 +1,4 @@
+
<%@ page import="org.wso2.registry.web.actions.ResourceDetailsAction" %>
<%@ page import="org.wso2.registry.web.actions.CollectionViewAction" %>
<%@ page import="java.util.Iterator" %>
_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev