@SuppressWarnings("unchecked") @Test public void testparse2EdmPropertyValueMapFromListComplex() { JPAEntityParser resultParser = new JPAEntityParser(); demoItem jpaEntity = new demoItem("laptop", 1); DemoRelatedEntity relatedEntity = new DemoRelatedEntity("DemoOrder"); jpaEntity.setRelatedEntity(relatedEntity); List<EdmProperty> selectPropertyList = new ArrayList<EdmProperty>(); EdmProperty edmProperty1 = EasyMock.createMock(EdmProperty.class); EdmProperty edmProperty2 = EasyMock.createMock(EdmProperty.class); EdmProperty edmComplexProperty = EasyMock.createMock(EdmProperty.class); EdmType edmType1 = EasyMock.createMock(EdmType.class); EdmStructuralType edmType2 = EasyMock.createMock(EdmStructuralType.class); EdmType edmComplexType = EasyMock.createMock(EdmType.class); JPAEdmMappingImpl mapping1 = EasyMock.createMock(JPAEdmMappingImpl.class); JPAEdmMappingImpl mapping2 = EasyMock.createMock(JPAEdmMappingImpl.class); JPAEdmMappingImpl complexMapping = EasyMock.createMock(JPAEdmMappingImpl.class); try { EasyMock.expect(edmType1.getKind()).andStubReturn(EdmTypeKind.SIMPLE); EasyMock.replay(edmType1); EasyMock.expect(mapping1.getInternalName()).andStubReturn("id"); EasyMock.expect(((JPAEdmMappingImpl) mapping1).isVirtualAccess()).andStubReturn(false); 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(edmComplexType.getKind()).andStubReturn(EdmTypeKind.SIMPLE); EasyMock.replay(edmComplexType); EasyMock.expect(complexMapping.getInternalName()).andStubReturn("order"); EasyMock.expect(((JPAEdmMappingImpl) complexMapping).isVirtualAccess()).andStubReturn(false); EasyMock.replay(complexMapping); EasyMock.expect(edmComplexProperty.getName()).andStubReturn("OrderName"); EasyMock.expect(edmComplexProperty.getMapping()).andStubReturn(complexMapping); EasyMock.expect(edmComplexProperty.getType()).andStubReturn(edmComplexType); EasyMock.replay(edmComplexProperty); EasyMock.expect(edmType2.getKind()).andStubReturn(EdmTypeKind.COMPLEX); EasyMock.expect(edmType2.getProperty("OrderName")).andStubReturn(edmComplexProperty); List<String> propertyNames = new ArrayList<String>(); propertyNames.add("OrderName"); EasyMock.expect(edmType2.getPropertyNames()).andStubReturn(propertyNames); EasyMock.replay(edmType2); EasyMock.expect(mapping2.getInternalName()).andStubReturn("relatedEntity"); EasyMock.expect(((JPAEdmMappingImpl) mapping2).isVirtualAccess()).andStubReturn(false); 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(1, ((HashMap<String, Object>) result.get("Order")).size()); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
public final HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity, final List<EdmProperty> selectPropertyList) throws ODataJPARuntimeException { HashMap<String, Object> edmEntity = new HashMap<String, Object>(); HashMap<String, Method> accessModifierMap = null; Object propertyValue = null; String jpaEntityAccessKey = null; jpaEntityAccessKey = jpaEntity.getClass().getName(); if (!jpaEntityAccessMap.containsKey(jpaEntityAccessKey)) { accessModifierMap = getAccessModifiers((List<EdmProperty>) selectPropertyList, jpaEntity.getClass(), ACCESS_MODIFIER_GET); } else { accessModifierMap = jpaEntityAccessMap.get(jpaEntityAccessKey); } for (EdmProperty property : selectPropertyList) { propertyValue = jpaEntity; try { String propertyName = property.getName(); Method method = accessModifierMap.get(propertyName); if (method == null) { String methodName = jpaEmbeddableKeyMap.get(jpaEntityAccessKey).get(propertyName); if (methodName != null) { boolean isVirtualAccess = false; if (property.getMapping() != null && property.getMapping() instanceof JPAEdmMappingImpl) { isVirtualAccess = ((JPAEdmMappingImpl) property.getMapping()).isVirtualAccess(); } if (isVirtualAccess) { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue, true); } else { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue); } } } else { propertyValue = getPropertyValue(accessModifierMap.get(propertyName), propertyValue, propertyName); } 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 (IllegalArgumentException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } } return edmEntity; }
JPAEntityParser { public final HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity, final List<EdmProperty> selectPropertyList) throws ODataJPARuntimeException { HashMap<String, Object> edmEntity = new HashMap<String, Object>(); HashMap<String, Method> accessModifierMap = null; Object propertyValue = null; String jpaEntityAccessKey = null; jpaEntityAccessKey = jpaEntity.getClass().getName(); if (!jpaEntityAccessMap.containsKey(jpaEntityAccessKey)) { accessModifierMap = getAccessModifiers((List<EdmProperty>) selectPropertyList, jpaEntity.getClass(), ACCESS_MODIFIER_GET); } else { accessModifierMap = jpaEntityAccessMap.get(jpaEntityAccessKey); } for (EdmProperty property : selectPropertyList) { propertyValue = jpaEntity; try { String propertyName = property.getName(); Method method = accessModifierMap.get(propertyName); if (method == null) { String methodName = jpaEmbeddableKeyMap.get(jpaEntityAccessKey).get(propertyName); if (methodName != null) { boolean isVirtualAccess = false; if (property.getMapping() != null && property.getMapping() instanceof JPAEdmMappingImpl) { isVirtualAccess = ((JPAEdmMappingImpl) property.getMapping()).isVirtualAccess(); } if (isVirtualAccess) { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue, true); } else { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue); } } } else { propertyValue = getPropertyValue(accessModifierMap.get(propertyName), propertyValue, propertyName); } 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 (IllegalArgumentException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } } return edmEntity; } }
JPAEntityParser { public final HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity, final List<EdmProperty> selectPropertyList) throws ODataJPARuntimeException { HashMap<String, Object> edmEntity = new HashMap<String, Object>(); HashMap<String, Method> accessModifierMap = null; Object propertyValue = null; String jpaEntityAccessKey = null; jpaEntityAccessKey = jpaEntity.getClass().getName(); if (!jpaEntityAccessMap.containsKey(jpaEntityAccessKey)) { accessModifierMap = getAccessModifiers((List<EdmProperty>) selectPropertyList, jpaEntity.getClass(), ACCESS_MODIFIER_GET); } else { accessModifierMap = jpaEntityAccessMap.get(jpaEntityAccessKey); } for (EdmProperty property : selectPropertyList) { propertyValue = jpaEntity; try { String propertyName = property.getName(); Method method = accessModifierMap.get(propertyName); if (method == null) { String methodName = jpaEmbeddableKeyMap.get(jpaEntityAccessKey).get(propertyName); if (methodName != null) { boolean isVirtualAccess = false; if (property.getMapping() != null && property.getMapping() instanceof JPAEdmMappingImpl) { isVirtualAccess = ((JPAEdmMappingImpl) property.getMapping()).isVirtualAccess(); } if (isVirtualAccess) { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue, true); } else { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue); } } } else { propertyValue = getPropertyValue(accessModifierMap.get(propertyName), propertyValue, propertyName); } 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 (IllegalArgumentException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } } return edmEntity; } JPAEntityParser(); }
JPAEntityParser { public final HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity, final List<EdmProperty> selectPropertyList) throws ODataJPARuntimeException { HashMap<String, Object> edmEntity = new HashMap<String, Object>(); HashMap<String, Method> accessModifierMap = null; Object propertyValue = null; String jpaEntityAccessKey = null; jpaEntityAccessKey = jpaEntity.getClass().getName(); if (!jpaEntityAccessMap.containsKey(jpaEntityAccessKey)) { accessModifierMap = getAccessModifiers((List<EdmProperty>) selectPropertyList, jpaEntity.getClass(), ACCESS_MODIFIER_GET); } else { accessModifierMap = jpaEntityAccessMap.get(jpaEntityAccessKey); } for (EdmProperty property : selectPropertyList) { propertyValue = jpaEntity; try { String propertyName = property.getName(); Method method = accessModifierMap.get(propertyName); if (method == null) { String methodName = jpaEmbeddableKeyMap.get(jpaEntityAccessKey).get(propertyName); if (methodName != null) { boolean isVirtualAccess = false; if (property.getMapping() != null && property.getMapping() instanceof JPAEdmMappingImpl) { isVirtualAccess = ((JPAEdmMappingImpl) property.getMapping()).isVirtualAccess(); } if (isVirtualAccess) { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue, true); } else { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue); } } } else { propertyValue = getPropertyValue(accessModifierMap.get(propertyName), propertyValue, propertyName); } 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 (IllegalArgumentException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } } return edmEntity; } JPAEntityParser(); HashMap<String, Method> getJPAEntityAccessMap(final String jpaEntityName); HashMap<String, String> getJPAEmbeddableKeyMap(final String jpaEntityName); List<Map<String, Object>> parse2EdmEntityList(final Collection<Object> jpaEntityList,
      final List<EdmProperty> properties); final HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity,
      final List<EdmProperty> selectPropertyList); final List<Map<String, Object>> parse2EdmEntityList(final Collection<Object> jpaEntityList,
      final EdmStructuralType structuralType); final HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity,
      final EdmStructuralType structuralType); final HashMap<String, Object> parse2EdmNavigationValueMap(
      final Object jpaEntity, final List<EdmNavigationProperty> navigationPropertyList); Method getAccessModifierSet(final Object jpaEntity, final String methodName); HashMap<String, Method> getAccessModifiers(final Object jpaEntity,
      final EdmStructuralType structuralType, final String accessModifier); static Object getPropertyValue(final Method method, final Object entity, String propertyName); static String getString(final Clob clob); static byte[] getBytes(final Blob blob); Object getEmbeddablePropertyValue(final String methodName, final Object jpaEntity, boolean isVirtualAccess); Object getEmbeddablePropertyValue(final String methodName, final Object jpaEntity); static String toString(final Character[] input); static Character[] toCharacterArray(final String input); static String getAccessModifierName(final String propertyName, final EdmMapping mapping,
      final String accessModifier); Method getAccessModifier(final Class<?> jpaEntityType, final EdmNavigationProperty navigationProperty,
      final String accessModifier); }
