http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8865db8/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java ---------------------------------------------------------------------- diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java index 2a23b11..b7285be 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * 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 - * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -28,11 +28,13 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; + import org.apache.commons.lang3.StringUtils; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataMediaRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.client.api.uri.CommonURIBuilder; +import org.apache.olingo.commons.api.ODataRuntimeException; import org.apache.olingo.commons.api.domain.CommonODataEntity; import org.apache.olingo.commons.api.domain.CommonODataProperty; import org.apache.olingo.commons.api.domain.v4.ODataAnnotation; @@ -57,72 +59,72 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler private static final long serialVersionUID = 2629912294765040037L; private final Map<Class<? extends AbstractTerm>, Object> annotations = - new HashMap<Class<? extends AbstractTerm>, Object>(); + new HashMap<Class<? extends AbstractTerm>, Object>(); private EdmStreamValue stream; private EntityUUID uuid; static EntityInvocationHandler getInstance( - final CommonODataEntity entity, - final EntitySetInvocationHandler<?, ?, ?> entitySet, - final Class<?> typeRef) { + final CommonODataEntity entity, + final EntitySetInvocationHandler<?, ?, ?> entitySet, + final Class<?> typeRef) { return new EntityInvocationHandler( - null, - entity, - entitySet.getURI(), - typeRef, - entitySet.service); + null, + entity, + entitySet.getURI(), + typeRef, + entitySet.service); } static EntityInvocationHandler getInstance( - final Object key, - final CommonODataEntity entity, - final URI entitySetURI, - final Class<?> typeRef, - final AbstractService<?> service) { + final Object key, + final CommonODataEntity entity, + final URI entitySetURI, + final Class<?> typeRef, + final AbstractService<?> service) { return new EntityInvocationHandler(key, entity, entitySetURI, typeRef, service); } public static EntityInvocationHandler getInstance( - final CommonODataEntity entity, - final URI entitySetURI, - final Class<?> typeRef, - final AbstractService<?> service) { + final CommonODataEntity entity, + final URI entitySetURI, + final Class<?> typeRef, + final AbstractService<?> service) { return new EntityInvocationHandler(null, entity, entitySetURI, typeRef, service); } public static EntityInvocationHandler getInstance( - final CommonODataEntity entity, - final URI entitySetURI, - final URI entityURI, - final Class<?> typeRef, - final AbstractService<?> service) { + final CommonODataEntity entity, + final URI entitySetURI, + final URI entityURI, + final Class<?> typeRef, + final AbstractService<?> service) { return new EntityInvocationHandler(entity, entityURI, entitySetURI, typeRef, service); } public static EntityInvocationHandler getInstance( - final URI entityURI, - final Class<?> typeRef, - final AbstractService<?> service) { + final URI entityURI, + final Class<?> typeRef, + final AbstractService<?> service) { return new EntityInvocationHandler(entityURI, typeRef, service); } public static EntityInvocationHandler getInstance( - final Class<?> typeRef, - final AbstractService<?> service) { + final Class<?> typeRef, + final AbstractService<?> service) { return new EntityInvocationHandler(typeRef, service); } private EntityInvocationHandler( - final Class<?> typeRef, - final AbstractService<?> service) { + final Class<?> typeRef, + final AbstractService<?> service) { super(typeRef, service); @@ -136,9 +138,9 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler } private EntityInvocationHandler( - final URI entityURI, - final Class<?> typeRef, - final AbstractService<?> service) { + final URI entityURI, + final Class<?> typeRef, + final AbstractService<?> service) { super(typeRef, service); @@ -155,11 +157,11 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler } private EntityInvocationHandler( - final CommonODataEntity entity, - final URI entitySetURI, - final URI entityURI, - final Class<?> typeRef, - final AbstractService<?> service) { + final CommonODataEntity entity, + final URI entitySetURI, + final URI entityURI, + final Class<?> typeRef, + final AbstractService<?> service) { super(typeRef, entity, service); if (entityURI != null) { @@ -177,11 +179,11 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler } private EntityInvocationHandler( - final Object entityKey, - final CommonODataEntity entity, - final URI entitySetURI, - final Class<?> typeRef, - final AbstractService<?> service) { + final Object entityKey, + final CommonODataEntity entity, + final URI entitySetURI, + final Class<?> typeRef, + final AbstractService<?> service) { super(typeRef, entity, service); @@ -192,7 +194,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler this.uri = getClient().newURIBuilder(baseURI.toASCIIString()); } else if (key != null) { final CommonURIBuilder<?> uriBuilder = - CoreUtils.buildEditLink(getClient(), entitySetURI.toASCIIString(), entity, key); + CoreUtils.buildEditLink(getClient(), entitySetURI.toASCIIString(), entity, key); this.uri = uriBuilder; this.baseURI = this.uri.build(); @@ -219,7 +221,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler // fix for OLINGO-353 if (this.uri == null) { final CommonURIBuilder<?> uriBuilder = - entity.getEditLink() == null + entity.getEditLink() == null ? CoreUtils.buildEditLink(getClient(), getUUID().getEntitySetURI().toASCIIString(), entity, key) : getClient().newURIBuilder(entity.getEditLink().toASCIIString()); @@ -252,7 +254,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler if (this.uri == null) { final CommonURIBuilder<?> uriBuilder = - getEntity().getEditLink() == null + getEntity().getEditLink() == null ? CoreUtils.buildEditLink(getClient(), entitySetURI.toASCIIString(), getEntity(), key) : getClient().newURIBuilder(getEntity().getEditLink().toASCIIString()); @@ -304,9 +306,9 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler public boolean isChanged(final boolean deep) { return this.linkChanges.hashCode() != this.linksTag - || this.propertyChanges.hashCode() != this.propertiesTag - || (deep && (this.stream != null - || !this.streamedPropertyChanges.isEmpty())); + || this.propertyChanges.hashCode() != this.propertiesTag + || (deep && (this.stream != null + || !this.streamedPropertyChanges.isEmpty())); } public void uploadStream(final EdmStreamValue stream) { @@ -325,15 +327,15 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler public EdmStreamValue loadStream() { final URI contentSource = getEntity().getMediaContentSource() == null - ? getClient().newURIBuilder(baseURI.toASCIIString()).appendValueSegment().build() - : getEntity().getMediaContentSource(); + ? getClient().newURIBuilder(baseURI.toASCIIString()).appendValueSegment().build() + : getEntity().getMediaContentSource(); if (this.stream == null - && typeRef.getAnnotation(EntityType.class).hasStream() - && contentSource != null) { + && typeRef.getAnnotation(EntityType.class).hasStream() + && contentSource != null) { final ODataMediaRequest retrieveReq = - getClient().getRetrieveRequestFactory().getMediaEntityRequest(contentSource); + getClient().getRetrieveRequestFactory().getMediaEntityRequest(contentSource); if (StringUtils.isNotBlank(getEntity().getMediaContentType())) { retrieveReq.setFormat(ODataFormat.fromString(getEntity().getMediaContentType())); @@ -341,9 +343,9 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler final ODataRetrieveResponse<InputStream> res = retrieveReq.execute(); this.stream = EdmStreamValue.class.cast(Proxy.newProxyInstance( - Thread.currentThread().getContextClassLoader(), - new Class<?>[] {EdmStreamValue.class}, - new EdmStreamValueHandler(res.getContentType(), res.getBody(), contentSource, service))); + Thread.currentThread().getContextClassLoader(), + new Class<?>[] { EdmStreamValue.class }, + new EdmStreamValueHandler(res.getContentType(), res.getBody(), contentSource, service))); } return this.stream; @@ -389,7 +391,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler if (item instanceof Proxy) { final InvocationHandler handler = Proxy.getInvocationHandler(item); if ((handler instanceof ComplexInvocationHandler) - && ((ComplexInvocationHandler) handler).getEntityHandler() == null) { + && ((ComplexInvocationHandler) handler).getEntityHandler() == null) { ((ComplexInvocationHandler) handler).setEntityHandler(this); } } @@ -422,8 +424,8 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler } } res = annotation == null || annotation.hasNullValue() - ? null - : CoreUtils.getObjectFromODataValue(annotation.getValue(), null, service); + ? null + : CoreUtils.getObjectFromODataValue(annotation.getValue(), null, service); if (res != null) { annotations.put(term, res); } @@ -438,8 +440,8 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler @Override public Collection<Class<? extends AbstractTerm>> readAnnotationTerms() { return getEntity() instanceof ODataEntity - ? CoreUtils.getAnnotationTerms(service, ((ODataEntity) getEntity()).getAnnotations()) - : Collections.<Class<? extends AbstractTerm>>emptyList(); + ? CoreUtils.getAnnotationTerms(service, ((ODataEntity) getEntity()).getAnnotations()) + : Collections.<Class<? extends AbstractTerm>> emptyList(); } @Override @@ -449,7 +451,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler try { final ODataEntityRequest<CommonODataEntity> req = - getClient().getRetrieveRequestFactory().getEntityRequest(uri.build()); + getClient().getRetrieveRequestFactory().getEntityRequest(uri.build()); if (getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) > 0) { req.setPrefer(getClient().newPreferences().includeAnnotations("*")); @@ -485,7 +487,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler @Override @SuppressWarnings("unchecked") protected <T extends CommonODataProperty> List<T> getInternalProperties() { - return getEntity() == null ? Collections.<T>emptyList() : (List<T>) getEntity().getProperties(); + return getEntity() == null ? Collections.<T> emptyList() : (List<T>) getEntity().getProperties(); } @Override @@ -494,11 +496,12 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler } // use read- instead of get- for .invoke() to distinguish it from entity property getter. - public String readEntityReferenceID() { - URI id = getEntity() == null ? null - : getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0 - ? ((org.apache.olingo.commons.api.domain.v3.ODataEntity) getEntity()).getLink() - : ((org.apache.olingo.commons.api.domain.v4.ODataEntity) getEntity()).getId(); + public String readEntityReferenceID() { + // TODO: Check + if (getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) { + throw new ODataRuntimeException("Only OData V4 or higher supported."); + } + URI id = getEntity() == null ? null : ((ODataEntity) getEntity()).getId(); return id == null ? null : id.toASCIIString(); } @@ -516,6 +519,6 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler @Override public boolean equals(final Object obj) { return obj instanceof EntityInvocationHandler - && ((EntityInvocationHandler) obj).getUUID().equals(uuid); + && ((EntityInvocationHandler) obj).getUUID().equals(uuid); } }
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8865db8/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 6ddf993..b61c4cc 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 @@ -26,15 +26,14 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.Future; + import org.apache.commons.lang3.tuple.Triple; import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest; import org.apache.olingo.client.api.uri.CommonURIBuilder; -import org.apache.olingo.client.api.v3.UnsupportedInV3Exception; import org.apache.olingo.client.api.v4.EdmEnabledODataClient; import org.apache.olingo.commons.api.domain.CommonODataEntity; import org.apache.olingo.commons.api.domain.v4.ODataAnnotation; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.ext.proxy.AbstractService; import org.apache.olingo.ext.proxy.api.AbstractEntitySet; @@ -197,19 +196,12 @@ public class EntitySetInvocationHandler< @Override public Search<T, EC> createSearch() { - if (getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) { - throw new UnsupportedInV3Exception(); - } return new SearchImpl<T, EC>((EdmEnabledODataClient) getClient(), this.collItemRef, this.baseURI, this); } @Override @SuppressWarnings("unchecked") public <S extends T, SEC extends EntityCollection<S, ?, ?>> Search<S, SEC> createSearch(final Class<SEC> reference) { - - if (getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) { - throw new UnsupportedInV3Exception(); - } return new SearchImpl<S, SEC>( (EdmEnabledODataClient) getClient(), reference, http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8865db8/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java ---------------------------------------------------------------------- diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java index 5d2a1e0..1bf97c9 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java @@ -35,10 +35,10 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeSet; + import org.apache.commons.lang3.StringUtils; import org.apache.olingo.client.api.CommonEdmEnabledODataClient; import org.apache.olingo.client.api.uri.CommonURIBuilder; -import org.apache.olingo.client.api.v3.UnsupportedInV3Exception; import org.apache.olingo.client.core.uri.URIUtils; import org.apache.olingo.commons.api.domain.CommonODataEntity; import org.apache.olingo.commons.api.domain.CommonODataProperty; @@ -58,7 +58,6 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.EdmTerm; 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.domain.v4.ODataAnnotationImpl; import org.apache.olingo.commons.core.edm.EdmTypeInfo; import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; @@ -93,7 +92,7 @@ public final class CoreUtils { } public static ODataValue getODataValue( - final CommonEdmEnabledODataClient<?> client, final EdmTypeInfo type, final Object obj) { + final CommonEdmEnabledODataClient<?> client, final EdmTypeInfo type, final Object obj) { final ODataValue value; @@ -101,19 +100,14 @@ public final class CoreUtils { value = client.getObjectFactory().newCollectionValue(type.getFullQualifiedName().toString()); final EdmTypeInfo intType = new EdmTypeInfo.Builder(). - setEdm(client.getCachedEdm()).setTypeExpression(type.getFullQualifiedName().toString()).build(); + 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.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()); - } - + value.asCollection().add(((org.apache.olingo.commons.api.domain.v4.ODataValue) getODataValue( + client, intType, collectionItem)).asEnum()); } else if (intType.isComplexType()) { value.asCollection().add(getODataValue(client, intType, collectionItem).asComplex()); } else { @@ -128,65 +122,58 @@ public final class CoreUtils { final Class<?> typeRef = ((ComplexInvocationHandler) objHandler).getTypeRef(); - for (Map.Entry<String, Object> changes - : ((ComplexInvocationHandler) objHandler).getPropertyChanges().entrySet()) { + for (Map.Entry<String, Object> changes : ((ComplexInvocationHandler) objHandler).getPropertyChanges() + .entrySet()) { try { value.asComplex().add(getODataComplexProperty( - client, type.getFullQualifiedName(), changes.getKey(), changes.getValue())); + client, type.getFullQualifiedName(), changes.getKey(), changes.getValue())); } catch (Exception ignore) { // ignore value LOG.warn("Error attaching complex {} for field '{}.{}'", - type.getFullQualifiedName(), typeRef.getName(), changes.getKey(), ignore); + type.getFullQualifiedName(), typeRef.getName(), changes.getKey(), ignore); } } - - - } else { throw new IllegalArgumentException(objHandler.getClass().getName() + "' 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()); - } + 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(); + build(); } return value; } private static CommonODataProperty getODataEntityProperty( - final CommonEdmEnabledODataClient<?> client, - final FullQualifiedName entity, - final String property, - final Object obj) { + final CommonEdmEnabledODataClient<?> client, + final FullQualifiedName entity, + final String property, + final Object obj) { final EdmElement edmProperty = client.getCachedEdm().getEntityType(entity).getProperty(property); return getODataProperty(client, edmProperty, property, obj); } private static CommonODataProperty getODataComplexProperty( - final CommonEdmEnabledODataClient<?> client, - final FullQualifiedName complex, - final String property, - final Object obj) { + final CommonEdmEnabledODataClient<?> client, + final FullQualifiedName complex, + final String property, + final Object obj) { final EdmElement edmProperty = client.getCachedEdm().getComplexType(complex).getProperty(property); return getODataProperty(client, edmProperty, property, obj); } private static CommonODataProperty getODataProperty( - final CommonEdmEnabledODataClient<?> client, - final EdmElement edmProperty, - final String property, - final Object obj) { + final CommonEdmEnabledODataClient<?> client, + final EdmElement edmProperty, + final String property, + final Object obj) { final EdmTypeInfo type; if (edmProperty == null) { @@ -196,7 +183,7 @@ public final class CoreUtils { final EdmType edmType = edmProperty.getType(); type = new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()).setTypeExpression( - edmProperty.isCollection() + edmProperty.isCollection() ? "Collection(" + edmType.getFullQualifiedName().toString() + ")" : edmType.getFullQualifiedName().toString()).build(); } @@ -205,7 +192,7 @@ public final class CoreUtils { } public static ODataAnnotation getODataAnnotation( - final CommonEdmEnabledODataClient<?> client, final String term, final EdmType type, final Object obj) { + final CommonEdmEnabledODataClient<?> client, final String term, final EdmType type, final Object obj) { ODataAnnotation annotation; @@ -213,19 +200,19 @@ public final class CoreUtils { annotation = new ODataAnnotationImpl(term, null); } else { final EdmTypeInfo valueType = type == null - ? guessTypeFromObject(client, obj) - : new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()). + ? guessTypeFromObject(client, obj) + : new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()). setTypeExpression(type.getFullQualifiedName().toString()).build(); annotation = new ODataAnnotationImpl(term, - (org.apache.olingo.commons.api.domain.v4.ODataValue) getODataValue(client, valueType, obj)); + (org.apache.olingo.commons.api.domain.v4.ODataValue) getODataValue(client, valueType, obj)); } return annotation; } public static CommonODataProperty getODataProperty( - final CommonEdmEnabledODataClient<?> client, final String name, final EdmTypeInfo type, final Object obj) { + final CommonEdmEnabledODataClient<?> client, final String name, final EdmTypeInfo type, final Object obj) { CommonODataProperty property; @@ -234,8 +221,8 @@ public final class CoreUtils { property = client.getObjectFactory().newPrimitiveProperty(name, null); } else { final EdmTypeInfo valueType = type == null - ? guessTypeFromObject(client, obj) - : type; + ? guessTypeFromObject(client, obj) + : type; final ODataValue value = getODataValue(client, valueType, obj); if (valueType.isCollection()) { @@ -245,12 +232,8 @@ public final class CoreUtils { } else if (valueType.isComplexType()) { property = client.getObjectFactory().newComplexProperty(name, value.asComplex()); } else if (valueType.isEnumType()) { - if (client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) { - throw new UnsupportedInV3Exception(); - } else { - property = ((ODataObjectFactory) client.getObjectFactory()).newEnumProperty(name, - ((org.apache.olingo.commons.api.domain.v4.ODataValue) value).asEnum()); - } + property = ((ODataObjectFactory) client.getObjectFactory()).newEnumProperty(name, + ((org.apache.olingo.commons.api.domain.v4.ODataValue) value).asEnum()); } else { throw new UnsupportedOperationException("Usupported object type " + valueType.getFullQualifiedName()); } @@ -263,13 +246,13 @@ public final class CoreUtils { } private static EdmTypeInfo guessTypeFromObject( - final CommonEdmEnabledODataClient<?> client, final Object obj) { + final CommonEdmEnabledODataClient<?> client, final Object obj) { final EdmTypeInfo.Builder edmTypeInfo = new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()); if (Collection.class.isAssignableFrom(obj.getClass())) { - final EdmTypeInfo type = guessPrimitiveType(client, ClassUtils.extractTypeArg(obj.getClass(), - EntityCollection.class, ComplexCollection.class, Collection.class)); + final EdmTypeInfo type = guessPrimitiveType(client, ClassUtils.extractTypeArg(obj.getClass(), + EntityCollection.class, ComplexCollection.class, Collection.class)); return edmTypeInfo.setTypeExpression("Collection(" + type.getFullQualifiedName() + ")").build(); } else if (obj instanceof Proxy) { final Class<?> typeRef = obj.getClass().getInterfaces()[0]; @@ -298,7 +281,7 @@ public final class CoreUtils { } else if (target.isAssignableFrom(clazz)) { bckCandidate = kind; } else if (target == Timestamp.class - && (kind == EdmPrimitiveTypeKind.DateTime || kind == EdmPrimitiveTypeKind.DateTimeOffset)) { + && (kind == EdmPrimitiveTypeKind.DateTime || kind == EdmPrimitiveTypeKind.DateTimeOffset)) { bckCandidate = kind; } } @@ -313,34 +296,34 @@ public final class CoreUtils { @SuppressWarnings("unchecked") public static void addProperties( - final CommonEdmEnabledODataClient<?> client, - final Map<String, Object> changes, - final CommonODataEntity entity) { + final CommonEdmEnabledODataClient<?> client, + final Map<String, Object> changes, + final CommonODataEntity entity) { for (Map.Entry<String, Object> entry : changes.entrySet()) { ((List<CommonODataProperty>) entity.getProperties()).add( - getODataEntityProperty(client, entity.getTypeName(), entry.getKey(), entry.getValue())); + getODataEntityProperty(client, entity.getTypeName(), entry.getKey(), entry.getValue())); } } public static void addProperties( - final CommonEdmEnabledODataClient<?> client, - final Map<String, Object> changes, - final ODataComplexValue<CommonODataProperty> entity) { + final CommonEdmEnabledODataClient<?> client, + final Map<String, Object> changes, + final ODataComplexValue<CommonODataProperty> entity) { for (Map.Entry<String, Object> entry : changes.entrySet()) { entity.add(getODataComplexProperty( - client, - new FullQualifiedName(entity.getTypeName()), - entry.getKey(), - entry.getValue())); + client, + new FullQualifiedName(entity.getTypeName()), + entry.getKey(), + entry.getValue())); } } public static void addAnnotations( - final CommonEdmEnabledODataClient<?> client, - final Map<Class<? extends AbstractTerm>, Object> annotations, - final ODataAnnotatable annotatable) { + final CommonEdmEnabledODataClient<?> client, + final Map<Class<? extends AbstractTerm>, Object> annotations, + final ODataAnnotatable annotatable) { for (Map.Entry<Class<? extends AbstractTerm>, Object> entry : annotations.entrySet()) { final Namespace nsAnn = entry.getKey().getAnnotation(Namespace.class); @@ -351,12 +334,12 @@ public final class CoreUtils { LOG.error("Could not find term for class {}", entry.getKey().getName()); } else { annotatable.getAnnotations().add(getODataAnnotation( - client, term.getFullQualifiedName().toString(), term.getType(), entry.getValue())); + client, term.getFullQualifiedName().toString(), term.getType(), entry.getValue())); } } } - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({ "unchecked", "rawtypes" }) private static Enum<?> enumValueToObject(final ODataEnumValue value, final Class<?> reference) { final Namespace namespace = reference.getAnnotation(Namespace.class); final EnumType enumType = reference.getAnnotation(EnumType.class); @@ -372,8 +355,8 @@ public final class CoreUtils { try { obj = reference == null - ? value.toValue() - : value.toCastValue(reference); + ? value.toValue() + : value.toCastValue(reference); } catch (EdmPrimitiveTypeException e) { LOG.warn("While casting primitive value {} to {}", value, reference, e); obj = value.toValue(); @@ -383,7 +366,7 @@ public final class CoreUtils { } private static void setPropertyValue(final Object bean, final Method getter, final Object value) - throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Assumption: setter is always prefixed by 'set' word final String setterName = getter.getName().replaceFirst("get", "set"); @@ -404,18 +387,18 @@ public final class CoreUtils { } public static CommonURIBuilder<?> buildEditLink( - final CommonEdmEnabledODataClient<?> client, - final String entitySetURI, - final CommonODataEntity entity, - final Object key) { + final CommonEdmEnabledODataClient<?> client, + final String entitySetURI, + final CommonODataEntity entity, + final Object key) { if (key == null) { return null; } final CommonURIBuilder<?> uriBuilder = StringUtils.isNotBlank(entitySetURI) - ? client.newURIBuilder(entitySetURI) - : client.newURIBuilder(); + ? client.newURIBuilder(entitySetURI) + : client.newURIBuilder(); if (key.getClass().getAnnotation(CompoundKey.class) == null) { LOG.debug("Append key segment '{}'", key); @@ -435,7 +418,7 @@ public final class CoreUtils { final Annotation annotation = method.getAnnotation(CompoundKeyElement.class); if (annotation instanceof CompoundKeyElement) { elements.add(new CompoundKeyElementWrapper( - ((CompoundKeyElement) annotation).name(), method, ((CompoundKeyElement) annotation).position())); + ((CompoundKeyElement) annotation).name(), method, ((CompoundKeyElement) annotation).position())); } } @@ -453,10 +436,10 @@ public final class CoreUtils { } public static Object getKey( - final CommonEdmEnabledODataClient<?> client, - final EntityInvocationHandler typeHandler, - final Class<?> entityTypeRef, - final CommonODataEntity entity) { + final CommonEdmEnabledODataClient<?> client, + final EntityInvocationHandler typeHandler, + final Class<?> entityTypeRef, + final CommonODataEntity entity) { Object res = null; @@ -466,7 +449,7 @@ public final class CoreUtils { final CommonODataProperty property = entity.getProperty(firstValidEntityKey(entityTypeRef)); if (property != null && property.hasPrimitiveValue()) { res = primitiveValueToObject( - property.getPrimitiveValue(), getPropertyClass(entityTypeRef, property.getName())); + property.getPrimitiveValue(), getPropertyClass(entityTypeRef, property.getName())); } } else { try { @@ -483,11 +466,11 @@ public final class CoreUtils { } private static void populate( - final CommonEdmEnabledODataClient<?> client, - final EntityInvocationHandler typeHandler, - final Object bean, - final Class<? extends Annotation> getterAnn, - final Iterator<? extends CommonODataProperty> propItor) { + final CommonEdmEnabledODataClient<?> client, + final EntityInvocationHandler typeHandler, + final Object bean, + final Class<? extends Annotation> getterAnn, + final Iterator<? extends CommonODataProperty> propItor) { if (bean != null) { final Class<?> typeRef; @@ -505,14 +488,14 @@ public final class CoreUtils { } } - @SuppressWarnings({"unchecked"}) + @SuppressWarnings({ "unchecked" }) private static void populate( - final CommonEdmEnabledODataClient<?> client, - final EntityInvocationHandler typeHandler, - final Object bean, - final Class<?> typeRef, - final Class<? extends Annotation> getterAnn, - final Iterator<? extends CommonODataProperty> propItor) { + final CommonEdmEnabledODataClient<?> client, + final EntityInvocationHandler typeHandler, + final Object bean, + final Class<?> typeRef, + final Class<? extends Annotation> getterAnn, + final Iterator<? extends CommonODataProperty> propItor) { if (bean != null) { while (propItor.hasNext()) { @@ -522,19 +505,19 @@ public final class CoreUtils { if (getter == null) { LOG.warn("Could not find any property annotated as {} in {}", - property.getName(), bean.getClass().getName()); + property.getName(), bean.getClass().getName()); } else { try { if (property.hasNullValue()) { setPropertyValue(bean, getter, null); } else if (property.hasPrimitiveValue()) { setPropertyValue(bean, getter, primitiveValueToObject( - property.getPrimitiveValue(), getPropertyClass(typeRef, property.getName()))); + property.getPrimitiveValue(), getPropertyClass(typeRef, property.getName()))); } else if (property.hasComplexValue()) { final Object complex = Proxy.newProxyInstance( - Thread.currentThread().getContextClassLoader(), - new Class<?>[] {getter.getReturnType()}, - ComplexInvocationHandler.getInstance(property.getName(), typeHandler, getter.getReturnType())); + Thread.currentThread().getContextClassLoader(), + new Class<?>[] { getter.getReturnType() }, + ComplexInvocationHandler.getInstance(property.getName(), typeHandler, getter.getReturnType())); populate(client, typeHandler, complex, Property.class, property.getValue().asComplex().iterator()); setPropertyValue(bean, getter, complex); @@ -553,12 +536,12 @@ public final class CoreUtils { final ODataValue value = collPropItor.next(); if (value.isPrimitive()) { collection.add(primitiveValueToObject( - value.asPrimitive(), getPropertyClass(typeRef, property.getName()))); + value.asPrimitive(), getPropertyClass(typeRef, property.getName()))); } else if (value.isComplex()) { final Object collItem = Proxy.newProxyInstance( - Thread.currentThread().getContextClassLoader(), - new Class<?>[] {collItemClass}, - ComplexInvocationHandler.getInstance(property.getName(), typeHandler, collItemClass)); + Thread.currentThread().getContextClassLoader(), + new Class<?>[] { collItemClass }, + ComplexInvocationHandler.getInstance(property.getName(), typeHandler, collItemClass)); populate(client, typeHandler, collItem, Property.class, value.asComplex().iterator()); collection.add(collItem); @@ -574,10 +557,10 @@ public final class CoreUtils { } public static Object getObjectFromODataValue( - final ODataValue value, - final Type typeRef, - final AbstractService<?> service) - throws InstantiationException, IllegalAccessException { + final ODataValue value, + final Type typeRef, + final AbstractService<?> service) + throws InstantiationException, IllegalAccessException { Class<?> internalRef; if (typeRef == null) { @@ -594,11 +577,10 @@ public final class CoreUtils { } public static Object getObjectFromODataValue( - final ODataValue value, - final Class<?> ref, - final AbstractService<?> service) - throws InstantiationException, IllegalAccessException { - + final ODataValue value, + final Class<?> ref, + final AbstractService<?> service) + throws InstantiationException, IllegalAccessException { final Object res; @@ -608,9 +590,9 @@ public final class CoreUtils { // complex types supports inheritance in V4, best to re-read actual type Class<?> internalRef = getComplexTypeRef(service, value); res = Proxy.newProxyInstance( - Thread.currentThread().getContextClassLoader(), - new Class<?>[] {internalRef}, - ComplexInvocationHandler.getInstance(value.asComplex(), internalRef, service)); + Thread.currentThread().getContextClassLoader(), + new Class<?>[] { internalRef }, + ComplexInvocationHandler.getInstance(value.asComplex(), internalRef, service)); } else if (value.isCollection()) { final ArrayList<Object> collection = new ArrayList<Object>(); @@ -622,9 +604,9 @@ public final class CoreUtils { } else if (itemValue.isComplex()) { Class<?> internalRef = getComplexTypeRef(service, value); final Object collItem = Proxy.newProxyInstance( - Thread.currentThread().getContextClassLoader(), - new Class<?>[] {internalRef}, - ComplexInvocationHandler.getInstance(itemValue.asComplex(), internalRef, service)); + Thread.currentThread().getContextClassLoader(), + new Class<?>[] { internalRef }, + ComplexInvocationHandler.getInstance(itemValue.asComplex(), internalRef, service)); collection.add(collItem); } @@ -641,7 +623,7 @@ public final class CoreUtils { } public static Collection<Class<? extends AbstractTerm>> getAnnotationTerms( - final AbstractService<?> service, final List<ODataAnnotation> annotations) { + final AbstractService<?> service, final List<ODataAnnotation> annotations) { final List<Class<? extends AbstractTerm>> res = new ArrayList<Class<? extends AbstractTerm>>(); @@ -681,11 +663,11 @@ public final class CoreUtils { } public static URI getTargetEntitySetURI( - final CommonEdmEnabledODataClient<?> client, final NavigationProperty property) { + final CommonEdmEnabledODataClient<?> client, final NavigationProperty property) { final Edm edm = client.getCachedEdm(); final FullQualifiedName containerName = - new FullQualifiedName(property.targetSchema(), property.targetContainer()); + new FullQualifiedName(property.targetSchema(), property.targetContainer()); final EdmEntityContainer container = edm.getEntityContainer(containerName); final CommonURIBuilder<?> uriBuilder = client.newURIBuilder(client.getServiceRoot()); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8865db8/ext/pojogen-maven-plugin/src/it/v3Sample/pom.xml ---------------------------------------------------------------------- diff --git a/ext/pojogen-maven-plugin/src/it/v3Sample/pom.xml b/ext/pojogen-maven-plugin/src/it/v3Sample/pom.xml deleted file mode 100644 index 156168a..0000000 --- a/ext/pojogen-maven-plugin/src/it/v3Sample/pom.xml +++ /dev/null @@ -1,107 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <artifactId>pojogen-maven-plugin-v3test</artifactId> - <groupId>org.apache.olingo</groupId> - <version>@project.version@</version> - <name>${project.artifactId}</name> - <description>A simple IT verifying the basic use case of pojogen-man-plugin.</description> - - <properties> - <project.source>1.6</project.source> - <compiler.plugin.version>3.2</compiler.plugin.version> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <dependencies> - <dependency> - <artifactId>pojogen-maven-plugin</artifactId> - <groupId>org.apache.olingo</groupId> - <version>@project.version@</version> - <scope>runtime</scope> - </dependency> - - <dependency> - <artifactId>odata-client-proxy</artifactId> - <groupId>org.apache.olingo</groupId> - <version>@project.version@</version> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>${compiler.plugin.version}</version> - <configuration> - <source>${project.source}</source> - <target>${project.source}</target> - <showWarnings>true</showWarnings> - <showDeprecation>true</showDeprecation> - <compilerArgument>-Xlint:unchecked</compilerArgument> - </configuration> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <version>1.8</version> - <executions> - <execution> - <phase>process-sources</phase> - <goals> - <goal>add-source</goal> - </goals> - <configuration> - <sources> - <source>${project.build.directory}/generated-sources</source> - </sources> - </configuration> - </execution> - </executions> - </plugin> - - <plugin> - <groupId>@project.groupId@</groupId> - <artifactId>pojogen-maven-plugin</artifactId> - <version>@project.version@</version> - <executions> - <execution> - <configuration> - <outputDirectory>${project.build.directory}/generated-sources</outputDirectory> - <localEdm>${project.basedir}/src/test/resources/metadata.xml</localEdm> - <basePackage>org.apache.olingo.fit.proxy.v3.staticservice</basePackage> - </configuration> - <id>v3pojoGen</id> - <phase>generate-sources</phase> - <goals> - <goal>v3pojoGen</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> -</project>
