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:12 UTC
[19/52] 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/0169bfc3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/0169bfc3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/0169bfc3
Branch: refs/heads/master
Commit: 0169bfc386e03306cc92070cb9ec6b6f1a30703a
Parents: 454e178
Author: Michael Bolz <mi...@apache.org>
Authored: Tue Nov 12 16:07:42 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Tue Nov 12 16:07:42 2013 +0100
----------------------------------------------------------------------
.../core/annotation/ds/AnnotationInMemoryDs.java | 13 ++++++++-----
.../olingo/odata2/ref/annotation/model/Photo.java | 4 +---
.../odata2/ref/annotation/model/ResourceHelper.java | 13 ++++++++++---
.../processor/AnnotationPocServiceFactory.java | 16 ++++++++++------
4 files changed, 29 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/0169bfc3/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/0169bfc3/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/0169bfc3/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 bba1c6b..3d2bb88 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
@@ -28,7 +28,7 @@ import javax.imageio.ImageIO;
/**
*
*/
-class ResourceHelper {
+public class ResourceHelper {
public static byte[] loadAsByte(String resource) {
return load(resource, new byte[0]);
@@ -59,16 +59,23 @@ 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)) % 2 == 0) {
+ if (((h / 32) + (w / 32)) % mod == 0) {
raster.setSample(w, h, 0, 0);
} else {
raster.setSample(w, h, 0, 1);
@@ -77,7 +84,7 @@ class ResourceHelper {
}
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
- ImageIO.write(image, "PNG", out);
+ 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/0169bfc3/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;
}