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

[23/52] Added support for multiple 'EdmKey' annotations

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
index d43f8c9..cca0b5e 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
@@ -78,14 +78,57 @@ public class AnnotationHelper {
     }
   }
 
+  /**
+   * Get the set property name from an EdmProperty or EdmNavigationProperty annotation.
+   * 
+   * @param field
+   * @return 
+   */
+  public String getPropertyNameFromAnnotation(Field field) {
+    EdmProperty property = field.getAnnotation(EdmProperty.class);
+    if(property == null) {
+      EdmNavigationProperty navProperty = field.getAnnotation(EdmNavigationProperty.class);
+      if(navProperty == null) {
+        throw new EdmAnnotationException("Given field '" + field
+                + "' has no EdmProperty or EdmNavigationProperty annotation.");
+      }
+      return navProperty.name();
+    }
+    return property.name();
+  }
+
+  public String getPropertyName(Field field) {
+      String propertyName = getPropertyNameFromAnnotation(field);
+      if (propertyName.isEmpty()) {
+        propertyName = getCanonicalName(field);
+      }
+      return propertyName;
+  }
+
   public static final class ODataAnnotationException extends ODataException {
 
     public ODataAnnotationException(String message) {
       super(message);
     }
   }
-  
-  public <T> T setKeyFields(T instance, Object[] keyValues) {
+
+  public <T> T setKeyFields(T instance, Map<String, Object> keys) {
+    List<Field> fields = getAnnotatedFields(instance, EdmKey.class);
+    if (fields.size() != keys.size()) {
+      throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
+              + fields + " given key predicates = " + keys);
+    }
+    
+    for (Field field : fields) {
+      String propertyName = getPropertyName(field);
+      Object keyValue = keys.get(propertyName);
+      setValueForProperty(instance, propertyName, keyValue);
+    }
+
+    return instance;
+  }
+
+  public <T> T setKeyFields__(T instance, Object[] keyValues) {
     List<Field> fields = getAnnotatedFields(instance, EdmKey.class);
     if (fields.size() != keyValues.length) {
       throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
@@ -370,7 +413,8 @@ public class AnnotationHelper {
       return type.getEdmSimpleTypeInstance().valueOfString(propertyValue,
               EdmLiteralKind.DEFAULT, null, fieldClass);
     } catch (EdmSimpleTypeException ex) {
-      throw new ODataRuntimeException(ex);
+      throw new ODataRuntimeException("Conversion failed for string property with error: " 
+              + ex.getMessage(), ex);
     }
   }
 
@@ -406,4 +450,11 @@ public class AnnotationHelper {
     }
     return content.substring(0, 1).toUpperCase(Locale.ENGLISH) + content.substring(1);
   }
