You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by tb...@apache.org on 2013/12/20 16:18:12 UTC

[10/12] git commit: [OLINGO-95] Refactor ExpandSelectTreeBuilder in smaller methods

[OLINGO-95] Refactor ExpandSelectTreeBuilder in smaller methods


Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/33aaa3ae
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/33aaa3ae
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/33aaa3ae

Branch: refs/heads/ODataServlet
Commit: 33aaa3ae02230cf0d90e387d91df84738972e58f
Parents: 3bd5905
Author: Christian Amend <ch...@apache.org>
Authored: Fri Dec 20 14:41:41 2013 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Fri Dec 20 14:42:29 2013 +0100

----------------------------------------------------------------------
 .../core/uri/ExpandSelectTreeNodeImpl.java      | 81 +++++++++++---------
 1 file changed, 43 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/33aaa3ae/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/ExpandSelectTreeNodeImpl.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/ExpandSelectTreeNodeImpl.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/ExpandSelectTreeNodeImpl.java
index ba3f624..0237cdf 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/ExpandSelectTreeNodeImpl.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/ExpandSelectTreeNodeImpl.java
@@ -168,7 +168,7 @@ public class ExpandSelectTreeNodeImpl extends ExpandSelectTreeNode {
 
   public class ExpandSelectTreeNodeBuilderImpl extends ExpandSelectTreeNodeBuilder {
 
-    EdmEntitySet entitySet;
+    private EdmEntitySet entitySet;
     private List<String> selectedPropertyNames;
     private List<String> selectedNavigationPropertyNames;
     private Map<String, ExpandSelectTreeNode> customExpandedNavigationProperties;
@@ -184,60 +184,65 @@ public class ExpandSelectTreeNodeImpl extends ExpandSelectTreeNode {
     public ExpandSelectTreeNode build() throws EdmException {
       EdmEntityType entityType = entitySet.getEntityType();
       if (selectedPropertyNames != null) {
-        for (String propertyName : selectedPropertyNames) {
-          EdmTyped property = entityType.getProperty(propertyName);
-          if (property == null) {
-            throw new EdmException(EdmException.PROPERTYNOTFOUND.addContent(propertyName));
-          } else if (!(property instanceof EdmProperty)) {
-            throw new EdmException(EdmException.MUSTBEPROPERTY.addContent(propertyName));
-          }
-          addProperty((EdmProperty) property);
-        }
+        handleProperties(entityType);
       }
 
       if (selectedNavigationPropertyNames != null) {
         setAllKindFalse();
-        for (String navigationPropertyName : selectedNavigationPropertyNames) {
-          EdmTyped navigationProperty = entityType.getProperty(navigationPropertyName);
-          if (navigationProperty == null) {
-            throw new EdmException(EdmException.NAVIGATIONPROPERTYNOTFOUND.addContent(navigationPropertyName));
-          } else if (!(navigationProperty instanceof EdmNavigationProperty)) {
-            throw new EdmException(EdmException.MUSTBENAVIGATIONPROPERTY.addContent(navigationPropertyName));
-          }
-          putLink(navigationPropertyName, null);
-        }
+        handleLinks(entityType, selectedNavigationPropertyNames, null);
       }
 
       if (expandedNavigationPropertyNames != null) {
         ExpandSelectTreeNodeImpl subNode = new ExpandSelectTreeNodeImpl();
         subNode.setExplicitlySelected();
-        for (String navigationPropertyName : expandedNavigationPropertyNames) {
-          EdmTyped navigationProperty = entityType.getProperty(navigationPropertyName);
-          if (navigationProperty == null) {
-            throw new EdmException(EdmException.NAVIGATIONPROPERTYNOTFOUND.addContent(navigationPropertyName));
-          } else if (!(navigationProperty instanceof EdmNavigationProperty)) {
-            throw new EdmException(EdmException.MUSTBENAVIGATIONPROPERTY.addContent(navigationPropertyName));
-          }
-          putLink(navigationPropertyName, subNode);
-        }
+        handleLinks(entityType, expandedNavigationPropertyNames, subNode);
       }
 
       if (customExpandedNavigationProperties != null) {
-        for (Map.Entry<String, ExpandSelectTreeNode> entry : customExpandedNavigationProperties.entrySet()) {
-          EdmTyped navigationProperty = entityType.getProperty(entry.getKey());
-          if (navigationProperty == null) {
-            throw new EdmException(EdmException.NAVIGATIONPROPERTYNOTFOUND.addContent(entry.getKey()));
-          }
-          if (!(navigationProperty instanceof EdmNavigationProperty)) {
-            throw new EdmException(EdmException.MUSTBENAVIGATIONPROPERTY.addContent(entry.getKey()));
-          }
-          putLink(entry.getKey(), (ExpandSelectTreeNodeImpl) entry.getValue());
-        }
+        handleCustomLinks(entityType);
       }
 
       return ExpandSelectTreeNodeImpl.this;
     }
 
+    private void handleCustomLinks(final EdmEntityType entityType) throws EdmException {
+      for (Map.Entry<String, ExpandSelectTreeNode> entry : customExpandedNavigationProperties.entrySet()) {
+        EdmTyped navigationProperty = entityType.getProperty(entry.getKey());
+        if (navigationProperty == null) {
+          throw new EdmException(EdmException.NAVIGATIONPROPERTYNOTFOUND.addContent(entry.getKey()));
+        }
+        if (!(navigationProperty instanceof EdmNavigationProperty)) {
+          throw new EdmException(EdmException.MUSTBENAVIGATIONPROPERTY.addContent(entry.getKey()));
+        }
+        putLink(entry.getKey(), (ExpandSelectTreeNodeImpl) entry.getValue());
+      }
+    }
+
+    private void handleLinks(final EdmEntityType entityType, final List<String> names,
+        final ExpandSelectTreeNodeImpl subNode) throws EdmException {
+      for (String navigationPropertyName : names) {
+        EdmTyped navigationProperty = entityType.getProperty(navigationPropertyName);
+        if (navigationProperty == null) {
+          throw new EdmException(EdmException.NAVIGATIONPROPERTYNOTFOUND.addContent(navigationPropertyName));
+        } else if (!(navigationProperty instanceof EdmNavigationProperty)) {
+          throw new EdmException(EdmException.MUSTBENAVIGATIONPROPERTY.addContent(navigationPropertyName));
+        }
+        putLink(navigationPropertyName, subNode);
+      }
+    }
+
+    private void handleProperties(final EdmEntityType entityType) throws EdmException {
+      for (String propertyName : selectedPropertyNames) {
+        EdmTyped property = entityType.getProperty(propertyName);
+        if (property == null) {
+          throw new EdmException(EdmException.PROPERTYNOTFOUND.addContent(propertyName));
+        } else if (!(property instanceof EdmProperty)) {
+          throw new EdmException(EdmException.MUSTBEPROPERTY.addContent(propertyName));
+        }
+        addProperty((EdmProperty) property);
+      }
+    }
+
     @Override
     public ExpandSelectTreeNodeBuilder selectedProperties(final List<String> selectedPropertyNames) {
       this.selectedPropertyNames = selectedPropertyNames;