olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmarte...@apache.org
Subject [1/3] [OLINGO-260] providing proxy merge from ODataJClient. Still missing integration tests
Date Wed, 07 May 2014 10:58:10 GMT
Repository: olingo-odata4
Updated Branches:
  refs/heads/master 8caf3fece -> 6b7be9deb


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6b7be9de/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V4MetadataMojo.java
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V4MetadataMojo.java
b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V4MetadataMojo.java
index 042a558..2751726 100644
--- a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V4MetadataMojo.java
+++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V4MetadataMojo.java
@@ -48,145 +48,147 @@ import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
 @Mojo(name = "pojosV4", defaultPhase = LifecyclePhase.PROCESS_SOURCES)
 public class V4MetadataMojo extends AbstractMetadataMojo {
 
-    @Override
-    protected V4Utility getUtility() {
-        return (V4Utility) utility;
+  @Override
+  protected V4Utility getUtility() {
+    return (V4Utility) utility;
+  }
+
+  @Override
+  protected String getVersion() {
+    return ODataServiceVersion.V40.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.V40.name().toLowerCase();
-    }
+    try {
+      Velocity.addProperty(Velocity.RESOURCE_LOADER, "class");
+      Velocity.addProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName());
+
+      final Edm metadata =
+              ODataClientFactory.getV4().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<String> complexTypeNames = new HashSet<String>();
+      final File services = mkdir("META-INF/services");
+
+      for (EdmSchema schema : metadata.getSchemas()) {
+        utility = new V4Utility(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<String, Object> objs = new HashMap<String, Object>();
+
+        // 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.getV4().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<String, String> 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<String> complexTypeNames = new HashSet<String>();
-            final File services = mkdir("META-INF/services");
-
-            for (EdmSchema schema : metadata.getSchemas()) {
-                utility = new V4Utility(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<String, Object> objs = new HashMap<String, Object>();
-
-                // 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<String, String> 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);
-                    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);
-                    }
-
-                    for (EdmSingleton singleton : container.getSingletons()) {
-                        objs.clear();
-                        objs.put("singleton", singleton);
-                        parseObj(base, pkg, "singleton",
-                                utility.capitalize(singleton.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);
+          }
+
+          for (EdmSingleton singleton : container.getSingletons()) {
+            objs.clear();
+            objs.put("singleton", singleton);
+            parseObj(base, pkg, "singleton",
+                    utility.capitalize(singleton.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 executin mojo", t);
     }
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6b7be9de/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 e37ba10..b2f2160 100644
--- a/ext/pojogen-maven-plugin/src/main/resources/container.vm
+++ b/ext/pojogen-maven-plugin/src/main/resources/container.vm
@@ -50,6 +50,7 @@ import javax.xml.datatype.Duration;
 
 @Namespace("$namespace")
 @EntityContainer(name = "$container.Name",
+  namespace = "$namespace",
   isDefaultEntityContainer = $container.Default)
 public interface $utility.capitalize($container.Name) extends AbstractContainer {
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6b7be9de/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonEdmEnabledODataClient.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonEdmEnabledODataClient.java
b/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonEdmEnabledODataClient.java
index 4967fc6..bb06abf 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonEdmEnabledODataClient.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonEdmEnabledODataClient.java
@@ -40,4 +40,11 @@ public interface CommonEdmEnabledODataClient<UT extends CommonUpdateType>
extend
    * @return Edm
    */
   Edm getEdm(String metadataETag);
+
+  /**
+   * Return the cached Edm matadata information.
+   *
+   * @return Edm
+   */
+  Edm getCachedEdm();
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6b7be9de/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/batch/CommonBatchRequestFactory.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/batch/CommonBatchRequestFactory.java
b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/batch/CommonBatchRequestFactory.java
index 8b6420b..623bb8e 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/batch/CommonBatchRequestFactory.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/batch/CommonBatchRequestFactory.java
@@ -24,4 +24,12 @@ import java.io.Serializable;
  * OData batch request factory class.
  */
 public interface CommonBatchRequestFactory extends Serializable {
+
+  /**
+   * Gets a batch request object instance.
+   *
+   * @param serviceRoot service root.
+   * @return new ODataBatchRequest instance.
+   */
+  CommonODataBatchRequest getBatchRequest(String serviceRoot);
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6b7be9de/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/batch/v3/BatchRequestFactory.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/batch/v3/BatchRequestFactory.java
b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/batch/v3/BatchRequestFactory.java
index a3cbcc7..92d74c2 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/batch/v3/BatchRequestFactory.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/batch/v3/BatchRequestFactory.java
@@ -21,12 +21,10 @@ package org.apache.olingo.client.api.communication.request.batch.v3;
 import org.apache.olingo.client.api.communication.request.batch.CommonBatchRequestFactory;
 
 public interface BatchRequestFactory extends CommonBatchRequestFactory {
-  
+
   /**
-   * Gets a batch request object instance.
-   *
-   * @param serviceRoot service root.
-   * @return new ODataBatchRequest instance.
+   * {@inheritDoc }
    */
+  @Override
   ODataBatchRequest getBatchRequest(String serviceRoot);
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6b7be9de/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/batch/v4/BatchRequestFactory.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/batch/v4/BatchRequestFactory.java
b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/batch/v4/BatchRequestFactory.java
index 680b9c2..240e978 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/batch/v4/BatchRequestFactory.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/batch/v4/BatchRequestFactory.java
@@ -21,12 +21,10 @@ package org.apache.olingo.client.api.communication.request.batch.v4;
 import org.apache.olingo.client.api.communication.request.batch.CommonBatchRequestFactory;
 
 public interface BatchRequestFactory extends CommonBatchRequestFactory {
-  
+
   /**
-   * Gets a batch request object instance.
-   *
-   * @param serviceRoot service root.
-   * @return new ODataBatchRequest instance.
+   * {@inheritDoc }
    */
+  @Override
   ODataBatchRequest getBatchRequest(String serviceRoot);
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6b7be9de/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/EdmEnabledODataClientImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/EdmEnabledODataClientImpl.java
b/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/EdmEnabledODataClientImpl.java
index e0f6dda..531d500 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/EdmEnabledODataClientImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/EdmEnabledODataClientImpl.java
@@ -50,4 +50,8 @@ public class EdmEnabledODataClientImpl extends ODataClientImpl implements
EdmEna
     return this.edm;
   }
 
+  @Override
+  public Edm getCachedEdm() {
+    return this.edm;
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6b7be9de/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/EdmEnabledODataClientImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/EdmEnabledODataClientImpl.java
b/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/EdmEnabledODataClientImpl.java
index 238045f..b42f269 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/EdmEnabledODataClientImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/EdmEnabledODataClientImpl.java
@@ -34,7 +34,7 @@ public class EdmEnabledODataClientImpl extends ODataClientImpl implements
EdmEna
 
   public EdmEnabledODataClientImpl(final String serviceRoot) {
     super();
-    
+
     this.serviceRoot = serviceRoot;
     this.metadataETag = StringUtils.EMPTY;
   }
@@ -56,4 +56,9 @@ public class EdmEnabledODataClientImpl extends ODataClientImpl implements
EdmEna
     }
     return this.edm;
   }
+
+  @Override
+  public Edm getCachedEdm() {
+    return this.edm;
+  }
 }


Mime
View raw message