You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2016/01/18 13:49:51 UTC
[1/3] olingo-odata4 git commit: [OLINGO-575] removal of some test V3
code
Repository: olingo-odata4
Updated Branches:
refs/heads/master 1b6259b97 -> 26f7d2a6b
[OLINGO-575] removal of some test V3 code
Signed-off-by: Christian Amend <ch...@sap.com>
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/c7aa842f
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/c7aa842f
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/c7aa842f
Branch: refs/heads/master
Commit: c7aa842fb40856e068dc2741fe5c33f1abb7b6ec
Parents: 1b6259b
Author: Klaus Straubinger <kl...@sap.com>
Authored: Fri Jan 15 16:06:45 2016 +0100
Committer: Christian Amend <ch...@sap.com>
Committed: Mon Jan 18 13:35:48 2016 +0100
----------------------------------------------------------------------
.../org/apache/olingo/fit/AbstractServices.java | 46 --------
.../apache/olingo/fit/metadata/Association.java | 70 ------------
.../olingo/fit/metadata/AssociationSet.java | 74 -------------
.../apache/olingo/fit/metadata/Container.java | 13 ---
.../apache/olingo/fit/metadata/Metadata.java | 110 +++----------------
.../olingo/fit/metadata/NavigationProperty.java | 27 -----
.../org/apache/olingo/fit/metadata/Schema.java | 14 ---
.../org/apache/olingo/fit/methods/MERGE.java | 33 ------
.../org/apache/olingo/fit/utils/Constants.java | 60 +++-------
.../olingo/fit/base/EntityUpdateTestITCase.java | 2 +-
.../edm/annotation/EdmConstantExpression.java | 8 +-
11 files changed, 35 insertions(+), 422 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c7aa842f/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
index fc886ff..c287e5b 100644
--- a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
+++ b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
@@ -88,7 +88,6 @@ import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.apache.olingo.fit.metadata.EntityType;
import org.apache.olingo.fit.metadata.Metadata;
import org.apache.olingo.fit.metadata.NavigationProperty;
-import org.apache.olingo.fit.methods.MERGE;
import org.apache.olingo.fit.methods.PATCH;
import org.apache.olingo.fit.serializer.FITAtomDeserializer;
import org.apache.olingo.fit.utils.AbstractUtilities;
@@ -414,23 +413,6 @@ public abstract class AbstractServices {
addSingleBatchResponse(xml.createFaultResponse(Accept.XML.toString(), e), contentId, bos);
}
- @MERGE
- @Path("/{entitySetName}({entityId})")
- @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
- @Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
- public Response mergeEntity(
- @Context final UriInfo uriInfo,
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
- @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
- @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
- @HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
- @PathParam("entitySetName") final String entitySetName,
- @PathParam("entityId") final String entityId,
- final String changes) {
-
- return patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName, entityId, changes);
- }
-
@PATCH
@Path("/{entitySetName}({entityId})")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
@@ -1510,34 +1492,6 @@ public abstract class AbstractServices {
* @param changes
* @return response
*/
- @MERGE
- @Path("/{entitySetName}({entityId})/{path:.*}")
- public Response mergeProperty(
- @Context final UriInfo uriInfo,
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
- @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
- @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
- @PathParam("entitySetName") final String entitySetName,
- @PathParam("entityId") final String entityId,
- @PathParam("path") final String path,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
- final String changes) {
-
- return replaceProperty(uriInfo.getRequestUri().toASCIIString(),
- accept, contentType, prefer, entitySetName, entityId, path, format, changes, false);
- }
-
- /**
- * Replace property.
- *
- * @param accept
- * @param entitySetName
- * @param entityId
- * @param path
- * @param format
- * @param changes
- * @return response
- */
@PATCH
@Path("/{entitySetName}({entityId})/{path:.*}")
public Response patchProperty(
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c7aa842f/fit/src/main/java/org/apache/olingo/fit/metadata/Association.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/metadata/Association.java b/fit/src/main/java/org/apache/olingo/fit/metadata/Association.java
deleted file mode 100644
index aa0ce6d..0000000
--- a/fit/src/main/java/org/apache/olingo/fit/metadata/Association.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.fit.metadata;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-public class Association extends AbstractMetadataElement {
-
- private final String name;
-
- private Map<String, Role> roles;
-
- public Association(final String name) {
- this.name = name;
- roles = new LinkedHashMap<String, Role>();
- }
-
- public String getName() {
- return name;
- }
-
- public Association addRole(final String name, final String type, final String multiplicity) {
- roles.put(name, new Role(name, type, multiplicity));
- return this;
- }
-
- public Role getRole(final String name) {
- return roles.get(name);
- }
-
- public static class Role {
-
- final String name;
-
- final String type;
-
- final String multiplicity;
-
- public Role(final String name, final String type, final String multiplicity) {
- this.name = name;
- this.type = type;
- this.multiplicity = multiplicity;
- }
-
- public String getType() {
- return type;
- }
-
- public String getMultiplicity() {
- return multiplicity;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c7aa842f/fit/src/main/java/org/apache/olingo/fit/metadata/AssociationSet.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/metadata/AssociationSet.java b/fit/src/main/java/org/apache/olingo/fit/metadata/AssociationSet.java
deleted file mode 100644
index 9bda9db..0000000
--- a/fit/src/main/java/org/apache/olingo/fit/metadata/AssociationSet.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.fit.metadata;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-public class AssociationSet extends AbstractMetadataElement {
-
- private final String name;
-
- private final String association;
-
- private Map<String, Role> roles;
-
- public AssociationSet(final String name, final String association) {
- this.name = name;
- this.association = association;
- roles = new LinkedHashMap<String, Role>();
- }
-
- public String getName() {
- return name;
- }
-
- public String getAssociation() {
- return association;
- }
-
- public AssociationSet addRole(final String name, final String entitySet) {
- roles.put(name, new Role(name, entitySet));
- return this;
- }
-
- public Role getRole(final String name) {
- return roles.get(name);
- }
-
- public static class Role {
-
- final String name;
-
- final String entitySet;
-
- public Role(final String name, final String entitySet) {
- this.name = name;
- this.entitySet = entitySet;
- }
-
- public String getName() {
- return name;
- }
-
- public String getEntitySet() {
- return entitySet;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c7aa842f/fit/src/main/java/org/apache/olingo/fit/metadata/Container.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/metadata/Container.java b/fit/src/main/java/org/apache/olingo/fit/metadata/Container.java
index aab6143..e8eb3bf 100644
--- a/fit/src/main/java/org/apache/olingo/fit/metadata/Container.java
+++ b/fit/src/main/java/org/apache/olingo/fit/metadata/Container.java
@@ -26,25 +26,17 @@ import java.util.Map;
public class Container extends AbstractMetadataElement {
private final String name;
-
private final Map<String, EntitySet> entitySets;
- private final Map<String, AssociationSet> associationSets;
-
public Container(final String name) {
this.name = name;
entitySets = new HashMap<String, EntitySet>();
- associationSets = new HashMap<String, AssociationSet>();
}
public String getName() {
return name;
}
- public AssociationSet getAssociationSet(final String association) {
- return associationSets.get(association);
- }
-
public Collection<EntitySet> getEntitySets() {
return entitySets.values();
}
@@ -68,9 +60,4 @@ public class Container extends AbstractMetadataElement {
entitySets.put(name, entitySet);
return this;
}
-
- public Container addAssociationSet(final String name, final AssociationSet associationSet) {
- associationSets.put(name, associationSet);
- return this;
- }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c7aa842f/fit/src/main/java/org/apache/olingo/fit/metadata/Metadata.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/metadata/Metadata.java b/fit/src/main/java/org/apache/olingo/fit/metadata/Metadata.java
index 6482143..0d88b1d 100644
--- a/fit/src/main/java/org/apache/olingo/fit/metadata/Metadata.java
+++ b/fit/src/main/java/org/apache/olingo/fit/metadata/Metadata.java
@@ -82,37 +82,20 @@ public class Metadata extends AbstractMetadataElement {
for (Map.Entry<String, Schema> schemaEntry : schemas.entrySet()) {
for (EntityType entityType : schemaEntry.getValue().getEntityTypes()) {
for (NavigationProperty property : entityType.getNavigationProperties()) {
- if (StringUtils.isNotBlank(property.getReleationship())) {
- // V3 ...
- final Association association = schemaEntry.getValue().getAssociation(
- property.getReleationship().replaceAll(schemaEntry.getKey() + "\\.", ""));
- final Association.Role role = association.getRole(property.getToRole());
- property.setFeed(role.getMultiplicity().equals("*"));
- property.setType(property.isEntitySet() ? "Collection(" + role.getType() + ")" : role.getType());
-
- // let me assume that it will be just a single container
- final AssociationSet associationSet = schemaEntry.getValue().getContainers().iterator().next().
- getAssociationSet(property.getReleationship());
-
- final AssociationSet.Role associationSetRole = associationSet.getRole(property.getToRole());
- property.setTarget(associationSetRole.getEntitySet());
- } else {
- // V4 ...
- property.setFeed(property.getType().startsWith("Collection("));
-
- final Collection<EntitySet> entitySets = schemaEntry.getValue().getContainers().iterator().next().
- getEntitySets(schemaEntry.getKey(), entityType.getName());
-
- final Iterator<EntitySet> iter = entitySets.iterator();
- boolean found = false;
-
- while (!found && iter.hasNext()) {
- final EntitySet entitySet = iter.next();
- final String target = entitySet.getTarget(property.getName());
- if (StringUtils.isNotBlank(target)) {
- property.setTarget(entitySet.getTarget(property.getName()));
- found = true;
- }
+ property.setFeed(property.getType().startsWith("Collection("));
+
+ final Collection<EntitySet> entitySets = schemaEntry.getValue().getContainers().iterator().next().
+ getEntitySets(schemaEntry.getKey(), entityType.getName());
+
+ final Iterator<EntitySet> iter = entitySets.iterator();
+ boolean found = false;
+
+ while (!found && iter.hasNext()) {
+ final EntitySet entitySet = iter.next();
+ final String target = entitySet.getTarget(property.getName());
+ if (StringUtils.isNotBlank(target)) {
+ property.setTarget(entitySet.getTarget(property.getName()));
+ found = true;
}
}
}
@@ -209,10 +192,6 @@ public class Metadata extends AbstractMetadataElement {
&& event.asStartElement().getName().equals(new QName(DEF_NS, "EntityContainer"))) {
final org.apache.olingo.fit.metadata.Container container = getContainer(event.asStartElement(), reader);
schema.addContainer(container.getName(), container);
- } else if (event.isStartElement() && event.asStartElement().getName().equals(new QName(DEF_NS, "Association"))) {
- // just for V3
- final Association association = getAssociation(event.asStartElement(), reader);
- schema.addAssociation(association.getName(), association);
} else if (event.isEndElement() && event.asEndElement().getName().equals(start.getName())) {
completed = true;
}
@@ -236,11 +215,6 @@ public class Metadata extends AbstractMetadataElement {
|| event.asStartElement().getName().equals(new QName(DEF_NS, "Singleton")))) {
final EntitySet entitySet = getEntitySet(event.asStartElement(), reader);
container.addEntitySet(entitySet.getName(), entitySet);
- } else if (event.isStartElement()
- && event.asStartElement().getName().equals(new QName(DEF_NS, "AssociationSet"))) {
- // just for V3
- final AssociationSet associationSet = getAssociationSet(event.asStartElement(), reader);
- container.addAssociationSet(associationSet.getAssociation(), associationSet);
} else if (event.isEndElement() && event.asEndElement().getName().equals(start.getName())) {
completed = true;
}
@@ -249,52 +223,6 @@ public class Metadata extends AbstractMetadataElement {
return container;
}
- private Association getAssociation(
- final StartElement start, final XMLEventReader reader) throws XMLStreamException {
- final Association association = new Association(start.getAttributeByName(new QName("Name")).getValue());
-
- boolean completed = false;
-
- while (!completed && reader.hasNext()) {
- XMLEvent event = reader.nextEvent();
-
- if (event.isStartElement() && event.asStartElement().getName().equals(new QName(DEF_NS, "End"))) {
- final String role = event.asStartElement().getAttributeByName(new QName("Role")).getValue();
- final String type = event.asStartElement().getAttributeByName(new QName("Type")).getValue();
- final String multiplicity =
- event.asStartElement().getAttributeByName(new QName("Multiplicity")).getValue();
- association.addRole(role, type, multiplicity);
- } else if (event.isEndElement() && event.asEndElement().getName().equals(start.getName())) {
- completed = true;
- }
- }
-
- return association;
- }
-
- private AssociationSet getAssociationSet(
- final StartElement start, final XMLEventReader reader) throws XMLStreamException {
- final AssociationSet associationSet = new AssociationSet(
- start.getAttributeByName(new QName("Name")).getValue(),
- start.getAttributeByName(new QName("Association")).getValue());
-
- boolean completed = false;
-
- while (!completed && reader.hasNext()) {
- XMLEvent event = reader.nextEvent();
-
- if (event.isStartElement() && event.asStartElement().getName().equals(new QName(DEF_NS, "End"))) {
- final String role = event.asStartElement().getAttributeByName(new QName("Role")).getValue();
- final String entitySet = event.asStartElement().getAttributeByName(new QName("EntitySet")).getValue();
- associationSet.addRole(role, entitySet);
- } else if (event.isEndElement() && event.asEndElement().getName().equals(start.getName())) {
- completed = true;
- }
- }
-
- return associationSet;
- }
-
private EntityType getEntityType(final StartElement start, final XMLEventReader reader) throws XMLStreamException {
final EntityType entityType = new EntityType(start.getAttributeByName(new QName("Name")).getValue());
final Attribute baseType = start.getAttributeByName(new QName("BaseType"));
@@ -348,16 +276,6 @@ public class Metadata extends AbstractMetadataElement {
property.setType(type.getValue());
}
- final Attribute relationship = start.getAttributeByName(new QName("Relationship"));
- if (relationship != null) {
- property.setReleationship(relationship.getValue());
- }
-
- final Attribute toRole = start.getAttributeByName(new QName("ToRole"));
- if (toRole != null) {
- property.setToRole(toRole.getValue());
- }
-
return property;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c7aa842f/fit/src/main/java/org/apache/olingo/fit/metadata/NavigationProperty.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/metadata/NavigationProperty.java b/fit/src/main/java/org/apache/olingo/fit/metadata/NavigationProperty.java
index 0e27dc1..e0cf627 100644
--- a/fit/src/main/java/org/apache/olingo/fit/metadata/NavigationProperty.java
+++ b/fit/src/main/java/org/apache/olingo/fit/metadata/NavigationProperty.java
@@ -21,19 +21,8 @@ package org.apache.olingo.fit.metadata;
public class NavigationProperty extends AbstractMetadataElement {
private final String name;
-
- // -----------------------
- // just for v3
- // -----------------------
- private String releationship;
-
- private String toRole;
- // -----------------------
-
private String type;
-
private String target;
-
private boolean entitySet;
public NavigationProperty(final String name) {
@@ -44,22 +33,6 @@ public class NavigationProperty extends AbstractMetadataElement {
return name;
}
- public String getReleationship() {
- return releationship;
- }
-
- public void setReleationship(final String releationship) {
- this.releationship = releationship;
- }
-
- public String getToRole() {
- return toRole;
- }
-
- public void setToRole(final String toRole) {
- this.toRole = toRole;
- }
-
public String getType() {
return type;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c7aa842f/fit/src/main/java/org/apache/olingo/fit/metadata/Schema.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/metadata/Schema.java b/fit/src/main/java/org/apache/olingo/fit/metadata/Schema.java
index 9a23f40..368894f 100644
--- a/fit/src/main/java/org/apache/olingo/fit/metadata/Schema.java
+++ b/fit/src/main/java/org/apache/olingo/fit/metadata/Schema.java
@@ -25,18 +25,13 @@ import java.util.Map;
public class Schema extends AbstractMetadataElement {
private final String namespace;
-
private final Map<String, Container> containers;
-
- private final Map<String, Association> associations;
-
private final Map<String, EntityType> entityTypes;
public Schema(final String namespace) {
this.namespace = namespace;
entityTypes = new HashMap<String, EntityType>();
containers = new HashMap<String, Container>();
- associations = new HashMap<String, Association>();
}
public String getNamespace() {
@@ -68,13 +63,4 @@ public class Schema extends AbstractMetadataElement {
containers.put(name, container);
return this;
}
-
- public Association getAssociation(final String name) {
- return associations.get(name);
- }
-
- public Schema addAssociation(final String name, final Association association) {
- associations.put(name, association);
- return this;
- }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c7aa842f/fit/src/main/java/org/apache/olingo/fit/methods/MERGE.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/methods/MERGE.java b/fit/src/main/java/org/apache/olingo/fit/methods/MERGE.java
deleted file mode 100644
index 8115826..0000000
--- a/fit/src/main/java/org/apache/olingo/fit/methods/MERGE.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.fit.methods;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import javax.ws.rs.HttpMethod;
-
-@Target({ ElementType.METHOD })
-@Retention(RetentionPolicy.RUNTIME)
-@HttpMethod("MERGE")
-public @interface MERGE {
- // No additional methods needed for now.
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c7aa842f/fit/src/main/java/org/apache/olingo/fit/utils/Constants.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/Constants.java b/fit/src/main/java/org/apache/olingo/fit/utils/Constants.java
index c2eaa7d..d0915a4 100644
--- a/fit/src/main/java/org/apache/olingo/fit/utils/Constants.java
+++ b/fit/src/main/java/org/apache/olingo/fit/utils/Constants.java
@@ -26,52 +26,35 @@ import java.util.Map;
public class Constants {
- private final static Map<ConstantKey, String> v4constants = new EnumMap<ConstantKey, String>(ConstantKey.class);
-
- private final static Map<ConstantKey, String> constants = new EnumMap<ConstantKey, String>(ConstantKey.class);
+ private static Map<ConstantKey, String> constants = new EnumMap<ConstantKey, String>(ConstantKey.class);
/**
* CR/LF.
*/
public static final byte[] CRLF = { 13, 10 };
-
public static final Charset ENCODING = Charset.forName("UTF-8");
-
public static final CharsetDecoder DECODER = ENCODING.newDecoder();
static {
DECODER.onMalformedInput(CodingErrorAction.IGNORE);
DECODER.onUnmappableCharacter(CodingErrorAction.IGNORE);
- // -----------------------------
- // V4 only
- // -----------------------------
- v4constants.put(ConstantKey.JSON_ID_NAME, "@odata.id");
- v4constants.put(ConstantKey.JSON_TYPE_NAME, "@odata.type");
- v4constants.put(ConstantKey.JSON_NAVIGATION_SUFFIX, "@odata.navigationLink");
- v4constants.put(ConstantKey.JSON_EDITLINK_NAME, "@odata.editLink");
- v4constants.put(ConstantKey.DATASERVICES_NS, "http://docs.oasis-open.org/odata/ns/dataservices");
- v4constants.put(ConstantKey.METADATA_NS, "http://docs.oasis-open.org/odata/ns/metadata");
- v4constants.put(ConstantKey.GEORSS_NS, "http://www.georss.org/georss");
- v4constants.put(ConstantKey.GML_NS, "http://www.opengis.net/gml");
- v4constants.put(ConstantKey.EDM_NS, "http://docs.oasis-open.org/odata/ns/edm");
- v4constants.put(ConstantKey.ATOM_LINK_REL, "http://docs.oasis-open.org/odata/ns/related/");
- v4constants.put(ConstantKey.ODATA_SERVICE_VERSION, "OData-Version");
- v4constants.put(ConstantKey.DEFAULT_SERVICE_URL, "http://localhost:9080/stub/StaticService/V40/Static.svc/");
- v4constants.put(ConstantKey.ODATA_METADATA_PREFIX,
+ constants.put(ConstantKey.JSON_ID_NAME, "@odata.id");
+ constants.put(ConstantKey.JSON_TYPE_NAME, "@odata.type");
+ constants.put(ConstantKey.JSON_NAVIGATION_SUFFIX, "@odata.navigationLink");
+ constants.put(ConstantKey.JSON_EDITLINK_NAME, "@odata.editLink");
+ constants.put(ConstantKey.DATASERVICES_NS, "http://docs.oasis-open.org/odata/ns/dataservices");
+ constants.put(ConstantKey.METADATA_NS, "http://docs.oasis-open.org/odata/ns/metadata");
+ constants.put(ConstantKey.GEORSS_NS, "http://www.georss.org/georss");
+ constants.put(ConstantKey.GML_NS, "http://www.opengis.net/gml");
+ constants.put(ConstantKey.EDM_NS, "http://docs.oasis-open.org/odata/ns/edm");
+ constants.put(ConstantKey.ATOM_LINK_REL, "http://docs.oasis-open.org/odata/ns/related/");
+ constants.put(ConstantKey.ODATA_SERVICE_VERSION, "OData-Version");
+ constants.put(ConstantKey.DEFAULT_SERVICE_URL, "http://localhost:9080/stub/StaticService/V40/Static.svc/");
+ constants.put(ConstantKey.ODATA_METADATA_PREFIX,
"http://localhost:9080/stub/StaticService/V40/Static.svc/$metadata#");
- v4constants.put(ConstantKey.ODATA_METADATA_ENTITY_SUFFIX, "/$entity");
- // -----------------------------
-
- // -----------------------------
- // V3 and defaults
- // -----------------------------
- constants.put(ConstantKey.ODATA_SERVICE_VERSION, "DataServiceVersion");
- constants.put(ConstantKey.DEFAULT_SERVICE_URL, "http://localhost:9080/stub/StaticService/V30/Static.svc/");
+ constants.put(ConstantKey.ODATA_METADATA_ENTITY_SUFFIX, "/$entity");
constants.put(ConstantKey.ODATA_COUNT_NAME, "odata.count");
- constants.put(ConstantKey.ODATA_METADATA_PREFIX,
- "http://localhost:9080/stub/StaticService/V30/Static.svc/$metadata#");
- constants.put(ConstantKey.ODATA_METADATA_ENTITY_SUFFIX, "/@Element");
constants.put(ConstantKey.ATOM_DEF_TYPE, "Edm.String");
constants.put(ConstantKey.ATOM_PROPERTY_PREFIX, "d:");
constants.put(ConstantKey.ATOM_METADATA_PREFIX, "m:");
@@ -79,7 +62,6 @@ public class Constants {
constants.put(ConstantKey.ATOM_DATASERVICE_NS, "xmlns:d");
constants.put(ConstantKey.ATOM_LINK_ENTRY, "application/atom+xml;type=entry");
constants.put(ConstantKey.ATOM_LINK_FEED, "application/atom+xml;type=feed");
- constants.put(ConstantKey.ATOM_LINK_REL, "http://schemas.microsoft.com/ado/2007/08/dataservices/related/");
constants.put(ConstantKey.TYPE, "m:type");
constants.put(ConstantKey.INLINE_LOCAL, "inline");
constants.put(ConstantKey.INLINE_FILE_PATH, "inline");
@@ -88,11 +70,6 @@ public class Constants {
constants.put(ConstantKey.CONTENT, "content");
constants.put(ConstantKey.PROPERTIES, "m:properties");
constants.put(ConstantKey.LINK, "link");
- constants.put(ConstantKey.METADATA_NS, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadta");
- constants.put(ConstantKey.DATASERVICES_NS, "http://schemas.microsoft.com/ado/2007/08/dataservices");
- constants.put(ConstantKey.GEORSS_NS, "http://www.georss.org/georss");
- constants.put(ConstantKey.GML_NS, "http://www.opengis.net/gml");
- constants.put(ConstantKey.EDM_NS, "http://schemas.microsoft.com/ado/2009/11/edm");
constants.put(ConstantKey.METADATA, "metadata");
constants.put(ConstantKey.SERVICES, "services");
constants.put(ConstantKey.FEED, "feed");
@@ -107,17 +84,12 @@ public class Constants {
constants.put(ConstantKey.JSON_NEXTLINK_SUFFIX, "@odata.nextLink");
constants.put(ConstantKey.JSON_ODATAMETADATA_NAME, "odata.metadata");
constants.put(ConstantKey.JSON_NAVIGATION_BIND_SUFFIX, "@odata.bind");
- constants.put(ConstantKey.JSON_NAVIGATION_SUFFIX, "@odata.navigationLinkUrl");
constants.put(ConstantKey.JSON_MEDIA_SUFFIX, "@odata.mediaEditLink");
- constants.put(ConstantKey.JSON_TYPE_NAME, "odata.type");
constants.put(ConstantKey.JSON_TYPE_SUFFIX, "@odata.type");
- constants.put(ConstantKey.JSON_ID_NAME, "odata.id");
- constants.put(ConstantKey.JSON_EDITLINK_NAME, "odata.editLink");
constants.put(ConstantKey.XHTTP_HEADER_NAME, "X-HTTP-METHOD");
- // -----------------------------
}
public static String get(final ConstantKey key) {
- return (!v4constants.containsKey(key) ? constants : v4constants).get(key);
+ return constants.get(key);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c7aa842f/fit/src/test/java/org/apache/olingo/fit/base/EntityUpdateTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/base/EntityUpdateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/base/EntityUpdateTestITCase.java
index aa2bc06..d1abb08 100644
--- a/fit/src/test/java/org/apache/olingo/fit/base/EntityUpdateTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/base/EntityUpdateTestITCase.java
@@ -79,7 +79,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
@Test
@Ignore
- public void testUpateSingleValuedNavtiogationReference() throws Exception {
+ public void updateSingleValuedNavigationReference() throws Exception {
URI targetURI =
getClient().newURIBuilder(testStaticServiceRootURL)
.appendEntitySetSegment("People")
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c7aa842f/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/annotation/EdmConstantExpression.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/annotation/EdmConstantExpression.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/annotation/EdmConstantExpression.java
index 7c9c69d..3541a3d 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/annotation/EdmConstantExpression.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/annotation/EdmConstantExpression.java
@@ -36,25 +36,25 @@ public interface EdmConstantExpression extends EdmExpression {
Object asPrimitive();
/**
- * A list of enum members or empty list if this expression is of type primitve or geospatial.
+ * A list of enum members or empty list if this expression is of type primitive or geospatial.
* @return a list of all enum members or empty list
*/
List<String> asEnumMembers();
/**
- * Return the Enum type name or null if this expression is of type primitve or geospatial.
+ * Return the Enum type name or null if this expression is of type primitive or geospatial.
* @return enum type name or null
*/
String getEnumTypeName();
/**
- * Return the geospatial object or null if this expression is of type primitve or enum.
+ * Return the geospatial object or null if this expression is of type primitive or enum.
* @return geospatial object or null
*/
Geospatial asGeospatial();
/**
- * Returns the value of the expression as String
+ * Returns the value of the expression as String.
* @return String representation of the expression
*/
String getValueAsString();
[3/3] olingo-odata4 git commit: [OLINGO-???] less use of reflection
in equals() and hashCode()
Posted by ch...@apache.org.
[OLINGO-???] less use of reflection in equals() and hashCode()
Signed-off-by: Christian Amend <ch...@sap.com>
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/26f7d2a6
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/26f7d2a6
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/26f7d2a6
Branch: refs/heads/master
Commit: 26f7d2a6b1ddf295d0133d78022b87391c98f48d
Parents: a283bdd
Author: Klaus Straubinger <kl...@sap.com>
Authored: Fri Jan 15 16:08:27 2016 +0100
Committer: Christian Amend <ch...@sap.com>
Committed: Mon Jan 18 13:36:52 2016 +0100
----------------------------------------------------------------------
.../commons/api/edm/FullQualifiedName.java | 19 ++----
.../commons/api/edm/geo/ComposedGeospatial.java | 32 ++++++++-
.../olingo/commons/api/edm/geo/Geospatial.java | 31 ++-------
.../api/edm/geo/GeospatialCollection.java | 10 ++-
.../olingo/commons/api/edm/geo/LineString.java | 8 +--
.../commons/api/edm/geo/MultiLineString.java | 8 +--
.../olingo/commons/api/edm/geo/MultiPoint.java | 8 +--
.../commons/api/edm/geo/MultiPolygon.java | 8 +--
.../olingo/commons/api/edm/geo/Point.java | 72 ++++++++++++++------
.../olingo/commons/api/edm/geo/Polygon.java | 38 ++++++++---
.../apache/olingo/commons/api/edm/geo/SRID.java | 49 +++++--------
11 files changed, 150 insertions(+), 133 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/26f7d2a6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/FullQualifiedName.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/FullQualifiedName.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/FullQualifiedName.java
index 9f83d42..de0325e 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/FullQualifiedName.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/FullQualifiedName.java
@@ -28,7 +28,6 @@ public final class FullQualifiedName implements Serializable {
private static final long serialVersionUID = -4063629050858999076L;
private final String namespace;
-
private final String name;
private final String fqn;
@@ -90,24 +89,14 @@ public final class FullQualifiedName implements Serializable {
return false;
}
- FullQualifiedName that = (FullQualifiedName) o;
-
- if (namespace != null ? !namespace.equals(that.namespace) : that.namespace != null) {
- return false;
- }
- if (name != null ? !name.equals(that.name) : that.name != null) {
- return false;
- }
- return !(fqn != null ? !fqn.equals(that.fqn) : that.fqn != null);
-
+ final FullQualifiedName that = (FullQualifiedName) o;
+ return (namespace == null ? that.namespace == null : namespace.equals(that.namespace))
+ && (name == null ? that.name == null : name.equals(that.name));
}
@Override
public int hashCode() {
- int result = namespace != null ? namespace.hashCode() : 0;
- result = 31 * result + (name != null ? name.hashCode() : 0);
- result = 31 * result + (fqn != null ? fqn.hashCode() : 0);
- return result;
+ return fqn == null ? 0 : fqn.hashCode();
}
@Override
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/26f7d2a6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/ComposedGeospatial.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/ComposedGeospatial.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/ComposedGeospatial.java
index f7e9f3d..0120a78 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/ComposedGeospatial.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/ComposedGeospatial.java
@@ -22,15 +22,13 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
- /**
+/**
* Abstract base class for all Geometries that are composed out of other geospatial elements.
*
* @param <T> Type of the contained geospatial elements
*/
public abstract class ComposedGeospatial<T extends Geospatial> extends Geospatial implements Iterable<T> {
- private static final long serialVersionUID = 8796254901098541307L;
-
protected final List<T> geospatials;
protected ComposedGeospatial(final Dimension dimension, final Type type, final SRID srid,
@@ -56,4 +54,32 @@ public abstract class ComposedGeospatial<T extends Geospatial> extends Geospatia
public boolean isEmpty() {
return geospatials.isEmpty();
}
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ final ComposedGeospatial<?> other = (ComposedGeospatial<?>) o;
+ return dimension == other.dimension
+ && (srid == null ? other.srid == null : srid.equals(other.srid))
+ && geospatials.equals(other.geospatials);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = dimension == null ? 0 : dimension.hashCode();
+ result = 31 * result + (srid == null ? 0 : srid.hashCode());
+ result = 31 * result + geospatials.hashCode();
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return geospatials.toString();
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/26f7d2a6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/Geospatial.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/Geospatial.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/Geospatial.java
index 539196c..63d8b3f 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/Geospatial.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/Geospatial.java
@@ -18,21 +18,13 @@
*/
package org.apache.olingo.commons.api.edm.geo;
-import java.io.Serializable;
-
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
/**
* Base class for all geospatial info.
*/
-public abstract class Geospatial implements Serializable {
+public abstract class Geospatial {
- private static final long serialVersionUID = 5409612902190067390L;
-
/**
* Dimension of the geospatial type
*/
@@ -46,7 +38,7 @@ public abstract class Geospatial implements Serializable {
*/
GEOGRAPHY
}
-
+
/**
* Type of the geospatial type
*/
@@ -122,7 +114,7 @@ public abstract class Geospatial implements Serializable {
* @return type.
* @see Type
*/
- public Type getType() {
+ public Type getGeoType() {
return type;
}
@@ -134,25 +126,10 @@ public abstract class Geospatial implements Serializable {
public SRID getSrid() {
return srid;
}
-
+
/**
* Returns the {@link EdmPrimitiveTypeKind}
* @return Edm primitve type kind
*/
public abstract EdmPrimitiveTypeKind getEdmPrimitiveTypeKind();
-
- @Override
- public boolean equals(final Object obj) {
- return EqualsBuilder.reflectionEquals(this, obj);
- }
-
- @Override
- public int hashCode() {
- return HashCodeBuilder.reflectionHashCode(this);
- }
-
- @Override
- public String toString() {
- return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
- }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/26f7d2a6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/GeospatialCollection.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/GeospatialCollection.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/GeospatialCollection.java
index e46aea2..4ac4a27 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/GeospatialCollection.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/GeospatialCollection.java
@@ -27,10 +27,8 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
*/
public class GeospatialCollection extends ComposedGeospatial<Geospatial> {
- private static final long serialVersionUID = -9181547636133878977L;
-
/**
- * Creates a new collection of geospatial types
+ * Creates a new collection of geospatial types.
* @param dimension Dimension of the collection
* @param srid SRID Value
* @param geospatials Members of the collection
@@ -41,8 +39,8 @@ public class GeospatialCollection extends ComposedGeospatial<Geospatial> {
@Override
public EdmPrimitiveTypeKind getEdmPrimitiveTypeKind() {
- return dimension == Dimension.GEOGRAPHY
- ? EdmPrimitiveTypeKind.GeographyCollection
- : EdmPrimitiveTypeKind.GeometryCollection;
+ return dimension == Dimension.GEOGRAPHY ?
+ EdmPrimitiveTypeKind.GeographyCollection :
+ EdmPrimitiveTypeKind.GeometryCollection;
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/26f7d2a6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/LineString.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/LineString.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/LineString.java
index af2e13e..38e4573 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/LineString.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/LineString.java
@@ -28,8 +28,6 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
*/
public class LineString extends ComposedGeospatial<Point> {
- private static final long serialVersionUID = 3207958185407535907L;
-
/**
* Creates a new LineString
* @param dimension Dimension of the LineString
@@ -42,8 +40,8 @@ public class LineString extends ComposedGeospatial<Point> {
@Override
public EdmPrimitiveTypeKind getEdmPrimitiveTypeKind() {
- return dimension == Dimension.GEOGRAPHY
- ? EdmPrimitiveTypeKind.GeographyLineString
- : EdmPrimitiveTypeKind.GeometryLineString;
+ return dimension == Dimension.GEOGRAPHY ?
+ EdmPrimitiveTypeKind.GeographyLineString :
+ EdmPrimitiveTypeKind.GeometryLineString;
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/26f7d2a6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/MultiLineString.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/MultiLineString.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/MultiLineString.java
index f8796b6..6bd88b2 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/MultiLineString.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/MultiLineString.java
@@ -28,8 +28,6 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
*/
public class MultiLineString extends ComposedGeospatial<LineString> {
- private static final long serialVersionUID = -5042414471218124125L;
-
/**
* Creates a new MultiLineString
*
@@ -43,9 +41,9 @@ public class MultiLineString extends ComposedGeospatial<LineString> {
@Override
public EdmPrimitiveTypeKind getEdmPrimitiveTypeKind() {
- return dimension == Dimension.GEOGRAPHY
- ? EdmPrimitiveTypeKind.GeographyMultiLineString
- : EdmPrimitiveTypeKind.GeometryMultiLineString;
+ return dimension == Dimension.GEOGRAPHY ?
+ EdmPrimitiveTypeKind.GeographyMultiLineString :
+ EdmPrimitiveTypeKind.GeometryMultiLineString;
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/26f7d2a6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/MultiPoint.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/MultiPoint.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/MultiPoint.java
index 8a38a73..8d23dcc 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/MultiPoint.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/MultiPoint.java
@@ -28,8 +28,6 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
*/
public class MultiPoint extends ComposedGeospatial<Point> {
- private static final long serialVersionUID = 4951011255142116129L;
-
/**
* Creates a new collection of points
* @param dimension Dimension of the points
@@ -42,9 +40,9 @@ public class MultiPoint extends ComposedGeospatial<Point> {
@Override
public EdmPrimitiveTypeKind getEdmPrimitiveTypeKind() {
- return dimension == Dimension.GEOGRAPHY
- ? EdmPrimitiveTypeKind.GeographyMultiPoint
- : EdmPrimitiveTypeKind.GeometryMultiPoint;
+ return dimension == Dimension.GEOGRAPHY ?
+ EdmPrimitiveTypeKind.GeographyMultiPoint :
+ EdmPrimitiveTypeKind.GeometryMultiPoint;
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/26f7d2a6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/MultiPolygon.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/MultiPolygon.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/MultiPolygon.java
index d39c3a1..8fae3d7 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/MultiPolygon.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/MultiPolygon.java
@@ -28,8 +28,6 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
*/
public class MultiPolygon extends ComposedGeospatial<Polygon> {
- private static final long serialVersionUID = -160184788048512883L;
-
/**
* Creates a collection of polygons
*
@@ -43,8 +41,8 @@ public class MultiPolygon extends ComposedGeospatial<Polygon> {
@Override
public EdmPrimitiveTypeKind getEdmPrimitiveTypeKind() {
- return dimension == Dimension.GEOGRAPHY
- ? EdmPrimitiveTypeKind.GeographyMultiPolygon
- : EdmPrimitiveTypeKind.GeometryMultiPolygon;
+ return dimension == Dimension.GEOGRAPHY ?
+ EdmPrimitiveTypeKind.GeographyMultiPolygon :
+ EdmPrimitiveTypeKind.GeometryMultiPolygon;
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/26f7d2a6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/Point.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/Point.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/Point.java
index 0a79622..fa0ff9e 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/Point.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/Point.java
@@ -21,15 +21,11 @@ package org.apache.olingo.commons.api.edm.geo;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
/**
- * Represents a point
- *
- * Either Edm.GeographyPoint or Edm.GeometryPoint
+ * Represents a point, either Edm.GeographyPoint or Edm.GeometryPoint.
*
*/
public class Point extends Geospatial {
- private static final long serialVersionUID = 4917380107331557828L;
-
/**
* The X coordinate of the point. In most long/lat systems, this is the longitude.
*/
@@ -47,41 +43,40 @@ public class Point extends Geospatial {
private double z;
/**
- * Creates a new point
- *
+ * Creates a new point.
* @param dimension Dimension of the point
* @param srid SRID value
*/
public Point(final Dimension dimension, final SRID srid) {
super(dimension, Type.POINT, srid);
}
-
+
/**
- * Returns the x coordinate
+ * Returns the x coordinate.
* @return x coordinate
*/
public double getX() {
return x;
}
-
+
/**
- * Sets the x coordinate
+ * Sets the x coordinate.
* @param x x coordinate
*/
public void setX(final double x) {
this.x = x;
}
-
+
/**
- * Returns the y coordinate
+ * Returns the y coordinate.
* @return y coordinate
*/
public double getY() {
return y;
}
-
+
/**
- * Sets the y coordinate
+ * Sets the y coordinate.
* @param y y coordinate
*/
public void setY(final double y) {
@@ -89,15 +84,15 @@ public class Point extends Geospatial {
}
/**
- * Returns the z coordinate
+ * Returns the z coordinate.
* @return z coordinate
*/
public double getZ() {
return z;
}
-
+
/**
- * Sets the z coordinate
+ * Sets the z coordinate.
* @param z z coordinate
*/
public void setZ(final double z) {
@@ -106,8 +101,43 @@ public class Point extends Geospatial {
@Override
public EdmPrimitiveTypeKind getEdmPrimitiveTypeKind() {
- return dimension == Dimension.GEOGRAPHY
- ? EdmPrimitiveTypeKind.GeographyPoint
- : EdmPrimitiveTypeKind.GeometryPoint;
+ return dimension == Dimension.GEOGRAPHY ?
+ EdmPrimitiveTypeKind.GeographyPoint :
+ EdmPrimitiveTypeKind.GeometryPoint;
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ final Point point = (Point) o;
+ return dimension == point.dimension
+ && (srid == null ? point.srid == null : srid.equals(point.srid))
+ && x == point.x
+ && y == point.y
+ && z == point.z;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = dimension == null ? 0 : dimension.hashCode();
+ result = 31 * result + (srid == null ? 0 : srid.hashCode());
+ result = 31 * result + Double.valueOf(x).hashCode();
+ result = 31 * result + Double.valueOf(y).hashCode();
+ result = 31 * result + Double.valueOf(z).hashCode();
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return (dimension == null ? "" : dimension.name())
+ + '\''
+ + (srid == null ? "" : "SRID=" + srid.toString() + ';')
+ + "Point(" + x + ' ' + y + ")'";
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/26f7d2a6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/Polygon.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/Polygon.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/Polygon.java
index c59d73f..7ac4681 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/Polygon.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/Polygon.java
@@ -27,14 +27,11 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
*/
public class Polygon extends Geospatial {
- private static final long serialVersionUID = 7797602503445391678L;
-
final ComposedGeospatial<Point> interior;
-
final ComposedGeospatial<Point> exterior;
-
+
/**
- * Creates a new polygon
+ * Creates a new polygon.
*
* @param dimension Dimension of the polygon
* @param srid SRID values
@@ -69,8 +66,33 @@ public class Polygon extends Geospatial {
@Override
public EdmPrimitiveTypeKind getEdmPrimitiveTypeKind() {
- return dimension == Dimension.GEOGRAPHY
- ? EdmPrimitiveTypeKind.GeographyPolygon
- : EdmPrimitiveTypeKind.GeometryPolygon;
+ return dimension == Dimension.GEOGRAPHY ?
+ EdmPrimitiveTypeKind.GeographyPolygon :
+ EdmPrimitiveTypeKind.GeometryPolygon;
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ final Polygon polygon = (Polygon) o;
+ return dimension == polygon.dimension
+ && (srid == null ? polygon.srid == null : srid.equals(polygon.srid))
+ && (interior == null ? polygon.interior == null : interior.equals(polygon.interior))
+ && (exterior == null ? polygon.exterior == null : exterior.equals(polygon.exterior));
+ }
+
+ @Override
+ public int hashCode() {
+ int result = dimension == null ? 0 : dimension.hashCode();
+ result = 31 * result + (srid == null ? 0 : srid.hashCode());
+ result = 31 * result + (interior == null ? 0 : interior.hashCode());
+ result = 31 * result + (exterior == null ? 0 : exterior.hashCode());
+ return result;
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/26f7d2a6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/SRID.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/SRID.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/SRID.java
index 1b1a1b0..0f28772 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/SRID.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/geo/SRID.java
@@ -18,10 +18,10 @@
*/
package org.apache.olingo.commons.api.edm.geo;
-import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
-
import java.io.Serializable;
+import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
+
/**
* A geometry or geography property MAY define a value for the SRID attribute. The value of this attribute identifies
* which spatial reference system is applied to values of the property on type instances.
@@ -29,23 +29,22 @@ import java.io.Serializable;
* The value of the SRID attribute MUST be a non-negative integer or the special value <tt>variable</tt>. If no value is
* specified, the attribute defaults to 0 for Geometry types or 4326 for Geography types.
* <br/>
- * Standards Track Work Product Copyright © OASIS Open 2013. All Rights Reserved. 19 November 2013 Page 22 of 83The
- * valid values of the SRID attribute and their meanings are as defined by the European Petroleum Survey Group [EPSG].
+ * Standards Track Work Product Copyright © OASIS Open 2013. All Rights Reserved. 19 November 2013
+ * <br>
+ * The valid values of the SRID attribute and their meanings are as defined by the
+ * European Petroleum Survey Group [EPSG].
*/
public final class SRID implements Serializable {
- private static final String VARIABLE = "variable";
-
private static final long serialVersionUID = 8412685060902464629L;
+ private static final String VARIABLE = "variable";
private Dimension dimension = Dimension.GEOGRAPHY;
-
private Integer value;
-
private Boolean variable;
/**
- * Creates a new SRID instance from a given
+ * Creates a new SRID instance from a given value.
* @param exp Either "variable" or a numeric non-negative SRID value
* @return SRID instance
*/
@@ -70,15 +69,15 @@ public final class SRID implements Serializable {
}
/**
- * Returns the dimension of the SRID instance
+ * Returns the dimension of the SRID instance.
* @return dimension of the SRID instance
*/
public Dimension getDimension() {
return dimension;
}
-
+
/**
- * Sets the dimension of the SRID instance
+ * Sets the dimension of the SRID instance.
* @param dimension dimension of the SRID instance
*/
public void setDimension(final Dimension dimension) {
@@ -86,27 +85,13 @@ public final class SRID implements Serializable {
}
private String getValue() {
- if (value == null) {
- if (dimension == Dimension.GEOMETRY) {
- return "0";
- } else {
- return "4326";
- }
- }
-
- return value.toString();
-// return value == null ? dimension == Dimension.GEOMETRY
-// ? "0"
-// : "4326"
-// : value.getName();
+ return value == null ?
+ dimension == Dimension.GEOMETRY ? "0" : "4326" :
+ value.toString();
}
- private boolean isVariable() {
- return variable != null && variable;
- }
-
/**
- * Returns true if the value of the instance is not equals to the default (uninitialized)
+ * Returns true if the value of the instance is not equals to the default (uninitialized).
* @return true if the value of the instance is not equals to the default (uninitialized)
*/
public boolean isNotDefault() {
@@ -144,8 +129,6 @@ public final class SRID implements Serializable {
@Override
public String toString() {
- return isVariable()
- ? VARIABLE
- : getValue();
+ return variable != null && variable ? VARIABLE : getValue();
}
}
[2/3] olingo-odata4 git commit: [OLINGO-834] parsing of most geo
literals in URI parser
Posted by ch...@apache.org.
[OLINGO-834] parsing of most geo literals in URI parser
Signed-off-by: Christian Amend <ch...@sap.com>
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/a283bddb
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/a283bddb
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/a283bddb
Branch: refs/heads/master
Commit: a283bddbbf1e6d16a7ec7926e183e367fd7ba544
Parents: c7aa842
Author: Klaus Straubinger <kl...@sap.com>
Authored: Fri Jan 15 16:10:32 2016 +0100
Committer: Christian Amend <ch...@sap.com>
Committed: Mon Jan 18 13:36:18 2016 +0100
----------------------------------------------------------------------
.../search/SearchUnaryOperatorKind.java | 2 +-
.../core/uri/parser/ExpressionParser.java | 22 +-
.../server/core/uri/parser/ParserHelper.java | 83 ++++++-
.../server/core/uri/parser/UriTokenizer.java | 244 +++++++++++++++++++
.../core/uri/parser/ExpressionParserTest.java | 19 +-
.../core/uri/parser/UriTokenizerTest.java | 64 +++++
.../core/uri/parser/TestUriParserImpl.java | 27 +-
7 files changed, 406 insertions(+), 55 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a283bddb/lib/server-api/src/main/java/org/apache/olingo/server/api/uri/queryoption/search/SearchUnaryOperatorKind.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/uri/queryoption/search/SearchUnaryOperatorKind.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/uri/queryoption/search/SearchUnaryOperatorKind.java
index bbc9ba6..f4122c7 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/uri/queryoption/search/SearchUnaryOperatorKind.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/uri/queryoption/search/SearchUnaryOperatorKind.java
@@ -22,6 +22,6 @@ public enum SearchUnaryOperatorKind {
NOT;
public static SearchUnaryOperatorKind get(final String operator) {
- return NOT.equals(operator) ? NOT : null;
+ return NOT.name().equals(operator) ? NOT : null;
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a283bddb/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ExpressionParser.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ExpressionParser.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ExpressionParser.java
index ef7d6da..8b28f6a 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ExpressionParser.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ExpressionParser.java
@@ -156,26 +156,6 @@ public class ExpressionParser {
tokenToMethod = Collections.unmodifiableMap(temp);
}
- private static final Map<TokenKind, EdmPrimitiveTypeKind> tokenToPrimitiveType;
- static {
- /* Enum and null are not present in the map. These have to be handled differently. */
- Map<TokenKind, EdmPrimitiveTypeKind> temp = new HashMap<TokenKind, EdmPrimitiveTypeKind>();
- temp.put(TokenKind.BooleanValue, EdmPrimitiveTypeKind.Boolean);
- temp.put(TokenKind.StringValue, EdmPrimitiveTypeKind.String);
- // TODO: Check if int64 is correct here or if it has to be decimal or single or double instead.
- temp.put(TokenKind.IntegerValue, EdmPrimitiveTypeKind.Int64);
- temp.put(TokenKind.GuidValue, EdmPrimitiveTypeKind.Guid);
- temp.put(TokenKind.DateValue, EdmPrimitiveTypeKind.Date);
- temp.put(TokenKind.DateTimeOffsetValue, EdmPrimitiveTypeKind.DateTimeOffset);
- temp.put(TokenKind.TimeOfDayValue, EdmPrimitiveTypeKind.TimeOfDay);
- temp.put(TokenKind.DecimalValue, EdmPrimitiveTypeKind.Decimal);
- temp.put(TokenKind.DoubleValue, EdmPrimitiveTypeKind.Double);
- temp.put(TokenKind.DurationValue, EdmPrimitiveTypeKind.Duration);
- temp.put(TokenKind.BinaryValue, EdmPrimitiveTypeKind.Binary);
-
- tokenToPrimitiveType = Collections.unmodifiableMap(temp);
- }
-
private final Edm edm;
private final OData odata;
@@ -408,7 +388,7 @@ public class ExpressionParser {
if (primitiveTokenKind == TokenKind.EnumValue) {
return createEnumExpression(primitiveValueLiteral);
} else {
- EdmPrimitiveTypeKind primitiveTypeKind = tokenToPrimitiveType.get(primitiveTokenKind);
+ EdmPrimitiveTypeKind primitiveTypeKind = ParserHelper.tokenToPrimitiveType.get(primitiveTokenKind);
if (primitiveTypeKind == EdmPrimitiveTypeKind.Int64) {
primitiveTypeKind = determineIntegerType(primitiveValueLiteral);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a283bddb/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ParserHelper.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ParserHelper.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ParserHelper.java
index 852c43a..0ac888f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ParserHelper.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ParserHelper.java
@@ -19,9 +19,11 @@
package org.apache.olingo.server.core.uri.parser;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEntityType;
@@ -50,6 +52,42 @@ public class ParserHelper {
private static final OData odata = new ODataImpl();
+ protected static final Map<TokenKind, EdmPrimitiveTypeKind> tokenToPrimitiveType;
+ static {
+ /* Enum and null are not present in the map. These have to be handled differently. */
+ Map<TokenKind, EdmPrimitiveTypeKind> temp = new HashMap<TokenKind, EdmPrimitiveTypeKind>();
+ temp.put(TokenKind.BooleanValue, EdmPrimitiveTypeKind.Boolean);
+ temp.put(TokenKind.StringValue, EdmPrimitiveTypeKind.String);
+ // TODO: Check if int64 is correct here or if it has to be decimal or single or double instead.
+ temp.put(TokenKind.IntegerValue, EdmPrimitiveTypeKind.Int64);
+ temp.put(TokenKind.GuidValue, EdmPrimitiveTypeKind.Guid);
+ temp.put(TokenKind.DateValue, EdmPrimitiveTypeKind.Date);
+ temp.put(TokenKind.DateTimeOffsetValue, EdmPrimitiveTypeKind.DateTimeOffset);
+ temp.put(TokenKind.TimeOfDayValue, EdmPrimitiveTypeKind.TimeOfDay);
+ temp.put(TokenKind.DecimalValue, EdmPrimitiveTypeKind.Decimal);
+ temp.put(TokenKind.DoubleValue, EdmPrimitiveTypeKind.Double);
+ temp.put(TokenKind.DurationValue, EdmPrimitiveTypeKind.Duration);
+ temp.put(TokenKind.BinaryValue, EdmPrimitiveTypeKind.Binary);
+
+ temp.put(TokenKind.GeographyPoint, EdmPrimitiveTypeKind.GeographyPoint);
+ temp.put(TokenKind.GeometryPoint, EdmPrimitiveTypeKind.GeometryPoint);
+ temp.put(TokenKind.GeographyLineString, EdmPrimitiveTypeKind.GeographyLineString);
+ temp.put(TokenKind.GeometryLineString, EdmPrimitiveTypeKind.GeometryLineString);
+ temp.put(TokenKind.GeographyPolygon, EdmPrimitiveTypeKind.GeographyPolygon);
+ temp.put(TokenKind.GeometryPolygon, EdmPrimitiveTypeKind.GeometryPolygon);
+ temp.put(TokenKind.GeographyMultiPoint, EdmPrimitiveTypeKind.GeographyMultiPoint);
+ temp.put(TokenKind.GeometryMultiPoint, EdmPrimitiveTypeKind.GeometryMultiPoint);
+ temp.put(TokenKind.GeographyMultiLineString, EdmPrimitiveTypeKind.GeographyMultiLineString);
+ temp.put(TokenKind.GeometryMultiLineString, EdmPrimitiveTypeKind.GeometryMultiLineString);
+ temp.put(TokenKind.GeographyMultiPolygon, EdmPrimitiveTypeKind.GeographyMultiPolygon);
+ temp.put(TokenKind.GeometryMultiPolygon, EdmPrimitiveTypeKind.GeometryMultiPolygon);
+ // TODO: Geo collections
+// temp.put(TokenKind.GeographyCollection, EdmPrimitiveTypeKind.GeographyCollection);
+// temp.put(TokenKind.GeometryCollection, EdmPrimitiveTypeKind.GeometryCollection);
+
+ tokenToPrimitiveType = Collections.unmodifiableMap(temp);
+ }
+
public static void requireNext(UriTokenizer tokenizer, final TokenKind required) throws UriParserException {
if (!tokenizer.next(required)) {
throw new UriParserSyntaxException("Expected token '" + required.toString() + "' not found.",
@@ -88,7 +126,25 @@ public class ParserHelper {
TokenKind.DurationValue,
TokenKind.BinaryValue,
- TokenKind.EnumValue);
+ TokenKind.EnumValue,
+
+ // Geography and geometry literals are defined to be primitive,
+ // although they contain several parts with their own meaning.
+ TokenKind.GeographyPoint,
+ TokenKind.GeometryPoint,
+ TokenKind.GeographyLineString,
+ TokenKind.GeometryLineString,
+ TokenKind.GeographyPolygon,
+ TokenKind.GeometryPolygon,
+ TokenKind.GeographyMultiPoint,
+ TokenKind.GeometryMultiPoint,
+ TokenKind.GeographyMultiLineString,
+ TokenKind.GeometryMultiLineString,
+ TokenKind.GeographyMultiPolygon,
+ TokenKind.GeometryMultiPolygon);
+ // TODO: Geo collections
+// TokenKind.GeographyCollection,
+// TokenKind.GeometryCollection);
}
protected static List<UriParameter> parseFunctionParameters(UriTokenizer tokenizer,
@@ -326,6 +382,7 @@ public class ParserHelper {
} else if (nullable && tokenizer.next(TokenKind.NULL)) {
return true;
+ // Special handling for frequently-used types and types with more than one token kind.
} else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean).equals(type)) {
return tokenizer.next(TokenKind.BooleanValue);
} else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String).equals(type)) {
@@ -338,31 +395,33 @@ public class ParserHelper {
return tokenizer.next(TokenKind.IntegerValue);
} else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Guid).equals(type)) {
return tokenizer.next(TokenKind.GuidValue);
- } else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Date).equals(type)) {
- return tokenizer.next(TokenKind.DateValue);
- } else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.DateTimeOffset).equals(type)) {
- return tokenizer.next(TokenKind.DateTimeOffsetValue);
- } else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.TimeOfDay).equals(type)) {
- return tokenizer.next(TokenKind.TimeOfDayValue);
} else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Decimal).equals(type)) {
// The order is important.
// A decimal value should not be parsed as integer and let the tokenizer stop at the decimal point.
return tokenizer.next(TokenKind.DecimalValue)
|| tokenizer.next(TokenKind.IntegerValue);
- } else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Double).equals(type)) {
+ } else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Double).equals(type)
+ || odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Single).equals(type)) {
// The order is important.
// A floating-point value should not be parsed as decimal and let the tokenizer stop at 'E'.
// A decimal value should not be parsed as integer and let the tokenizer stop at the decimal point.
return tokenizer.next(TokenKind.DoubleValue)
|| tokenizer.next(TokenKind.DecimalValue)
|| tokenizer.next(TokenKind.IntegerValue);
- } else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Duration).equals(type)) {
- return tokenizer.next(TokenKind.DurationValue);
- } else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Binary).equals(type)) {
- return tokenizer.next(TokenKind.BinaryValue);
} else if (type.getKind() == EdmTypeKind.ENUM) {
return tokenizer.next(TokenKind.EnumValue);
} else {
+ // Check the types that have not been checked already above.
+ for (final Entry<TokenKind, EdmPrimitiveTypeKind> entry : tokenToPrimitiveType.entrySet()) {
+ final EdmPrimitiveTypeKind kind = entry.getValue();
+ if ((kind == EdmPrimitiveTypeKind.Date || kind == EdmPrimitiveTypeKind.DateTimeOffset
+ || kind == EdmPrimitiveTypeKind.TimeOfDay || kind == EdmPrimitiveTypeKind.Duration
+ || kind == EdmPrimitiveTypeKind.Binary
+ || kind.isGeospatial())
+ && odata.createPrimitiveTypeInstance(kind).equals(type)) {
+ return tokenizer.next(entry.getKey());
+ }
+ }
return false;
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a283bddb/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriTokenizer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriTokenizer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriTokenizer.java
index 3b673a6..5a48cc1 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriTokenizer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriTokenizer.java
@@ -84,6 +84,19 @@ public class UriTokenizer {
BinaryValue,
EnumValue,
+ GeographyPoint,
+ GeometryPoint,
+ GeographyLineString,
+ GeometryLineString,
+ GeographyPolygon,
+ GeometryPolygon,
+ GeographyMultiPoint,
+ GeometryMultiPoint,
+ GeographyMultiLineString,
+ GeometryMultiLineString,
+ GeographyMultiPolygon,
+ GeometryMultiPolygon,
+
jsonArrayOrObject,
Word,
@@ -322,6 +335,44 @@ public class UriTokenizer {
found = nextEnumValue();
break;
+ // Geo Values
+ case GeographyPoint:
+ found = nextGeoPoint(true);
+ break;
+ case GeometryPoint:
+ found = nextGeoPoint(false);
+ break;
+ case GeographyLineString:
+ found = nextGeoLineString(true);
+ break;
+ case GeometryLineString:
+ found = nextGeoLineString(false);
+ break;
+ case GeographyPolygon:
+ found = nextGeoPolygon(true);
+ break;
+ case GeometryPolygon:
+ found = nextGeoPolygon(false);
+ break;
+ case GeographyMultiPoint:
+ found = nextGeoMultiPoint(true);
+ break;
+ case GeometryMultiPoint:
+ found = nextGeoMultiPoint(false);
+ break;
+ case GeographyMultiLineString:
+ found = nextGeoMultiLineString(true);
+ break;
+ case GeometryMultiLineString:
+ found = nextGeoMultiLineString(false);
+ break;
+ case GeographyMultiPolygon:
+ found = nextGeoMultiPolygon(true);
+ break;
+ case GeometryMultiPolygon:
+ found = nextGeoMultiPolygon(false);
+ break;
+
// Complex or Collection Value
case jsonArrayOrObject:
found = nextJsonArrayOrObject();
@@ -950,6 +1001,199 @@ public class UriTokenizer {
}
/**
+ * Moves past a geo prefix if found; otherwise leaves the index unchanged.
+ * @return whether a geo prefix has been found at the current index
+ */
+ private boolean nextGeoPrefix(final boolean isGeography) {
+ return nextConstantIgnoreCase(isGeography ? "geography" : "geometry");
+ }
+
+ /**
+ * Moves past an SRID if found; otherwise leaves the index unchanged.
+ * @return whether an SRID has been found at the current index
+ */
+ private boolean nextSrid() {
+ final int lastGoodIndex = index;
+ if (nextConstantIgnoreCase("SRID") && nextCharacter('=') && nextDigit()) {
+ // The digit checked above is mandatory, four more digits are optional.
+ nextDigit();
+ nextDigit();
+ nextDigit();
+ nextDigit();
+ return true;
+ } else {
+ index = lastGoodIndex;
+ return false;
+ }
+ }
+
+ /**
+ * Moves past a geo position if found; otherwise leaves the index unchanged.
+ * @return whether a geo position has been found at the current index
+ */
+ private boolean nextPosition() {
+ final int lastGoodIndex = index;
+ if ((nextDoubleValue() || nextDecimalValue() || nextIntegerValue(true))
+ && nextCharacter(' ')
+ && (nextDoubleValue() || nextDecimalValue() || nextIntegerValue(true))) {
+ return true;
+ } else {
+ index = lastGoodIndex;
+ return false;
+ }
+ }
+
+ /**
+ * Moves past a geo-point data instance if found; otherwise leaves the index unchanged.
+ * @return whether a geo-point data instance has been found at the current index
+ */
+ private boolean nextPointData() {
+ final int lastGoodIndex = index;
+ if (nextCharacter('(') && nextPosition() && nextCharacter(')')) {
+ return true;
+ } else {
+ index = lastGoodIndex;
+ return false;
+ }
+ }
+
+ private boolean nextGeoPoint(final boolean isGeography) {
+ return nextGeoPrefix(isGeography) && nextCharacter('\'')
+ && nextSrid() && nextCharacter(';')
+ && nextConstantIgnoreCase("Point") && nextPointData()
+ && nextCharacter('\'');
+ }
+
+ /**
+ * Moves past geo LineString data if found; otherwise leaves the index unchanged.
+ * @param isRing whether the line is a closed ring (in that case it must have at least four positions,
+ * and the last position must have the same coordinates as the first position)
+ * @return whether geo LineString data has been found at the current index
+ */
+ private boolean nextLineStringData(final boolean isRing) {
+ final int lastGoodIndex = index;
+ if (nextCharacter('(') && nextPosition()) {
+ int count = 1;
+ while (nextCharacter(',')) {
+ if (nextPosition()) {
+ count++;
+ } else {
+ index = lastGoodIndex;
+ return false;
+ }
+ }
+ // TODO: Check that the first and last ring positions are identical.
+ if (count < (isRing ? 4 : 2)) {
+ index = lastGoodIndex;
+ return false;
+ }
+ if (!nextCharacter(')')) {
+ index = lastGoodIndex;
+ return false;
+ }
+ return true;
+ } else {
+ index = lastGoodIndex;
+ return false;
+ }
+ }
+
+ private boolean nextGeoLineString(final boolean isGeography) {
+ return nextGeoPrefix(isGeography) && nextCharacter('\'')
+ && nextSrid() && nextCharacter(';')
+ && nextConstantIgnoreCase("LineString") && nextLineStringData(false)
+ && nextCharacter('\'');
+ }
+
+ /**
+ * Moves past geo polygon data if found; otherwise leaves the index unchanged.
+ * @return whether geo polygon data have been found at the current index
+ */
+ private boolean nextPolygonData() {
+ final int lastGoodIndex = index;
+ if (nextCharacter('(') && nextLineStringData(true)) {
+ // The polygon can have holes, described by further rings.
+ while (nextCharacter(',')) {
+ if (!nextLineStringData(true)) {
+ index = lastGoodIndex;
+ return false;
+ }
+ }
+ if (!nextCharacter(')')) {
+ index = lastGoodIndex;
+ return false;
+ }
+ return true;
+ } else {
+ index = lastGoodIndex;
+ return false;
+ }
+ }
+
+ private boolean nextGeoPolygon(final boolean isGeography) {
+ return nextGeoPrefix(isGeography) && nextCharacter('\'')
+ && nextSrid() && nextCharacter(';')
+ && nextConstantIgnoreCase("Polygon") && nextPolygonData()
+ && nextCharacter('\'');
+ }
+
+ private boolean nextMultiPoint() {
+ if (nextPointData()) {
+ while (nextCharacter(',')) {
+ if (!nextPointData()) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ private boolean nextGeoMultiPoint(final boolean isGeography) {
+ return nextGeoPrefix(isGeography) && nextCharacter('\'')
+ && nextSrid() && nextCharacter(';')
+ && nextConstantIgnoreCase("MultiPoint") && nextCharacter('(') && nextMultiPoint() && nextCharacter(')')
+ && nextCharacter('\'');
+ }
+
+ private boolean nextMultiLineString() {
+ if (nextLineStringData(false)) {
+ while (nextCharacter(',')) {
+ if (!nextLineStringData(false)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ private boolean nextGeoMultiLineString(final boolean isGeography) {
+ return nextGeoPrefix(isGeography) && nextCharacter('\'')
+ && nextSrid() && nextCharacter(';')
+ && nextConstantIgnoreCase("MultiLineString")
+ && nextCharacter('(') && nextMultiLineString() && nextCharacter(')')
+ && nextCharacter('\'');
+ }
+
+ private boolean nextMultiPolygon() {
+ if (nextPolygonData()) {
+ while (nextCharacter(',')) {
+ if (!nextPolygonData()) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ private boolean nextGeoMultiPolygon(final boolean isGeography) {
+ return nextGeoPrefix(isGeography) && nextCharacter('\'')
+ && nextSrid() && nextCharacter(';')
+ && nextConstantIgnoreCase("MultiPolygon")
+ && nextCharacter('(') && nextMultiPolygon() && nextCharacter(')')
+ && nextCharacter('\'');
+ }
+
+ /**
* Moves past a JSON string if found; otherwise leaves the index unchanged.
* @return whether a JSON string has been found at the current index
*/
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a283bddb/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/ExpressionParserTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/ExpressionParserTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/ExpressionParserTest.java
index f495c5b..c764999 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/ExpressionParserTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/ExpressionParserTest.java
@@ -239,14 +239,17 @@ public class ExpressionParserTest {
expression = parseMethod(TokenKind.ConcatMethod, "'a'", "'b'");
assertEquals("{concat ['a', 'b']}", expression.toString());
- // TODO: Geo methods.
-// expression = parseMethod(TokenKind.GeoDistanceMethod,
-// "geography'SRID=0;Point(1.2 3.4)'", "geography'SRID=0;Point(5.6 7.8)'");
-// assertEquals("{geo.distance [geography'SRID=0;Point(1.2 3.4)', geography'SRID=0;Point(5.6 7.8)']}",
-// expression.toString());
-//
-// expression = parseMethod(TokenKind.GeoIntersectsMethod);
-// assertEquals("{geo.intersects []}", expression.toString());
+ expression = parseMethod(TokenKind.GeoDistanceMethod,
+ "geography'SRID=0;Point(1.2 3.4)'", "geography'SRID=0;Point(5.6 7.8)'");
+ assertEquals("{geo.distance [geography'SRID=0;Point(1.2 3.4)', geography'SRID=0;Point(5.6 7.8)']}",
+ expression.toString());
+
+ expression = parseMethod(TokenKind.GeoIntersectsMethod,
+ "geometry'SRID=0;Point(1.2 3.4)'",
+ "geometry'SRID=0;Polygon((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1))'");
+ assertEquals("{geo.intersects [geometry'SRID=0;Point(1.2 3.4)', "
+ + "geometry'SRID=0;Polygon((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1))']}",
+ expression.toString());
assertEquals("{startswith [null, 'b']}", parseMethod(TokenKind.StartswithMethod, null, "'b'").toString());
assertEquals("{indexof ['a', null]}", parseMethod(TokenKind.IndexofMethod, "'a'", null).toString());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a283bddb/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/UriTokenizerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/UriTokenizerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/UriTokenizerTest.java
index e130457..78c6204 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/UriTokenizerTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/UriTokenizerTest.java
@@ -560,6 +560,70 @@ public class UriTokenizerTest {
assertFalse(new UriTokenizer("NOT").next(TokenKind.Word));
}
+ @Test
+ public void geoPoint() {
+ assertTrue(new UriTokenizer("geography'SRID=4326;Point(1.23 4.56)'").next(TokenKind.GeographyPoint));
+ assertTrue(new UriTokenizer("GeOgRaPhY'SrId=4326;pOiNt(1 2)'").next(TokenKind.GeographyPoint));
+ assertTrue(new UriTokenizer("geography'srid=4326;point(1.2E3 4.5E-6)'").next(TokenKind.GeographyPoint));
+ wrongToken(TokenKind.GeographyPoint, "geography'SRID=4326;Point(1.23 4.56)'", 'x');
+
+ assertTrue(new UriTokenizer("geometry'SRID=0;Point(1 2)'").next(TokenKind.GeometryPoint));
+ assertFalse(new UriTokenizer("geometry'SRID=123456;Point(1 2)'").next(TokenKind.GeometryPoint));
+ assertFalse(new UriTokenizer("geometry'SRID=123456;Point(1)'").next(TokenKind.GeometryPoint));
+ wrongToken(TokenKind.GeometryPoint, "geometry'SRID=0;Point(1.23 4.56)'", ',');
+ }
+
+ @Test
+ public void geoLineString() {
+ assertTrue(new UriTokenizer("geography'SRID=4326;LineString(1.23 4.56,7 8)'")
+ .next(TokenKind.GeographyLineString));
+ wrongToken(TokenKind.GeographyLineString, "geography'SRID=4326;LineString(1.23 4.56,7 8)'", '{');
+
+ assertTrue(new UriTokenizer("geometry'SRID=0;LineString(1 2,3 4,5 6,7 8)'")
+ .next(TokenKind.GeometryLineString));
+ wrongToken(TokenKind.GeometryLineString, "geometry'SRID=0;LineString(1 2,3 4,5 6,7 8)'", '.');
+ }
+
+ @Test
+ public void geoPolygon() {
+ assertTrue(new UriTokenizer("geography'SRID=4326;Polygon((0 0,1 0,0 1,0 0))'").next(TokenKind.GeographyPolygon));
+ assertTrue(new UriTokenizer("geometry'SRID=0;Polygon((0 0,1 0,0 1,0 0))'").next(TokenKind.GeometryPolygon));
+ wrongToken(TokenKind.GeometryPolygon,
+ "geometry'SRID=0;Polygon((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1))'",
+ 'x');
+ }
+
+ @Test
+ public void geoMultiPoint() {
+ assertTrue(new UriTokenizer("geography'SRID=4326;MultiPoint()'").next(TokenKind.GeographyMultiPoint));
+ assertTrue(new UriTokenizer("geography'SRID=4326;MultiPoint((0 0))'").next(TokenKind.GeographyMultiPoint));
+ assertTrue(new UriTokenizer("geometry'SRID=0;MultiPoint((0 0),(1 1))'").next(TokenKind.GeometryMultiPoint));
+ wrongToken(TokenKind.GeometryMultiPoint, "geometry'SRID=0;MultiPoint((0 0),(1 1),(2.3 4.5))'", 'x');
+ }
+
+ @Test
+ public void geoMultiLineString() {
+ assertTrue(new UriTokenizer("geography'SRID=4326;MultiLineString()'").next(TokenKind.GeographyMultiLineString));
+ assertTrue(new UriTokenizer("geography'SRID=4326;MultiLineString((1 2,3 4))'")
+ .next(TokenKind.GeographyMultiLineString));
+
+ wrongToken(TokenKind.GeometryMultiLineString,
+ "geometry'SRID=0;MultiLineString((1.23 4.56,7 8),(0 0,1 1),(2 2,3 3))'",
+ '}');
+ }
+
+ @Test
+ public void geoMultiPolygon() {
+ assertTrue(new UriTokenizer("geography'SRID=4326;MultiPolygon()'").next(TokenKind.GeographyMultiPolygon));
+ assertTrue(new UriTokenizer("geography'SRID=4326;MultiPolygon(((0 0,1 0,0 1,0 0)))'")
+ .next(TokenKind.GeographyMultiPolygon));
+
+ wrongToken(TokenKind.GeometryMultiPolygon,
+ "geometry'SRID=0;MultiPolygon(((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1)),"
+ + "((0 0,40 0,40 40,0 40,0 0),(10 10,20 10,20 20,10 20,10 10)))'",
+ 'x');
+ }
+
private void wrongToken(final TokenKind kind, final String value, final char disturbCharacter) {
assertFalse(new UriTokenizer(disturbCharacter + value).next(kind));
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a283bddb/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/TestUriParserImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/TestUriParserImpl.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/TestUriParserImpl.java
index fa7a0df..138e598 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/TestUriParserImpl.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/TestUriParserImpl.java
@@ -22,12 +22,12 @@ import java.util.Arrays;
import java.util.Collections;
import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.edmx.EdmxReference;
import org.apache.olingo.server.api.uri.UriInfoKind;
import org.apache.olingo.server.api.uri.UriResourceKind;
import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind;
-import org.apache.olingo.server.core.uri.parser.UriParserSemanticException;
import org.apache.olingo.server.core.uri.testutil.FilterValidator;
import org.apache.olingo.server.core.uri.testutil.ResourceValidator;
import org.apache.olingo.server.core.uri.testutil.TestUriValidator;
@@ -38,11 +38,11 @@ import org.apache.olingo.server.tecsvc.provider.ContainerProvider;
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider;
import org.apache.olingo.server.tecsvc.provider.PropertyProvider;
-import org.junit.Ignore;
import org.junit.Test;
public class TestUriParserImpl {
- private final Edm edm = OData.newInstance().createServiceMetadata(
+ private static final OData oData = OData.newInstance();
+ private final Edm edm = oData.createServiceMetadata(
new EdmTechProvider(), Collections.<EdmxReference> emptyList()).getEdm();
private final TestUriValidator testUri = new TestUriValidator().setEdm(edm);
private final ResourceValidator testRes = new ResourceValidator().setEdm(edm);
@@ -1031,16 +1031,17 @@ public class TestUriParserImpl {
}
@Test
- @Ignore("Geo types are not supported yet.")
public void geo() throws Exception {
- testFilter.runOnETAllPrim("geo.distance(PropertySByte,PropertySByte)")
- .is("<geo.distance(<PropertySByte>,<PropertySByte>)>")
- .isMethod(MethodKind.GEODISTANCE, 2);
- testFilter.runOnETAllPrim("geo.length(PropertySByte)")
- .is("<geo.length(<PropertySByte>)>")
- .isMethod(MethodKind.GEOLENGTH, 1);
- testFilter.runOnETAllPrim("geo.intersects(PropertySByte,PropertySByte)")
- .is("<geo.intersects(<PropertySByte>,<PropertySByte>)>")
- .isMethod(MethodKind.GEOINTERSECTS, 2);
+ testFilter.runOnETAllPrim("geo.distance(geometry'SRID=0;Point(0 0)',geometry'SRID=0;Point(1 1)') lt 1.5")
+ .left().isMethod(MethodKind.GEODISTANCE, 2)
+ .goParameter(0).isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.GeometryPoint))
+ .root().left()
+ .goParameter(1).isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.GeometryPoint));
+ testFilter.runOnETAllPrim("geo.length(geometry'SRID=0;LineString(0 0,1 1)') lt 1.5")
+ .left().isMethod(MethodKind.GEOLENGTH, 1)
+ .goParameter(0).isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.GeometryLineString));
+ testFilter.runOnETAllPrim("geo.intersects(geometry'SRID=0;Point(0 0)',null)")
+ .isMethod(MethodKind.GEOINTERSECTS, 2)
+ .goParameter(0).isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.GeometryPoint));
}
}