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 2016/01/25 21:31:25 UTC
[45/51] [abbrv] olingo-odata4 git commit: OLINGO-853: Correcting the
encoding of datetime properties correctly to be used in a URI
OLINGO-853: Correcting the encoding of datetime properties correctly to be used in a URI
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/03aa1d07
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/03aa1d07
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/03aa1d07
Branch: refs/heads/OLINGO-832_StreamSerializerPoC
Commit: 03aa1d07d9b82e431d2b5949c4390aaf41aac6a3
Parents: 8537f3a
Author: Ramesh Reddy <ra...@jboss.org>
Authored: Thu Jan 21 13:13:37 2016 -0600
Committer: Ramesh Reddy <ra...@jboss.org>
Committed: Thu Jan 21 13:13:37 2016 -0600
----------------------------------------------------------------------
.../server/core/responses/EntityResponse.java | 43 ++++++++++++++++----
.../olingo/server/example/TripPinDataModel.java | 4 +-
2 files changed, 37 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/03aa1d07/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java
index a687424..5bf86a3 100644
--- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java
@@ -24,13 +24,17 @@ import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.api.http.HttpStatusCode;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmString;
import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataLibraryException;
import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.ODataServerError;
-import org.apache.olingo.server.api.ODataLibraryException;
import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
import org.apache.olingo.server.api.serializer.ODataSerializer;
@@ -99,7 +103,12 @@ public class EntityResponse extends ServiceResponse {
// exception
assert (entity != null);
- String locationHeader = buildLocation(this.baseURL, entity, entitySet.getName(), entitySet.getEntityType());
+ String locationHeader;
+ try {
+ locationHeader = buildLocation(this.baseURL, entity, entitySet.getName(), entitySet.getEntityType());
+ } catch (EdmPrimitiveTypeException e) {
+ throw new SerializerException(e.getMessage(), e, SerializerException.MessageKeys.WRONG_PRIMITIVE_VALUE);
+ }
// Note that if media written just like Stream, but on entity URL
@@ -163,12 +172,20 @@ public class EntityResponse extends ServiceResponse {
close();
}
- public static String buildLocation(String baseURL, Entity entity, String enitySetName, EdmEntityType type) {
+ public static String buildLocation(String baseURL, Entity entity, String enitySetName, EdmEntityType type)
+ throws EdmPrimitiveTypeException {
+ StringBuilder location = new StringBuilder();
+ location.append(baseURL).append("/").append(enitySetName);
+ location.append(buildKeySegmentsURI(entity, type));
+ return location.toString();
+ }
+
+ public static String buildKeySegmentsURI(Entity entity, EdmEntityType type)
+ throws EdmPrimitiveTypeException {
StringBuilder location = new StringBuilder();
- location.append(baseURL).append("/").append(enitySetName).append("(");
int i = 0;
boolean usename = type.getKeyPredicateNames().size() > 1;
-
+ location.append("(");
for (String key : type.getKeyPredicateNames()) {
if (i > 0) {
location.append(",");
@@ -177,11 +194,19 @@ public class EntityResponse extends ServiceResponse {
if (usename) {
location.append(key).append("=");
}
- if (entity.getProperty(key).getType().equals("Edm.String")) {
- location.append("'").append(entity.getProperty(key).getValue().toString()).append("'");
- } else {
- location.append(entity.getProperty(key).getValue().toString());
+ String propertyType = entity.getProperty(key).getType();
+ Object propertyValue = entity.getProperty(key).getValue();
+
+ if(propertyType.startsWith("Edm.")) {
+ propertyType = propertyType.substring(4);
+ }
+ EdmPrimitiveTypeKind kind = EdmPrimitiveTypeKind.valueOf(propertyType);
+ String value = EdmPrimitiveTypeFactory.getInstance(kind).valueToString(
+ propertyValue, true, 4000, 0, 0, true);
+ if (kind == EdmPrimitiveTypeKind.String) {
+ value = EdmString.getInstance().toUriLiteral(value);
}
+ location.append(value);
}
location.append(")");
return location.toString();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/03aa1d07/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java
index 646e835..c58d9ce 100644
--- a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java
+++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java
@@ -625,8 +625,10 @@ public class TripPinDataModel {
} catch (URISyntaxException e) {
throw new ODataApplicationException("Failed to create ID for entity", 500,
Locale.getDefault());
+ } catch (EdmPrimitiveTypeException e) {
+ throw new ODataApplicationException("Failed to create ID for entity", 500,
+ Locale.getDefault());
}
-
set.getEntities().add(copy);
return copy;
}