Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6D9F6200B29 for ; Thu, 16 Jun 2016 04:33:52 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 6C0C1160A5D; Thu, 16 Jun 2016 02:33:52 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id ED1DD160A57 for ; Thu, 16 Jun 2016 04:33:49 +0200 (CEST) Received: (qmail 34041 invoked by uid 500); 16 Jun 2016 02:33:49 -0000 Mailing-List: contact commits-help@zest.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zest.apache.org Delivered-To: mailing list commits@zest.apache.org Received: (qmail 34032 invoked by uid 99); 16 Jun 2016 02:33:49 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Jun 2016 02:33:49 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EF1C6DFBA8; Thu, 16 Jun 2016 02:33:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: niclas@apache.org To: commits@zest.apache.org Date: Thu, 16 Jun 2016 02:33:46 -0000 Message-Id: <7f82571527c5485a9751928c72165a40@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [13/23] zest-java git commit: ZEST-151 : Removed Conversion Library archived-at: Thu, 16 Jun 2016 02:33:52 -0000 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/5229303a Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/5229303a Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/5229303a Branch: refs/heads/develop Commit: 5229303a2394233af083f81e2e46aa4bcac5356f Parents: e4736b0 Author: Niclas Hedhman Authored: Sun Jun 12 16:56:17 2016 +0800 Committer: Niclas Hedhman Committed: Sun Jun 12 22:51:05 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/5229303a/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™ Conversion Library has various generic services to manipulate Apache Zest™ ValueComposites, such as converting an Entity to a Value." - -jar { manifest { name = "Apache Zest™ 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/5229303a/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 @@ - - - - - - stable - - - brief - - - some - - - ALv2 - - http://git-wip-us.apache.org/repos/asf/zest-java/blob/5229303a/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 <> 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/5229303a/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 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 convert( Class valueType, Object entity ); - - /** - * Convert an entity to a value with an opportunity to customize its prototype. - * - * @param 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 convert( Class valueType, Object entity, Function prototypeOpportunity ); - - /** - * Convert an iterable of entities to an iterable of values. - * - * @param parametrized type of the value - * @param valueType type of the value - * @param entities the entities to convert to values - * @return the resulting values - */ - Iterable convert( Class valueType, Iterable entities ); - - /** - * Convert an iterable of entities to an iterable of values with an opportunity to customize their prototypes. - * - * @param 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 - */ - Iterable convert( Class valueType, Iterable entities, Function prototypeOpportunity ); - - static class EntityToValueMixin - implements EntityToValue - { - - @Structure - private ZestSPI spi; - @Structure - private Module module; - - @Override - public T convert( final Class valueType, Object entity ) - { - return createInstance( doConversion( valueType, entity ) ); - } - - @Override - @SuppressWarnings( "unchecked" ) - public T convert( final Class valueType, Object entity, Function prototypeOpportunity ) - { - ValueBuilder builder = doConversion( valueType, entity ); - prototypeOpportunity.apply( (T) builder.prototype() ); - return createInstance( builder ); - } - - @Override - public Iterable convert( final Class valueType, Iterable entities ) - { - return Iterables.map( - new Function() - { - @Override - public T apply( Object entity ) - { - return convert( valueType, entity ); - } - }, entities ); - } - - @Override - public Iterable convert( final Class valueType, Iterable entities, final Function prototypeOpportunity ) - { - return Iterables.map( - new Function() - { - @Override - public T apply( Object entity ) - { - return convert( valueType, entity, prototypeOpportunity ); - } - }, entities ); - } - - private ValueBuilder doConversion( final Class 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 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() - { - @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 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 entities = new LinkedHashMap<>( state.count() ); - for( String name : state ) - { - entities.put( name, ( (Identity) state.get( name ) ).identity().get() ); - } - return entities; - } - - return null; - } - } - }, - new Function() - { - @Override - public EntityReference apply( AssociationDescriptor associationDescriptor ) - { - return EntityReference.entityReferenceFor( - associationState.associationFor( associationDescriptor.accessor() ).get() ); - } - }, - new Function>() - { - @Override - public Iterable apply( AssociationDescriptor associationDescriptor ) - { - ManyAssociation state = associationState.manyAssociationFor( associationDescriptor.accessor() ); - List refs = new ArrayList<>( state.count() ); - for( Object entity : state ) - { - refs.add( EntityReference.entityReferenceFor( entity ) ); - } - return refs; - } - }, - new Function>() - { - @Override - public Map apply( AssociationDescriptor associationDescriptor ) - { - NamedAssociation assoc = associationState.namedAssociationFor( associationDescriptor.accessor() ); - Map 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() - { - @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 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 entities = new LinkedHashMap<>( state.count() ); - for( String name : state ) - { - entities.put( name, ( (Identity) state.get( name ) ).identity().get() ); - } - return entities; - } - return null; - } - } - }, - new Function() - { - @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 association = associationState.associationFor( associationMethod ); - return EntityReference.entityReferenceFor( association.get() ); - } - }, - new Function>() - { - @Override - public Iterable 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 refs = new ArrayList<>( state.count() ); - for( Object entity : state ) - { - refs.add( EntityReference.entityReferenceFor( entity ) ); - } - return refs; - } - }, - new Function>() - { - @Override - public Map 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 assoc = associationState.namedAssociationFor( associationMethod ); - Map 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 createInstance( ValueBuilder builder ) - { - return (T) builder.newInstance(); - } - } - -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/5229303a/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 -{ - @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/5229303a/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. - *