JPAEntityParser { public final HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity, final List<EdmProperty> selectPropertyList) throws ODataJPARuntimeException { HashMap<String, Object> edmEntity = new HashMap<String, Object>(); HashMap<String, Method> accessModifierMap = null; Object propertyValue = null; String jpaEntityAccessKey = null; jpaEntityAccessKey = jpaEntity.getClass().getName(); if (!jpaEntityAccessMap.containsKey(jpaEntityAccessKey)) { accessModifierMap = getAccessModifiers((List<EdmProperty>) selectPropertyList, jpaEntity.getClass(), ACCESS_MODIFIER_GET); } else { accessModifierMap = jpaEntityAccessMap.get(jpaEntityAccessKey); } for (EdmProperty property : selectPropertyList) { propertyValue = jpaEntity; try { String propertyName = property.getName(); Method method = accessModifierMap.get(propertyName); if (method == null) { String methodName = jpaEmbeddableKeyMap.get(jpaEntityAccessKey).get(propertyName); if (methodName != null) { boolean isVirtualAccess = false; if (property.getMapping() != null && property.getMapping() instanceof JPAEdmMappingImpl) { isVirtualAccess = ((JPAEdmMappingImpl) property.getMapping()).isVirtualAccess(); } if (isVirtualAccess) { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue, true); } else { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue); } } } else { propertyValue = getPropertyValue(accessModifierMap.get(propertyName), propertyValue, propertyName); } 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 (IllegalArgumentException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } } return edmEntity; } JPAEntityParser(); HashMap<String, Method> getJPAEntityAccessMap(final String jpaEntityName); HashMap<String, String> getJPAEmbeddableKeyMap(final String jpaEntityName); List<Map<String, Object>> parse2EdmEntityList(final Collection<Object> jpaEntityList,
      final List<EdmProperty> properties); final HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity,
      final List<EdmProperty> selectPropertyList); final List<Map<String, Object>> parse2EdmEntityList(final Collection<Object> jpaEntityList,
      final EdmStructuralType structuralType); final HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity,
      final EdmStructuralType structuralType); final HashMap<String, Object> parse2EdmNavigationValueMap(
      final Object jpaEntity, final List<EdmNavigationProperty> navigationPropertyList); Method getAccessModifierSet(final Object jpaEntity, final String methodName); HashMap<String, Method> getAccessModifiers(final Object jpaEntity,
      final EdmStructuralType structuralType, final String accessModifier); static Object getPropertyValue(final Method method, final Object entity, String propertyName); static String getString(final Clob clob); static byte[] getBytes(final Blob blob); Object getEmbeddablePropertyValue(final String methodName, final Object jpaEntity, boolean isVirtualAccess); Object getEmbeddablePropertyValue(final String methodName, final Object jpaEntity); static String toString(final Character[] input); static Character[] toCharacterArray(final String input); static String getAccessModifierName(final String propertyName, final EdmMapping mapping,
      final String accessModifier); Method getAccessModifier(final Class<?> jpaEntityType, final EdmNavigationProperty navigationProperty,
      final String accessModifier); static final String ACCESS_MODIFIER_GET; static final String ACCESS_MODIFIER_SET; }