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:53:05 UTC
[23/50] [abbrv] git commit: Added support for write binary
Added support for write binary
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/93d0002a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/93d0002a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/93d0002a
Branch: refs/heads/ODataServlet
Commit: 93d0002ad79c999d55b0edbfb059acfdf6042406
Parents: acee769
Author: Michael Bolz <mi...@apache.org>
Authored: Tue Dec 3 09:46:16 2013 +0100
Committer: Tamara Boehm <ta...@sap.com>
Committed: Fri Dec 6 17:49:24 2013 +0100
----------------------------------------------------------------------
.../annotation/data/AnnotationInMemoryDs.java | 15 +++++++--
.../annotation/data/AnnotationValueAccess.java | 4 ++-
.../odata2/core/annotation/data/DataStore.java | 3 +-
.../core/annotation/edm/AnnotationHelper.java | 34 +++++++++++++++-----
4 files changed, 43 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/93d0002a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
index 938a0d2..3389140 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
@@ -34,6 +34,7 @@ import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper.AnnotatedNavInfo;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper.ODataAnnotationException;
import org.apache.olingo.odata2.core.annotation.edm.ClassHelper;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
@@ -173,14 +174,22 @@ public class AnnotationInMemoryDs implements ListsDataSource {
return dataStore.createInstance();
}
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ throw new ODataRuntimeException("No DataStore found for entitySet with name: " + entitySet.getName());
}
@Override
- public void writeBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData, BinaryData binaryData)
+ public void writeBinaryData(EdmEntitySet entitySet, Object mediaEntityInstance, BinaryData binaryData)
throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ try {
+ ANNOTATION_HELPER.setValueForAnnotatedField(
+ mediaEntityInstance, EdmMediaResourceContent.class, binaryData.getData());
+ ANNOTATION_HELPER.setValueForAnnotatedField(
+ mediaEntityInstance, EdmMediaResourceMimeType.class, binaryData.getMimeType());
+ } catch (ODataAnnotationException e) {
+ throw new ODataRuntimeException("Invalid media resource annotation at entity set '" + entitySet.getName()
+ + "' with message '" + e.getMessage() + "'.", e);
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/93d0002a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
index 3408c84..c29ac39 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
@@ -39,7 +39,9 @@ public class AnnotationValueAccess implements ValueAccess {
*/
@Override
public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException {
- if (annotationHelper.isEdmAnnotated(data)) {
+ if(data == null) {
+ return null;
+ } else if (annotationHelper.isEdmAnnotated(data)) {
return annotationHelper.getValueForProperty(data, property.getName());
}
throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/93d0002a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
index f52e023..4e43db4 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
@@ -146,7 +146,7 @@ public class DataStore<T> {
fieldName2KeyValue.put(ANNOTATION_HELPER.getCanonicalName(field), key);
}
- ANNOTATION_HELPER.setValuesToAnnotatedFields(fieldName2KeyValue, object, EdmKey.class);
+ ANNOTATION_HELPER.setValuesToAnnotatedFields(object, EdmKey.class, fieldName2KeyValue);
return object;
}
@@ -167,6 +167,7 @@ public class DataStore<T> {
}
public static class DataStoreException extends ODataApplicationException {
+ private static final long serialVersionUID = 42L;
public DataStoreException(String message) {
this(message, null);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/93d0002a/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 08699fa..f25d9b9 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
@@ -298,6 +298,8 @@ public class AnnotationHelper {
}
public static final class ODataAnnotationException extends ODataException {
+ private static final long serialVersionUID = 1L;
+
public ODataAnnotationException(String message) {
super(message);
}
@@ -482,8 +484,23 @@ public class AnnotationHelper {
return fieldName2Value;
}
- public void setValuesToAnnotatedFields(Map<String, Object> fieldName2Value, Object instance,
- Class<? extends Annotation> annotation) {
+ public void setValueForAnnotatedField(Object instance, Class<? extends Annotation> annotation, Object value)
+ throws ODataAnnotationException {
+ List<Field> fields = getAnnotatedFields(instance, annotation);
+
+ if(fields.isEmpty()) {
+ throw new ODataAnnotationException("No field found for annotation '" + annotation
+ + "' on instance '" + instance + "'.");
+ } else if(fields.size() > 1) {
+ throw new ODataAnnotationException("More then one field found for annotation '" + annotation
+ + "' on instance '" + instance + "'.");
+ }
+
+ setFieldValue(instance, fields.get(0), value);
+ }
+
+ public void setValuesToAnnotatedFields(Object instance,
+ Class<? extends Annotation> annotation, Map<String, Object> fieldName2Value) {
List<Field> fields = getAnnotatedFields(instance, annotation);
// XXX: refactore
@@ -575,16 +592,17 @@ public class AnnotationHelper {
}
}
- private void setFieldValue(Object instance, Field field, Object propertyValue) {
+ private void setFieldValue(Object instance, Field field, Object value) {
try {
- if (propertyValue != null
- && field.getType() != propertyValue.getClass()
- && propertyValue.getClass() == String.class) {
- propertyValue = convert(field, (String) propertyValue);
+ Object usedValue = value;
+ if (value != null
+ && field.getType() != value.getClass()
+ && value.getClass() == String.class) {
+ usedValue = convert(field, (String) value);
}
boolean access = field.isAccessible();
field.setAccessible(true);
- field.set(instance, propertyValue);
+ field.set(instance, usedValue);
field.setAccessible(access);
} catch (IllegalArgumentException ex) { // should never happen
throw new ODataRuntimeException(ex);