- * 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; - *

- *
    - *
  1. 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.
  2. - *
  3. For any Association in the EntityComposite, a Property<String> with the same unqualified - * 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.
  4. - *
  5. For any ManyAssociation in the EntityComposite, a Property<List<String>> with the same - * unqualified 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.
  6. - *
  7. For any NamedAssociation in the EntityComposite, a Property<Map<String,String>> with the same - * unqualified 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. - *
  8. - * - *
- *

- * If a Property from the Entity is not found in the Value, then it is ignored. - *

- * @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/5229303a/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 entityType; - - public PropertyNotPresentException( String message, Class valueType, Class 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/5229303a/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 STRING_TYPE_SPEC; - static final Predicate STRING_COLLECTION_TYPE_SPEC; - static final Predicate STRING_MAP_TYPE_SPEC; - - static - { - // Type Specifications - STRING_TYPE_SPEC = new Predicate() - { - @Override - public boolean test( ValueType valueType ) - { - return valueType.mainType().equals( String.class ); - } - }; - STRING_COLLECTION_TYPE_SPEC = new Predicate() - { - @Override - public boolean test( ValueType valueType ) - { - return valueType instanceof CollectionType - && ( (CollectionType) valueType ).collectedType().mainType().equals( String.class ); - } - }; - STRING_MAP_TYPE_SPEC = new Predicate() - { - @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/5229303a/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 unqualified 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/5229303a/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. - *

- * 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 Value Type - * @param entityType Entity Type - * @param value Value - * - * @return the created Entity - */ - T create( Class entityType, Object value ); - - /** - * Create an Entity from a Value. - *

- * 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 Value Type - * @param entityType Entity Type - * @param identity Entity Identity, may be null - * @param value Value - * - * @return the created Entity - */ - T create( Class entityType, String identity, Object value ); - - /** - * Create an Entity from a Value. - *

- * 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 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 create( Class entityType, Object value, Function prototypeOpportunity ); - - /** - * Create an Entity from a Value. - *

- * 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 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 create( Class entityType, String identity, Object value, Function prototypeOpportunity ); - - /** - * Create an Iterable of Entities from an Iterable of Values. - *

- * 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 Value Type - * @param entityType Entity Type - * @param values An Iterable of Values - * - * @return the Iterable of created Entities - */ - Iterable create( Class entityType, Iterable values ); - - /** - * Create an Iterable of Entities from an Iterable of Values. - *

- * 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 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 - */ - Iterable create( Class entityType, Iterable values, Function 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/5229303a/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 -{ - @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/5229303a/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, Iterable> MANY_ASSOC_TO_ENTITY_REF_ITERABLE; - private static final Function, Map> NAMED_ASSOC_TO_ENTITY_REF_MAP; - private static final Function, Iterable> STRING_COLLEC_TO_ENTITY_REF_ITERABLE; - private static final Function, Map> 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 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 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 refMap = new LinkedHashMap<>( stringMap.size() ); - for( Map.Entry 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 create( Class entityType, Object value ) - { - return createInstance( doConversion( entityType, null, value ) ); - } - - @Override - public T create( Class entityType, String identity, Object value ) - { - return createInstance( doConversion( entityType, identity, value ) ); - } - - @Override - public T create( Class entityType, Object value, Function prototypeOpportunity ) - { - EntityBuilder builder = doConversion( entityType, null, value ); - //noinspection unchecked - prototypeOpportunity.apply( (T) builder.instance() ); - return createInstance( builder ); - } - - @Override - public T create( Class entityType, String identity, Object value, Function prototypeOpportunity ) - { - EntityBuilder builder = doConversion( entityType, identity, value ); - //noinspection unchecked - prototypeOpportunity.apply( (T) builder.instance() ); - return createInstance( builder ); - } - - @Override - public Iterable create( final Class entityType, final Iterable values ) - { - return Iterables.map( - value -> create( entityType, value ), - values - ); - } - - @Override - public Iterable create( final Class entityType, - final Iterable values, - final Function prototypeOpportunity - ) - { - return Iterables.map( - value -> create( entityType, value, prototypeOpportunity ), - values - ); - } - - private EntityBuilder doConversion( Class 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 EntityBuilder doQualifiedConversion( - Class entityType, String identity, - final AssociationStateHolder vState, final AssociationStateDescriptor vStateDesc - ) - { - Function props = ePropDesc -> { - try - { - return vState.propertyFor( ePropDesc.accessor() ).get(); - } - catch( IllegalArgumentException propNotFoundOnValue ) - { - // Property not found - return null; - } - }; - Function 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> manyAssocs = eAssocDesc -> { - try - { - ManyAssociation vAssocState = vState.manyAssociationFor( eAssocDesc.accessor() ); - return MANY_ASSOC_TO_ENTITY_REF_ITERABLE.apply( vAssocState ); - } - catch( IllegalArgumentException assocNotFoundOnValue ) - { - // Find Collection 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 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> namedAssocs = eAssocDesc -> { - try - { - NamedAssociation vAssocState = vState.namedAssociationFor( eAssocDesc.accessor() ); - return NAMED_ASSOC_TO_ENTITY_REF_MAP.apply( vAssocState ); - } - catch( IllegalArgumentException assocNotFoundOnValue ) - { - // Find Map 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 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 EntityBuilder doUnqualifiedConversion( - Class entityType, String identity, - final AssociationStateHolder vState, final AssociationStateDescriptor vStateDesc - ) - { - Function 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 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 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> manyAssocs = eAssocDesc -> { - String assocName = eAssocDesc.qualifiedName().name(); - try - { - AssociationDescriptor vAssocDesc = vStateDesc.getManyAssociationByName( assocName ); - ManyAssociation vManyAssoc = vState.manyAssociationFor( vAssocDesc.accessor() ); - return MANY_ASSOC_TO_ENTITY_REF_ITERABLE.apply( vManyAssoc ); - } - catch( IllegalArgumentException assocNotFoundOnValue ) - { - // ManyAssociation not found on Value, find List and convert to ManyAssociation - try - { - PropertyDescriptor vPropDesc = vStateDesc.findPropertyModelByName( assocName ); - if( STRING_COLLECTION_TYPE_SPEC.test( vPropDesc.valueType() ) ) - { - @SuppressWarnings( "unchecked" ) - Collection 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> namedAssocs = eAssocDesc -> { - String assocName = eAssocDesc.qualifiedName().name(); - try - { - AssociationDescriptor vAssocDesc = vStateDesc.getNamedAssociationByName( assocName ); - NamedAssociation vAssocState = vState.namedAssociationFor( vAssocDesc.accessor() ); - return NAMED_ASSOC_TO_ENTITY_REF_MAP.apply( vAssocState ); - } - catch( IllegalArgumentException assocNotFoundOnValue ) - { - // Find Map Property and convert to NamedAssociation - try - { - PropertyDescriptor vPropDesc = vStateDesc.findPropertyModelByName( assocName ); - if( STRING_MAP_TYPE_SPEC.test( vPropDesc.valueType() ) ) - { - @SuppressWarnings( "unchecked" ) - Map 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 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 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 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 eManyAssoc = eState.manyAssociationFor( eAssocDesc.accessor() ); - try - { - AssociationDescriptor vAssocDesc - = vStateDesc.getManyAssociationByQualifiedName( eAssocDesc.qualifiedName() ); - ManyAssociation 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> and load associated Entities - try - { - PropertyDescriptor vPropDesc - = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() ); - if( STRING_COLLECTION_TYPE_SPEC.test( vPropDesc.valueType() ) ) - { - @SuppressWarnings( "unchecked" ) - Collection 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 eNamedAssoc = eState.namedAssociationFor( eAssocDesc.accessor() ); - try - { - AssociationDescriptor vAssocDesc - = vStateDesc.getNamedAssociationByQualifiedName( eAssocDesc.qualifiedName() ); - NamedAssociation vNamedAssoc = vState.namedAssociationFor( vAssocDesc.accessor() ); - Iterables.toList( eNamedAssoc ).forEach( eNamedAssoc::remove ); - for( Map.Entry assocEntry : vNamedAssoc.toMap().entrySet() ) - { - eNamedAssoc.put( assocEntry.getKey(), assocEntry.getValue() ); - } - } - catch( IllegalArgumentException assocNotFoundOnValue ) - { - // NamedAssociation not found on Value, find Property> and load associated Entities - try - { - PropertyDescriptor vPropDesc - = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() ); - if( STRING_MAP_TYPE_SPEC.test( vPropDesc.valueType() ) ) - { - @SuppressWarnings( "unchecked" ) - Map vAssocState = (Map) vState.propertyFor( vPropDesc.accessor() ).get(); - Iterables.toList( eNamedAssoc ).forEach( eNamedAssoc::remove ); - if( vAssocState != null ) - { - for( Map.Entry 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 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 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 eManyAssoc = eState.manyAssociationFor( eAssocDesc.accessor() ); - try - { - AssociationDescriptor vAssDesc - = vStateDesc.getManyAssociationByName( eAssocDesc.qualifiedName().name() ); - ManyAssociation 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> and load associated Entities - try - { - PropertyDescriptor vPropDesc - = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() ); - if( STRING_COLLECTION_TYPE_SPEC.test( vPropDesc.valueType() ) ) - { - @SuppressWarnings( "unchecked" ) - Collection 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 eNamedAssoc = eState.namedAssociationFor( eAssocDesc.accessor() ); - try - { - AssociationDescriptor vAssocDesc - = vStateDesc.getNamedAssociationByName( eAssocDesc.qualifiedName().name() ); - NamedAssociation vNamedAssoc = vState.namedAssociationFor( vAssocDesc.accessor() ); - Iterables.toList( eNamedAssoc ).forEach( eNamedAssoc::remove ); - for( Map.Entry assocEntry : vNamedAssoc.toMap().entrySet() ) - { - eNamedAssoc.put( assocEntry.getKey(), assocEntry.getValue() ); - } - } - catch( IllegalArgumentException assocNotFoundOnValue ) - { - // NamedAssociation not found on Value, find Property> and load associated Entities - try - { - PropertyDescriptor vPropDesc - = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() ); - if( STRING_MAP_TYPE_SPEC.test( vPropDesc.valueType() ) ) - { - @SuppressWarnings( "unchecked" ) - Map vAssocState = - (Map) vState.propertyFor( vPropDesc.accessor() ).get(); - Iterables.toList( eNamedAssoc ).forEach( eNamedAssoc::remove ); - if( vAssocState != null ) - { - for( Map.Entry assocEntry : vAssocState.entrySet() ) - { - eNamedAssoc.put( - assocEntry.getKey(), - uowf.currentUnitOfWork().get( (Class) eAssocDesc.type(), assocEntry.getValue() ) - ); - } - } - } - } - catch( IllegalArgumentException propNotFoundOnValue ) - { - // Do nothing - } - } - } ); - } -}