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 2014/10/10 08:11:40 UTC
git commit: [OLINGO-444] Minor improvements
Repository: olingo-odata4
Updated Branches:
refs/heads/master 169651531 -> ef0553a02
[OLINGO-444] Minor improvements
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/ef0553a0
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/ef0553a0
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/ef0553a0
Branch: refs/heads/master
Commit: ef0553a025c80ed0709ec0bdc13c00ae56852b31
Parents: 1696515
Author: Michael Bolz <mi...@sap.com>
Authored: Fri Oct 10 07:46:22 2014 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Fri Oct 10 08:11:16 2014 +0200
----------------------------------------------------------------------
.../olingo/commons/api/data/ContextURL.java | 8 ++---
.../serializer/utils/ContextURLBuilderTest.java | 6 ++--
.../tecsvc/processor/TechnicalProcessor.java | 37 ++++++--------------
3 files changed, 17 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef0553a0/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/ContextURL.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/ContextURL.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/ContextURL.java
index 476da10..dcc45f5 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/ContextURL.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/ContextURL.java
@@ -143,14 +143,14 @@ public class ContextURL {
return this;
}
- public Builder keySegment(Object value) {
+ public Builder keySegment(String value) {
if (value != null) {
- contextURL.keyPath = String.valueOf(value);
+ contextURL.keyPath = value;
}
return this;
}
- public Builder keySegment(Map<String, Object> values) {
+ public Builder keySegment(Map<String, String> values) {
if (values != null && !values.isEmpty()) {
if (values.size() == 1) {
@@ -158,7 +158,7 @@ public class ContextURL {
}
StringBuilder sb = new StringBuilder();
- for (String key:values.keySet()) {
+ for (String key: values.keySet()) {
if (sb.length() > 0) {
sb.append(",");
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef0553a0/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java
index a8b5e71..4ce699f 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java
@@ -111,13 +111,13 @@ public class ContextURLBuilderTest {
Mockito.when(entitySet.getName()).thenReturn("Customers");
ContextURL contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/"))
.entitySet(entitySet)
- .keySegment(1)
+ .keySegment(String.valueOf(1))
.navOrPropertyPath("Name")
.build();
assertEquals("http://host/service/$metadata#Customers(1)/Name",
ContextURLBuilder.create(contextURL).toASCIIString());
- TreeMap<String, Object> keys = new TreeMap<String, Object>();
- keys.put("one", 1);
+ TreeMap<String, String> keys = new TreeMap<String, String>();
+ keys.put("one", String.valueOf(1));
keys.put("two", "'two'");
contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/"))
.entitySet(entitySet)
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef0553a0/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
index 63a59c3..8609b0e 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
@@ -20,10 +20,7 @@ package org.apache.olingo.server.tecsvc.processor;
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.TreeMap;
+import java.util.*;
import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.commons.api.data.ContextURL.Suffix;
@@ -32,7 +29,6 @@ import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
-import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmProperty;
@@ -217,24 +213,11 @@ public class TechnicalProcessor implements EntitySetProcessor, EntityProcessor,
.build();
}
- private Map<String, Object> getKeys(EdmEntityType entityType,
- List<UriParameter> parameters) throws ODataApplicationException {
- TreeMap<String, Object> keys = new TreeMap<String, Object>();
+ private Map<String, String> mapKeys(List<UriParameter> parameters)
+ throws ODataApplicationException {
+ Map<String, String> keys = new LinkedHashMap<String, String>();
for (UriParameter param: parameters) {
- final EdmProperty property = (EdmProperty) entityType.getProperty(param.getName());
- final EdmPrimitiveType type = (EdmPrimitiveType) property.getType();
- try {
- Object keyValue = type.valueOfString(param.getText(),
- property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(),
- property.isUnicode(), type.getDefaultType());
- if (keyValue instanceof String) {
- keyValue = "'"+keyValue+"'";
- }
- keys.put(param.getName(), keyValue);
- } catch (EdmPrimitiveTypeException e) {
- throw new ODataApplicationException("Invalid key found", HttpStatusCode.BAD_REQUEST.getStatusCode(),
- Locale.ROOT, e);
- }
+ keys.put(param.getName(), param.getText());
}
return keys;
}
@@ -264,11 +247,11 @@ public class TechnicalProcessor implements EntitySetProcessor, EntityProcessor,
final ODataFormat format = ODataFormat.fromContentType(contentType);
ODataSerializer serializer = odata.createSerializer(format);
response.setContent(serializer.entityProperty(edmProperty, property,
- ODataSerializerOptions.with().contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
- ContextURL.with().entitySet(edmEntitySet)
- .keySegment(getKeys(edmEntitySet.getEntityType(), resourceEntitySet.getKeyPredicates()))
- .navOrPropertyPath(edmProperty.getName())
- .build()).build()));
+ ODataSerializerOptions.with().contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
+ ContextURL.with().entitySet(edmEntitySet)
+ .keySegment(mapKeys(resourceEntitySet.getKeyPredicates()))
+ .navOrPropertyPath(edmProperty.getName())
+ .build()).build()));
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, contentType.toContentTypeString());
}