+
+  
+  private static class EdmAnnotationException extends RuntimeException {
+    public EdmAnnotationException(String message) {
+      super(message);
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
index 23fc743..b1b8730 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
@@ -44,7 +44,7 @@ import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
 import org.apache.olingo.odata2.api.uri.info.GetMediaResourceUriInfo;
 import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
 import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
-import org.apache.olingo.odata2.core.annotation.ds.DataSourceHolder;
+import org.apache.olingo.odata2.core.annotation.data.DataSourceHolder;
 import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
 import org.apache.olingo.odata2.core.annotation.edm.ClassHelper;
 import org.apache.olingo.odata2.core.annotation.processor.json.EdmAnnotationSerializer;

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
new file mode 100644
index 0000000..0aaf309
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.olingo.odata2.core.annotation.data;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.exception.ODataApplicationException;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationEdmProvider;
+import org.apache.olingo.odata2.core.annotation.model.Building;
+import org.apache.olingo.odata2.core.annotation.model.ModelSharedConstants;
+import org.apache.olingo.odata2.core.annotation.model.Photo;
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ *
+ */
+public class AnnotationsInMemoryDsTest {
+  
+  private final AnnotationInMemoryDs datasource;
+  private AnnotationEdmProvider edmProvider;
+  private static final String DEFAULT_CONTAINER = ModelSharedConstants.CONTAINER_1;
+  private static final String DEFAULT_NAMESPACE = ModelSharedConstants.NAMESPACE_1;
+
+  public AnnotationsInMemoryDsTest() {
+    datasource = new AnnotationInMemoryDs(Building.class.getPackage().getName());
+    edmProvider = new AnnotationEdmProvider(Building.class.getPackage().getName());
+  }
+
+
+  @Test(expected = ODataApplicationException.class)
+  public void invalidEntity() throws Exception {
+    EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Building");
+    
+    datasource.createData(edmEntitySet, this);
+  }
+
+  @Test
+  public void createSimpleEntity() throws Exception {
+    EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Building");
+    
+    Building building = new Building();
+    building.setName("Common Building");
+    datasource.createData(edmEntitySet, building);
+    
+    Map<String, Object> keys = new HashMap<String, Object>();
+    keys.put("Id", "1");
+    
+    Building read = (Building) datasource.readData(edmEntitySet, keys);
+    Assert.assertEquals("Common Building", read.getName());
+  }
+
+  @Test
+  public void createEntityTwoKeys() throws Exception {
+    EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photo");
+    
+    Photo photo = new Photo();
+    photo.setName("BigPicture");
+    photo.setType("PNG");
+    photo.setImageUri("https://localhost/image.png");
+    photo.setImageType("image/png");
+    datasource.createData(edmEntitySet, photo);
+    
+    Map<String, Object> keys = new HashMap<String, Object>();
+//    keys.put("ImageFormat", "PNG");
+//    keys.put("Name", "BigPicture");
+    keys.put("Name", "1");
+    keys.put("ImageFormat", "2");
+    
+    Photo read = (Photo) datasource.readData(edmEntitySet, keys);
+//    Assert.assertEquals("BigPicture", read.getName());
+    Assert.assertEquals("1", read.getName());
+    Assert.assertEquals("2", read.getType());
+    Assert.assertEquals("image/png", read.getImageType());
+    Assert.assertEquals("https://localhost/image.png", read.getImageUri());
+  }
+
+  @Test
+//  @Ignore("Rethink update method")
+  public void createAndUpdateEntityTwoKeys() throws Exception {
+    EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photo");
+    
+    Photo photo = new Photo();
+    final String nameKeyValue = "BigPicture";
+    final String typeKeyValue = "PNG";
+    photo.setName(nameKeyValue);
+    photo.setType(typeKeyValue);
+    photo.setImageUri("https://localhost/image.png");
+    photo.setImageType("image/png");
+    datasource.createData(edmEntitySet, photo);
+    
+    Map<String, Object> keys = new HashMap<String, Object>();
+    keys.put("Name", "1");
+    keys.put("ImageFormat", "2");
+    
+    Photo read = (Photo) datasource.readData(edmEntitySet, keys);
+    Assert.assertEquals("1", read.getName());
+    Assert.assertEquals("2", read.getType());
+    Assert.assertEquals("image/png", read.getImageType());
+    Assert.assertEquals("https://localhost/image.png", read.getImageUri());
+    
+
+    // update
+    Photo updatedPhoto = new Photo();
+//    updatedPhoto.setName(nameKeyValue);
+//    updatedPhoto.setType(typeKeyValue);
+    updatedPhoto.setName("1");
+    updatedPhoto.setType("2");
+    updatedPhoto.setImageUri("https://localhost/image.jpg");
+    updatedPhoto.setImageType("image/jpg");
+    datasource.updateData(edmEntitySet, updatedPhoto);
+    
+    Map<String, Object> updatedKeys = new HashMap<String, Object>();
+//    updatedKeys.put("Name", nameKeyValue);
+//    updatedKeys.put("ImageFormat", typeKeyValue);
+    updatedKeys.put("Name", "1");
+    updatedKeys.put("ImageFormat", "2");
+    
+    Photo readUpdated = (Photo) datasource.readData(edmEntitySet, updatedKeys);
+    Assert.assertEquals("1", readUpdated.getName());
+    Assert.assertEquals("2", readUpdated.getType());
+    Assert.assertEquals("image/jpg", readUpdated.getImageType());
+    Assert.assertEquals("https://localhost/image.jpg", readUpdated.getImageUri());
+  }
+
+  private EdmEntitySet createMockedEdmEntitySet(String entitySetName) throws ODataException {
+//    EntitySet entitySet = edmProvider.getEntitySet(DEFAULT_CONTAINER, entitySetName);
+    EntityType entityType = edmProvider.getEntityType(new FullQualifiedName(DEFAULT_NAMESPACE, entitySetName));
+    
+    EdmEntitySet edmEntitySet = Mockito.mock(EdmEntitySet.class);
+    EdmEntityType edmEntityType = Mockito.mock(EdmEntityType.class);
+    Mockito.when(edmEntitySet.getEntityType()).thenReturn(edmEntityType);
+    Mockito.when(edmEntityType.getName()).thenReturn(entityType.getName());
+    
+    return edmEntitySet;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
index 4a875a2..4d1a6b7 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
@@ -36,6 +36,7 @@ import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
 import org.apache.olingo.odata2.api.edm.provider.EntitySet;
 import org.apache.olingo.odata2.api.edm.provider.EntityType;
 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.NavigationProperty;
 import org.apache.olingo.odata2.api.edm.provider.Property;
 import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
@@ -50,11 +51,11 @@ import org.apache.olingo.odata2.core.annotation.model.Photo;
 import org.apache.olingo.odata2.core.annotation.model.RefBase;
 import org.apache.olingo.odata2.core.annotation.model.Room;
 import org.apache.olingo.odata2.core.annotation.model.Team;
+import static org.junit.Assert.assertFalse;
 import org.junit.Test;
 
 /**
  *
- * @author d046871
  */
 public class AnnotationEdmProviderTest {
 
@@ -148,7 +149,7 @@ public class AnnotationEdmProviderTest {
     EntityContainer container = containers.get(0);
     assertEquals(ModelSharedConstants.CONTAINER_1, container.getName());
     final List<EntitySet> entitySets = container.getEntitySets();
-    assertEquals(5, entitySets.size());
+    assertEquals(6, entitySets.size());
     
     List<Association> associations = schema.getAssociations();
     assertEquals(4, associations.size());
@@ -257,6 +258,33 @@ public class AnnotationEdmProviderTest {
   }
 
   @Test
+  public void entityTypePhotoWithTwoKeyProperties() throws Exception {
+    // validate team
+    EntityType photo = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Photo"));
+    assertEquals("Photo", photo.getName());
+    final List<Property> properties = photo.getProperties();
+    assertEquals(5, properties.size());
+    assertTrue(containsProperty(properties, "Name"));
+    assertTrue(containsProperty(properties, "ImageFormat"));
+    assertTrue(containsProperty(properties, "MimeType"));
+    assertTrue(containsProperty(properties, "ImageUrl"));
+    assertTrue(containsProperty(properties, "Image"));
+    assertFalse(photo.isAbstract());
+    assertTrue(photo.isHasStream());
+
+    Key photoKey = photo.getKey();
+    List<PropertyRef> keyReferences = photoKey.getKeys();
+    assertEquals(2, keyReferences.size());
+    PropertyRef name = getPropertyRef(keyReferences, "Name");
+    assertEquals("Name", name.getName());
+    PropertyRef imageFormat = getPropertyRef(keyReferences, "ImageFormat");
+    assertEquals("ImageFormat", imageFormat.getName());
+    
+//    assertEquals(0, photo.getNavigationProperties().size());
+    assertNull(photo.getNavigationProperties());
+  }
+
+  @Test
   public void entityTypeAbstractBaseType() throws Exception {
     // validate employee
     EntityType baseType = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Base"));
@@ -331,4 +359,26 @@ public class AnnotationEdmProviderTest {
           String relationship, String fromRole, String toRole) {
     validateNavProperty(navigationProperty, null, relationship, fromRole, toRole);
   }
+  
+  private boolean containsProperty(List<Property> properties, String propertyName) {
+    return getProperty(properties, propertyName) != null;
+  }
+
+  private Property getProperty(List<Property> properties, String name) {
+    for (Property property : properties) {
+      if(name.equals(property.getName())) {
+        return property;
+      }
+    }
+    return null;
+  }
+  
+  private PropertyRef getPropertyRef(List<PropertyRef> properties, String name) {
+    for (PropertyRef property : properties) {
+      if(name.equals(property.getName())) {
+        return property;
+      }
+    }
+    return null;
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
index 2abf4e3..f1a3fa9 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
@@ -39,7 +39,7 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
 public class Building {
   @EdmKey
   @EdmProperty(type = EdmSimpleTypeKind.String)
-  private int id;
+  private String id;
   @EdmProperty
   private String name;
   private byte[] image;
@@ -47,16 +47,8 @@ public class Building {
           to = @NavigationEnd(role = "r_Room", entitySet=Room.class, multiplicity = EdmMultiplicity.MANY))
   private List<Room> rooms = new ArrayList<Room>();
 
-  public Building() {
-  }
-
-  public Building(final int id, final String name) {
-    this.id = id;
-    setName(name);
-  }
-
   public String getId() {
-    return Integer.toString(id);
+    return id;
   }
 
   public void setName(final String name) {
@@ -85,7 +77,10 @@ public class Building {
 
   @Override
   public int hashCode() {
-    return id;
+    if(id == null) {
+      return 0;
+    }
+    return id.hashCode();
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
index 6c89654..52cb2cc 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
@@ -19,31 +19,38 @@
 package org.apache.olingo.odata2.core.annotation.model;
 
 import java.util.Arrays;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+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.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.core.annotation.model.ModelSharedConstants;
+import org.apache.olingo.odata2.core.annotation.model.ResourceHelper;
 
 /**
  *  
  */
+@EdmEntityType(name = "Photo", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Photos")
 public class Photo {
-  private static final String RESOURCE = "/male_1_WinterW.jpg";
-
-  private final int id;
+  @EdmProperty
+  @EdmKey
   private String name;
-  private String type = "image/jpeg";
-  private String imageUrl = "http://localhost" + RESOURCE;
-  private byte[] image = new byte[0];
-  private String imageType = type;
-  private byte[] binaryData;
-  private String content;
-
-  public Photo(final int id, final String name, final String type) {
-    this.id = id;
-    setName(name);
-    setType(type);
-  }
-
-  public int getId() {
-    return id;
-  }
+  @EdmProperty(name = "ImageFormat")
+  @EdmKey
+  private String type;
+  @EdmProperty
+  @EdmMediaResourceMimeType
+  private String mimeType;
+  @EdmProperty
+  @EdmMediaResourceSource
+  private String imageUrl = "http://localhost/someResource.png";
+  @EdmProperty(type = EdmSimpleTypeKind.Binary)
+  @EdmMediaResourceContent
+  private byte[] image = ResourceHelper.generateImage();
 
   public String getName() {
     return name;
@@ -78,53 +85,45 @@ public class Photo {
   }
 
   public String getImageType() {
-    return imageType;
+    return mimeType;
   }
 
   public void setImageType(final String imageType) {
-    this.imageType = imageType;
-  }
-
-  public byte[] getBinaryData() {
-    if (binaryData == null) {
-      return null;
-    } else {
-      return binaryData.clone();
-    }
-  }
-
-  public void setBinaryData(final byte[] binaryData) {
-    this.binaryData = binaryData;
-  }
-
-  public void setContent(final String content) {
-    this.content = content;
-  }
-
-  public String getContent() {
-    return content;
+    this.mimeType = imageType;
   }
 
   @Override
   public int hashCode() {
-    return id;
+    int hash = 5;
+    hash = 83 * hash + (this.name != null ? this.name.hashCode() : 0);
+    hash = 83 * hash + (this.type != null ? this.type.hashCode() : 0);
+    return hash;
   }
 
   @Override
-  public boolean equals(final Object obj) {
-    return this == obj
-        || obj != null && getClass() == obj.getClass() && id == ((Photo) obj).id;
+  public boolean equals(Object obj) {
+    if (obj == null) {
+      return false;
+    }
+    if (getClass() != obj.getClass()) {
+      return false;
+    }
+    final Photo other = (Photo) obj;
+    if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
+      return false;
+    }
+    if ((this.type == null) ? (other.type != null) : !this.type.equals(other.type)) {
+      return false;
+    }
+    return true;
   }
-
+  
   @Override
   public String toString() {
-    return "{\"Id\":" + id + ","
-        + "\"Name\":\"" + name + "\","
+    return "{\"Name\":\"" + name + "\","
         + "\"Type\":\"" + type + "\","
         + "\"ImageUrl\":\"" + imageUrl + "\","
         + "\"Image\":\"" + Arrays.toString(image) + "\","
-        + "\"ImageType\":\"" + imageType + "\","
-        + "\"Content:\"" + content + "\","
-        + "\"BinaryData\":\"" + Arrays.toString(binaryData) + "\"}";
+        + "\"MimeType\":\"" + mimeType + "\"";
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java
new file mode 100644
index 0000000..73d1218
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.core.annotation.model;
+
+import java.awt.image.BufferedImage;
+import java.awt.image.WritableRaster;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import javax.imageio.ImageIO;
+
+/**
+ *
+ */
+public class ResourceHelper {
+
+  public enum Format {BMP, JPEG, PNG, GIF};
+  
+  public static byte[] generateImage() {
+    return generateImage(Format.PNG);
+  }
+  
+  public static byte[] generateImage(Format format) {
+    try {
+      int width = 320;
+      int height = 320;
+      BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
+      WritableRaster raster = image.getRaster();
+      
+      int mod = format.ordinal() + 2;
+      for (int h = 0; h < height; h++) {
+        for (int w = 0; w < width; w++) {
+          if (((h / 32) + (w / 32)) % mod == 0) {
+            raster.setSample(w, h, 0, 0);
+          } else {
+            raster.setSample(w, h, 0, 1);
+          }
+        }
+      }
+      
+      ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
+      ImageIO.write(image, format.name(), out);
+      return out.toByteArray();
+    } catch (IOException ex) {
+      return new byte[0];
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
index 3623b2b..eafee7b 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
@@ -34,9 +34,10 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
 @EdmEntityType(name = "Photo", namespace = ModelSharedConstants.NAMESPACE_1)
 @EdmEntitySet(name = "Photos")
 public class Photo {
-  @EdmProperty
   @EdmKey
+  @EdmProperty
   private String name;
+  @EdmKey
   @EdmProperty
   private String type;
   @EdmProperty

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
index 9dcac65..5210466 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
@@ -14,8 +14,8 @@
  */
 package org.apache.olingo.odata2.ref.annotation.processor;
 
-import org.apache.olingo.odata2.core.annotation.ds.AnnotationValueAccess;
-import org.apache.olingo.odata2.core.annotation.ds.AnnotationInMemoryDs;
+import org.apache.olingo.odata2.core.annotation.data.AnnotationValueAccess;
+import org.apache.olingo.odata2.core.annotation.data.AnnotationInMemoryDs;
 import org.apache.olingo.odata2.api.ODataCallback;
 import org.apache.olingo.odata2.api.ODataDebugCallback;
 import org.apache.olingo.odata2.api.ODataService;
@@ -28,13 +28,12 @@ import org.apache.olingo.odata2.api.processor.ODataContext;
 import org.apache.olingo.odata2.api.processor.ODataErrorCallback;
 import org.apache.olingo.odata2.api.processor.ODataErrorContext;
 import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.core.annotation.ds.DataStore;
+import org.apache.olingo.odata2.core.annotation.data.DataStore;
 import org.apache.olingo.odata2.core.annotation.edm.AnnotationEdmProvider;
 import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
 import org.apache.olingo.odata2.ref.annotation.model.Building;
 import org.apache.olingo.odata2.ref.annotation.model.Photo;
 import org.apache.olingo.odata2.ref.annotation.model.ResourceHelper;
-import org.apache.olingo.odata2.ref.annotation.model.ResourceHelper;
 import org.apache.olingo.odata2.ref.annotation.model.Room;
 import org.apache.olingo.odata2.ref.annotation.model.Team;
 import org.slf4j.Logger;
@@ -73,8 +72,6 @@ public class AnnotationPocServiceFactory extends ODataServiceFactory {
             ? new ScenarioDebugCallback() : super.getCallback(callbackInterface));
   }
 
-  
-  
   /*
   * Helper classes and methods
   */
@@ -105,7 +102,7 @@ public class AnnotationPocServiceFactory extends ODataServiceFactory {
 
   }
 
-  private void initializeSampleData(AnnotationInMemoryDs dataSource) {
+  private void initializeSampleData(AnnotationInMemoryDs dataSource) throws ODataApplicationException {
     DataStore<Team> teamDs = dataSource.getDataStore(Team.class);
     teamDs.create(createTeam("Team Alpha", true));
     teamDs.create(createTeam("Team Beta", false));

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp b/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
index 3ffc551..dffa84d 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
@@ -77,11 +77,11 @@ th, td { border: 1px solid; padding: 20px; }
 						target="_blank">Employees('1')</a></li>
 					<li><a href="ReferenceScenario.svc/Managers('1')"
 						target="_blank">Managers('1')</a></li>
-					<li><a href="ReferenceScenario.svc/Buildings('1')"
-						target="_blank">Buildings('1')</a></li>
+					<li><a href="ReferenceScenario.svc/Buildings(1)"
+						target="_blank">Buildings(1)</a></li>
 					<li><a href="ReferenceScenario.svc/Rooms('1')" target="_blank">Rooms('1')</a></li>
- 					<li><a href="ReferenceScenario.svc/Container2.Photos(Id=4,Type='foo')"
-                           target="_blank">Container2.Photos(Id=4,Type='foo')</a></li>
+ 					<li><a href="ReferenceScenario.svc/Photos(Name='1',Type='2')"
+                           target="_blank">Container2.Photos(Name='1',Type='2')</a></li>
 				</ul>
 			</td>
 			<td valign="top">

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/AbstractRefTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/AbstractRefTest.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/AbstractRefTest.java
index e9e2153..de5f99e 100644
--- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/AbstractRefTest.java
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/AbstractRefTest.java
@@ -39,7 +39,7 @@ import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
 import org.apache.olingo.odata2.api.commons.ODataHttpMethod;
 import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
 import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
-import org.apache.olingo.odata2.core.annotation.ds.BeanPropertyAccess;
+import org.apache.olingo.odata2.core.annotation.data.BeanPropertyAccess;
 import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
 import org.apache.olingo.odata2.core.processor.ODataSingleProcessorService;
 import org.apache.olingo.odata2.ref.edm.ScenarioEdmProvider;

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/contentnegotiation/AbstractContentNegotiationTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/contentnegotiation/AbstractContentNegotiationTest.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/contentnegotiation/AbstractContentNegotiationTest.java
index 265fc28..688532d 100644
--- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/contentnegotiation/AbstractContentNegotiationTest.java
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/contentnegotiation/AbstractContentNegotiationTest.java
@@ -49,7 +49,7 @@ import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
 import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
 import org.apache.olingo.odata2.api.exception.ODataException;
 import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
-import org.apache.olingo.odata2.core.annotation.ds.BeanPropertyAccess;
+import org.apache.olingo.odata2.core.annotation.data.BeanPropertyAccess;
 import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
 import org.apache.olingo.odata2.core.commons.ContentType;
 import org.apache.olingo.odata2.core.processor.ODataSingleProcessorService;

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioServiceFactory.java b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioServiceFactory.java
index 49cd8b2..08d6e16 100644
--- a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioServiceFactory.java
+++ b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioServiceFactory.java
@@ -24,7 +24,7 @@ import org.apache.olingo.odata2.api.ODataService;
 import org.apache.olingo.odata2.api.ODataServiceFactory;
 import org.apache.olingo.odata2.api.exception.ODataException;
 import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.core.annotation.ds.BeanPropertyAccess;
+import org.apache.olingo.odata2.core.annotation.data.BeanPropertyAccess;
 import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
 import org.apache.olingo.odata2.ref.edm.ScenarioEdmProvider;
 import org.apache.olingo.odata2.ref.model.DataContainer;

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntitySetTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntitySetTest.java b/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntitySetTest.java
index 53fd6ef..d07473d 100644
--- a/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntitySetTest.java
+++ b/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntitySetTest.java
@@ -38,7 +38,7 @@ import org.apache.olingo.odata2.api.processor.ODataContext;
 import org.apache.olingo.odata2.api.processor.ODataResponse;
 import org.apache.olingo.odata2.api.uri.PathInfo;
 import org.apache.olingo.odata2.api.uri.UriInfo;
-import org.apache.olingo.odata2.core.annotation.ds.BeanPropertyAccess;
+import org.apache.olingo.odata2.core.annotation.data.BeanPropertyAccess;
 import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
 import org.apache.olingo.odata2.core.commons.ContentType;
 import org.apache.olingo.odata2.ref.model.DataContainer;

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntityTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntityTest.java b/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntityTest.java
index 87593f2..be55778 100644
--- a/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntityTest.java
+++ b/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntityTest.java
@@ -43,7 +43,7 @@ import org.apache.olingo.odata2.api.processor.ODataResponse;
 import org.apache.olingo.odata2.api.uri.KeyPredicate;
 import org.apache.olingo.odata2.api.uri.PathInfo;
 import org.apache.olingo.odata2.api.uri.UriInfo;
-import org.apache.olingo.odata2.core.annotation.ds.BeanPropertyAccess;
+import org.apache.olingo.odata2.core.annotation.data.BeanPropertyAccess;
 import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
 import org.apache.olingo.odata2.core.commons.ContentType;
 import org.apache.olingo.odata2.ref.model.DataContainer;