[OLINGO-260] V4 function / action import invoke
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/397c82f1 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/397c82f1 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/397c82f1 Branch: refs/heads/master Commit: 397c82f1b1222338c0789792187d8cfaff3f2328 Parents: 22f6a6a Author: Francesco Chicchiriccò <--global> Authored: Wed May 14 10:21:03 2014 +0200 Committer: Stephan Klevenz <[email protected]> Committed: Mon May 19 14:33:13 2014 +0200 ---------------------------------------------------------------------- .../commons/AbstractInvocationHandler.java | 4 +- .../AbstractStructuredInvocationHandler.java | 88 +++++++++----------- .../olingo/ext/proxy/commons/ContainerImpl.java | 2 +- .../proxy/commons/EntityInvocationHandler.java | 2 +- .../olingo/ext/proxy/utils/CoreUtils.java | 58 +++++++++---- .../olingo/ext/pojogen/AbstractPOJOGenMojo.java | 44 +--------- .../java/org/apache/olingo/fit/V4Services.java | 40 ++------- .../olingo/fit/utils/AbstractUtilities.java | 1 - fit/src/test/resources/META-INF/enumTypes | 3 + .../client/core/v3/PrimitiveValueTest.java | 14 ++-- pom.xml | 2 +- 11 files changed, 105 insertions(+), 153 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/397c82f1/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 9da6aab..516664d 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 @@ -193,7 +193,7 @@ abstract class AbstractInvocationHandler<C extends CommonEdmEnabledODataClient<? final EdmTypeInfo edmType = new EdmTypeInfo.Builder(). setEdm(client.getCachedEdm()).setTypeExpression(annotation.returnType()).build(); - + if (edmType.isEntityType()) { if (edmType.isCollection()) { final ParameterizedType collType = (ParameterizedType) method.getReturnType().getGenericInterfaces()[0]; @@ -213,7 +213,7 @@ abstract class AbstractInvocationHandler<C extends CommonEdmEnabledODataClient<? method.getReturnType(), false); } - }else{ + } else { return CoreUtils.getValueFromProperty(client, (CommonODataProperty) result, method.getGenericReturnType(), null); } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/397c82f1/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java ---------------------------------------------------------------------- diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java index 689d99f..d9a9d85 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java @@ -35,9 +35,9 @@ import org.apache.olingo.commons.api.domain.ODataInlineEntity; import org.apache.olingo.commons.api.domain.ODataInlineEntitySet; import org.apache.olingo.commons.api.domain.ODataLink; import org.apache.olingo.commons.api.domain.ODataLinked; +import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.ext.proxy.EntityContainerFactory; import org.apache.olingo.ext.proxy.api.AbstractEntityCollection; -import org.apache.olingo.ext.proxy.api.AbstractEntitySet; import org.apache.olingo.ext.proxy.api.annotations.EntityType; import org.apache.olingo.ext.proxy.api.annotations.NavigationProperty; import org.apache.olingo.ext.proxy.api.annotations.Property; @@ -47,66 +47,57 @@ import org.apache.olingo.ext.proxy.utils.ClassUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public abstract class AbstractStructuredInvocationHandler extends AbstractInvocationHandler { +public abstract class AbstractTypeInvocationHandler<C extends CommonEdmEnabledODataClient<?>> + extends AbstractInvocationHandler<C> { private static final long serialVersionUID = 2629912294765040037L; /** * Logger. */ - protected static final Logger LOG = LoggerFactory.getLogger(AbstractStructuredInvocationHandler.class); + protected static final Logger LOG = LoggerFactory.getLogger(AbstractTypeInvocationHandler.class); protected final Class<?> typeRef; protected final EntityContext entityContext = EntityContainerFactory.getContext().entityContext(); - protected EntityInvocationHandler entityHandler; + protected final EntityTypeInvocationHandler<C> targetHandler; protected Object internal; - protected AbstractStructuredInvocationHandler( - final CommonEdmEnabledODataClient<?> client, + @SuppressWarnings("unchecked") + protected AbstractTypeInvocationHandler( + final C client, final Class<?> typeRef, final Object internal, - final EntityContainerInvocationHandler containerHandler) { + final EntityContainerInvocationHandler<C> containerHandler) { super(client, containerHandler); this.internal = internal; this.typeRef = typeRef; - this.entityHandler = null; + this.targetHandler = EntityTypeInvocationHandler.class.cast(this); } - protected AbstractStructuredInvocationHandler( - final CommonEdmEnabledODataClient<?> client, + protected AbstractTypeInvocationHandler( + final C client, final Class<?> typeRef, final Object internal, - final EntityInvocationHandler entityHandler) { + final EntityTypeInvocationHandler<C> targetHandler) { - super(client, entityHandler == null ? null : entityHandler.containerHandler); + super(client, targetHandler == null ? null : targetHandler.containerHandler); this.internal = internal; this.typeRef = typeRef; - // prevent memory leak - this.entityHandler = entityHandler == this ? null : entityHandler; + this.targetHandler = targetHandler; } - public EntityInvocationHandler getEntityHandler() { - return entityHandler == null - ? this instanceof EntityInvocationHandler - ? EntityInvocationHandler.class.cast(this) - : null - : entityHandler; - } - - public void setEntityHandler(EntityInvocationHandler entityHandler) { - // prevent memory leak - this.entityHandler = entityHandler == this ? null : entityHandler; - } + public abstract FullQualifiedName getName(); public Class<?> getTypeRef() { return typeRef; } @Override + @SuppressWarnings("unchecked") public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { if (isSelfMethod(method, args)) { return invokeSelfMethod(method, args); @@ -116,14 +107,14 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca return Proxy.newProxyInstance( Thread.currentThread().getContextClassLoader(), new Class<?>[] {returnType}, - OperationInvocationHandler.getInstance(getEntityHandler())); + OperationInvocationHandler.getInstance(targetHandler)); } else if ("factory".equals(method.getName()) && ArrayUtils.isEmpty(args)) { final Class<?> returnType = method.getReturnType(); return Proxy.newProxyInstance( Thread.currentThread().getContextClassLoader(), new Class<?>[] {returnType}, - ComplexFactoryInvocationHandler.getInstance(getEntityHandler(), this)); + FactoryInvocationHandler.getInstance(targetHandler, this)); } else if (method.getName().startsWith("get")) { // Assumption: for each getter will always exist a setter and viceversa. // get method annotation and check if it exists as expected @@ -172,13 +163,13 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca return ClassUtils.returnVoid(); } else { - throw new NoSuchMethodException(method.getName()); + throw new UnsupportedOperationException("Method not found: " + method); } } protected void attach() { - if (getEntityHandler() != null && !entityContext.isAttached(getEntityHandler())) { - entityContext.attach(getEntityHandler(), AttachedEntityStatus.ATTACHED); + if (targetHandler != null && !entityContext.isAttached(targetHandler)) { + entityContext.attach(targetHandler, AttachedEntityStatus.ATTACHED); } } @@ -187,20 +178,18 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca } protected void attach(final AttachedEntityStatus status, final boolean override) { - if (entityContext.isAttached(getEntityHandler())) { + if (entityContext.isAttached(targetHandler)) { if (override) { - entityContext.setStatus(getEntityHandler(), status); + entityContext.setStatus(targetHandler, status); } } else { - entityContext.attach(getEntityHandler(), status); + entityContext.attach(targetHandler, status); } } protected abstract Object getNavigationPropertyValue(final NavigationProperty property, final Method getter); - protected Object retrieveNavigationProperty( - final NavigationProperty property, final Method getter, final String serviceRoot) { - + protected Object retriveNavigationProperty(final NavigationProperty property, final Method getter) { final Class<?> type = getter.getReturnType(); final Class<?> collItemType; if (AbstractEntityCollection.class.isAssignableFrom(type)) { @@ -217,15 +206,14 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca if (link instanceof ODataInlineEntity) { // return entity navPropValue = getEntityProxy( - null, ((ODataInlineEntity) link).getEntity(), property.targetContainer(), - client.getURIBuilder(serviceRoot).appendEntitySetSegment(property.targetEntitySet()).build(), + property.targetEntitySet(), type, false); } else if (link instanceof ODataInlineEntitySet) { // return entity set - navPropValue = getEntityCollectionProxy( + navPropValue = getEntityCollection( collItemType, type, property.targetContainer(), @@ -234,26 +222,25 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca false); } else { // navigate - final URI uri = URIUtils.getURI(containerHandler.getFactory().getServiceRoot(), link.getLink().toASCIIString()); + final URI uri = URIUtils.getURI( + containerHandler.getFactory().getServiceRoot(), link.getLink().toASCIIString()); + if (AbstractEntityCollection.class.isAssignableFrom(type)) { - navPropValue = getEntityCollectionProxy( + navPropValue = getEntityCollection( collItemType, type, property.targetContainer(), client.getRetrieveRequestFactory().getEntitySetRequest(uri).execute().getBody(), uri, true); - } else if (AbstractEntitySet.class.isAssignableFrom(type)) { - navPropValue = getEntitySetProxy(type, uri); } else { final ODataRetrieveResponse<CommonODataEntity> res = client.getRetrieveRequestFactory().getEntityRequest(uri).execute(); navPropValue = getEntityProxy( - uri, res.getBody(), property.targetContainer(), - client.getURIBuilder(serviceRoot).appendEntitySetSegment(property.targetEntitySet()).build(), + property.targetEntitySet(), type, res.getETag(), true); @@ -282,8 +269,8 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca private void setNavigationPropertyValue(final NavigationProperty property, final Object value) { // 1) attach source entity - if (!entityContext.isAttached(getEntityHandler())) { - entityContext.attach(getEntityHandler(), AttachedEntityStatus.CHANGED); + if (!entityContext.isAttached(targetHandler)) { + entityContext.attach(targetHandler, AttachedEntityStatus.CHANGED); } // 2) attach the target entity handlers @@ -291,11 +278,12 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca ? (AbstractEntityCollection) value : Collections.singleton(value)) { final InvocationHandler etih = Proxy.getInvocationHandler(link); - if (!(etih instanceof EntityInvocationHandler)) { + if (!(etih instanceof EntityTypeInvocationHandler)) { throw new IllegalArgumentException("Invalid argument type"); } - final EntityInvocationHandler linkedHandler = (EntityInvocationHandler) etih; + @SuppressWarnings("unchecked") + final EntityTypeInvocationHandler<C> linkedHandler = (EntityTypeInvocationHandler<C>) etih; if (!linkedHandler.getTypeRef().isAnnotationPresent(EntityType.class)) { throw new IllegalArgumentException("Invalid argument type " + linkedHandler.getTypeRef().getSimpleName()); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/397c82f1/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java ---------------------------------------------------------------------- diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java index 3d30497..49c1c9f 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java @@ -410,7 +410,7 @@ class ContainerImpl implements Container { final URI targetURI = currentStatus == AttachedEntityStatus.NEW ? URI.create("$" + startingPos) : URIUtils.getURI( factory.getServiceRoot(), - CoreUtils.getEditMediaLink(streamedChanges.getKey(), entity).toASCIIString()); + CoreUtils.getMediaEditLink(streamedChanges.getKey(), entity).toASCIIString()); batchUpdateMediaResource(handler, targetURI, streamedChanges.getValue(), changeset); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/397c82f1/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 9f81634..afafeb3 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 @@ -289,7 +289,7 @@ public class EntityTypeInvocationHandler<C extends CommonEdmEnabledODataClient<? if (res == null) { final URI link = URIUtils.getURI( containerHandler.getFactory().getServiceRoot(), - CoreUtils.getEditMediaLink(property.name(), getEntity()).toASCIIString()); + CoreUtils.getMediaEditLink(property.name(), getEntity()).toASCIIString()); final ODataMediaRequest req = client.getRetrieveRequestFactory().getMediaRequest(link); res = req.execute().getBody(); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/397c82f1/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 981d285..d1ea8a3 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 @@ -33,6 +33,8 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.olingo.client.api.CommonEdmEnabledODataClient; import org.apache.olingo.client.api.v3.UnsupportedInV3Exception; import org.apache.olingo.commons.api.domain.CommonODataEntity; @@ -40,6 +42,8 @@ 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.domain.v4.ODataEnumValue; +import org.apache.olingo.commons.api.domain.v4.ODataProperty; import org.apache.olingo.commons.api.edm.EdmElement; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.EdmType; @@ -47,7 +51,9 @@ 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.CompoundKeyElement; +import org.apache.olingo.ext.proxy.api.annotations.EnumType; import org.apache.olingo.ext.proxy.api.annotations.Key; +import org.apache.olingo.ext.proxy.api.annotations.Namespace; import org.apache.olingo.ext.proxy.api.annotations.Property; import org.apache.olingo.ext.proxy.commons.AbstractTypeInvocationHandler; import org.apache.olingo.ext.proxy.commons.ComplexTypeInvocationHandler; @@ -202,8 +208,8 @@ public final class CoreUtils { } 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()); + ((org.apache.olingo.commons.api.domain.v4.ODataValue) getODataValue(client, type, obj)). + asEnum()); } } else { throw new UnsupportedOperationException("Usupported object type " + type.getFullQualifiedName()); @@ -332,7 +338,7 @@ public final class CoreUtils { Thread.currentThread().getContextClassLoader(), new Class<?>[] {getter.getReturnType()}, ComplexTypeInvocationHandler.getInstance( - client, property.getName(), getter.getReturnType(), null)); + client, property.getName(), getter.getReturnType(), null)); populate(client, complex, Property.class, property.getValue().asComplex().iterator()); setPropertyValue(bean, getter, complex); @@ -356,7 +362,7 @@ public final class CoreUtils { Thread.currentThread().getContextClassLoader(), new Class<?>[] {collItemClass}, ComplexTypeInvocationHandler.getInstance( - client, property.getName(), collItemClass, null)); + client, property.getName(), collItemClass, null)); populate(client, collItem, Property.class, value.asComplex().iterator()); collection.add(collItem); @@ -371,6 +377,29 @@ public final class CoreUtils { } } + @SuppressWarnings({"unchecked", "rawtypes"}) + private static Enum<?> buildEnumInstance(final ODataEnumValue value) { + try { + for (String enumTypeName + : StringUtils.split(IOUtils.toString(CoreUtils.class.getResourceAsStream("/META-INF/enumTypes")), '\n')) { + + final Class<Enum> enumClass = + (Class<Enum>) Thread.currentThread().getContextClassLoader().loadClass(enumTypeName); + if (enumClass != null) { + final Namespace namespace = enumClass.getAnnotation(Namespace.class); + final EnumType enumType = enumClass.getAnnotation(EnumType.class); + if (value.getTypeName().equals(namespace.value() + "." + enumType.name())) { + return Enum.valueOf(enumClass, value.getValue()); + } + } + } + } catch (Exception e) { + LOG.error("While trying to load enum for {}", value, e); + } + + return null; + } + @SuppressWarnings("unchecked") public static Object getValueFromProperty( final CommonEdmEnabledODataClient<?> client, @@ -379,8 +408,6 @@ public final class CoreUtils { final EntityTypeInvocationHandler<?> entityHandler) throws InstantiationException, IllegalAccessException { - final Object res; - Class<?> internalRef; if (typeRef == null) { internalRef = null; @@ -392,6 +419,8 @@ public final class CoreUtils { } } + final Object res; + if (property == null || property.hasNullValue()) { res = null; } else if (property.hasComplexValue()) { @@ -399,8 +428,7 @@ public final class CoreUtils { Thread.currentThread().getContextClassLoader(), new Class<?>[] {internalRef}, ComplexTypeInvocationHandler.getInstance( - client, property.getValue().asComplex(), internalRef, entityHandler)); - + client, property.getValue().asComplex(), internalRef, entityHandler)); } else if (property.hasCollectionValue()) { final ArrayList<Object> collection = new ArrayList<Object>(); @@ -414,15 +442,17 @@ public final class CoreUtils { Thread.currentThread().getContextClassLoader(), new Class<?>[] {internalRef}, ComplexTypeInvocationHandler.getInstance( - client, value.asComplex(), internalRef, entityHandler)); + client, value.asComplex(), internalRef, entityHandler)); collection.add(collItem); } } res = collection; + } else if (property instanceof ODataProperty && ((ODataProperty) property).hasEnumValue()) { + res = buildEnumInstance(((ODataProperty) property).getEnumValue()); } else { - res = CoreUtils.primitiveValueToObject(property.getPrimitiveValue()); + res = primitiveValueToObject(property.getPrimitiveValue()); } return res; @@ -440,10 +470,10 @@ public final class CoreUtils { 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(); + public static URI getMediaEditLink(final String name, final CommonODataEntity entity) { + for (ODataLink link : entity.getMediaEditLinks()) { + if (name.equalsIgnoreCase(link.getName())) { + return link.getLink(); } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/397c82f1/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java ---------------------------------------------------------------------- diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java index f8ab5f2..ce566ee 100644 --- a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java +++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java @@ -23,11 +23,9 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; -import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; import org.apache.commons.io.IOUtils; @@ -37,14 +35,12 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Parameter; import org.apache.olingo.client.api.CommonODataClient; -import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmComplexType; import org.apache.olingo.commons.api.edm.EdmEntityContainer; import org.apache.olingo.commons.api.edm.EdmEntitySet; import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.edm.EdmEnumType; -import org.apache.olingo.commons.api.edm.EdmNavigationProperty; import org.apache.olingo.commons.api.edm.EdmSchema; import org.apache.olingo.commons.api.edm.EdmSingleton; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; @@ -231,7 +227,6 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo { namespaces.add(schema.getNamespace().toLowerCase()); } - final StringBuilder complexTypeNames = new StringBuilder(); final StringBuilder enumTypeNames = new StringBuilder(); for (EdmSchema schema : edm.getSchemas()) { @@ -259,29 +254,11 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo { parseObj(typesBaseDir, typesPkg, "enumType", className + ".java", objs); } - final List<EdmComplexType> complexes = new ArrayList<EdmComplexType>(); - for (EdmComplexType complex : schema.getComplexTypes()) { - complexes.add(complex); final String className = utility.capitalize(complex.getName()); - complexTypeNames.append(typesPkg).append('.').append(className).append('\n'); objs.clear(); objs.put("complexType", complex); parseObj(typesBaseDir, typesPkg, "complexType", className + ".java", objs); - - for (String navPropName : complex.getNavigationPropertyNames()) { - final EdmNavigationProperty navProp = complex.getNavigationProperty(navPropName); - if ((complex.getBaseType() == null - || edm.getEntityType(complex.getBaseType().getFullQualifiedName()). - getNavigationProperty(navPropName) == null) - && navProp.containsTarget()) { - - objs.clear(); - objs.put("navProp", navProp); - parseObj(base, pkg, "containedEntitySet", - utility.capitalize(navProp.getName()) + ".java", objs); - } - } } for (EdmEntityType entity : schema.getEntityTypes()) { @@ -319,20 +296,6 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo { utility.capitalize(entity.getName()) + ".java", objs); parseObj(typesBaseDir, typesPkg, "entityCollection", utility.capitalize(entity.getName()) + "Collection.java", objs); - - for (String navPropName : entity.getNavigationPropertyNames()) { - final EdmNavigationProperty navProp = entity.getNavigationProperty(navPropName); - if ((entity.getBaseType() == null - || edm.getEntityType(entity.getBaseType().getFullQualifiedName()). - getNavigationProperty(navPropName) == null) - && navProp.containsTarget()) { - - objs.clear(); - objs.put("navProp", navProp); - parseObj(base, pkg, "containedEntitySet", - utility.capitalize(navProp.getName()) + ".java", objs); - } - } } // write container and top entity sets into the base package @@ -340,7 +303,6 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo { objs.clear(); objs.put("container", container); objs.put("namespace", schema.getNamespace()); - objs.put("complexes", complexes); parseObj(base, pkg, "container", utility.capitalize(container.getName()) + ".java", objs); @@ -364,10 +326,7 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo { } final File metaInf = mkdir("META-INF"); - FileUtils.fileWrite( - metaInf.getPath() + File.separator + Constants.PROXY_ENUM_CLASS_LIST, enumTypeNames.toString()); - FileUtils.fileWrite( - metaInf.getPath() + File.separator + Constants.PROXY_COMPLEX_CLASS_LIST, complexTypeNames.toString()); + FileUtils.fileWrite(metaInf.getPath() + File.separator + "enumTypes", enumTypeNames.toString()); } catch (Exception t) { getLog().error(t); @@ -376,4 +335,5 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo { : new MojoExecutionException("While executin mojo", t); } } + } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/397c82f1/fit/src/main/java/org/apache/olingo/fit/V4Services.java ---------------------------------------------------------------------- diff --git a/fit/src/main/java/org/apache/olingo/fit/V4Services.java b/fit/src/main/java/org/apache/olingo/fit/V4Services.java index 0bd689d..2d774d5 100644 --- a/fit/src/main/java/org/apache/olingo/fit/V4Services.java +++ b/fit/src/main/java/org/apache/olingo/fit/V4Services.java @@ -54,7 +54,6 @@ import javax.ws.rs.core.UriInfo; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.math.NumberUtils; import org.apache.cxf.interceptor.InInterceptors; import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Multipart; @@ -103,7 +102,7 @@ public class V4Services extends AbstractServices { protected static final Pattern CROSSJOIN_PATTERN = Pattern.compile( "^\\$crossjoin\\(.*\\)\\?\\$filter=\\([a-zA-Z/]+ eq [a-zA-Z/]+\\)$"); - private final Map<String, String> providedAsync = new HashMap<String, String>(); + private Map<String, String> providedAsync = new HashMap<String, String>(); public V4Services() throws Exception { super(ODataServiceVersion.V40, Commons.getMetadata(ODataServiceVersion.V40)); @@ -112,7 +111,7 @@ public class V4Services extends AbstractServices { protected V4Services(final Metadata metadata) throws Exception { super(ODataServiceVersion.V40, metadata); } - + @GET @Path("/$crossjoin({elements:.*})") public Response crossjoin( @@ -293,7 +292,7 @@ public class V4Services extends AbstractServices { addChangesetItemIntro(chbos, lastContebtID, cboundary); res = bodyPartRequest(new MimeBodyPart(part.getInputStream()), references); - if (res==null || res.getStatus() >= 400) { + if (res.getStatus() >= 400) { throw new Exception("Failure processing changeset"); } @@ -347,29 +346,6 @@ public class V4Services extends AbstractServices { } @GET - @Path("/People/{type:.*}") - public Response getPeople( - @Context UriInfo uriInfo, - @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, - @PathParam("type") final String type, - @QueryParam("$top") @DefaultValue(StringUtils.EMPTY) String top, - @QueryParam("$skip") @DefaultValue(StringUtils.EMPTY) String skip, - @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format, - @QueryParam("$inlinecount") @DefaultValue(StringUtils.EMPTY) String count, - @QueryParam("$filter") @DefaultValue(StringUtils.EMPTY) String filter, - @QueryParam("$search") @DefaultValue(StringUtils.EMPTY) String search, - @QueryParam("$orderby") @DefaultValue(StringUtils.EMPTY) String orderby, - @QueryParam("$skiptoken") @DefaultValue(StringUtils.EMPTY) String skiptoken) { - - return StringUtils.isBlank(filter) && StringUtils.isBlank(search) - ? NumberUtils.isNumber(type) - ? super.getEntityInternal( - uriInfo.getRequestUri().toASCIIString(), accept, "People", type, format, null, null, true) - : super.getEntitySet(accept, "People", type) - : super.getEntitySet(uriInfo, accept, "People", top, skip, format, count, filter, orderby, skiptoken); - } - - @GET @Path("/Boss") public Response getSingletonBoss( @Context UriInfo uriInfo, @@ -1263,21 +1239,15 @@ public class V4Services extends AbstractServices { acceptType = Accept.parse(accept, version); } - final Accept contentTypeValue = Accept.parse(contentType, version); + final Accept contentTypeValue = Accept.parse(contentType, version); final AtomEntityImpl entity = xml.readEntity(contentTypeValue, IOUtils.toInputStream(param, Constants.ENCODING)); assert "Microsoft.Test.OData.Services.ODataWCFService.Address".equals(entity.getType()); assert entity.getProperty("address").getValue().isComplex(); - final ResWrap<AtomPropertyImpl> result = new ResWrap<AtomPropertyImpl>( - URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) - + "Microsoft.Test.OData.Services.ODataWCFService.Address"), - null, - (AtomPropertyImpl) entity.getProperty("address")); - return xml.createResponse( null, - xml.writeProperty(acceptType, result), + xml.writeProperty(acceptType, entity.getProperty("address")), null, acceptType); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/397c82f1/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java ---------------------------------------------------------------------- diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java index 77c24d6..00259321 100644 --- a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java +++ b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java @@ -41,7 +41,6 @@ import javax.ws.rs.NotFoundException; import javax.ws.rs.core.Response; import javax.xml.stream.XMLStreamException; import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.vfs2.FileObject; import org.apache.olingo.commons.api.data.Entity; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/397c82f1/fit/src/test/resources/META-INF/enumTypes ---------------------------------------------------------------------- diff --git a/fit/src/test/resources/META-INF/enumTypes b/fit/src/test/resources/META-INF/enumTypes new file mode 100644 index 0000000..c1e5365 --- /dev/null +++ b/fit/src/test/resources/META-INF/enumTypes @@ -0,0 +1,3 @@ +org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.AccessLevel +org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Color +org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.CompanyCategory http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/397c82f1/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/PrimitiveValueTest.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/PrimitiveValueTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/PrimitiveValueTest.java index f902a0d..03f30d7 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/PrimitiveValueTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/PrimitiveValueTest.java @@ -29,12 +29,12 @@ import java.util.Iterator; import java.util.List; import java.util.TimeZone; import java.util.UUID; -import javax.xml.datatype.Duration; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.RandomStringUtils; import org.apache.olingo.commons.api.domain.ODataValue; import org.apache.olingo.client.api.v3.ODataClient; import org.apache.olingo.client.core.AbstractTest; +import org.apache.olingo.commons.api.domain.ODataPrimitiveValue; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.geo.Geospatial; @@ -122,12 +122,14 @@ public class PrimitiveValueTest extends AbstractTest { @Test public void time() throws EdmPrimitiveTypeException { final String primitive = "-P9DT51M10.5063807S"; - final ODataValue value = - getClient().getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Time). - setText(primitive).build(); + final ODataValue value = getClient().getObjectFactory().newPrimitiveValueBuilder(). + setType(EdmPrimitiveTypeKind.Time).setText(primitive).build(); assertEquals(EdmPrimitiveTypeKind.Time, value.asPrimitive().getTypeKind()); - // performed cast to improve the check - assertEquals("-780670.5063807", value.asPrimitive().toCastValue(BigDecimal.class).toString()); + assertEquals(-780670.5063807, value.asPrimitive().toCastValue(BigDecimal.class)); + + final ODataPrimitiveValue write = getClient().getObjectFactory().newPrimitiveValueBuilder(). + setType(EdmPrimitiveTypeKind.Time).setValue(-780670.5063807).build(); + assertEquals(primitive, write.toString()); } @Test http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/397c82f1/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index ba29b92..23e6460 100644 --- a/pom.xml +++ b/pom.xml @@ -430,7 +430,7 @@ </goals> <configuration> <excludes> - <exclude>**/META-INF/services/*</exclude> + <exclude>**/META-INF/**</exclude> <exclude>**/*.txt</exclude> <exclude>**/*.ini</exclude> <exclude>**/*.bin</exclude>
