[Registry-dev] svn commit r14617 - in trunk/registry/modules:
core/src/main/java/org/wso2/registry
core/src/main/java/org/wso2/registry/jdbc
core/src/main/java/org/wso2/registry/jdbc/dao
core/src/main/java/org/wso2/registry/jdbc/hsql
core/src/main/java/org/wso2/registry/jdbc/queries
core/src/test/java/org/wso2/registry/jdbc
webapps/src/main/webapp/admin webapps/src/main/webapp/admin/ajax
svn at wso2.org
svn at wso2.org
Sun Mar 9 10:42:18 PDT 2008
Author: chathura
Date: Sun Mar 9 10:41:53 2008
New Revision: 14617
Log:
Implemented multivalued properties support.
Now a property can have a list of string values.
UI still only supports single valued properties. Have to improve the UI to allow multivalued properties.
APP interface has to be updated to support this feature. APP related test cases are failing because of this.
Added:
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/PropertiesTest.java
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/Resource.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
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/hsql/DBUtils.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/SQLQueryProcessor.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
trunk/registry/modules/webapps/src/main/webapp/admin/ajax/resource-properties.jsp
trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/Resource.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/Resource.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/Resource.java Sun Mar 9 10:41:53 2008
@@ -17,6 +17,7 @@
import java.util.Date;
import java.util.Properties;
+import java.util.List;
import java.io.InputStream;
public interface Resource {
@@ -42,6 +43,8 @@
String getProperty(String key);
+ public List getPropertyValues(String key);
+
Properties getProperties();
void setProperty(String key, String value);
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java Sun Mar 9 10:41:53 2008
@@ -261,7 +261,17 @@
}
public String getProperty(String key) {
- return (String)properties.get(key);
+
+ List propValues = (List) properties.get(key);
+ if (propValues == null) {
+ return null;
+ } else {
+ return (String) propValues.get(0);
+ }
+ }
+
+ public List getPropertyValues(String key) {
+ return (List) properties.get(key);
}
public Properties getProperties() {
@@ -269,7 +279,17 @@
}
public void setProperty(String key, String value) {
- this.properties.put(key, value);
+
+ List propValues = (List) properties.get(key);
+ if (propValues != null) {
+ if (!propValues.contains(value)) {
+ propValues.add(value);
+ }
+ } else {
+ propValues = new ArrayList();
+ propValues.add(value);
+ properties.put(key, propValues);
+ }
}
public void setProperties(Properties properties) {
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java Sun Mar 9 10:41:53 2008
@@ -289,7 +289,9 @@
requestContext.setResourcePath(suggestedPath);
requestContext.setResource(resource);
- handlerManager.putChild(requestContext);
+ if (!suggestedPath.equals(RegistryConstants.ROOT_PATH)) {
+ handlerManager.putChild(requestContext);
+ }
handlerManager.put(requestContext);
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 Sun Mar 9 10:41:53 2008
@@ -104,7 +104,7 @@
// set the datasource to fetch the content.
resource.setDataSource(dataSource);
-
+
//resource.setContentStream(getDisconnectedStream(
// versionResults.getBinaryStream(DatabaseConstants.VERSION_CONTENT_FIELD)));
}
@@ -204,7 +204,7 @@
if (versionNumber == -1) {
versionNumber = getLatestVersionNumber(resourceID, conn);
}
-
+
String sqlVersionedFields = "SELECT * FROM VERSIONS WHERE AID=? AND VN=?";
PreparedStatement versionQuery = conn.prepareStatement(sqlVersionedFields);
versionQuery.setLong(1, resourceID);
@@ -228,13 +228,14 @@
s3.setLong(1, resource.getId());
ResultSet propResults = s3.executeQuery();
- Properties props = new Properties();
+ //Properties props = new Properties();
while (propResults.next()) {
String key = propResults.getString(DatabaseConstants.PROPERTY_KEY_FIELD);
String value = propResults.getString(DatabaseConstants.PROPERTY_VALUE_FIELD);
- props.put(key, value);
+ resource.setProperty(key, value);
+ //props.put(key, value);
}
- resource.setProperties(props);
+ //resource.setProperties(props);
return resource;
}
@@ -243,7 +244,7 @@
throws SQLException {
String depSQL = "SELECT A.PATH, D.DAID, D.DVN FROM ARTIFACTS A, DEPENDENCY_MANAGEMENT D " +
- "WHERE D.AID=? AND D.VN=? AND D.DTYPE=? AND A.AID=D.DAID";
+ "WHERE D.AID=? AND D.VN=? AND D.DTYPE=? AND A.AID=D.DAID";
PreparedStatement depSt = conn.prepareStatement(depSQL);
depSt.setLong(1, resourceID);
@@ -271,7 +272,7 @@
throws SQLException {
String depSQL = "SELECT A.PATH, D.DAID, D.DVN FROM ARTIFACTS A, DEPENDENCY_MANAGEMENT D " +
- "WHERE D.AID=? AND D.VN=? AND D.DTYPE=? AND A.AID=D.DAID";
+ "WHERE D.AID=? AND D.VN=? AND D.DTYPE=? AND A.AID=D.DAID";
PreparedStatement depSt = conn.prepareStatement(depSQL);
depSt.setLong(1, resourceID);
@@ -320,7 +321,7 @@
throws SQLException {
String depSQL = "SELECT A.PATH, D.AID, D.VN FROM ARTIFACTS A, DEPENDENCY_MANAGEMENT D " +
- "WHERE D.DAID=? AND D.DVN=? AND D.DTYPE=? AND A.AID=D.AID";
+ "WHERE D.DAID=? AND D.DVN=? AND D.DTYPE=? AND A.AID=D.AID";
PreparedStatement depSt = conn.prepareStatement(depSQL);
depSt.setLong(1, resourceID);
@@ -346,7 +347,7 @@
throws SQLException {
String depSQL = "SELECT A.PATH, D.AID, D.VN FROM ARTIFACTS A, DEPENDENCY_MANAGEMENT D " +
- "WHERE D.DAID=? AND D.DVN=? AND D.DTYPE=? AND A.AID=D.AID";
+ "WHERE D.DAID=? AND D.DVN=? AND D.DTYPE=? AND A.AID=D.AID";
PreparedStatement depSt = conn.prepareStatement(depSQL);
depSt.setLong(1, resourceID);
@@ -455,7 +456,7 @@
// set the datasource to fetch the content.
resource.setDataSource(dataSource);
-
+
//if (!isDirectory) {
// resource.setContentStream(getDisconnectedStream(
// versionResults.getBinaryStream(DatabaseConstants.VERSION_CONTENT_FIELD)));
@@ -465,7 +466,7 @@
// get resource children
if (resource.isDirectory()) {
String[] children = getLatestChildPaths(resource.getId(),
- getCurrentVersionNumber(path, conn), conn);
+ getCurrentVersionNumber(path, conn), conn);
resource.setContent(children);
}
@@ -538,7 +539,7 @@
// }
} catch (SQLException e) {
log.info("Something went wrong while calculating the current " +
- "version for the path : " + path + " and the error us " + e);
+ "version for the path : " + path + " and the error us " + e);
return -1;
}
}
@@ -696,7 +697,7 @@
String sql =
"INSERT INTO ARTIFACTS (PATH, MEDIA_TYPE, DIRECTORY, STATE, CREATED_TIME, AUTHOR, " +
- "DESCRIPTION) VALUES (?,?,?,?,?,?,?)";
+ "DESCRIPTION) VALUES (?,?,?,?,?,?,?)";
long now = System.currentTimeMillis();
@@ -777,14 +778,30 @@
Iterator i = props.keySet().iterator();
while (i.hasNext()) {
String key = (String)i.next();
- String value = (String)props.get(key);
- s2.setLong(1, resourceID);
- s2.setString(2, key);
- s2.setString(3, value);
+ List propValues = (List) props.get(key);
+ if (propValues != null) {
+ Iterator<String> iValues = propValues.iterator();
+ while (iValues.hasNext()) {
+ String value = iValues.next();
+
+ s2.setLong(1, resourceID);
+ s2.setString(2, key);
+ s2.setString(3, value);
- s2.executeUpdate();
- s2.clearParameters();
+ s2.executeUpdate();
+ s2.clearParameters();
+ }
+ }
+
+ //String value = (String)props.get(key);
+ //
+ //s2.setLong(1, resourceID);
+ //s2.setString(2, key);
+ //s2.setString(3, value);
+ //
+ //s2.executeUpdate();
+ //s2.clearParameters();
}
}
}
@@ -798,11 +815,11 @@
throws SQLException, RegistryException {
String depAddSQL = "INSERT INTO DEPENDENCY_MANAGEMENT (AID, VN, DAID, DVN, DTYPE) " +
- "VALUES (?,?,?,?,?)";
+ "VALUES (?,?,?,?,?)";
PreparedStatement addSt = conn.prepareStatement(depAddSQL);
String checkSQL = "SELECT AID FROM DEPENDENCY_MANAGEMENT " +
- "WHERE AID=? AND VN=? AND DAID=? AND DVN=? AND DTYPE=?";
+ "WHERE AID=? AND VN=? AND DAID=? AND DVN=? AND DTYPE=?";
PreparedStatement checkSt = conn.prepareStatement(checkSQL);
for (String dependencyPath : dependencyPaths) {
@@ -983,7 +1000,7 @@
// calling the getContentStream loads the input stream to the resource. so we can
// access it even after changing the original resource.
resource.setContentStream(resource.getContentStream());
-
+
String resourcePath = resource.getPath();
long resourceID = resource.getId();
//to see whether the patent node is there in the table , if not need to add that
@@ -1288,9 +1305,9 @@
// long artifactVersionNumber = getLatestVersionNumber(parentId, connection);
long nextVersionNumber = createNextVersion(parentId,
- resource.getLastUpdaterUserName(),
- resource.getLastModified().getTime(),
- connection);
+ resource.getLastUpdaterUserName(),
+ resource.getLastModified().getTime(),
+ connection);
String selectSql = "SELECT DAID, DVN FROM DEPENDENCY WHERE AID=? AND VN=?";
PreparedStatement s = connection.prepareStatement(selectSql);
@@ -1308,19 +1325,19 @@
if (daid != resource.getId()) {
long dvn = result.getLong("DVN");
PreparedStatement ps = getStatementForDependencyTable(connection,
- parentId,
- nextVersionNumber,
- daid, dvn);
+ parentId,
+ nextVersionNumber,
+ daid, dvn);
dependeyMap.add(ps);
}
}
if (!delete) {
PreparedStatement ds = getStatementForDependencyTable(connection,
- parentId,
- nextVersionNumber,
- resource.getId(),
- versionNumber);
+ parentId,
+ nextVersionNumber,
+ resource.getId(),
+ versionNumber);
dependeyMap.add(ds);
}
@@ -1397,8 +1414,8 @@
long dvn = childResult.getLong("DVN");
long versionNumber = getLatestVersionNumber(resourceId, connection);
PreparedStatement ps = getStatementForDependencyTable(connection,
- resourceId, versionNumber,
- daid, dvn);
+ resourceId, versionNumber,
+ daid, dvn);
dependencyList.add(ps);
}
@@ -1513,7 +1530,7 @@
}
} catch (SQLException e) {
log.debug("Inside getResourceStatus trying to access the path: " + resourcePath +
- " error message" + e.getMessage());
+ " error message" + e.getMessage());
}
return false;
}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/hsql/DBUtils.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/hsql/DBUtils.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/hsql/DBUtils.java Sun Mar 9 10:41:53 2008
@@ -41,7 +41,7 @@
"PKEY VARCHAR (100) NOT NULL," +
"PVALUE VARCHAR (500) NOT NULL," +
"PRIMARY KEY (P_ID)," +
- "UNIQUE (AID, PKEY)," +
+ "UNIQUE (AID, PKEY, PVALUE)," +
"FOREIGN KEY (AID) REFERENCES ARTIFACTS (AID))";
private static final String childrenTable =
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/SQLQueryProcessor.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/SQLQueryProcessor.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/SQLQueryProcessor.java Sun Mar 9 10:41:53 2008
@@ -71,8 +71,7 @@
ResultSet results = s.executeQuery();
- String resultType =
- (String)query.getProperties().get(RegistryConstants.RESULT_TYPE_PROPERTY_NAME);
+ String resultType = query.getProperty(RegistryConstants.RESULT_TYPE_PROPERTY_NAME);
if (resultType == null || resultType.equals(RegistryConstants.RESOURCES_RESULT_TYPE)) {
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 Sun Mar 9 10:41:53 2008
@@ -831,6 +831,10 @@
r1.setContent(r1Content.getBytes());
registry.put("/r11", r1);
+ Resource r1New = registry.newResource();
+ r1New.setContent("New r1");
+ registry.put("/r1", r1New);
+
// put a collection in to the root
Collection c1 = registry.newCollection();
@@ -848,10 +852,9 @@
String r3Content = "this is r3 content";
Resource r3 = registry.newResource();
- Properties props = new Properties();
- props.put("Reviewer", "Deepal");
- props.put("Testedon", "Axis2");
- r3.setProperties(props);
+
+ r3.setProperty("Reviewer", "Deepal");
+ r3.setProperty("Testedon", "Axis2");
r3.setContent(r3Content.getBytes());
registry.put("/c2/r3", r3);
Added: trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/PropertiesTest.java
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/PropertiesTest.java Sun Mar 9 10:41:53 2008
@@ -0,0 +1,87 @@
+/*
+ * 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.jdbc;
+
+import junit.framework.TestCase;
+import org.wso2.registry.Registry;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.Resource;
+import org.wso2.registry.jdbc.realm.RegistryRealm;
+import org.wso2.registry.jdbc.realm.InMemoryRegistryRealm;
+
+import java.util.List;
+
+public class PropertiesTest extends TestCase {
+
+ protected static Registry registry = null;
+ protected static RegistryRealm realm = null;
+
+ public void setUp() {
+ try {
+ if (registry == null) {
+ realm = new InMemoryRegistryRealm();
+ registry = new InMemoryJDBCRegistry(realm);
+ }
+ } catch (RegistryException e) {
+ fail("Failed to initialize the registry. Caused by: " + e.getMessage());
+ }
+ }
+
+ public void testRootLevelProperties() throws RegistryException {
+
+ Resource root = registry.get("/");
+ root.setProperty("p1", "v1");
+ registry.put("/", root);
+
+ Resource rootb = registry.get("/");
+ assertEquals("Root should have a property named p1 with value v1", rootb.getProperty("p1"), "v1");
+ }
+
+ public void testSingleValuedProperties() throws RegistryException {
+
+ Resource r2 = registry.newResource();
+ r2.setContent("Some content for r2");
+ r2.setProperty("p1", "p1v1");
+ registry.put("/propTest/r2", r2);
+
+ Resource r2b = registry.get("/propTest/r2");
+ String p1Value = r2b.getProperty("p1");
+
+ assertEquals("Property p1 of /propTest/r2 should contain the value p1v1",
+ p1Value, "p1v1");
+ }
+
+ public void testMultiValuedProperties() throws RegistryException {
+
+ Resource r1 = registry.newResource();
+ r1.setContent("Some content for r1");
+ r1.setProperty("p1", "p1v1");
+ r1.setProperty("p1", "p1v2");
+ registry.put("/propTest/r1", r1);
+
+ Resource r1b = registry.get("/propTest/r1");
+ List propValues = r1b.getPropertyValues("p1");
+
+ assertTrue("Property p1 of /propTest/r1 should contain the value p1v1",
+ propValues.contains("p1v1"));
+
+ assertTrue("Property p1 of /propTest/r1 should contain the value p1v2",
+ propValues.contains("p1v2"));
+ }
+
+
+}
Modified: trunk/registry/modules/webapps/src/main/webapp/admin/ajax/resource-properties.jsp
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/ajax/resource-properties.jsp (original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/ajax/resource-properties.jsp Sun Mar 9 10:41:53 2008
@@ -3,6 +3,7 @@
<%@ page import="org.wso2.registry.web.utils.PropertiesUtil" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Properties" %>
+<%@ page import="java.util.List" %>
<%--
Created by IntelliJ IDEA.
User: chathura
@@ -29,11 +30,16 @@
Iterator iProps = props.keySet().iterator();
for (int i = 0; iProps.hasNext(); i++) {
- String name = (String) iProps.next();
- String value = (String) props.get(name);
- String safeName = name.replace("\'","\\\'");
- safeName = safeName.replace("\"","\\\"");
- safeName = safeName.replace(";","\\;");
+ String name = (String) iProps.next();
+ String value = "";
+ List propValues = (List) props.get(name);
+ if (propValues != null) {
+ value = (String) propValues.get(0);
+ }
+
+ String safeName = name.replace("\'", "\\\'");
+ safeName = safeName.replace("\"", "\\\"");
+ safeName = safeName.replace(";", "\\;");
%>
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 Sun Mar 9 10:41:53 2008
@@ -209,7 +209,13 @@
for (int i=0;iProps.hasNext();i++) {
String name = (String) iProps.next();
- String value = (String) props.get(name);
+
+ String value = "";
+ List propValues = (List) props.get(name);
+ if (propValues != null) {
+ value = (String) propValues.get(0);
+ }
+ //String value = (String) props.get(name);
String safeName = name.replace("\'","\\\'");
safeName = safeName.replace("\"","\\\"");
//safeName = safeName.replace(";","\\;");
More information about the Registry-dev
mailing list