Repository: olingo-odata4 Updated Branches: refs/heads/master f7c18f744 -> 256468aa2
OLINGO-907: correcting entity-id resolution with different paths Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/d613bb96 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/d613bb96 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/d613bb96 Branch: refs/heads/master Commit: d613bb96a7c07a223ff4fb07d209eaf9c6feeb58 Parents: 5dee97f Author: Ramesh Reddy <[email protected]> Authored: Thu Mar 24 10:42:43 2016 -0500 Committer: Ramesh Reddy <[email protected]> Committed: Thu Mar 24 10:42:43 2016 -0500 ---------------------------------------------------------------------- .../server/core/SchemaBasedEdmProvider.java | 2 +- .../olingo/server/core/ServiceDispatcher.java | 71 +++++++++++--------- .../olingo/server/core/ServiceRequest.java | 6 +- .../olingo/server/example/TripPinHandler.java | 48 +++++-------- 4 files changed, 62 insertions(+), 65 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d613bb96/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/SchemaBasedEdmProvider.java ---------------------------------------------------------------------- diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/SchemaBasedEdmProvider.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/SchemaBasedEdmProvider.java index 4de41d9..3017682 100644 --- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/SchemaBasedEdmProvider.java +++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/SchemaBasedEdmProvider.java @@ -57,7 +57,7 @@ public class SchemaBasedEdmProvider implements CsdlEdmProvider { this.edmSchemas.add(schema); } - List<EdmxReference> getReferences(){ + public List<EdmxReference> getReferences(){ return new ArrayList<EdmxReference>(references.values()); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d613bb96/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java ---------------------------------------------------------------------- diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java index 45e9b06..0500247 100644 --- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java +++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java @@ -20,7 +20,6 @@ package org.apache.olingo.server.core; import java.net.URI; import java.net.URISyntaxException; -import java.net.URL; import java.util.StringTokenizer; import org.apache.olingo.commons.api.ex.ODataException; @@ -87,37 +86,16 @@ public class ServiceDispatcher extends RequestURLHierarchyVisitor { String path = odRequest.getRawODataPath(); String query = odRequest.getRawQueryPath(); if(path.indexOf("$entity") != -1) { - StringBuilder sb = new StringBuilder(); - StringTokenizer st = new StringTokenizer(query, "&"); - while(st.hasMoreTokens()) { - String token = st.nextToken(); - if (token.startsWith("$id=")) { - try { - path = new URL(Decoder.decode(token.substring(4))).getPath(); - int index = path.indexOf('/', 1); - if (index != -1) { - path = path.substring(index); - } - } catch (Exception e) { - path = Decoder.decode(token.substring(4)); - } - } else { - if (sb.length() > 0) { - sb.append("&"); - } - sb.append(token); - } - } - query = sb.toString(); + executeIdOption(query, odRequest, odResponse); + } else { + UriInfo uriInfo = new Parser(this.metadata.getEdm(), odata) + .parseUri(path, query, null); + + contentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), + odRequest, this.customContentSupport, RepresentationType.ERROR); + + internalExecute(uriInfo, odRequest, odResponse); } - - UriInfo uriInfo = new Parser(this.metadata.getEdm(), odata) - .parseUri(path, query, null); - - contentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), - odRequest, this.customContentSupport, RepresentationType.ERROR); - - internalExecute(uriInfo, odRequest, odResponse); } catch(ODataLibraryException e) { handleException(e, contentType, odRequest, odResponse); } catch(ODataApplicationException e) { @@ -291,4 +269,35 @@ public class ServiceDispatcher extends RequestURLHierarchyVisitor { dataRequest.setCrossJoin(info); this.request = dataRequest; } + + private void executeIdOption(String query, ODataRequest odRequest, + ODataResponse odResponse) throws ODataLibraryException, + ODataApplicationException { + StringBuilder sb = new StringBuilder(); + StringTokenizer st = new StringTokenizer(query, "&"); + boolean first = true; + while(st.hasMoreTokens()) { + String token = st.nextToken(); + if (token.startsWith("$id=")) { + URI id = URI.create(Decoder.decode(token.substring(4))); + sb.append(id.getPath()); + } else { + if (first) { + sb.append("?"); + } else { + sb.append("&"); + } + sb.append(token); + } + } + DataRequest dataRequest = new DataRequest(this.odata, this.metadata); + this.request = dataRequest; + + this.request.setODataRequest(odRequest); + this.request = this.request.parseLink(URI.create(sb.toString())); + + this.request.setODataRequest(odRequest); + this.request.setCustomContentTypeSupport(this.customContentSupport); + this.request.execute(this.handler, odResponse); + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d613bb96/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java ---------------------------------------------------------------------- diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java index e85d7ba..67d794c 100644 --- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java +++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java @@ -20,7 +20,6 @@ package org.apache.olingo.server.core; import java.net.URI; -import java.net.URISyntaxException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -328,9 +327,9 @@ public abstract class ServiceRequest { return null; } - public DataRequest parseLink(URI uri) throws UriParserException, UriValidationException, URISyntaxException { + public DataRequest parseLink(URI uri) throws UriParserException, UriValidationException { String path = "/"; - URI servicePath = new URI(getODataRequest().getRawBaseUri()); + URI servicePath = URI.create(getODataRequest().getRawBaseUri()); path = servicePath.getPath(); String rawPath = uri.getPath(); @@ -344,6 +343,7 @@ public abstract class ServiceRequest { UriInfo uriInfo = new Parser(serviceMetadata.getEdm(), odata).parseUri(rawPath, uri.getQuery(), null); ServiceDispatcher dispatcher = new ServiceDispatcher(odata, serviceMetadata, null, customContentType); dispatcher.visit(uriInfo); + dispatcher.request.setUriInfo(uriInfo); return (DataRequest)dispatcher.request; } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d613bb96/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinHandler.java ---------------------------------------------------------------------- diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinHandler.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinHandler.java index b83c0e4..4a92198 100644 --- a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinHandler.java +++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinHandler.java @@ -464,14 +464,10 @@ public class TripPinHandler implements ServiceHandler { final EntityDetails details = process(request); - try { - DataRequest bindingRequest = request.parseLink(referenceId); - Entity linkEntity = this.dataModel.getEntity(bindingRequest.getEntitySet().getName(), - bindingRequest.getKeyPredicates()); - this.dataModel.addNavigationLink(details.navigationProperty, details.entity, linkEntity); - } catch (URISyntaxException e) { - throw new ODataApplicationException(e.getMessage(), 500, Locale.getDefault(), e); - } + DataRequest bindingRequest = request.parseLink(referenceId); + Entity linkEntity = this.dataModel.getEntity(bindingRequest.getEntitySet().getName(), + bindingRequest.getKeyPredicates()); + this.dataModel.addNavigationLink(details.navigationProperty, details.entity, linkEntity); response.writeNoContent(); } @@ -480,17 +476,13 @@ public class TripPinHandler implements ServiceHandler { NoContentResponse response) throws ODataLibraryException, ODataApplicationException { // this single valued navigation. boolean updated = false; - try { - final EntityDetails details = process(request); - DataRequest updateRequest = request.parseLink(updateId); - Entity updateEntity = this.dataModel.getEntity(updateRequest.getEntitySet().getName(), - updateRequest.getKeyPredicates()); - if (updateEntity != null) { - updated = this.dataModel.updateNavigationLink(details.navigationProperty, - details.parentEntity, updateEntity); - } - } catch (URISyntaxException e) { - throw new ODataApplicationException(e.getMessage(), 500, Locale.getDefault(), e); + final EntityDetails details = process(request); + DataRequest updateRequest = request.parseLink(updateId); + Entity updateEntity = this.dataModel.getEntity(updateRequest.getEntitySet().getName(), + updateRequest.getKeyPredicates()); + if (updateEntity != null) { + updated = this.dataModel.updateNavigationLink(details.navigationProperty, + details.parentEntity, updateEntity); } if (updated) { @@ -505,17 +497,13 @@ public class TripPinHandler implements ServiceHandler { NoContentResponse response) throws ODataLibraryException, ODataApplicationException { boolean removed = false; if (deleteId != null) { - try { - final EntityDetails details = process(request); - DataRequest deleteRequest = request.parseLink(deleteId); - Entity deleteEntity = this.dataModel.getEntity(deleteRequest.getEntitySet().getName(), - deleteRequest.getKeyPredicates()); - if (deleteEntity != null) { - removed = this.dataModel.removeNavigationLink(details.navigationProperty, details.entity, - deleteEntity); - } - } catch (URISyntaxException e) { - throw new ODataApplicationException(e.getMessage(), 500, Locale.getDefault(), e); + final EntityDetails details = process(request); + DataRequest deleteRequest = request.parseLink(deleteId); + Entity deleteEntity = this.dataModel.getEntity(deleteRequest.getEntitySet().getName(), + deleteRequest.getKeyPredicates()); + if (deleteEntity != null) { + removed = this.dataModel.removeNavigationLink(details.navigationProperty, details.entity, + deleteEntity); } } else { // this single valued navigation.
