You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2014/01/23 17:32:06 UTC
[04/14] git commit: [OLINGO-109] Fix for on expanded entries
[OLINGO-109] Fix for on expanded entries
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/22164610
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/22164610
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/22164610
Branch: refs/heads/olingo-117
Commit: 22164610bc1fd2bd48acc71fed1f1a7822ec4f48
Parents: 53984da
Author: Chandan V A <ch...@sap.com>
Authored: Mon Jan 20 18:33:15 2014 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Mon Jan 20 18:33:15 2014 +0530
----------------------------------------------------------------------
.../core/ODataJPAResponseBuilderDefault.java | 19 +-
.../core/access/data/JPAEntityParser.java | 389 +++++++++----------
.../core/access/data/JPAExpandCallBack.java | 47 ++-
.../jpa/processor/core/access/data/JPALink.java | 8 +-
.../core/access/data/JPAEntityParserTest.java | 50 +--
.../JPAEntityParserTestForStaticMethods.java | 18 +-
.../processor/core/mock/data/EdmMockUtil.java | 16 +-
7 files changed, 270 insertions(+), 277 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/22164610/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java
index 2a5e446..04a0fbd 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java
@@ -83,21 +83,14 @@ public final class ODataJPAResponseBuilderDefault implements ODataJPAResponseBui
try {
edmEntityType = resultsView.getTargetEntitySet().getEntityType();
- List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>();
- Map<String, Object> edmPropertyValueMap = null;
+ List<Map<String, Object>> edmEntityList = null;
JPAEntityParser jpaResultParser = new JPAEntityParser();
final List<SelectItem> selectedItems = resultsView.getSelect();
if (selectedItems != null && selectedItems.size() > 0) {
- for (Object jpaEntity : jpaEntities) {
- edmPropertyValueMap =
- jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, buildSelectItemList(selectedItems, edmEntityType));
- edmEntityList.add(edmPropertyValueMap);
- }
+ edmEntityList =
+ jpaResultParser.parse2EdmEntityList(jpaEntities, buildSelectItemList(selectedItems, edmEntityType));
} else {
- for (Object jpaEntity : jpaEntities) {
- edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, edmEntityType);
- edmEntityList.add(edmPropertyValueMap);
- }
+ edmEntityList = jpaResultParser.parse2EdmEntityList(jpaEntities, edmEntityType);
}
expandList = resultsView.getExpand();
if (expandList != null && expandList.size() != 0) {
@@ -572,7 +565,9 @@ public final class ODataJPAResponseBuilderDefault implements ODataJPAResponseBui
List<EdmProperty> selectPropertyList = new ArrayList<EdmProperty>();
try {
for (SelectItem selectItem : selectItems) {
- selectPropertyList.add(selectItem.getProperty());
+ if (selectItem.getNavigationPropertySegments().size() <= 0) {
+ selectPropertyList.add(selectItem.getProperty());
+ }
}
for (EdmProperty keyProperty : entity.getKeyProperties()) {
flag = true;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/22164610/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
index dd030ce..f0ff44f 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
@@ -20,8 +20,11 @@ package org.apache.olingo.odata2.jpa.processor.core.access.data;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.olingo.odata2.api.edm.EdmAssociationEnd;
import org.apache.olingo.odata2.api.edm.EdmException;
@@ -32,6 +35,8 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleType;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
import org.apache.olingo.odata2.api.edm.EdmStructuralType;
import org.apache.olingo.odata2.api.edm.EdmTypeKind;
+import org.apache.olingo.odata2.api.uri.NavigationPropertySegment;
+import org.apache.olingo.odata2.api.uri.SelectItem;
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
@@ -62,67 +67,73 @@ public final class JPAEntityParser {
return jpaEmbeddableKeyMap.get(jpaEntityName);
}
- /**
- * The method returns a Hash Map of Properties and values for selected
- * properties of an EdmEntity Type
- *
- * @param jpaEntity
- * @param selectedItems
- * @return a Hash Map of Properties and values for given selected properties
- * of an EdmEntity Type
- * @throws ODataJPARuntimeException
- */
-
- public final HashMap<String, Object> parse2EdmPropertyValueMap(
- final Object jpaEntity, final List<EdmProperty> selectPropertyList)
+ public List<Map<String, Object>> parse2EdmEntityList(Collection<Object> jpaEntityList, List<EdmProperty> properties)
throws ODataJPARuntimeException {
+
+ if (jpaEntityList == null) {
+ return null;
+ }
+ List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>();
+ for (Object item : jpaEntityList) {
+ edmEntityList.add(parse2EdmPropertyValueMap(item, properties));
+ }
+
+ return edmEntityList;
+ }
+
+ @SuppressWarnings("unchecked")
+ public final <T> HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity,
+ final List<T> selectPropertyList) throws ODataJPARuntimeException {
+
HashMap<String, Object> edmEntity = new HashMap<String, Object>();
- String methodName = null;
- Method method = null;
- for (int i = 0; i < selectPropertyList.size(); i++) {
- String key = null;
- Object propertyValue = null;
- EdmProperty property = null;
- property = selectPropertyList.get(i);
+ HashMap<String, Method> accessModifierMap = null;
+ Object propertyValue = null;
+ EdmProperty property = null;
+ String jpaEntityAccessKey = null;
+
+ if (selectPropertyList.get(0) instanceof EdmProperty) {
+ jpaEntityAccessKey = jpaEntity.getClass().getName();
+ if (!jpaEntityAccessMap.containsKey(jpaEntityAccessKey)) {
+ accessModifierMap =
+ getAccessModifiers((List<EdmProperty>) selectPropertyList, jpaEntity.getClass(), ACCESS_MODIFIER_GET);
+ } else {
+ accessModifierMap = jpaEntityAccessMap.get(jpaEntityAccessKey);
+ }
+ }
+ for (Object item : selectPropertyList) {
+ propertyValue = jpaEntity;
+ if (item instanceof SelectItem) {
+ SelectItem selectItem = (SelectItem) item;
+ for (NavigationPropertySegment navPropSegement : selectItem.getNavigationPropertySegments()) {
+ Method method =
+ getAccessModifier(propertyValue.getClass(), navPropSegement.getNavigationProperty(), ACCESS_MODIFIER_GET);
+ propertyValue = getPropertyValue(method, propertyValue);
+ }
+ property = selectItem.getProperty();
+ } else if (item instanceof EdmProperty) {
+ property = (EdmProperty) item;
+ }
try {
- methodName = getAccessModifierName(property.getName(),
- property.getMapping(), ACCESS_MODIFIER_GET);
- String[] nameParts = methodName.split("\\.");
- if (nameParts.length > 1) {
- Object propertyVal = new Object();
- propertyVal = jpaEntity;
- for (String namePart : nameParts) {
- method = propertyVal.getClass().getMethod(
- namePart, (Class<?>[]) null);
- method.setAccessible(true);
- propertyVal = getProperty(method, propertyVal);
+ String propertyName = property.getName();
+ Method method = accessModifierMap.get(propertyName);
+ if (method == null) {
+ String methodName = jpaEmbeddableKeyMap.get(jpaEntityAccessKey).get(propertyName);
+ if (methodName != null) {
+ propertyValue = getEmbeddablePropertyValue(methodName, propertyValue);
}
- edmEntity.put(property.getName(), propertyVal);
} else {
- method = jpaEntity.getClass().getMethod(methodName,
- (Class<?>[]) null);
- method.setAccessible(true);
- propertyValue = getProperty(method, jpaEntity);
- key = property.getName();
- if (property.getType().getKind()
- .equals(EdmTypeKind.COMPLEX)) {
- try {
- propertyValue = parse2EdmPropertyValueMap(
- propertyValue,
- (EdmStructuralType) property.getType());
- } catch (ODataJPARuntimeException e) {
- throw e;
- }
- }
- edmEntity.put(key, propertyValue);
+ propertyValue = getPropertyValue(accessModifierMap.get(propertyName), propertyValue);
}
+ if (property.getType().getKind()
+ .equals(EdmTypeKind.COMPLEX)) {
+ propertyValue = parse2EdmPropertyValueMap(propertyValue, (EdmStructuralType) property.getType());
+ }
+ edmEntity.put(propertyName, propertyValue);
} catch (EdmException e) {
throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
} catch (SecurityException e) {
throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (NoSuchMethodException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
} catch (IllegalArgumentException e) {
throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
}
@@ -131,92 +142,28 @@ public final class JPAEntityParser {
return edmEntity;
}
- /**
- * The method returns a Hash Map of Properties and values for an EdmEntity
- * Type The method uses reflection on object jpaEntity to get the list of
- * accessModifier method. Then uses the accessModifier method to extract the value from
- * JPAEntity.
- *
- * @param jpaEntity
- * @param structuralType
- * @return a Hash Map of Properties and values for given EdmEntity Type
- * @throws ODataJPARuntimeException
- */
- public final HashMap<String, Object> parse2EdmPropertyValueMap(
- final Object jpaEntity, final EdmStructuralType structuralType)
- throws ODataJPARuntimeException {
-
- if (jpaEntity == null || structuralType == null) {
+ public final List<Map<String, Object>> parse2EdmEntityList(final Collection<Object> jpaEntityList,
+ final EdmStructuralType structuralType) throws ODataJPARuntimeException {
+ if (jpaEntityList == null || structuralType == null) {
return null;
}
-
- String jpaEntityAccessKey = jpaEntity.getClass().getName();
-
- if (!jpaEntityAccessMap.containsKey(jpaEntityAccessKey)) {
- jpaEntityAccessMap.put(jpaEntityAccessKey,
- getAccessModifiers(jpaEntity, structuralType, ACCESS_MODIFIER_GET));
+ List<EdmProperty> edmProperties = getEdmProperties(structuralType);
+ List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>();
+ for (Object jpaEntity : jpaEntityList) {
+ edmEntityList.add(parse2EdmPropertyValueMap(jpaEntity, edmProperties));
}
- HashMap<String, Object> edmEntity = new HashMap<String, Object>();
- HashMap<String, Method> getters = jpaEntityAccessMap
- .get(jpaEntityAccessKey);
- HashMap<String, String> embeddableKeys = jpaEmbeddableKeyMap
- .get(jpaEntityAccessKey);
-
- try {
- for (String key : getters.keySet()) {
-
- EdmProperty property = (EdmProperty) structuralType
- .getProperty(key);
-
- Method method = getters.get(key);
- Object propertyValue = null;
-
- if (method != null) {
- getters.get(key).setAccessible(true);
- propertyValue = getProperty(method, jpaEntity);
- }
- if (property.getType().getKind().equals(EdmTypeKind.COMPLEX)) {
- propertyValue = parse2EdmPropertyValueMap(propertyValue,
- (EdmStructuralType) property.getType());
- }
-
- edmEntity.put(key, propertyValue);
-
- }
+ return edmEntityList;
+ }
- if (embeddableKeys != null) {
- for (String key : embeddableKeys.keySet()) {
- String name = embeddableKeys.get(key);
- String[] nameParts = name.split("\\.");
- Object propertyValue = jpaEntity;
- Method method = null;
- for (String namePart : nameParts) {
- if (propertyValue == null) {
- break;
- }
- method = propertyValue.getClass().getMethod(
- namePart, (Class<?>[]) null);
- method.setAccessible(true);
- propertyValue = getProperty(method, propertyValue);
- }
- edmEntity.put(key, propertyValue);
- }
- }
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (SecurityException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (NoSuchMethodException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (IllegalArgumentException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ public final HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity,
+ final EdmStructuralType structuralType) throws ODataJPARuntimeException {
+ if (jpaEntity == null || structuralType == null) {
+ return null;
}
- return edmEntity;
+ return parse2EdmPropertyValueMap(jpaEntity, getEdmProperties(structuralType));
}
- // This method appends the associated entities as a java list to an expanded
- // map of a source entity
public final HashMap<String, Object> parse2EdmNavigationValueMap(
final Object jpaEntity, final List<EdmNavigationProperty> navigationPropertyList)
throws ODataJPARuntimeException {
@@ -233,7 +180,7 @@ public final class JPAEntityParser {
Method getterMethod = jpaEntity.getClass()
.getDeclaredMethod(methodName, (Class<?>[]) null);
getterMethod.setAccessible(true);
- result = getProperty(getterMethod, jpaEntity);
+ result = getPropertyValue(getterMethod, jpaEntity);
navigationMap.put(navigationProperty.getName(), result);
}
} catch (IllegalArgumentException e) {
@@ -269,75 +216,16 @@ public final class JPAEntityParser {
public HashMap<String, Method> getAccessModifiers(final Object jpaEntity,
final EdmStructuralType structuralType, final String accessModifier) throws ODataJPARuntimeException {
-
- HashMap<String, Method> accessModifierMap = new HashMap<String, Method>();
- HashMap<String, String> embeddableKey = new HashMap<String, String>();
- Method acceserMethod = null;
- EdmProperty property = null;
- try {
- for (String propertyName : structuralType.getPropertyNames()) {
- try {
- property = (EdmProperty) structuralType
- .getProperty(propertyName);
-
- String name = getAccessModifierName(property.getName(),
- property.getMapping(), accessModifier);
- String[] nameParts = name.split("\\.");
- if (nameParts.length > 1) {
- embeddableKey.put(propertyName, name);
- } else {
- if (accessModifier.equals(ACCESS_MODIFIER_SET)) {
- JPAEdmMapping jpaEdmMapping = (JPAEdmMapping) property.getMapping();
- accessModifierMap.put(
- propertyName,
- jpaEntity.getClass().getMethod(name, new Class<?>[] { jpaEdmMapping.getJPAType() }));
- } else {
- acceserMethod = jpaEntity.getClass().getMethod(name, (Class<?>[]) null);
- }
- }
-
- } catch (EdmException exp) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, exp);
- } catch (NoSuchMethodException e1) {
- try {
- EdmSimpleType edmSimpleType = (EdmSimpleType) property.getType();
- if (edmSimpleType == EdmSimpleTypeKind.Boolean.getEdmSimpleTypeInstance()
- && accessModifier.equals("get")) {
- String nameWithIs = getAccessModifierName(property.getName(),
- property.getMapping(), ACCESS_MODIFIER_IS);
- acceserMethod = jpaEntity.getClass().getMethod(nameWithIs, (Class<?>[]) null);
- }
- } catch (EdmException exp) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, exp);
- } catch (NoSuchMethodException exp) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, exp);
- } catch (SecurityException exp) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, exp);
- }
- } catch (SecurityException e1) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e1);
- }
- if (acceserMethod != null) {
- accessModifierMap.put(
- propertyName,
- acceserMethod);
- }
-
- }
- } catch (EdmException exp) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, exp);
- }
-
- if (!embeddableKey.isEmpty()) {
- jpaEmbeddableKeyMap.put(jpaEntity.getClass().getName(),
- embeddableKey);
- }
- return accessModifierMap;
+ return getAccessModifiers(getEdmProperties(structuralType), jpaEntity.getClass(), accessModifier);
}
- public static Object getProperty(final Method method, final Object entity) throws ODataJPARuntimeException {
+ public static Object getPropertyValue(final Method method, final Object entity) throws ODataJPARuntimeException {
Object propertyValue = null;
+ if (method == null) {
+ return null;
+ }
try {
+ method.setAccessible(true);
Class<?> returnType = method.getReturnType();
if (returnType.equals(char[].class)) {
@@ -366,6 +254,31 @@ public final class JPAEntityParser {
throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
} catch (InvocationTargetException e) {
throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ } catch (SecurityException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+
+ return propertyValue;
+ }
+
+ public Object getEmbeddablePropertyValue(final String methodName, Object jpaEntity) throws ODataJPARuntimeException {
+
+ String[] nameParts = methodName.split("\\.");
+ Object propertyValue = jpaEntity;
+ Method method = null;
+ try {
+ for (String namePart : nameParts) {
+ if (propertyValue == null) {
+ break;
+ }
+ method = propertyValue.getClass().getMethod(namePart, (Class<?>[]) null);
+ method.setAccessible(true);
+ propertyValue = getPropertyValue(method, propertyValue);
+ }
+ } catch (NoSuchMethodException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ } catch (SecurityException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
}
return propertyValue;
}
@@ -445,7 +358,7 @@ public final class JPAEntityParser {
}
- public Method getAccessModifier(final Object jpaEntity, final EdmNavigationProperty navigationProperty,
+ public Method getAccessModifier(final Class<?> jpaEntityType, final EdmNavigationProperty navigationProperty,
final String accessModifier)
throws ODataJPARuntimeException {
@@ -467,8 +380,7 @@ public final class JPAEntityParser {
break;
}
}
- return jpaEntity.getClass().getMethod(name,
- params);
+ return jpaEntityType.getMethod(name, params);
} catch (NoSuchMethodException e) {
throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
@@ -477,6 +389,89 @@ public final class JPAEntityParser {
} catch (EdmException e) {
throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
}
+ }
+
+ private HashMap<String, Method> getAccessModifiers(List<EdmProperty> edmProperties, Class<?> jpaEntityType,
+ String accessModifier) throws ODataJPARuntimeException {
+
+ HashMap<String, Method> accessModifierMap = jpaEntityAccessMap.get(jpaEntityType.getName());
+ if (accessModifierMap == null) {
+ accessModifierMap = new HashMap<String, Method>();
+ jpaEntityAccessMap.put(jpaEntityType.getName(), accessModifierMap);
+ }
+ HashMap<String, String> embeddableKey = jpaEmbeddableKeyMap.get(jpaEntityType.getName());
+ if (embeddableKey == null) {
+ embeddableKey = new HashMap<String, String>();
+ }
+
+ Method method = null;
+ try {
+ for (EdmProperty property : edmProperties) {
+ String propertyName = property.getName();
+ if (accessModifierMap.containsKey(propertyName)) {
+ continue;
+ }
+ String methodName = getAccessModifierName(property.getName(), property.getMapping(), accessModifier);
+ String[] nameParts = methodName.split("\\.");
+ try {
+ if (nameParts.length > 1) {
+ if (!embeddableKey.containsKey(propertyName)) {
+ embeddableKey.put(propertyName, methodName);
+ continue;
+ }
+ } else {
+ if (accessModifier.equals(ACCESS_MODIFIER_SET)) {
+ JPAEdmMapping jpaEdmMapping = (JPAEdmMapping) property.getMapping();
+ accessModifierMap.put(propertyName, jpaEntityType.getMethod(methodName,
+ new Class<?>[] { jpaEdmMapping.getJPAType() }));
+ } else {
+ method = jpaEntityType.getMethod(methodName, (Class<?>[]) null);
+ }
+ }
+ } catch (EdmException exp) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, exp);
+ } catch (NoSuchMethodException e1) {
+ try {
+ EdmSimpleType edmSimpleType = (EdmSimpleType) property.getType();
+ if (edmSimpleType == EdmSimpleTypeKind.Boolean.getEdmSimpleTypeInstance()
+ && accessModifier.equals(ACCESS_MODIFIER_GET)) {
+ String nameWithIs = getAccessModifierName(property.getName(),
+ property.getMapping(), ACCESS_MODIFIER_IS);
+ method = jpaEntityType.getMethod(nameWithIs, (Class<?>[]) null);
+ }
+ } catch (EdmException exp) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, exp);
+ } catch (NoSuchMethodException exp) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, exp);
+ } catch (SecurityException exp) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, exp);
+ }
+ } catch (SecurityException e1) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e1);
+ }
+ if (method != null) {
+ accessModifierMap.put(propertyName, method);
+ }
+ }
+ } catch (EdmException exp) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, exp);
+ }
+ if (!embeddableKey.isEmpty()) {
+ jpaEmbeddableKeyMap.put(jpaEntityType.getName(), embeddableKey);
+ }
+ return accessModifierMap;
+ }
+ private List<EdmProperty> getEdmProperties(EdmStructuralType structuralType) throws ODataJPARuntimeException {
+ List<EdmProperty> edmProperties = new ArrayList<EdmProperty>();
+ try {
+ for (String propertyName : structuralType.getPropertyNames()) {
+ edmProperties.add((EdmProperty) structuralType.getProperty(propertyName));
+ }
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+ return edmProperties;
}
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/22164610/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAExpandCallBack.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAExpandCallBack.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAExpandCallBack.java
index 7383081..4bfa743 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAExpandCallBack.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAExpandCallBack.java
@@ -31,6 +31,7 @@ import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.edm.EdmEntityType;
import org.apache.olingo.odata2.api.edm.EdmException;
import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties.ODataEntityProviderPropertiesBuilder;
import org.apache.olingo.odata2.api.ep.callback.OnWriteEntryContent;
@@ -50,6 +51,7 @@ public class JPAExpandCallBack implements OnWriteFeedContent, OnWriteEntryConten
private URI baseUri;
private List<ArrayList<NavigationPropertySegment>> expandList;
private EdmEntitySet nextEntitySet = null;
+ private HashMap<String, List<EdmProperty>> edmPropertyMap = new HashMap<String, List<EdmProperty>>();
private JPAExpandCallBack(final URI baseUri, final List<ArrayList<NavigationPropertySegment>> expandList) {
super();
@@ -97,28 +99,63 @@ public class JPAExpandCallBack implements OnWriteFeedContent, OnWriteEntryConten
return result;
}
+ private List<EdmProperty> getEdmProperties(EdmEntitySet entitySet, ExpandSelectTreeNode expandTreeNode)
+ throws ODataApplicationException {
+
+ try {
+ String name = entitySet.getName();
+ if (edmPropertyMap.containsKey(name)) {
+ return edmPropertyMap.get(name);
+ }
+ List<EdmProperty> edmProperties = new ArrayList<EdmProperty>();
+ edmProperties.addAll(expandTreeNode.getProperties());
+ boolean hit = false;
+ for (EdmProperty keyProperty : entitySet.getEntityType().getKeyProperties()) {
+ hit = false;
+ for (EdmProperty property : edmProperties) {
+ if (property.getName().equals(keyProperty.getName())) {
+ hit = true;
+ break;
+ }
+ }
+ if (hit == false) {
+ edmProperties.add(keyProperty);
+ }
+ }
+ edmPropertyMap.put(name, edmProperties);
+ return edmProperties;
+ } catch (EdmException e) {
+ throw new ODataApplicationException(e.getMessage(), Locale.getDefault(), e);
+ }
+ }
+
@Override
public WriteFeedCallbackResult retrieveFeedResult(final WriteFeedCallbackContext context)
throws ODataApplicationException {
WriteFeedCallbackResult result = new WriteFeedCallbackResult();
HashMap<String, Object> inlinedEntry = (HashMap<String, Object>) context.getEntryData();
List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>();
- Map<String, Object> edmPropertyValueMap = null;
JPAEntityParser jpaResultParser = new JPAEntityParser();
List<EdmNavigationProperty> currentNavPropertyList = null;
EdmNavigationProperty currentNavigationProperty = context.getNavigationProperty();
+ ExpandSelectTreeNode currentExpandTreeNode = context.getCurrentExpandSelectTreeNode();
+
try {
@SuppressWarnings({ "unchecked" })
Collection<Object> listOfItems = (Collection<Object>) inlinedEntry.get(context.getNavigationProperty().getName());
if (nextEntitySet == null) {
nextEntitySet = context.getSourceEntitySet().getRelatedEntitySet(currentNavigationProperty);
}
- for (Object object : listOfItems) {
- edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(object, nextEntitySet.getEntityType());
- edmEntityList.add(edmPropertyValueMap);
+ if (currentExpandTreeNode.getProperties().size() > 0) {
+ edmEntityList =
+ jpaResultParser.parse2EdmEntityList(listOfItems, getEdmProperties(nextEntitySet,
+ currentExpandTreeNode));
+ } else {
+ edmEntityList = jpaResultParser.parse2EdmEntityList(listOfItems, nextEntitySet.getEntityType());
}
result.setFeedData(edmEntityList);
- if (context.getCurrentExpandSelectTreeNode().getLinks().size() > 0) {
+
+ if (currentExpandTreeNode.getLinks().size() > 0) {
currentNavPropertyList = new ArrayList<EdmNavigationProperty>();
EdmNavigationProperty nextNavProperty =
getNextNavigationProperty(context.getSourceEntitySet().getEntityType(), context.getNavigationProperty());
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/22164610/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPALink.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPALink.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPALink.java
index 91ac44e..437c057 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPALink.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPALink.java
@@ -154,10 +154,10 @@ public class JPALink {
try {
JPAEntityParser entityParser = new JPAEntityParser();
- Method setMethod = entityParser.getAccessModifier(jpaEntity,
+ Method setMethod = entityParser.getAccessModifier(jpaEntity.getClass(),
targetNavigationProperty, JPAEntityParser.ACCESS_MODIFIER_SET);
- Method getMethod = entityParser.getAccessModifier(jpaEntity,
+ Method getMethod = entityParser.getAccessModifier(jpaEntity.getClass(),
targetNavigationProperty, JPAEntityParser.ACCESS_MODIFIER_GET);
if (getMethod.getReturnType().getTypeParameters() != null
@@ -300,12 +300,12 @@ public class JPALink {
}
try {
JPAEntityParser entityParser = new JPAEntityParser();
- Method setMethod = entityParser.getAccessModifier(sourceJPAEntity,
+ Method setMethod = entityParser.getAccessModifier(sourceJPAEntity.getClass(),
navigationProperty, JPAEntityParser.ACCESS_MODIFIER_SET);
switch (navigationProperty.getMultiplicity()) {
case MANY:
- Method getMethod = entityParser.getAccessModifier(sourceJPAEntity,
+ Method getMethod = entityParser.getAccessModifier(sourceJPAEntity.getClass(),
navigationProperty, JPAEntityParser.ACCESS_MODIFIER_GET);
Collection<Object> relatedEntities = (Collection<Object>) getMethod.invoke(sourceJPAEntity);
relatedEntities.addAll(targetJPAEntities);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/22164610/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTest.java
index e1c7c35..01bf774 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTest.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTest.java
@@ -132,7 +132,7 @@ public class JPAEntityParserTest {
EasyMock.expect(edmTyped.getType()).andStubThrow(
new EdmException(null));
EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);
- EasyMock.expect(edmTyped.getName()).andReturn("identifier");
+ EasyMock.expect(edmTyped.getName()).andReturn("identifier").anyTimes();
EasyMock.replay(edmTyped);
EasyMock.expect(structuralType.getProperty("identifier"))
.andStubReturn(edmTyped);
@@ -144,7 +144,7 @@ public class JPAEntityParserTest {
EasyMock.expect(edmMapping01.getInternalName()).andStubReturn(
"value");
EasyMock.replay(edmMapping01);
- EasyMock.expect(edmTyped01.getName()).andReturn("value");
+ EasyMock.expect(edmTyped01.getName()).andReturn("value").anyTimes();
EasyMock.expect(edmTyped01.getType()).andStubReturn(edmType01);
EasyMock.expect(edmTyped01.getMapping())
.andStubReturn(edmMapping01);
@@ -204,52 +204,6 @@ public class JPAEntityParserTest {
}
}
- @Test
- public void testparse2EdmPropertyValueMapFromList() {
- JPAEntityParser resultParser = new JPAEntityParser();
- demoItem jpaEntity = new demoItem("laptop", 1);
- DemoRelatedEntity relatedEntity = new DemoRelatedEntity("DemoOrder");
- jpaEntity.setRelatedEntity(relatedEntity);
- List<EdmProperty> selectPropertyList = new ArrayList<EdmProperty>();
- // Mocking EdmProperties
- EdmProperty edmProperty1 = EasyMock.createMock(EdmProperty.class);
- EdmProperty edmProperty2 = EasyMock.createMock(EdmProperty.class);
- EdmType edmType1 = EasyMock.createMock(EdmType.class);
- EdmType edmType2 = EasyMock.createMock(EdmType.class);
- EdmMapping mapping1 = EasyMock.createMock(EdmMapping.class);
- EdmMapping mapping2 = EasyMock.createMock(EdmMapping.class);
- try {
- EasyMock.expect(edmType1.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
- EasyMock.replay(edmType1);
- EasyMock.expect(mapping1.getInternalName()).andStubReturn("id");
- EasyMock.replay(mapping1);
- EasyMock.expect(edmProperty1.getName()).andStubReturn("Id");
- EasyMock.expect(edmProperty1.getMapping()).andStubReturn(mapping1);
- EasyMock.expect(edmProperty1.getType()).andStubReturn(edmType1);
- EasyMock.replay(edmProperty1);
- EasyMock.expect(edmType2.getKind()).andStubReturn(EdmTypeKind.COMPLEX);
- EasyMock.replay(edmType2);
- EasyMock.expect(mapping2.getInternalName()).andStubReturn("relatedEntity.order");
- EasyMock.replay(mapping2);
- EasyMock.expect(edmProperty2.getName()).andStubReturn("Order");
- EasyMock.expect(edmProperty2.getMapping()).andStubReturn(mapping2);
- EasyMock.expect(edmProperty2.getType()).andStubReturn(edmType2);
- EasyMock.replay(edmProperty2);
-
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- selectPropertyList.add(edmProperty1);
- selectPropertyList.add(edmProperty2);
- try {
- Map<String, Object> result = resultParser.parse2EdmPropertyValueMap(jpaEntity, selectPropertyList);
- assertEquals("DemoOrder", result.get("Order"));
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
// This unit tests when there is a complex type in the select list
@SuppressWarnings("unchecked")
@Test
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/22164610/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTestForStaticMethods.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTestForStaticMethods.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTestForStaticMethods.java
index e75b060..22bac6c 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTestForStaticMethods.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTestForStaticMethods.java
@@ -73,7 +73,7 @@ public class JPAEntityParserTestForStaticMethods {
public void testGetPropertyCharacter() {
try {
Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharacter", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getProperty(method, this);
+ String output = (String) JPAEntityParser.getPropertyValue(method, this);
assertEquals("A", output);
} catch (NoSuchMethodException e) {
@@ -89,7 +89,7 @@ public class JPAEntityParserTestForStaticMethods {
public void testGetPropertyCharacterNull() {
try {
Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharacterNull", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getProperty(method, this);
+ String output = (String) JPAEntityParser.getPropertyValue(method, this);
assertNull(output);
} catch (NoSuchMethodException e) {
@@ -105,7 +105,7 @@ public class JPAEntityParserTestForStaticMethods {
public void testGetPropertyCharacterArray() {
try {
Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharacterArray", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getProperty(method, this);
+ String output = (String) JPAEntityParser.getPropertyValue(method, this);
assertEquals("AB", output);
} catch (NoSuchMethodException e) {
@@ -121,7 +121,7 @@ public class JPAEntityParserTestForStaticMethods {
public void testGetPropertyCharacterArrayNull() {
try {
Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharacterArrayNull", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getProperty(method, this);
+ String output = (String) JPAEntityParser.getPropertyValue(method, this);
assertNull(output);
} catch (NoSuchMethodException e) {
@@ -137,7 +137,7 @@ public class JPAEntityParserTestForStaticMethods {
public void testGetPropertyChar() {
try {
Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getChar", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getProperty(method, this);
+ String output = (String) JPAEntityParser.getPropertyValue(method, this);
assertEquals("A", output);
} catch (NoSuchMethodException e) {
@@ -153,7 +153,7 @@ public class JPAEntityParserTestForStaticMethods {
public void testGetPropertyCharNull() {
try {
Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharNull", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getProperty(method, this);
+ String output = (String) JPAEntityParser.getPropertyValue(method, this);
assertNull(output);
} catch (NoSuchMethodException e) {
@@ -169,7 +169,7 @@ public class JPAEntityParserTestForStaticMethods {
public void testGetPropertyCharArray() {
try {
Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharArray", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getProperty(method, this);
+ String output = (String) JPAEntityParser.getPropertyValue(method, this);
assertEquals("AB", output);
} catch (NoSuchMethodException e) {
@@ -185,7 +185,7 @@ public class JPAEntityParserTestForStaticMethods {
public void testGetPropertyCharArrayNull() {
try {
Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharArrayNull", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getProperty(method, this);
+ String output = (String) JPAEntityParser.getPropertyValue(method, this);
assertNull(output);
} catch (NoSuchMethodException e) {
@@ -201,7 +201,7 @@ public class JPAEntityParserTestForStaticMethods {
public void testGetPropertyCharArrayValueNull() {
try {
Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharArrayValueNull", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getProperty(method, this);
+ String output = (String) JPAEntityParser.getPropertyValue(method, this);
assertEquals("A\u0000", output);
} catch (NoSuchMethodException e) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/22164610/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtil.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtil.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtil.java
index e525ffd..632a299 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtil.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtil.java
@@ -55,6 +55,9 @@ public class EdmMockUtil {
Map<String, ExpandSelectTreeNode> links = new HashMap<String, ExpandSelectTreeNode>();
links.put("SalesOrderLineItemDetails", nextExpandNode);
EasyMock.expect(expandNode.getLinks()).andStubReturn(links);
+ List<EdmProperty> edmPropertyList = new ArrayList<EdmProperty>();
+ edmPropertyList.add(mockEdmPropertyOfTarget());
+ EasyMock.expect(expandNode.getProperties()).andReturn(edmPropertyList).anyTimes();
EasyMock.replay(expandNode);
return expandNode;
}
@@ -63,6 +66,9 @@ public class EdmMockUtil {
ExpandSelectTreeNode expandNode = EasyMock.createMock(ExpandSelectTreeNode.class);
Map<String, ExpandSelectTreeNode> links = new HashMap<String, ExpandSelectTreeNode>();
EasyMock.expect(expandNode.getLinks()).andStubReturn(links);
+ List<EdmProperty> edmPropertyList = new ArrayList<EdmProperty>();
+ edmPropertyList.add(mockEdmPropertyOfTarget());
+ EasyMock.expect(expandNode.getProperties()).andReturn(edmPropertyList).anyTimes();
EasyMock.replay(expandNode);
return expandNode;
}
@@ -85,7 +91,6 @@ public class EdmMockUtil {
writeContext.setNavigationProperty(mockNavigationProperty());
writeContext.setSourceEntitySet(mockSourceEntitySet());
writeContext.setEntryData(getFeedData());
-
} catch (URISyntaxException e) {
fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
}
@@ -132,7 +137,9 @@ public class EdmMockUtil {
EasyMock.expect(entityType.getProperty("id")).andStubReturn(property1);
EasyMock.expect(entityType.getProperty("description")).andStubReturn(mockEdmPropertyOfSource2());
EasyMock.expect(entityType.getPropertyNames()).andStubReturn(propertyNames);
-
+ List<EdmProperty> keyProperties = new ArrayList<EdmProperty>();
+ keyProperties.add(property1);
+ EasyMock.expect(entityType.getKeyProperties()).andStubReturn(keyProperties);
} catch (EdmException e) {
fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
}
@@ -234,6 +241,7 @@ public class EdmMockUtil {
EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
try {
EasyMock.expect(entitySet.getEntityType()).andStubReturn(mockTargetEdmEntityType());
+ EasyMock.expect(entitySet.getName()).andStubReturn("SalesOrderLineItems");
} catch (EdmException e) {
fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
}
@@ -289,6 +297,10 @@ public class EdmMockUtil {
EdmProperty property = mockEdmPropertyOfTarget();
EasyMock.expect(entityType.getProperty("price")).andStubReturn(property);
EasyMock.expect(entityType.getPropertyNames()).andStubReturn(propertyNames);
+
+ List<EdmProperty> keyProperties = new ArrayList<EdmProperty>();
+ keyProperties.add(property);
+ EasyMock.expect(entityType.getKeyProperties()).andStubReturn(keyProperties);
} catch (EdmException e) {
fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);