http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/logging/src/main/java/org/apache/zest/library/logging/log/service/LoggingServiceMixin.java ---------------------------------------------------------------------- diff --git a/libraries/logging/src/main/java/org/apache/zest/library/logging/log/service/LoggingServiceMixin.java b/libraries/logging/src/main/java/org/apache/zest/library/logging/log/service/LoggingServiceMixin.java index 4431865..e11aa58 100644 --- a/libraries/logging/src/main/java/org/apache/zest/library/logging/log/service/LoggingServiceMixin.java +++ b/libraries/logging/src/main/java/org/apache/zest/library/logging/log/service/LoggingServiceMixin.java @@ -134,7 +134,7 @@ public abstract class LoggingServiceMixin EntityBuilder<ServiceLogRecord> builder = uow.newEntityBuilder( ServiceLogRecord.class ); ServiceLogRecord state = builder.instance(); setStandardStuff( type, composite, category, message, state, params ); - state.source().set( ( (ServiceComposite) composite ).identity().get() ); + state.source().set( ( (ServiceComposite) composite ).identity().get().toString() ); ServiceLogRecord slr = builder.newInstance(); } else if( composite instanceof EntityComposite )
http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/logging/src/main/java/org/apache/zest/library/logging/trace/service/TraceServiceMixin.java ---------------------------------------------------------------------- diff --git a/libraries/logging/src/main/java/org/apache/zest/library/logging/trace/service/TraceServiceMixin.java b/libraries/logging/src/main/java/org/apache/zest/library/logging/trace/service/TraceServiceMixin.java index 9d1258b..9afadce 100644 --- a/libraries/logging/src/main/java/org/apache/zest/library/logging/trace/service/TraceServiceMixin.java +++ b/libraries/logging/src/main/java/org/apache/zest/library/logging/trace/service/TraceServiceMixin.java @@ -128,12 +128,11 @@ public class TraceServiceMixin if( object instanceof EntityComposite ) { EntityComposite entity = (EntityComposite) object; - String identity = entity.identity().get(); EntityComposite source = (EntityComposite) uow.get( ZestAPI.FUNCTION_DESCRIPTOR_FOR.apply( entity ) .types() .findFirst() - .orElse( null ), identity ); + .orElse( null ), entity.identity().get() ); EntityBuilder<EntityTraceRecordEntity> builder = uow.newEntityBuilder( EntityTraceRecordEntity.class ); EntityTraceRecordEntity state = builder.instance(); setStandardStuff( compositeType, method, args, entryTime, duration, state, exception ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/logging/src/test/java/org/apache/zest/library/logging/DebuggingTest.java ---------------------------------------------------------------------- diff --git a/libraries/logging/src/test/java/org/apache/zest/library/logging/DebuggingTest.java b/libraries/logging/src/test/java/org/apache/zest/library/logging/DebuggingTest.java index 6a66ba7..b76c3e0 100644 --- a/libraries/logging/src/test/java/org/apache/zest/library/logging/DebuggingTest.java +++ b/libraries/logging/src/test/java/org/apache/zest/library/logging/DebuggingTest.java @@ -21,6 +21,7 @@ package org.apache.zest.library.logging; import java.util.function.Function; +import org.apache.zest.api.identity.Identity; import org.junit.Test; import org.apache.zest.api.injection.scope.This; import org.apache.zest.api.mixin.Mixins; @@ -72,11 +73,11 @@ public class DebuggingTest // QueryBuilder<DebugRecord> builder = module.newQueryBuilder( DebugRecord.class ); // Query<DebugRecord> query = builder.newQuery( uow ); // assertEquals( 0, query.count() ); - Some service = (Some) serviceFinder.findService( Some.class ).get(); + Some service = serviceFinder.findService( Some.class ).get(); String message = service.doSomething( "World!", 10 ); assertEquals( message, "Hello!" ); - EntityStore es = (EntityStore) serviceFinder.findService( EntityStore.class ).get(); - final String[] result = new String[1]; + EntityStore es = serviceFinder.findService( EntityStore.class ).get(); + final Identity[] result = new Identity[1]; es.entityStates( module ).transferTo( Transforms.map( new Function<EntityState, EntityState>() { public EntityState apply( EntityState entityState ) @@ -84,7 +85,7 @@ public class DebuggingTest if( ServiceDebugRecordEntity.class.getName() .equals( entityState.entityDescriptor().types().findFirst().get().getName() ) ) { - result[0] = entityState.identity().identity(); + result[0] = entityState.entityReference().identity(); } return entityState; http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/osgi/src/main/java/org/apache/zest/library/osgi/OSGiServiceExporter.java ---------------------------------------------------------------------- diff --git a/libraries/osgi/src/main/java/org/apache/zest/library/osgi/OSGiServiceExporter.java b/libraries/osgi/src/main/java/org/apache/zest/library/osgi/OSGiServiceExporter.java index 14d05c7..74cbdb5 100644 --- a/libraries/osgi/src/main/java/org/apache/zest/library/osgi/OSGiServiceExporter.java +++ b/libraries/osgi/src/main/java/org/apache/zest/library/osgi/OSGiServiceExporter.java @@ -95,7 +95,7 @@ public interface OSGiServiceExporter } properties.put( "org.apache.zest.api.service.active", ref.isActive() ); properties.put( "org.apache.zest.api.service.available", ref.isAvailable() ); - properties.put( "org.apache.zest.api.service.identity", ref.identity() ); + properties.put( "org.apache.zest.api.service.reference", ref.identity() ); String[] interfaceNames = interfacesOf( service.getClass() ) http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/osgi/src/test/java/org/apache/zest/library/osgi/OSGiServiceTest.java ---------------------------------------------------------------------- diff --git a/libraries/osgi/src/test/java/org/apache/zest/library/osgi/OSGiServiceTest.java b/libraries/osgi/src/test/java/org/apache/zest/library/osgi/OSGiServiceTest.java index 1b8ae91..e2bc45e 100644 --- a/libraries/osgi/src/test/java/org/apache/zest/library/osgi/OSGiServiceTest.java +++ b/libraries/osgi/src/test/java/org/apache/zest/library/osgi/OSGiServiceTest.java @@ -60,7 +60,7 @@ public class OSGiServiceTest "org.apache.zest.library.osgi.OSGiServiceTest$MyService", "org.apache.zest.library.osgi.OSGiEnabledService", "org.apache.zest.api.service.ServiceComposite", - "org.apache.zest.api.entity.Identity", + "org.apache.zest.api.identity.HasIdentity", "org.apache.zest.api.composite.Composite" }; verify( bundleContext ).registerService( expectedClasses, service, null ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/rdf/src/main/java/org/apache/zest/library/rdf/entity/EntityStateSerializer.java ---------------------------------------------------------------------- diff --git a/libraries/rdf/src/main/java/org/apache/zest/library/rdf/entity/EntityStateSerializer.java b/libraries/rdf/src/main/java/org/apache/zest/library/rdf/entity/EntityStateSerializer.java index 1be4b52..8386bd8 100644 --- a/libraries/rdf/src/main/java/org/apache/zest/library/rdf/entity/EntityStateSerializer.java +++ b/libraries/rdf/src/main/java/org/apache/zest/library/rdf/entity/EntityStateSerializer.java @@ -57,9 +57,9 @@ public class EntityStateSerializer @Tagged( ValueSerialization.Formats.JSON ) private ValueSerializer valueSerializer; - public URI createEntityURI( ValueFactory valueFactory, EntityReference identity ) + public URI createEntityURI( ValueFactory valueFactory, EntityReference reference ) { - return valueFactory.createURI( identity.toURI() ); + return valueFactory.createURI( reference.toURI() ); } public Iterable<Statement> serialize( final EntityState entityState ) @@ -82,8 +82,8 @@ public class EntityStateSerializer ) { ValueFactory values = graph.getValueFactory(); - EntityReference identity = entityState.identity(); - URI entityUri = createEntityURI( values, identity ); + EntityReference reference = entityState.entityReference(); + URI entityUri = createEntityURI( values, reference ); graph.add( entityUri, Rdfs.TYPE, http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/rdf/src/main/java/org/apache/zest/library/rdf/repository/NativeRepositoryService.java ---------------------------------------------------------------------- diff --git a/libraries/rdf/src/main/java/org/apache/zest/library/rdf/repository/NativeRepositoryService.java b/libraries/rdf/src/main/java/org/apache/zest/library/rdf/repository/NativeRepositoryService.java index fe8adc2..2cf1d7a 100644 --- a/libraries/rdf/src/main/java/org/apache/zest/library/rdf/repository/NativeRepositoryService.java +++ b/libraries/rdf/src/main/java/org/apache/zest/library/rdf/repository/NativeRepositoryService.java @@ -109,7 +109,7 @@ public interface NativeRepositoryService extends Repository, ServiceComposite, A File dataDirectory; if( dataDir == null || "".equals( dataDir ) ) { - String serviceIdentity = configuration.get().identity().get(); + String serviceIdentity = configuration.get().identity().get().toString(); if( fileConfiguration != null ) { dataDir = new File( fileConfiguration.dataDirectory(), serviceIdentity ).getAbsolutePath(); http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/EntitySerializerTest.java ---------------------------------------------------------------------- diff --git a/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/EntitySerializerTest.java b/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/EntitySerializerTest.java index 5947683..f57896e 100755 --- a/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/EntitySerializerTest.java +++ b/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/EntitySerializerTest.java @@ -22,6 +22,7 @@ package org.apache.zest.library.rdf.entity; import java.io.PrintWriter; import java.time.Instant; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.time.SystemTime; import org.junit.Before; import org.junit.Test; @@ -83,7 +84,7 @@ public class EntitySerializerTest public void testEntitySerializer() throws RDFHandlerException { - EntityReference entityReference = new EntityReference( "test2" ); + EntityReference entityReference = EntityReference.parseEntityReference( "test2" ); Usecase usecase = UsecaseBuilder.newUsecase( "Test" ); Instant currentTime = SystemTime.now(); EntityStoreUnitOfWork unitOfWork = entityStore.newUnitOfWork( module, usecase, currentTime ); @@ -110,14 +111,14 @@ public class EntitySerializerTest valueBuilder.prototype().test3().set( valueBuilder2.newInstance() ); TestValue testValue = valueBuilder.newInstance(); - EntityBuilder<TestEntity> builder = unitOfWork.newEntityBuilder( TestEntity.class, "test1" ); + EntityBuilder<TestEntity> builder = unitOfWork.newEntityBuilder( TestEntity.class, new StringIdentity( "test1" ) ); TestEntity rickardTemplate = builder.instance(); rickardTemplate.name().set( "Rickard" ); rickardTemplate.title().set( "Mr" ); rickardTemplate.value().set( testValue ); TestEntity testEntity = builder.newInstance(); - EntityBuilder<TestEntity> builder2 = unitOfWork.newEntityBuilder( TestEntity.class, "test2" ); + EntityBuilder<TestEntity> builder2 = unitOfWork.newEntityBuilder( TestEntity.class, new StringIdentity( "test2" ) ); TestEntity niclasTemplate = builder2.instance(); niclasTemplate.name().set( "Niclas" ); niclasTemplate.title().set( "Mr" ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/EntityTypeSerializerTest.java ---------------------------------------------------------------------- diff --git a/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/EntityTypeSerializerTest.java b/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/EntityTypeSerializerTest.java index c515902..d7154f2 100644 --- a/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/EntityTypeSerializerTest.java +++ b/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/EntityTypeSerializerTest.java @@ -20,6 +20,7 @@ package org.apache.zest.library.rdf.entity; +import org.apache.zest.api.identity.StringIdentity; import org.junit.Before; import org.junit.Test; import org.openrdf.model.Statement; @@ -95,14 +96,14 @@ public class EntityTypeSerializerTest valueBuilder.prototype().test3().set( vb2.newInstance() ); TestValue testValue = valueBuilder.newInstance(); - EntityBuilder<TestEntity> builder = unitOfWork.newEntityBuilder(TestEntity.class, "test1"); + EntityBuilder<TestEntity> builder = unitOfWork.newEntityBuilder(TestEntity.class, new StringIdentity( "test1") ); TestEntity rickardTemplate = builder.instance(); rickardTemplate.name().set( "Rickard" ); rickardTemplate.title().set( "Mr" ); rickardTemplate.value().set( testValue ); TestEntity testEntity = builder.newInstance(); - EntityBuilder<TestEntity> builder2 = unitOfWork.newEntityBuilder(TestEntity.class, "test2"); + EntityBuilder<TestEntity> builder2 = unitOfWork.newEntityBuilder(TestEntity.class, new StringIdentity( "test2") ); TestEntity niclasTemplate = builder2.instance(); niclasTemplate.name().set( "Niclas" ); niclasTemplate.title().set( "Mr" ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/test.xml ---------------------------------------------------------------------- diff --git a/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/test.xml b/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/test.xml index 3e4bcc1..3373b7e 100644 --- a/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/test.xml +++ b/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/test.xml @@ -37,7 +37,7 @@ </rdf:Description> <rdf:Description rdf:about="urn:zest:entity:test2"> <value xmlns="urn:zest:persistent:org.apache.zest.library.rdf.entity.TestEntity#"/> - <identity xmlns="urn:zest:persistent:org.apache.zest.api.entity.Identity#">test2</identity> + <identity xmlns="urn:zest:persistent:org.apache.zest.api.identity.HasIdentity#">test2</identity> <name xmlns="urn:zest:persistent:org.apache.zest.library.rdf.entity.TestEntity#">Niclas</name> <title xmlns="urn:zest:persistent:org.apache.zest.library.rdf.entity.TestEntity#">Mr</title> <association xmlns="urn:zest:persistent:org.apache.zest.library.rdf.entity.TestEntity#" rdf:resource="urn:zest:entity:test1"/> http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/test2.xml ---------------------------------------------------------------------- diff --git a/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/test2.xml b/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/test2.xml index a21e9a6..3a21393 100644 --- a/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/test2.xml +++ b/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/test2.xml @@ -26,7 +26,7 @@ <org.apache.zest.library.rdf.entity.TestEntity xmlns="urn:zest:persistent:Wvgf5vdB2OuC8JfcNmUqJLEPSYM:" rdf:about="urn:zest:entity:test2"> <value xmlns="urn:zest:persistent:org.apache.zest.library.rdf.entity.TestEntity#">{test1:5,test2:null,test3:{data:"Habba"}}</value> - <identity xmlns="urn:zest:persistent:org.apache.zest.api.entity.Identity#">test2</identity> + <identity xmlns="urn:zest:persistent:org.apache.zest.api.identity.HasIdentity#">test2</identity> <name xmlns="urn:zest:persistent:org.apache.zest.library.rdf.entity.TestEntity#">Niclas</name> <title xmlns="urn:zest:persistent:org.apache.zest.library.rdf.entity.TestEntity#">Mr</title> <association xmlns="urn:zest:persistent:org.apache.zest.library.rdf.entity.TestEntity#" rdf:resource="urn:zest:entity:test1"/> http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ContextResource.java ---------------------------------------------------------------------- diff --git a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ContextResource.java b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ContextResource.java index b6d6317..f062fdb 100644 --- a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ContextResource.java +++ b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ContextResource.java @@ -37,6 +37,7 @@ import org.apache.zest.api.constraint.ConstraintViolation; import org.apache.zest.api.constraint.ConstraintViolationException; import org.apache.zest.api.constraint.Name; import org.apache.zest.api.entity.EntityComposite; +import org.apache.zest.api.identity.Identity; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.injection.scope.Uses; @@ -204,12 +205,12 @@ public class ContextResource restlet.subResource( subResourceClass ); } - protected <T> T select( Class<T> entityClass, String id ) + protected <T> T select( Class<T> entityClass, Identity id ) throws ResourceException { try { - T composite = uowf.currentUnitOfWork().get( entityClass, id ); + T composite = uowf.currentUnitOfWork().get( entityClass, id ); current().select( composite ); return composite; } @@ -219,10 +220,10 @@ public class ContextResource } } - protected <T> T selectFromManyAssociation( ManyAssociation<T> manyAssociation, String id ) + protected <T> T selectFromManyAssociation( ManyAssociation<T> manyAssociation, Identity id ) throws ResourceException { - T entity = (T) uowf.currentUnitOfWork().get( Object.class, id ); + T entity = (T) uowf.currentUnitOfWork().get( Object.class, id ); if( !manyAssociation.contains( entity ) ) { throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND ); @@ -232,7 +233,7 @@ public class ContextResource return entity; } - protected <T> T selectFromNamedAssociation( NamedAssociation<T> namedAssociation, String id ) + protected <T> T selectFromNamedAssociation( NamedAssociation<T> namedAssociation, Identity id ) throws ResourceException { T entity = (T) uowf.currentUnitOfWork().get( Object.class, id ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ResourceValidity.java ---------------------------------------------------------------------- diff --git a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ResourceValidity.java b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ResourceValidity.java index d8d43e0..9fadf1c 100644 --- a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ResourceValidity.java +++ b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ResourceValidity.java @@ -67,7 +67,7 @@ class ResourceValidity if( entity != null ) { EntityState state = spi.entityStateOf( entity ); - Tag tag = new Tag( state.identity().identity() + "/" + state.version() ); + Tag tag = new Tag( state.entityReference().identity() + "/" + state.version() ); response.getEntity().setModificationDate( java.util.Date.from( state.lastModified() ) ); response.getEntity().setTag( tag ); } http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/RequestReaderDelegator.java ---------------------------------------------------------------------- diff --git a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/RequestReaderDelegator.java b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/RequestReaderDelegator.java index f1104e1..61447d8 100644 --- a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/RequestReaderDelegator.java +++ b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/RequestReaderDelegator.java @@ -24,6 +24,8 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; +import org.apache.zest.api.identity.Identity; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.mixin.InitializationException; @@ -51,11 +53,12 @@ public class RequestReaderDelegator throws InitializationException { Logger logger = LoggerFactory.getLogger( getClass() ); + Identity requestreaderdelegator = new StringIdentity("requestreaderdelegator"); // Add custom readers first for( ServiceReference<RequestReader> requestReader : requestReaderReferences ) { - if( !requestReader.identity().equals( "requestreaderdelegator" ) ) + if( !requestReader.identity().equals(requestreaderdelegator) ) { logger.info( "Registered request reader:" + requestReader.identity() ); registerRequestReader( requestReader.get() ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/ResponseWriterDelegator.java ---------------------------------------------------------------------- diff --git a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/ResponseWriterDelegator.java b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/ResponseWriterDelegator.java index a486184..66a17d3 100644 --- a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/ResponseWriterDelegator.java +++ b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/ResponseWriterDelegator.java @@ -23,6 +23,8 @@ package org.apache.zest.library.rest.server.restlet; import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; +import org.apache.zest.api.identity.Identity; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.mixin.InitializationException; @@ -48,11 +50,12 @@ public class ResponseWriterDelegator throws InitializationException { Logger logger = LoggerFactory.getLogger( getClass() ); + Identity responsewriterdelegator = new StringIdentity( "responsewriterdelegator" ); // Add custom writers first for( ServiceReference<ResponseWriter> resultWriter : resultWriters ) { - if( !resultWriter.identity().equals( "responsewriterdelegator" ) ) + if( !resultWriter.identity().equals(responsewriterdelegator) ) { logger.info( "Registered result writer:" + resultWriter.identity() ); registerResultWriter( resultWriter.get() ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/requestreader/DefaultRequestReader.java ---------------------------------------------------------------------- diff --git a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/requestreader/DefaultRequestReader.java b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/requestreader/DefaultRequestReader.java index 6d4af64..642d1c1 100644 --- a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/requestreader/DefaultRequestReader.java +++ b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/requestreader/DefaultRequestReader.java @@ -35,6 +35,8 @@ import org.apache.zest.api.association.AssociationDescriptor; import org.apache.zest.api.common.Optional; import org.apache.zest.api.constraint.Name; import org.apache.zest.api.entity.EntityReference; +import org.apache.zest.api.identity.Identity; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.property.PropertyDescriptor; @@ -257,8 +259,8 @@ public class DefaultRequestReader entityAsForm = new Form(); } - args[0] = uowf.currentUnitOfWork().get( method.getParameterTypes()[0], - getValue( "entity", queryAsForm, entityAsForm ) ); + Identity entityIdentity = new StringIdentity( getValue( "entity", queryAsForm, entityAsForm ) ); + args[0] = uowf.currentUnitOfWork().get( method.getParameterTypes()[0], entityIdentity ); return args; } @@ -490,7 +492,7 @@ public class DefaultRequestReader } else if( parameterType.isInterface() ) { - arg = uowf.currentUnitOfWork().get( parameterType, argString ); + arg = uowf.currentUnitOfWork().get( parameterType, new StringIdentity( argString ) ); } else { http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntitiesResource.java ---------------------------------------------------------------------- diff --git a/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntitiesResource.java b/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntitiesResource.java index 7b1bd14..22bff3e 100644 --- a/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntitiesResource.java +++ b/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntitiesResource.java @@ -207,7 +207,7 @@ public class EntitiesResource Entry entry = new Entry(); entry.setTitle( new Text( MediaType.TEXT_PLAIN, entityReference.toString() ) ); Link link = new Link(); - link.setHref( getRequest().getResourceRef().clone().addSegment( entityReference.identity() ) ); + link.setHref( getRequest().getResourceRef().clone().addSegment( entityReference.identity().toString() ) ); entry.getLinks().add( link ); entries.add( entry ); } @@ -227,11 +227,11 @@ public class EntitiesResource try { /* - * InputStream in = entity.getStream(); ObjectInputStream oin = new ObjectInputStream( in ); String identity + * InputStream in = entity.getStream(); ObjectInputStream oin = new ObjectInputStream( in ); String reference * = oin.readUTF(); Usecase usecase = (Usecase) oin.readUnshared(); MetaInfo unitofwork = (MetaInfo) * oin.readUnshared(); Iterable<UnitOfWorkEvent> events = (Iterable<UnitOfWorkEvent>) oin.readUnshared(); * - * // Store state try { entityStore.apply( identity, events, usecase, unitofwork ).commit(); } catch( + * // Store state try { entityStore.apply( reference, events, usecase, unitofwork ).commit(); } catch( * ConcurrentEntityStateModificationException e ) { throw new ResourceException( * Status.CLIENT_ERROR_CONFLICT ); } */ http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntityResource.java ---------------------------------------------------------------------- diff --git a/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntityResource.java b/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntityResource.java index 212678c..bd6d5e0 100755 --- a/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntityResource.java +++ b/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntityResource.java @@ -32,6 +32,8 @@ import java.util.Map; import java.util.Set; import org.apache.zest.api.entity.EntityDescriptor; import org.apache.zest.api.entity.EntityReference; +import org.apache.zest.api.identity.Identity; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.injection.scope.Uses; @@ -85,7 +87,7 @@ public class EntityResource @Uses private EntityStateSerializer entitySerializer; - private String identity; + private Identity identity; public EntityResource() { @@ -102,9 +104,9 @@ public class EntityResource protected void doInit() throws ResourceException { - // /entity/{identity} + // /entity/{reference} Map<String, Object> attributes = getRequest().getAttributes(); - identity = (String) attributes.get( "identity" ); + identity = new StringIdentity( (String) attributes.get( "reference" ) ); } @Override @@ -115,8 +117,8 @@ public class EntityResource EntityStoreUnitOfWork uow = entityStore.newUnitOfWork( module, usecase, SystemTime.now() ); try { - EntityReference identityRef = EntityReference.parseEntityReference( identity ); - uow.entityStateOf( module, identityRef ).remove(); + EntityReference reference = EntityReference.create( identity ); + uow.entityStateOf( module, reference ).remove(); uow.applyChanges().commit(); getResponse().setStatus( Status.SUCCESS_NO_CONTENT ); } @@ -179,7 +181,7 @@ public class EntityResource EntityState entityState; try { - EntityReference entityReference = EntityReference.parseEntityReference( identity ); + EntityReference entityReference = EntityReference.create( identity ); entityState = unitOfWork.entityStateOf( module, entityReference ); } catch( EntityNotFoundException e ) @@ -208,10 +210,10 @@ public class EntityResource throws IOException { PrintWriter out = new PrintWriter( writer ); - out.println( "<html><head><title>" + entity.identity() + "</title>" + out.println( "<html><head><title>" + entity.entityReference() + "</title>" + "<link rel=\"alternate\" type=\"application/rdf+xml\" " - + "href=\"" + entity.identity() + ".rdf\"/></head><body>" ); - out.println( "<h1>" + entity.identity() + "</h1>" ); + + "href=\"" + entity.entityReference() + ".rdf\"/></head><body>" ); + out.println( "<h1>" + entity.entityReference() + "</h1>" ); out.println( "<form method=\"post\" action=\"" + getRequest().getResourceRef().getPath() + "\">\n" ); out.println( "<fieldset><legend>Properties</legend>\n<table>" ); @@ -255,11 +257,11 @@ public class EntityResource out.println( "<fieldset><legend>ManyAssociations</legend>\n<table>" ); descriptor.state().manyAssociations().forEach( associationType -> { - ManyAssociationState identities = entity.manyAssociationValueOf( associationType.qualifiedName() ); + ManyAssociationState references = entity.manyAssociationValueOf( associationType.qualifiedName() ); String value = ""; - for( EntityReference identity : identities ) + for( EntityReference reference : references ) { - value += identity.identity() + "\n"; + value += reference.identity() + "\n"; } out.println( "<tr><td>" @@ -414,7 +416,7 @@ public class EntityResource int index = 0; while( ( identity = bufferedReader.readLine() ) != null ) { - EntityReference reference = new EntityReference( identity ); + EntityReference reference = EntityReference.parseEntityReference( identity ); if( manyAssociation.count() < index && manyAssociation.get( index ).equals( reference ) ) { @@ -473,7 +475,7 @@ public class EntityResource break; } String identity = line; - EntityReference reference = new EntityReference( identity ); + EntityReference reference = EntityReference.parseEntityReference( identity ); try { unitOfWork.entityStateOf( module, reference ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/RestApplication.java ---------------------------------------------------------------------- diff --git a/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/RestApplication.java b/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/RestApplication.java index 6173672..54f45f8 100644 --- a/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/RestApplication.java +++ b/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/RestApplication.java @@ -99,7 +99,7 @@ public class RestApplication Router router = new Router( getContext() ); router.attach( "/entity", newFinder( EntitiesResource.class ) ); - router.attach( "/entity/{identity}", newFinder( EntityResource.class ) ); + router.attach( "/entity/{reference}", newFinder( EntityResource.class ) ); router.attach( "/query", newFinder( SPARQLResource.class ) ); router.attach( "/query/sparqlhtml", newFinder( SPARQLResource.class ) ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/rest/src/main/resources/org/apache/zest/library/rest/admin/sparqlform.html ---------------------------------------------------------------------- diff --git a/libraries/rest/src/main/resources/org/apache/zest/library/rest/admin/sparqlform.html b/libraries/rest/src/main/resources/org/apache/zest/library/rest/admin/sparqlform.html index 24200e3..b91eaa7 100644 --- a/libraries/rest/src/main/resources/org/apache/zest/library/rest/admin/sparqlform.html +++ b/libraries/rest/src/main/resources/org/apache/zest/library/rest/admin/sparqlform.html @@ -43,7 +43,7 @@ <body> <form method="GET" action=""> <label>Query:</label><br/> - <textarea rows="20" cols="80" name="query">PREFIX ns0: <urn:zest:type:org.apache.zest.api.entity.Identity#> + <textarea rows="20" cols="80" name="query">PREFIX ns0: <urn:zest:type:org.apache.zest.api.identity.HasIdentity#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?entityType ?identity @@ -60,7 +60,7 @@ <h3>Get all entities</h3> <pre> -PREFIX ns0: <urn:zest:type:org.apache.zest.api.entity.Identity#> +PREFIX ns0: <urn:zest:type:org.apache.zest.api.identity.HasIdentity#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?entityType ?identity @@ -73,7 +73,7 @@ PREFIX ns0: <urn:zest:type:org.apache.zest.api.entity.Identity#> </pre> <h3>Get entities of a given type</h3> <pre> -PREFIX ns0: <urn:zest:type:org.apache.zest.api.entity.Identity#> +PREFIX ns0: <urn:zest:type:org.apache.zest.api.identity.HasIdentity#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?identity @@ -85,7 +85,7 @@ PREFIX ns0: <urn:zest:type:org.apache.zest.api.entity.Identity#> <h3>Get entities with a given property value</h3> <pre> -PREFIX ns0: <urn:zest:type:org.apache.zest.api.entity.Identity#> +PREFIX ns0: <urn:zest:type:org.apache.zest.api.identity.HasIdentity#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?identity http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/rest/src/test/java/org/apache/zest/library/rest/admin/DummyDataService.java ---------------------------------------------------------------------- diff --git a/libraries/rest/src/test/java/org/apache/zest/library/rest/admin/DummyDataService.java b/libraries/rest/src/test/java/org/apache/zest/library/rest/admin/DummyDataService.java index 918d3cc..4bb187d 100644 --- a/libraries/rest/src/test/java/org/apache/zest/library/rest/admin/DummyDataService.java +++ b/libraries/rest/src/test/java/org/apache/zest/library/rest/admin/DummyDataService.java @@ -24,6 +24,7 @@ import java.util.HashMap; import org.apache.zest.api.activation.ActivatorAdapter; import org.apache.zest.api.activation.Activators; import org.apache.zest.api.entity.EntityBuilder; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.mixin.Mixins; import org.apache.zest.api.service.ServiceComposite; @@ -76,13 +77,13 @@ public interface DummyDataService valueBuilder.prototype().string().set( "Foo bar value" ); valueBuilder.prototype().map().set( new HashMap() ); - EntityBuilder<TestEntity> builder = unitOfWork.newEntityBuilder( TestEntity.class, "test1" ); + EntityBuilder<TestEntity> builder = unitOfWork.newEntityBuilder( TestEntity.class, new StringIdentity( "test1" ) ); builder.instance().name().set( "Foo bar" ); builder.instance().age().set( 42 ); builder.instance().value().set( valueBuilder.newInstance() ); TestEntity testEntity = builder.newInstance(); - EntityBuilder<TestEntity> builder2 = unitOfWork.newEntityBuilder( TestEntity.class, "test2" ); + EntityBuilder<TestEntity> builder2 = unitOfWork.newEntityBuilder( TestEntity.class, new StringIdentity( "test2" ) ); builder2.instance().name().set( "Xyzzy" ); builder2.instance().age().set( 12 ); builder2.instance().association().set( testEntity ); @@ -97,7 +98,7 @@ public interface DummyDataService } { - EntityBuilder<TestEntity2> builder = unitOfWork.newEntityBuilder( TestEntity2.class, "test3" ); + EntityBuilder<TestEntity2> builder = unitOfWork.newEntityBuilder( TestEntity2.class, new StringIdentity( "test3" ) ); builder.instance().name().set( "Test3" ); builder.newInstance(); } http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/rest/src/test/java/org/apache/zest/library/rest/admin/RestTest.java ---------------------------------------------------------------------- diff --git a/libraries/rest/src/test/java/org/apache/zest/library/rest/admin/RestTest.java b/libraries/rest/src/test/java/org/apache/zest/library/rest/admin/RestTest.java index 651495c..fef807b 100644 --- a/libraries/rest/src/test/java/org/apache/zest/library/rest/admin/RestTest.java +++ b/libraries/rest/src/test/java/org/apache/zest/library/rest/admin/RestTest.java @@ -42,6 +42,7 @@ import org.apache.zest.api.common.Optional; import org.apache.zest.api.common.Visibility; import org.apache.zest.api.entity.EntityBuilder; import org.apache.zest.api.entity.EntityComposite; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.property.Property; import org.apache.zest.api.structure.ApplicationDescriptor; @@ -125,13 +126,13 @@ public class RestTest extends AbstractZestTest UnitOfWork uow = unitOfWorkFactory.newUnitOfWork(); try { - EntityBuilder<PersonEntity> builder1 = uow.newEntityBuilder( PersonEntity.class, "P2" ); + EntityBuilder<PersonEntity> builder1 = uow.newEntityBuilder( PersonEntity.class, new StringIdentity( "P2" ) ); PersonEntity maryDoe = builder1.instance(); maryDoe.firstname().set( "Mary" ); maryDoe.lastname().set( "Doe" ); maryDoe = builder1.newInstance(); - EntityBuilder<PersonEntity> builder2 = uow.newEntityBuilder( PersonEntity.class, "P1" ); + EntityBuilder<PersonEntity> builder2 = uow.newEntityBuilder( PersonEntity.class, new StringIdentity( "P1" ) ); PersonEntity joeDoe = builder2.instance(); joeDoe.firstname().set( "Joe" ); joeDoe.lastname().set( "Doe" ); @@ -155,12 +156,12 @@ public class RestTest extends AbstractZestTest // System.out.println( rdf.replaceAll( "\n", "\\\\n" ).replaceAll( "\"", "\\\\\"" ) ); assertThat( "Incorrect RDF produced", rdf, anyOf( // Open JDK 8 & Valid - equalTo( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rdf:RDF\n\txmlns:zest=\"http://zest.apache.org/rdf/model/1.0/\"\n\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n\txmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\">\n<org.apache.zest.library.rest.admin.RestTest-PersonEntity xmlns=\"urn:zest:type:\" rdf:about=\"urn:zest:entity:P1\">\n\t<lastname xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\">Doe</lastname>\n\t<firstname xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\">Joe</firstname>\n\t<identity xmlns=\"urn:zest:type:org.apache.zest.api.entity.Identity#\">P1</identity>\n\t<mother xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\" rdf:resource=\"urn:zest:entity:P2\"/>\n</org.apache.zest.library.rest.admin.RestTest-PersonEntity>\n\n</rdf:RDF>" ), - equalTo( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rdf:RDF\n\txmlns:zest=\"http://zest.apache.org/rdf/model/1.0/\"\n\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n\txmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\">\n<org.apache.zest.library.rest.admin.RestTest-PersonEntity xmlns=\"urn:zest:type:\" rdf:about=\"urn:zest:entity:P1\">\n\t<identity xmlns=\"urn:zest:type:org.apache.zest.api.entity.Identity#\">P1</identity>\n\t<firstname xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\">Joe</firstname>\n\t<lastname xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\">Doe</lastname>\n\t<mother xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\" rdf:resource=\"urn:zest:entity:P2\"/>\n</org.apache.zest.library.rest.admin.RestTest-PersonEntity>\n\n</rdf:RDF>" ), + equalTo( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rdf:RDF\n\txmlns:zest=\"http://zest.apache.org/rdf/model/1.0/\"\n\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n\txmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\">\n<org.apache.zest.library.rest.admin.RestTest-PersonEntity xmlns=\"urn:zest:type:\" rdf:about=\"urn:zest:entity:P1\">\n\t<lastname xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\">Doe</lastname>\n\t<firstname xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\">Joe</firstname>\n\t<identity xmlns=\"urn:zest:type:org.apache.zest.api.identity.HasIdentity#\">P1</identity>\n\t<mother xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\" rdf:resource=\"urn:zest:entity:P2\"/>\n</org.apache.zest.library.rest.admin.RestTest-PersonEntity>\n\n</rdf:RDF>" ), + equalTo( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rdf:RDF\n\txmlns:zest=\"http://zest.apache.org/rdf/model/1.0/\"\n\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n\txmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\">\n<org.apache.zest.library.rest.admin.RestTest-PersonEntity xmlns=\"urn:zest:type:\" rdf:about=\"urn:zest:entity:P1\">\n\t<identity xmlns=\"urn:zest:type:org.apache.zest.api.identity.HasIdentity#\">P1</identity>\n\t<firstname xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\">Joe</firstname>\n\t<lastname xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\">Doe</lastname>\n\t<mother xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\" rdf:resource=\"urn:zest:entity:P2\"/>\n</org.apache.zest.library.rest.admin.RestTest-PersonEntity>\n\n</rdf:RDF>" ), // Sun JDK 6 / Oracle JDK 7 & Valid - equalTo( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rdf:RDF\n\txmlns:zest=\"http://zest.apache.org/rdf/model/1.0/\"\n\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n\txmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\">\n<org.apache.zest.library.rest.admin.RestTest-PersonEntity xmlns=\"urn:zest:type:\" rdf:about=\"urn:zest:entity:P1\">\n\t<firstname xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\">Joe</firstname>\n\t<lastname xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\">Doe</lastname>\n\t<identity xmlns=\"urn:zest:type:org.apache.zest.api.entity.Identity#\">P1</identity>\n\t<mother xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\" rdf:resource=\"urn:zest:entity:P2\"/>\n</org.apache.zest.library.rest.admin.RestTest-PersonEntity>\n\n</rdf:RDF>" ), + equalTo( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rdf:RDF\n\txmlns:zest=\"http://zest.apache.org/rdf/model/1.0/\"\n\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n\txmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\">\n<org.apache.zest.library.rest.admin.RestTest-PersonEntity xmlns=\"urn:zest:type:\" rdf:about=\"urn:zest:entity:P1\">\n\t<firstname xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\">Joe</firstname>\n\t<lastname xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\">Doe</lastname>\n\t<identity xmlns=\"urn:zest:type:org.apache.zest.api.identity.HasIdentity#\">P1</identity>\n\t<mother xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\" rdf:resource=\"urn:zest:entity:P2\"/>\n</org.apache.zest.library.rest.admin.RestTest-PersonEntity>\n\n</rdf:RDF>" ), // IBM JDK 6 & Valid - equalTo( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rdf:RDF\n\txmlns:zest=\"http://zest.apache.org/rdf/model/1.0/\"\n\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n\txmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\">\n<org.apache.zest.library.rest.admin.RestTest-PersonEntity xmlns=\"urn:zest:type:\" rdf:about=\"urn:zest:entity:P1\">\n\t<identity xmlns=\"urn:zest:type:org.apache.zest.api.entity.Identity#\">P1</identity>\n\t<lastname xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\">Doe</lastname>\n\t<firstname xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\">Joe</firstname>\n\t<mother xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\" rdf:resource=\"urn:zest:entity:P2\"/>\n</org.apache.zest.library.rest.admin.RestTest-PersonEntity>\n\n</rdf:RDF>" ) ) ); + equalTo( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rdf:RDF\n\txmlns:zest=\"http://zest.apache.org/rdf/model/1.0/\"\n\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n\txmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\">\n<org.apache.zest.library.rest.admin.RestTest-PersonEntity xmlns=\"urn:zest:type:\" rdf:about=\"urn:zest:entity:P1\">\n\t<identity xmlns=\"urn:zest:type:org.apache.zest.api.identity.HasIdentity#\">P1</identity>\n\t<lastname xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\">Doe</lastname>\n\t<firstname xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\">Joe</firstname>\n\t<mother xmlns=\"urn:zest:type:org.apache.zest.library.rest.admin.RestTest-Person#\" rdf:resource=\"urn:zest:entity:P2\"/>\n</org.apache.zest.library.rest.admin.RestTest-PersonEntity>\n\n</rdf:RDF>" ) ) ); } @Test @@ -169,14 +170,14 @@ public class RestTest extends AbstractZestTest { RestTester restTester = objectFactory.newObject( RestTester.class ); Map<String, String> properties = new HashMap<String, String>(); - properties.put( "identity", "P1" ); + properties.put( "reference", "P1" ); properties.put( "firstname", "Jack" ); properties.put( "lastname", "Doe" ); restTester.putEntity( "P1", properties ); UnitOfWork work = unitOfWorkFactory.newUnitOfWork(); try { - PersonEntity entity = work.get( PersonEntity.class, "P1" ); + PersonEntity entity = work.get( PersonEntity.class, new StringIdentity( "P1" ) ); assertEquals( "FirstName not changed.", "Jack", entity.firstname().get() ); assertEquals( "LastName not changed.", "Doe", entity.lastname().get() ); work.complete(); @@ -199,7 +200,7 @@ public class RestTest extends AbstractZestTest PersonEntity entity = null; try { - entity = work.get( PersonEntity.class, "P1" ); + entity = work.get( PersonEntity.class, new StringIdentity( "P1" ) ); } catch( NoSuchEntityException expected ) { http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/restlet/src/main/java/org/apache/zest/library/restlet/ZestEntityRestlet.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/ZestEntityRestlet.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/ZestEntityRestlet.java index 977dad2..59c7a8d 100644 --- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/ZestEntityRestlet.java +++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/ZestEntityRestlet.java @@ -25,7 +25,7 @@ import java.util.List; import java.util.function.Consumer; import org.apache.zest.api.common.Optional; import org.apache.zest.api.entity.EntityComposite; -import org.apache.zest.api.entity.Identity; +import org.apache.zest.api.identity.HasIdentity; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.injection.scope.Uses; @@ -57,7 +57,7 @@ import org.restlet.representation.Variant; import org.restlet.routing.Router; import org.restlet.security.User; -public class ZestEntityRestlet<T extends Identity> extends Restlet +public class ZestEntityRestlet<T extends HasIdentity> extends Restlet { /** * Creates a new ZestEntityRestlet instance for the given resource and entity classes. @@ -73,7 +73,7 @@ public class ZestEntityRestlet<T extends Identity> extends Restlet * * @return The ZestEntityRestlet instance */ - public static <K extends Identity, T extends ServerResource<K>> Restlet newInstance( + public static <K extends HasIdentity, T extends ServerResource<K>> Restlet newInstance( Module module, Router router, Class<T> resourceClass, Class<K> entityClass ) { http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/restlet/src/main/java/org/apache/zest/library/restlet/ZrestApplication.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/ZrestApplication.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/ZrestApplication.java index 888b1c8..735533f 100644 --- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/ZrestApplication.java +++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/ZrestApplication.java @@ -21,7 +21,7 @@ package org.apache.zest.library.restlet; import java.util.logging.Level; import org.apache.zest.api.composite.TransientBuilderFactory; -import org.apache.zest.api.entity.Identity; +import org.apache.zest.api.identity.HasIdentity; import org.apache.zest.api.object.ObjectFactory; import org.apache.zest.api.service.ServiceFinder; import org.apache.zest.api.structure.Application; @@ -213,7 +213,7 @@ public abstract class ZrestApplication extends org.restlet.Application protected abstract void addRoutes( Router router ); protected void addResourcePath( String name, - Class<? extends Identity> type, + Class<? extends HasIdentity> type, String basePath ) { @@ -221,7 +221,7 @@ public abstract class ZrestApplication extends org.restlet.Application } protected void addResourcePath( String name, - Class<? extends Identity> type, + Class<? extends HasIdentity> type, String basePath, boolean createLink, boolean rootRoute @@ -240,8 +240,8 @@ public abstract class ZrestApplication extends org.restlet.Application router.attach( basePath + name + "/{id}/{invoke}", newZestRestlet( EntityResource.class, type ) ); } - private <K extends Identity, T extends ServerResource<K>> Restlet newZestRestlet( Class<T> resourceClass, - Class<K> entityClass + private <K extends HasIdentity, T extends ServerResource<K>> Restlet newZestRestlet(Class<T> resourceClass, + Class<K> entityClass ) { http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/EntityList.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/EntityList.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/EntityList.java index 95da91e..0db1c3d 100644 --- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/EntityList.java +++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/EntityList.java @@ -21,11 +21,11 @@ package org.apache.zest.library.restlet.crud; import java.util.List; -import org.apache.zest.api.entity.Identity; +import org.apache.zest.api.identity.HasIdentity; import org.apache.zest.api.property.Property; import org.apache.zest.library.restlet.Command; -public interface EntityList extends Identity +public interface EntityList extends HasIdentity { Property<List<EntityRef>> entities(); http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/EntityListResource.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/EntityListResource.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/EntityListResource.java index 605210b..6961ef9 100644 --- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/EntityListResource.java +++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/EntityListResource.java @@ -25,7 +25,9 @@ import java.util.Collections; import java.util.List; import java.util.stream.Stream; import java.util.stream.StreamSupport; -import org.apache.zest.api.entity.Identity; +import org.apache.zest.api.identity.HasIdentity; +import org.apache.zest.api.identity.Identity; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.injection.scope.This; @@ -46,9 +48,9 @@ import org.restlet.data.Method; import org.restlet.data.Reference; @Mixins( EntityListResource.Mixin.class ) -public interface EntityListResource<T extends Identity> extends ServerResource<EntityList> +public interface EntityListResource<T extends HasIdentity> extends ServerResource<EntityList> { - abstract class Mixin<T extends Identity> + abstract class Mixin<T extends HasIdentity> implements EntityListResource<T> { @This @@ -72,7 +74,7 @@ public interface EntityListResource<T extends Identity> extends ServerResource<E Property<Request> request = parameters.request(); Reference base = request.get().getResourceRef(); String name = "list[" + parameters.entityType().get().getSimpleName() + "]"; - String identity = identityManager.generate( EntityListResource.class, name ); + Identity identity = identityManager.generate( EntityListResource.class, name ); ValueBuilder<EntityList> builder = vbf.newValueBuilder( EntityList.class ); List<EntityRef> result = getEntityRefs( base ); EntityList prototype = builder.prototype(); @@ -96,9 +98,9 @@ public interface EntityListResource<T extends Identity> extends ServerResource<E //noinspection unchecked Class<T> entityType = parameters.entityType().get(); - identityManager.generate( entityType, name ); - locator.find( entityType ).create( name ); - return resourceBuilder.createRestLink( name, base, Method.GET ); + Identity identity = identityManager.generate(entityType, name); + locator.find( entityType ).create( identity ); + return resourceBuilder.createRestLink( identity, base, Method.GET ); } @SuppressWarnings( "unchecked" ) http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/EntityResource.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/EntityResource.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/EntityResource.java index d3cf73a..01abb1e 100644 --- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/EntityResource.java +++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/EntityResource.java @@ -25,7 +25,9 @@ import java.lang.reflect.Method; import java.time.format.DateTimeFormatter; import java.time.temporal.TemporalAccessor; import org.apache.zest.api.common.Optional; -import org.apache.zest.api.entity.Identity; +import org.apache.zest.api.identity.HasIdentity; +import org.apache.zest.api.identity.Identity; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.injection.scope.This; @@ -43,7 +45,7 @@ import org.apache.zest.spi.ZestSPI; import org.restlet.data.Reference; @Mixins( EntityResource.Mixin.class ) -public interface EntityResource<T extends Identity> extends ServerResource<T> +public interface EntityResource<T extends HasIdentity> extends ServerResource<T> { interface EntityParam { @@ -51,7 +53,7 @@ public interface EntityResource<T extends Identity> extends ServerResource<T> Property<String> invoke(); } - abstract class Mixin<T extends Identity> + abstract class Mixin<T extends HasIdentity> implements EntityResource<T> { @@ -62,7 +64,7 @@ public interface EntityResource<T extends Identity> extends ServerResource<T> private ValueBuilderFactory vbf; @This - private Identity me; + private HasIdentity me; @This private Parameters<T> parameters; @@ -95,8 +97,8 @@ public interface EntityResource<T extends Identity> extends ServerResource<T> public void delete() { Class entityType = parameters.entityType().get(); - String nameOfEntity = parameters.id().get(); - locator.find( entityType ).delete( nameOfEntity ); + String idOfEntity = parameters.id().get(); + locator.find( entityType ).delete( new StringIdentity( idOfEntity ) ); } @Override @@ -136,7 +138,7 @@ public interface EntityResource<T extends Identity> extends ServerResource<T> throw new RuntimeException( message, e ); } Reference base = parameters.request().get().getResourceRef(); - return resourceBuilder.createRestLink( "", base, org.restlet.data.Method.GET ); + return resourceBuilder.createRestLink( new StringIdentity( "" ), base, org.restlet.data.Method.GET ); } private Object createParametersComposite( RestForm form, Class argType ) http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/HasIdentitySpecification.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/HasIdentitySpecification.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/HasIdentitySpecification.java new file mode 100644 index 0000000..e54766d --- /dev/null +++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/HasIdentitySpecification.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.zest.library.restlet.crud; + +import java.util.function.Predicate; +import org.apache.zest.api.identity.HasIdentity; +import org.apache.zest.api.identity.Identity; +import org.apache.zest.api.util.NullArgumentException; + +public class HasIdentitySpecification + implements Predicate<HasIdentity> +{ + private final Identity id; + + public HasIdentitySpecification(Identity identity ) + { + NullArgumentException.validateNotNull( "reference", identity ); + this.id = identity; + } + + @Override + public boolean test( HasIdentity item ) + { + return id.equals( item.identity().get() ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/IdentitySpecification.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/IdentitySpecification.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/IdentitySpecification.java deleted file mode 100644 index 3f91e3e..0000000 --- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/crud/IdentitySpecification.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.zest.library.restlet.crud; - -import java.util.function.Predicate; -import org.apache.zest.api.entity.Identity; -import org.apache.zest.api.util.NullArgumentException; - -public class IdentitySpecification - implements Predicate<Identity> -{ - private final String id; - - public IdentitySpecification( String identity ) - { - NullArgumentException.validateNotNull( "identity", identity ); - this.id = identity; - } - - @Override - public boolean test( Identity item ) - { - return id.equals( item.identity().get() ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/restlet/src/main/java/org/apache/zest/library/restlet/identity/CanonicalName.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/identity/CanonicalName.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/identity/CanonicalName.java index abdee30..e4e29fd 100644 --- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/identity/CanonicalName.java +++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/identity/CanonicalName.java @@ -20,7 +20,7 @@ package org.apache.zest.library.restlet.identity; -import org.apache.zest.api.entity.Identity; +import org.apache.zest.api.identity.HasIdentity; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.injection.scope.This; import org.apache.zest.api.mixin.Mixins; @@ -36,7 +36,7 @@ public interface CanonicalName implements CanonicalName { @This - private Identity me; + private HasIdentity me; @Service private IdentityManager manager; http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/restlet/src/main/java/org/apache/zest/library/restlet/identity/IdentityManager.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/identity/IdentityManager.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/identity/IdentityManager.java index 40c5eda..b984459 100644 --- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/identity/IdentityManager.java +++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/identity/IdentityManager.java @@ -26,6 +26,8 @@ import java.util.function.Predicate; import org.apache.zest.api.common.Optional; import org.apache.zest.api.concern.Concerns; import org.apache.zest.api.configuration.Configuration; +import org.apache.zest.api.identity.Identity; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.injection.scope.This; import org.apache.zest.api.mixin.Mixins; @@ -45,11 +47,11 @@ public interface IdentityManager boolean isIdentity( String candidate ); - String generate( Class type, @Optional String canonicalName ); + Identity generate( Class type, @Optional String canonicalName ); - String extractName( String identity ); + String extractName( Identity identity ); - Class extractType( String identity ); + Class extractType( Identity identity ); @UnitOfWorkPropagation String findPrefix( Class type ); @@ -72,19 +74,19 @@ public interface IdentityManager } @Override - public String generate( Class type, String canonicalName ) + public Identity generate( Class type, String canonicalName ) { if( canonicalName == null ) { - canonicalName = uuidService.generate( type ); + canonicalName = uuidService.generate( type ).toString(); } if( isIdentity( canonicalName ) ) { // This is already an ID, and we simply return it. - return canonicalName; + return new StringIdentity( canonicalName ); } String prefix = findPrefix( type ); - return prefix + SEPARATOR + canonicalName; + return new StringIdentity( prefix + SEPARATOR + canonicalName ); } @Override @@ -106,33 +108,31 @@ public interface IdentityManager } @Override - public String extractName( String identity ) + public String extractName( Identity identity ) { - if( !isIdentity( identity ) ) - { - return identity; - } - int pos = identity.indexOf( SEPARATOR ); + String idString = identity.toString(); + int pos = idString.indexOf( SEPARATOR ); if( pos < 1 ) { - throw new InvalidIdentityFormatException( identity ); + throw new InvalidIdentityFormatException( idString ); } - return identity.substring( pos + 1 ); + return idString.substring( pos + 1 ); } @Override - public Class extractType( String identity ) + public Class extractType( Identity identity ) { - if( !isIdentity( identity ) ) + String idString = identity.toString(); + if( !isIdentity( idString ) ) { - throw new IllegalArgumentException( "Given argument '" + identity + "' is not an Identity" ); + throw new IllegalArgumentException( "Given argument '" + idString + "' is not an Identity" ); } - int pos = identity.indexOf( SEPARATOR ); + int pos = idString.indexOf( SEPARATOR ); if( pos < 1 ) { - throw new InvalidIdentityFormatException( identity ); + throw new InvalidIdentityFormatException( idString ); } - String prefix = identity.substring( 0, pos ); + String prefix = idString.substring( 0, pos ); Map.Entry<String, String> found = first( filter( http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/restlet/src/main/java/org/apache/zest/library/restlet/identity/InvalidIdentityFormatException.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/identity/InvalidIdentityFormatException.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/identity/InvalidIdentityFormatException.java index 876e7d1..76996ad 100644 --- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/identity/InvalidIdentityFormatException.java +++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/identity/InvalidIdentityFormatException.java @@ -24,6 +24,6 @@ public class InvalidIdentityFormatException extends RuntimeException { public InvalidIdentityFormatException( String identity ) { - super( "The given identity wasn't generated by the UrlIdentityManager: " + identity ); + super( "The given reference wasn't generated by the UrlIdentityManager: " + identity ); } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/CrudRepository.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/CrudRepository.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/CrudRepository.java index c4c5f05..ccc5ddd 100644 --- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/CrudRepository.java +++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/CrudRepository.java @@ -22,22 +22,23 @@ package org.apache.zest.library.restlet.repository; import java.util.function.Predicate; import org.apache.zest.api.composite.Composite; -import org.apache.zest.api.entity.Identity; +import org.apache.zest.api.identity.HasIdentity; +import org.apache.zest.api.identity.Identity; import org.apache.zest.api.unitofwork.concern.UnitOfWorkPropagation; -public interface CrudRepository<T extends Identity> +public interface CrudRepository<T extends HasIdentity> { @UnitOfWorkPropagation - void create( @EntityName String nameOfEntity ); + void create( @EntityName Identity identityOfEntity ); @UnitOfWorkPropagation - T get( @EntityName String nameOfEntity ); + T get( @EntityName Identity identityOfEntity ); @UnitOfWorkPropagation void update( T newStateAsValue ); @UnitOfWorkPropagation - void delete( @EntityName String nameOfEntity ); + void delete( @EntityName Identity identityOfEntity ); @UnitOfWorkPropagation Iterable<T> findAll(); http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/RepositoryLocator.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/RepositoryLocator.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/RepositoryLocator.java index 57ce091..2001376 100644 --- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/RepositoryLocator.java +++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/RepositoryLocator.java @@ -23,7 +23,7 @@ package org.apache.zest.library.restlet.repository; import java.util.HashMap; import java.util.Map; import java.util.stream.StreamSupport; -import org.apache.zest.api.entity.Identity; +import org.apache.zest.api.identity.HasIdentity; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.mixin.Mixins; import org.apache.zest.api.service.ServiceReference; @@ -31,7 +31,7 @@ import org.apache.zest.api.service.ServiceReference; @Mixins( RepositoryLocator.Mixin.class ) public interface RepositoryLocator { - <T extends Identity> CrudRepository<T> find( Class<T> entityType ); + <T extends HasIdentity> CrudRepository<T> find(Class<T> entityType ); class Mixin implements RepositoryLocator @@ -48,7 +48,7 @@ public interface RepositoryLocator } @Override - public <T extends Identity> CrudRepository<T> find( Class<T> entityType ) + public <T extends HasIdentity> CrudRepository<T> find(Class<T> entityType ) { //noinspection unchecked return repositories.get( entityType ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/SmallCrudRepositoryMixin.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/SmallCrudRepositoryMixin.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/SmallCrudRepositoryMixin.java index 781812c..73f04c0 100644 --- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/SmallCrudRepositoryMixin.java +++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/SmallCrudRepositoryMixin.java @@ -23,7 +23,8 @@ package org.apache.zest.library.restlet.repository; import java.util.function.Predicate; import org.apache.zest.api.ZestAPI; import org.apache.zest.api.composite.Composite; -import org.apache.zest.api.entity.Identity; +import org.apache.zest.api.identity.HasIdentity; +import org.apache.zest.api.identity.Identity; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.injection.scope.This; @@ -37,7 +38,7 @@ import org.apache.zest.api.unitofwork.UnitOfWork; import org.apache.zest.api.unitofwork.UnitOfWorkFactory; import org.apache.zest.library.restlet.identity.IdentityManager; -public class SmallCrudRepositoryMixin<T extends Identity> +public class SmallCrudRepositoryMixin<T extends HasIdentity> implements CrudRepository<T> { @Structure @@ -58,17 +59,17 @@ public class SmallCrudRepositoryMixin<T extends Identity> } @Override - public void create( String idOrName ) + public void create( Identity identity ) { UnitOfWork uow = uowf.currentUnitOfWork(); - uow.newEntity( entityType, identityManager.generate( entityType, idOrName ) ); + uow.newEntity( entityType, identity ); } @Override - public T get( String idOrName ) + public T get( Identity identity ) { UnitOfWork uow = uowf.currentUnitOfWork(); - return uow.get( entityType, identityManager.generate( entityType, idOrName ) ); + return uow.get( entityType, identity ); } @Override @@ -77,24 +78,23 @@ public class SmallCrudRepositoryMixin<T extends Identity> UnitOfWork uow = uowf.currentUnitOfWork(); @SuppressWarnings( "unchecked" ) - Class<Identity> type = (Class<Identity>) entityType; + Class<HasIdentity> type = (Class<HasIdentity>) entityType; uow.toEntity( type, newStateAsValue ); //updates the identified entity with the value } @Override - public void delete( String idOrName ) + public void delete( Identity identity ) { - String id = identityManager.generate( entityType, idOrName ); UnitOfWork uow = uowf.currentUnitOfWork(); try { - T entity = uow.get( entityType, id ); + T entity = uow.get( entityType, identity ); uow.remove( entity ); } catch( NoSuchEntityException | NoSuchEntityTypeException e ) { - throw new IllegalArgumentException( "Entity '" + idOrName + "' doesn't exist." ); + throw new IllegalArgumentException( "Entity '" + identity + "' doesn't exist." ); } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/CreationResource.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/CreationResource.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/CreationResource.java index 45dff20..b51d599 100644 --- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/CreationResource.java +++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/CreationResource.java @@ -20,7 +20,8 @@ package org.apache.zest.library.restlet.resource; -import org.apache.zest.api.entity.Identity; +import org.apache.zest.api.identity.HasIdentity; +import org.apache.zest.api.identity.Identity; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.injection.scope.This; @@ -38,9 +39,9 @@ import org.apache.zest.library.restlet.repository.RepositoryLocator; import org.restlet.data.Method; @Mixins( CreationResource.Mixin.class ) -public interface CreationResource<T extends Identity> extends ServerResource<T> +public interface CreationResource<T extends HasIdentity> extends ServerResource<T> { - abstract class Mixin<T extends Identity> + abstract class Mixin<T extends HasIdentity> implements CreationResource<T> { @Structure @@ -66,13 +67,13 @@ public interface CreationResource<T extends Identity> extends ServerResource<T> { String name = form.field( "name" ).value().get(); Class entityType = parameters.entityType().get(); - String identity = identityManager.generate( entityType, name ); + Identity identity = identityManager.generate( entityType, name ); locator.find( entityType ).create( identity ); doParameterization( form, entityType, identity ); - return resourceBuilder.createRestLink( name, parameters.request().get().getResourceRef(), Method.GET ); + return resourceBuilder.createRestLink( identity, parameters.request().get().getResourceRef(), Method.GET ); } - private <P> void doParameterization( RestForm form, Class entityType, String identity ) + private <P> void doParameterization( RestForm form, Class entityType, Identity identity ) { if( !CreationParameterized.class.isAssignableFrom( entityType ) ) { http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/DefaultResourceFactoryImpl.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/DefaultResourceFactoryImpl.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/DefaultResourceFactoryImpl.java index 735e97a..c28a1b1 100644 --- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/DefaultResourceFactoryImpl.java +++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/DefaultResourceFactoryImpl.java @@ -21,7 +21,7 @@ package org.apache.zest.library.restlet.resource; import java.util.Map; -import org.apache.zest.api.entity.Identity; +import org.apache.zest.api.identity.HasIdentity; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.injection.scope.Uses; import org.apache.zest.api.property.PropertyDescriptor; @@ -33,7 +33,7 @@ import org.restlet.Request; import org.restlet.Response; import org.restlet.routing.Router; -public class DefaultResourceFactoryImpl<K extends Identity, T extends ServerResource<K>> +public class DefaultResourceFactoryImpl<K extends HasIdentity, T extends ServerResource<K>> implements ResourceFactory<K, T> { @Uses @@ -81,7 +81,7 @@ public class DefaultResourceFactoryImpl<K extends Identity, T extends ServerReso private Object findValue( Map<String, Object> attributes, PropertyDescriptor descriptor ) { String name = descriptor.qualifiedName().name(); - if( name.equals( "identity" ) ) + if( name.equals( "reference" ) ) { Object id = attributes.get( "id" ); if( id == null ) http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/EntryPoint.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/EntryPoint.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/EntryPoint.java index f76a726..c877061 100644 --- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/EntryPoint.java +++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/EntryPoint.java @@ -21,11 +21,11 @@ package org.apache.zest.library.restlet.resource; import java.util.Map; -import org.apache.zest.api.entity.Identity; +import org.apache.zest.api.identity.HasIdentity; import org.apache.zest.api.property.Property; import org.apache.zest.library.restlet.RestLink; -public interface EntryPoint extends Identity +public interface EntryPoint extends HasIdentity { Property<Map<String,RestLink>> api(); } http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/EntryPointResource.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/EntryPointResource.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/EntryPointResource.java index 62b6779..e5dda03 100644 --- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/EntryPointResource.java +++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/EntryPointResource.java @@ -22,6 +22,7 @@ package org.apache.zest.library.restlet.resource; import java.util.HashMap; import java.util.Map; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.injection.scope.This; @@ -79,18 +80,18 @@ public interface EntryPointResource extends ServerResource<EntryPoint> RestLink link; if( route.getDescription() == null ) { - link = resourceBuilder.createRestLink( template.getPattern() , hostRef, Method.GET ); + link = resourceBuilder.createRestLink( new StringIdentity( template.getPattern() ), hostRef, Method.GET ); } else { - link = resourceBuilder.createRestLink( template.getPattern() , hostRef, Method.GET, route.getDescription() ); + link = resourceBuilder.createRestLink( new StringIdentity( template.getPattern() ), hostRef, Method.GET, route.getDescription() ); } entryPoints.put( route.getName(), link ); } } } ValueBuilder<EntryPoint> builder = vbf.newValueBuilder( EntryPoint.class ); - builder.prototype().identity().set( "/" ); + builder.prototype().identity().set( new StringIdentity( "/" ) ); builder.prototype().api().set( entryPoints ); return builder.newInstance(); }
