You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by tb...@apache.org on 2013/12/06 17:52:49 UTC
[07/50] [abbrv] git commit: Implementation for Binary read
Implementation for Binary read
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/8aceb95e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/8aceb95e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/8aceb95e
Branch: refs/heads/ODataServlet
Commit: 8aceb95ea9b5eba809759fd8568b6f69803b62ca
Parents: 99ef03a
Author: Michael Bolz <mi...@apache.org>
Authored: Tue Nov 12 16:07:42 2013 +0100
Committer: Tamara Boehm <ta...@sap.com>
Committed: Fri Dec 6 17:49:21 2013 +0100
----------------------------------------------------------------------
.../core/annotation/ds/AnnotationInMemoryDs.java | 13 ++++++++-----
.../olingo/odata2/ref/annotation/model/Photo.java | 4 +---
.../odata2/ref/annotation/model/ResourceHelper.java | 2 +-
.../processor/AnnotationPocServiceFactory.java | 16 ++++++++++------
4 files changed, 20 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8aceb95e/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
index 999b2ab..0a467fa 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
@@ -16,16 +16,14 @@ package org.apache.olingo.odata2.core.annotation.ds;
import java.lang.reflect.Field;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
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.EdmNavigationProperty;
import org.apache.olingo.odata2.api.data.ListsDataSource;
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
@@ -157,7 +155,12 @@ public class AnnotationInMemoryDs implements ListsDataSource {
@Override
public BinaryData readBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData)
throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+
+ Object data = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceContent.class);
+ Object mimeType = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceMimeType.class);
+
+ BinaryData db = new BinaryData((byte[])data, String.valueOf(mimeType));
+ return db;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8aceb95e/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 fd266ce..432baba 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
@@ -33,8 +33,6 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
@EdmEntityType(name = "Photo", namespace = ModelSharedConstants.NAMESPACE_1,
entitySetName = "Photos", container = ModelSharedConstants.CONTAINER_1)
public class Photo {
- private static final String RESOURCE = "/male_1_WinterW.jpg";
-
@EdmProperty
@EdmKey
private String name;
@@ -45,7 +43,7 @@ public class Photo {
private String mimeType;
@EdmProperty
@EdmMediaResourceSource
- private String imageUrl = "http://localhost" + RESOURCE;
+ private String imageUrl = "http://localhost/someResource.png";
@EdmProperty(type = EdmSimpleTypeKind.Binary)
@EdmMediaResourceContent
private byte[] image = ResourceHelper.generateImage();
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8aceb95e/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
index 07ee5b4..948f6e5 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
@@ -32,7 +32,7 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
/**
*
*/
-class ResourceHelper {
+public class ResourceHelper {
public static byte[] loadAsByte(String resource) {
return load(resource, new byte[0]);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8aceb95e/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 eb1c252..9dcac65 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
@@ -33,6 +33,8 @@ 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;
@@ -122,9 +124,10 @@ public class AnnotationPocServiceFactory extends ODataServiceFactory {
buildingsDs.create(yellowBuilding);
DataStore<Photo> photoDs = dataSource.getDataStore(Photo.class);
- photoDs.create(createPhoto("Small picture"));
- photoDs.create(createPhoto("Medium picture"));
- photoDs.create(createPhoto("Big picture"));
+ photoDs.create(createPhoto("Small picture", ResourceHelper.Format.GIF));
+ photoDs.create(createPhoto("Medium picture", ResourceHelper.Format.PNG));
+ photoDs.create(createPhoto("Big picture", ResourceHelper.Format.JPEG));
+ photoDs.create(createPhoto("Huge picture", ResourceHelper.Format.BMP));
DataStore<Room> roomDs = dataSource.getDataStore(Room.class);
roomDs.create(createRoom("Tiny red room", 5, 1, redBuilding));
@@ -148,12 +151,13 @@ public class AnnotationPocServiceFactory extends ODataServiceFactory {
return b;
}
- private Photo createPhoto(String name) {
+ private Photo createPhoto(String name, ResourceHelper.Format format) {
Photo p = new Photo();
p.setName(name);
- p.setType("PNG");
- p.setImageType("image/png");
p.setImageUri("http://localhost/image/" + name);
+ p.setType(format.name());
+ p.setImageType("image/" + format.name().toLowerCase());
+ p.setImage(ResourceHelper.generateImage(format));
return p;
}