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 2015/04/30 15:36:35 UTC
[1/2] olingo-odata2 git commit: [OLINGO-637] Added
'createPathSegment' to UriParser
Repository: olingo-odata2
Updated Branches:
refs/heads/master fcf813717 -> 6c321d04b
[OLINGO-637] Added 'createPathSegment' to UriParser
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/c9524569
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/c9524569
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/c9524569
Branch: refs/heads/master
Commit: c9524569ea269c7b84e650e25dbf7b8ce1626700
Parents: fcf8137
Author: Michael Bolz <mi...@sap.com>
Authored: Thu Apr 23 10:08:34 2015 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Thu Apr 30 15:33:07 2015 +0200
----------------------------------------------------------------------
.../apache/olingo/odata2/api/uri/UriParser.java | 19 ++++++++++
.../olingo/odata2/core/uri/UriParserImpl.java | 6 ++++
.../olingo/odata2/core/uri/UriParserTest.java | 38 ++++++++++++++------
3 files changed, 52 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/c9524569/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/uri/UriParser.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/uri/UriParser.java b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/uri/UriParser.java
index 4032306..5447bc4 100644
--- a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/uri/UriParser.java
+++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/uri/UriParser.java
@@ -206,6 +206,25 @@ public abstract class UriParser {
List<ArrayList<NavigationPropertySegment>> expand) throws EdmException;
/**
+ * Creates an path segment object.
+ * @param path path of created path segment
+ * @param matrixParameters Map of Lists of matrix parameters for this path segemt
+ * @return create path segment
+ */
+ protected abstract PathSegment buildPathSegment(String path, Map<String, List<String>> matrixParameters);
+
+
+ /**
+ * Creates an path segment object.
+ * @param path path of created path segment
+ * @param matrixParameters Map of Lists of matrix parameters for this path segemt
+ * @return create path segment
+ */
+ public static PathSegment createPathSegment(String path, Map<String, List<String>> matrixParameters) {
+ return RuntimeDelegate.getUriParser(null).buildPathSegment(path, matrixParameters);
+ }
+
+ /**
* <p>Retrieves the key predicates from a canonical link to an entity.</p>
* <p>A canonical link to an entity must follow the pattern
* <code>[<service root>][<entityContainer>.]<entitySet>(<key>)</code>, i.e.,
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/c9524569/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java
index 162ca8d..61f73dc 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java
@@ -62,6 +62,7 @@ import org.apache.olingo.odata2.api.uri.UriSyntaxException;
import org.apache.olingo.odata2.api.uri.expression.ExpressionParserException;
import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
+import org.apache.olingo.odata2.core.ODataPathSegmentImpl;
import org.apache.olingo.odata2.core.commons.Decoder;
import org.apache.olingo.odata2.core.edm.EdmSimpleTypeFacadeImpl;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
@@ -894,6 +895,11 @@ public class UriParserImpl extends UriParser {
}
@Override
+ protected PathSegment buildPathSegment(String path, Map<String, List<String>> matrixParameters) {
+ return new ODataPathSegmentImpl(path, matrixParameters);
+ }
+
+ @Override
public List<KeyPredicate> getKeyFromEntityLink(final EdmEntitySet entitySet, final String entityLink,
final URI serviceRoot) throws ODataException {
final String relativeLink = serviceRoot == null ? entityLink :
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/c9524569/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/UriParserTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/UriParserTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/UriParserTest.java
index 64b88bd..e628fc3 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/UriParserTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/UriParserTest.java
@@ -48,8 +48,8 @@ import org.apache.olingo.odata2.api.uri.KeyPredicate;
import org.apache.olingo.odata2.api.uri.PathSegment;
import org.apache.olingo.odata2.api.uri.UriInfo;
import org.apache.olingo.odata2.api.uri.UriNotMatchingException;
+import org.apache.olingo.odata2.api.uri.UriParser;
import org.apache.olingo.odata2.api.uri.UriSyntaxException;
-import org.apache.olingo.odata2.core.ODataPathSegmentImpl;
import org.apache.olingo.odata2.testutil.fit.BaseTest;
import org.apache.olingo.odata2.testutil.mock.MockFacade;
import org.junit.Before;
@@ -64,7 +64,7 @@ public class UriParserTest extends BaseTest {
private Edm edm;
@Before
- public void getEdm() throws ODataException, EdmException {
+ public void getEdm() throws ODataException {
edm = MockFacade.getMockEdm();
}
@@ -124,7 +124,7 @@ public class UriParserTest extends BaseTest {
@Test
public void copyPathSegmentsTest() throws Exception {
List<PathSegment> pathSegments = new ArrayList<PathSegment>();
- pathSegments.add(new ODataPathSegmentImpl("$metadata", null));
+ pathSegments.add(UriParser.createPathSegment("$metadata", null));
UriInfo result = new UriParserImpl(edm).parse(pathSegments, Collections.<String, String> emptyMap());
assertNotNull(result);
assertEquals(1, pathSegments.size());
@@ -134,8 +134,8 @@ public class UriParserTest extends BaseTest {
@Test
public void copyPathSegmentsTestEncoded() throws Exception {
List<PathSegment> pathSegments = new ArrayList<PathSegment>();
- pathSegments.add(new ODataPathSegmentImpl("%24metadata", null));
- UriInfoImpl result = (UriInfoImpl) new UriParserImpl(edm).parse(pathSegments,
+ pathSegments.add(UriParser.createPathSegment("%24metadata", null));
+ UriInfoImpl result = (UriInfoImpl) new UriParserImpl(edm).parse(pathSegments,
Collections.<String, String> emptyMap());
assertNotNull(result);
assertEquals(UriType.URI8, result.getUriType());
@@ -951,8 +951,8 @@ public class UriParserTest extends BaseTest {
assertEquals("EmployeeName", result.getSelect().get(0).getProperty().getName());
assertEquals("Location", result.getSelect().get(1).getProperty().getName());
assertEquals(1, result.getSelect().get(0).getNavigationPropertySegments().size());
- assertEquals("Employees", result.getSelect().get(0).getNavigationPropertySegments().get(0).getTargetEntitySet()
- .getName());
+ assertEquals("Employees",
+ result.getSelect().get(0).getNavigationPropertySegments().get(0).getTargetEntitySet().getName());
}
@Test
@@ -980,8 +980,8 @@ public class UriParserTest extends BaseTest {
assertEquals(1, result.getExpand().size());
assertEquals(1, result.getExpand().get(0).size());
assertEquals("Employees", result.getExpand().get(0).get(0).getTargetEntitySet().getName());
- assertEquals(result.getTargetEntitySet().getEntityType().getProperty("nm_Employees"), result.getExpand().get(0)
- .get(0).getNavigationProperty());
+ assertEquals(result.getTargetEntitySet().getEntityType().getProperty("nm_Employees"),
+ result.getExpand().get(0).get(0).getNavigationProperty());
result = parse("Managers('1')?%24expand=nm_Employees");
assertEquals("Managers", result.getTargetEntitySet().getName());
@@ -989,8 +989,8 @@ public class UriParserTest extends BaseTest {
assertEquals(1, result.getExpand().size());
assertEquals(1, result.getExpand().get(0).size());
assertEquals("Employees", result.getExpand().get(0).get(0).getTargetEntitySet().getName());
- assertEquals(result.getTargetEntitySet().getEntityType().getProperty("nm_Employees"), result.getExpand().get(0)
- .get(0).getNavigationProperty());
+ assertEquals(result.getTargetEntitySet().getEntityType().getProperty("nm_Employees"),
+ result.getExpand().get(0).get(0).getNavigationProperty());
}
@Test
@@ -1057,4 +1057,20 @@ public class UriParserTest extends BaseTest {
wrongGetKey(entitySet2, "anotherContainer.Photos(Id=12,Type='test')", null,
UriNotMatchingException.CONTAINERNOTFOUND);
}
+
+ @Test
+ public void createPathSegment() {
+ PathSegment segment = UriParser.createPathSegment("simple", null);
+ assertEquals("simple", segment.getPath());
+ assertTrue(segment.getMatrixParameters().isEmpty());
+
+ Map<String, List<String>> matrixParameter = new HashMap<String, List<String>>();
+ matrixParameter.put("parameter1", Arrays.asList("one", "two"));
+ PathSegment segmentWithMatrix = UriParser.createPathSegment("matrix", matrixParameter);
+ assertEquals("matrix", segmentWithMatrix.getPath());
+ assertEquals(1, segmentWithMatrix.getMatrixParameters().size());
+ assertEquals(2, segmentWithMatrix.getMatrixParameters().get("parameter1").size());
+ assertTrue(segmentWithMatrix.getMatrixParameters().get("parameter1").contains("one"));
+ assertTrue(segmentWithMatrix.getMatrixParameters().get("parameter1").contains("two"));
+ }
}
[2/2] olingo-odata2 git commit: [OLINGO-637] Added
'createPathSegment' to UriParser
Posted by mi...@apache.org.
[OLINGO-637] Added 'createPathSegment' to UriParser
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/6c321d04
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/6c321d04
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/6c321d04
Branch: refs/heads/master
Commit: 6c321d04b440bda3f058fe9411be3bf54036d450
Parents: c952456
Author: Michael Bolz <mi...@sap.com>
Authored: Thu Apr 23 12:56:58 2015 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Thu Apr 30 15:33:08 2015 +0200
----------------------------------------------------------------------
.../org/apache/olingo/odata2/api/uri/UriParser.java | 10 ++++++----
.../apache/olingo/odata2/core/ODataPathSegmentImpl.java | 12 ++++++++++--
2 files changed, 16 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/6c321d04/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/uri/UriParser.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/uri/UriParser.java b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/uri/UriParser.java
index 5447bc4..11426d0 100644
--- a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/uri/UriParser.java
+++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/uri/UriParser.java
@@ -208,8 +208,9 @@ public abstract class UriParser {
/**
* Creates an path segment object.
* @param path path of created path segment
- * @param matrixParameters Map of Lists of matrix parameters for this path segemt
- * @return create path segment
+ * @param matrixParameters Map of Lists of matrix parameters for this path segment (can be null if no matrix
+ * parameters should be set for this path segment)
+ * @return created path segment
*/
protected abstract PathSegment buildPathSegment(String path, Map<String, List<String>> matrixParameters);
@@ -217,8 +218,9 @@ public abstract class UriParser {
/**
* Creates an path segment object.
* @param path path of created path segment
- * @param matrixParameters Map of Lists of matrix parameters for this path segemt
- * @return create path segment
+ * @param matrixParameters Map of Lists of matrix parameters for this path segment (can be null if no matrix
+ * parameters should be set for this path segment)
+ * @return created path segment
*/
public static PathSegment createPathSegment(String path, Map<String, List<String>> matrixParameters) {
return RuntimeDelegate.getUriParser(null).buildPathSegment(path, matrixParameters);
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/6c321d04/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataPathSegmentImpl.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataPathSegmentImpl.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataPathSegmentImpl.java
index 94de51d..b56b4b3 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataPathSegmentImpl.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataPathSegmentImpl.java
@@ -18,6 +18,7 @@
******************************************************************************/
package org.apache.olingo.odata2.core;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -33,14 +34,21 @@ public class ODataPathSegmentImpl implements PathSegment {
private String path;
private Map<String, List<String>> matrixParameter;
+ /**
+ * Constructor for an path segment object.
+ * @param path path of created path segment
+ * @param matrixParameters Map of Lists of matrix parameters for this path segment (can be null if no matrix
+ * parameters should be set for this path segment)
+ */
public ODataPathSegmentImpl(final String path, final Map<String, List<String>> matrixParameters) {
this.path = path;
Map<String, List<String>> unmodifiableMap = new HashMap<String, List<String>>();
if (matrixParameters != null) {
for (String key : matrixParameters.keySet()) {
- List<String> values = Collections.unmodifiableList(matrixParameters.get(key));
- unmodifiableMap.put(key, values);
+ List<String> values = matrixParameters.get(key);
+ List<String> tempList = values == null ? null: Collections.unmodifiableList(new ArrayList<String>(values));
+ unmodifiableMap.put(key, tempList);
}
}