[Registry-dev] svn commit r19306 - in trunk/registry: . modules/core modules/core/src/main/java/org/wso2/registry modules/core/src/main/java/org/wso2/registry/app modules/core/src/main/java/org/wso2/registry/config modules/core/src/main/java/org/wso2/registry/jdbc modules/core/src/main/java/org/wso2/registry/jdbc/indexing modules/core/src/main/java/org/wso2/registry/jdbc/utils modules/core/src/main/java/org/wso2/registry/session modules/extensions/src/org/wso2/registry/handlers modules/extensions/src/org/wso2/registry/servlet modules/extensions/test/org/wso2/registry/jdbc
kalani at wso2.com
kalani at wso2.com
Tue Jul 15 01:52:49 PDT 2008
Author: kalani
Date: Tue Jul 15 01:52:48 2008
New Revision: 19306
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=19306
Log:
Implemented the Indexer class and a sample handler. Introduced a new method(Collection searchContent (String
keywords)) to Registry API and added a test case to demonstrate indexing and content searching.
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/indexing/
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/indexing/DialectFactory.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/indexing/Indexer.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/utils/FlushTimer.java
trunk/registry/modules/extensions/src/org/wso2/registry/handlers/IndexingHandler.java
trunk/registry/modules/extensions/test/org/wso2/registry/jdbc/IndexingTest.java
Modified:
trunk/registry/modules/core/pom.xml
trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/AtomicRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/BasicRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/session/UserRegistry.java
trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml
trunk/registry/pom.xml
Modified: trunk/registry/modules/core/pom.xml
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/pom.xml?rev=19306&r1=19305&r2=19306&view=diff
==============================================================================
--- trunk/registry/modules/core/pom.xml (original)
+++ trunk/registry/modules/core/pom.xml Tue Jul 15 01:52:48 2008
@@ -86,7 +86,7 @@
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
- <scope>provided</scope>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.abdera</groupId>
@@ -163,6 +163,16 @@
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.compass-project</groupId>
+ <artifactId>compass</artifactId>
+ <version>2.0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.lucene</groupId>
+ <artifactId>lucene-core</artifactId>
+ <version>2.3.2</version>
+ </dependency>
</dependencies>
</project>
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java?rev=19306&r1=19305&r2=19306&view=diff
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java Tue Jul 15 01:52:48 2008
@@ -387,4 +387,11 @@
* @return the currently active RegistryContext, or null
*/
RegistryContext getRegistryContext();
+
+ /**
+ * Search the content of resources
+ * @param keywords
+ * @return the result set as a collection
+ */
+ Collection searchContent(String keywords) throws RegistryException;
}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java?rev=19306&r1=19305&r2=19306&view=diff
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java Tue Jul 15 01:52:48 2008
@@ -1119,4 +1119,8 @@
public RegistryContext getRegistryContext() {
return null;
}
+
+ public Collection searchContent (String keywords) throws RegistryException{
+ throw new UnsupportedOperationException();
+ }
}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java?rev=19306&r1=19305&r2=19306&view=diff
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java Tue Jul 15 01:52:48 2008
@@ -18,6 +18,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.store.jdbc.JdbcDirectory;
+import org.apache.lucene.store.RAMDirectory;
import org.wso2.registry.Aspect;
import org.wso2.registry.exceptions.RegistryException;
import org.wso2.registry.jdbc.EmbeddedRegistry;
@@ -55,6 +57,9 @@
private DataSource dataSource;
private EmbeddedRegistry embeddedRegistry;
+ private JdbcDirectory jdbcDir;
+ private RAMDirectory ramDir;
+
private static RegistryContext registryContext = null;
public static RegistryContext getSingleton() {
@@ -234,4 +239,20 @@
public void setCustomEditManager(CustomEditManager customEditManager) {
this.customEditManager = customEditManager;
}
+
+ public void setJdbcDir(JdbcDirectory jdbcDir){
+ this.jdbcDir = jdbcDir;
+ }
+
+ public JdbcDirectory getJdbcDir(){
+ return jdbcDir;
+ }
+
+ public void setRamDir(RAMDirectory ramDir){
+ this.ramDir = ramDir;
+ }
+
+ public RAMDirectory getRamDir(){
+ return ramDir;
+ }
}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/AtomicRegistry.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/AtomicRegistry.java?rev=19306&r1=19305&r2=19306&view=diff
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/AtomicRegistry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/AtomicRegistry.java Tue Jul 15 01:52:48 2008
@@ -1050,4 +1050,26 @@
throw new RegistryException(msg, e);
}
}
+
+ public Collection searchContent(String keywords) throws RegistryException{
+ try {
+
+ beginTransaction();
+
+ Collection result = basicRegistry.searchContent(keywords);
+
+ commitTransaction();
+
+ return result;
+
+ } catch (Exception e) {
+
+ String msg = "Failed to search content for the keywords " + keywords + ". " + e.getMessage();
+ log.error(msg, e);
+
+ rollbackTransaction();
+
+ throw new RegistryException(msg, e);
+ }
+ }
}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/BasicRegistry.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/BasicRegistry.java?rev=19306&r1=19305&r2=19306&view=diff
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/BasicRegistry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/BasicRegistry.java Tue Jul 15 01:52:48 2008
@@ -18,6 +18,13 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.search.Searcher;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Hits;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.wso2.registry.*;
import org.wso2.registry.Collection;
import org.wso2.registry.config.RegistryContext;
@@ -35,6 +42,7 @@
import org.wso2.registry.utils.VersionedPath;
import java.util.*;
+import java.io.IOException;
public class BasicRegistry implements Registry {
@@ -749,4 +757,25 @@
context.setResource(resource);
return aspect.getAvailableActions(context);
}
+
+ public Collection searchContent (String keywords) throws RegistryException{
+ try{
+ Searcher searcher = new IndexSearcher(RegistryContext.getSingleton().getRamDir());
+ Query query = new QueryParser("content", new StandardAnalyzer()).parse(keywords);
+ Hits hits = searcher.search(query);
+ Collection collection = new CollectionImpl();
+ String [] paths = new String [hits.length()];
+ for (int i = 0; i < hits.length(); i++) {
+ String id = hits.doc(i).get("id");
+ String path = resourceDAO.getResourcePath(id);
+ paths[i] = path;
+ }
+ collection.setContent(paths);
+ return collection;
+ }catch(IOException e){
+ throw new RegistryException(e.getMessage());
+ }catch(ParseException e){
+ throw new RegistryException(e.getMessage());
+ }
+ }
}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java?rev=19306&r1=19305&r2=19306&view=diff
==============================================================================
--- 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 Tue Jul 15 01:52:48 2008
@@ -18,6 +18,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.store.jdbc.JdbcDirectory;
+import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.index.LuceneUtils;
import org.wso2.registry.*;
import org.wso2.registry.exceptions.RegistryException;
import org.wso2.registry.config.RegistryContext;
@@ -30,6 +33,8 @@
import org.wso2.registry.jdbc.queries.QueryProcessorManager;
import org.wso2.registry.jdbc.realm.RegistryRealm;
import org.wso2.registry.jdbc.utils.Transaction;
+import org.wso2.registry.jdbc.utils.FlushTimer;
+import org.wso2.registry.jdbc.indexing.DialectFactory;
import org.wso2.registry.session.CurrentSession;
import org.wso2.registry.users.UserRealm;
import org.wso2.registry.users.UserStoreException;
@@ -40,8 +45,10 @@
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
+import java.sql.ResultSet;
import java.util.Date;
import java.util.Map;
+import java.io.IOException;
/**
* JDBC based implementation of the Registry. This will be used mostly as the back-end by other
@@ -66,6 +73,9 @@
private UserRealm systemUserRealm;
+ private JdbcDirectory jdbcDir;
+ private RAMDirectory ramDir;
+
/**
* Default constructor. JDBC registry should be configured using the configure(...) method, if
* it is instantiated using this constructor.
@@ -131,11 +141,15 @@
QueryProcessorManager queryProcessorManager =
new QueryProcessorManager(dataSource, realm, this);
+ initializeIndex();
+
if (registryContext == null) {
registryContext = new RegistryContext();
}
RegistryContext.setSingleton(registryContext);
registryContext.setRepository(repository);
+ registryContext.setJdbcDir(jdbcDir);
+ registryContext.setRamDir(ramDir);
resourceDAO = new ResourceDAO();
@@ -187,6 +201,27 @@
handlerManager.addHandler(0, tagURLMatcher, tagURLHandler);
}
+ private void initializeIndex() throws RegistryException{
+ try{
+ ResultSet rs =dataSource.getConnection().getMetaData().getTables(null, null, "indexTable", null);
+ jdbcDir = new JdbcDirectory(dataSource, DialectFactory.getDialect(dataSource)
+, "indexTable");
+ if(!rs.next()){
+ jdbcDir.create();
+ }
+ ramDir = new RAMDirectory();
+ byte [] buffer = new byte [100] ;
+ LuceneUtils.copy(jdbcDir, ramDir, buffer);
+ }catch(SQLException e){
+ throw new RegistryException(e.getMessage());
+ }catch(IOException e){
+ throw new RegistryException(e.getMessage());
+ }
+
+ java.util.Timer timer = new java.util.Timer();
+ timer.schedule(new FlushTimer(ramDir,jdbcDir), 0, 300);
+ }
+
public void beginTransaction() throws RegistryException {
if (Transaction.isStarted()) {
@@ -645,7 +680,17 @@
}
+ public Collection searchContent(String keywords) throws RegistryException{
+ if (Transaction.isStarted()) {
+ return basicRegistry.searchContent(keywords);
+ } else {
+ return atomicRegistry.searchContent(keywords);
+ }
+ }
+
public RegistryContext getRegistryContext() {
return registryContext;
}
+
+
}
Added: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/indexing/DialectFactory.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/indexing/DialectFactory.java?pathrev=19306
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/indexing/DialectFactory.java Tue Jul 15 01:52:48 2008
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2008, 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.indexing;
+
+import org.apache.lucene.store.jdbc.dialect.DerbyDialect;
+import org.apache.lucene.store.jdbc.dialect.Dialect;
+import org.apache.lucene.store.jdbc.dialect.HSQLDialect;
+import org.apache.lucene.store.jdbc.dialect.MySQLDialect;
+import org.wso2.registry.exceptions.RegistryException;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+
+public class DialectFactory {
+ public static Dialect getDialect(DataSource dataSource) throws RegistryException{
+ Connection conn = null;
+
+ try {
+ conn = dataSource.getConnection();
+ DatabaseMetaData metaData = conn.getMetaData();
+
+ if (metaData.getDatabaseProductName().matches("(?i).*hsql.*")) {
+ return new HSQLDialect();
+
+ } else if (metaData.getDatabaseProductName().matches("(?i).*derby.*")) {
+ return new DerbyDialect();
+
+ } else if (metaData.getDatabaseProductName().matches("(?i).*mysql.*")) {
+ return new MySQLDialect();
+
+ } else {
+ String msg = "Unsupported database: " + metaData.getDatabaseProductName() +
+ ". Database will not be created automatically by the WSO2 Registry. " +
+ "Please create the database using appropriate database scripts for " +
+ "the database.";
+
+ return null;
+ }
+
+ } catch (SQLException e) {
+
+ String msg = "Failed to detect dialect " + e.getMessage();
+ throw new RegistryException(msg, e);
+
+ } finally {
+ try {
+ if (conn != null) conn.close();
+ } catch (SQLException e) {
+
+ }
+ }
+ }
+}
Added: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/indexing/Indexer.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/indexing/Indexer.java?pathrev=19306
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/indexing/Indexer.java Tue Jul 15 01:52:48 2008
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2008, 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.indexing;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.store.RAMDirectory;
+import org.wso2.registry.Resource;
+import org.wso2.registry.config.RegistryContext;
+import org.wso2.registry.exceptions.RegistryException;
+import org.wso2.registry.jdbc.dao.ResourceDAO;
+import org.wso2.registry.jdbc.handlers.RequestContext;
+
+import java.io.IOException;
+import java.sql.SQLException;
+
+public class Indexer {
+
+ public void updateIndex(RequestContext requestContext) throws RegistryException {
+ StringBuffer sb = new StringBuffer();
+ String line, id;
+ ResourceDAO resourceDAO = new ResourceDAO();
+
+ Resource resource = requestContext.getResource();
+ String path = requestContext.getResourcePath().getPath();
+ RAMDirectory ramDir = RegistryContext.getSingleton().getRamDir();
+
+ try{
+
+ if(resourceDAO.resourceExists(path)){
+ id = resourceDAO.getResourceID(path, RegistryContext.getSingleton().getDataSource().getConnection());
+ if(IndexReader.indexExists(ramDir)){
+ IndexReader reader = IndexReader.open(ramDir);
+ Term term = new Term("id",id);
+ if(reader.docFreq(term) > 0){
+ reader.deleteDocuments(term);
+ }
+ reader.close();
+ }
+ }else{
+ id = resource.getId();
+ }
+ //InputStream is = resource.getContentStream();
+ // DataInputStream din = new DataInputStream(is);
+ // while((line=din.readLine()) != null){
+ // sb.append(line+"\n");
+ // }
+ // is.close();
+ byte [] content = (byte [])resource.getContent();
+ resource.setContentStream(null);
+
+ Document document = new Document();
+ document.add(new Field("id", id, Field.Store.YES, Field.Index.TOKENIZED));
+ document.add(new Field("content", new String(content),Field.Store.NO, Field.Index.TOKENIZED));
+
+ IndexWriter writer = new IndexWriter(RegistryContext.getSingleton().getRamDir(),new StandardAnalyzer());
+ writer.addDocument(document);
+ writer.optimize();
+ writer.close();
+ }catch(CorruptIndexException e){
+ e.printStackTrace();
+ }catch(IOException e){
+ e.printStackTrace();
+ }catch(SQLException e){
+ throw new RegistryException(e.getMessage());
+ }
+ }
+}
Added: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/utils/FlushTimer.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/utils/FlushTimer.java?pathrev=19306
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/utils/FlushTimer.java Tue Jul 15 01:52:48 2008
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2008, 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.utils;
+
+import org.apache.lucene.index.LuceneUtils;
+import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.store.jdbc.JdbcDirectory;
+
+import java.io.IOException;
+import java.util.TimerTask;
+
+
+public class FlushTimer extends TimerTask {
+ RAMDirectory ramDir;
+ JdbcDirectory jdbcDir;
+
+ byte [] buffer = new byte [100] ;
+
+ public FlushTimer (RAMDirectory ramDir, JdbcDirectory jdbcDir){
+ this.ramDir = ramDir;
+ this.jdbcDir = jdbcDir;
+ }
+
+ public void run(){
+
+
+ try{
+ jdbcDir.deleteContent();
+ LuceneUtils.copy(ramDir, jdbcDir, buffer);
+ }catch(IOException e){
+ e.printStackTrace();
+ }
+ }
+
+}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/session/UserRegistry.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/session/UserRegistry.java?rev=19306&r1=19305&r2=19306&view=diff
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/session/UserRegistry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/session/UserRegistry.java Tue Jul 15 01:52:48 2008
@@ -459,4 +459,11 @@
return coreRegistry.getAspectActions(resourcePath, aspectName);
}
+
+ public Collection searchContent(String keywords) throws RegistryException{
+ CurrentSession.setUser(userName);
+ CurrentSession.setRealm(userRealm);
+
+ return coreRegistry.searchContent(keywords);
+ }
}
Added: trunk/registry/modules/extensions/src/org/wso2/registry/handlers/IndexingHandler.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/extensions/src/org/wso2/registry/handlers/IndexingHandler.java?pathrev=19306
==============================================================================
--- (empty file)
+++ trunk/registry/modules/extensions/src/org/wso2/registry/handlers/IndexingHandler.java Tue Jul 15 01:52:48 2008
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2008, 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.handlers;
+
+import org.wso2.registry.Resource;
+import org.wso2.registry.exceptions.RegistryException;
+import org.wso2.registry.jdbc.indexing.Indexer;
+import org.wso2.registry.jdbc.handlers.Handler;
+import org.wso2.registry.jdbc.handlers.RequestContext;
+
+public class IndexingHandler extends Handler {
+ public Resource get(RequestContext requestContext) throws RegistryException {
+ return null;
+ }
+
+ public void put(RequestContext requestContext) throws RegistryException {
+ new Indexer().updateIndex(requestContext);
+ }
+
+ public void importResource(RequestContext requestContext) throws RegistryException {
+ }
+
+ public void delete(RequestContext requestContext) throws RegistryException {
+ }
+
+ public void putChild(RequestContext requestContext) throws RegistryException {
+
+ }
+
+ public void importChild(RequestContext requestContext) throws RegistryException {
+ }
+}
Modified: trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml?rev=19306&r1=19305&r2=19306&view=diff
==============================================================================
--- trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml (original)
+++ trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml Tue Jul 15 01:52:48 2008
@@ -121,6 +121,11 @@
<property name="mediaType">application/vnd.server-collection</property>
</filter>
</handler-->
+ <handler class="org.wso2.registry.handlers.IndexingHandler">
+ <filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">
+ <property name="mediaType">text/plain</property>
+ </filter>
+ </handler>
<aspect name="Lifecycle" class="org.wso2.registry.aspects.Lifecycle"/>
</wso2regsitry>
\ No newline at end of file
Added: trunk/registry/modules/extensions/test/org/wso2/registry/jdbc/IndexingTest.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/extensions/test/org/wso2/registry/jdbc/IndexingTest.java?pathrev=19306
==============================================================================
--- (empty file)
+++ trunk/registry/modules/extensions/test/org/wso2/registry/jdbc/IndexingTest.java Tue Jul 15 01:52:48 2008
@@ -0,0 +1,56 @@
+package org.wso2.registry.jdbc;
+
+import junit.framework.TestCase;
+import org.wso2.registry.Collection;
+import org.wso2.registry.Registry;
+import org.wso2.registry.RegistryConstants;
+import org.wso2.registry.Resource;
+import org.wso2.registry.config.RegistryContext;
+import org.wso2.registry.exceptions.RegistryException;
+
+public class IndexingTest extends TestCase {
+ /**
+ * Registry instance for use in tests. Note that there should be only one Registry instance in a
+ * JVM.
+ */
+ protected static Registry registry = null;
+
+ public void setUp() throws RegistryException {
+ if (registry == null) {
+// EmbeddedRegistry embeddedRegistry = new EmbeddedRegistry(new RegistryContext());
+ EmbeddedRegistry embeddedRegistry = new InMemoryEmbeddedRegistry();
+ registry = embeddedRegistry.getUserRegistry(
+ RegistryConstants.ADMIN_USER, RegistryConstants.ADMIN_PASSWORD);
+ }
+
+ }
+
+ public void testIndexing() throws RegistryException {
+ Resource r6 = registry.newResource();
+ String r6Content = "this is r6 content";
+ r6.setContent(r6Content.getBytes());
+ r6.setDescription("production ready.");
+ r6.setMediaType("text/plain");
+ String r6Path = "/c1/r6";
+
+ try {
+ registry.put(r6Path, r6);
+ } catch (RegistryException e) {
+
+ }
+
+ Collection collection1 = registry.searchContent("r6");
+ String [] paths1 = (String [])collection1.getContent();
+
+ assertEquals("Search should return the relevant path corresponding to the content which includes " +
+ "submitted keywords.","/c1/r6", paths1[0]);
+
+ Collection collection2 = registry.searchContent("non existing");
+ String [] paths2 = (String [])collection2.getContent();
+
+ assertEquals("Search should not return results when non existing keywords are submitted.",0, paths2.length);
+
+ }
+
+
+}
Modified: trunk/registry/pom.xml
URL: http://wso2.org/svn/browse/wso2/trunk/registry/pom.xml?rev=19306&r1=19305&r2=19306&view=diff
==============================================================================
--- trunk/registry/pom.xml (original)
+++ trunk/registry/pom.xml Tue Jul 15 01:52:48 2008
@@ -459,7 +459,13 @@
<id>wso2-maven2-repo</id>
<name>wso2.org maven2 repo</name>
<url>http://dist.wso2.org/maven2</url>
- </repository>
+ </repository>
+ <repository>
+ <id>compass-project.org</id>
+ <name>Compass</name>
+ <url>http://repo.compass-project.org</url>
+ </repository>
+
</repositories>
</project>
More information about the Registry-dev
mailing list