http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/core/spi/src/test/resources/logback-test.xml ---------------------------------------------------------------------- diff --cc core/spi/src/test/resources/logback-test.xml index 0000000,ac10e48..2dab9c5 mode 000000,100644..100644 --- a/core/spi/src/test/resources/logback-test.xml +++ b/core/spi/src/test/resources/logback-test.xml @@@ -1,0 -1,19 +1,16 @@@ + <?xml version="1.0" encoding="UTF-8"?> + <configuration> + + <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"> + <layout class="ch.qos.logback.classic.PatternLayout"> + <Pattern>%-5level %logger{24} - %msg%n</Pattern> + </layout> + </appender> + + <root level="info"> + <appender-ref ref="stdout" /> + </root> + - <logger name="org.qi4j.spi" level="trace"/> - <logger name="org.qi4j.spi.value" level="trace"/> - <logger name="org.qi4j.test.value" level="trace"/> - <logger name="org.qi4j.valueserializer" level="trace"/> ++ <logger name="org.qi4j.spi" level="debug"/> + -</configuration> ++</configuration>
http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/extensions/entitystore-gae/src/main/java/org/qi4j/entitystore/gae/GaeEntityState.java ---------------------------------------------------------------------- diff --cc extensions/entitystore-gae/src/main/java/org/qi4j/entitystore/gae/GaeEntityState.java index 0a20500,4895424..a246891 --- a/extensions/entitystore-gae/src/main/java/org/qi4j/entitystore/gae/GaeEntityState.java +++ b/extensions/entitystore-gae/src/main/java/org/qi4j/entitystore/gae/GaeEntityState.java @@@ -206,22 -209,28 +209,28 @@@ public class GaeEntityStat } @Override - public void setPropertyValue( QualifiedName stateName, Object value ) - public void setProperty( QualifiedName stateName, Object newValue ) ++ public void setPropertyValue( QualifiedName stateName, Object newValue ) { - System.out.println( "setProperty( " + stateName + ", " + value + " )" ); - if( value != null && Proxy.isProxyClass( value.getClass() ) ) + System.out.println( "setProperty( " + stateName + ", " + newValue + " )" ); + Object value = null; + if( newValue == null || ValueType.isPrimitiveValue( newValue ) ) + { + value = newValue; + } + else { - System.out.println( "handler: " + Proxy.getInvocationHandler( value ) ); - ValueType type = valueTypes.get( stateName ); try { - JSONWriterSerializer serializer = new JSONWriterSerializer(); - serializer.serialize( value, type ); - value = serializer.getJSON().toString(); + value = valueSerialization.serialize( newValue ); } - catch( JSONException e ) + catch( ValueSerializationException e ) { - InternalError error = new InternalError(); + String message = "\nqualifiedName: " + stateName + + "\n stateName: " + stateName.name() + + "\n class: " + newValue.getClass() + + "\n value: " + value + + "\n"; + InternalError error = new InternalError( message ); error.initCause( e ); throw error; } http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/extensions/entitystore-gae/src/main/java/org/qi4j/entitystore/gae/GaeEntityStoreUnitOfWork.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/extensions/entitystore-neo4j/src/main/java/org/qi4j/entitystore/neo4j/NeoEntityState.java ---------------------------------------------------------------------- diff --cc extensions/entitystore-neo4j/src/main/java/org/qi4j/entitystore/neo4j/NeoEntityState.java index 09bd808,a08fae9..73f986a --- a/extensions/entitystore-neo4j/src/main/java/org/qi4j/entitystore/neo4j/NeoEntityState.java +++ b/extensions/entitystore-neo4j/src/main/java/org/qi4j/entitystore/neo4j/NeoEntityState.java @@@ -118,6 -119,7 +119,7 @@@ public class NeoEntityStat { try { - PropertyDescriptor persistentProperty = entityDescriptor().state().getPropertyByQualifiedName( stateName ); ++ PropertyDescriptor persistentProperty = entityDescriptor().state().findPropertyModelByQualifiedName( stateName ); Object prop = underlyingNode.getProperty( "prop::" + stateName.toString(), null ); if( prop == null ) { @@@ -158,7 -147,8 +147,8 @@@ { if( prop != null ) { - if( isPrimitiveType( prop ) ) - PropertyDescriptor persistentProperty = entityDescriptor().state().getPropertyByQualifiedName( stateName ); ++ PropertyDescriptor persistentProperty = entityDescriptor().state().findPropertyModelByQualifiedName( stateName ); + if( ValueType.isPrimitiveValueType( persistentProperty.valueType() ) ) { underlyingNode.setProperty( "prop::" + stateName.toString(), prop ); } @@@ -314,4 -264,4 +264,4 @@@ { return uow; } --} ++} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/extensions/entitystore-neo4j/src/main/java/org/qi4j/entitystore/neo4j/NeoEntityStoreMixin.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/extensions/entitystore-neo4j/src/main/java/org/qi4j/entitystore/neo4j/NeoEntityStoreUnitOfWork.java ---------------------------------------------------------------------- diff --cc extensions/entitystore-neo4j/src/main/java/org/qi4j/entitystore/neo4j/NeoEntityStoreUnitOfWork.java index 1963a11,b7895c2..b372355 --- a/extensions/entitystore-neo4j/src/main/java/org/qi4j/entitystore/neo4j/NeoEntityStoreUnitOfWork.java +++ b/extensions/entitystore-neo4j/src/main/java/org/qi4j/entitystore/neo4j/NeoEntityStoreUnitOfWork.java @@@ -74,10 -77,10 +77,10 @@@ public class NeoEntityStoreUnitOfWor } @Override - public EntityState getEntityState( EntityReference anIdentity ) + public EntityState entityStateOf( EntityReference anIdentity ) throws EntityStoreException, EntityNotFoundException { - return new NeoEntityState( this, getEntityStateNode( anIdentity ), + return new NeoEntityState( valueSerialization, this, getEntityStateNode( anIdentity ), EntityStatus.LOADED ); } http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/extensions/entitystore-preferences/src/main/java/org/qi4j/entitystore/prefs/PreferencesEntityStoreMixin.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/extensions/entitystore-sql/src/main/java/org/qi4j/entitystore/sql/SQLEntityStoreMixin.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchIndexer.java ---------------------------------------------------------------------- diff --cc extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchIndexer.java index 8b74f18,8fdc00e..35430ca --- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchIndexer.java +++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchIndexer.java @@@ -146,91 -162,137 +162,137 @@@ public interface ElasticSearchIndexe private void index( BulkRequestBuilder bulkBuilder, String identity, String json ) { - LOGGER.trace( "Will index: {}", json ); bulkBuilder.add( support.client(). - prepareIndex( support.index(), support.entitiesType(), identity ). - setSource( json ) ); + prepareIndex( support.index(), support.entitiesType(), identity ). + setSource( json ) ); } + /** + * <pre> + * { + * "_identity": "ENTITY-IDENTITY", + * "_types": [ "All", "Entity", "types" ], + * "property.name": property.value, + * "association.name": "ASSOCIATED-IDENTITY", + * "manyassociation.name": [ "ASSOCIATED", "IDENTITIES" ] + * } + * </pre> + */ private String toJSON( EntityState state, Map<String, EntityState> newStates, EntityStoreUnitOfWork uow ) { - try { - StringWriter writer = new StringWriter(); - JSONWriter json = new JSONWriter( writer ); - JSONWriter types = json.object(). - key( "_identity" ).value( state.identity().identity() ). - key( "_types" ).array(); - for ( Class<?> type : state.entityDescriptor().mixinTypes() ) { - types.value( type.getName() ); - } - types.endArray(); + try + { + JSONObject json = new JSONObject(); + + json.put( "_identity", state.identity().identity() ); + json.put( "_types", Iterables.toList( Iterables.map( Classes.toClassName(), state.entityDescriptor().mixinTypes() ) ) ); + EntityDescriptor entityType = state.entityDescriptor(); - JSONWriterSerializer serializer = new JSONWriterSerializer( json ); // Properties - for ( PropertyDescriptor persistentProperty : entityType.state().properties() ) { - if ( persistentProperty.queryable() ) { - Object value = state.propertyValueOf( persistentProperty.qualifiedName() ); - json.key( persistentProperty.qualifiedName().name() ); - serializer.serialize( value, persistentProperty.valueType() ); + for( PropertyDescriptor propDesc : entityType.state().properties() ) + { + if( propDesc.queryable() ) + { + String key = propDesc.qualifiedName().name(); - Object value = state.getProperty( propDesc.qualifiedName() ); ++ Object value = state.propertyValueOf( propDesc.qualifiedName() ); + if( value == null || ValueType.isPrimitiveValue( value ) ) + { + json.put( key, value ); + } + else + { + // TODO Theses tests are pretty fragile, find a better way to fix this, Jackson API should behave better + String serialized = valueSerializer.serialize( value ); + if( serialized.startsWith( "{" ) ) + { + json.put( key, new JSONObject( serialized ) ); + } + else if( serialized.startsWith( "[" ) ) + { + json.put( key, new JSONArray( serialized ) ); + } + else + { + json.put( key, serialized ); + } + } } } // Associations - for ( AssociationDescriptor assocDesc : entityType.state().associations() ) { - if ( assocDesc.queryable() ) { + for( AssociationDescriptor assocDesc : entityType.state().associations() ) + { + if( assocDesc.queryable() ) + { + String key = assocDesc.qualifiedName().name(); - EntityReference associated = state.getAssociation( assocDesc.qualifiedName() ); + EntityReference associated = state.associationValueOf( assocDesc.qualifiedName() ); - json.key( assocDesc.qualifiedName().name() ); - if ( associated == null ) { - json.value( null ); - } else { - if ( assocDesc.isAggregated() || support.indexNonAggregatedAssociations() ) { - if ( newStates.containsKey( associated.identity() ) ) { - json.json( toJSON( newStates.get( associated.identity() ), newStates, uow ) ); - } else { - EntityState assocState = uow.entityStateOf( EntityReference.parseEntityReference( associated - .identity() ) ); - json.json( toJSON( assocState, newStates, uow ) ); + Object value; + if( associated == null ) + { + value = null; + } + else + { + if( assocDesc.isAggregated() || support.indexNonAggregatedAssociations() ) + { + if( newStates.containsKey( associated.identity() ) ) + { + value = new JSONObject( toJSON( newStates.get( associated.identity() ), newStates, uow ) ); } - } else { - json.object().key( "identity" ).value( associated.identity() ).endObject(); + else + { - EntityState assocState = uow.getEntityState( EntityReference.parseEntityReference( associated.identity() ) ); ++ EntityState assocState = uow.entityStateOf( EntityReference.parseEntityReference( associated.identity() ) ); + value = new JSONObject( toJSON( assocState, newStates, uow ) ); + } + } + else + { + value = new JSONObject( Collections.singletonMap( "identity", associated.identity() ) ); } } + json.put( key, value ); } } // ManyAssociations - for ( AssociationDescriptor manyAssocDesc : entityType.state().manyAssociations() ) { - if ( manyAssocDesc.queryable() ) { - JSONWriter assocs = json.key( manyAssocDesc.qualifiedName().name() ).array(); + for( AssociationDescriptor manyAssocDesc : entityType.state().manyAssociations() ) + { + if( manyAssocDesc.queryable() ) + { + String key = manyAssocDesc.qualifiedName().name(); + JSONArray array = new JSONArray(); - ManyAssociationState associateds = state.getManyAssociation( manyAssocDesc.qualifiedName() ); + ManyAssociationState associateds = state.manyAssociationValueOf( manyAssocDesc.qualifiedName() ); - for ( EntityReference associated : associateds ) { - if ( manyAssocDesc.isAggregated() || support.indexNonAggregatedAssociations() ) { - if ( newStates.containsKey( associated.identity() ) ) { - assocs.json( toJSON( newStates.get( associated.identity() ), newStates, uow ) ); - } else { - EntityState assocState = uow.entityStateOf( EntityReference.parseEntityReference( associated - .identity() ) ); - assocs.json( toJSON( assocState, newStates, uow ) ); + for( EntityReference associated : associateds ) + { + if( manyAssocDesc.isAggregated() || support.indexNonAggregatedAssociations() ) + { + if( newStates.containsKey( associated.identity() ) ) + { + array.put( new JSONObject( toJSON( newStates.get( associated.identity() ), newStates, uow ) ) ); + } + else + { - EntityState assocState = uow.getEntityState( EntityReference.parseEntityReference( associated.identity() ) ); ++ EntityState assocState = uow.entityStateOf( EntityReference.parseEntityReference( associated.identity() ) ); + array.put( new JSONObject( toJSON( assocState, newStates, uow ) ) ); } - } else { - assocs.object().key( "identity" ).value( associated.identity() ).endObject(); + } + else + { + array.put( new JSONObject( Collections.singletonMap( "identity", associated.identity() ) ) ); } } - assocs.endArray(); + json.put( key, array ); } } - json.endObject(); - - String result = writer.toString(); - return result; - } catch ( JSONException e ) { + return json.toString(); + } + catch( JSONException e ) + { throw new ElasticSearchIndexException( "Could not index EntityState", e ); } - } - } } http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/extensions/indexing-rdf/src/main/java/org/qi4j/index/rdf/query/internal/RdfQueryParserImpl2.java ---------------------------------------------------------------------- diff --cc extensions/indexing-rdf/src/main/java/org/qi4j/index/rdf/query/internal/RdfQueryParserImpl2.java index f1c8792,3c4cb53..2708545 --- a/extensions/indexing-rdf/src/main/java/org/qi4j/index/rdf/query/internal/RdfQueryParserImpl2.java +++ b/extensions/indexing-rdf/src/main/java/org/qi4j/index/rdf/query/internal/RdfQueryParserImpl2.java @@@ -533,23 -421,16 +428,15 @@@ public class RdfQueryParserImpl private void processContainsPredicate( final ContainsSpecification<?> predicate, StringBuilder builder ) { - Object value = predicate.getValue(); - - String valueVariable = triples.addTriple( predicate.getCollectionProperty(), false ).getValue(); + Object value = predicate.value(); - + String valueVariable = triples.addTriple( predicate.collectionProperty(), false ).value(); - try - { - builder.append( this.createRegexStringForContaining( - valueVariable, - this.createAndEscapeJSONString( - value, - predicate.collectionProperty() - ) - ) ); - } - catch( JSONException jsone ) - { - throw new UnsupportedOperationException( "Error when JSONing value", jsone ); - } + builder.append( this.createRegexStringForContaining( + valueVariable, + this.createAndEscapeJSONString( + value, - predicate.getCollectionProperty() ++ predicate.collectionProperty() + ) + ) ); } private void processMatchesPredicate( final MatchesSpecification predicate, StringBuilder builder ) @@@ -696,4 -577,4 +583,4 @@@ return value.toString(); } } --} ++} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/libraries/conversion/src/test/java/org/qi4j/library/conversion/values/EntityToValueTest.java ---------------------------------------------------------------------- diff --cc libraries/conversion/src/test/java/org/qi4j/library/conversion/values/EntityToValueTest.java index 82d8e2e,82d8e2e..f2e6030 --- a/libraries/conversion/src/test/java/org/qi4j/library/conversion/values/EntityToValueTest.java +++ b/libraries/conversion/src/test/java/org/qi4j/library/conversion/values/EntityToValueTest.java @@@ -20,8 -20,8 +20,8 @@@ import org.qi4j.api.unitofwork.UnitOfWo import org.qi4j.api.value.ValueComposite; import org.qi4j.bootstrap.AssemblyException; import org.qi4j.bootstrap.ModuleAssembly; --import org.qi4j.entitystore.memory.MemoryEntityStoreService; import org.qi4j.test.AbstractQi4jTest; ++import org.qi4j.test.EntityTestAssembler; import static org.junit.Assert.assertEquals; @@@ -36,7 -36,7 +36,7 @@@ public class EntityToValueTes // START SNIPPET: assembly module.services( EntityToValueService.class ); // END SNIPPET: assembly -- module.services( MemoryEntityStoreService.class ); ++ new EntityTestAssembler().assemble( module ); module.entities( PersonEntity.class ); module.values( PersonValue.class ); module.values( PersonValue2.class ); http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/libraries/eventsourcing/src/main/java/org/qi4j/library/eventsourcing/domain/replay/DomainEventPlayerService.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/libraries/rdf/src/main/java/org/qi4j/library/rdf/entity/EntityStateSerializer.java ---------------------------------------------------------------------- diff --cc libraries/rdf/src/main/java/org/qi4j/library/rdf/entity/EntityStateSerializer.java index b001815,e65c67b..e6af82c --- a/libraries/rdf/src/main/java/org/qi4j/library/rdf/entity/EntityStateSerializer.java +++ b/libraries/rdf/src/main/java/org/qi4j/library/rdf/entity/EntityStateSerializer.java @@@ -118,25 -119,17 +119,17 @@@ public class EntityStateSerialize final Graph graph, final Resource subject, final EntityDescriptor entityType, - final boolean includeNonQueryable - ) + final boolean includeNonQueryable ) { - try + // Properties + for( PropertyDescriptor persistentProperty : entityType.state().properties() ) { - // Properties - for( PropertyDescriptor persistentProperty : entityType.state().properties() ) - Object property = entityState.getProperty( persistentProperty.qualifiedName() ); ++ Object property = entityState.propertyValueOf( persistentProperty.qualifiedName() ); + if( property != null ) { - Object property = entityState.propertyValueOf( persistentProperty.qualifiedName() ); - if( property != null ) - { - serializeProperty( persistentProperty, property, subject, graph, includeNonQueryable ); - } + serializeProperty( persistentProperty, property, subject, graph, includeNonQueryable ); } } - catch( JSONException e ) - { - throw new IllegalArgumentException( "Could not JSON serialize value", e ); - } } private void serializeProperty( PropertyDescriptor persistentProperty, @@@ -166,11 -157,8 +157,7 @@@ } else { - JSONObjectSerializer serializer = new JSONObjectSerializer(); - serializer.setIncludeType( false ); - serializer.serialize( property, valueType ); - String stringProperty = serializer.rootObject().toString(); - + String stringProperty = valueSerializer.serialize( property, false ); - final Literal object = valueFactory.createLiteral( stringProperty ); graph.add( subject, predicate, object ); } http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/libraries/rdf/src/test/java/org/qi4j/library/rdf/entity/EntitySerializerTest.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/libraries/rest-client/src/main/java/org/qi4j/library/rest/client/requestwriter/ValueCompositeRequestWriter.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/libraries/rest/src/main/java/org/qi4j/library/rest/admin/EntityResource.java ---------------------------------------------------------------------- diff --cc libraries/rest/src/main/java/org/qi4j/library/rest/admin/EntityResource.java index b01aa45,175d75f..dbe1722 --- a/libraries/rest/src/main/java/org/qi4j/library/rest/admin/EntityResource.java +++ b/libraries/rest/src/main/java/org/qi4j/library/rest/admin/EntityResource.java @@@ -167,9 -156,9 +156,9 @@@ public class EntityResourc try { EntityReference entityReference = EntityReference.parseEntityReference( identity ); - entityState = unitOfWork.getEntityState( entityReference ); + entityState = unitOfWork.entityStateOf( entityReference ); } - catch (EntityNotFoundException e) + catch( EntityNotFoundException e ) { throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND ); } @@@ -202,33 -192,27 +192,27 @@@ final EntityDescriptor descriptor = entity.entityDescriptor(); - for (PropertyDescriptor persistentProperty : descriptor.state().properties()) + for( PropertyDescriptor persistentProperty : descriptor.state().properties() ) { - Object value = entity.getProperty( persistentProperty.qualifiedName() ); + Object value = entity.propertyValueOf( persistentProperty.qualifiedName() ); - try - { - out.println( "<tr><td>" + - "<label for=\"" + persistentProperty.qualifiedName() + "\" >" + - persistentProperty.qualifiedName().name() + - "</label></td>\n" + - "<td><input " + - "size=\"80\" " + - "type=\"text\" " + - (persistentProperty.isImmutable() ? "readonly=\"true\" " : "") + - "name=\"" + persistentProperty.qualifiedName() + "\" " + - "value=\"" + EntityResource.toString( value, persistentProperty.valueType() ) + "\"></td></tr>" ); - } catch (JSONException e) - { - throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e); - } + out.println( "<tr><td>" + + "<label for=\"" + persistentProperty.qualifiedName() + "\" >" + + persistentProperty.qualifiedName().name() + + "</label></td>\n" + + "<td><input " + + "size=\"80\" " + + "type=\"text\" " + + ( persistentProperty.isImmutable() ? "readonly=\"true\" " : "" ) + + "name=\"" + persistentProperty.qualifiedName() + "\" " + + "value=\"" + ( value == null ? "" : valueSerialization.serialize( value ) ) + "\"/></td></tr>" ); } out.println( "</table></fieldset>\n" ); out.println( "<fieldset><legend>Associations</legend>\n<table>" ); - for (AssociationDescriptor associationType : descriptor.state().associations()) + for( AssociationDescriptor associationType : descriptor.state().associations() ) { - Object value = entity.getAssociation( associationType.qualifiedName() ); + Object value = entity.associationValueOf( associationType.qualifiedName() ); - if (value == null) + if( value == null ) { value = ""; } @@@ -244,12 -228,12 +228,12 @@@ } out.println( "</table></fieldset>\n" ); - out.println( "<fieldset><legend>Many manyAssociations</legend>\n<table>" ); - for (AssociationDescriptor associationType : descriptor.state().manyAssociations()) + out.println( "<fieldset><legend>ManyAssociations</legend>\n<table>" ); + for( AssociationDescriptor associationType : descriptor.state().manyAssociations() ) { - ManyAssociationState identities = entity.getManyAssociation( associationType.qualifiedName() ); + ManyAssociationState identities = entity.manyAssociationValueOf( associationType.qualifiedName() ); String value = ""; - for (EntityReference identity : identities) + for( EntityReference identity : identities ) { value += identity.toString() + "\n"; } @@@ -331,79 -316,43 +316,43 @@@ { final EntityDescriptor descriptor = entity.entityDescriptor(); - // Create JSON string of all properties - StringBuilder str = new StringBuilder(); - str.append( '{' ); - - boolean first = true; - for (PropertyDescriptor persistentProperty : descriptor.state().properties()) + // Parse JSON into properties + for( PropertyDescriptor persistentProperty : descriptor.state().properties() ) { - if ( !persistentProperty.isImmutable()) + if( !persistentProperty.isImmutable() ) { - if (!first) - str.append( "," ); - first = false; - - str.append( '"' ).append( persistentProperty.qualifiedName().name() ).append( "\":" ); - - String newStringValue = form.getFirstValue( persistentProperty.qualifiedName().toString() ); - - if (newStringValue == null) + String formValue = form.getFirstValue( persistentProperty.qualifiedName().name(), null ); + if( formValue == null ) { - str.append("null"); - } else - entity.setProperty( persistentProperty.qualifiedName(), null ); ++ entity.setPropertyValue( persistentProperty.qualifiedName(), null ); + } + else { - if ( JSONDeserializer.isString( persistentProperty.valueType())) - { - str.append( '"' ).append( newStringValue ).append( '"' ); - } else - { - str.append(newStringValue); - } - entity.setProperty( persistentProperty.qualifiedName(), valueSerialization.deserialize( persistentProperty.valueType(), formValue ) ); ++ entity.setPropertyValue( persistentProperty.qualifiedName(), valueSerialization.deserialize( persistentProperty.valueType(), formValue ) ); } } } - str.append( '}' ); - - // Parse JSON into properties - JSONObject properties = new JSONObject(str.toString()); - - JSONDeserializer deserializer = new JSONDeserializer( module ); - for (PropertyDescriptor persistentProperty : descriptor.state().properties()) + for( AssociationDescriptor associationType : descriptor.state().associations() ) { - if ( !persistentProperty.isImmutable()) - { - Object jsonValue = properties.get( persistentProperty.qualifiedName().name() ); - - if (jsonValue == JSONObject.NULL) - jsonValue = null; - - Object value = deserializer.deserialize( jsonValue, persistentProperty.valueType() ); - - entity.setPropertyValue( persistentProperty.qualifiedName(), value ); - } - } - - for (AssociationDescriptor associationType : descriptor.state().associations()) - { - String newStringAssociation = form.getFirstValue( associationType.qualifiedName().toString() ); - if (newStringAssociation == null || newStringAssociation.equals( "" )) + String newStringAssociation = form.getFirstValue( associationType.qualifiedName().name() ); + if( newStringAssociation == null || newStringAssociation.equals( "" ) ) { - entity.setAssociation( associationType.qualifiedName(), null ); + entity.setAssociationValue( associationType.qualifiedName(), null ); - } else + } + else { - entity.setAssociation( associationType.qualifiedName(), EntityReference.parseEntityReference( newStringAssociation ) ); + entity.setAssociationValue( associationType.qualifiedName(), EntityReference.parseEntityReference( newStringAssociation ) ); } } - for (AssociationDescriptor associationType : descriptor.state().manyAssociations()) + for( AssociationDescriptor associationType : descriptor.state().manyAssociations() ) { - String newStringAssociation = form.getFirstValue( associationType.qualifiedName().toString() ); + String newStringAssociation = form.getFirstValue( associationType.qualifiedName().name() ); - ManyAssociationState manyAssociation = entity.getManyAssociation( associationType.qualifiedName() ); + ManyAssociationState manyAssociation = entity.manyAssociationValueOf( associationType.qualifiedName() ); - if (newStringAssociation == null) + if( newStringAssociation == null ) { // Remove "left-overs" - for (EntityReference entityReference : manyAssociation) + for( EntityReference entityReference : manyAssociation ) { manyAssociation.remove( entityReference ); } @@@ -476,4 -426,4 +426,4 @@@ return new EmptyRepresentation(); } --} ++} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/libraries/sql-liquibase/src/test/java/org/qi4j/library/sql/liquibase/LiquibaseServiceTest.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/libraries/sql/src/test/java/org/qi4j/library/sql/jmx/DataSourceConfigurationManagerServiceTest.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/samples/dci-cargo/dcisample_a/src/main/java/org/qi4j/sample/dcicargo/sample_a/infrastructure/model/JSONModel.java ---------------------------------------------------------------------- diff --cc samples/dci-cargo/dcisample_a/src/main/java/org/qi4j/sample/dcicargo/sample_a/infrastructure/model/JSONModel.java index ebaad3e,9a5cd5a..2abc2b8 --- a/samples/dci-cargo/dcisample_a/src/main/java/org/qi4j/sample/dcicargo/sample_a/infrastructure/model/JSONModel.java +++ b/samples/dci-cargo/dcisample_a/src/main/java/org/qi4j/sample/dcicargo/sample_a/infrastructure/model/JSONModel.java @@@ -76,4 -66,4 +66,4 @@@ public class JSONModel<T, U extends Val { valueComposite = null; } --} ++} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/infrastructure/model/JSONModel.java ---------------------------------------------------------------------- diff --cc samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/infrastructure/model/JSONModel.java index 69cccc2,7f8907d..a61a8a8 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/infrastructure/model/JSONModel.java +++ b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/infrastructure/model/JSONModel.java @@@ -78,4 -68,4 +68,4 @@@ public class JSONModel<T, U extends Val { valueComposite = null; } --} ++} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/e2ea757e/settings.gradle ----------------------------------------------------------------------
