Return-Path: X-Original-To: apmail-olingo-commits-archive@minotaur.apache.org Delivered-To: apmail-olingo-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 56C8510C01 for ; Mon, 12 May 2014 09:06:43 +0000 (UTC) Received: (qmail 29893 invoked by uid 500); 12 May 2014 08:38:41 -0000 Delivered-To: apmail-olingo-commits-archive@olingo.apache.org Received: (qmail 29851 invoked by uid 500); 12 May 2014 08:38:41 -0000 Mailing-List: contact commits-help@olingo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@olingo.apache.org Delivered-To: mailing list commits@olingo.apache.org Received: (qmail 29312 invoked by uid 99); 12 May 2014 08:38:38 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 May 2014 08:38:38 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id A7F4D81D291; Mon, 12 May 2014 08:38:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: challenh@apache.org To: commits@olingo.apache.org Date: Mon, 12 May 2014 08:39:20 -0000 Message-Id: In-Reply-To: <7dee00767dfd45f5a3114296fdba7334@git.apache.org> References: <7dee00767dfd45f5a3114296fdba7334@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [45/50] [abbrv] git commit: Various small fixes and improvements Various small fixes and improvements Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/ec30775b Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/ec30775b Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/ec30775b Branch: refs/heads/olingo274 Commit: ec30775b8c129436f2084ca9ac89fc75a17a0fcb Parents: 365ea6f Author: Francesco Chicchiriccò <--global> Authored: Sat May 10 10:26:19 2014 +0200 Committer: Francesco Chicchiriccò <--global> Committed: Sat May 10 10:26:19 2014 +0200 ---------------------------------------------------------------------- .../commons/AbstractInvocationHandler.java | 7 +- .../commons/AbstractTypeInvocationHandler.java | 4 +- .../commons/ComplexTypeInvocationHandler.java | 24 +- .../olingo/ext/proxy/commons/ContainerImpl.java | 6 +- .../commons/EntitySetInvocationHandler.java | 2 +- .../commons/EntityTypeInvocationHandler.java | 18 +- .../olingo/ext/proxy/utils/CoreUtils.java | 452 +++++++++++++++++++ .../olingo/ext/proxy/utils/EngineUtils.java | 439 ------------------ .../ext/pojogen/AbstractMetadataMojo.java | 1 - .../olingo/ext/pojogen/AbstractUtility.java | 4 - .../olingo/ext/pojogen/V3MetadataMojo.java | 245 +++++----- .../src/main/resources/complexType.vm | 1 - .../src/main/resources/container.vm | 1 - .../src/main/resources/entityCollection.vm | 5 +- .../src/main/resources/entitySet.vm | 1 - .../src/main/resources/entityType.vm | 3 +- .../src/main/resources/entityTypeKey.vm | 1 - .../src/main/resources/singleton.vm | 1 - .../org/apache/olingo/fit/AbstractServices.java | 40 +- .../apache/olingo/fit/V3ActionOverloading.java | 2 +- .../java/org/apache/olingo/fit/V3OpenType.java | 7 +- .../java/org/apache/olingo/fit/V3Services.java | 7 +- .../main/java/org/apache/olingo/fit/V4Demo.java | 7 +- .../java/org/apache/olingo/fit/V4OpenType.java | 9 +- .../java/org/apache/olingo/fit/V4Services.java | 19 +- .../org/apache/olingo/fit/V4Vocabularies.java | 8 +- .../apache/olingo/fit/metadata/EntityType.java | 10 + .../apache/olingo/fit/metadata/Metadata.java | 7 +- .../olingo/fit/utils/AbstractUtilities.java | 17 +- .../org/apache/olingo/fit/utils/Commons.java | 1 + .../org/apache/olingo/fit/utils/Constants.java | 1 + .../org/apache/olingo/fit/utils/DataBinder.java | 63 +-- .../org/apache/olingo/fit/utils/FSManager.java | 6 +- .../apache/olingo/fit/utils/JSONUtilities.java | 5 +- .../apache/olingo/fit/utils/XMLUtilities.java | 5 +- fit/src/main/resources/V40/openTypeMetadata.xml | 10 +- .../olingo/fit/proxy/v3/AbstractTest.java | 9 - .../proxy/v3/AuthEntityRetrieveTestITCase.java | 2 +- .../fit/proxy/v3/EntityRetrieveTestITCase.java | 2 +- .../AllGeoCollectionTypesSet.java | 1 - .../astoriadefaultservice/AllGeoTypesSet.java | 1 - .../services/astoriadefaultservice/Car.java | 1 - .../astoriadefaultservice/Computer.java | 1 - .../astoriadefaultservice/ComputerDetail.java | 1 - .../astoriadefaultservice/Customer.java | 1 - .../astoriadefaultservice/CustomerInfo.java | 1 - .../astoriadefaultservice/DefaultContainer.java | 1 - .../services/astoriadefaultservice/Driver.java | 1 - .../astoriadefaultservice/LastLogin.java | 1 - .../services/astoriadefaultservice/License.java | 1 - .../services/astoriadefaultservice/Login.java | 1 - .../astoriadefaultservice/MappedEntityType.java | 1 - .../services/astoriadefaultservice/Message.java | 1 - .../MessageAttachment.java | 1 - .../services/astoriadefaultservice/Order.java | 1 - .../astoriadefaultservice/OrderLine.java | 1 - .../astoriadefaultservice/PageView.java | 1 - .../services/astoriadefaultservice/Person.java | 1 - .../astoriadefaultservice/PersonMetadata.java | 1 - .../services/astoriadefaultservice/Product.java | 1 - .../astoriadefaultservice/ProductDetail.java | 1 - .../astoriadefaultservice/ProductPhoto.java | 1 - .../astoriadefaultservice/ProductReview.java | 1 - .../astoriadefaultservice/RSAToken.java | 1 - .../astoriadefaultservice/types/Aliases.java | 3 +- .../types/AllSpatialCollectionTypes.java | 6 +- .../AllSpatialCollectionTypesCollection.java | 1 - .../types/AllSpatialCollectionTypes_Simple.java | 18 +- ...SpatialCollectionTypes_SimpleCollection.java | 1 - .../types/AllSpatialTypes.java | 38 +- .../types/AllSpatialTypesCollection.java | 1 - .../astoriadefaultservice/types/AuditInfo.java | 4 +- .../types/BackOrderLine.java | 14 +- .../types/BackOrderLine2.java | 14 +- .../types/BackOrderLine2Collection.java | 1 - .../types/BackOrderLineCollection.java | 1 - .../astoriadefaultservice/types/Car.java | 12 +- .../types/CarCollection.java | 1 - .../types/ComplexToCategory.java | 3 +- .../types/ComplexWithAllPrimitiveTypes.java | 3 +- .../astoriadefaultservice/types/Computer.java | 13 +- .../types/ComputerCollection.java | 14 - .../types/ComputerDetail.java | 24 +- .../types/ComputerDetailCollection.java | 15 - .../types/ConcurrencyInfo.java | 3 +- .../types/ContactDetails.java | 7 +- .../astoriadefaultservice/types/Contractor.java | 16 +- .../types/ContractorCollection.java | 1 - .../astoriadefaultservice/types/Customer.java | 21 +- .../types/CustomerCollection.java | 1 - .../types/CustomerInfo.java | 8 +- .../types/CustomerInfoCollection.java | 1 - .../astoriadefaultservice/types/Dimensions.java | 3 +- .../types/DiscontinuedProduct.java | 30 +- .../types/DiscontinuedProductCollection.java | 1 - .../astoriadefaultservice/types/Driver.java | 8 +- .../types/DriverCollection.java | 1 - .../astoriadefaultservice/types/Employee.java | 19 +- .../types/EmployeeCollection.java | 11 +- .../astoriadefaultservice/types/LastLogin.java | 12 +- .../types/LastLoginCollection.java | 1 - .../astoriadefaultservice/types/License.java | 14 +- .../types/LicenseCollection.java | 1 - .../astoriadefaultservice/types/Login.java | 8 +- .../types/LoginCollection.java | 1 - .../types/MappedEntityType.java | 47 +- .../types/MappedEntityTypeCollection.java | 1 - .../astoriadefaultservice/types/Message.java | 18 +- .../types/MessageAttachment.java | 8 +- .../types/MessageAttachmentCollection.java | 1 - .../types/MessageCollection.java | 1 - .../astoriadefaultservice/types/MessageKey.java | 1 - .../astoriadefaultservice/types/Order.java | 11 +- .../types/OrderCollection.java | 1 - .../astoriadefaultservice/types/OrderLine.java | 14 +- .../types/OrderLineCollection.java | 1 - .../types/OrderLineKey.java | 1 - .../astoriadefaultservice/types/PageView.java | 14 +- .../types/PageViewCollection.java | 1 - .../astoriadefaultservice/types/Person.java | 8 +- .../types/PersonCollection.java | 1 - .../types/PersonMetadata.java | 12 +- .../types/PersonMetadataCollection.java | 1 - .../astoriadefaultservice/types/Phone.java | 3 +- .../astoriadefaultservice/types/Product.java | 26 +- .../types/ProductCollection.java | 14 - .../types/ProductDetail.java | 8 +- .../types/ProductDetailCollection.java | 1 - .../types/ProductPageView.java | 18 +- .../types/ProductPageViewCollection.java | 1 - .../types/ProductPhoto.java | 10 +- .../types/ProductPhotoCollection.java | 1 - .../types/ProductPhotoKey.java | 1 - .../types/ProductReview.java | 12 +- .../types/ProductReviewCollection.java | 1 - .../types/ProductReviewKey.java | 1 - .../astoriadefaultservice/types/RSAToken.java | 8 +- .../types/RSATokenCollection.java | 1 - .../types/SpecialEmployee.java | 20 +- .../types/SpecialEmployeeCollection.java | 1 - .../proxy/v4/AuthEntityRetrieveTestITCase.java | 2 +- .../services/odatawcfservice/Accounts.java | 1 - .../odata/services/odatawcfservice/Boss.java | 1 - .../odata/services/odatawcfservice/Company.java | 1 - .../services/odatawcfservice/Customers.java | 1 - .../odatawcfservice/DefaultStoredPI.java | 1 - .../services/odatawcfservice/Departments.java | 1 - .../services/odatawcfservice/Employees.java | 1 - .../odatawcfservice/InMemoryEntities.java | 1 - .../services/odatawcfservice/LabourUnion.java | 1 - .../services/odatawcfservice/OrderDetails.java | 1 - .../odata/services/odatawcfservice/Orders.java | 1 - .../odata/services/odatawcfservice/People.java | 1 - .../odatawcfservice/ProductDetails.java | 1 - .../odatawcfservice/ProductReviews.java | 1 - .../services/odatawcfservice/Products.java | 1 - .../services/odatawcfservice/PublicCompany.java | 1 - .../services/odatawcfservice/StoredPIs.java | 1 - .../odatawcfservice/SubscriptionTemplates.java | 1 - .../services/odatawcfservice/VipCustomer.java | 1 - .../services/odatawcfservice/types/Account.java | 11 +- .../types/AccountCollection.java | 28 -- .../odatawcfservice/types/AccountInfo.java | 3 +- .../services/odatawcfservice/types/Address.java | 3 +- .../services/odatawcfservice/types/Asset.java | 10 +- .../odatawcfservice/types/AssetCollection.java | 1 - .../services/odatawcfservice/types/Club.java | 8 +- .../odatawcfservice/types/ClubCollection.java | 1 - .../services/odatawcfservice/types/Company.java | 15 +- .../odatawcfservice/types/CompanyAddress.java | 3 +- .../types/CompanyCollection.java | 21 - .../odatawcfservice/types/CreditCardPI.java | 20 +- .../types/CreditCardPICollection.java | 1 - .../odatawcfservice/types/CreditRecord.java | 12 +- .../types/CreditRecordCollection.java | 1 - .../odatawcfservice/types/Customer.java | 27 +- .../types/CustomerCollection.java | 1 - .../odatawcfservice/types/Department.java | 8 +- .../types/DepartmentCollection.java | 1 - .../odatawcfservice/types/Employee.java | 25 +- .../types/EmployeeCollection.java | 1 - .../odatawcfservice/types/GiftCard.java | 12 +- .../types/GiftCardCollection.java | 15 - .../odatawcfservice/types/HomeAddress.java | 3 +- .../odatawcfservice/types/LabourUnion.java | 8 +- .../types/LabourUnionCollection.java | 1 - .../services/odatawcfservice/types/Order.java | 12 +- .../odatawcfservice/types/OrderCollection.java | 1 - .../odatawcfservice/types/OrderDetail.java | 14 +- .../types/OrderDetailCollection.java | 1 - .../odatawcfservice/types/OrderDetailKey.java | 1 - .../types/PaymentInstrument.java | 10 +- .../types/PaymentInstrumentCollection.java | 1 - .../services/odatawcfservice/types/Person.java | 21 +- .../odatawcfservice/types/PersonCollection.java | 22 - .../services/odatawcfservice/types/Product.java | 22 +- .../types/ProductCollection.java | 17 +- .../odatawcfservice/types/ProductDetail.java | 12 +- .../types/ProductDetailCollection.java | 14 - .../odatawcfservice/types/ProductDetailKey.java | 1 - .../odatawcfservice/types/ProductReview.java | 16 +- .../types/ProductReviewCollection.java | 1 - .../odatawcfservice/types/ProductReviewKey.java | 1 - .../odatawcfservice/types/PublicCompany.java | 17 +- .../types/PublicCompanyCollection.java | 1 - .../odatawcfservice/types/Statement.java | 12 +- .../types/StatementCollection.java | 1 - .../odatawcfservice/types/StoredPI.java | 12 +- .../types/StoredPICollection.java | 1 - .../odatawcfservice/types/Subscription.java | 14 +- .../types/SubscriptionCollection.java | 1 - .../olingo/fit/v4/AbstractTestITCase.java | 6 +- .../olingo/fit/v4/EntityCreateTestITCase.java | 2 +- .../olingo/fit/v4/EntityRetrieveTestITCase.java | 30 +- .../olingo/fit/v4/KeyAsSegmentTestITCase.java | 9 +- .../olingo/fit/v4/OpenTypeTestITCase.java | 12 +- .../olingo/client/core/edm/EdmClientImpl.java | 6 +- .../olingo/client/core/edm/EdmSchemaImpl.java | 24 +- .../client/core/edm/v3/EdmOperationProxy.java | 10 +- .../olingo/client/core/v3/MetadataTest.java | 33 +- .../client/core/v3/ComputerDetail_-10.json | 29 +- .../core/v3/Product_-10_Dimensions_Width.json | 5 +- .../core/data/AbstractJsonDeserializer.java | 9 +- .../core/data/AbstractJsonSerializer.java | 5 +- 224 files changed, 1378 insertions(+), 1390 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec30775b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java ---------------------------------------------------------------------- diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java index 5b031f2..3ffb6be 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java @@ -48,7 +48,7 @@ import org.apache.olingo.ext.proxy.api.OperationType; import org.apache.olingo.ext.proxy.api.annotations.Operation; import org.apache.olingo.ext.proxy.api.annotations.Parameter; import org.apache.olingo.ext.proxy.utils.ClassUtils; -import org.apache.olingo.ext.proxy.utils.EngineUtils; +import org.apache.olingo.ext.proxy.utils.CoreUtils; abstract class AbstractInvocationHandler> implements InvocationHandler { @@ -171,7 +171,7 @@ abstract class AbstractInvocationHandler typeRef, final Object internal, final EntityContainerInvocationHandler containerHandler) { + super(client, containerHandler); this.internal = internal; this.typeRef = typeRef; @@ -78,7 +79,8 @@ public abstract class AbstractTypeInvocationHandler typeRef, final Object internal, final EntityTypeInvocationHandler targetHandler) { - super(client, targetHandler.containerHandler); + + super(client, targetHandler == null ? null : targetHandler.containerHandler); this.internal = internal; this.typeRef = typeRef; this.targetHandler = targetHandler; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec30775b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexTypeInvocationHandler.java ---------------------------------------------------------------------- diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexTypeInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexTypeInvocationHandler.java index 05aa7ff..76bfe7f 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexTypeInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexTypeInvocationHandler.java @@ -38,7 +38,7 @@ import org.apache.olingo.ext.proxy.api.annotations.NavigationProperty; import org.apache.olingo.ext.proxy.api.annotations.Property; import org.apache.olingo.ext.proxy.context.AttachedEntityStatus; import org.apache.olingo.ext.proxy.utils.ClassUtils; -import org.apache.olingo.ext.proxy.utils.EngineUtils; +import org.apache.olingo.ext.proxy.utils.CoreUtils; public class ComplexTypeInvocationHandler> extends AbstractTypeInvocationHandler { @@ -51,15 +51,16 @@ public class ComplexTypeInvocationHandler typeRef, final EntityTypeInvocationHandler handler) { - return new ComplexTypeInvocationHandler(complex, typeRef, handler); + return new ComplexTypeInvocationHandler(handler.targetHandler.getClient(), complex, typeRef, handler); } - private ComplexTypeInvocationHandler( + public ComplexTypeInvocationHandler( + final C client, final ODataComplexValue complex, final Class typeRef, final EntityTypeInvocationHandler handler) { - super(handler.containerHandler.getClient(), typeRef, complex, handler); + super(client, typeRef, complex, handler); } public void setComplex(final ODataComplexValue complex) { @@ -84,13 +85,12 @@ public class ComplexTypeInvocationHandler[] {(Class) type}, newComplex(name, (Class) type)); - EngineUtils.populate( + CoreUtils.populate( client.getCachedEdm(), res, (Class) type, @@ -98,8 +98,8 @@ public class ComplexTypeInvocationHandler property : handler.getLinkChanges().entrySet()) { @@ -409,7 +409,7 @@ class ContainerImpl implements Container { final URI targetURI = currentStatus == AttachedEntityStatus.NEW ? URI.create("$" + startingPos) : URIUtils.getURI( factory.getServiceRoot(), - EngineUtils.getEditMediaLink(streamedChanges.getKey(), entity).toASCIIString()); + CoreUtils.getEditMediaLink(streamedChanges.getKey(), entity).toASCIIString()); batchUpdateMediaResource(handler, targetURI, streamedChanges.getValue(), changeset); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec30775b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java ---------------------------------------------------------------------- diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java index 244db50..9b14fd1 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java @@ -221,7 +221,7 @@ class EntitySetInvocationHandler, T ext } @Override - public T get(KEY key) throws IllegalArgumentException { + public T get(final KEY key) throws IllegalArgumentException { return get(key, typeRef); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec30775b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityTypeInvocationHandler.java ---------------------------------------------------------------------- diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityTypeInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityTypeInvocationHandler.java index 7c4ea37..242e853 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityTypeInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityTypeInvocationHandler.java @@ -38,6 +38,7 @@ import org.apache.olingo.client.core.uri.URIUtils; import org.apache.olingo.commons.api.domain.CommonODataEntity; import org.apache.olingo.commons.api.domain.CommonODataProperty; import org.apache.olingo.commons.api.domain.ODataLinked; +import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.format.ODataMediaFormat; import org.apache.olingo.ext.proxy.api.annotations.EntityType; @@ -45,7 +46,7 @@ import org.apache.olingo.ext.proxy.api.annotations.NavigationProperty; import org.apache.olingo.ext.proxy.api.annotations.Property; import org.apache.olingo.ext.proxy.context.AttachedEntityStatus; import org.apache.olingo.ext.proxy.context.EntityUUID; -import org.apache.olingo.ext.proxy.utils.EngineUtils; +import org.apache.olingo.ext.proxy.utils.CoreUtils; public class EntityTypeInvocationHandler> extends AbstractTypeInvocationHandler { @@ -106,7 +107,7 @@ public class EntityTypeInvocationHandler[] {(Class) type}, newComplex(name, (Class) type)); - EngineUtils.populate( + CoreUtils.populate( client.getCachedEdm(), res, (Class) type, Property.class, property.getValue().asComplex().iterator()); } else { - res = type == null - ? EngineUtils.getValueFromProperty(client.getCachedEdm(), property) - : EngineUtils.getValueFromProperty(client.getCachedEdm(), property, type); + ? CoreUtils.getValueFromProperty(client, property) + : CoreUtils.getValueFromProperty(client, property, type); if (res != null) { addPropertyChanges(name, res, false); @@ -257,7 +257,7 @@ public class EntityTypeInvocationHandler client, final EdmTypeInfo type, final Object obj) { + + final ODataValue value; + + if (type.isCollection()) { + value = client.getObjectFactory().newCollectionValue(type.getFullQualifiedName().toString()); + + final EdmTypeInfo intType = new EdmTypeInfo.Builder(). + setEdm(client.getCachedEdm()).setTypeExpression(type.getFullQualifiedName().toString()).build(); + + for (Object collectionItem : (Collection) obj) { + if (intType.isPrimitiveType()) { + value.asCollection().add(getODataValue(client, intType, collectionItem).asPrimitive()); + } else if (intType.isComplexType()) { + value.asCollection().add(getODataValue(client, intType, collectionItem).asComplex()); + } else if (intType.isEnumType()) { + if (client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) { + throw new UnsupportedInV3Exception(); + } else { + value.asCollection().add(((org.apache.olingo.commons.api.domain.v4.ODataValue) getODataValue( + client, intType, collectionItem)).asEnum()); + } + + } else { + throw new UnsupportedOperationException("Usupported object type " + intType.getFullQualifiedName()); + } + } + } else if (type.isComplexType()) { + value = client.getObjectFactory().newComplexValue(type.getFullQualifiedName().toString()); + + if (obj instanceof ComplexTypeInvocationHandler) { + final Class typeRef = ((ComplexTypeInvocationHandler)obj).getTypeRef(); + final Object complex = Proxy.newProxyInstance( + Thread.currentThread().getContextClassLoader(), + new Class[] {typeRef}, + (ComplexTypeInvocationHandler)obj); + + for (Method method : typeRef.getMethods()) { + final Property complexPropertyAnn = method.getAnnotation(Property.class); + try { + if (complexPropertyAnn != null) { + value.asComplex().add(getODataComplexProperty( + client, type.getFullQualifiedName(), complexPropertyAnn.name(), method.invoke(complex))); + } + } catch (Exception ignore) { + // ignore value + LOG.warn("Error attaching complex field '{}'", complexPropertyAnn.name(), ignore); + } + } + } else { + throw new IllegalArgumentException( + "Object '" + obj.getClass().getSimpleName() + "' is not a complex value"); + } + } else if (type.isEnumType()) { + if (client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) { + throw new UnsupportedInV3Exception(); + } else { + value = ((org.apache.olingo.commons.api.domain.v4.ODataObjectFactory) client.getObjectFactory()). + newEnumValue(type.getFullQualifiedName().toString(), ((Enum) obj).name()); + } + } else { + value = client.getObjectFactory().newPrimitiveValueBuilder().setType(type.getPrimitiveTypeKind()).setValue(obj). + build(); + } + + return value; + } + + private static CommonODataProperty getODataProperty( + final CommonEdmEnabledODataClient client, + final FullQualifiedName entity, + final String property, + final Object obj) { + + final EdmType edmType = client.getCachedEdm().getEntityType(entity).getProperty(property).getType(); + final EdmTypeInfo type = new EdmTypeInfo.Builder(). + setEdm(client.getCachedEdm()).setTypeExpression(edmType.getFullQualifiedName().toString()).build(); + + return getODataProperty(client, property, type, obj); + } + + private static CommonODataProperty getODataComplexProperty( + final CommonEdmEnabledODataClient client, + final FullQualifiedName complex, + final String property, + final Object obj) { + + final EdmType edmType = client.getCachedEdm().getComplexType(complex).getProperty(property).getType(); + final EdmTypeInfo type = new EdmTypeInfo.Builder(). + setEdm(client.getCachedEdm()).setTypeExpression(edmType.getFullQualifiedName().toString()).build(); + + return getODataProperty(client, property, type, obj); + } + + public static CommonODataProperty getODataProperty( + final CommonEdmEnabledODataClient client, final String name, final EdmTypeInfo type, final Object obj) { + + CommonODataProperty oprop; + + try { + if (type == null || obj == null) { + oprop = client.getObjectFactory().newPrimitiveProperty(name, null); + } else if (type.isCollection()) { + // create collection property + oprop = client.getObjectFactory().newCollectionProperty(name, getODataValue(client, type, obj).asCollection()); + } else if (type.isPrimitiveType()) { + // create a primitive property + oprop = client.getObjectFactory().newPrimitiveProperty(name, getODataValue(client, type, obj).asPrimitive()); + } else if (type.isComplexType()) { + // create a complex property + oprop = client.getObjectFactory().newComplexProperty(name, getODataValue(client, type, obj).asComplex()); + } else if (type.isEnumType()) { + if (client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) { + throw new UnsupportedInV3Exception(); + } else { + oprop = ((org.apache.olingo.commons.api.domain.v4.ODataObjectFactory) client.getObjectFactory()). + newEnumProperty(name, + ((org.apache.olingo.commons.api.domain.v4.ODataValue) getODataValue(client, type, obj)). + asEnum()); + } + } else { + throw new UnsupportedOperationException("Usupported object type " + type.getFullQualifiedName()); + } + + return oprop; + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + @SuppressWarnings("unchecked") + public static void addProperties( + final CommonEdmEnabledODataClient client, + final Map changes, + final CommonODataEntity entity) { + + for (Map.Entry property : changes.entrySet()) { + // if the getter exists and it is annotated as expected then get value/value and add a new property + final CommonODataProperty odataProperty = entity.getProperty(property.getKey()); + if (odataProperty != null) { + entity.getProperties().remove(odataProperty); + } + + ((List) entity.getProperties()).add( + getODataProperty(client, entity.getTypeName(), property.getKey(), property.getValue())); + } + } + + private static Object primitiveValueToObject(final ODataPrimitiveValue value) { + Object obj; + + try { + obj = value.toValue() instanceof Timestamp + ? value.toCastValue(Calendar.class) + : value.toValue(); + } catch (EdmPrimitiveTypeException e) { + LOG.warn("Could not read temporal value as Calendar, reverting to Timestamp", e); + obj = value.toValue(); + } + + return obj; + } + + private static void setPropertyValue(final Object bean, final Method getter, final Object value) + throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + + // Assumption: setter is always prefixed by 'set' word + final String setterName = getter.getName().replaceFirst("get", "set"); + bean.getClass().getMethod(setterName, getter.getReturnType()).invoke(bean, value); + } + + public static Object getKey( + final Edm metadata, final Class entityTypeRef, final CommonODataEntity entity) { + + Object res = null; + + if (!entity.getProperties().isEmpty()) { + final Class keyRef = ClassUtils.getCompoundKeyRef(entityTypeRef); + if (keyRef == null) { + final CommonODataProperty property = entity.getProperty(firstValidEntityKey(entityTypeRef)); + if (property != null && property.hasPrimitiveValue()) { + res = primitiveValueToObject(property.getPrimitiveValue()); + } + } else { + try { + res = keyRef.newInstance(); + populate(metadata, res, CompoundKeyElement.class, entity.getProperties().iterator()); + } catch (Exception e) { + LOG.error("Error population compound key {}", keyRef.getSimpleName(), e); + throw new IllegalArgumentException("Cannot populate compound key"); + } + } + } + + return res; + } + + public static void populate( + final Edm metadata, + final Object bean, + final Class getterAnn, + final Iterator propItor) { + + if (bean != null) { + populate(metadata, bean, bean.getClass(), getterAnn, propItor); + } + } + + @SuppressWarnings({"unchecked"}) + public static void populate( + final Edm metadata, + final Object bean, + final Class reference, + final Class getterAnn, + final Iterator propItor) { + + if (bean != null) { + while (propItor.hasNext()) { + final CommonODataProperty property = propItor.next(); + + final Method getter = ClassUtils.findGetterByAnnotatedName(reference, getterAnn, property.getName()); + + if (getter == null) { + LOG.warn("Could not find any property annotated as {} in {}", + property.getName(), bean.getClass().getName()); + } else { + try { + if (property.hasNullValue()) { + setPropertyValue(bean, getter, null); + } + if (property.hasPrimitiveValue()) { + setPropertyValue(bean, getter, primitiveValueToObject(property.getPrimitiveValue())); + } + if (property.hasComplexValue()) { + final Object complex = getter.getReturnType().newInstance(); + populate(metadata, complex, Property.class, property.getValue().asComplex().iterator()); + setPropertyValue(bean, getter, complex); + } + if (property.hasCollectionValue()) { + final ParameterizedType collType = (ParameterizedType) getter.getGenericReturnType(); + final Class collItemClass = (Class) collType.getActualTypeArguments()[0]; + + Collection collection = (Collection) getter.invoke(bean); + if (collection == null) { + collection = new ArrayList(); + setPropertyValue(bean, getter, collection); + } + + final Iterator collPropItor = property.getValue().asCollection().iterator(); + while (collPropItor.hasNext()) { + final ODataValue value = collPropItor.next(); + if (value.isPrimitive()) { + collection.add(primitiveValueToObject(value.asPrimitive())); + } + if (value.isComplex()) { + final Object collItem = collItemClass.newInstance(); + populate(metadata, collItem, Property.class, value.asComplex().iterator()); + collection.add(collItem); + } + } + } + } catch (Exception e) { + LOG.error("Could not set property {} on {}", getter, bean, e); + } + } + } + } + } + + @SuppressWarnings("unchecked") + public static Object getValueFromProperty( + final CommonEdmEnabledODataClient client, final CommonODataProperty property) + throws InstantiationException, IllegalAccessException { + + final Object value; + + if (property == null || property.hasNullValue()) { + value = null; + } else if (property.hasCollectionValue()) { + value = new ArrayList(); + + final Iterator collPropItor = property.getValue().asCollection().iterator(); + while (collPropItor.hasNext()) { + final ODataValue odataValue = collPropItor.next(); + if (odataValue.isPrimitive()) { + ((Collection) value).add(primitiveValueToObject(odataValue.asPrimitive())); + } + if (odataValue.isComplex()) { + final Object collItem = + buildComplexInstance(client.getCachedEdm(), property.getName(), odataValue.asComplex().iterator()); + ((Collection) value).add(collItem); + } + } + } else if (property.hasPrimitiveValue()) { + value = primitiveValueToObject(property.getPrimitiveValue()); + } else if (property.hasComplexValue()) { + value = buildComplexInstance(client.getCachedEdm(), property.getValue().asComplex().getTypeName(), + property.getValue().asComplex().iterator()); + } else { + throw new IllegalArgumentException("Invalid property " + property); + } + + return value; + } + + @SuppressWarnings("unchecked") + private static C buildComplexInstance( + final Edm metadata, final String name, final Iterator properties) { + + for (C complex : (Iterable) ServiceLoader.load(AbstractComplexType.class)) { + final ComplexType ann = complex.getClass().getAnnotation(ComplexType.class); + final String fn = ann == null ? null : ClassUtils.getNamespace(complex.getClass()) + "." + ann.name(); + + if (name.equals(fn)) { + populate(metadata, complex, Property.class, properties); + return complex; + } + } + + return null; + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + public static Object getValueFromProperty( + final CommonEdmEnabledODataClient client, final CommonODataProperty property, final Type type) + throws InstantiationException, IllegalAccessException { + + final Object value; + + if (property == null || property.hasNullValue()) { + value = null; + } else if (property.hasCollectionValue()) { + value = new ArrayList(); + + final ParameterizedType collType = (ParameterizedType) type; + final Class collItemClass = (Class) collType.getActualTypeArguments()[0]; + + final Iterator collPropItor = property.getValue().asCollection().iterator(); + while (collPropItor.hasNext()) { + final ODataValue odataValue = collPropItor.next(); + if (odataValue.isPrimitive()) { + ((Collection) value).add(primitiveValueToObject(odataValue.asPrimitive())); + } + if (odataValue.isComplex()) { + final Object collItem = Proxy.newProxyInstance( + Thread.currentThread().getContextClassLoader(), + new Class[] {collItemClass}, + new ComplexTypeInvocationHandler(client, odataValue.asComplex(), collItemClass, null)); + populate(client.getCachedEdm(), collItem, Property.class, odataValue.asComplex().iterator()); + ((Collection) value).add(collItem); + } + } + } else if (property.hasPrimitiveValue()) { + value = primitiveValueToObject(property.getPrimitiveValue()); + } else { + throw new IllegalArgumentException("Invalid property " + property); + } + + return value; + } + + private static String firstValidEntityKey(final Class entityTypeRef) { + for (Method method : entityTypeRef.getDeclaredMethods()) { + if (method.getAnnotation(Key.class) != null) { + final Annotation ann = method.getAnnotation(Property.class); + if (ann != null) { + return ((Property) ann).name(); + } + } + } + return null; + } + + public static URI getEditMediaLink(final String name, final CommonODataEntity entity) { + for (ODataLink editMediaLink : entity.getMediaEditLinks()) { + if (name.equalsIgnoreCase(editMediaLink.getName())) { + return editMediaLink.getLink(); + } + } + + throw new IllegalArgumentException("Invalid streamed property " + name); + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec30775b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/EngineUtils.java ---------------------------------------------------------------------- diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/EngineUtils.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/EngineUtils.java deleted file mode 100644 index 35dc7f8..0000000 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/EngineUtils.java +++ /dev/null @@ -1,439 +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.olingo.ext.proxy.utils; - -import java.lang.annotation.Annotation; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.net.URI; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.ServiceLoader; -import org.apache.olingo.client.api.CommonEdmEnabledODataClient; -import org.apache.olingo.client.api.v3.UnsupportedInV3Exception; -import org.apache.olingo.client.core.edm.xml.AbstractComplexType; -import org.apache.olingo.commons.api.domain.CommonODataEntity; -import org.apache.olingo.commons.api.domain.CommonODataProperty; -import org.apache.olingo.commons.api.domain.ODataLink; -import org.apache.olingo.commons.api.domain.ODataPrimitiveValue; -import org.apache.olingo.commons.api.domain.ODataValue; -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; -import org.apache.olingo.commons.api.edm.EdmType; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; -import org.apache.olingo.commons.core.edm.EdmTypeInfo; -import org.apache.olingo.ext.proxy.api.annotations.ComplexType; -import org.apache.olingo.ext.proxy.api.annotations.CompoundKeyElement; -import org.apache.olingo.ext.proxy.api.annotations.Key; -import org.apache.olingo.ext.proxy.api.annotations.Property; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class EngineUtils { - - /** - * Logger. - */ - private static final Logger LOG = LoggerFactory.getLogger(EngineUtils.class); - - private EngineUtils() { - // Empty private constructor for static utility classes - } - - public static ODataValue getODataValue( - final CommonEdmEnabledODataClient client, final EdmTypeInfo type, final Object obj) { - - final ODataValue value; - - if (type.isCollection()) { - value = client.getObjectFactory().newCollectionValue(type.getFullQualifiedName().toString()); - - final EdmTypeInfo intType = new EdmTypeInfo.Builder(). - setEdm(client.getCachedEdm()).setTypeExpression(type.getFullQualifiedName().toString()).build(); - - for (Object collectionItem : (Collection) obj) { - if (intType.isPrimitiveType()) { - value.asCollection().add(getODataValue(client, intType, collectionItem).asPrimitive()); - } else if (intType.isComplexType()) { - value.asCollection().add(getODataValue(client, intType, collectionItem).asComplex()); - } else if (intType.isEnumType()) { - if (client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) { - throw new UnsupportedInV3Exception(); - } else { - value.asCollection().add(((org.apache.olingo.commons.api.domain.v4.ODataValue) getODataValue( - client, intType, collectionItem)).asEnum()); - } - - } else { - throw new UnsupportedOperationException("Usupported object type " + intType.getFullQualifiedName()); - } - } - } else if (type.isComplexType()) { - value = client.getObjectFactory().newComplexValue(type.getFullQualifiedName().toString()); - - if (obj.getClass().isAnnotationPresent(ComplexType.class)) { - for (Method method : obj.getClass().getMethods()) { - final Property complexPropertyAnn = method.getAnnotation(Property.class); - try { - if (complexPropertyAnn != null) { - value.asComplex().add(getODataComplexProperty( - client, type.getFullQualifiedName(), complexPropertyAnn.name(), method.invoke(obj))); - } - } catch (Exception ignore) { - // ignore value - LOG.warn("Error attaching complex field '{}'", complexPropertyAnn.name(), ignore); - } - } - } else { - throw new IllegalArgumentException( - "Object '" + obj.getClass().getSimpleName() + "' is not a complex value"); - } - } else if (type.isEnumType()) { - if (client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) { - throw new UnsupportedInV3Exception(); - } else { - value = ((org.apache.olingo.commons.api.domain.v4.ODataObjectFactory) client.getObjectFactory()). - newEnumValue(type.getFullQualifiedName().toString(), ((Enum) obj).name()); - } - } else { - value = client.getObjectFactory().newPrimitiveValueBuilder().setType(type.getPrimitiveTypeKind()).setValue(obj). - build(); - } - - return value; - } - - private static CommonODataProperty getODataProperty( - final CommonEdmEnabledODataClient client, - final FullQualifiedName entity, - final String property, - final Object obj) { - - final EdmType edmType = client.getCachedEdm().getEntityType(entity).getProperty(property).getType(); - final EdmTypeInfo type = new EdmTypeInfo.Builder(). - setEdm(client.getCachedEdm()).setTypeExpression(edmType.getFullQualifiedName().toString()).build(); - - return getODataProperty(client, property, type, obj); - } - - private static CommonODataProperty getODataComplexProperty( - final CommonEdmEnabledODataClient client, - final FullQualifiedName complex, - final String property, - final Object obj) { - - final EdmType edmType = client.getCachedEdm().getComplexType(complex).getProperty(property).getType(); - final EdmTypeInfo type = new EdmTypeInfo.Builder(). - setEdm(client.getCachedEdm()).setTypeExpression(edmType.getFullQualifiedName().toString()).build(); - - return getODataProperty(client, property, type, obj); - } - - public static CommonODataProperty getODataProperty( - final CommonEdmEnabledODataClient client, final String name, final EdmTypeInfo type, final Object obj) { - - CommonODataProperty oprop; - - try { - if (type == null || obj == null) { - oprop = client.getObjectFactory().newPrimitiveProperty(name, null); - } else if (type.isCollection()) { - // create collection property - oprop = client.getObjectFactory().newCollectionProperty(name, getODataValue(client, type, obj).asCollection()); - } else if (type.isPrimitiveType()) { - // create a primitive property - oprop = client.getObjectFactory().newPrimitiveProperty(name, getODataValue(client, type, obj).asPrimitive()); - } else if (type.isComplexType()) { - // create a complex property - oprop = client.getObjectFactory().newComplexProperty(name, getODataValue(client, type, obj).asComplex()); - } else if (type.isEnumType()) { - if (client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) { - throw new UnsupportedInV3Exception(); - } else { - oprop = ((org.apache.olingo.commons.api.domain.v4.ODataObjectFactory) client.getObjectFactory()). - newEnumProperty(name, - ((org.apache.olingo.commons.api.domain.v4.ODataValue) getODataValue(client, type, obj)). - asEnum()); - } - } else { - throw new UnsupportedOperationException("Usupported object type " + type.getFullQualifiedName()); - } - - return oprop; - } catch (Exception e) { - throw new IllegalStateException(e); - } - } - - @SuppressWarnings("unchecked") - public static void addProperties( - final CommonEdmEnabledODataClient client, - final Map changes, - final CommonODataEntity entity) { - - for (Map.Entry property : changes.entrySet()) { - // if the getter exists and it is annotated as expected then get value/value and add a new property - final CommonODataProperty odataProperty = entity.getProperty(property.getKey()); - if (odataProperty != null) { - entity.getProperties().remove(odataProperty); - } - - ((List) entity.getProperties()).add( - getODataProperty(client, entity.getTypeName(), property.getKey(), property.getValue())); - } - } - - private static Object primitiveValueToObject(final ODataPrimitiveValue value) { - Object obj; - - try { - obj = value.toValue() instanceof Timestamp - ? value.toCastValue(Calendar.class) - : value.toValue(); - } catch (EdmPrimitiveTypeException e) { - LOG.warn("Could not read temporal value as Calendar, reverting to Timestamp", e); - obj = value.toValue(); - } - - return obj; - } - - private static void setPropertyValue(final Object bean, final Method getter, final Object value) - throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - - // Assumption: setter is always prefixed by 'set' word - final String setterName = getter.getName().replaceFirst("get", "set"); - bean.getClass().getMethod(setterName, getter.getReturnType()).invoke(bean, value); - } - - public static Object getKey( - final Edm metadata, final Class entityTypeRef, final CommonODataEntity entity) { - - Object res = null; - - if (!entity.getProperties().isEmpty()) { - final Class keyRef = ClassUtils.getCompoundKeyRef(entityTypeRef); - if (keyRef == null) { - final CommonODataProperty property = entity.getProperty(firstValidEntityKey(entityTypeRef)); - if (property != null && property.hasPrimitiveValue()) { - res = primitiveValueToObject(property.getPrimitiveValue()); - } - } else { - try { - res = keyRef.newInstance(); - populate(metadata, res, CompoundKeyElement.class, entity.getProperties().iterator()); - } catch (Exception e) { - LOG.error("Error population compound key {}", keyRef.getSimpleName(), e); - throw new IllegalArgumentException("Cannot populate compound key"); - } - } - } - - return res; - } - - public static void populate( - final Edm metadata, - final Object bean, - final Class getterAnn, - final Iterator propItor) { - - if (bean != null) { - populate(metadata, bean, bean.getClass(), getterAnn, propItor); - } - } - - @SuppressWarnings({"unchecked"}) - public static void populate( - final Edm metadata, - final Object bean, - final Class reference, - final Class getterAnn, - final Iterator propItor) { - - if (bean != null) { - while (propItor.hasNext()) { - final CommonODataProperty property = propItor.next(); - - final Method getter = ClassUtils.findGetterByAnnotatedName(reference, getterAnn, property.getName()); - - if (getter == null) { - LOG.warn("Could not find any property annotated as {} in {}", - property.getName(), bean.getClass().getName()); - } else { - try { - if (property.hasNullValue()) { - setPropertyValue(bean, getter, null); - } - if (property.hasPrimitiveValue()) { - setPropertyValue(bean, getter, primitiveValueToObject(property.getPrimitiveValue())); - } - if (property.hasComplexValue()) { - final Object complex = getter.getReturnType().newInstance(); - populate(metadata, complex, Property.class, property.getValue().asComplex().iterator()); - setPropertyValue(bean, getter, complex); - } - if (property.hasCollectionValue()) { - final ParameterizedType collType = (ParameterizedType) getter.getGenericReturnType(); - final Class collItemClass = (Class) collType.getActualTypeArguments()[0]; - - Collection collection = (Collection) getter.invoke(bean); - if (collection == null) { - collection = new ArrayList(); - setPropertyValue(bean, getter, collection); - } - - final Iterator collPropItor = property.getValue().asCollection().iterator(); - while (collPropItor.hasNext()) { - final ODataValue value = collPropItor.next(); - if (value.isPrimitive()) { - collection.add(primitiveValueToObject(value.asPrimitive())); - } - if (value.isComplex()) { - final Object collItem = collItemClass.newInstance(); - populate(metadata, collItem, Property.class, value.asComplex().iterator()); - collection.add(collItem); - } - } - } - } catch (Exception e) { - LOG.error("Could not set property {} on {}", getter, bean, e); - } - } - } - } - } - - @SuppressWarnings("unchecked") - public static Object getValueFromProperty(final Edm metadata, final CommonODataProperty property) - throws InstantiationException, IllegalAccessException { - - final Object value; - - if (property == null || property.hasNullValue()) { - value = null; - } else if (property.hasCollectionValue()) { - value = new ArrayList(); - - final Iterator collPropItor = property.getValue().asCollection().iterator(); - while (collPropItor.hasNext()) { - final ODataValue odataValue = collPropItor.next(); - if (odataValue.isPrimitive()) { - ((Collection) value).add(primitiveValueToObject(odataValue.asPrimitive())); - } - if (odataValue.isComplex()) { - final Object collItem = - buildComplexInstance(metadata, property.getName(), odataValue.asComplex().iterator()); - ((Collection) value).add(collItem); - } - } - } else if (property.hasPrimitiveValue()) { - value = primitiveValueToObject(property.getPrimitiveValue()); - } else if (property.hasComplexValue()) { - value = buildComplexInstance( - metadata, property.getValue().asComplex().getTypeName(), property.getValue().asComplex().iterator()); - } else { - throw new IllegalArgumentException("Invalid property " + property); - } - - return value; - } - - @SuppressWarnings("unchecked") - private static C buildComplexInstance( - final Edm metadata, final String name, final Iterator properties) { - - for (C complex : (Iterable) ServiceLoader.load(AbstractComplexType.class)) { - final ComplexType ann = complex.getClass().getAnnotation(ComplexType.class); - final String fn = ann == null ? null : ClassUtils.getNamespace(complex.getClass()) + "." + ann.name(); - - if (name.equals(fn)) { - populate(metadata, complex, Property.class, properties); - return complex; - } - } - - return null; - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - public static Object getValueFromProperty(final Edm metadata, final CommonODataProperty property, final Type type) - throws InstantiationException, IllegalAccessException { - - final Object value; - - if (property == null || property.hasNullValue()) { - value = null; - } else if (property.hasCollectionValue()) { - value = new ArrayList(); - - final ParameterizedType collType = (ParameterizedType) type; - final Class collItemClass = (Class) collType.getActualTypeArguments()[0]; - - final Iterator collPropItor = property.getValue().asCollection().iterator(); - while (collPropItor.hasNext()) { - final ODataValue odataValue = collPropItor.next(); - if (odataValue.isPrimitive()) { - ((Collection) value).add(primitiveValueToObject(odataValue.asPrimitive())); - } - if (odataValue.isComplex()) { - final Object collItem = collItemClass.newInstance(); - populate(metadata, collItem, Property.class, odataValue.asComplex().iterator()); - ((Collection) value).add(collItem); - } - } - } else if (property.hasPrimitiveValue()) { - value = primitiveValueToObject(property.getPrimitiveValue()); - } else { - throw new IllegalArgumentException("Invalid property " + property); - } - - return value; - } - - private static String firstValidEntityKey(final Class entityTypeRef) { - for (Method method : entityTypeRef.getDeclaredMethods()) { - if (method.getAnnotation(Key.class) != null) { - final Annotation ann = method.getAnnotation(Property.class); - if (ann != null) { - return ((Property) ann).name(); - } - } - } - return null; - } - - public static URI getEditMediaLink(final String name, final CommonODataEntity entity) { - for (ODataLink editMediaLink : entity.getMediaEditLinks()) { - if (name.equalsIgnoreCase(editMediaLink.getName())) { - return editMediaLink.getLink(); - } - } - - throw new IllegalArgumentException("Invalid streamed property " + name); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec30775b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractMetadataMojo.java ---------------------------------------------------------------------- diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractMetadataMojo.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractMetadataMojo.java index 2347761..065e172 100644 --- a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractMetadataMojo.java +++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractMetadataMojo.java @@ -105,7 +105,6 @@ public abstract class AbstractMetadataMojo extends AbstractMojo { } protected VelocityContext newContext() { - final VelocityContext ctx = new VelocityContext(); ctx.put("utility", getUtility()); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec30775b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractUtility.java ---------------------------------------------------------------------- diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractUtility.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractUtility.java index 1a0ebf2..052f415 100644 --- a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractUtility.java +++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractUtility.java @@ -158,7 +158,6 @@ public abstract class AbstractUtility { } public EdmFunction getFunctionByName(final FullQualifiedName name) { - final EdmSchema targetSchema = metadata.getSchema(name.getNamespace()); if (targetSchema != null) { @@ -173,7 +172,6 @@ public abstract class AbstractUtility { } public EdmAction getActionByName(final FullQualifiedName name) { - final EdmSchema targetSchema = metadata.getSchema(name.getNamespace()); if (targetSchema != null) { @@ -188,7 +186,6 @@ public abstract class AbstractUtility { } public List getFunctionsBoundTo(final String typeExpression, final boolean collection) { - final List result = new ArrayList(); for (EdmSchema sch : getMetadata().getSchemas()) { @@ -210,7 +207,6 @@ public abstract class AbstractUtility { } public List getActionsBoundTo(final String typeExpression, final boolean collection) { - final List result = new ArrayList(); for (EdmSchema sch : getMetadata().getSchemas()) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec30775b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V3MetadataMojo.java ---------------------------------------------------------------------- diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V3MetadataMojo.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V3MetadataMojo.java index 28bcdd0..9ab6f48 100644 --- a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V3MetadataMojo.java +++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V3MetadataMojo.java @@ -47,139 +47,138 @@ import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; @Mojo(name = "pojosV3", defaultPhase = LifecyclePhase.PROCESS_SOURCES) public class V3MetadataMojo extends AbstractMetadataMojo { - @Override - protected V3Utility getUtility() { - return (V3Utility) utility; + @Override + protected V3Utility getUtility() { + return (V3Utility) utility; + } + + @Override + protected String getVersion() { + return ODataServiceVersion.V30.name().toLowerCase(); + } + + @Override + public void execute() throws MojoExecutionException { + if (new File(outputDirectory + File.separator + TOOL_DIR).exists()) { + getLog().info("Nothing to do because " + TOOL_DIR + " directory already exists. Clean to update."); + return; } - @Override - protected String getVersion() { - return ODataServiceVersion.V30.name().toLowerCase(); - } + try { + Velocity.addProperty(Velocity.RESOURCE_LOADER, "class"); + Velocity.addProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName()); + + final Edm metadata = ODataClientFactory.getV3().getRetrieveRequestFactory(). + getMetadataRequest(serviceRootURL).execute().getBody(); + + if (metadata == null) { + throw new IllegalStateException("Metadata not found"); + } + + for (EdmSchema schema : metadata.getSchemas()) { + namespaces.add(schema.getNamespace().toLowerCase()); + } + + final Set complexTypeNames = new HashSet(); + final File services = mkdir("META-INF/services"); + + for (EdmSchema schema : metadata.getSchemas()) { + utility = new V3Utility(metadata, schema, basePackage); + + // write package-info for the base package + final String schemaPath = utility.getNamespace().toLowerCase().replace('.', File.separatorChar); + final File base = mkPkgDir(schemaPath); + final String pkg = basePackage + "." + utility.getNamespace().toLowerCase(); + parseObj(base, pkg, "package-info", "package-info.java"); + + // write package-info for types package + final File typesBaseDir = mkPkgDir(schemaPath + "/types"); + final String typesPkg = pkg + ".types"; + parseObj(typesBaseDir, typesPkg, "package-info", "package-info.java"); - @Override - public void execute() throws MojoExecutionException { - if (new File(outputDirectory + File.separator + TOOL_DIR).exists()) { - getLog().info("Nothing to do because " + TOOL_DIR + " directory already exists. Clean to update."); - return; + final Map objs = new HashMap(); + + // write types into types package + for (EdmEnumType enumType : schema.getEnumTypes()) { + final String className = utility.capitalize(enumType.getName()); + objs.clear(); + objs.put("enumType", enumType); + parseObj(typesBaseDir, typesPkg, "enumType", className + ".java", objs); } - try { - Velocity.addProperty(Velocity.RESOURCE_LOADER, "class"); - Velocity.addProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName()); + for (EdmComplexType complex : schema.getComplexTypes()) { + final String className = utility.capitalize(complex.getName()); + complexTypeNames.add(typesPkg + "." + className); + objs.clear(); + objs.put("complexType", complex); + parseObj(typesBaseDir, typesPkg, "complexType", className + ".java", objs); + } - final Edm metadata = - ODataClientFactory.getV3().getRetrieveRequestFactory().getMetadataRequest(serviceRootURL).execute(). - getBody(); + for (EdmEntityType entity : schema.getEntityTypes()) { + objs.clear(); + objs.put("entityType", entity); - if (metadata == null) { - throw new IllegalStateException("Metadata not found"); - } + final Map keys; - for (EdmSchema schema : metadata.getSchemas()) { - namespaces.add(schema.getNamespace().toLowerCase()); + EdmEntityType baseType = null; + if (entity.getBaseType() == null) { + keys = getUtility().getEntityKeyType(entity); + } else { + baseType = entity.getBaseType(); + objs.put("baseType", getUtility().getJavaType(baseType.getFullQualifiedName().toString())); + while (baseType.getBaseType() != null) { + baseType = baseType.getBaseType(); } - - final Set complexTypeNames = new HashSet(); - final File services = mkdir("META-INF/services"); - - for (EdmSchema schema : metadata.getSchemas()) { - utility = new V3Utility(metadata, schema, basePackage); - - // write package-info for the base package - final String schemaPath = utility.getNamespace().toLowerCase().replace('.', File.separatorChar); - final File base = mkPkgDir(schemaPath); - final String pkg = basePackage + "." + utility.getNamespace().toLowerCase(); - parseObj(base, pkg, "package-info", "package-info.java"); - - // write package-info for types package - final File typesBaseDir = mkPkgDir(schemaPath + "/types"); - final String typesPkg = pkg + ".types"; - parseObj(typesBaseDir, typesPkg, "package-info", "package-info.java"); - - final Map objs = new HashMap(); - - // write types into types package - for (EdmEnumType enumType : schema.getEnumTypes()) { - final String className = utility.capitalize(enumType.getName()); - objs.clear(); - objs.put("enumType", enumType); - parseObj(typesBaseDir, typesPkg, "enumType", className + ".java", objs); - } - - for (EdmComplexType complex : schema.getComplexTypes()) { - final String className = utility.capitalize(complex.getName()); - complexTypeNames.add(typesPkg + "." + className); - objs.clear(); - objs.put("complexType", complex); - parseObj(typesBaseDir, typesPkg, "complexType", className + ".java", objs); - } - - for (EdmEntityType entity : schema.getEntityTypes()) { - objs.clear(); - objs.put("entityType", entity); - - final Map keys; - - EdmEntityType baseType = null; - if (entity.getBaseType() == null) { - keys = getUtility().getEntityKeyType(entity); - } else { - baseType = entity.getBaseType(); - objs.put("baseType", getUtility().getJavaType(baseType.getFullQualifiedName().toString())); - while (baseType.getBaseType() != null) { - baseType = baseType.getBaseType(); - } - keys = getUtility().getEntityKeyType(baseType); - } - - if (keys.size() > 1) { - // create compound key class - final String keyClassName = utility.capitalize(baseType == null - ? entity.getName() - : baseType.getName()) + "Key"; - objs.put("keyRef", keyClassName); - - if (entity.getBaseType() == null) { - objs.put("keys", keys); - parseObj(typesBaseDir, typesPkg, "entityTypeKey", keyClassName + ".java", objs); - } - } - - parseObj(typesBaseDir, typesPkg, "entityType", - utility.capitalize(entity.getName()) + ".java", objs); - parseObj(typesBaseDir, typesPkg, "entityCollection", - utility.capitalize(entity.getName()) + "Collection.java", objs); - } - - // write container and top entity sets into the base package - for (EdmEntityContainer container : schema.getEntityContainers()) { - objs.clear(); - objs.put("container", container); - objs.put("namespace", schema.getNamespace()); - parseObj(base, pkg, "container", - utility.capitalize(container.getName()) + ".java", objs); - - for (EdmEntitySet entitySet : container.getEntitySets()) { - objs.clear(); - objs.put("entitySet", entitySet); - parseObj(base, pkg, "entitySet", - utility.capitalize(entitySet.getName()) + ".java", objs); - } - } - - parseObj(services, true, null, "services", "org.apache.olingo.ext.proxy.api.AbstractComplexType", - Collections.singletonMap("services", (Object) complexTypeNames)); + keys = getUtility().getEntityKeyType(baseType); + } + + if (keys.size() > 1) { + // create compound key class + final String keyClassName = utility.capitalize(baseType == null + ? entity.getName() + : baseType.getName()) + "Key"; + objs.put("keyRef", keyClassName); + + if (entity.getBaseType() == null) { + objs.put("keys", keys); + parseObj(typesBaseDir, typesPkg, "entityTypeKey", keyClassName + ".java", objs); } - } catch (Exception t) { - final StringWriter stringWriter = new StringWriter(); - final PrintWriter printWriter = new PrintWriter(stringWriter); - t.printStackTrace(printWriter); - getLog().error(stringWriter.toString()); - - throw (t instanceof MojoExecutionException) - ? (MojoExecutionException) t - : new MojoExecutionException("While executin mojo", t); + } + + parseObj(typesBaseDir, typesPkg, "entityType", + utility.capitalize(entity.getName()) + ".java", objs); + parseObj(typesBaseDir, typesPkg, "entityCollection", + utility.capitalize(entity.getName()) + "Collection.java", objs); + } + + // write container and top entity sets into the base package + for (EdmEntityContainer container : schema.getEntityContainers()) { + objs.clear(); + objs.put("container", container); + objs.put("namespace", schema.getNamespace()); + parseObj(base, pkg, "container", + utility.capitalize(container.getName()) + ".java", objs); + + for (EdmEntitySet entitySet : container.getEntitySets()) { + objs.clear(); + objs.put("entitySet", entitySet); + parseObj(base, pkg, "entitySet", + utility.capitalize(entitySet.getName()) + ".java", objs); + } } + + parseObj(services, true, null, "services", "org.apache.olingo.ext.proxy.api.AbstractComplexType", + Collections.singletonMap("services", (Object) complexTypeNames)); + } + } catch (Exception t) { + final StringWriter stringWriter = new StringWriter(); + final PrintWriter printWriter = new PrintWriter(stringWriter); + t.printStackTrace(printWriter); + getLog().error(stringWriter.toString()); + + throw (t instanceof MojoExecutionException) + ? (MojoExecutionException) t + : new MojoExecutionException("While executing mojo", t); } + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec30775b/ext/pojogen-maven-plugin/src/main/resources/complexType.vm ---------------------------------------------------------------------- diff --git a/ext/pojogen-maven-plugin/src/main/resources/complexType.vm b/ext/pojogen-maven-plugin/src/main/resources/complexType.vm index 05bc161..ba03282 100644 --- a/ext/pojogen-maven-plugin/src/main/resources/complexType.vm +++ b/ext/pojogen-maven-plugin/src/main/resources/complexType.vm @@ -27,7 +27,6 @@ import ${basePackage}.${ns}.*; import ${basePackage}.${ns}.types.*; #end -// EdmSimpleType property imports import org.apache.olingo.commons.api.edm.geo.Geospatial; import org.apache.olingo.commons.api.edm.geo.GeospatialCollection; import org.apache.olingo.commons.api.edm.geo.LineString; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec30775b/ext/pojogen-maven-plugin/src/main/resources/container.vm ---------------------------------------------------------------------- diff --git a/ext/pojogen-maven-plugin/src/main/resources/container.vm b/ext/pojogen-maven-plugin/src/main/resources/container.vm index 40fc44a..0692ad6 100644 --- a/ext/pojogen-maven-plugin/src/main/resources/container.vm +++ b/ext/pojogen-maven-plugin/src/main/resources/container.vm @@ -31,7 +31,6 @@ import ${basePackage}.${ns}.*; import ${basePackage}.${ns}.types.*; #end -// EdmSimpleType property imports import org.apache.olingo.commons.api.edm.geo.Geospatial; import org.apache.olingo.commons.api.edm.geo.GeospatialCollection; import org.apache.olingo.commons.api.edm.geo.LineString; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec30775b/ext/pojogen-maven-plugin/src/main/resources/entityCollection.vm ---------------------------------------------------------------------- diff --git a/ext/pojogen-maven-plugin/src/main/resources/entityCollection.vm b/ext/pojogen-maven-plugin/src/main/resources/entityCollection.vm index b48e2de..c2d49c8 100644 --- a/ext/pojogen-maven-plugin/src/main/resources/entityCollection.vm +++ b/ext/pojogen-maven-plugin/src/main/resources/entityCollection.vm @@ -28,7 +28,6 @@ import ${basePackage}.${ns}.*; import ${basePackage}.${ns}.types.*; #end -// EdmSimpleType property imports import org.apache.olingo.commons.api.edm.geo.Geospatial; import org.apache.olingo.commons.api.edm.geo.GeospatialCollection; import org.apache.olingo.commons.api.edm.geo.LineString; @@ -46,8 +45,8 @@ import java.util.Calendar; import javax.xml.datatype.Duration; public interface $utility.capitalize($entityType.Name)Collection extends AbstractEntityCollection<$utility.capitalize($entityType.Name)> { -#set( $functions = $utility.getFunctionsBoundTo($entityType.Name, false) ) -#set( $actions = $utility.getActionsBoundTo($entityType.Name, false) ) +#set( $functions = $utility.getFunctionsBoundTo($entityType.Name, true) ) +#set( $actions = $utility.getActionsBoundTo($entityType.Name, true) ) #if( $functions.size() > 0 || $actions.size() > 0 ) Operations operations(); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec30775b/ext/pojogen-maven-plugin/src/main/resources/entitySet.vm ---------------------------------------------------------------------- diff --git a/ext/pojogen-maven-plugin/src/main/resources/entitySet.vm b/ext/pojogen-maven-plugin/src/main/resources/entitySet.vm index 378eb8f..e98ed97 100644 --- a/ext/pojogen-maven-plugin/src/main/resources/entitySet.vm +++ b/ext/pojogen-maven-plugin/src/main/resources/entitySet.vm @@ -27,7 +27,6 @@ import ${basePackage}.${ns}.*; import ${basePackage}.${ns}.types.*; #end -// EdmSimpleType property imports import org.apache.olingo.commons.api.edm.geo.Geospatial; import org.apache.olingo.commons.api.edm.geo.GeospatialCollection; import org.apache.olingo.commons.api.edm.geo.LineString; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec30775b/ext/pojogen-maven-plugin/src/main/resources/entityType.vm ---------------------------------------------------------------------- diff --git a/ext/pojogen-maven-plugin/src/main/resources/entityType.vm b/ext/pojogen-maven-plugin/src/main/resources/entityType.vm index e5873a1..3386d6b 100644 --- a/ext/pojogen-maven-plugin/src/main/resources/entityType.vm +++ b/ext/pojogen-maven-plugin/src/main/resources/entityType.vm @@ -37,7 +37,6 @@ import ${basePackage}.${ns}.*; import ${basePackage}.${ns}.types.*; #end -// EdmSimpleType property imports import org.apache.olingo.commons.api.edm.geo.Geospatial; import org.apache.olingo.commons.api.edm.geo.GeospatialCollection; import org.apache.olingo.commons.api.edm.geo.LineString; @@ -95,7 +94,7 @@ public interface $utility.capitalize($entityType.Name) fcKeepInContent = #if($fcprops.containsKey("fcKeepInContent"))$fcprops.get("fcKeepInContent")#{else}false#end) $utility.getJavaType($property.Type, $property.Collection) get$utility.capitalize($property.Name)(); - void set$utility.capitalize($property.Name)(final $utility.getJavaType($property.Type, $property.Collection) _$utility.uncapitalize($property.Name)); + void set$utility.capitalize($property.Name)(final $utility.getJavaType($property.Type, $property.Collection) _$utility.uncapitalize($property.Name)); #if($utility.isComplex($property.Type.FullQualifiedName))#* *#$utility.getJavaType($property.Type) new$utility.capitalize($property.Name)(); #end http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec30775b/ext/pojogen-maven-plugin/src/main/resources/entityTypeKey.vm ---------------------------------------------------------------------- diff --git a/ext/pojogen-maven-plugin/src/main/resources/entityTypeKey.vm b/ext/pojogen-maven-plugin/src/main/resources/entityTypeKey.vm index fe6b7f3..143ae5e 100644 --- a/ext/pojogen-maven-plugin/src/main/resources/entityTypeKey.vm +++ b/ext/pojogen-maven-plugin/src/main/resources/entityTypeKey.vm @@ -32,7 +32,6 @@ import ${basePackage}.${ns}.*; import ${basePackage}.${ns}.types.*; #end -// EdmSimpleType property imports import org.apache.olingo.commons.api.edm.geo.Geospatial; import org.apache.olingo.commons.api.edm.geo.GeospatialCollection; import org.apache.olingo.commons.api.edm.geo.LineString;