You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by ni...@apache.org on 2016/06/12 08:56:27 UTC
[1/2] zest-java git commit: ZEST-151 : Removed Conversion Library
Repository: zest-java
Updated Branches:
refs/heads/develop 529448658 -> 1ead13389
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1ead1338/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntityService.java
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntityService.java b/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntityService.java
deleted file mode 100644
index 07eb026..0000000
--- a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntityService.java
+++ /dev/null
@@ -1,33 +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.conversion.values;
-
-import org.apache.zest.api.entity.Identity;
-import org.apache.zest.api.mixin.Mixins;
-
-/**
- * Service that creates or updates Entities from matching Values.
- * @deprecated Please use {@link org.apache.zest.api.unitofwork.UnitOfWork#toEntity(Class, Identity)} instead.
- */
-@Mixins( ValueToEntityMixin.class )
-public interface ValueToEntityService
- extends ValueToEntity
-{
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1ead1338/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/package.html
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/package.html b/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/package.html
deleted file mode 100644
index 8e3482c..0000000
--- a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/package.html
+++ /dev/null
@@ -1,24 +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.
- ~
- ~
- -->
-<html>
- <body>
- <h2>Entities to Values Conversion.</h2>
- </body>
-</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1ead1338/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/EntityToValueTest.java
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/EntityToValueTest.java b/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/EntityToValueTest.java
deleted file mode 100644
index 13c1868..0000000
--- a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/EntityToValueTest.java
+++ /dev/null
@@ -1,232 +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.conversion.values;
-
-import java.time.Instant;
-import java.time.LocalDate;
-import java.util.function.Function;
-import org.junit.Test;
-import org.apache.zest.api.constraint.ConstraintViolationException;
-import org.apache.zest.api.service.ServiceReference;
-import org.apache.zest.api.unitofwork.UnitOfWork;
-import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException;
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.ModuleAssembly;
-import org.apache.zest.library.conversion.values.TestModel.PersonEntity;
-import org.apache.zest.library.conversion.values.TestModel.PersonValue;
-import org.apache.zest.library.conversion.values.TestModel.PersonValue2;
-import org.apache.zest.library.conversion.values.TestModel.PersonValue3;
-import org.apache.zest.library.conversion.values.TestModel.PersonValue4;
-import org.apache.zest.test.AbstractZestTest;
-import org.apache.zest.test.EntityTestAssembler;
-
-import static org.junit.Assert.assertEquals;
-import static org.apache.zest.library.conversion.values.TestModel.createBirthDate;
-import static org.apache.zest.library.conversion.values.TestModel.createPerson;
-
-public class EntityToValueTest
- extends AbstractZestTest
-{
- @Override
- public void assemble( ModuleAssembly module )
- throws AssemblyException
- {
- // START SNIPPET: assembly
- new EntityToValueAssembler().assemble( module );
- // END SNIPPET: assembly
- new EntityTestAssembler().assemble( module );
- module.entities( PersonEntity.class );
- module.values( PersonValue.class );
- module.values( PersonValue2.class );
- module.values( PersonValue3.class );
- module.values( PersonValue4.class );
- }
-
- @Test
- public void whenConvertingEntityToValueExpectCorrectValues()
- throws UnitOfWorkCompletionException
- {
- UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
- try
- {
- PersonEntity entity = setupPersonEntities( uow );
-
- // START SNIPPET: conversion
- EntityToValueService conversion = serviceFinder.findService( EntityToValueService.class ).get();
- PersonValue value = conversion.convert( PersonValue.class, entity );
- // END SNIPPET: conversion
- assertEquals( "Niclas", value.firstName().get() );
- assertEquals( "Hedhman", value.lastName().get() );
- assertEquals( "id:Lis", value.spouse().get() );
- assertEquals( "id:Eric", value.children().get().get( 0 ) );
- uow.complete();
- }
- finally
- {
- uow.discard();
- }
- }
-
- @Test
- public void givenUnqualifiedValueWhenConvertingEntityExpectCorrectMapping()
- throws UnitOfWorkCompletionException
- {
- UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
- try
- {
- PersonEntity niclas = setupPersonEntities( uow );
-
- ServiceReference<EntityToValueService> reference = serviceFinder.findService( EntityToValueService.class );
- EntityToValueService service = reference.get();
-
- PersonValue2 niclasValue = service.convert( PersonValue2.class, niclas );
- assertEquals( "Niclas", niclasValue.firstName().get() );
- assertEquals( "Hedhman", niclasValue.lastName().get() );
- assertEquals( "id:Lis", niclasValue.spouse().get() );
- assertEquals( "id:Eric", niclasValue.children().get().get( 0 ) );
- uow.complete();
- }
- finally
- {
- uow.discard();
- }
- }
-
- @Test
- public void givenUnqualifiedValue2WhenConvertingEntityExpectCorrectMapping()
- throws UnitOfWorkCompletionException
- {
- UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
- try
- {
- PersonEntity niclas = setupPersonEntities( uow );
-
- ServiceReference<EntityToValueService> reference = serviceFinder.findService( EntityToValueService.class );
- EntityToValueService service = reference.get();
-
- PersonValue3 niclasValue = service.convert( PersonValue3.class, niclas );
- assertEquals( "Niclas", niclasValue.firstName().get() );
- assertEquals( "Hedhman", niclasValue.lastName().get() );
- assertEquals( "id:Lis", niclasValue.spouse().get() );
- assertEquals( "id:Eric", niclasValue.children().get().get( 0 ) );
- uow.complete();
- }
- finally
- {
- uow.discard();
- }
- }
-
- @Test( expected = ConstraintViolationException.class )
- public void givenQualifiedValueNotFromSameInterfaceWhenConvertingEntityExpectNonOptionalException()
- throws UnitOfWorkCompletionException
- {
- UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
- try
- {
- PersonEntity niclas = setupPersonEntities( uow );
-
- ServiceReference<EntityToValueService> reference = serviceFinder.findService( EntityToValueService.class );
- EntityToValueService service = reference.get();
-
- PersonValue4 niclasValue = service.convert( PersonValue4.class, niclas );
- uow.complete();
- }
- finally
- {
- uow.discard();
- }
- }
-
- @Test
- public void whenConvertingEntityToValueUsingPrototypeOpportunityExpectCorrectValues()
- throws UnitOfWorkCompletionException
- {
- UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
- try
- {
- PersonEntity entity = setupPersonEntities( uow );
-
- // START SNIPPET: prototypeOpportunity
- EntityToValueService conversion = serviceFinder.findService( EntityToValueService.class ).get();
- PersonValue value = conversion.convert( PersonValue.class, entity, new Function<PersonValue, PersonValue>()
- {
- @Override
- public PersonValue apply( PersonValue prototype )
- {
- prototype.firstName().set( "Prototype Opportunity" );
- return prototype;
- }
- } );
- // END SNIPPET: prototypeOpportunity
- assertEquals( "Prototype Opportunity", value.firstName().get() );
- assertEquals( "Hedhman", value.lastName().get() );
- assertEquals( "id:Lis", value.spouse().get() );
- assertEquals( "id:Eric", value.children().get().get( 0 ) );
- uow.complete();
- }
- finally
- {
- uow.discard();
- }
- }
-
- private static PersonEntity setupPersonEntities( UnitOfWork uow )
- {
- PersonEntity niclas = createNiclas( uow );
- PersonEntity lis = createLis( uow );
- PersonEntity eric = createEric( uow );
- niclas.spouse().set( lis );
- niclas.children().add( eric );
- lis.spouse().set( niclas );
- lis.children().add( eric );
- assertEquals( "Niclas", niclas.firstName() );
- assertEquals( "Hedhman", niclas.lastName() );
- assertEquals( "Lis", lis.firstName() );
- assertEquals( "Gazi", lis.lastName() );
- assertEquals( "Eric", eric.firstName() );
- assertEquals( "Hedman", eric.lastName() );
- return niclas;
- }
-
- private static PersonEntity createNiclas( UnitOfWork uow )
- {
- String firstName = "Niclas";
- String lastName = "Hedhman";
- LocalDate birthTime = createBirthDate( 1964, 9, 25 );
- return createPerson( uow, firstName, lastName, birthTime );
- }
-
- private static PersonEntity createLis( UnitOfWork uow )
- {
- String firstName = "Lis";
- String lastName = "Gazi";
- LocalDate birthTime = createBirthDate( 1976, 2, 19 );
- return createPerson( uow, firstName, lastName, birthTime );
- }
-
- private static PersonEntity createEric( UnitOfWork uow )
- {
- String firstName = "Eric";
- String lastName = "Hedman";
- LocalDate birthTime = createBirthDate( 2004, 4, 8 );
- return createPerson( uow, firstName, lastName, birthTime );
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1ead1338/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/NestedValuesConversionTest.java
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/NestedValuesConversionTest.java b/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/NestedValuesConversionTest.java
deleted file mode 100644
index e049c30..0000000
--- a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/NestedValuesConversionTest.java
+++ /dev/null
@@ -1,130 +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.conversion.values;
-
-import java.util.Arrays;
-import java.util.List;
-import org.junit.Test;
-import org.apache.zest.api.entity.EntityBuilder;
-import org.apache.zest.api.entity.EntityComposite;
-import org.apache.zest.api.property.Property;
-import org.apache.zest.api.unitofwork.UnitOfWork;
-import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException;
-import org.apache.zest.api.value.ValueBuilder;
-import org.apache.zest.api.value.ValueComposite;
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.ModuleAssembly;
-import org.apache.zest.test.AbstractZestTest;
-import org.apache.zest.test.EntityTestAssembler;
-
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertThat;
-
-public class NestedValuesConversionTest
- extends AbstractZestTest
-{
-
- @Override
- public void assemble( ModuleAssembly ma )
- throws AssemblyException
- {
- new EntityToValueAssembler().assemble( ma );
- new EntityTestAssembler().assemble( ma );
-
- ma.entities( FooEntity.class );
- ma.values( FooValue.class, BarValue.class );
- }
-
- @Test
- public void testNestedValuesConversion()
- throws UnitOfWorkCompletionException
- {
- UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
- try
- {
- FooEntity fooEntity = createFooEntity( uow, "Test nested values conversion" );
- EntityToValueService conversion = serviceFinder.findService( EntityToValueService.class ).get();
- FooValue fooValue = conversion.convert( FooValue.class, fooEntity );
- assertThat( fooValue.name().get(), equalTo( "Test nested values conversion" ) );
- assertThat( fooValue.bar().get().bazar().get(), equalTo( "single" ) );
- List<BarValue> barList = fooValue.barList().get();
- assertThat( barList.size(), equalTo( 3 ) );
- assertThat( barList.get( 0 ).bazar().get(), equalTo( "multi-one" ) );
- assertThat( barList.get( 1 ).bazar().get(), equalTo( "multi-two" ) );
- assertThat( barList.get( 2 ).bazar().get(), equalTo( "multi-three" ) );
- uow.complete();
- uow = null;
- }
- finally
- {
- if( uow != null )
- {
- uow.discard();
- }
- }
- }
-
- private FooEntity createFooEntity( UnitOfWork uow, String name )
- {
- EntityBuilder<FooEntity> builder = uow.newEntityBuilder( FooEntity.class );
- builder.instance().name().set( name );
- builder.instance().bar().set( createBarValue( "single" ) );
- List<BarValue> bars = Arrays.asList( createBarValue( "multi-one" ),
- createBarValue( "multi-two" ),
- createBarValue( "multi-three" ) );
- builder.instance().barList().set( bars );
- return builder.newInstance();
- }
-
- private BarValue createBarValue( String bazar )
- {
- ValueBuilder<BarValue> builder = valueBuilderFactory.newValueBuilder( BarValue.class );
- builder.prototype().bazar().set( bazar );
- return builder.newInstance();
- }
-
- public interface FooState
- {
-
- Property<String> name();
-
- Property<BarValue> bar();
-
- Property<List<BarValue>> barList();
- }
-
- public interface FooValue
- extends FooState, ValueComposite
- {
- }
-
- public interface FooEntity
- extends FooState, EntityComposite
- {
- }
-
- public interface BarValue
- extends ValueComposite
- {
-
- Property<String> bazar();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1ead1338/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/TestModel.java
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/TestModel.java b/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/TestModel.java
deleted file mode 100644
index 54fe910..0000000
--- a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/TestModel.java
+++ /dev/null
@@ -1,202 +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.conversion.values;
-
-import java.time.Duration;
-import java.time.Instant;
-import java.time.LocalDate;
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
-import java.util.List;
-import org.apache.zest.api.association.Association;
-import org.apache.zest.api.association.ManyAssociation;
-import org.apache.zest.api.common.Optional;
-import org.apache.zest.api.entity.EntityBuilder;
-import org.apache.zest.api.entity.EntityComposite;
-import org.apache.zest.api.injection.scope.This;
-import org.apache.zest.api.mixin.Mixins;
-import org.apache.zest.api.property.Property;
-import org.apache.zest.api.unitofwork.UnitOfWork;
-import org.apache.zest.api.value.ValueComposite;
-
-import static java.time.ZoneOffset.UTC;
-
-/**
- * Test Model.
- */
-final class TestModel
-{
- static PersonEntity createPerson( UnitOfWork uow, String firstName, String lastName, LocalDate birthDate )
- {
- EntityBuilder<PersonEntity> builder = uow.newEntityBuilder( PersonEntity.class, "id:" + firstName );
- PersonState state = builder.instanceFor( PersonState.class );
- state.firstName().set( firstName );
- state.lastName().set( lastName );
- state.dateOfBirth().set( birthDate );
- return builder.newInstance();
- }
-
- static LocalDate createBirthDate( int year, int month, int day )
- {
- return LocalDate.of( year, month, day);
- }
-
- // START SNIPPET: state
- public interface PersonState
- {
-
- Property<String> firstName();
-
- Property<String> lastName();
-
- Property<LocalDate> dateOfBirth();
-
- }
- // END SNIPPET: state
-
- // START SNIPPET: value
- public interface PersonValue
- extends PersonState, ValueComposite
- {
-
- @Optional
- Property<String> spouse();
-
- @Optional
- Property<List<String>> children();
-
- }
- // END SNIPPET: value
-
- // START SNIPPET: entity
- @Mixins( PersonMixin.class )
- public interface PersonEntity
- extends EntityComposite
- {
-
- String firstName();
-
- String lastName();
-
- Integer age();
-
- @Optional
- Association<PersonEntity> spouse();
-
- ManyAssociation<PersonEntity> children();
-
- }
- // END SNIPPET: entity
-
- // START SNIPPET: entity
- public static abstract class PersonMixin
- implements PersonEntity
- {
-
- @This
- private PersonState state;
- // END SNIPPET: entity
-
- @Override
- public String firstName()
- {
- return state.firstName().get();
- }
-
- @Override
- public String lastName()
- {
- return state.lastName().get();
- }
-
- @Override
- public Integer age()
- {
- Duration age = Duration.between( state.dateOfBirth().get(), Instant.now() );
- return (int) age.toDays()/365;
- }
-
- // START SNIPPET: entity
- }
- // END SNIPPET: entity
-
- // START SNIPPET: unqualified
- @Unqualified
- public interface PersonValue2
- extends ValueComposite
- {
-
- Property<String> firstName();
-
- Property<String> lastName();
-
- Property<LocalDate> dateOfBirth();
-
- @Optional
- Property<String> spouse();
-
- @Optional
- Property<List<String>> children();
-
- }
- // END SNIPPET: unqualified
-
- @Unqualified( true )
- public interface PersonValue3
- extends ValueComposite
- {
-
- Property<String> firstName();
-
- Property<String> lastName();
-
- Property<LocalDate> dateOfBirth();
-
- @Optional
- Property<String> spouse();
-
- @Optional
- Property<List<String>> children();
-
- }
-
- @Unqualified( false )
- public interface PersonValue4
- extends ValueComposite
- {
-
- Property<String> firstName();
-
- Property<String> lastName();
-
- Property<LocalDate> dateOfBirth();
-
- @Optional
- Property<String> spouse();
-
- @Optional
- Property<List<String>> children();
-
- }
-
- private TestModel()
- {
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1ead1338/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/ValueToEntityTest.java
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/ValueToEntityTest.java b/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/ValueToEntityTest.java
deleted file mode 100644
index c0f8eea..0000000
--- a/libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/ValueToEntityTest.java
+++ /dev/null
@@ -1,355 +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.conversion.values;
-
-import java.time.LocalDate;
-import java.util.Arrays;
-import java.util.function.Predicate;
-import org.junit.Before;
-import org.junit.Test;
-import org.apache.zest.api.constraint.ConstraintViolationException;
-import org.apache.zest.api.unitofwork.UnitOfWork;
-import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException;
-import org.apache.zest.api.value.ValueBuilder;
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.ModuleAssembly;
-import org.apache.zest.functional.Iterables;
-import org.apache.zest.library.conversion.values.TestModel.PersonEntity;
-import org.apache.zest.library.conversion.values.TestModel.PersonValue;
-import org.apache.zest.library.conversion.values.TestModel.PersonValue2;
-import org.apache.zest.library.conversion.values.TestModel.PersonValue3;
-import org.apache.zest.library.conversion.values.TestModel.PersonValue4;
-import org.apache.zest.test.AbstractZestTest;
-import org.apache.zest.test.EntityTestAssembler;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertThat;
-import static org.apache.zest.api.usecase.UsecaseBuilder.newUsecase;
-import static org.apache.zest.library.conversion.values.TestModel.createBirthDate;
-import static org.apache.zest.library.conversion.values.TestModel.createPerson;
-
-/**
- * ValueToEntity Service Test.
- */
-public class ValueToEntityTest
- extends AbstractZestTest
-{
- @Override
- public void assemble( ModuleAssembly module )
- throws AssemblyException
- {
- // START SNIPPET: assembly
- new ValueToEntityAssembler().assemble( module );
- // END SNIPPET: assembly
- new EntityTestAssembler().assemble( module );
- module.entities( PersonEntity.class );
- module.values( PersonValue.class );
- module.values( PersonValue2.class );
- module.values( PersonValue3.class );
- module.values( PersonValue4.class );
- }
-
- private LocalDate someBirthDate;
- private String ednaIdentity;
- private String zekeIdentity;
- private String fredIdentity;
-
- @Before
- public void setupInitialData()
- throws UnitOfWorkCompletionException
- {
- // See http://en.wikipedia.org/wiki/Template:Flintstones_family_tree
- someBirthDate = createBirthDate( 1, 1, 1 );
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "InitialData" ) ) )
- {
- ednaIdentity = createPerson( uow, "Edna", "Flintstone", someBirthDate ).identity().get();
- zekeIdentity = createPerson( uow, "Zeke", "Flintstone", someBirthDate ).identity().get();
- fredIdentity = createPerson( uow, "Fred", "Flintstone", someBirthDate ).identity().get();
- uow.complete();
- }
- }
-
- @Test
- public void givenQualifiedValueWhenCreatingEntityExpectCorrectEntity()
- throws UnitOfWorkCompletionException
- {
- ValueBuilder<PersonValue> builder = valueBuilderFactory.newValueBuilder( PersonValue.class );
- builder.prototype().firstName().set( "Ed" );
- builder.prototype().lastName().set( "Flintstone" );
- builder.prototype().dateOfBirth().set( someBirthDate );
- builder.prototype().spouse().set( ednaIdentity );
- builder.prototype().children().set( Arrays.asList( zekeIdentity, fredIdentity ) );
- PersonValue edValue = builder.newInstance();
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "CreatingEntityFromQualifiedValue" ) ) )
- {
- // START SNIPPET: creation
- ValueToEntity conversion = serviceFinder.findService( ValueToEntity.class ).get();
- PersonEntity edEntity = conversion.create( PersonEntity.class, edValue );
- // END SNIPPET: creation
- assertThat( edEntity.firstName(), equalTo( "Ed" ) );
- assertThat( edEntity.lastName(), equalTo( "Flintstone" ) );
- assertThat( edEntity.spouse().get().firstName(), equalTo( "Edna" ) );
- assertThat( Iterables.count( Iterables.filter( new Predicate<PersonEntity>()
- {
- @Override
- public boolean test( PersonEntity child )
- {
- return "Zeke".equals( child.firstName() ) || "Fred".equals( child.firstName() );
- }
- }, edEntity.children() ) ), is( 2L ) );
-
- uow.complete();
- }
- }
-
- @Test
- public void givenUnqualifiedValueWhenCreatingEntityExpectCorrectEntity()
- throws UnitOfWorkCompletionException
- {
- ValueBuilder<PersonValue2> builder = valueBuilderFactory.newValueBuilder( PersonValue2.class );
- builder.prototype().firstName().set( "Ed" );
- builder.prototype().lastName().set( "Flintstone" );
- builder.prototype().dateOfBirth().set( someBirthDate );
- builder.prototype().spouse().set( ednaIdentity );
- builder.prototype().children().set( Arrays.asList( zekeIdentity, fredIdentity ) );
- PersonValue2 edValue = builder.newInstance();
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "CreatingEntityFromUnqualifiedValue" ) ) )
- {
- ValueToEntity conversion = serviceFinder.findService( ValueToEntity.class ).get();
-
- PersonEntity edEntity = conversion.create( PersonEntity.class, "id:Ed", edValue );
-
- assertThat( edEntity.identity().get(), equalTo( "id:Ed" ) );
- assertThat( edEntity.firstName(), equalTo( "Ed" ) );
- assertThat( edEntity.lastName(), equalTo( "Flintstone" ) );
- assertThat( edEntity.spouse().get().firstName(), equalTo( "Edna" ) );
- assertThat( Iterables.count( Iterables.filter( new Predicate<PersonEntity>()
- {
- @Override
- public boolean test( PersonEntity child )
- {
- return "Zeke".equals( child.firstName() ) || "Fred".equals( child.firstName() );
- }
- }, edEntity.children() ) ), is( 2L ) );
-
- uow.complete();
- }
- }
-
- @Test
- public void givenUnqualifiedValue2WhenCreatingEntityExpectCorrectEntity()
- throws UnitOfWorkCompletionException
- {
- ValueBuilder<PersonValue3> builder = valueBuilderFactory.newValueBuilder( PersonValue3.class );
- builder.prototype().firstName().set( "Ed" );
- builder.prototype().lastName().set( "Flintstone" );
- builder.prototype().dateOfBirth().set( someBirthDate );
- builder.prototype().spouse().set( ednaIdentity );
- builder.prototype().children().set( Arrays.asList( zekeIdentity, fredIdentity ) );
- PersonValue3 edValue = builder.newInstance();
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "CreatingEntityFromUnqualifiedValue" ) ) )
- {
- ValueToEntity conversion = serviceFinder.findService( ValueToEntity.class ).get();
-
- PersonEntity edEntity = conversion.create( PersonEntity.class, "id:Ed", edValue );
-
- assertThat( edEntity.identity().get(), equalTo( "id:Ed" ) );
- assertThat( edEntity.firstName(), equalTo( "Ed" ) );
- assertThat( edEntity.lastName(), equalTo( "Flintstone" ) );
- assertThat( edEntity.spouse().get().firstName(), equalTo( "Edna" ) );
- assertThat( Iterables.count( Iterables.filter( new Predicate<PersonEntity>()
- {
- @Override
- public boolean test( PersonEntity child )
- {
- return "Zeke".equals( child.firstName() ) || "Fred".equals( child.firstName() );
- }
- }, edEntity.children() ) ), is( 2L ) );
-
- uow.complete();
- }
- }
-
- @Test( expected = ConstraintViolationException.class )
- public void givenQualifiedValueNotFromSameInterfaceWhenCreatingEntityExpectNonOptionalException()
- throws UnitOfWorkCompletionException
- {
- ValueBuilder<PersonValue4> builder = valueBuilderFactory.newValueBuilder( PersonValue4.class );
- builder.prototype().firstName().set( "Ed" );
- builder.prototype().lastName().set( "Flintstone" );
- builder.prototype().dateOfBirth().set( someBirthDate );
- builder.prototype().spouse().set( ednaIdentity );
- builder.prototype().children().set( Arrays.asList( zekeIdentity, fredIdentity ) );
- PersonValue4 edValue = builder.newInstance();
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "CreatingEntityFromUnqualifiedValue" ) ) )
- {
- ValueToEntity conversion = serviceFinder.findService( ValueToEntity.class ).get();
-
- PersonEntity edEntity = conversion.create( PersonEntity.class, "id:Ed", edValue );
-
- uow.complete();
- }
-
- }
-
- @Test
- public void givenQualifiedValueWhenUpdatingEntityExpectCorrectEntity()
- throws UnitOfWorkCompletionException
- {
- String rickyIdentity;
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "CreateRickySlaghoopleWithTypo" ) ) )
- {
- PersonEntity ricky = createPerson( uow, "Ricky", "Slaghople", someBirthDate );
- ricky.spouse().set( uow.get( PersonEntity.class, ednaIdentity ) );
- ricky.children().add( uow.get( PersonEntity.class, zekeIdentity ) );
- rickyIdentity = ricky.identity().get();
- assertThat( ricky.spouse().get(), notNullValue() );
- assertThat( ricky.children().count(), is( 1 ) );
- uow.complete();
- }
- ValueBuilder<PersonValue> builder = valueBuilderFactory.newValueBuilder( PersonValue.class );
- builder.prototype().firstName().set( "Ricky" );
- builder.prototype().lastName().set( "Slaghoople" );
- builder.prototype().dateOfBirth().set( someBirthDate );
- PersonValue rickyNewStateValue = builder.newInstance();
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "UpdateRickySlaghoople" ) ) )
- {
- PersonEntity rickyEntity = uow.get( PersonEntity.class, rickyIdentity );
- // START SNIPPET: update
- ValueToEntity conversion = serviceFinder.findService( ValueToEntity.class ).get();
- conversion.update( rickyEntity, rickyNewStateValue );
- // END SNIPPET: update
-
- assertThat( rickyEntity.lastName(), equalTo( "Slaghoople" ) );
- assertThat( rickyEntity.spouse().get(), nullValue() );
- assertThat( rickyEntity.children().count(), is( 0 ) );
-
- uow.complete();
- }
- }
-
- @Test
- public void givenUnqualifiedValueWhenUpdatingEntityExpectCorrectEntity()
- throws UnitOfWorkCompletionException
- {
- String rickyIdentity;
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "CreateRickySlaghoopleWithTypo" ) ) )
- {
- PersonEntity ricky = createPerson( uow, "Ricky", "Slaghople", someBirthDate );
- ricky.spouse().set( uow.get( PersonEntity.class, ednaIdentity ) );
- ricky.children().add( uow.get( PersonEntity.class, zekeIdentity ) );
- rickyIdentity = ricky.identity().get();
- assertThat( ricky.spouse().get(), notNullValue() );
- assertThat( ricky.children().count(), is( 1 ) );
- uow.complete();
- }
- ValueBuilder<PersonValue2> builder = valueBuilderFactory.newValueBuilder( PersonValue2.class );
- builder.prototype().firstName().set( "Ricky" );
- builder.prototype().lastName().set( "Slaghoople" );
- builder.prototype().dateOfBirth().set( someBirthDate );
- PersonValue2 newStateValue = builder.newInstance();
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "UpdateRickySlaghoople" ) ) )
- {
- PersonEntity ricky = uow.get( PersonEntity.class, rickyIdentity );
-
- ValueToEntity conversion = serviceFinder.findService( ValueToEntity.class ).get();
- conversion.update( ricky, newStateValue );
-
- assertThat( ricky.lastName(), equalTo( "Slaghoople" ) );
- assertThat( ricky.spouse().get(), nullValue() );
- assertThat( ricky.children().count(), is( 0 ) );
-
- uow.complete();
- }
- }
-
- @Test
- public void givenUnqualifiedValue2WhenUpdatingEntityExpectCorrectEntity()
- throws UnitOfWorkCompletionException
- {
- String rickyIdentity;
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "CreateRickySlaghoopleWithTypo" ) ) )
- {
- PersonEntity ricky = createPerson( uow, "Ricky", "Slaghople", someBirthDate );
- ricky.spouse().set( uow.get( PersonEntity.class, ednaIdentity ) );
- ricky.children().add( uow.get( PersonEntity.class, zekeIdentity ) );
- rickyIdentity = ricky.identity().get();
- assertThat( ricky.spouse().get(), notNullValue() );
- assertThat( ricky.children().count(), is( 1 ) );
- uow.complete();
- }
- ValueBuilder<PersonValue3> builder = valueBuilderFactory.newValueBuilder( PersonValue3.class );
- builder.prototype().firstName().set( "Ricky" );
- builder.prototype().lastName().set( "Slaghoople" );
- builder.prototype().dateOfBirth().set( someBirthDate );
- PersonValue3 newStateValue = builder.newInstance();
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "UpdateRickySlaghoople" ) ) )
- {
- PersonEntity ricky = uow.get( PersonEntity.class, rickyIdentity );
-
- ValueToEntity conversion = serviceFinder.findService( ValueToEntity.class ).get();
- conversion.update( ricky, newStateValue );
-
- assertThat( ricky.lastName(), equalTo( "Slaghoople" ) );
- assertThat( ricky.spouse().get(), nullValue() );
- assertThat( ricky.children().count(), is( 0 ) );
-
- uow.complete();
- }
- }
-
- @Test
- public void givenQualifiedValueNotFromSameInterfaceWhenUpdatingEntityExpectPropsNotUpdated()
- throws UnitOfWorkCompletionException
- {
- String rickyIdentity;
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "CreateRickySlaghoopleWithTypo" ) ) )
- {
- PersonEntity ricky = createPerson( uow, "Ricky", "Slaghople", someBirthDate );
- ricky.spouse().set( uow.get( PersonEntity.class, ednaIdentity ) );
- ricky.children().add( uow.get( PersonEntity.class, zekeIdentity ) );
- rickyIdentity = ricky.identity().get();
- assertThat( ricky.spouse().get(), notNullValue() );
- assertThat( ricky.children().count(), is( 1 ) );
- uow.complete();
- }
- ValueBuilder<PersonValue4> builder = valueBuilderFactory.newValueBuilder( PersonValue4.class );
- builder.prototype().firstName().set( "Ricky" );
- builder.prototype().lastName().set( "Slaghoople" );
- builder.prototype().dateOfBirth().set( someBirthDate );
- PersonValue4 newStateValue = builder.newInstance();
- try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( newUsecase( "UpdateRickySlaghoopleWontWork" ) ) )
- {
- PersonEntity ricky = uow.get( PersonEntity.class, rickyIdentity );
-
- ValueToEntity conversion = serviceFinder.findService( ValueToEntity.class ).get();
- conversion.update( ricky, newStateValue );
-
- assertThat( ricky.lastName(), equalTo( "Slaghople" ) );
- assertThat( ricky.spouse().get(), nullValue() );
- assertThat( ricky.children().count(), is( 0 ) );
-
- uow.complete();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1ead1338/settings.gradle
----------------------------------------------------------------------
diff --git a/settings.gradle b/settings.gradle
index 16a0615..058f616 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -28,7 +28,6 @@ include 'core:functional',
'libraries:alarm',
'libraries:circuitbreaker',
'libraries:constraints',
- 'libraries:conversion',
'libraries:eventsourcing',
'libraries:eventsourcing-jdbm',
'libraries:eventsourcing-rest',
[2/2] zest-java git commit: ZEST-151 : Removed Conversion Library
Posted by ni...@apache.org.
ZEST-151 : Removed Conversion Library
Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/1ead1338
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/1ead1338
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/1ead1338
Branch: refs/heads/develop
Commit: 1ead13389f098d8bb68efd336b0ecabcc1358310
Parents: 5294486
Author: Niclas Hedhman <ni...@hedhman.org>
Authored: Sun Jun 12 16:56:17 2016 +0800
Committer: Niclas Hedhman <ni...@hedhman.org>
Committed: Sun Jun 12 16:56:17 2016 +0800
----------------------------------------------------------------------
libraries/conversion/build.gradle | 32 -
libraries/conversion/dev-status.xml | 38 -
libraries/conversion/src/docs/conversion.txt | 129 ----
.../conversion/values/EntityToValue.java | 463 ------------
.../values/EntityToValueAssembler.java | 45 --
.../conversion/values/EntityToValueService.java | 55 --
.../values/PropertyNotPresentException.java | 46 --
.../zest/library/conversion/values/Shared.java | 71 --
.../library/conversion/values/Unqualified.java | 35 -
.../conversion/values/ValueToEntity.java | 137 ----
.../values/ValueToEntityAssembler.java | 45 --
.../conversion/values/ValueToEntityMixin.java | 730 -------------------
.../conversion/values/ValueToEntityService.java | 33 -
.../zest/library/conversion/values/package.html | 24 -
.../conversion/values/EntityToValueTest.java | 232 ------
.../values/NestedValuesConversionTest.java | 130 ----
.../library/conversion/values/TestModel.java | 202 -----
.../conversion/values/ValueToEntityTest.java | 355 ---------
settings.gradle | 1 -
19 files changed, 2803 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1ead1338/libraries/conversion/build.gradle
----------------------------------------------------------------------
diff --git a/libraries/conversion/build.gradle b/libraries/conversion/build.gradle
deleted file mode 100644
index 7443b58..0000000
--- a/libraries/conversion/build.gradle
+++ /dev/null
@@ -1,32 +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.
- *
- *
- */
-
-description = "Apache Zest\u2122 Conversion Library has various generic services to manipulate Apache Zest\u2122 ValueComposites, such as converting an Entity to a Value."
-
-jar { manifest { name = "Apache Zest\u2122 Library - Conversion" }}
-
-dependencies {
- compile(project(":org.apache.zest.core:org.apache.zest.core.bootstrap"))
-
- testCompile(project(":org.apache.zest.core:org.apache.zest.core.testsupport"))
-
- testRuntime(project(":org.apache.zest.core:org.apache.zest.core.runtime"))
- testRuntime(libraries.logback)
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1ead1338/libraries/conversion/dev-status.xml
----------------------------------------------------------------------
diff --git a/libraries/conversion/dev-status.xml b/libraries/conversion/dev-status.xml
deleted file mode 100644
index 5b78a6d..0000000
--- a/libraries/conversion/dev-status.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!--
- ~ 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.
- ~
- ~
- -->
-<module xmlns="http://zest.apache.org/schemas/2008/dev-status/1"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://zest.apache.org/schemas/2008/dev-status/1
- http://zest.apache.org/schemas/2008/dev-status/1/dev-status.xsd">
- <status>
- <!--none,early,beta,stable,mature-->
- <codebase>stable</codebase>
-
- <!-- none, brief, good, complete -->
- <documentation>brief</documentation>
-
- <!-- none, some, good, complete -->
- <unittests>some</unittests>
- </status>
- <licenses>
- <license>ALv2</license>
- </licenses>
-</module>
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1ead1338/libraries/conversion/src/docs/conversion.txt
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/docs/conversion.txt b/libraries/conversion/src/docs/conversion.txt
deleted file mode 100644
index a8eb3cf..0000000
--- a/libraries/conversion/src/docs/conversion.txt
+++ /dev/null
@@ -1,129 +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.
-///////////////////////////////////////////////////////////////
-
-[[library-conversion, Conversion Library]]
-= Conversion - DEPRECATED =
-
-[devstatus]
---------------
-source=libraries/conversion/dev-status.xml
---------------
-
-The Conversion Library provides support for converting composite types.
-
-include::../../build/docs/buildinfo/artifact.txt[]
-
-
-[WARNING]
-.DEPRECATED
-====
-This functionality is now present in <<def-unitofwork>> as
-the two methods toEntity() and toValue(). Since this library was written
-assocations of all kinds are now fully supported in Values.
-====
-
-
-== Entities to Values ==
-
-To convert Entities to Values, use the EntityToValueService. It is easily assembled:
-
-[snippet,java]
-----
-source=libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/EntityToValueTest.java
-tag=assembly
-----
-
-Let's say we have an interface defining state:
-
-[snippet,java]
-----
-source=libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/TestModel.java
-tag=state
-----
-
-An EntityComposite using the state as a Private Mixin:
-
-[snippet,java]
-----
-source=libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/TestModel.java
-tag=entity
-----
-
-And a ValueComposite extending this very same state;
-
-[snippet,java]
-----
-source=libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/TestModel.java
-tag=value
-----
-
-Here is how to convert an EntityComposite to a ValueComposite:
-
-[snippet,java]
-----
-source=libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/EntityToValueTest.java
-tag=conversion
-----
-
-
-== Values to Entities ==
-
-Using the ValueToEntity service one can create new Entities or update existing ones from Values.
-It is easy assembled:
-
-[snippet,java]
-----
-source=libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/ValueToEntityTest.java
-tag=assembly
-----
-
-Let's say we have the exact same model as described above.
-
-Here is how to create an EntityComposite from a ValueComposite:
-
-[snippet,java]
-----
-source=libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/ValueToEntityTest.java
-tag=creation
-----
-
-Here is how to update an EntityComposite from a ValueComposite:
-
-[snippet,java]
-----
-source=libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/ValueToEntityTest.java
-tag=update
-----
-
-
-== Associations are converted to Identity strings ==
-
-If your Entities and Values cannot use the same state type, you can annotate the Value that is the target of the
-conversion with the `@Unqualified` annotation. Then, the lookup of the Value Property will be performed using the
-*unqualified* name only, and not via the default of the full qualified name. In other words, this means that the
-Property may be declared in the different interfaces and still be matched.
-
-Here is an example:
-
-[snippet,java]
-----
-source=libraries/conversion/src/test/java/org/apache/zest/library/conversion/values/TestModel.java
-tag=unqualified
-----
-
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1ead1338/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/EntityToValue.java
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/EntityToValue.java b/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/EntityToValue.java
deleted file mode 100644
index bdddaa4..0000000
--- a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/EntityToValue.java
+++ /dev/null
@@ -1,463 +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.conversion.values;
-
-import java.lang.reflect.AccessibleObject;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import org.apache.zest.api.association.Association;
-import org.apache.zest.api.association.AssociationDescriptor;
-import org.apache.zest.api.association.AssociationStateDescriptor;
-import org.apache.zest.api.association.AssociationStateHolder;
-import org.apache.zest.api.association.ManyAssociation;
-import org.apache.zest.api.association.NamedAssociation;
-import org.apache.zest.api.entity.EntityComposite;
-import org.apache.zest.api.entity.EntityDescriptor;
-import org.apache.zest.api.entity.EntityReference;
-import org.apache.zest.api.entity.Identity;
-import org.apache.zest.api.injection.scope.Structure;
-import org.apache.zest.api.mixin.Mixins;
-import org.apache.zest.api.property.PropertyDescriptor;
-import org.apache.zest.api.structure.Module;
-import org.apache.zest.api.value.NoSuchValueException;
-import org.apache.zest.api.value.ValueBuilder;
-import org.apache.zest.api.value.ValueDescriptor;
-import org.apache.zest.functional.Iterables;
-import org.apache.zest.spi.ZestSPI;
-
-import static org.apache.zest.library.conversion.values.Shared.STRING_COLLECTION_TYPE_SPEC;
-import static org.apache.zest.library.conversion.values.Shared.STRING_MAP_TYPE_SPEC;
-import static org.apache.zest.library.conversion.values.Shared.STRING_TYPE_SPEC;
-
-/**
- * @deprecated Please use {@link org.apache.zest.api.unitofwork.UnitOfWork#toValue(Class, Identity)} instead.
- */
-@Mixins( EntityToValue.EntityToValueMixin.class )
-public interface EntityToValue
-{
- /**
- * Convert an entity to a value.
- *
- * @param <T> parametrized type of the value
- * @param valueType type of the value
- * @param entity the entity to convert to a value
- * @return the resulting value
- */
- <T> T convert( Class<T> valueType, Object entity );
-
- /**
- * Convert an entity to a value with an opportunity to customize its prototype.
- *
- * @param <T> parametrized type of the value
- * @param valueType type of the value
- * @param entity the entity to convert to a value
- * @param prototypeOpportunity a Function that will be mapped on the value prototype before instanciantion
- * @return the resulting value
- */
- <T> T convert( Class<T> valueType, Object entity, Function<T, T> prototypeOpportunity );
-
- /**
- * Convert an iterable of entities to an iterable of values.
- *
- * @param <T> parametrized type of the value
- * @param valueType type of the value
- * @param entities the entities to convert to values
- * @return the resulting values
- */
- <T> Iterable<T> convert( Class<T> valueType, Iterable<Object> entities );
-
- /**
- * Convert an iterable of entities to an iterable of values with an opportunity to customize their prototypes.
- *
- * @param <T> parametrized type of the value
- * @param valueType type of the value
- * @param entities the entities to convert to values
- * @param prototypeOpportunity a Function that will be mapped on each of the value prototypes before instanciation.
- * @return the resulting values
- */
- <T> Iterable<T> convert( Class<T> valueType, Iterable<Object> entities, Function<T, T> prototypeOpportunity );
-
- static class EntityToValueMixin
- implements EntityToValue
- {
-
- @Structure
- private ZestSPI spi;
- @Structure
- private Module module;
-
- @Override
- public <T> T convert( final Class<T> valueType, Object entity )
- {
- return createInstance( doConversion( valueType, entity ) );
- }
-
- @Override
- @SuppressWarnings( "unchecked" )
- public <T> T convert( final Class<T> valueType, Object entity, Function<T, T> prototypeOpportunity )
- {
- ValueBuilder<?> builder = doConversion( valueType, entity );
- prototypeOpportunity.apply( (T) builder.prototype() );
- return createInstance( builder );
- }
-
- @Override
- public <T> Iterable<T> convert( final Class<T> valueType, Iterable<Object> entities )
- {
- return Iterables.map(
- new Function<Object, T>()
- {
- @Override
- public T apply( Object entity )
- {
- return convert( valueType, entity );
- }
- }, entities );
- }
-
- @Override
- public <T> Iterable<T> convert( final Class<T> valueType, Iterable<Object> entities, final Function<T, T> prototypeOpportunity )
- {
- return Iterables.map(
- new Function<Object, T>()
- {
- @Override
- public T apply( Object entity )
- {
- return convert( valueType, entity, prototypeOpportunity );
- }
- }, entities );
- }
-
- private <T> ValueBuilder<?> doConversion( final Class<T> valueType, Object entity )
- {
- ValueDescriptor valueDescriptor = module.descriptor().valueDescriptor( valueType.getName() );
- if( valueDescriptor == null )
- {
- throw new NoSuchValueException( valueType.getName(), module.name(), module.typeLookup() );
- }
- Unqualified unqualified = valueDescriptor.metaInfo( Unqualified.class );
-// Iterable<? extends PropertyDescriptor> properties = valueDescriptor.state().properties();
- final EntityComposite composite = (EntityComposite) entity;
- final EntityDescriptor entityDescriptor = spi.entityDescriptorFor( composite );
- final AssociationStateHolder associationState = spi.stateOf( composite );
- ValueBuilder<?> builder;
-
- if( unqualified == null || !unqualified.value() )
- {
- // Copy state using qualified names
- builder = module.newValueBuilderWithState(
- valueType,
- new Function<PropertyDescriptor, Object>()
- {
- @Override
- public Object apply( PropertyDescriptor descriptor )
- {
- try
- {
- return associationState.propertyFor( descriptor.accessor() ).get();
- }
- catch( IllegalArgumentException e )
- {
- AssociationStateDescriptor entityState = entityDescriptor.state();
- String associationName = descriptor.qualifiedName().name();
- if( STRING_TYPE_SPEC.test( descriptor.valueType() ) )
- {
- // Find Association and convert to string
- AssociationDescriptor associationDescriptor;
- try
- {
- associationDescriptor = entityState.getAssociationByName( associationName );
- }
- catch( IllegalArgumentException e1 )
- {
- return null;
- }
- AccessibleObject associationMethod = associationDescriptor.accessor();
- Object entity = associationState.associationFor( associationMethod ).get();
- if( entity != null )
- {
- return ( (Identity) entity ).identity().get();
- }
- else
- {
- return null;
- }
- }
- else if( STRING_COLLECTION_TYPE_SPEC.test( descriptor.valueType() ) )
- {
- AssociationDescriptor associationDescriptor;
- try
- {
- associationDescriptor = entityState.getManyAssociationByName( associationName );
- }
- catch( IllegalArgumentException e1 )
- {
- return Collections.emptyList();
- }
-
- ManyAssociation<?> state = associationState.manyAssociationFor( associationDescriptor.accessor() );
- List<String> entities = new ArrayList<>( state.count() );
- for( Object entity : state )
- {
- entities.add( ( (Identity) entity ).identity().get() );
- }
- return entities;
- }
- else if( STRING_MAP_TYPE_SPEC.test( descriptor.valueType() ) )
- {
- AssociationDescriptor associationDescriptor;
- try
- {
- associationDescriptor = entityState.getNamedAssociationByName( associationName );
- }
- catch( IllegalArgumentException e1 )
- {
- return Collections.emptyMap();
- }
-
- NamedAssociation<?> state = associationState.namedAssociationFor( associationDescriptor.accessor() );
- Map<String, String> entities = new LinkedHashMap<>( state.count() );
- for( String name : state )
- {
- entities.put( name, ( (Identity) state.get( name ) ).identity().get() );
- }
- return entities;
- }
-
- return null;
- }
- }
- },
- new Function<AssociationDescriptor, EntityReference>()
- {
- @Override
- public EntityReference apply( AssociationDescriptor associationDescriptor )
- {
- return EntityReference.entityReferenceFor(
- associationState.associationFor( associationDescriptor.accessor() ).get() );
- }
- },
- new Function<AssociationDescriptor, Iterable<EntityReference>>()
- {
- @Override
- public Iterable<EntityReference> apply( AssociationDescriptor associationDescriptor )
- {
- ManyAssociation<?> state = associationState.manyAssociationFor( associationDescriptor.accessor() );
- List<EntityReference> refs = new ArrayList<>( state.count() );
- for( Object entity : state )
- {
- refs.add( EntityReference.entityReferenceFor( entity ) );
- }
- return refs;
- }
- },
- new Function<AssociationDescriptor, Map<String, EntityReference>>()
- {
- @Override
- public Map<String, EntityReference> apply( AssociationDescriptor associationDescriptor )
- {
- NamedAssociation<?> assoc = associationState.namedAssociationFor( associationDescriptor.accessor() );
- Map<String, EntityReference> refs = new LinkedHashMap<>( assoc.count() );
- for( String name : assoc )
- {
- refs.put( name, EntityReference.entityReferenceFor( assoc.get( name ) ) );
- }
- return refs;
- }
- } );
- }
- else
- {
- builder = module.newValueBuilderWithState(valueType,
- new Function<PropertyDescriptor, Object>()
- {
- @Override
- public Object apply( final PropertyDescriptor descriptor )
- {
- AssociationStateDescriptor entityState = entityDescriptor.state();
- String propertyName = descriptor.qualifiedName().name();
- try
- {
- PropertyDescriptor propertyDescriptor = entityState.findPropertyModelByName( propertyName );
- return associationState.propertyFor( propertyDescriptor.accessor() ).get();
- }
- catch( IllegalArgumentException e )
- {
- if( STRING_TYPE_SPEC.test( descriptor.valueType() ) )
- {
- // Find Association and convert to string
- AssociationDescriptor associationDescriptor;
- try
- {
- associationDescriptor = entityState.getAssociationByName( propertyName );
- }
- catch( IllegalArgumentException e1 )
- {
- return null;
- }
-
- AccessibleObject associationMethod = associationDescriptor.accessor();
- Object entity = associationState.associationFor( associationMethod ).get();
- if( entity != null )
- {
- return ( (Identity) entity ).identity().get();
- }
- else
- {
- return null;
- }
- }
- else if( STRING_COLLECTION_TYPE_SPEC.test( descriptor.valueType() ) )
- {
- AssociationDescriptor associationDescriptor;
- try
- {
- associationDescriptor = entityState.getManyAssociationByName( propertyName );
- }
- catch( IllegalArgumentException e1 )
- {
- return null;
- }
-
- AccessibleObject associationMethod = associationDescriptor.accessor();
- ManyAssociation<?> state = associationState.manyAssociationFor( associationMethod );
- List<String> entities = new ArrayList<>( state.count() );
- for( Object entity : state )
- {
- entities.add( ( (Identity) entity ).identity().get() );
- }
- return entities;
- }
- else if( STRING_MAP_TYPE_SPEC.test( descriptor.valueType() ) )
- {
- AssociationDescriptor associationDescriptor;
- try
- {
- associationDescriptor = entityState.getNamedAssociationByName( propertyName );
- }
- catch( IllegalArgumentException e1 )
- {
- return null;
- }
-
- AccessibleObject associationMethod = associationDescriptor.accessor();
- NamedAssociation<?> state = associationState.namedAssociationFor( associationMethod );
- Map<String, String> entities = new LinkedHashMap<>( state.count() );
- for( String name : state )
- {
- entities.put( name, ( (Identity) state.get( name ) ).identity().get() );
- }
- return entities;
- }
- return null;
- }
- }
- },
- new Function<AssociationDescriptor, EntityReference>()
- {
- @Override
- public EntityReference apply( AssociationDescriptor descriptor )
- {
- AssociationDescriptor associationDescriptor;
- try
- {
- associationDescriptor = entityDescriptor.state()
- .getAssociationByName( descriptor.qualifiedName().name() );
- }
- catch( IllegalArgumentException e )
- {
- return null;
- }
-
- AccessibleObject associationMethod = associationDescriptor.accessor();
- Association<Object> association = associationState.associationFor( associationMethod );
- return EntityReference.entityReferenceFor( association.get() );
- }
- },
- new Function<AssociationDescriptor, Iterable<EntityReference>>()
- {
- @Override
- public Iterable<EntityReference> apply( final AssociationDescriptor descriptor )
- {
- AssociationDescriptor associationDescriptor;
- try
- {
- String associationName = descriptor.qualifiedName().name();
- AssociationStateDescriptor entityState = entityDescriptor.state();
- associationDescriptor = entityState.getManyAssociationByName( associationName );
- }
- catch( IllegalArgumentException e )
- {
- return Iterables.empty();
- }
-
- ManyAssociation<?> state = associationState.manyAssociationFor( associationDescriptor.accessor() );
- List<EntityReference> refs = new ArrayList<>( state.count() );
- for( Object entity : state )
- {
- refs.add( EntityReference.entityReferenceFor( entity ) );
- }
- return refs;
- }
- },
- new Function<AssociationDescriptor, Map<String, EntityReference>>()
- {
- @Override
- public Map<String, EntityReference> apply( AssociationDescriptor descriptor )
- {
- AssociationDescriptor associationDescriptor;
- try
- {
- String associationName = descriptor.qualifiedName().name();
- AssociationStateDescriptor entityState = entityDescriptor.state();
- associationDescriptor = entityState.getNamedAssociationByName( associationName );
- }
- catch( IllegalArgumentException e )
- {
- return Collections.emptyMap();
- }
- AccessibleObject associationMethod = associationDescriptor.accessor();
- NamedAssociation<Object> assoc = associationState.namedAssociationFor( associationMethod );
- Map<String, EntityReference> refs = new LinkedHashMap<>( assoc.count() );
- for( String name : assoc )
- {
- refs.put( name, EntityReference.entityReferenceFor( assoc.get( name ) ) );
- }
- return refs;
- }
- } );
- }
- return builder;
- }
-
- @SuppressWarnings( "unchecked" )
- private <T> T createInstance( ValueBuilder<?> builder )
- {
- return (T) builder.newInstance();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1ead1338/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/EntityToValueAssembler.java
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/EntityToValueAssembler.java b/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/EntityToValueAssembler.java
deleted file mode 100644
index 3f071cb..0000000
--- a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/EntityToValueAssembler.java
+++ /dev/null
@@ -1,45 +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.conversion.values;
-
-import org.apache.zest.api.entity.Identity;
-import org.apache.zest.bootstrap.Assemblers;
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.ModuleAssembly;
-import org.apache.zest.bootstrap.ServiceDeclaration;
-
-/**
- * EntityToValue Service Assembler.
- * @deprecated Please use {@link org.apache.zest.api.unitofwork.UnitOfWork#toValue(Class, Identity)} instead.
- */
-public class EntityToValueAssembler
- extends Assemblers.VisibilityIdentity<EntityToValueAssembler>
-{
- @Override
- public void assemble( ModuleAssembly module )
- throws AssemblyException
- {
- ServiceDeclaration service = module.services( EntityToValueService.class ).visibleIn( visibility() );
- if( hasIdentity() )
- {
- service.identifiedBy( identity() );
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1ead1338/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/EntityToValueService.java
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/EntityToValueService.java b/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/EntityToValueService.java
deleted file mode 100644
index 8bdaa01..0000000
--- a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/EntityToValueService.java
+++ /dev/null
@@ -1,55 +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.conversion.values;
-
-import org.apache.zest.api.entity.Identity;
-import org.apache.zest.api.service.ServiceComposite;
-
-/** The EntityToValueService converts Entities to matching Values.
- * <p>
- * The main purpose of this service is to provide convenience to map entities to serializable values, for instance
- * to be transported across a network. The ValueComposite to convert the Entity to must closely match the Entity
- * for this mapping to work. The rules are fairly straight forward;
- * </p>
- * <ol>
- * <li>Any Property in the EntityComposite to be mapped, must (by default) exist in the ValueComposite with the same
- * fully qualified name, i.e. method declared in the same interface. If the ValueComposite is annotated with
- * @Unqualified then the Property method look up will only locate the properties with the name only,
- * i.e. the methods may defined in different interfaces.</li>
- * <li>For any Association in the EntityComposite, a Property<String> with the same <strong>unqualified</strong>
- * name will be looked up in the ValueComposite. If found, the EntityReference of the Association will be
- * converted to an URI and written to the String property.</li>
- * <li>For any ManyAssociation in the EntityComposite, a Property<List<String>> with the same <strong>
- * unqualified</strong> name will be looked up in the ValueComposite. If found, the EntityReferences in the
- * ManyAssociation will be converted to URIs and placed into a List and set to the Property in ValueComposite.</li>
- * <li>For any NamedAssociation in the EntityComposite, a Property<Map<String,String>> with the same
- * <strong>unqualified</strong> name will be looked up in the ValueComposite. If found, the EntityReferences in
- * the NamedAssociation will be converted to URIs and placed into a Map and set to the Property in ValueComposite.
- * </li>
- *
- * </ol>
- * <p>
- * If a Property from the Entity is not found in the Value, then it is ignored.
- * </p>
- * @deprecated Please use {@link org.apache.zest.api.unitofwork.UnitOfWork#toValue(Class, Identity)} instead.
- */
-public interface EntityToValueService extends EntityToValue, ServiceComposite
-{
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1ead1338/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/PropertyNotPresentException.java
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/PropertyNotPresentException.java b/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/PropertyNotPresentException.java
deleted file mode 100644
index 1450852..0000000
--- a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/PropertyNotPresentException.java
+++ /dev/null
@@ -1,46 +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.conversion.values;
-
-import org.apache.zest.api.entity.EntityComposite;
-
-public class PropertyNotPresentException extends RuntimeException
-{
- private Class valueType;
- private Class<? extends EntityComposite> entityType;
-
- public PropertyNotPresentException( String message, Class valueType, Class<? extends EntityComposite> entityType )
- {
- super(message);
- this.valueType = valueType;
- this.entityType = entityType;
- }
-
- public Class valueType()
- {
- return valueType;
- }
-
- public Class entityType()
- {
- return entityType;
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1ead1338/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/Shared.java
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/Shared.java b/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/Shared.java
deleted file mode 100644
index 936d086..0000000
--- a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/Shared.java
+++ /dev/null
@@ -1,71 +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.conversion.values;
-
-import java.util.function.Predicate;
-import org.apache.zest.api.type.CollectionType;
-import org.apache.zest.api.type.MapType;
-import org.apache.zest.api.type.ValueType;
-
-/**
- * Shared.
- */
-final class Shared
-{
- static final Predicate<ValueType> STRING_TYPE_SPEC;
- static final Predicate<ValueType> STRING_COLLECTION_TYPE_SPEC;
- static final Predicate<ValueType> STRING_MAP_TYPE_SPEC;
-
- static
- {
- // Type Specifications
- STRING_TYPE_SPEC = new Predicate<ValueType>()
- {
- @Override
- public boolean test( ValueType valueType )
- {
- return valueType.mainType().equals( String.class );
- }
- };
- STRING_COLLECTION_TYPE_SPEC = new Predicate<ValueType>()
- {
- @Override
- public boolean test( ValueType valueType )
- {
- return valueType instanceof CollectionType
- && ( (CollectionType) valueType ).collectedType().mainType().equals( String.class );
- }
- };
- STRING_MAP_TYPE_SPEC = new Predicate<ValueType>()
- {
- @Override
- public boolean test( ValueType valueType )
- {
- return valueType instanceof MapType
- && ( (MapType) valueType ).keyType().mainType().equals( String.class )
- && ( (MapType) valueType ).valueType().mainType().equals( String.class );
- }
- };
- }
-
- private Shared()
- {
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1ead1338/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/Unqualified.java
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/Unqualified.java b/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/Unqualified.java
deleted file mode 100644
index 8e3497f..0000000
--- a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/Unqualified.java
+++ /dev/null
@@ -1,35 +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.conversion.values;
-
-import java.lang.annotation.*;
-
-/** If the ValueComposite is annotated with this, it means that the lookup of the Value Property should be performed
- * using the <strong>unqualified</strong> name only, and not via the default of the full qualified name. This
- * means that the Property may be declared in the different interfaces and still be matched.
- */
-@Retention( RetentionPolicy.RUNTIME )
-@Target( ElementType.TYPE )
-@Documented
-public @interface Unqualified
-{
- boolean value() default true;
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1ead1338/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntity.java
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntity.java b/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntity.java
deleted file mode 100644
index 70ec04f..0000000
--- a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntity.java
+++ /dev/null
@@ -1,137 +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.conversion.values;
-
-import java.util.function.Function;
-import org.apache.zest.api.entity.EntityComposite;
-import org.apache.zest.api.entity.Identity;
-import org.apache.zest.api.unitofwork.NoSuchEntityException;
-import org.apache.zest.api.value.ValueComposite;
-
-/**
- * Create or update Entities from matching Values.
- * @deprecated Please use {@link org.apache.zest.api.unitofwork.UnitOfWork#toEntity(Class, Identity)} instead.
- */
-public interface ValueToEntity
-{
- /**
- * Create an Entity from a Value.
- * <p>
- * If the Value extends {@link Identity} the Entity identity is taken from the Value's state.
- * Else, if the Value's state for {@code Identity} is absent, a new Identity is generated.
- *
- * @param <T> Value Type
- * @param entityType Entity Type
- * @param value Value
- *
- * @return the created Entity
- */
- <T> T create( Class<T> entityType, Object value );
-
- /**
- * Create an Entity from a Value.
- * <p>
- * If {@code identity} is not null, it is used as Entity identity.
- * Else, if the Value extends {@link Identity} the Entity identity is taken from the Value's state.
- * Else, if the Value's state for {@code Identity} is absent, a new Identity is generated.
- *
- * @param <T> Value Type
- * @param entityType Entity Type
- * @param identity Entity Identity, may be null
- * @param value Value
- *
- * @return the created Entity
- */
- <T> T create( Class<T> entityType, String identity, Object value );
-
- /**
- * Create an Entity from a Value.
- * <p>
- * If the Value extends {@link Identity} the Entity identity is taken from the Value's state.
- * Else, if the Value's state for {@code Identity} is absent, a new Identity is generated.
- *
- * @param <T> Value Type
- * @param entityType Entity Type
- * @param value Value
- * @param prototypeOpportunity A Function that will be mapped on the Entity prototype before instanciation
- *
- * @return the created Entity
- */
- <T> T create( Class<T> entityType, Object value, Function<T, T> prototypeOpportunity );
-
- /**
- * Create an Entity from a Value.
- * <p>
- * If {@code identity} is not null, it is used as Entity identity.
- * Else, if the Value extends {@link Identity} the Entity identity is taken from the Value's state.
- * Else, if the Value's state for {@code Identity} is absent, a new Identity is generated.
- *
- * @param <T> Value Type
- * @param entityType Entity Type
- * @param identity Entity Identity, may be null
- * @param value Value
- * @param prototypeOpportunity A Function that will be mapped on the Entity prototype before instanciation
- *
- * @return the created Entity
- */
- <T> T create( Class<T> entityType, String identity, Object value, Function<T, T> prototypeOpportunity );
-
- /**
- * Create an Iterable of Entities from an Iterable of Values.
- * <p>
- * If a Value extends {@link Identity} the Entity identity is taken from the Value's state.
- * Else, if a Value's state for {@code Identity} is absent, a new Identity is generated.
- *
- * @param <T> Value Type
- * @param entityType Entity Type
- * @param values An Iterable of Values
- *
- * @return the Iterable of created Entities
- */
- <T> Iterable<T> create( Class<T> entityType, Iterable<Object> values );
-
- /**
- * Create an Iterable of Entities from an Iterable of Values.
- * <p>
- * If a Value extends {@link Identity} the Entity identity is taken from the Value's state.
- * Else, if a Value's state for {@code Identity} is absent, a new Identity is generated.
- *
- * @param <T> Value Type
- * @param entityType Entity Type
- * @param values An Iterable of Values
- * @param prototypeOpportunity A Function that will be mapped on each Entity prototype before instanciation
- *
- * @return the Iterable of created Entities
- */
- <T> Iterable<T> create( Class<T> entityType, Iterable<Object> values, Function<T, T> prototypeOpportunity );
-
- /**
- * Update an Entity from a Value.
- *
- * @param entity Entity
- * @param value Value
- *
- * @throws ClassCastException If {@code entity} is not an {@link EntityComposite}
- * or if {@code value} is not a {@link ValueComposite}
- * @throws NoSuchEntityException If some associated Entity is absent from the EntityStore/UoW
- */
- void update( Object entity, Object value )
- throws ClassCastException, NoSuchEntityException;
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1ead1338/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntityAssembler.java
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntityAssembler.java b/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntityAssembler.java
deleted file mode 100644
index 6774712..0000000
--- a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntityAssembler.java
+++ /dev/null
@@ -1,45 +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.conversion.values;
-
-import org.apache.zest.api.entity.Identity;
-import org.apache.zest.bootstrap.Assemblers;
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.ModuleAssembly;
-import org.apache.zest.bootstrap.ServiceDeclaration;
-
-/**
- * ValueToEntity Service Assembler.
- * @deprecated Please use {@link org.apache.zest.api.unitofwork.UnitOfWork#toEntity(Class, Identity)} instead.
- */
-public class ValueToEntityAssembler
- extends Assemblers.VisibilityIdentity<ValueToEntityAssembler>
-{
- @Override
- public void assemble( ModuleAssembly module )
- throws AssemblyException
- {
- ServiceDeclaration service = module.services( ValueToEntityService.class ).visibleIn( visibility() );
- if( hasIdentity() )
- {
- service.identifiedBy( identity() );
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1ead1338/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntityMixin.java
----------------------------------------------------------------------
diff --git a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntityMixin.java b/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntityMixin.java
deleted file mode 100644
index 52ec6da..0000000
--- a/libraries/conversion/src/main/java/org/apache/zest/library/conversion/values/ValueToEntityMixin.java
+++ /dev/null
@@ -1,730 +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.conversion.values;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import org.apache.zest.api.association.Association;
-import org.apache.zest.api.association.AssociationDescriptor;
-import org.apache.zest.api.association.AssociationStateDescriptor;
-import org.apache.zest.api.association.AssociationStateHolder;
-import org.apache.zest.api.association.ManyAssociation;
-import org.apache.zest.api.association.NamedAssociation;
-import org.apache.zest.api.common.QualifiedName;
-import org.apache.zest.api.entity.EntityBuilder;
-import org.apache.zest.api.entity.EntityComposite;
-import org.apache.zest.api.entity.EntityDescriptor;
-import org.apache.zest.api.entity.EntityReference;
-import org.apache.zest.api.entity.Identity;
-import org.apache.zest.api.injection.scope.Structure;
-import org.apache.zest.api.property.PropertyDescriptor;
-import org.apache.zest.api.structure.ModuleDescriptor;
-import org.apache.zest.api.unitofwork.NoSuchEntityTypeException;
-import org.apache.zest.api.unitofwork.NoSuchEntityException;
-import org.apache.zest.api.unitofwork.UnitOfWorkFactory;
-import org.apache.zest.api.value.ValueComposite;
-import org.apache.zest.api.value.ValueDescriptor;
-import org.apache.zest.functional.Iterables;
-import org.apache.zest.spi.ZestSPI;
-
-import static org.apache.zest.library.conversion.values.Shared.STRING_COLLECTION_TYPE_SPEC;
-import static org.apache.zest.library.conversion.values.Shared.STRING_MAP_TYPE_SPEC;
-import static org.apache.zest.library.conversion.values.Shared.STRING_TYPE_SPEC;
-
-/**
- * ValueToEntity Mixin.
- *
- * @deprecated Please use {@link org.apache.zest.api.unitofwork.UnitOfWork#toEntity(Class, Identity)} instead.
- */
-public class ValueToEntityMixin
- implements ValueToEntity
-{
- private static final QualifiedName IDENTITY_STATE_NAME;
- private static final Function<ManyAssociation<?>, Iterable<EntityReference>> MANY_ASSOC_TO_ENTITY_REF_ITERABLE;
- private static final Function<NamedAssociation<?>, Map<String, EntityReference>> NAMED_ASSOC_TO_ENTITY_REF_MAP;
- private static final Function<Collection<String>, Iterable<EntityReference>> STRING_COLLEC_TO_ENTITY_REF_ITERABLE;
- private static final Function<Map<String, String>, Map<String, EntityReference>> STRING_MAP_TO_ENTITY_REF_MAP;
-
- static
- {
- try
- {
- IDENTITY_STATE_NAME = QualifiedName.fromAccessor( Identity.class.getMethod( "identity" ) );
- }
- catch( NoSuchMethodException e )
- {
- throw new InternalError( "Zest Core Runtime codebase is corrupted. Contact Zest team: ValueToEntityMixin" );
- }
- MANY_ASSOC_TO_ENTITY_REF_ITERABLE = manyAssoc -> {
- if( manyAssoc == null )
- {
- return Iterables.empty();
- }
- List<EntityReference> refs = new ArrayList<>( manyAssoc.count() );
- for( Object entity : manyAssoc )
- {
- refs.add( EntityReference.entityReferenceFor( entity ) );
- }
- return refs;
- };
- NAMED_ASSOC_TO_ENTITY_REF_MAP = namedAssoc -> {
- if( namedAssoc == null )
- {
- return Collections.emptyMap();
- }
- Map<String, EntityReference> refs = new LinkedHashMap<>( namedAssoc.count() );
- for( String name : namedAssoc )
- {
- refs.put( name, EntityReference.entityReferenceFor( namedAssoc.get( name ) ) );
- }
- return refs;
- };
- STRING_COLLEC_TO_ENTITY_REF_ITERABLE = stringCollec -> {
- if( stringCollec == null )
- {
- return Iterables.empty();
- }
- return stringCollec.stream()
- .map( EntityReference::parseEntityReference )
- .collect( Collectors.toList() );
- };
- STRING_MAP_TO_ENTITY_REF_MAP = stringMap -> {
- if( stringMap == null )
- {
- return Collections.emptyMap();
- }
- Map<String, EntityReference> refMap = new LinkedHashMap<>( stringMap.size() );
- for( Map.Entry<String, String> entry : stringMap.entrySet() )
- {
- refMap.put( entry.getKey(), EntityReference.parseEntityReference( entry.getValue() ) );
- }
- return refMap;
- };
- }
-
- @Structure
- private ZestSPI spi;
-
- @Structure
- private UnitOfWorkFactory uowf;
-
- @Structure
- private ModuleDescriptor module;
-
- @Override
- public <T> T create( Class<T> entityType, Object value )
- {
- return createInstance( doConversion( entityType, null, value ) );
- }
-
- @Override
- public <T> T create( Class<T> entityType, String identity, Object value )
- {
- return createInstance( doConversion( entityType, identity, value ) );
- }
-
- @Override
- public <T> T create( Class<T> entityType, Object value, Function<T, T> prototypeOpportunity )
- {
- EntityBuilder<?> builder = doConversion( entityType, null, value );
- //noinspection unchecked
- prototypeOpportunity.apply( (T) builder.instance() );
- return createInstance( builder );
- }
-
- @Override
- public <T> T create( Class<T> entityType, String identity, Object value, Function<T, T> prototypeOpportunity )
- {
- EntityBuilder<?> builder = doConversion( entityType, identity, value );
- //noinspection unchecked
- prototypeOpportunity.apply( (T) builder.instance() );
- return createInstance( builder );
- }
-
- @Override
- public <T> Iterable<T> create( final Class<T> entityType, final Iterable<Object> values )
- {
- return Iterables.map(
- value -> create( entityType, value ),
- values
- );
- }
-
- @Override
- public <T> Iterable<T> create( final Class<T> entityType,
- final Iterable<Object> values,
- final Function<T, T> prototypeOpportunity
- )
- {
- return Iterables.map(
- value -> create( entityType, value, prototypeOpportunity ),
- values
- );
- }
-
- private <T> EntityBuilder<?> doConversion( Class<T> entityType, String identity, Object value )
- {
- EntityDescriptor eDesc = module.entityDescriptor( entityType.getName() );
- if( eDesc == null )
- {
- throw new NoSuchEntityTypeException( entityType.getName(), module.name(), module.typeLookup() );
- }
-
- ValueComposite vComposite = (ValueComposite) value;
-
- ValueDescriptor vDesc = spi.valueDescriptorFor( vComposite );
- AssociationStateHolder vState = spi.stateOf( vComposite );
- AssociationStateDescriptor vStateDesc = vDesc.state();
-
- Unqualified unqualified = vDesc.metaInfo( Unqualified.class );
- if( unqualified == null || !unqualified.value() )
- {
- return doQualifiedConversion( entityType, identity, vState, vStateDesc );
- }
- return doUnqualifiedConversion( entityType, identity, vState, vStateDesc );
- }
-
- private <T> EntityBuilder<?> doQualifiedConversion(
- Class<T> entityType, String identity,
- final AssociationStateHolder vState, final AssociationStateDescriptor vStateDesc
- )
- {
- Function<PropertyDescriptor, Object> props = ePropDesc -> {
- try
- {
- return vState.propertyFor( ePropDesc.accessor() ).get();
- }
- catch( IllegalArgumentException propNotFoundOnValue )
- {
- // Property not found
- return null;
- }
- };
- Function<AssociationDescriptor, EntityReference> assocs = eAssocDesc -> {
- try
- {
- return EntityReference.entityReferenceFor( vState.associationFor( eAssocDesc.accessor() ) );
- }
- catch( IllegalArgumentException assocNotFoundOnValue )
- {
- // Find String Property and convert to Association
- String propName = eAssocDesc.qualifiedName().name();
- try
- {
- PropertyDescriptor vPropDesc = vStateDesc.findPropertyModelByName( propName );
- if( STRING_TYPE_SPEC.test( vPropDesc.valueType() ) )
- {
- String assocState = (String) vState.propertyFor( vPropDesc.accessor() ).get();
- return EntityReference.parseEntityReference( assocState );
- }
- return null;
- }
- catch( IllegalArgumentException propNotFoundOnValue )
- {
- return null;
- }
- }
- };
- Function<AssociationDescriptor, Iterable<EntityReference>> manyAssocs = eAssocDesc -> {
- try
- {
- ManyAssociation<Object> vAssocState = vState.manyAssociationFor( eAssocDesc.accessor() );
- return MANY_ASSOC_TO_ENTITY_REF_ITERABLE.apply( vAssocState );
- }
- catch( IllegalArgumentException assocNotFoundOnValue )
- {
- // Find Collection<String> Property and convert to ManyAssociation
- String propName = eAssocDesc.qualifiedName().name();
- try
- {
- PropertyDescriptor vPropDesc = vStateDesc.findPropertyModelByName( propName );
- if( STRING_COLLECTION_TYPE_SPEC.test( vPropDesc.valueType() ) )
- {
- @SuppressWarnings( "unchecked" )
- Collection<String> vAssocState = (Collection) vState.propertyFor( vPropDesc.accessor() ).get();
- return STRING_COLLEC_TO_ENTITY_REF_ITERABLE.apply( vAssocState );
- }
- return Iterables.empty();
- }
- catch( IllegalArgumentException propNotFoundOnValue )
- {
- return Iterables.empty();
- }
- }
- };
- Function<AssociationDescriptor, Map<String, EntityReference>> namedAssocs = eAssocDesc -> {
- try
- {
- NamedAssociation<?> vAssocState = vState.namedAssociationFor( eAssocDesc.accessor() );
- return NAMED_ASSOC_TO_ENTITY_REF_MAP.apply( vAssocState );
- }
- catch( IllegalArgumentException assocNotFoundOnValue )
- {
- // Find Map<String,String> Property and convert to NamedAssociation
- String propName = eAssocDesc.qualifiedName().name();
- try
- {
- PropertyDescriptor vPropDesc = vStateDesc.findPropertyModelByName( propName );
- if( STRING_MAP_TYPE_SPEC.test( vPropDesc.valueType() ) )
- {
- //noinspection unchecked
- Map<String, String> vAssocState = (Map) vState.propertyFor( vPropDesc.accessor() ).get();
- return STRING_MAP_TO_ENTITY_REF_MAP.apply( vAssocState );
- }
- return Collections.EMPTY_MAP;
- }
- catch( IllegalArgumentException propNotFoundOnValue )
- {
- return Collections.EMPTY_MAP;
- }
- }
- };
- return uowf.currentUnitOfWork().newEntityBuilderWithState(
- entityType, identity, props, assocs, manyAssocs, namedAssocs
- );
- }
-
- private <T> EntityBuilder<?> doUnqualifiedConversion(
- Class<T> entityType, String identity,
- final AssociationStateHolder vState, final AssociationStateDescriptor vStateDesc
- )
- {
- Function<PropertyDescriptor, Object> props = ePropDesc -> {
- String propName = ePropDesc.qualifiedName().name();
- try
- {
- PropertyDescriptor vPropDesc = vStateDesc.findPropertyModelByName( propName );
- return vState.propertyFor( vPropDesc.accessor() ).get();
- }
- catch( IllegalArgumentException propNotFoundOnValue )
- {
- // Property not found on Value
- return null;
- }
- };
- Function<AssociationDescriptor, EntityReference> assocs = eAssocDesc -> {
- String assocName = eAssocDesc.qualifiedName().name();
- try
- {
- AssociationDescriptor vAssocDesc = vStateDesc.getAssociationByName( assocName );
- Object assocEntity = vState.associationFor( vAssocDesc.accessor() ).get();
- return assocEntity == null ? null : EntityReference.entityReferenceFor( assocEntity );
- }
- catch( IllegalArgumentException assocNotFoundOnValue )
- {
- // Association not found on Value, find Property<String> and convert to Association
- try
- {
- PropertyDescriptor vPropDesc = vStateDesc.findPropertyModelByName( assocName );
- if( STRING_TYPE_SPEC.test( vPropDesc.valueType() ) )
- {
- String assocId = (String) vState.propertyFor( vPropDesc.accessor() ).get();
- return assocId == null ? null : EntityReference.parseEntityReference( assocId );
- }
- return null;
- }
- catch( IllegalArgumentException propNotFoundOnValue )
- {
- return null;
- }
- }
- };
- Function<AssociationDescriptor, Iterable<EntityReference>> manyAssocs = eAssocDesc -> {
- String assocName = eAssocDesc.qualifiedName().name();
- try
- {
- AssociationDescriptor vAssocDesc = vStateDesc.getManyAssociationByName( assocName );
- ManyAssociation<Object> vManyAssoc = vState.manyAssociationFor( vAssocDesc.accessor() );
- return MANY_ASSOC_TO_ENTITY_REF_ITERABLE.apply( vManyAssoc );
- }
- catch( IllegalArgumentException assocNotFoundOnValue )
- {
- // ManyAssociation not found on Value, find List<String> and convert to ManyAssociation
- try
- {
- PropertyDescriptor vPropDesc = vStateDesc.findPropertyModelByName( assocName );
- if( STRING_COLLECTION_TYPE_SPEC.test( vPropDesc.valueType() ) )
- {
- @SuppressWarnings( "unchecked" )
- Collection<String> vAssocState = (Collection) vState.propertyFor( vPropDesc.accessor() ).get();
- return STRING_COLLEC_TO_ENTITY_REF_ITERABLE.apply( vAssocState );
- }
- return Iterables.empty();
- }
- catch( IllegalArgumentException propNotFoundOnValue )
- {
- return Iterables.empty();
- }
- }
- };
- Function<AssociationDescriptor, Map<String, EntityReference>> namedAssocs = eAssocDesc -> {
- String assocName = eAssocDesc.qualifiedName().name();
- try
- {
- AssociationDescriptor vAssocDesc = vStateDesc.getNamedAssociationByName( assocName );
- NamedAssociation<Object> vAssocState = vState.namedAssociationFor( vAssocDesc.accessor() );
- return NAMED_ASSOC_TO_ENTITY_REF_MAP.apply( vAssocState );
- }
- catch( IllegalArgumentException assocNotFoundOnValue )
- {
- // Find Map<String,String> Property and convert to NamedAssociation
- try
- {
- PropertyDescriptor vPropDesc = vStateDesc.findPropertyModelByName( assocName );
- if( STRING_MAP_TYPE_SPEC.test( vPropDesc.valueType() ) )
- {
- @SuppressWarnings( "unchecked" )
- Map<String, String> vAssocState = (Map) vState.propertyFor( vPropDesc.accessor() ).get();
- return STRING_MAP_TO_ENTITY_REF_MAP.apply( vAssocState );
- }
- return Collections.EMPTY_MAP;
- }
- catch( IllegalArgumentException propNotFoundOnValue )
- {
- return Collections.EMPTY_MAP;
- }
- }
- };
- return uowf.currentUnitOfWork().newEntityBuilderWithState(
- entityType, identity, props, assocs, manyAssocs, namedAssocs
- );
- }
-
- protected <T> T createInstance( EntityBuilder<?> builder )
- {
- //noinspection unchecked
- return (T) builder.newInstance();
- }
-
- @Override
- public void update( Object entity, Object value )
- throws NoSuchEntityException
- {
- EntityComposite eComposite = (EntityComposite) entity;
- ValueComposite vComposite = (ValueComposite) value;
-
- EntityDescriptor eDesc = spi.entityDescriptorFor( eComposite );
- AssociationStateHolder eState = spi.stateOf( eComposite );
- AssociationStateDescriptor eStateDesc = eDesc.state();
-
- ValueDescriptor vDesc = spi.valueDescriptorFor( vComposite );
- AssociationStateHolder vState = spi.stateOf( vComposite );
- AssociationStateDescriptor vStateDesc = vDesc.state();
-
- Unqualified unqualified = vDesc.metaInfo( Unqualified.class );
- if( unqualified == null || !unqualified.value() )
- {
- doQualifiedUpdate( eState, eStateDesc, vState, vStateDesc );
- }
- else
- {
- doUnQualifiedUpdate( eState, eStateDesc, vState, vStateDesc );
- }
- }
-
- private void doQualifiedUpdate(
- AssociationStateHolder eState, AssociationStateDescriptor eStateDesc,
- AssociationStateHolder vState, AssociationStateDescriptor vStateDesc
- )
- throws NoSuchEntityException
- {
- eStateDesc.properties().forEach( ePropDesc ->
- {
- if( ! IDENTITY_STATE_NAME.equals( ePropDesc.qualifiedName() ) )
- {
- try
- {
- PropertyDescriptor vPropDesc = vStateDesc.findPropertyModelByQualifiedName( ePropDesc.qualifiedName() );
- eState.propertyFor( ePropDesc.accessor() ).set( vState.propertyFor( vPropDesc.accessor() ).get() );
- }
- catch( IllegalArgumentException propNotFoundOnValue )
- {
- // Property not found on Value, do nothing
- }
- }
- } );
- eStateDesc.associations().forEach( eAssocDesc ->
- {
- Association<Object> eAssoc = eState.associationFor( eAssocDesc.accessor() );
- try
- {
- AssociationDescriptor vAssocDesc
- = vStateDesc.getAssociationByQualifiedName( eAssocDesc.qualifiedName() );
- eAssoc.set( vState.associationFor( vAssocDesc.accessor() ).get() );
- }
- catch( IllegalArgumentException assocNotFoundOnValue )
- {
- // Association not found on Value, find Property<String> and load associated Entity
- try
- {
- PropertyDescriptor vPropDesc
- = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() );
- if( STRING_TYPE_SPEC.test( vPropDesc.valueType() ) )
- {
- String assocId = (String) vState.propertyFor( vPropDesc.accessor() ).get();
- if( assocId != null )
- {
- eAssoc.set( uowf.currentUnitOfWork().get( (Class) eAssocDesc.type(), assocId ) );
- }
- else
- {
- eAssoc.set( null );
- }
- }
- }
- catch( IllegalArgumentException propNotFoundOnValue )
- {
- // Do nothing
- }
- }
- });
- eStateDesc.manyAssociations().forEach( eAssocDesc ->
- {
- ManyAssociation<Object> eManyAssoc = eState.manyAssociationFor( eAssocDesc.accessor() );
- try
- {
- AssociationDescriptor vAssocDesc
- = vStateDesc.getManyAssociationByQualifiedName( eAssocDesc.qualifiedName() );
- ManyAssociation<Object> vManyAssoc = vState.manyAssociationFor( vAssocDesc.accessor() );
- eManyAssoc.toList().forEach( eManyAssoc::remove );
- vManyAssoc.toList().forEach( eManyAssoc::add );
- }
- catch( IllegalArgumentException assocNotFoundOnValue )
- {
- // ManyAssociation not found on Value, find Property<List<String>> and load associated Entities
- try
- {
- PropertyDescriptor vPropDesc
- = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() );
- if( STRING_COLLECTION_TYPE_SPEC.test( vPropDesc.valueType() ) )
- {
- @SuppressWarnings( "unchecked" )
- Collection<String> vAssocState = (Collection) vState.propertyFor( vPropDesc.accessor() ).get();
- eManyAssoc.toList().forEach( eManyAssoc::remove );
- if( vAssocState != null )
- {
- for( String eachAssoc : vAssocState )
- {
- eManyAssoc.add(
- uowf.currentUnitOfWork().get( (Class) eAssocDesc.type(), eachAssoc )
- );
- }
- }
- }
- }
- catch( IllegalArgumentException propNotFoundOnValue )
- {
- // Do nothing
- }
- }
- });
- eStateDesc.namedAssociations().forEach( eAssocDesc ->
- {
- NamedAssociation<Object> eNamedAssoc = eState.namedAssociationFor( eAssocDesc.accessor() );
- try
- {
- AssociationDescriptor vAssocDesc
- = vStateDesc.getNamedAssociationByQualifiedName( eAssocDesc.qualifiedName() );
- NamedAssociation<Object> vNamedAssoc = vState.namedAssociationFor( vAssocDesc.accessor() );
- Iterables.toList( eNamedAssoc ).forEach( eNamedAssoc::remove );
- for( Map.Entry<String, Object> assocEntry : vNamedAssoc.toMap().entrySet() )
- {
- eNamedAssoc.put( assocEntry.getKey(), assocEntry.getValue() );
- }
- }
- catch( IllegalArgumentException assocNotFoundOnValue )
- {
- // NamedAssociation not found on Value, find Property<Map<String,String>> and load associated Entities
- try
- {
- PropertyDescriptor vPropDesc
- = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() );
- if( STRING_MAP_TYPE_SPEC.test( vPropDesc.valueType() ) )
- {
- @SuppressWarnings( "unchecked" )
- Map<String, String> vAssocState = (Map) vState.propertyFor( vPropDesc.accessor() ).get();
- Iterables.toList( eNamedAssoc ).forEach( eNamedAssoc::remove );
- if( vAssocState != null )
- {
- for( Map.Entry<String, String> assocEntry : vAssocState.entrySet() )
- {
- eNamedAssoc.put(
- assocEntry.getKey(),
- uowf.currentUnitOfWork().get( (Class) eAssocDesc.type(), assocEntry.getValue() )
- );
- }
- }
- }
- }
- catch( IllegalArgumentException propNotFoundOnValue )
- {
- // Do nothing
- }
- }
- } );
- }
-
- private void doUnQualifiedUpdate(
- AssociationStateHolder eState, AssociationStateDescriptor eStateDesc,
- AssociationStateHolder vState, AssociationStateDescriptor vStateDesc
- )
- {
- eStateDesc.properties().forEach( ePropDesc ->
- {
- if( ! IDENTITY_STATE_NAME.equals( ePropDesc.qualifiedName() ) )
- {
- try
- {
- PropertyDescriptor vPropDesc = vStateDesc.findPropertyModelByName( ePropDesc.qualifiedName().name() );
- eState.propertyFor( ePropDesc.accessor() ).set( vState.propertyFor( vPropDesc.accessor() ).get() );
- }
- catch( IllegalArgumentException propNotFoundOnValue )
- {
- // Property not found on Value, do nothing
- }
- }
- } );
- eStateDesc.associations().forEach( eAssocDesc ->
- {
- Association<Object> eAssoc = eState.associationFor( eAssocDesc.accessor() );
- try
- {
- AssociationDescriptor vAssocDesc = vStateDesc.getAssociationByName( eAssocDesc.qualifiedName().name() );
- eAssoc.set( vState.associationFor( vAssocDesc.accessor() ).get() );
- }
- catch( IllegalArgumentException assocNotFoundOnValue )
- {
- // Association not found on Value, find Property<String> and load associated Entity
- try
- {
- PropertyDescriptor vPropDesc
- = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() );
- if( STRING_TYPE_SPEC.test( vPropDesc.valueType() ) )
- {
- String assocId = (String) vState.propertyFor( vPropDesc.accessor() ).get();
- if( assocId != null )
- {
- eAssoc.set( uowf.currentUnitOfWork().get( (Class) eAssocDesc.type(), assocId ) );
- }
- else
- {
- eAssoc.set( null );
- }
- }
- }
- catch( IllegalArgumentException propNotFoundOnValue )
- {
- // Do nothing
- }
- }
- } );
- eStateDesc.manyAssociations().forEach( eAssocDesc ->
- {
- ManyAssociation<Object> eManyAssoc = eState.manyAssociationFor( eAssocDesc.accessor() );
- try
- {
- AssociationDescriptor vAssDesc
- = vStateDesc.getManyAssociationByName( eAssocDesc.qualifiedName().name() );
- ManyAssociation<Object> vManyAss = vState.manyAssociationFor( vAssDesc.accessor() );
- eManyAssoc.toList().forEach( eManyAssoc::remove );
- vManyAss.toList().forEach( eManyAssoc::add );
- }
- catch( IllegalArgumentException assNotFoundOnValue )
- {
- // ManyAssociation not found on Value, find Property<List<String>> and load associated Entities
- try
- {
- PropertyDescriptor vPropDesc
- = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() );
- if( STRING_COLLECTION_TYPE_SPEC.test( vPropDesc.valueType() ) )
- {
- @SuppressWarnings( "unchecked" )
- Collection<String> vAssocState = (Collection) vState.propertyFor( vPropDesc.accessor() ).get();
- eManyAssoc.toList().forEach( eManyAssoc::remove );
- if( vAssocState != null )
- {
- vAssocState.forEach( eachAssoc ->
- {
- eManyAssoc.add(
- uowf.currentUnitOfWork().get( (Class<?>) eAssocDesc.type(), eachAssoc )
- );
- } );
- }
- }
- }
- catch( IllegalArgumentException propNotFoundOnValue )
- {
- // Do nothing
- }
- }
- } );
- eStateDesc.namedAssociations().forEach( eAssocDesc ->
- {
- NamedAssociation<Object> eNamedAssoc = eState.namedAssociationFor( eAssocDesc.accessor() );
- try
- {
- AssociationDescriptor vAssocDesc
- = vStateDesc.getNamedAssociationByName( eAssocDesc.qualifiedName().name() );
- NamedAssociation<Object> vNamedAssoc = vState.namedAssociationFor( vAssocDesc.accessor() );
- Iterables.toList( eNamedAssoc ).forEach( eNamedAssoc::remove );
- for( Map.Entry<String, Object> assocEntry : vNamedAssoc.toMap().entrySet() )
- {
- eNamedAssoc.put( assocEntry.getKey(), assocEntry.getValue() );
- }
- }
- catch( IllegalArgumentException assocNotFoundOnValue )
- {
- // NamedAssociation not found on Value, find Property<Map<String,String>> and load associated Entities
- try
- {
- PropertyDescriptor vPropDesc
- = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() );
- if( STRING_MAP_TYPE_SPEC.test( vPropDesc.valueType() ) )
- {
- @SuppressWarnings( "unchecked" )
- Map<String, String> vAssocState =
- (Map<String,String>) vState.propertyFor( vPropDesc.accessor() ).get();
- Iterables.toList( eNamedAssoc ).forEach( eNamedAssoc::remove );
- if( vAssocState != null )
- {
- for( Map.Entry<String, String> assocEntry : vAssocState.entrySet() )
- {
- eNamedAssoc.put(
- assocEntry.getKey(),
- uowf.currentUnitOfWork().get( (Class) eAssocDesc.type(), assocEntry.getValue() )
- );
- }
- }
- }
- }
- catch( IllegalArgumentException propNotFoundOnValue )
- {
- // Do nothing
- }
- }
- } );
- }
-}