Repository: olingo-odata2
Updated Branches:
  refs/heads/master 8b40fff59 -> 17dc8da79


[OLINGO-1024] Fix media resource annotations


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

Branch: refs/heads/master
Commit: 17dc8da793f8aaeb8c2c4391cfd1ace28742adb3
Parents: 8b40fff
Author: Stefan Boller <stefan.bol...@sap.com>
Authored: Mon Sep 19 14:54:34 2016 +0200
Committer: mibo <m...@apache.org>
Committed: Tue Sep 20 19:20:44 2016 +0200

----------------------------------------------------------------------
 .../core/edm/AnnotationEdmProvider.java         | 20 ++++++++++++++++++--
 .../core/edm/AnnotationEdmProviderTest.java     |  2 ++
 2 files changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/17dc8da7/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------
diff --git 
a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProvider.java
 
b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProvider.java
index 81546a7..9dd6bd8 100644
--- 
a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProvider.java
+++ 
b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProvider.java
@@ -41,6 +41,8 @@ import 
org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
 import org.apache.olingo.odata2.api.annotation.edm.EdmFacets;
 import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
 import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceSource;
 import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
 import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
 import org.apache.olingo.odata2.api.annotation.edm.EdmType;
@@ -63,6 +65,7 @@ import org.apache.olingo.odata2.api.edm.provider.EntityType;
 import org.apache.olingo.odata2.api.edm.provider.Facets;
 import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
 import org.apache.olingo.odata2.api.edm.provider.Key;
+import org.apache.olingo.odata2.api.edm.provider.Mapping;
 import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
 import org.apache.olingo.odata2.api.edm.provider.Property;
 import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
@@ -336,6 +339,8 @@ public class AnnotationEdmProvider extends EdmProvider {
     final private String name;
     private boolean isAbstract = false;
     private boolean isMediaResource = false;
+    private String mediaResourceMimeTypeKey;
+    private String mediaResourceSourceKey;
     private FullQualifiedName baseEntityType = null;
     private final List<PropertyRef> keyProperties = new 
ArrayList<PropertyRef>();
     private final List<Property> properties = new ArrayList<Property>();
@@ -366,11 +371,20 @@ public class AnnotationEdmProvider extends EdmProvider {
       for (Field field : fields) {
         EdmProperty ep = field.getAnnotation(EdmProperty.class);
         if (ep != null) {
-          properties.add(createProperty(ep, field));
+          Property property = createProperty(ep, field);
+          properties.add(property);
           EdmKey eti = field.getAnnotation(EdmKey.class);
           if (eti != null) {
             keyProperties.add(createKeyProperty(ep, field));
           }
+          EdmMediaResourceMimeType emrmt = 
field.getAnnotation(EdmMediaResourceMimeType.class);
+          if (emrmt !=null) {
+            mediaResourceMimeTypeKey = property.getName();
+          }
+          EdmMediaResourceSource emrs = 
field.getAnnotation(EdmMediaResourceSource.class);
+          if (emrs !=null) {
+            mediaResourceSourceKey =  property.getName();
+          }
         }
         EdmNavigationProperty enp = 
field.getAnnotation(EdmNavigationProperty.class);
         if (enp != null) {
@@ -434,7 +448,9 @@ public class AnnotationEdmProvider extends EdmProvider {
       return entityType.setName(name)
           .setAbstract(isAbstract)
           .setHasStream(isMediaResource)
-          .setProperties(properties);
+          .setProperties(properties)
+          .setMapping(new 
Mapping().setMediaResourceMimeTypeKey(mediaResourceMimeTypeKey)
+                                    
.setMediaResourceSourceKey(mediaResourceSourceKey));
     }
 
     public Collection<Association> buildAssociations() {

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/17dc8da7/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java
----------------------------------------------------------------------
diff --git 
a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java
 
b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java
index 4d2f077..778d349 100644
--- 
a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java
+++ 
b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java
@@ -401,6 +401,8 @@ public class AnnotationEdmProviderTest {
     assertTrue(containsProperty(properties, "Image"));
     assertFalse(photo.isAbstract());
     assertTrue(photo.isHasStream());
+    assertEquals("MimeType",photo.getMapping().getMediaResourceMimeTypeKey());
+    assertEquals("ImageUrl",photo.getMapping().getMediaResourceSourceKey());
 
     Key photoKey = photo.getKey();
     List<PropertyRef> keyReferences = photoKey.getKeys();

Reply via email to