Started fixing the REST index stuff

This commit is contained in:
Andres Taylor
2011-03-28 15:08:35 +02:00
parent 8d759cbc68
commit 0d90f8907b
4 changed files with 32 additions and 20 deletions

View File

@@ -21,7 +21,7 @@ import java.util.Map;
* @since 24.01.11
*/
public abstract class RestIndex<T extends PropertyContainer> implements Index<T> {
private final RestRequest restRequest;
protected final RestRequest restRequest;
private final String indexName;
protected final RestGraphDatabase restGraphDatabase;
@@ -44,13 +44,20 @@ public abstract class RestIndex<T extends PropertyContainer> implements Index<T>
restRequest.post( indexPath( key, value ), JsonHelper.createJsonFrom( uri ) );
}
private String indexPath( String key, Object value ) {
return "index/" + getTypeName() + "/" + indexName + "/" + RestRequest.encode( key ) + "/" + RestRequest.encode( value );
protected String indexPath( ) {
return "index/" + getTypeName() + "/" + indexName;
}
protected String indexPath( String key ) {
return indexPath() + "/" + RestRequest.encode( key );
}
protected String indexPath( String key, Object value ) {
return indexPath( key ) + "/" + RestRequest.encode( value );
}
public void remove( T entity, String key, Object value ) {
restRequest.delete( indexPath( key, value ) + "/" + ( (RestEntity) entity ).getId() );
}
public void remove(T entity, String key) {

View File

@@ -9,26 +9,33 @@ import java.util.Map;
/**
* @author mh
* @author Andres Taylor <andres@neotechnology.com>
* @since 24.01.11
*/
public class RestNodeIndex extends RestIndex<Node> {
public RestNodeIndex( RestRequest restRequest, String indexName, RestGraphDatabase restGraphDatabase ) {
public class RestNodeIndex extends RestIndex<Node>
{
public RestNodeIndex( RestRequest restRequest, String indexName, RestGraphDatabase restGraphDatabase )
{
super( restRequest, indexName, restGraphDatabase );
}
public Class<Node> getEntityType() {
public Class<Node> getEntityType()
{
return Node.class;
}
public void remove(Node entity, String key) {
throw new UnsupportedOperationException();
public void remove( Node entity, String key )
{
restRequest.delete( indexPath( key ) );
}
public void remove(Node entity) {
throw new UnsupportedOperationException();
public void remove( Node entity )
{
restRequest.delete( indexPath() );
}
protected Node createEntity(Map<?, ?> item) {
return new RestNode((Map<?, ?>) item, restGraphDatabase);
protected Node createEntity( Map<?, ?> item )
{
return new RestNode( (Map<?, ?>)item, restGraphDatabase );
}
}

View File

@@ -1,9 +1,10 @@
package org.springframework.data.graph.neo4j.rest;
import org.apache.log4j.BasicConfigurator;
import org.junit.*;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.neo4j.rest.graphdb.RestGraphDatabase;
import org.neo4j.rest.graphdb.RestTestBase;
import org.springframework.data.graph.neo4j.support.NodeEntityTest;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
@@ -13,9 +14,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
import java.net.URI;
import java.net.URISyntaxException;
/**
* @author mh
* @since 28.03.11

View File

@@ -15,6 +15,6 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="graphDatabaseService" class="org.neo4j.rest.graphdb.RestGraphDatabase" scope="singleton">
<constructor-arg index="0" value="http://localhost:7475/db/data" />
<constructor-arg index="0" value="http://localhost:7473/db/data" />
</bean>
</beans>