[OLINGO-194] geospatial literals
This commit is contained in:
parent
c1b8976e9b
commit
7651350846
|
@ -26,7 +26,6 @@ import org.apache.olingo.client.api.communication.request.retrieve.CommonRetriev
|
|||
import org.apache.olingo.client.api.communication.request.streamed.CommonStreamedRequestFactory;
|
||||
import org.apache.olingo.client.api.op.ClientODataDeserializer;
|
||||
import org.apache.olingo.commons.api.domain.ODataObjectFactory;
|
||||
import org.apache.olingo.commons.api.domain.ODataGeospatialValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.client.api.op.CommonODataBinder;
|
||||
import org.apache.olingo.client.api.op.CommonODataReader;
|
||||
|
@ -50,8 +49,6 @@ public interface CommonODataClient {
|
|||
|
||||
ODataPrimitiveValue.Builder getPrimitiveValueBuilder();
|
||||
|
||||
ODataGeospatialValue.Builder getGeospatialValueBuilder();
|
||||
|
||||
ODataSerializer getSerializer();
|
||||
|
||||
ClientODataDeserializer getDeserializer();
|
||||
|
|
|
@ -21,8 +21,7 @@ package org.apache.olingo.client.core;
|
|||
import org.apache.olingo.client.api.CommonODataClient;
|
||||
import org.apache.olingo.commons.api.domain.ODataObjectFactory;
|
||||
import org.apache.olingo.client.api.op.ODataWriter;
|
||||
import org.apache.olingo.client.core.domain.ODataGeospatialValueImpl;
|
||||
import org.apache.olingo.client.core.domain.ODataPrimitiveValueImpl;
|
||||
import org.apache.olingo.commons.core.domain.ODataPrimitiveValueImpl;
|
||||
import org.apache.olingo.commons.core.op.ODataObjectFactoryImpl;
|
||||
import org.apache.olingo.client.core.op.ODataWriterImpl;
|
||||
|
||||
|
@ -39,11 +38,6 @@ public abstract class AbstractODataClient implements CommonODataClient {
|
|||
return new ODataPrimitiveValueImpl.BuilderImpl(this.getServiceVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataGeospatialValueImpl.BuilderImpl getGeospatialValueBuilder() {
|
||||
return new ODataGeospatialValueImpl.BuilderImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataWriter getWriter() {
|
||||
return writer;
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.apache.olingo.client.api.http.HttpMethod;
|
|||
import org.apache.olingo.client.core.uri.URIUtils;
|
||||
import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
|
||||
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
|
||||
import org.apache.olingo.client.core.domain.ODataPrimitiveValueImpl;
|
||||
import org.apache.olingo.commons.core.domain.ODataPrimitiveValueImpl;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse
|
|||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.format.ODataValueFormat;
|
||||
import org.apache.olingo.client.api.http.HttpClientException;
|
||||
import org.apache.olingo.client.core.domain.ODataPrimitiveValueImpl;
|
||||
import org.apache.olingo.commons.core.domain.ODataPrimitiveValueImpl;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,130 +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.client.core.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.apache.olingo.commons.api.domain.AbstractODataValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataGeospatialValue;
|
||||
import org.apache.olingo.commons.api.edm.EdmGeospatialType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
|
||||
public class ODataGeospatialValueImpl extends AbstractODataValue implements ODataGeospatialValue {
|
||||
|
||||
private static final long serialVersionUID = 8277433906326348952L;
|
||||
|
||||
public static class BuilderImpl implements Builder {
|
||||
|
||||
private final ODataGeospatialValueImpl instance;
|
||||
|
||||
public BuilderImpl() {
|
||||
this.instance = new ODataGeospatialValueImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuilderImpl setType(final EdmPrimitiveTypeKind type) {
|
||||
if (type != null && !type.isGeospatial()) {
|
||||
throw new IllegalArgumentException("Don't use this for non-geospatial types");
|
||||
}
|
||||
if (type == EdmPrimitiveTypeKind.Geography || type == EdmPrimitiveTypeKind.Geometry) {
|
||||
throw new IllegalArgumentException(
|
||||
type + "is not an instantiable type. "
|
||||
+ "An entity can declare a property to be of type Geometry. "
|
||||
+ "An instance of an entity MUST NOT have a value of type Geometry. "
|
||||
+ "Each value MUST be of some subtype.");
|
||||
}
|
||||
|
||||
if (type != null) {
|
||||
this.instance.typeKind = type;
|
||||
this.instance.type = EdmPrimitiveTypeFactory.getGeoInstance(type);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuilderImpl setValue(final Geospatial value) {
|
||||
this.instance.value = value;
|
||||
if (value != null) {
|
||||
setType(value.getEdmPrimitiveTypeKind());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataGeospatialValueImpl build() {
|
||||
if (this.instance.type == null) {
|
||||
throw new IllegalArgumentException("Must provide geospatial type");
|
||||
}
|
||||
if (this.instance.value == null) {
|
||||
throw new IllegalArgumentException("Must provide geospatial value");
|
||||
}
|
||||
|
||||
return this.instance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Type kind.
|
||||
*/
|
||||
private EdmPrimitiveTypeKind typeKind;
|
||||
|
||||
/**
|
||||
* Type.
|
||||
*/
|
||||
private EdmGeospatialType type;
|
||||
|
||||
/**
|
||||
* Value.
|
||||
*/
|
||||
private Geospatial value;
|
||||
|
||||
@Override
|
||||
public EdmPrimitiveTypeKind getTypeKind() {
|
||||
return typeKind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmGeospatialType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Geospatial toValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Geospatial> T toCastValue(final Class<T> reference) {
|
||||
return reference.cast(this.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return EqualsBuilder.reflectionEquals(this, obj);
|
||||
}
|
||||
|
||||
}
|
|
@ -62,9 +62,9 @@ public class EdmEnumTypeImpl extends AbstractEdmEnumType implements EdmEnumType
|
|||
super(edm, fqn, xmlEnumType.isFlags());
|
||||
|
||||
if (xmlEnumType.getUnderlyingType() == null) {
|
||||
this.underlyingType = EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int32);
|
||||
this.underlyingType = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32);
|
||||
} else {
|
||||
this.underlyingType = EdmPrimitiveTypeFactory.getNonGeoInstance(
|
||||
this.underlyingType = EdmPrimitiveTypeFactory.getInstance(
|
||||
EdmPrimitiveTypeKind.valueOfFQN(version, xmlEnumType.getUnderlyingType()));
|
||||
if (!ArrayUtils.contains(VALID_UNDERLYING_TYPES, this.underlyingType.getKind())) {
|
||||
throw new EdmException("Not allowed as underlying type: " + this.underlyingType.getKind());
|
||||
|
|
|
@ -41,7 +41,7 @@ public class EdmTypeDefinitionImpl extends AbstractEdmTypeDefinition implements
|
|||
super(edm, typeDefinitionName);
|
||||
this.typeDefinition = typeDefinition;
|
||||
try {
|
||||
this.edmPrimitiveTypeInstance = EdmPrimitiveTypeFactory.getNonGeoInstance(
|
||||
this.edmPrimitiveTypeInstance = EdmPrimitiveTypeFactory.getInstance(
|
||||
EdmPrimitiveTypeKind.valueOfFQN(version, typeDefinition.getUnderlyingType()));
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new EdmException("Invalid underlying type: " + typeDefinition.getUnderlyingType(), e);
|
||||
|
|
|
@ -18,19 +18,20 @@
|
|||
*/
|
||||
package org.apache.olingo.client.core.op;
|
||||
|
||||
import org.apache.olingo.commons.core.op.ResourceFactory;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URI;
|
||||
import java.util.Iterator;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.olingo.client.api.CommonODataClient;
|
||||
import org.apache.olingo.client.api.data.ServiceDocument;
|
||||
import org.apache.olingo.client.api.data.ServiceDocumentItem;
|
||||
import org.apache.olingo.client.api.op.CommonODataBinder;
|
||||
import org.apache.olingo.client.core.uri.URIUtils;
|
||||
import org.apache.olingo.commons.api.Constants;
|
||||
import org.apache.olingo.commons.api.data.Entry;
|
||||
import org.apache.olingo.commons.api.data.Feed;
|
||||
import org.apache.olingo.commons.api.data.Link;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.client.api.data.ServiceDocument;
|
||||
import org.apache.olingo.client.api.data.ServiceDocumentItem;
|
||||
import org.apache.olingo.commons.api.data.Value;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
|
@ -43,8 +44,9 @@ import org.apache.olingo.commons.api.domain.ODataOperation;
|
|||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataServiceDocument;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
import org.apache.olingo.client.api.op.CommonODataBinder;
|
||||
import org.apache.olingo.commons.core.data.CollectionValueImpl;
|
||||
import org.apache.olingo.commons.core.data.ComplexValueImpl;
|
||||
import org.apache.olingo.commons.core.data.GeospatialValueImpl;
|
||||
|
@ -52,8 +54,7 @@ import org.apache.olingo.commons.core.data.JSONPropertyImpl;
|
|||
import org.apache.olingo.commons.core.data.LinkImpl;
|
||||
import org.apache.olingo.commons.core.data.NullValueImpl;
|
||||
import org.apache.olingo.commons.core.data.PrimitiveValueImpl;
|
||||
import org.apache.olingo.client.core.uri.URIUtils;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.core.op.ResourceFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -232,9 +233,9 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
|
|||
if (value == null) {
|
||||
valueResource = new NullValueImpl();
|
||||
} else if (value.isPrimitive()) {
|
||||
valueResource = new PrimitiveValueImpl(value.asPrimitive().toString());
|
||||
} else if (value.isGeospatial()) {
|
||||
valueResource = new GeospatialValueImpl(value.asGeospatial().toValue());
|
||||
valueResource = value.asPrimitive().getTypeKind().isGeospatial()
|
||||
? new GeospatialValueImpl((Geospatial) value.asPrimitive().toValue())
|
||||
: new PrimitiveValueImpl(value.asPrimitive().toString());
|
||||
} else if (value.isComplex()) {
|
||||
final ODataComplexValue _value = value.asComplex();
|
||||
valueResource = new ComplexValueImpl();
|
||||
|
@ -269,7 +270,7 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
|
|||
}
|
||||
|
||||
final URI base = defaultBaseURI == null ? resource.getBaseURI() : defaultBaseURI;
|
||||
|
||||
|
||||
final URI next = resource.getNext();
|
||||
|
||||
final ODataEntitySet entitySet = next == null
|
||||
|
@ -283,7 +284,7 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
|
|||
for (Entry entryResource : resource.getEntries()) {
|
||||
entitySet.addEntity(getODataEntity(entryResource));
|
||||
}
|
||||
|
||||
|
||||
return entitySet;
|
||||
}
|
||||
|
||||
|
@ -311,11 +312,11 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
|
|||
if (StringUtils.isNotBlank(resource.getETag())) {
|
||||
entity.setETag(resource.getETag());
|
||||
}
|
||||
|
||||
|
||||
if (resource.getEditLink() != null) {
|
||||
entity.setEditLink(URIUtils.getURI(base, resource.getEditLink().getHref()));
|
||||
}
|
||||
|
||||
|
||||
for (Link link : resource.getAssociationLinks()) {
|
||||
entity.addLink(client.getObjectFactory().newAssociationLink(link.getTitle(), base, link.getHref()));
|
||||
}
|
||||
|
@ -377,12 +378,12 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
|
|||
? null
|
||||
: EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), resource.getType())).build();
|
||||
} else if (resource.getValue().isGeospatial()) {
|
||||
value = client.getGeospatialValueBuilder().
|
||||
value = client.getPrimitiveValueBuilder().
|
||||
setValue(resource.getValue().asGeospatial().get()).
|
||||
setType(resource.getType() == null
|
||||
|| EdmPrimitiveTypeKind.Geography.getFullQualifiedName().toString().equals(resource.getType())
|
||||
|| EdmPrimitiveTypeKind.Geometry.getFullQualifiedName().toString().equals(resource.getType())
|
||||
? null
|
||||
? resource.getValue().asGeospatial().get().getEdmPrimitiveTypeKind()
|
||||
: EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), resource.getType())).build();
|
||||
} else if (resource.getValue().isComplex()) {
|
||||
value = new ODataComplexValue(resource.getType());
|
||||
|
|
|
@ -41,6 +41,8 @@ import org.apache.olingo.commons.api.edm.EdmFunctionImport;
|
|||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmBinary;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDate;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTime;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTimeOffset;
|
||||
|
@ -48,6 +50,7 @@ import org.apache.olingo.commons.core.edm.primitivetype.EdmDecimal;
|
|||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDouble;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDuration;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt64;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmSingle;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmTime;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmTimeOfDay;
|
||||
|
@ -170,14 +173,6 @@ public final class URIUtils {
|
|||
result = "X'";
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
} else {
|
||||
switch (typeKind) {
|
||||
case Binary:
|
||||
result = "binary'";
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +187,6 @@ public final class URIUtils {
|
|||
case Guid:
|
||||
case DateTime:
|
||||
case DateTimeOffset:
|
||||
case Binary:
|
||||
result = "'";
|
||||
break;
|
||||
|
||||
|
@ -212,14 +206,6 @@ public final class URIUtils {
|
|||
result = "L";
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
} else {
|
||||
switch (typeKind) {
|
||||
case Binary:
|
||||
result = "'";
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
@ -280,12 +266,12 @@ public final class URIUtils {
|
|||
throws UnsupportedEncodingException, EdmPrimitiveTypeException {
|
||||
|
||||
return version == ODataServiceVersion.V30
|
||||
? "time'" + URLEncoder.encode(EdmTime.getInstance().
|
||||
valueToString(duration, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null),
|
||||
Constants.UTF8) + "'"
|
||||
: "duration'" + URLEncoder.encode(EdmDuration.getInstance().
|
||||
valueToString(duration, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null),
|
||||
Constants.UTF8) + "'";
|
||||
? EdmTime.getInstance().toUriLiteral(URLEncoder.encode(EdmTime.getInstance().
|
||||
valueToString(duration, null, null,
|
||||
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null), Constants.UTF8))
|
||||
: EdmDuration.getInstance().toUriLiteral(URLEncoder.encode(EdmDuration.getInstance().
|
||||
valueToString(duration, null, null,
|
||||
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null), Constants.UTF8));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -305,9 +291,7 @@ public final class URIUtils {
|
|||
+ obj.toString()
|
||||
+ suffix(version, EdmPrimitiveTypeKind.Guid)
|
||||
: (obj instanceof byte[])
|
||||
? prefix(version, EdmPrimitiveTypeKind.Binary)
|
||||
+ Hex.encodeHexString((byte[]) obj)
|
||||
+ suffix(version, EdmPrimitiveTypeKind.Binary)
|
||||
? EdmBinary.getInstance().toUriLiteral(Hex.encodeHexString((byte[]) obj))
|
||||
: (obj instanceof Timestamp)
|
||||
? timestamp(version, (Timestamp) obj)
|
||||
: (obj instanceof Calendar)
|
||||
|
@ -330,6 +314,10 @@ public final class URIUtils {
|
|||
? EdmInt64.getInstance().valueToString(obj, null, null,
|
||||
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null)
|
||||
+ suffix(version, EdmPrimitiveTypeKind.Int64)
|
||||
: (obj instanceof Geospatial)
|
||||
? URLEncoder.encode(EdmPrimitiveTypeFactory.getInstance(((Geospatial) obj).getEdmPrimitiveTypeKind()).
|
||||
valueToString(obj, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null),
|
||||
Constants.UTF8)
|
||||
: (obj instanceof String)
|
||||
? "'" + URLEncoder.encode((String) obj, Constants.UTF8) + "'"
|
||||
: obj.toString();
|
||||
|
@ -340,7 +328,7 @@ public final class URIUtils {
|
|||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
public static InputStreamEntity buildInputStreamEntity(final CommonODataClient client, final InputStream input) {
|
||||
InputStreamEntity entity;
|
||||
if (client.getConfiguration().isUseChuncked()) {
|
||||
|
|
|
@ -29,7 +29,6 @@ import java.util.List;
|
|||
import java.util.UUID;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.olingo.commons.api.Constants;
|
||||
import org.apache.olingo.commons.api.domain.ODataGeospatialValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
|
@ -93,35 +92,6 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
|
|||
return value;
|
||||
}
|
||||
|
||||
protected ODataGeospatialValue writeGeospatialValue(final ODataGeospatialValue value) {
|
||||
final ODataGeospatialValue newValue = getClient().getGeospatialValueBuilder().
|
||||
setType(value.getTypeKind()).
|
||||
setValue(value.toValue()).
|
||||
build();
|
||||
final InputStream written = getClient().getWriter().writeProperty(
|
||||
getClient().getObjectFactory().newPrimitiveProperty(Constants.ELEM_PROPERTY, newValue),
|
||||
getFormat());
|
||||
return readGeospatialValue(written);
|
||||
}
|
||||
|
||||
protected ODataGeospatialValue readGeospatialValue(final InputStream input) {
|
||||
final ODataProperty property = getClient().getReader().readProperty(input, getFormat());
|
||||
assertNotNull(property);
|
||||
assertTrue(property.hasGeospatialValue());
|
||||
assertNotNull(property.getGeospatialValue());
|
||||
|
||||
return property.getGeospatialValue();
|
||||
}
|
||||
|
||||
protected ODataGeospatialValue readGeospatialValue(final String entity, final String propertyName) {
|
||||
final ODataGeospatialValue value =
|
||||
readGeospatialValue(getClass().getResourceAsStream(getFilename(entity, propertyName)));
|
||||
|
||||
assertEquals(value.toValue(), writeGeospatialValue(value).toValue());
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
protected void int32(final String entity, final String propertyName, final int check)
|
||||
throws EdmPrimitiveTypeException {
|
||||
|
||||
|
@ -200,9 +170,9 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
|
|||
final String propertyName,
|
||||
final Point expectedValues,
|
||||
final EdmPrimitiveTypeKind expectedType,
|
||||
final Dimension expectedDimension) {
|
||||
final Dimension expectedDimension) throws EdmPrimitiveTypeException {
|
||||
|
||||
final ODataGeospatialValue opv = readGeospatialValue(entity, propertyName);
|
||||
final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
|
||||
assertEquals(expectedType, opv.getTypeKind());
|
||||
|
||||
final Point point = opv.toCastValue(Point.class);
|
||||
|
@ -231,9 +201,9 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
|
|||
final String propertyName,
|
||||
final List<Point> check,
|
||||
final EdmPrimitiveTypeKind expectedType,
|
||||
final Dimension expectedDimension) {
|
||||
final Dimension expectedDimension) throws EdmPrimitiveTypeException {
|
||||
|
||||
final ODataGeospatialValue opv = readGeospatialValue(entity, propertyName);
|
||||
final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
|
||||
assertEquals(expectedType, opv.getTypeKind());
|
||||
|
||||
final LineString lineString = opv.toCastValue(LineString.class);
|
||||
|
@ -248,9 +218,9 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
|
|||
final String propertyName,
|
||||
final List<Point> check,
|
||||
final EdmPrimitiveTypeKind expectedType,
|
||||
final Dimension expectedDimension) {
|
||||
final Dimension expectedDimension) throws EdmPrimitiveTypeException {
|
||||
|
||||
final ODataGeospatialValue opv = readGeospatialValue(entity, propertyName);
|
||||
final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
|
||||
assertEquals(expectedType, opv.getTypeKind());
|
||||
|
||||
final MultiPoint multiPoint = opv.toCastValue(MultiPoint.class);
|
||||
|
@ -275,9 +245,9 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
|
|||
final String propertyName,
|
||||
final List<List<Point>> check,
|
||||
final EdmPrimitiveTypeKind expectedType,
|
||||
final Dimension expectedDimension) {
|
||||
final Dimension expectedDimension) throws EdmPrimitiveTypeException {
|
||||
|
||||
final ODataGeospatialValue opv = readGeospatialValue(entity, propertyName);
|
||||
final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
|
||||
assertEquals(expectedType, opv.getTypeKind());
|
||||
|
||||
final MultiLineString multiLine = opv.toCastValue(MultiLineString.class);
|
||||
|
@ -330,9 +300,9 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
|
|||
final List<Point> checkInterior,
|
||||
final List<Point> checkExterior,
|
||||
final EdmPrimitiveTypeKind expectedType,
|
||||
final Dimension expectedDimension) {
|
||||
final Dimension expectedDimension) throws EdmPrimitiveTypeException {
|
||||
|
||||
final ODataGeospatialValue opv = readGeospatialValue(entity, propertyName);
|
||||
final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
|
||||
assertEquals(expectedType, opv.getTypeKind());
|
||||
|
||||
final Polygon polygon = opv.toCastValue(Polygon.class);
|
||||
|
@ -350,9 +320,9 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
|
|||
final List<List<Point>> checkInterior,
|
||||
final List<List<Point>> checkExterior,
|
||||
final EdmPrimitiveTypeKind expectedType,
|
||||
final Dimension expectedDimension) {
|
||||
final Dimension expectedDimension) throws EdmPrimitiveTypeException {
|
||||
|
||||
final ODataGeospatialValue opv = readGeospatialValue(entity, propertyName);
|
||||
final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
|
||||
assertEquals(expectedType, opv.getTypeKind());
|
||||
|
||||
final MultiPolygon multiPolygon = opv.toCastValue(MultiPolygon.class);
|
||||
|
@ -373,9 +343,9 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
|
|||
final String entity,
|
||||
final String propertyName,
|
||||
final EdmPrimitiveTypeKind expectedType,
|
||||
final Dimension expectedDimension) {
|
||||
final Dimension expectedDimension) throws EdmPrimitiveTypeException {
|
||||
|
||||
final ODataGeospatialValue opv = readGeospatialValue(entity, propertyName);
|
||||
final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
|
||||
assertEquals(expectedType, opv.getTypeKind());
|
||||
|
||||
final GeospatialCollection collection = opv.toCastValue(GeospatialCollection.class);
|
||||
|
@ -402,9 +372,9 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
|
|||
final String entity,
|
||||
final String propertyName,
|
||||
final EdmPrimitiveTypeKind expectedType,
|
||||
final Dimension expectedDimension) {
|
||||
final Dimension expectedDimension) throws EdmPrimitiveTypeException {
|
||||
|
||||
final ODataGeospatialValue opv = readGeospatialValue(entity, propertyName);
|
||||
final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
|
||||
assertEquals(expectedType, opv.getTypeKind());
|
||||
|
||||
final GeospatialCollection collection = opv.toCastValue(GeospatialCollection.class);
|
||||
|
|
|
@ -118,25 +118,25 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
|
|||
point.setX(1.2);
|
||||
point.setY(2.1);
|
||||
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aPoint",
|
||||
client.getGeospatialValueBuilder().setType(EdmPrimitiveTypeKind.GeographyPoint).
|
||||
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeographyPoint).
|
||||
setValue(point).build()));
|
||||
final List<Point> points = new ArrayList<Point>();
|
||||
points.add(point);
|
||||
points.add(point);
|
||||
final MultiPoint multipoint = new MultiPoint(Geospatial.Dimension.GEOMETRY, null, points);
|
||||
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aMultiPoint",
|
||||
client.getGeospatialValueBuilder().setType(EdmPrimitiveTypeKind.GeometryMultiPoint).
|
||||
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeometryMultiPoint).
|
||||
setValue(multipoint).build()));
|
||||
final LineString lineString = new LineString(Geospatial.Dimension.GEOMETRY, null, points);
|
||||
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aLineString",
|
||||
client.getGeospatialValueBuilder().setType(EdmPrimitiveTypeKind.GeometryLineString).
|
||||
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeometryLineString).
|
||||
setValue(lineString).build()));
|
||||
final List<LineString> lineStrings = new ArrayList<LineString>();
|
||||
lineStrings.add(lineString);
|
||||
lineStrings.add(lineString);
|
||||
final MultiLineString multiLineString = new MultiLineString(Geospatial.Dimension.GEOGRAPHY, null, lineStrings);
|
||||
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aMultiLineString",
|
||||
client.getGeospatialValueBuilder().setType(EdmPrimitiveTypeKind.GeometryMultiLineString).
|
||||
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeometryMultiLineString).
|
||||
setValue(multiLineString).build()));
|
||||
final Point otherPoint = new Point(Geospatial.Dimension.GEOGRAPHY, null);
|
||||
otherPoint.setX(3.4);
|
||||
|
@ -146,14 +146,14 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
|
|||
points.add(point);
|
||||
final Polygon polygon = new Polygon(Geospatial.Dimension.GEOGRAPHY, null, points, points);
|
||||
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aPolygon",
|
||||
client.getGeospatialValueBuilder().setType(EdmPrimitiveTypeKind.GeographyPolygon).
|
||||
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeographyPolygon).
|
||||
setValue(polygon).build()));
|
||||
final List<Polygon> polygons = new ArrayList<Polygon>();
|
||||
polygons.add(polygon);
|
||||
polygons.add(polygon);
|
||||
final MultiPolygon multiPolygon = new MultiPolygon(Geospatial.Dimension.GEOGRAPHY, null, polygons);
|
||||
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aMultiPolygon",
|
||||
client.getGeospatialValueBuilder().setType(EdmPrimitiveTypeKind.GeographyMultiPolygon).
|
||||
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeographyMultiPolygon).
|
||||
setValue(multiPolygon).build()));
|
||||
final List<Geospatial> geospatials = new ArrayList<Geospatial>();
|
||||
geospatials.add(otherPoint);
|
||||
|
@ -162,7 +162,7 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
|
|||
geospatials.add(multiPolygon);
|
||||
final GeospatialCollection geoColl = new GeospatialCollection(Geospatial.Dimension.GEOGRAPHY, null, geospatials);
|
||||
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aCollection",
|
||||
client.getGeospatialValueBuilder().setType(EdmPrimitiveTypeKind.GeographyCollection).
|
||||
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeographyCollection).
|
||||
setValue(geoColl).build()));
|
||||
|
||||
final ODataComplexValue contactDetails =
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.apache.olingo.commons.api.domain.ODataLink;
|
|||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
import org.apache.olingo.client.core.AbstractTest;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.core.op.ResourceFactory;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
||||
|
@ -88,8 +89,8 @@ public class EntityTest extends AbstractTest {
|
|||
for (ODataProperty property : entity.getProperties()) {
|
||||
if ("GeogMultiLine".equals(property.getName())) {
|
||||
found = true;
|
||||
assertTrue(property.hasGeospatialValue());
|
||||
assertEquals(EdmPrimitiveTypeKind.GeographyMultiLineString, property.getGeospatialValue().getTypeKind());
|
||||
assertTrue(property.hasPrimitiveValue());
|
||||
assertEquals(EdmPrimitiveTypeKind.GeographyMultiLineString, property.getPrimitiveValue().getTypeKind());
|
||||
}
|
||||
}
|
||||
assertTrue(found);
|
||||
|
@ -160,30 +161,30 @@ public class EntityTest extends AbstractTest {
|
|||
mediaEntity(ODataPubFormat.JSON_FULL_METADATA);
|
||||
}
|
||||
|
||||
private void issue128(final ODataPubFormat format) {
|
||||
private void issue128(final ODataPubFormat format) throws EdmPrimitiveTypeException {
|
||||
final InputStream input = getClass().getResourceAsStream("AllGeoTypesSet_-5." + getSuffix(format));
|
||||
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
||||
getClient().getDeserializer().toEntry(input, format));
|
||||
assertNotNull(entity);
|
||||
|
||||
final ODataProperty geogCollection = entity.getProperty("GeogCollection");
|
||||
assertEquals(EdmPrimitiveTypeKind.GeographyCollection, geogCollection.getGeospatialValue().getTypeKind());
|
||||
assertEquals(EdmPrimitiveTypeKind.GeographyCollection, geogCollection.getPrimitiveValue().getTypeKind());
|
||||
|
||||
int count = 0;
|
||||
for (Geospatial g : geogCollection.getGeospatialValue().toCastValue(GeospatialCollection.class)) {
|
||||
assertNotNull(g);
|
||||
for (Geospatial geo : geogCollection.getPrimitiveValue().toCastValue(GeospatialCollection.class)) {
|
||||
assertNotNull(geo);
|
||||
count++;
|
||||
}
|
||||
assertEquals(2, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void issue128FromAtom() {
|
||||
public void issue128FromAtom() throws EdmPrimitiveTypeException {
|
||||
issue128(ODataPubFormat.ATOM);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void issue128FromJSON() {
|
||||
public void issue128FromJSON() throws EdmPrimitiveTypeException {
|
||||
issue128(ODataPubFormat.JSON_FULL_METADATA);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ public class MetadataTest extends AbstractTest {
|
|||
new FullQualifiedName("Microsoft.Test.OData.Services.AstoriaDefaultService", "ProductReview"));
|
||||
assertNotNull(entity);
|
||||
assertFalse(entity.getPropertyNames().isEmpty());
|
||||
assertEquals(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int32),
|
||||
assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32),
|
||||
entity.getProperty("ProductId").getType());
|
||||
|
||||
assertFalse(entity.getKeyPropertyRefs().isEmpty());
|
||||
|
@ -178,7 +178,7 @@ public class MetadataTest extends AbstractTest {
|
|||
|
||||
final EdmFunctionImport getArgumentPlusOne = container.getFunctionImport("GetArgumentPlusOne");
|
||||
assertNotNull(getArgumentPlusOne);
|
||||
assertEquals(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int32),
|
||||
assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32),
|
||||
getArgumentPlusOne.getFunction(null).getReturnType().getType());
|
||||
|
||||
final EdmActionImport resetDataSource = container.getActionImport("ResetDataSource");
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.olingo.client.core.v3;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
|
@ -182,32 +181,24 @@ public class PrimitiveValueTest extends AbstractTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void managePoint() {
|
||||
public void managePoint() throws EdmPrimitiveTypeException {
|
||||
final Point primitive = new Point(Geospatial.Dimension.GEOGRAPHY, null);
|
||||
primitive.setX(52.8606);
|
||||
primitive.setY(173.334);
|
||||
|
||||
try {
|
||||
getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeographyPoint).
|
||||
setValue(primitive).build();
|
||||
fail();
|
||||
} catch (IllegalArgumentException iae) {
|
||||
// nothing top do
|
||||
}
|
||||
|
||||
final ODataValue value =
|
||||
getClient().getGeospatialValueBuilder().setType(EdmPrimitiveTypeKind.GeographyPoint).
|
||||
getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeographyPoint).
|
||||
setValue(primitive).
|
||||
build();
|
||||
assertEquals(EdmPrimitiveTypeKind.GeographyPoint, value.asGeospatial().getTypeKind());
|
||||
assertEquals(EdmPrimitiveTypeKind.GeographyPoint, value.asPrimitive().getTypeKind());
|
||||
assertEquals(Double.valueOf(primitive.getX()),
|
||||
Double.valueOf(value.asGeospatial().toCastValue(Point.class).getX()));
|
||||
Double.valueOf(value.asPrimitive().toCastValue(Point.class).getX()));
|
||||
assertEquals(Double.valueOf(primitive.getY()),
|
||||
Double.valueOf(value.asGeospatial().toCastValue(Point.class).getY()));
|
||||
Double.valueOf(value.asPrimitive().toCastValue(Point.class).getY()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void manageLineString() {
|
||||
public void manageLineString() throws EdmPrimitiveTypeException {
|
||||
final List<Point> points = new ArrayList<Point>();
|
||||
Point point = new Point(Geospatial.Dimension.GEOGRAPHY, null);
|
||||
point.setX(40.5);
|
||||
|
@ -231,11 +222,11 @@ public class PrimitiveValueTest extends AbstractTest {
|
|||
|
||||
final LineString primitive = new LineString(Geospatial.Dimension.GEOGRAPHY, null, points);
|
||||
|
||||
final ODataValue value = getClient().getGeospatialValueBuilder().
|
||||
final ODataValue value = getClient().getPrimitiveValueBuilder().
|
||||
setType(EdmPrimitiveTypeKind.GeographyLineString).setValue(primitive).build();
|
||||
assertEquals(EdmPrimitiveTypeKind.GeographyLineString, value.asGeospatial().getTypeKind());
|
||||
assertEquals(EdmPrimitiveTypeKind.GeographyLineString, value.asPrimitive().getTypeKind());
|
||||
|
||||
final Iterator<Point> iter = value.asGeospatial().toCastValue(LineString.class).iterator();
|
||||
final Iterator<Point> iter = value.asPrimitive().toCastValue(LineString.class).iterator();
|
||||
|
||||
// take the third one and check the point value ...
|
||||
iter.next();
|
||||
|
@ -247,7 +238,7 @@ public class PrimitiveValueTest extends AbstractTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void manageMultiPoint() {
|
||||
public void manageMultiPoint() throws EdmPrimitiveTypeException {
|
||||
final List<Point> points = new ArrayList<Point>();
|
||||
Point point = new Point(Geospatial.Dimension.GEOMETRY, null);
|
||||
point.setX(0);
|
||||
|
@ -256,11 +247,11 @@ public class PrimitiveValueTest extends AbstractTest {
|
|||
|
||||
final MultiPoint primitive = new MultiPoint(Geospatial.Dimension.GEOMETRY, null, points);
|
||||
|
||||
final ODataValue value = getClient().getGeospatialValueBuilder().
|
||||
final ODataValue value = getClient().getPrimitiveValueBuilder().
|
||||
setType(EdmPrimitiveTypeKind.GeometryMultiPoint).setValue(primitive).build();
|
||||
assertEquals(EdmPrimitiveTypeKind.GeometryMultiPoint, value.asGeospatial().getTypeKind());
|
||||
assertEquals(EdmPrimitiveTypeKind.GeometryMultiPoint, value.asPrimitive().getTypeKind());
|
||||
|
||||
final Iterator<Point> iter = value.asGeospatial().toCastValue(MultiPoint.class).iterator();
|
||||
final Iterator<Point> iter = value.asPrimitive().toCastValue(MultiPoint.class).iterator();
|
||||
point = iter.next();
|
||||
|
||||
assertEquals(Double.valueOf(points.get(0).getX()), Double.valueOf(point.getX()));
|
||||
|
@ -268,7 +259,7 @@ public class PrimitiveValueTest extends AbstractTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void manageMultiLine() {
|
||||
public void manageMultiLine() throws EdmPrimitiveTypeException {
|
||||
final List<LineString> lines = new ArrayList<LineString>();
|
||||
|
||||
// line one ...
|
||||
|
@ -317,11 +308,11 @@ public class PrimitiveValueTest extends AbstractTest {
|
|||
final MultiLineString primitive = new MultiLineString(Geospatial.Dimension.GEOMETRY, null, lines);
|
||||
|
||||
final ODataValue value =
|
||||
getClient().getGeospatialValueBuilder().setType(EdmPrimitiveTypeKind.GeometryMultiLineString).
|
||||
getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeometryMultiLineString).
|
||||
setValue(primitive).build();
|
||||
assertEquals(EdmPrimitiveTypeKind.GeometryMultiLineString, value.asGeospatial().getTypeKind());
|
||||
assertEquals(EdmPrimitiveTypeKind.GeometryMultiLineString, value.asPrimitive().getTypeKind());
|
||||
|
||||
final Iterator<LineString> lineIter = value.asGeospatial().toCastValue(MultiLineString.class).iterator();
|
||||
final Iterator<LineString> lineIter = value.asPrimitive().toCastValue(MultiLineString.class).iterator();
|
||||
|
||||
// take the second line and check the third point value ...
|
||||
lineIter.next();
|
||||
|
@ -337,7 +328,7 @@ public class PrimitiveValueTest extends AbstractTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void managePolygon() {
|
||||
public void managePolygon() throws EdmPrimitiveTypeException {
|
||||
|
||||
final List<Point> interior = new ArrayList<Point>();
|
||||
final List<Point> exterior = new ArrayList<Point>();
|
||||
|
@ -370,12 +361,12 @@ public class PrimitiveValueTest extends AbstractTest {
|
|||
final Polygon primitive = new Polygon(Geospatial.Dimension.GEOGRAPHY, null, interior, exterior);
|
||||
|
||||
final ODataValue value =
|
||||
getClient().getGeospatialValueBuilder().setType(EdmPrimitiveTypeKind.GeographyPolygon).
|
||||
getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeographyPolygon).
|
||||
setValue(primitive).build();
|
||||
assertEquals(EdmPrimitiveTypeKind.GeographyPolygon, value.asGeospatial().getTypeKind());
|
||||
assertEquals(EdmPrimitiveTypeKind.GeographyPolygon, value.asPrimitive().getTypeKind());
|
||||
|
||||
assertTrue(value.asGeospatial().toCastValue(Polygon.class).getInterior().isEmpty());
|
||||
final Iterator<Point> iter = value.asGeospatial().toCastValue(Polygon.class).getExterior().iterator();
|
||||
assertTrue(value.asPrimitive().toCastValue(Polygon.class).getInterior().isEmpty());
|
||||
final Iterator<Point> iter = value.asPrimitive().toCastValue(Polygon.class).getExterior().iterator();
|
||||
|
||||
// take the third one ...
|
||||
iter.next();
|
||||
|
@ -387,7 +378,7 @@ public class PrimitiveValueTest extends AbstractTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void manageMultiPolygon() {
|
||||
public void manageMultiPolygon() throws EdmPrimitiveTypeException {
|
||||
final List<Polygon> polygons = new ArrayList<Polygon>();
|
||||
|
||||
List<Point> interior = new ArrayList<Point>();
|
||||
|
@ -476,11 +467,11 @@ public class PrimitiveValueTest extends AbstractTest {
|
|||
final MultiPolygon primitive = new MultiPolygon(Geospatial.Dimension.GEOMETRY, null, polygons);
|
||||
|
||||
final ODataValue value =
|
||||
getClient().getGeospatialValueBuilder().setType(EdmPrimitiveTypeKind.GeometryMultiPolygon).
|
||||
getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeometryMultiPolygon).
|
||||
setValue(primitive).build();
|
||||
assertEquals(EdmPrimitiveTypeKind.GeometryMultiPolygon, value.asGeospatial().getTypeKind());
|
||||
assertEquals(EdmPrimitiveTypeKind.GeometryMultiPolygon, value.asPrimitive().getTypeKind());
|
||||
|
||||
final Iterator<Polygon> iter = value.asGeospatial().toCastValue(MultiPolygon.class).iterator();
|
||||
final Iterator<Polygon> iter = value.asPrimitive().toCastValue(MultiPolygon.class).iterator();
|
||||
|
||||
// second one polygon
|
||||
iter.next();
|
||||
|
@ -504,7 +495,7 @@ public class PrimitiveValueTest extends AbstractTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void manageGeomCollection() {
|
||||
public void manageGeomCollection() throws EdmPrimitiveTypeException {
|
||||
final List<Geospatial> collection = new ArrayList<Geospatial>();
|
||||
|
||||
Point point = new Point(Geospatial.Dimension.GEOMETRY, null);
|
||||
|
@ -522,11 +513,11 @@ public class PrimitiveValueTest extends AbstractTest {
|
|||
final GeospatialCollection primitive = new GeospatialCollection(Geospatial.Dimension.GEOMETRY, null, collection);
|
||||
|
||||
final ODataValue value =
|
||||
getClient().getGeospatialValueBuilder().setType(EdmPrimitiveTypeKind.GeometryCollection).
|
||||
getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeometryCollection).
|
||||
setValue(primitive).build();
|
||||
assertEquals(EdmPrimitiveTypeKind.GeometryCollection, value.asGeospatial().getTypeKind());
|
||||
assertEquals(EdmPrimitiveTypeKind.GeometryCollection, value.asPrimitive().getTypeKind());
|
||||
|
||||
final Iterator<Geospatial> iter = value.asGeospatial().toCastValue(GeospatialCollection.class).iterator();
|
||||
final Iterator<Geospatial> iter = value.asPrimitive().toCastValue(GeospatialCollection.class).iterator();
|
||||
iter.next();
|
||||
final Point collectedPoint = (Point) iter.next();
|
||||
|
||||
|
@ -536,7 +527,7 @@ public class PrimitiveValueTest extends AbstractTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void manageGeogCollection() {
|
||||
public void manageGeogCollection() throws EdmPrimitiveTypeException {
|
||||
final List<Geospatial> collection = new ArrayList<Geospatial>();
|
||||
|
||||
Point point = new Point(Geospatial.Dimension.GEOGRAPHY, null);
|
||||
|
@ -554,11 +545,11 @@ public class PrimitiveValueTest extends AbstractTest {
|
|||
final GeospatialCollection primitive = new GeospatialCollection(Geospatial.Dimension.GEOGRAPHY, null, collection);
|
||||
|
||||
final ODataValue value =
|
||||
getClient().getGeospatialValueBuilder().setType(EdmPrimitiveTypeKind.GeographyCollection).
|
||||
getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeographyCollection).
|
||||
setValue(primitive).build();
|
||||
assertEquals(EdmPrimitiveTypeKind.GeographyCollection, value.asGeospatial().getTypeKind());
|
||||
assertEquals(EdmPrimitiveTypeKind.GeographyCollection, value.asPrimitive().getTypeKind());
|
||||
|
||||
final Iterator<Geospatial> iter = value.asGeospatial().toCastValue(GeospatialCollection.class).iterator();
|
||||
final Iterator<Geospatial> iter = value.asPrimitive().toCastValue(GeospatialCollection.class).iterator();
|
||||
iter.next();
|
||||
final Point collectedPoint = (Point) iter.next();
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ public class MetadataTest extends AbstractTest {
|
|||
assertNotNull(responseStatus);
|
||||
assertTrue(responseStatus.getNavigationPropertyNames().isEmpty());
|
||||
assertEquals("Recipient", responseStatus.getBaseType().getName());
|
||||
assertEquals(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.DateTimeOffset),
|
||||
assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.DateTimeOffset),
|
||||
responseStatus.getProperty("Time").getType());
|
||||
|
||||
// 3. Entity
|
||||
|
@ -107,7 +107,7 @@ public class MetadataTest extends AbstractTest {
|
|||
assertNotNull(move);
|
||||
assertTrue(move.isBound());
|
||||
assertEquals(2, move.getParameterNames().size());
|
||||
assertEquals(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.String),
|
||||
assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String),
|
||||
move.getParameter("DestinationId").getType());
|
||||
|
||||
// 5. EntityContainer
|
||||
|
|
|
@ -24,10 +24,6 @@ import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
|||
|
||||
public final class GeoUtils {
|
||||
|
||||
private GeoUtils() {
|
||||
// Empty private constructor for static utility classes
|
||||
}
|
||||
|
||||
public static Geospatial.Dimension getDimension(final EdmPrimitiveTypeKind type) {
|
||||
Geospatial.Dimension dimension;
|
||||
|
||||
|
@ -87,4 +83,9 @@ public final class GeoUtils {
|
|||
|
||||
return type;
|
||||
}
|
||||
|
||||
private GeoUtils() {
|
||||
// Empty private constructor for static utility classes
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -50,26 +50,6 @@ public abstract class AbstractODataValue implements ODataValue {
|
|||
return isPrimitive() ? (ODataPrimitiveValue) this : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check is is a geospatail value.
|
||||
*
|
||||
* @return 'TRUE' if geospatail; 'FALSE' otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isGeospatial() {
|
||||
return (this instanceof ODataGeospatialValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Casts to geospatail value.
|
||||
*
|
||||
* @return geospatail value.
|
||||
*/
|
||||
@Override
|
||||
public ODataGeospatialValue asGeospatial() {
|
||||
return isGeospatial() ? (ODataGeospatialValue) this : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check is is a complex value.
|
||||
*
|
||||
|
|
|
@ -1,57 +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.commons.api.domain;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmGeospatialType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
||||
|
||||
public interface ODataGeospatialValue extends ODataValue {
|
||||
|
||||
interface Builder {
|
||||
|
||||
Builder setType(EdmPrimitiveTypeKind type);
|
||||
|
||||
Builder setValue(Geospatial value);
|
||||
|
||||
ODataGeospatialValue build();
|
||||
|
||||
}
|
||||
|
||||
EdmPrimitiveTypeKind getTypeKind();
|
||||
|
||||
EdmGeospatialType getType();
|
||||
|
||||
/**
|
||||
* Returns the current geospatial value.
|
||||
*
|
||||
* @return the current geospatial value.
|
||||
*/
|
||||
Geospatial toValue();
|
||||
|
||||
/**
|
||||
* Returns the current value casted to the given type.
|
||||
*
|
||||
* @param <T> cast type
|
||||
* @param reference class reference
|
||||
* @return the current value as typed java instance
|
||||
*/
|
||||
<T extends Geospatial> T toCastValue(Class<T> reference);
|
||||
|
||||
}
|
|
@ -189,15 +189,6 @@ public interface ODataObjectFactory {
|
|||
*/
|
||||
ODataProperty newPrimitiveProperty(String name, ODataPrimitiveValue value);
|
||||
|
||||
/**
|
||||
* Instantiates a new primitive property.
|
||||
*
|
||||
* @param name name.
|
||||
* @param value geospatial value.
|
||||
* @return primitive property.
|
||||
*/
|
||||
ODataProperty newPrimitiveProperty(String name, ODataGeospatialValue value);
|
||||
|
||||
/**
|
||||
* Instantiates a new complex property.
|
||||
*
|
||||
|
|
|
@ -106,24 +106,6 @@ public class ODataProperty implements Serializable, ODataInvokeResult {
|
|||
return hasPrimitiveValue() ? this.value.asPrimitive() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if has geospatial value.
|
||||
*
|
||||
* @return 'TRUE' if has geospatial value; 'FALSE' otherwise.
|
||||
*/
|
||||
public boolean hasGeospatialValue() {
|
||||
return !hasNullValue() && this.value.isGeospatial();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets geospatial value.
|
||||
*
|
||||
* @return geospatial value if exists; null otherwise.
|
||||
*/
|
||||
public ODataGeospatialValue getGeospatialValue() {
|
||||
return hasGeospatialValue() ? this.value.asGeospatial() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if has complex value.
|
||||
*
|
||||
|
|
|
@ -39,20 +39,6 @@ public interface ODataValue extends Serializable {
|
|||
*/
|
||||
ODataPrimitiveValue asPrimitive();
|
||||
|
||||
/**
|
||||
* Check is is a geospatail value.
|
||||
*
|
||||
* @return 'TRUE' if geospatail; 'FALSE' otherwise.
|
||||
*/
|
||||
boolean isGeospatial();
|
||||
|
||||
/**
|
||||
* Casts to geospatail value.
|
||||
*
|
||||
* @return geospatail value.
|
||||
*/
|
||||
ODataGeospatialValue asGeospatial();
|
||||
|
||||
/**
|
||||
* Check is is a collection value.
|
||||
*
|
||||
|
|
|
@ -1,34 +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.commons.api.edm;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
||||
|
||||
public interface EdmGeospatialType extends EdmType {
|
||||
|
||||
String EDM_NAMESPACE = EdmPrimitiveType.EDM_NAMESPACE;
|
||||
|
||||
/**
|
||||
* Returns the Java type for this EDM geospatial type.
|
||||
*
|
||||
* @return the geospatial Java type
|
||||
*/
|
||||
Class<? extends Geospatial> getJavaType();
|
||||
|
||||
}
|
|
@ -31,18 +31,10 @@ public abstract class ComposedGeospatial<T extends Geospatial> extends Geospatia
|
|||
|
||||
protected final List<T> geospatials;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param dimension dimension.
|
||||
* @param type type.
|
||||
* @param crs crs.
|
||||
* @param geospatials geospatials info.
|
||||
*/
|
||||
protected ComposedGeospatial(final Dimension dimension, final Type type, final String crs,
|
||||
protected ComposedGeospatial(final Dimension dimension, final Type type, final Integer srid,
|
||||
final List<T> geospatials) {
|
||||
|
||||
super(dimension, type, crs);
|
||||
super(dimension, type, srid);
|
||||
this.geospatials = new ArrayList<T>();
|
||||
if (geospatials != null) {
|
||||
this.geospatials.addAll(geospatials);
|
||||
|
@ -65,14 +57,4 @@ public abstract class ComposedGeospatial<T extends Geospatial> extends Geospatia
|
|||
public boolean isEmpty() {
|
||||
return geospatials.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc }
|
||||
*/
|
||||
@Override
|
||||
public void setSrid(final Integer srid) {
|
||||
for (Geospatial geospatial : this.geospatials) {
|
||||
geospatial.setSrid(srid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,23 +75,22 @@ public abstract class Geospatial implements Serializable {
|
|||
|
||||
protected final Type type;
|
||||
|
||||
protected String crs;
|
||||
|
||||
/**
|
||||
* Null value means it is expected to vary per instance.
|
||||
*/
|
||||
protected Integer srid;
|
||||
protected final Integer srid;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param dimension dimension.
|
||||
* @param type type.
|
||||
* @param srid SRID
|
||||
*/
|
||||
protected Geospatial(final Dimension dimension, final Type type, final String crs) {
|
||||
protected Geospatial(final Dimension dimension, final Type type, final Integer srid) {
|
||||
this.dimension = dimension;
|
||||
this.type = type;
|
||||
this.crs = crs;
|
||||
this.srid = srid;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,15 +113,6 @@ public abstract class Geospatial implements Serializable {
|
|||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets CRS.
|
||||
*
|
||||
* @return CRS
|
||||
*/
|
||||
public String getCrs() {
|
||||
return crs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets s-rid.
|
||||
*
|
||||
|
@ -132,36 +122,18 @@ public abstract class Geospatial implements Serializable {
|
|||
return srid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets s-rid.
|
||||
*
|
||||
* @param srid s-rid.
|
||||
*/
|
||||
public void setSrid(final Integer srid) {
|
||||
this.srid = srid;
|
||||
}
|
||||
|
||||
public abstract EdmPrimitiveTypeKind getEdmPrimitiveTypeKind();
|
||||
|
||||
/**
|
||||
* {@inheritDoc }
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return EqualsBuilder.reflectionEquals(this, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc }
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc }
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
|
||||
|
|
|
@ -28,21 +28,14 @@ public class GeospatialCollection extends ComposedGeospatial<Geospatial> {
|
|||
|
||||
private static final long serialVersionUID = -9181547636133878977L;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param dimension dimension.
|
||||
* @param crs crs.
|
||||
* @param geospatials geospatials info.
|
||||
*/
|
||||
public GeospatialCollection(final Dimension dimension, final String crs, final List<Geospatial> geospatials) {
|
||||
super(dimension, Type.GEOSPATIALCOLLECTION, crs, geospatials);
|
||||
public GeospatialCollection(final Dimension dimension, final Integer srid, final List<Geospatial> geospatials) {
|
||||
super(dimension, Type.GEOSPATIALCOLLECTION, srid, geospatials);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmPrimitiveTypeKind getEdmPrimitiveTypeKind() {
|
||||
return dimension == Dimension.GEOGRAPHY
|
||||
? EdmPrimitiveTypeKind.GeographyCollection
|
||||
: EdmPrimitiveTypeKind.GeometryCollection;
|
||||
? EdmPrimitiveTypeKind.GeographyCollection
|
||||
: EdmPrimitiveTypeKind.GeometryCollection;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ public class LineString extends ComposedGeospatial<Point> {
|
|||
|
||||
private static final long serialVersionUID = 3207958185407535907L;
|
||||
|
||||
public LineString(final Dimension dimension, final String crs, final List<Point> points) {
|
||||
super(dimension, Type.LINESTRING, crs, points);
|
||||
public LineString(final Dimension dimension, final Integer srid, final List<Point> points) {
|
||||
super(dimension, Type.LINESTRING, srid, points);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,15 +25,15 @@ public class MultiLineString extends ComposedGeospatial<LineString> {
|
|||
|
||||
private static final long serialVersionUID = -5042414471218124125L;
|
||||
|
||||
public MultiLineString(final Dimension dimension, final String crs, final List<LineString> lineStrings) {
|
||||
super(dimension, Type.MULTILINESTRING, crs, lineStrings);
|
||||
public MultiLineString(final Dimension dimension, final Integer srid, final List<LineString> lineStrings) {
|
||||
super(dimension, Type.MULTILINESTRING, srid, lineStrings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmPrimitiveTypeKind getEdmPrimitiveTypeKind() {
|
||||
return dimension == Dimension.GEOGRAPHY
|
||||
? EdmPrimitiveTypeKind.GeographyMultiLineString
|
||||
: EdmPrimitiveTypeKind.GeometryMultiLineString;
|
||||
? EdmPrimitiveTypeKind.GeographyMultiLineString
|
||||
: EdmPrimitiveTypeKind.GeometryMultiLineString;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ public class MultiPoint extends ComposedGeospatial<Point> {
|
|||
|
||||
private static final long serialVersionUID = 4951011255142116129L;
|
||||
|
||||
public MultiPoint(final Dimension dimension, final String crs, final List<Point> points) {
|
||||
super(dimension, Type.MULTIPOINT, crs, points);
|
||||
public MultiPoint(final Dimension dimension, final Integer srid, final List<Point> points) {
|
||||
super(dimension, Type.MULTIPOINT, srid, points);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,14 +25,14 @@ public class MultiPolygon extends ComposedGeospatial<Polygon> {
|
|||
|
||||
private static final long serialVersionUID = -160184788048512883L;
|
||||
|
||||
public MultiPolygon(final Dimension dimension, final String crs, final List<Polygon> polygons) {
|
||||
super(dimension, Type.MULTIPOLYGON, crs, polygons);
|
||||
public MultiPolygon(final Dimension dimension, final Integer srid, final List<Polygon> polygons) {
|
||||
super(dimension, Type.MULTIPOLYGON, srid, polygons);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmPrimitiveTypeKind getEdmPrimitiveTypeKind() {
|
||||
return dimension == Dimension.GEOGRAPHY
|
||||
? EdmPrimitiveTypeKind.GeographyMultiPolygon
|
||||
: EdmPrimitiveTypeKind.GeometryMultiPolygon;
|
||||
? EdmPrimitiveTypeKind.GeographyMultiPolygon
|
||||
: EdmPrimitiveTypeKind.GeometryMultiPolygon;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,8 +40,8 @@ public class Point extends Geospatial {
|
|||
*/
|
||||
private double z;
|
||||
|
||||
public Point(final Dimension dimension, final String crs) {
|
||||
super(dimension, Type.POINT, crs);
|
||||
public Point(final Dimension dimension, final Integer srid) {
|
||||
super(dimension, Type.POINT, srid);
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
|
@ -71,7 +71,7 @@ public class Point extends Geospatial {
|
|||
@Override
|
||||
public EdmPrimitiveTypeKind getEdmPrimitiveTypeKind() {
|
||||
return dimension == Dimension.GEOGRAPHY
|
||||
? EdmPrimitiveTypeKind.GeographyPoint
|
||||
: EdmPrimitiveTypeKind.GeometryPoint;
|
||||
? EdmPrimitiveTypeKind.GeographyPoint
|
||||
: EdmPrimitiveTypeKind.GeometryPoint;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,18 +32,12 @@ public class Polygon extends Geospatial {
|
|||
|
||||
final ComposedGeospatial<Point> exterior;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param dimension dimension.
|
||||
* @param crs crs.
|
||||
* @param interior interior points.
|
||||
* @param exterior exterior points.
|
||||
*/
|
||||
public Polygon(final Dimension dimension, final String crs, final List<Point> interior, final List<Point> exterior) {
|
||||
super(dimension, Type.POLYGON, crs);
|
||||
this.interior = new MultiPoint(dimension, crs, interior);
|
||||
this.exterior = new MultiPoint(dimension, crs, exterior);
|
||||
public Polygon(final Dimension dimension, final Integer srid,
|
||||
final List<Point> interior, final List<Point> exterior) {
|
||||
|
||||
super(dimension, Type.POLYGON, srid);
|
||||
this.interior = new MultiPoint(dimension, srid, interior);
|
||||
this.exterior = new MultiPoint(dimension, srid, exterior);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,7 +44,7 @@ import org.apache.olingo.commons.core.edm.primitivetype.EdmDouble;
|
|||
class AtomGeoValueDeserializer {
|
||||
|
||||
private List<Point> points(final XMLEventReader reader, final StartElement start,
|
||||
final EdmPrimitiveTypeKind type, final String crs) throws XMLStreamException {
|
||||
final EdmPrimitiveTypeKind type, final Integer srid) throws XMLStreamException {
|
||||
|
||||
final List<Point> result = new ArrayList<Point>();
|
||||
|
||||
|
@ -55,7 +55,7 @@ class AtomGeoValueDeserializer {
|
|||
if (event.isCharacters() && !event.asCharacters().isWhiteSpace()) {
|
||||
final String[] pointInfo = event.asCharacters().getData().split(" ");
|
||||
|
||||
final Point point = new Point(GeoUtils.getDimension(type), crs);
|
||||
final Point point = new Point(GeoUtils.getDimension(type), srid);
|
||||
try {
|
||||
point.setX(EdmDouble.getInstance().valueOfString(pointInfo[0], null, null,
|
||||
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, Double.class));
|
||||
|
@ -76,7 +76,7 @@ class AtomGeoValueDeserializer {
|
|||
}
|
||||
|
||||
private MultiPoint multipoint(final XMLEventReader reader, final StartElement start,
|
||||
final EdmPrimitiveTypeKind type, final String crs) throws XMLStreamException {
|
||||
final EdmPrimitiveTypeKind type, final Integer srid) throws XMLStreamException {
|
||||
|
||||
List<Point> points = Collections.<Point>emptyList();
|
||||
|
||||
|
@ -93,17 +93,17 @@ class AtomGeoValueDeserializer {
|
|||
}
|
||||
}
|
||||
|
||||
return new MultiPoint(GeoUtils.getDimension(type), crs, points);
|
||||
return new MultiPoint(GeoUtils.getDimension(type), srid, points);
|
||||
}
|
||||
|
||||
private LineString lineString(final XMLEventReader reader, final StartElement start,
|
||||
final EdmPrimitiveTypeKind type, final String crs) throws XMLStreamException {
|
||||
final EdmPrimitiveTypeKind type, final Integer srid) throws XMLStreamException {
|
||||
|
||||
return new LineString(GeoUtils.getDimension(type), crs, points(reader, start, type, null));
|
||||
return new LineString(GeoUtils.getDimension(type), srid, points(reader, start, type, null));
|
||||
}
|
||||
|
||||
private Polygon polygon(final XMLEventReader reader, final StartElement start,
|
||||
final EdmPrimitiveTypeKind type, final String crs) throws XMLStreamException {
|
||||
final EdmPrimitiveTypeKind type, final Integer srid) throws XMLStreamException {
|
||||
|
||||
List<Point> extPoints = null;
|
||||
List<Point> intPoints = null;
|
||||
|
@ -126,11 +126,11 @@ class AtomGeoValueDeserializer {
|
|||
}
|
||||
}
|
||||
|
||||
return new Polygon(GeoUtils.getDimension(type), crs, intPoints, extPoints);
|
||||
return new Polygon(GeoUtils.getDimension(type), srid, intPoints, extPoints);
|
||||
}
|
||||
|
||||
private MultiLineString multiLineString(final XMLEventReader reader, final StartElement start,
|
||||
final EdmPrimitiveTypeKind type, final String crs) throws XMLStreamException {
|
||||
final EdmPrimitiveTypeKind type, final Integer srid) throws XMLStreamException {
|
||||
|
||||
final List<LineString> lineStrings = new ArrayList<LineString>();
|
||||
|
||||
|
@ -147,11 +147,11 @@ class AtomGeoValueDeserializer {
|
|||
}
|
||||
}
|
||||
|
||||
return new MultiLineString(GeoUtils.getDimension(type), crs, lineStrings);
|
||||
return new MultiLineString(GeoUtils.getDimension(type), srid, lineStrings);
|
||||
}
|
||||
|
||||
private MultiPolygon multiPolygon(final XMLEventReader reader, final StartElement start,
|
||||
final EdmPrimitiveTypeKind type, final String crs) throws XMLStreamException {
|
||||
final EdmPrimitiveTypeKind type, final Integer srid) throws XMLStreamException {
|
||||
|
||||
final List<Polygon> polygons = new ArrayList<Polygon>();
|
||||
|
||||
|
@ -168,11 +168,11 @@ class AtomGeoValueDeserializer {
|
|||
}
|
||||
}
|
||||
|
||||
return new MultiPolygon(GeoUtils.getDimension(type), crs, polygons);
|
||||
return new MultiPolygon(GeoUtils.getDimension(type), srid, polygons);
|
||||
}
|
||||
|
||||
private GeospatialCollection collection(final XMLEventReader reader, final StartElement start,
|
||||
final EdmPrimitiveTypeKind type, final String crs) throws XMLStreamException {
|
||||
final EdmPrimitiveTypeKind type, final Integer srid) throws XMLStreamException {
|
||||
|
||||
final List<Geospatial> geospatials = new ArrayList<Geospatial>();
|
||||
|
||||
|
@ -201,16 +201,16 @@ class AtomGeoValueDeserializer {
|
|||
}
|
||||
}
|
||||
|
||||
return new GeospatialCollection(GeoUtils.getDimension(type), crs, geospatials);
|
||||
return new GeospatialCollection(GeoUtils.getDimension(type), srid, geospatials);
|
||||
}
|
||||
|
||||
public Geospatial deserialize(final XMLEventReader reader, final StartElement start,
|
||||
final EdmPrimitiveTypeKind type) throws XMLStreamException {
|
||||
|
||||
String crs = null;
|
||||
Integer srid = null;
|
||||
final Attribute srsName = start.getAttributeByName(Constants.QNAME_ATTR_SRSNAME);
|
||||
if (srsName != null) {
|
||||
crs = StringUtils.substringAfterLast(srsName.getValue(), "/");
|
||||
srid = Integer.valueOf(StringUtils.substringAfterLast(srsName.getValue(), "/"));
|
||||
}
|
||||
|
||||
Geospatial value;
|
||||
|
@ -218,37 +218,37 @@ class AtomGeoValueDeserializer {
|
|||
switch (type) {
|
||||
case GeographyPoint:
|
||||
case GeometryPoint:
|
||||
value = points(reader, start, type, crs).get(0);
|
||||
value = points(reader, start, type, srid).get(0);
|
||||
break;
|
||||
|
||||
case GeographyMultiPoint:
|
||||
case GeometryMultiPoint:
|
||||
value = multipoint(reader, start, type, crs);
|
||||
value = multipoint(reader, start, type, srid);
|
||||
break;
|
||||
|
||||
case GeographyLineString:
|
||||
case GeometryLineString:
|
||||
value = lineString(reader, start, type, crs);
|
||||
value = lineString(reader, start, type, srid);
|
||||
break;
|
||||
|
||||
case GeographyMultiLineString:
|
||||
case GeometryMultiLineString:
|
||||
value = multiLineString(reader, start, type, crs);
|
||||
value = multiLineString(reader, start, type, srid);
|
||||
break;
|
||||
|
||||
case GeographyPolygon:
|
||||
case GeometryPolygon:
|
||||
value = polygon(reader, start, type, crs);
|
||||
value = polygon(reader, start, type, srid);
|
||||
break;
|
||||
|
||||
case GeographyMultiPolygon:
|
||||
case GeometryMultiPolygon:
|
||||
value = multiPolygon(reader, start, type, crs);
|
||||
value = multiPolygon(reader, start, type, srid);
|
||||
break;
|
||||
|
||||
case GeographyCollection:
|
||||
case GeometryCollection:
|
||||
value = collection(reader, start, type, crs);
|
||||
value = collection(reader, start, type, srid);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -118,9 +118,9 @@ class AtomGeoValueSerializer {
|
|||
}
|
||||
|
||||
private void writeSrsName(final XMLStreamWriter writer, final Geospatial value) throws XMLStreamException {
|
||||
if (value.getCrs() != null) {
|
||||
if (value.getSrid() != null) {
|
||||
writer.writeAttribute(Constants.PREFIX_GML, Constants.NS_GML, Constants.ATTR_SRSNAME,
|
||||
Constants.SRS_URLPREFIX + value.getCrs());
|
||||
Constants.SRS_URLPREFIX + value.getSrid());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,11 +47,11 @@ class JSONGeoValueDeserializer {
|
|||
this.version = version;
|
||||
}
|
||||
|
||||
private Point point(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type, final String crs) {
|
||||
private Point point(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type, final Integer srid) {
|
||||
Point point = null;
|
||||
|
||||
if (itor.hasNext()) {
|
||||
point = new Point(GeoUtils.getDimension(type), crs);
|
||||
point = new Point(GeoUtils.getDimension(type), srid);
|
||||
try {
|
||||
point.setX(EdmDouble.getInstance().valueOfString(itor.next().asText(), null, null,
|
||||
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, Double.class));
|
||||
|
@ -65,46 +65,42 @@ class JSONGeoValueDeserializer {
|
|||
return point;
|
||||
}
|
||||
|
||||
private MultiPoint multipoint(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type,
|
||||
final String crs) {
|
||||
|
||||
private MultiPoint multipoint(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type, final Integer srid) {
|
||||
final MultiPoint multiPoint;
|
||||
|
||||
if (itor.hasNext()) {
|
||||
final List<Point> points = new ArrayList<Point>();
|
||||
while (itor.hasNext()) {
|
||||
final Iterator<JsonNode> mpItor = itor.next().elements();
|
||||
points.add(point(mpItor, type, crs));
|
||||
points.add(point(mpItor, type, srid));
|
||||
}
|
||||
multiPoint = new MultiPoint(GeoUtils.getDimension(type), crs, points);
|
||||
multiPoint = new MultiPoint(GeoUtils.getDimension(type), srid, points);
|
||||
} else {
|
||||
multiPoint = new MultiPoint(GeoUtils.getDimension(type), crs, Collections.<Point>emptyList());
|
||||
multiPoint = new MultiPoint(GeoUtils.getDimension(type), srid, Collections.<Point>emptyList());
|
||||
}
|
||||
|
||||
return multiPoint;
|
||||
}
|
||||
|
||||
private LineString lineString(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type,
|
||||
final String crs) {
|
||||
|
||||
private LineString lineString(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type, final Integer srid) {
|
||||
final LineString lineString;
|
||||
|
||||
if (itor.hasNext()) {
|
||||
final List<Point> points = new ArrayList<Point>();
|
||||
while (itor.hasNext()) {
|
||||
final Iterator<JsonNode> mpItor = itor.next().elements();
|
||||
points.add(point(mpItor, type, crs));
|
||||
points.add(point(mpItor, type, srid));
|
||||
}
|
||||
lineString = new LineString(GeoUtils.getDimension(type), crs, points);
|
||||
lineString = new LineString(GeoUtils.getDimension(type), srid, points);
|
||||
} else {
|
||||
lineString = new LineString(GeoUtils.getDimension(type), crs, Collections.<Point>emptyList());
|
||||
lineString = new LineString(GeoUtils.getDimension(type), srid, Collections.<Point>emptyList());
|
||||
}
|
||||
|
||||
return lineString;
|
||||
}
|
||||
|
||||
private MultiLineString multiLineString(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type,
|
||||
final String crs) {
|
||||
final Integer srid) {
|
||||
|
||||
final MultiLineString multiLineString;
|
||||
|
||||
|
@ -112,18 +108,18 @@ class JSONGeoValueDeserializer {
|
|||
final List<LineString> lineStrings = new ArrayList<LineString>();
|
||||
while (itor.hasNext()) {
|
||||
final Iterator<JsonNode> mlsItor = itor.next().elements();
|
||||
lineStrings.add(lineString(mlsItor, type, crs));
|
||||
lineStrings.add(lineString(mlsItor, type, srid));
|
||||
}
|
||||
multiLineString = new MultiLineString(GeoUtils.getDimension(type), crs, lineStrings);
|
||||
multiLineString = new MultiLineString(GeoUtils.getDimension(type), srid, lineStrings);
|
||||
} else {
|
||||
multiLineString = new MultiLineString(GeoUtils.getDimension(type), crs, Collections.<LineString>emptyList());
|
||||
multiLineString = new MultiLineString(GeoUtils.getDimension(type), srid, Collections.<LineString>emptyList());
|
||||
}
|
||||
|
||||
return multiLineString;
|
||||
}
|
||||
|
||||
private Polygon polygon(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type,
|
||||
final String crs) {
|
||||
final Integer srid) {
|
||||
|
||||
List<Point> extPoints = null;
|
||||
if (itor.hasNext()) {
|
||||
|
@ -132,7 +128,7 @@ class JSONGeoValueDeserializer {
|
|||
extPoints = new ArrayList<Point>();
|
||||
while (extItor.hasNext()) {
|
||||
final Iterator<JsonNode> mpItor = extItor.next().elements();
|
||||
extPoints.add(point(mpItor, type, crs));
|
||||
extPoints.add(point(mpItor, type, srid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -144,16 +140,16 @@ class JSONGeoValueDeserializer {
|
|||
intPoints = new ArrayList<Point>();
|
||||
while (intItor.hasNext()) {
|
||||
final Iterator<JsonNode> mpItor = intItor.next().elements();
|
||||
intPoints.add(point(mpItor, type, crs));
|
||||
intPoints.add(point(mpItor, type, srid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Polygon(GeoUtils.getDimension(type), crs, intPoints, extPoints);
|
||||
return new Polygon(GeoUtils.getDimension(type), srid, intPoints, extPoints);
|
||||
}
|
||||
|
||||
private MultiPolygon multiPolygon(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type,
|
||||
final String crs) {
|
||||
final Integer srid) {
|
||||
|
||||
final MultiPolygon multiPolygon;
|
||||
|
||||
|
@ -161,18 +157,18 @@ class JSONGeoValueDeserializer {
|
|||
final List<Polygon> polygons = new ArrayList<Polygon>();
|
||||
while (itor.hasNext()) {
|
||||
final Iterator<JsonNode> mpItor = itor.next().elements();
|
||||
polygons.add(polygon(mpItor, type, crs));
|
||||
polygons.add(polygon(mpItor, type, srid));
|
||||
}
|
||||
multiPolygon = new MultiPolygon(GeoUtils.getDimension(type), crs, polygons);
|
||||
multiPolygon = new MultiPolygon(GeoUtils.getDimension(type), srid, polygons);
|
||||
} else {
|
||||
multiPolygon = new MultiPolygon(GeoUtils.getDimension(type), crs, Collections.<Polygon>emptyList());
|
||||
multiPolygon = new MultiPolygon(GeoUtils.getDimension(type), srid, Collections.<Polygon>emptyList());
|
||||
}
|
||||
|
||||
return multiPolygon;
|
||||
}
|
||||
|
||||
private GeospatialCollection collection(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type,
|
||||
final String crs) {
|
||||
final Integer srid) {
|
||||
|
||||
final GeospatialCollection collection;
|
||||
|
||||
|
@ -195,9 +191,9 @@ class JSONGeoValueDeserializer {
|
|||
geospatials.add(deserialize(geo, new EdmTypeInfo.Builder().setTypeExpression(callAsType).build()));
|
||||
}
|
||||
|
||||
collection = new GeospatialCollection(GeoUtils.getDimension(type), crs, geospatials);
|
||||
collection = new GeospatialCollection(GeoUtils.getDimension(type), srid, geospatials);
|
||||
} else {
|
||||
collection = new GeospatialCollection(GeoUtils.getDimension(type), crs, Collections.<Geospatial>emptyList());
|
||||
collection = new GeospatialCollection(GeoUtils.getDimension(type), srid, Collections.<Geospatial>emptyList());
|
||||
}
|
||||
|
||||
return collection;
|
||||
|
@ -223,46 +219,47 @@ class JSONGeoValueDeserializer {
|
|||
? node.get(Constants.JSON_COORDINATES).elements()
|
||||
: Collections.<JsonNode>emptyList().iterator();
|
||||
|
||||
String crs = null;
|
||||
Integer srid = null;
|
||||
if (node.has(Constants.JSON_CRS)) {
|
||||
crs = node.get(Constants.JSON_CRS).get(Constants.PROPERTIES).get(Constants.JSON_NAME).asText().split(":")[1];
|
||||
srid = Integer.valueOf(
|
||||
node.get(Constants.JSON_CRS).get(Constants.PROPERTIES).get(Constants.JSON_NAME).asText().split(":")[1]);
|
||||
}
|
||||
|
||||
Geospatial value = null;
|
||||
switch (actualType) {
|
||||
case GeographyPoint:
|
||||
case GeometryPoint:
|
||||
value = point(cooItor, actualType, crs);
|
||||
value = point(cooItor, actualType, srid);
|
||||
break;
|
||||
|
||||
case GeographyMultiPoint:
|
||||
case GeometryMultiPoint:
|
||||
value = multipoint(cooItor, actualType, crs);
|
||||
value = multipoint(cooItor, actualType, srid);
|
||||
break;
|
||||
|
||||
case GeographyLineString:
|
||||
case GeometryLineString:
|
||||
value = lineString(cooItor, actualType, crs);
|
||||
value = lineString(cooItor, actualType, srid);
|
||||
break;
|
||||
|
||||
case GeographyMultiLineString:
|
||||
case GeometryMultiLineString:
|
||||
value = multiLineString(cooItor, actualType, crs);
|
||||
value = multiLineString(cooItor, actualType, srid);
|
||||
break;
|
||||
|
||||
case GeographyPolygon:
|
||||
case GeometryPolygon:
|
||||
value = polygon(cooItor, actualType, crs);
|
||||
value = polygon(cooItor, actualType, srid);
|
||||
break;
|
||||
|
||||
case GeographyMultiPolygon:
|
||||
case GeometryMultiPolygon:
|
||||
value = multiPolygon(cooItor, actualType, crs);
|
||||
value = multiPolygon(cooItor, actualType, srid);
|
||||
break;
|
||||
|
||||
case GeographyCollection:
|
||||
case GeometryCollection:
|
||||
value = collection(node.get(Constants.JSON_GEOMETRIES).elements(), actualType, crs);
|
||||
value = collection(node.get(Constants.JSON_GEOMETRIES).elements(), actualType, srid);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -37,11 +37,11 @@ import org.apache.olingo.commons.core.edm.primitivetype.EdmDouble;
|
|||
|
||||
class JSONGeoValueSerializer {
|
||||
|
||||
private void crs(final JsonGenerator jgen, final String crs) throws IOException {
|
||||
private void srid(final JsonGenerator jgen, final Integer srid) throws IOException {
|
||||
jgen.writeObjectFieldStart(Constants.JSON_CRS);
|
||||
jgen.writeStringField(Constants.ATTR_TYPE, Constants.JSON_NAME);
|
||||
jgen.writeObjectFieldStart(Constants.PROPERTIES);
|
||||
jgen.writeStringField(Constants.JSON_NAME, "EPSG:" + crs);
|
||||
jgen.writeStringField(Constants.JSON_NAME, "EPSG:" + srid);
|
||||
jgen.writeEndObject();
|
||||
jgen.writeEndObject();
|
||||
}
|
||||
|
@ -175,8 +175,8 @@ class JSONGeoValueSerializer {
|
|||
default:
|
||||
}
|
||||
|
||||
if (value.getCrs() != null) {
|
||||
crs(jgen, value.getCrs());
|
||||
if (value.getSrid() != null) {
|
||||
srid(jgen, value.getSrid());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,12 +16,10 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.client.core.domain;
|
||||
package org.apache.olingo.commons.core.domain;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Calendar;
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.apache.olingo.commons.api.Constants;
|
||||
import org.apache.olingo.commons.api.domain.AbstractODataValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
|
@ -56,12 +54,16 @@ public class ODataPrimitiveValueImpl extends AbstractODataValue implements OData
|
|||
throw new IllegalArgumentException(String.format(
|
||||
"Cannot build a primitive value for %s", EdmPrimitiveTypeKind.Stream.toString()));
|
||||
}
|
||||
if (type != null && type.isGeospatial()) {
|
||||
throw new IllegalArgumentException("Don't use this for geospatial types");
|
||||
if (type == EdmPrimitiveTypeKind.Geography || type == EdmPrimitiveTypeKind.Geometry) {
|
||||
throw new IllegalArgumentException(
|
||||
type + "is not an instantiable type. "
|
||||
+ "An entity can declare a property to be of type Geometry. "
|
||||
+ "An instance of an entity MUST NOT have a value of type Geometry. "
|
||||
+ "Each value MUST be of some subtype.");
|
||||
}
|
||||
|
||||
this.instance.typeKind = type == null ? EdmPrimitiveTypeKind.String : type;
|
||||
this.instance.type = EdmPrimitiveTypeFactory.getNonGeoInstance(this.instance.typeKind);
|
||||
this.instance.type = EdmPrimitiveTypeFactory.getInstance(this.instance.typeKind);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@ -154,9 +156,11 @@ public class ODataPrimitiveValueImpl extends AbstractODataValue implements OData
|
|||
|
||||
@Override
|
||||
public <T> T toCastValue(final Class<T> reference) throws EdmPrimitiveTypeException {
|
||||
// TODO: when Edm is available, set facets when calling this method
|
||||
return type.valueOfString(this.text, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null,
|
||||
reference);
|
||||
return typeKind.isGeospatial()
|
||||
? reference.cast(this.value)
|
||||
// TODO: when Edm is available, set facets when calling this method
|
||||
: type.valueOfString(this.text,
|
||||
null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, reference);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -164,14 +168,4 @@ public class ODataPrimitiveValueImpl extends AbstractODataValue implements OData
|
|||
return this.text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return EqualsBuilder.reflectionEquals(this, obj);
|
||||
}
|
||||
|
||||
}
|
|
@ -44,7 +44,7 @@ public abstract class AbstractEdmParameter extends EdmElementImpl implements Edm
|
|||
if (typeImpl == null) {
|
||||
if (EdmPrimitiveType.EDM_NAMESPACE.equals(paramType.getNamespace())) {
|
||||
try {
|
||||
typeImpl = EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.valueOf(paramType.getName()));
|
||||
typeImpl = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.valueOf(paramType.getName()));
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new EdmException("Cannot find type with name: " + paramType, e);
|
||||
}
|
||||
|
|
|
@ -1,76 +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.commons.core.edm.primitivetype;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmGeospatialType;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Type;
|
||||
|
||||
public abstract class AbstractEdmGeospatialType<T extends Geospatial> implements EdmGeospatialType {
|
||||
|
||||
private final Class<T> reference;
|
||||
|
||||
protected final Dimension dimension;
|
||||
|
||||
protected final Type type;
|
||||
|
||||
protected AbstractEdmGeospatialType(final Class<T> reference, final Dimension dimension, final Type type) {
|
||||
this.reference = reference;
|
||||
this.dimension = dimension;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Geospatial> getJavaType() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return EDM_NAMESPACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getClass().getSimpleName().substring(3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmTypeKind getKind() {
|
||||
return EdmTypeKind.PRIMITIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return this == obj || obj != null && getClass() == obj.getClass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getClass().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new FullQualifiedName(getNamespace(), getName()).getFullQualifiedNameAsString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,539 @@
|
|||
/*
|
||||
* 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.commons.core.edm.primitivetype;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Type;
|
||||
import org.apache.olingo.commons.api.edm.geo.GeospatialCollection;
|
||||
import org.apache.olingo.commons.api.edm.geo.LineString;
|
||||
import org.apache.olingo.commons.api.edm.geo.MultiLineString;
|
||||
import org.apache.olingo.commons.api.edm.geo.MultiPoint;
|
||||
import org.apache.olingo.commons.api.edm.geo.MultiPolygon;
|
||||
import org.apache.olingo.commons.api.edm.geo.Point;
|
||||
import org.apache.olingo.commons.api.edm.geo.Polygon;
|
||||
|
||||
public abstract class AbstractGeospatialType<T extends Geospatial> extends SingletonPrimitiveType {
|
||||
|
||||
private static final Pattern PATTERN =
|
||||
Pattern.compile("([a-z]+)'SRID=([0-9]+);([a-zA-Z]+)\\((.*)\\)'");
|
||||
|
||||
private static final Pattern COLLECTION_PATTERN =
|
||||
Pattern.compile("([a-z]+)'SRID=([0-9]+);Collection\\(([a-zA-Z]+)\\((.*)\\)\\)'");
|
||||
|
||||
private final Class<T> reference;
|
||||
|
||||
protected final Dimension dimension;
|
||||
|
||||
protected final Type type;
|
||||
|
||||
protected AbstractGeospatialType(final Class<T> reference, final Dimension dimension, final Type type) {
|
||||
this.reference = reference;
|
||||
this.dimension = dimension;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getDefaultType() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
private Matcher getMatcher(final Pattern pattern, final String value) throws EdmPrimitiveTypeException {
|
||||
final Matcher matcher = pattern.matcher(value);
|
||||
if (!matcher.matches()) {
|
||||
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
|
||||
}
|
||||
|
||||
Geospatial.Dimension _dimension = null;
|
||||
Geospatial.Type _type = null;
|
||||
try {
|
||||
_dimension = Geospatial.Dimension.valueOf(matcher.group(1).toUpperCase());
|
||||
_type = Geospatial.Type.valueOf(matcher.group(3).toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
|
||||
}
|
||||
if (_dimension != this.dimension || (!pattern.equals(COLLECTION_PATTERN) && _type != this.type)) {
|
||||
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
|
||||
}
|
||||
|
||||
return matcher;
|
||||
}
|
||||
|
||||
private Point newPoint(final Integer srid, final String point, final Boolean isNullable,
|
||||
final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode)
|
||||
throws EdmPrimitiveTypeException {
|
||||
|
||||
final String[] pointCoo = StringUtils.split(point, ' ');
|
||||
if (pointCoo == null || pointCoo.length != 2) {
|
||||
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
|
||||
}
|
||||
|
||||
final Point result = new Point(this.dimension, srid);
|
||||
result.setX(EdmDouble.getInstance().valueOfString(pointCoo[0],
|
||||
isNullable, maxLength, precision, scale, isUnicode, Double.class));
|
||||
result.setY(EdmDouble.getInstance().valueOfString(pointCoo[1],
|
||||
isNullable, maxLength, precision, scale, isUnicode, Double.class));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Point stringToPoint(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
final Matcher matcher = getMatcher(PATTERN, value);
|
||||
|
||||
return newPoint(Integer.valueOf(matcher.group(2)), matcher.group(4),
|
||||
isNullable, maxLength, precision, scale, isUnicode);
|
||||
}
|
||||
|
||||
protected MultiPoint stringToMultiPoint(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
final Matcher matcher = getMatcher(PATTERN, value);
|
||||
|
||||
final List<Point> points = new ArrayList<Point>();
|
||||
for (String pointCoo : StringUtils.split(matcher.group(4), ',')) {
|
||||
points.add(newPoint(null, pointCoo.substring(1, pointCoo.length() - 1),
|
||||
isNullable, maxLength, precision, scale, isUnicode));
|
||||
}
|
||||
|
||||
return new MultiPoint(dimension, Integer.valueOf(matcher.group(2)), points);
|
||||
}
|
||||
|
||||
private LineString newLineString(final Integer srid, final String lineString, final Boolean isNullable,
|
||||
final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode)
|
||||
throws EdmPrimitiveTypeException {
|
||||
|
||||
final List<Point> points = new ArrayList<Point>();
|
||||
for (String pointCoo : StringUtils.split(lineString, ',')) {
|
||||
points.add(newPoint(null, pointCoo, isNullable, maxLength, precision, scale, isUnicode));
|
||||
}
|
||||
|
||||
return new LineString(this.dimension, srid, points);
|
||||
}
|
||||
|
||||
protected LineString stringToLineString(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
final Matcher matcher = getMatcher(PATTERN, value);
|
||||
|
||||
return newLineString(Integer.valueOf(matcher.group(2)), matcher.group(4),
|
||||
isNullable, maxLength, precision, scale, isUnicode);
|
||||
}
|
||||
|
||||
protected MultiLineString stringToMultiLineString(final String value, final Boolean isNullable,
|
||||
final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode)
|
||||
throws EdmPrimitiveTypeException {
|
||||
|
||||
final Matcher matcher = getMatcher(PATTERN, value);
|
||||
|
||||
final List<LineString> lineStrings = new ArrayList<LineString>();
|
||||
for (String coo : matcher.group(4).contains("),(")
|
||||
? matcher.group(4).split("\\),\\(") : new String[] {matcher.group(4)}) {
|
||||
|
||||
String lineString = coo;
|
||||
if (lineString.charAt(0) == '(') {
|
||||
lineString = lineString.substring(1);
|
||||
}
|
||||
if (lineString.endsWith(")")) {
|
||||
lineString = StringUtils.substringBeforeLast(lineString, ")");
|
||||
}
|
||||
|
||||
lineStrings.add(newLineString(null, lineString, isNullable, maxLength, precision, scale, isUnicode));
|
||||
}
|
||||
|
||||
return new MultiLineString(this.dimension, Integer.valueOf(matcher.group(2)), lineStrings);
|
||||
}
|
||||
|
||||
private Polygon newPolygon(final Integer srid, final String polygon, final Boolean isNullable,
|
||||
final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode)
|
||||
throws EdmPrimitiveTypeException {
|
||||
|
||||
final String[] first = polygon.split("\\),\\(");
|
||||
|
||||
final List<Point> interior = new ArrayList<Point>();
|
||||
for (String pointCoo : StringUtils.split(first[0].substring(1, first[0].length()), ',')) {
|
||||
interior.add(newPoint(null, pointCoo, isNullable, maxLength, precision, scale, isUnicode));
|
||||
}
|
||||
final List<Point> exterior = new ArrayList<Point>();
|
||||
for (String pointCoo : StringUtils.split(first[1].substring(0, first[1].length() - 1), ',')) {
|
||||
exterior.add(newPoint(null, pointCoo, isNullable, maxLength, precision, scale, isUnicode));
|
||||
}
|
||||
|
||||
return new Polygon(dimension, srid, interior, exterior);
|
||||
}
|
||||
|
||||
protected Polygon stringToPolygon(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
final Matcher matcher = getMatcher(PATTERN, value);
|
||||
|
||||
return newPolygon(Integer.valueOf(matcher.group(2)), matcher.group(4),
|
||||
isNullable, maxLength, precision, scale, isUnicode);
|
||||
}
|
||||
|
||||
protected MultiPolygon stringToMultiPolygon(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
final Matcher matcher = getMatcher(PATTERN, value);
|
||||
|
||||
final List<Polygon> polygons = new ArrayList<Polygon>();
|
||||
for (String coo : matcher.group(4).contains(")),((")
|
||||
? matcher.group(4).split("\\)\\),\\(\\(") : new String[] {matcher.group(4)}) {
|
||||
|
||||
String polygon = coo;
|
||||
if (polygon.startsWith("((")) {
|
||||
polygon = polygon.substring(1);
|
||||
}
|
||||
if (polygon.endsWith("))")) {
|
||||
polygon = StringUtils.substringBeforeLast(polygon, ")");
|
||||
}
|
||||
if (polygon.charAt(0) != '(') {
|
||||
polygon = "(" + polygon;
|
||||
}
|
||||
if (!polygon.endsWith(")")) {
|
||||
polygon += ")";
|
||||
}
|
||||
|
||||
polygons.add(newPolygon(null, polygon, isNullable, maxLength, precision, scale, isUnicode));
|
||||
}
|
||||
|
||||
return new MultiPolygon(dimension, Integer.valueOf(matcher.group(2)), polygons);
|
||||
}
|
||||
|
||||
protected GeospatialCollection stringToCollection(final String value, final Boolean isNullable,
|
||||
final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode)
|
||||
throws EdmPrimitiveTypeException {
|
||||
|
||||
final Matcher matcher = getMatcher(COLLECTION_PATTERN, value);
|
||||
|
||||
Geospatial item = null;
|
||||
switch (Geospatial.Type.valueOf(matcher.group(3).toUpperCase())) {
|
||||
case POINT:
|
||||
item = newPoint(Integer.valueOf(matcher.group(2)), matcher.group(4),
|
||||
isNullable, maxLength, precision, scale, isUnicode);
|
||||
break;
|
||||
|
||||
case MULTIPOINT:
|
||||
final List<Point> points = new ArrayList<Point>();
|
||||
for (String pointCoo : StringUtils.split(matcher.group(4), ',')) {
|
||||
points.add(newPoint(null, pointCoo.substring(1, pointCoo.length() - 1),
|
||||
isNullable, maxLength, precision, scale, isUnicode));
|
||||
}
|
||||
|
||||
item = new MultiPoint(dimension, Integer.valueOf(matcher.group(2)), points);
|
||||
break;
|
||||
|
||||
case LINESTRING:
|
||||
item = newLineString(Integer.valueOf(matcher.group(2)), matcher.group(4),
|
||||
isNullable, maxLength, precision, scale, isUnicode);
|
||||
break;
|
||||
|
||||
case MULTILINESTRING:
|
||||
final List<LineString> lineStrings = new ArrayList<LineString>();
|
||||
for (String coo : StringUtils.split(matcher.group(4), ',')) {
|
||||
lineStrings.add(newLineString(null, coo.substring(1, coo.length() - 1),
|
||||
isNullable, maxLength, precision, scale, isUnicode));
|
||||
}
|
||||
|
||||
item = new MultiLineString(this.dimension, Integer.valueOf(matcher.group(2)), lineStrings);
|
||||
break;
|
||||
|
||||
case POLYGON:
|
||||
item = newPolygon(Integer.valueOf(matcher.group(2)), matcher.group(4),
|
||||
isNullable, maxLength, precision, scale, isUnicode);
|
||||
break;
|
||||
|
||||
case MULTIPOLYGON:
|
||||
final List<Polygon> polygons = new ArrayList<Polygon>();
|
||||
for (String coo : StringUtils.split(matcher.group(4), ',')) {
|
||||
polygons.add(newPolygon(null, coo.substring(1, coo.length() - 1),
|
||||
isNullable, maxLength, precision, scale, isUnicode));
|
||||
}
|
||||
|
||||
item = new MultiPolygon(dimension, Integer.valueOf(matcher.group(2)), polygons);
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
|
||||
return new GeospatialCollection(dimension, Integer.valueOf(matcher.group(2)),
|
||||
Collections.<Geospatial>singletonList(item));
|
||||
}
|
||||
|
||||
private StringBuilder toStringBuilder(final Integer srid) {
|
||||
return new StringBuilder(dimension.name().toLowerCase()).append('\'').
|
||||
append("SRID=").append(srid).append(';');
|
||||
}
|
||||
|
||||
private String point(final Point point, final Boolean isNullable,
|
||||
final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode)
|
||||
throws EdmPrimitiveTypeException {
|
||||
|
||||
return new StringBuilder().
|
||||
append(EdmDouble.getInstance().valueToString(point.getX(),
|
||||
isNullable, maxLength, precision, scale, isUnicode)).
|
||||
append(' ').
|
||||
append(EdmDouble.getInstance().valueToString(point.getY(),
|
||||
isNullable, maxLength, precision, scale, isUnicode)).
|
||||
toString();
|
||||
}
|
||||
|
||||
protected String toString(final Point point, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (dimension != point.getDimension()) {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
|
||||
}
|
||||
|
||||
return toStringBuilder(point.getSrid()).
|
||||
append(reference.getSimpleName()).
|
||||
append('(').
|
||||
append(point(point, isNullable, maxLength, precision, scale, isUnicode)).
|
||||
append(")'").
|
||||
toString();
|
||||
}
|
||||
|
||||
protected String toString(final MultiPoint multiPoint, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (dimension != multiPoint.getDimension()) {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
|
||||
}
|
||||
|
||||
final StringBuilder result = toStringBuilder(multiPoint.getSrid()).
|
||||
append(reference.getSimpleName()).
|
||||
append('(');
|
||||
|
||||
for (final Iterator<Point> itor = multiPoint.iterator(); itor.hasNext();) {
|
||||
result.append('(').
|
||||
append(point(itor.next(), isNullable, maxLength, precision, scale, isUnicode)).
|
||||
append(')');
|
||||
if (itor.hasNext()) {
|
||||
result.append(',');
|
||||
}
|
||||
}
|
||||
|
||||
return result.append(")'").toString();
|
||||
}
|
||||
|
||||
private String lineString(final LineString lineString, final Boolean isNullable,
|
||||
final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode)
|
||||
throws EdmPrimitiveTypeException {
|
||||
|
||||
final StringBuilder result = new StringBuilder();
|
||||
|
||||
for (final Iterator<Point> itor = lineString.iterator(); itor.hasNext();) {
|
||||
result.append(point(itor.next(), isNullable, maxLength, precision, scale, isUnicode));
|
||||
if (itor.hasNext()) {
|
||||
result.append(',');
|
||||
}
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
protected String toString(final LineString lineString, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (dimension != lineString.getDimension()) {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
|
||||
}
|
||||
|
||||
return toStringBuilder(lineString.getSrid()).
|
||||
append(reference.getSimpleName()).
|
||||
append('(').
|
||||
append(lineString(lineString, isNullable, maxLength, precision, scale, isUnicode)).
|
||||
append(")'").toString();
|
||||
}
|
||||
|
||||
protected String toString(final MultiLineString multiLineString, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (dimension != multiLineString.getDimension()) {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
|
||||
}
|
||||
|
||||
final StringBuilder result = toStringBuilder(multiLineString.getSrid()).
|
||||
append(reference.getSimpleName()).
|
||||
append('(');
|
||||
|
||||
for (final Iterator<LineString> itor = multiLineString.iterator(); itor.hasNext();) {
|
||||
result.append('(').
|
||||
append(lineString(itor.next(), isNullable, maxLength, precision, scale, isUnicode)).
|
||||
append(')');
|
||||
if (itor.hasNext()) {
|
||||
result.append(',');
|
||||
}
|
||||
}
|
||||
|
||||
return result.append(")'").toString();
|
||||
}
|
||||
|
||||
private String polygon(final Polygon polygon, final Boolean isNullable,
|
||||
final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode)
|
||||
throws EdmPrimitiveTypeException {
|
||||
|
||||
final StringBuilder result = new StringBuilder();
|
||||
|
||||
result.append('(');
|
||||
for (final Iterator<Point> itor = polygon.getInterior().iterator(); itor.hasNext();) {
|
||||
result.append(point(itor.next(), isNullable, maxLength, precision, scale, isUnicode));
|
||||
if (itor.hasNext()) {
|
||||
result.append(',');
|
||||
}
|
||||
}
|
||||
result.append("),(");
|
||||
for (final Iterator<Point> itor = polygon.getExterior().iterator(); itor.hasNext();) {
|
||||
result.append(point(itor.next(), isNullable, maxLength, precision, scale, isUnicode));
|
||||
if (itor.hasNext()) {
|
||||
result.append(',');
|
||||
}
|
||||
}
|
||||
|
||||
return result.append(')').toString();
|
||||
}
|
||||
|
||||
protected String toString(final Polygon polygon, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (dimension != polygon.getDimension()) {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
|
||||
}
|
||||
|
||||
return toStringBuilder(polygon.getSrid()).
|
||||
append(reference.getSimpleName()).
|
||||
append('(').
|
||||
append(polygon(polygon, isNullable, maxLength, precision, scale, isUnicode)).
|
||||
append(")'").toString();
|
||||
}
|
||||
|
||||
protected String toString(final MultiPolygon multiPolygon, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (dimension != multiPolygon.getDimension()) {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
|
||||
}
|
||||
|
||||
final StringBuilder result = toStringBuilder(multiPolygon.getSrid()).
|
||||
append(reference.getSimpleName()).
|
||||
append('(');
|
||||
|
||||
for (final Iterator<Polygon> itor = multiPolygon.iterator(); itor.hasNext();) {
|
||||
result.append('(').
|
||||
append(polygon(itor.next(), isNullable, maxLength, precision, scale, isUnicode)).
|
||||
append(')');
|
||||
if (itor.hasNext()) {
|
||||
result.append(',');
|
||||
}
|
||||
}
|
||||
|
||||
return result.append(")'").toString();
|
||||
}
|
||||
|
||||
protected String toString(final GeospatialCollection collection, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (dimension != collection.getDimension()) {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
|
||||
}
|
||||
|
||||
final StringBuilder result = toStringBuilder(collection.getSrid()).
|
||||
append("Collection(");
|
||||
|
||||
if (collection.iterator().hasNext()) {
|
||||
final Geospatial item = collection.iterator().next();
|
||||
result.append(item.getClass().getSimpleName()).append('(');
|
||||
|
||||
switch (item.getEdmPrimitiveTypeKind()) {
|
||||
case GeographyPoint:
|
||||
case GeometryPoint:
|
||||
result.append(point((Point) item, isNullable, maxLength, precision, scale, isUnicode));
|
||||
break;
|
||||
|
||||
case GeographyMultiPoint:
|
||||
case GeometryMultiPoint:
|
||||
for (final Iterator<Point> itor = ((MultiPoint) item).iterator(); itor.hasNext();) {
|
||||
result.append('(').
|
||||
append(point(itor.next(), isNullable, maxLength, precision, scale, isUnicode)).
|
||||
append(')');
|
||||
if (itor.hasNext()) {
|
||||
result.append(',');
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case GeographyLineString:
|
||||
case GeometryLineString:
|
||||
result.append(lineString((LineString) item, isNullable, maxLength, precision, scale, isUnicode));
|
||||
break;
|
||||
|
||||
case GeographyMultiLineString:
|
||||
case GeometryMultiLineString:
|
||||
for (final Iterator<LineString> itor = ((MultiLineString) item).iterator(); itor.hasNext();) {
|
||||
result.append('(').
|
||||
append(lineString(itor.next(), isNullable, maxLength, precision, scale, isUnicode)).
|
||||
append(')');
|
||||
if (itor.hasNext()) {
|
||||
result.append(',');
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case GeographyPolygon:
|
||||
case GeometryPolygon:
|
||||
result.append(polygon((Polygon) item, isNullable, maxLength, precision, scale, isUnicode));
|
||||
break;
|
||||
|
||||
case GeographyMultiPolygon:
|
||||
case GeometryMultiPolygon:
|
||||
for (final Iterator<Polygon> itor = ((MultiPolygon) item).iterator(); itor.hasNext();) {
|
||||
result.append('(').
|
||||
append(polygon(itor.next(), isNullable, maxLength, precision, scale, isUnicode)).
|
||||
append(')');
|
||||
if (itor.hasNext()) {
|
||||
result.append(',');
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
|
||||
result.append(')');
|
||||
}
|
||||
|
||||
return result.append(")'").toString();
|
||||
}
|
||||
}
|
|
@ -18,10 +18,11 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.primitivetype;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
|
||||
|
||||
public final class EdmGeography extends AbstractEdmGeospatialType<Geospatial> {
|
||||
public final class EdmGeography extends AbstractGeospatialType<Geospatial> {
|
||||
|
||||
private static final EdmGeography INSTANCE = new EdmGeography();
|
||||
|
||||
|
@ -33,4 +34,20 @@ public final class EdmGeography extends AbstractEdmGeospatialType<Geospatial> {
|
|||
super(Geospatial.class, Dimension.GEOGRAPHY, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType)
|
||||
throws EdmPrimitiveTypeException {
|
||||
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.primitivetype;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Type;
|
||||
import org.apache.olingo.commons.api.edm.geo.Point;
|
||||
import org.apache.olingo.commons.api.edm.geo.GeospatialCollection;
|
||||
|
||||
public final class EdmGeographyCollection extends AbstractEdmGeospatialType<Point> {
|
||||
public final class EdmGeographyCollection extends AbstractGeospatialType<GeospatialCollection> {
|
||||
|
||||
private static final EdmGeographyCollection INSTANCE = new EdmGeographyCollection();
|
||||
|
||||
|
@ -31,7 +32,33 @@ public final class EdmGeographyCollection extends AbstractEdmGeospatialType<Poin
|
|||
}
|
||||
|
||||
public EdmGeographyCollection() {
|
||||
super(Point.class, Dimension.GEOGRAPHY, Type.GEOSPATIALCOLLECTION);
|
||||
super(GeospatialCollection.class, Dimension.GEOGRAPHY, Type.GEOSPATIALCOLLECTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode,
|
||||
final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
final GeospatialCollection collection =
|
||||
stringToCollection(value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
if (returnType.isAssignableFrom(GeospatialCollection.class)) {
|
||||
return returnType.cast(collection);
|
||||
} else {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (value instanceof GeospatialCollection) {
|
||||
return toString((GeospatialCollection) value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
}
|
||||
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.primitivetype;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Type;
|
||||
import org.apache.olingo.commons.api.edm.geo.Point;
|
||||
import org.apache.olingo.commons.api.edm.geo.LineString;
|
||||
|
||||
public final class EdmGeographyLineString extends AbstractEdmGeospatialType<Point> {
|
||||
public final class EdmGeographyLineString extends AbstractGeospatialType<LineString> {
|
||||
|
||||
private static final EdmGeographyLineString INSTANCE = new EdmGeographyLineString();
|
||||
|
||||
|
@ -31,7 +32,32 @@ public final class EdmGeographyLineString extends AbstractEdmGeospatialType<Poin
|
|||
}
|
||||
|
||||
public EdmGeographyLineString() {
|
||||
super(Point.class, Dimension.GEOGRAPHY, Type.LINESTRING);
|
||||
super(LineString.class, Dimension.GEOGRAPHY, Type.LINESTRING);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode,
|
||||
final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
final LineString lineString = stringToLineString(value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
if (returnType.isAssignableFrom(LineString.class)) {
|
||||
return returnType.cast(lineString);
|
||||
} else {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (value instanceof LineString) {
|
||||
return toString((LineString) value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
}
|
||||
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.primitivetype;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Type;
|
||||
import org.apache.olingo.commons.api.edm.geo.Point;
|
||||
import org.apache.olingo.commons.api.edm.geo.MultiLineString;
|
||||
|
||||
public final class EdmGeographyMultiLineString extends AbstractEdmGeospatialType<Point> {
|
||||
public final class EdmGeographyMultiLineString extends AbstractGeospatialType<MultiLineString> {
|
||||
|
||||
private static final EdmGeographyMultiLineString INSTANCE = new EdmGeographyMultiLineString();
|
||||
|
||||
|
@ -31,7 +32,33 @@ public final class EdmGeographyMultiLineString extends AbstractEdmGeospatialType
|
|||
}
|
||||
|
||||
public EdmGeographyMultiLineString() {
|
||||
super(Point.class, Dimension.GEOGRAPHY, Type.MULTILINESTRING);
|
||||
super(MultiLineString.class, Dimension.GEOGRAPHY, Type.MULTILINESTRING);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode,
|
||||
final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
final MultiLineString multiLineString =
|
||||
stringToMultiLineString(value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
if (returnType.isAssignableFrom(MultiLineString.class)) {
|
||||
return returnType.cast(multiLineString);
|
||||
} else {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (value instanceof MultiLineString) {
|
||||
return toString((MultiLineString) value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
}
|
||||
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,13 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.primitivetype;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Type;
|
||||
import org.apache.olingo.commons.api.edm.geo.MultiPoint;
|
||||
import org.apache.olingo.commons.api.edm.geo.Point;
|
||||
|
||||
public final class EdmGeographyMultiPoint extends AbstractEdmGeospatialType<Point> {
|
||||
public final class EdmGeographyMultiPoint extends AbstractGeospatialType<MultiPoint> {
|
||||
|
||||
private static final EdmGeographyMultiPoint INSTANCE = new EdmGeographyMultiPoint();
|
||||
|
||||
|
@ -31,7 +33,34 @@ public final class EdmGeographyMultiPoint extends AbstractEdmGeospatialType<Poin
|
|||
}
|
||||
|
||||
public EdmGeographyMultiPoint() {
|
||||
super(Point.class, Dimension.GEOGRAPHY, Type.MULTIPOINT);
|
||||
super(MultiPoint.class, Dimension.GEOGRAPHY, Type.MULTIPOINT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType)
|
||||
throws EdmPrimitiveTypeException {
|
||||
|
||||
final MultiPoint point = stringToMultiPoint(value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
if (returnType.isAssignableFrom(MultiPoint.class)) {
|
||||
return returnType.cast(point);
|
||||
} else {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (value instanceof MultiPoint) {
|
||||
return toString((MultiPoint) value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
}
|
||||
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.primitivetype;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Type;
|
||||
import org.apache.olingo.commons.api.edm.geo.Point;
|
||||
import org.apache.olingo.commons.api.edm.geo.MultiPolygon;
|
||||
|
||||
public final class EdmGeographyMultiPolygon extends AbstractEdmGeospatialType<Point> {
|
||||
public final class EdmGeographyMultiPolygon extends AbstractGeospatialType<MultiPolygon> {
|
||||
|
||||
private static final EdmGeographyMultiPolygon INSTANCE = new EdmGeographyMultiPolygon();
|
||||
|
||||
|
@ -31,7 +32,32 @@ public final class EdmGeographyMultiPolygon extends AbstractEdmGeospatialType<Po
|
|||
}
|
||||
|
||||
public EdmGeographyMultiPolygon() {
|
||||
super(Point.class, Dimension.GEOGRAPHY, Type.MULTIPOLYGON);
|
||||
super(MultiPolygon.class, Dimension.GEOGRAPHY, Type.MULTIPOLYGON);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode,
|
||||
final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
final MultiPolygon multiPolygon = stringToMultiPolygon(value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
if (returnType.isAssignableFrom(MultiPolygon.class)) {
|
||||
return returnType.cast(multiPolygon);
|
||||
} else {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (value instanceof MultiPolygon) {
|
||||
return toString((MultiPolygon) value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
}
|
||||
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.primitivetype;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Type;
|
||||
import org.apache.olingo.commons.api.edm.geo.Point;
|
||||
|
||||
public final class EdmGeographyPoint extends AbstractEdmGeospatialType<Point> {
|
||||
public final class EdmGeographyPoint extends AbstractGeospatialType<Point> {
|
||||
|
||||
private static final EdmGeographyPoint INSTANCE = new EdmGeographyPoint();
|
||||
|
||||
|
@ -34,4 +35,30 @@ public final class EdmGeographyPoint extends AbstractEdmGeospatialType<Point> {
|
|||
super(Point.class, Dimension.GEOGRAPHY, Type.POINT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode,
|
||||
final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
final Point point = stringToPoint(value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
if (returnType.isAssignableFrom(Point.class)) {
|
||||
return returnType.cast(point);
|
||||
} else {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (value instanceof Point) {
|
||||
return toString((Point) value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
}
|
||||
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.primitivetype;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Type;
|
||||
import org.apache.olingo.commons.api.edm.geo.Point;
|
||||
import org.apache.olingo.commons.api.edm.geo.Polygon;
|
||||
|
||||
public final class EdmGeographyPolygon extends AbstractEdmGeospatialType<Point> {
|
||||
public final class EdmGeographyPolygon extends AbstractGeospatialType<Polygon> {
|
||||
|
||||
private static final EdmGeographyPolygon INSTANCE = new EdmGeographyPolygon();
|
||||
|
||||
|
@ -31,7 +32,32 @@ public final class EdmGeographyPolygon extends AbstractEdmGeospatialType<Point>
|
|||
}
|
||||
|
||||
public EdmGeographyPolygon() {
|
||||
super(Point.class, Dimension.GEOGRAPHY, Type.POLYGON);
|
||||
super(Polygon.class, Dimension.GEOGRAPHY, Type.POLYGON);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode,
|
||||
final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
final Polygon polygon = stringToPolygon(value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
if (returnType.isAssignableFrom(Polygon.class)) {
|
||||
return returnType.cast(polygon);
|
||||
} else {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (value instanceof Polygon) {
|
||||
return toString((Polygon) value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
}
|
||||
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,10 +18,11 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.primitivetype;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
|
||||
|
||||
public final class EdmGeometry extends AbstractEdmGeospatialType<Geospatial> {
|
||||
public final class EdmGeometry extends AbstractGeospatialType<Geospatial> {
|
||||
|
||||
private static final EdmGeometry INSTANCE = new EdmGeometry();
|
||||
|
||||
|
@ -33,4 +34,20 @@ public final class EdmGeometry extends AbstractEdmGeospatialType<Geospatial> {
|
|||
super(Geospatial.class, Dimension.GEOMETRY, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType)
|
||||
throws EdmPrimitiveTypeException {
|
||||
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,13 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.primitivetype;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Type;
|
||||
import org.apache.olingo.commons.api.edm.geo.GeospatialCollection;
|
||||
import org.apache.olingo.commons.api.edm.geo.Point;
|
||||
|
||||
public final class EdmGeometryCollection extends AbstractEdmGeospatialType<Point> {
|
||||
public final class EdmGeometryCollection extends AbstractGeospatialType<GeospatialCollection> {
|
||||
|
||||
private static final EdmGeometryCollection INSTANCE = new EdmGeometryCollection();
|
||||
|
||||
|
@ -31,7 +33,33 @@ public final class EdmGeometryCollection extends AbstractEdmGeospatialType<Point
|
|||
}
|
||||
|
||||
public EdmGeometryCollection() {
|
||||
super(Point.class, Dimension.GEOMETRY, Type.GEOSPATIALCOLLECTION);
|
||||
super(GeospatialCollection.class, Dimension.GEOMETRY, Type.GEOSPATIALCOLLECTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode,
|
||||
final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
final GeospatialCollection collection =
|
||||
stringToCollection(value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
if (returnType.isAssignableFrom(GeospatialCollection.class)) {
|
||||
return returnType.cast(collection);
|
||||
} else {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (value instanceof GeospatialCollection) {
|
||||
return toString((GeospatialCollection) value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
}
|
||||
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.primitivetype;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Type;
|
||||
import org.apache.olingo.commons.api.edm.geo.Point;
|
||||
import org.apache.olingo.commons.api.edm.geo.LineString;
|
||||
|
||||
public final class EdmGeometryLineString extends AbstractEdmGeospatialType<Point> {
|
||||
public final class EdmGeometryLineString extends AbstractGeospatialType<LineString> {
|
||||
|
||||
private static final EdmGeometryLineString INSTANCE = new EdmGeometryLineString();
|
||||
|
||||
|
@ -31,7 +32,32 @@ public final class EdmGeometryLineString extends AbstractEdmGeospatialType<Point
|
|||
}
|
||||
|
||||
public EdmGeometryLineString() {
|
||||
super(Point.class, Dimension.GEOMETRY, Type.LINESTRING);
|
||||
super(LineString.class, Dimension.GEOMETRY, Type.LINESTRING);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode,
|
||||
final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
final LineString lineString = stringToLineString(value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
if (returnType.isAssignableFrom(LineString.class)) {
|
||||
return returnType.cast(lineString);
|
||||
} else {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (value instanceof LineString) {
|
||||
return toString((LineString) value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
}
|
||||
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.primitivetype;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Type;
|
||||
import org.apache.olingo.commons.api.edm.geo.Point;
|
||||
import org.apache.olingo.commons.api.edm.geo.MultiLineString;
|
||||
|
||||
public final class EdmGeometryMultiLineString extends AbstractEdmGeospatialType<Point> {
|
||||
public final class EdmGeometryMultiLineString extends AbstractGeospatialType<MultiLineString> {
|
||||
|
||||
private static final EdmGeometryMultiLineString INSTANCE = new EdmGeometryMultiLineString();
|
||||
|
||||
|
@ -31,7 +32,33 @@ public final class EdmGeometryMultiLineString extends AbstractEdmGeospatialType<
|
|||
}
|
||||
|
||||
public EdmGeometryMultiLineString() {
|
||||
super(Point.class, Dimension.GEOMETRY, Type.MULTILINESTRING);
|
||||
super(MultiLineString.class, Dimension.GEOMETRY, Type.MULTILINESTRING);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode,
|
||||
final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
final MultiLineString multiLineString =
|
||||
stringToMultiLineString(value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
if (returnType.isAssignableFrom(MultiLineString.class)) {
|
||||
return returnType.cast(multiLineString);
|
||||
} else {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (value instanceof MultiLineString) {
|
||||
return toString((MultiLineString) value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
}
|
||||
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.primitivetype;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Type;
|
||||
import org.apache.olingo.commons.api.edm.geo.Point;
|
||||
import org.apache.olingo.commons.api.edm.geo.MultiPoint;
|
||||
|
||||
public final class EdmGeometryMultiPoint extends AbstractEdmGeospatialType<Point> {
|
||||
public final class EdmGeometryMultiPoint extends AbstractGeospatialType<MultiPoint> {
|
||||
|
||||
private static final EdmGeometryMultiPoint INSTANCE = new EdmGeometryMultiPoint();
|
||||
|
||||
|
@ -31,7 +32,33 @@ public final class EdmGeometryMultiPoint extends AbstractEdmGeospatialType<Point
|
|||
}
|
||||
|
||||
public EdmGeometryMultiPoint() {
|
||||
super(Point.class, Dimension.GEOMETRY, Type.MULTIPOINT);
|
||||
super(MultiPoint.class, Dimension.GEOMETRY, Type.MULTIPOINT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType)
|
||||
throws EdmPrimitiveTypeException {
|
||||
|
||||
final MultiPoint point = stringToMultiPoint(value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
if (returnType.isAssignableFrom(MultiPoint.class)) {
|
||||
return returnType.cast(point);
|
||||
} else {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (value instanceof MultiPoint) {
|
||||
return toString((MultiPoint) value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
}
|
||||
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.primitivetype;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Type;
|
||||
import org.apache.olingo.commons.api.edm.geo.Point;
|
||||
import org.apache.olingo.commons.api.edm.geo.MultiPolygon;
|
||||
|
||||
public final class EdmGeometryMultiPolygon extends AbstractEdmGeospatialType<Point> {
|
||||
public final class EdmGeometryMultiPolygon extends AbstractGeospatialType<MultiPolygon> {
|
||||
|
||||
private static final EdmGeometryMultiPolygon INSTANCE = new EdmGeometryMultiPolygon();
|
||||
|
||||
|
@ -31,7 +32,33 @@ public final class EdmGeometryMultiPolygon extends AbstractEdmGeospatialType<Poi
|
|||
}
|
||||
|
||||
public EdmGeometryMultiPolygon() {
|
||||
super(Point.class, Dimension.GEOMETRY, Type.MULTIPOLYGON);
|
||||
super(MultiPolygon.class, Dimension.GEOMETRY, Type.MULTIPOLYGON);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode,
|
||||
final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
final MultiPolygon multiPolygon =
|
||||
stringToMultiPolygon(value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
if (returnType.isAssignableFrom(MultiPolygon.class)) {
|
||||
return returnType.cast(multiPolygon);
|
||||
} else {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (value instanceof MultiPolygon) {
|
||||
return toString((MultiPolygon) value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
}
|
||||
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.primitivetype;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Type;
|
||||
import org.apache.olingo.commons.api.edm.geo.Point;
|
||||
|
||||
public final class EdmGeometryPoint extends AbstractEdmGeospatialType<Point> {
|
||||
public final class EdmGeometryPoint extends AbstractGeospatialType<Point> {
|
||||
|
||||
private static final EdmGeometryPoint INSTANCE = new EdmGeometryPoint();
|
||||
|
||||
|
@ -34,4 +35,29 @@ public final class EdmGeometryPoint extends AbstractEdmGeospatialType<Point> {
|
|||
super(Point.class, Dimension.GEOMETRY, Type.POINT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode,
|
||||
final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
final Point point = stringToPoint(value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
if (returnType.isAssignableFrom(Point.class)) {
|
||||
return returnType.cast(point);
|
||||
} else {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (value instanceof Point) {
|
||||
return toString((Point) value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
}
|
||||
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.primitivetype;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial.Type;
|
||||
import org.apache.olingo.commons.api.edm.geo.Point;
|
||||
import org.apache.olingo.commons.api.edm.geo.Polygon;
|
||||
|
||||
public final class EdmGeometryPolygon extends AbstractEdmGeospatialType<Point> {
|
||||
public final class EdmGeometryPolygon extends AbstractGeospatialType<Polygon> {
|
||||
|
||||
private static final EdmGeometryPolygon INSTANCE = new EdmGeometryPolygon();
|
||||
|
||||
|
@ -31,7 +32,32 @@ public final class EdmGeometryPolygon extends AbstractEdmGeospatialType<Point> {
|
|||
}
|
||||
|
||||
public EdmGeometryPolygon() {
|
||||
super(Point.class, Dimension.GEOMETRY, Type.POLYGON);
|
||||
super(Polygon.class, Dimension.GEOMETRY, Type.POLYGON);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode,
|
||||
final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
final Polygon polygon = stringToPolygon(value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
if (returnType.isAssignableFrom(Polygon.class)) {
|
||||
return returnType.cast(polygon);
|
||||
} else {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
|
||||
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (value instanceof Polygon) {
|
||||
return toString((Polygon) value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
}
|
||||
|
||||
throw new EdmPrimitiveTypeException(
|
||||
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,27 +18,18 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.primitivetype;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmGeospatialType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
|
||||
public final class EdmPrimitiveTypeFactory {
|
||||
|
||||
public static EdmType getInstance(final EdmPrimitiveTypeKind kind) {
|
||||
return kind.isGeospatial()
|
||||
? getGeoInstance(kind)
|
||||
: getNonGeoInstance(kind);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance for the provided {@link EdmPrimitiveTypeKind} in the form of {@link EdmPrimitiveType} (for
|
||||
* non-geospatial types).
|
||||
* Returns an instance for the provided {@link EdmPrimitiveTypeKind} in the form of {@link EdmPrimitiveType}.
|
||||
*
|
||||
* @param kind EdmPrimitiveTypeKind
|
||||
* @return {@link EdmPrimitiveType} instance
|
||||
*/
|
||||
public static EdmPrimitiveType getNonGeoInstance(final EdmPrimitiveTypeKind kind) {
|
||||
public static EdmPrimitiveType getInstance(final EdmPrimitiveTypeKind kind) {
|
||||
switch (kind) {
|
||||
case Binary:
|
||||
return EdmBinary.getInstance();
|
||||
|
@ -79,19 +70,6 @@ public final class EdmPrimitiveTypeFactory {
|
|||
case Stream:
|
||||
return EdmStream.getInstance();
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Wrong type: " + kind);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance for the provided {@link EdmPrimitiveTypeKind} in the form of {@link EdmGeospatialType}.
|
||||
*
|
||||
* @param kind EdmPrimitiveTypeKind
|
||||
* @return {@link EdmGeospatialType} instance
|
||||
*/
|
||||
public static EdmGeospatialType getGeoInstance(final EdmPrimitiveTypeKind kind) {
|
||||
switch (kind) {
|
||||
case Geography:
|
||||
return EdmGeography.getInstance();
|
||||
case GeographyPoint:
|
||||
|
@ -111,7 +89,7 @@ public final class EdmPrimitiveTypeFactory {
|
|||
case Geometry:
|
||||
return EdmGeometry.getInstance();
|
||||
case GeometryPoint:
|
||||
return EdmGeometry.getInstance();
|
||||
return EdmGeometryPoint.getInstance();
|
||||
case GeometryLineString:
|
||||
return EdmGeometryLineString.getInstance();
|
||||
case GeometryPolygon:
|
||||
|
@ -119,7 +97,7 @@ public final class EdmPrimitiveTypeFactory {
|
|||
case GeometryMultiPoint:
|
||||
return EdmGeometryMultiPoint.getInstance();
|
||||
case GeometryMultiLineString:
|
||||
return EdmGeographyMultiLineString.getInstance();
|
||||
return EdmGeometryMultiLineString.getInstance();
|
||||
case GeometryMultiPolygon:
|
||||
return EdmGeometryMultiPolygon.getInstance();
|
||||
case GeometryCollection:
|
||||
|
@ -127,7 +105,6 @@ public final class EdmPrimitiveTypeFactory {
|
|||
|
||||
default:
|
||||
throw new IllegalArgumentException("Wrong type: " + kind);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,11 @@ public final class EdmTime extends SingletonPrimitiveType {
|
|||
return INSTANCE;
|
||||
}
|
||||
|
||||
{
|
||||
uriPrefix = "time'";
|
||||
uriSuffix = "'";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getDefaultType() {
|
||||
return Duration.class;
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
|||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataGeospatialValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataLink;
|
||||
|
@ -144,11 +143,6 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory {
|
|||
return new ODataProperty(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataProperty newPrimitiveProperty(final String name, final ODataGeospatialValue value) {
|
||||
return new ODataProperty(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataProperty newComplexProperty(final String name, final ODataComplexValue value) {
|
||||
return new ODataProperty(name, value);
|
||||
|
|
|
@ -41,9 +41,7 @@ public class CommonPrimitiveTypeTest extends PrimitiveTypeBaseTest {
|
|||
|
||||
assertEquals(EdmPrimitiveType.EDM_NAMESPACE, EdmInt32.getInstance().getNamespace());
|
||||
for (EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
|
||||
final EdmType instance = kind.isGeospatial()
|
||||
? EdmPrimitiveTypeFactory.getGeoInstance(kind)
|
||||
: EdmPrimitiveTypeFactory.getNonGeoInstance(kind);
|
||||
final EdmType instance = EdmPrimitiveTypeFactory.getInstance(kind);
|
||||
assertEquals(EdmPrimitiveType.EDM_NAMESPACE, instance.getNamespace());
|
||||
}
|
||||
}
|
||||
|
@ -52,33 +50,29 @@ public class CommonPrimitiveTypeTest extends PrimitiveTypeBaseTest {
|
|||
public void names() throws Exception {
|
||||
assertEquals("Uint7", Uint7.getInstance().getName());
|
||||
|
||||
assertEquals("Binary", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Binary).getName());
|
||||
assertEquals("Boolean", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Boolean).getName());
|
||||
assertEquals("Byte", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Byte).getName());
|
||||
assertEquals("Date", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Date).getName());
|
||||
assertEquals("Binary", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary).getName());
|
||||
assertEquals("Boolean", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean).getName());
|
||||
assertEquals("Byte", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Byte).getName());
|
||||
assertEquals("Date", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Date).getName());
|
||||
assertEquals("DateTimeOffset",
|
||||
EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.DateTimeOffset).getName());
|
||||
assertEquals("Decimal", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Decimal).getName());
|
||||
assertEquals("Double", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Double).getName());
|
||||
assertEquals("Duration", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Duration).getName());
|
||||
assertEquals("Guid", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Guid).getName());
|
||||
assertEquals("Int16", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int16).getName());
|
||||
assertEquals("Int32", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int32).getName());
|
||||
assertEquals("Int64", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int64).getName());
|
||||
assertEquals("SByte", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.SByte).getName());
|
||||
assertEquals("Single", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Single).getName());
|
||||
assertEquals("String", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.String).getName());
|
||||
assertEquals("TimeOfDay", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.TimeOfDay).getName());
|
||||
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.DateTimeOffset).getName());
|
||||
assertEquals("Decimal", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal).getName());
|
||||
assertEquals("Double", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Double).getName());
|
||||
assertEquals("Duration", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Duration).getName());
|
||||
assertEquals("Guid", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Guid).getName());
|
||||
assertEquals("Int16", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16).getName());
|
||||
assertEquals("Int32", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32).getName());
|
||||
assertEquals("Int64", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int64).getName());
|
||||
assertEquals("SByte", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte).getName());
|
||||
assertEquals("Single", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Single).getName());
|
||||
assertEquals("String", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String).getName());
|
||||
assertEquals("TimeOfDay", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.TimeOfDay).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kind() throws Exception {
|
||||
for (EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
|
||||
if (kind.isGeospatial()) {
|
||||
assertEquals(EdmTypeKind.PRIMITIVE, EdmPrimitiveTypeFactory.getGeoInstance(kind).getKind());
|
||||
} else {
|
||||
assertEquals(EdmTypeKind.PRIMITIVE, EdmPrimitiveTypeFactory.getNonGeoInstance(kind).getKind());
|
||||
}
|
||||
assertEquals(EdmTypeKind.PRIMITIVE, EdmPrimitiveTypeFactory.getInstance(kind).getKind());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,41 +80,37 @@ public class CommonPrimitiveTypeTest extends PrimitiveTypeBaseTest {
|
|||
public void toStringAll() throws Exception {
|
||||
assertEquals("System.Uint7", Uint7.getInstance().toString());
|
||||
|
||||
assertEquals("Edm.Binary", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Binary).toString());
|
||||
assertEquals("Edm.Boolean", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Boolean).toString());
|
||||
assertEquals("Edm.Byte", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Byte).toString());
|
||||
assertEquals("Edm.Date", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Date).toString());
|
||||
assertEquals("Edm.Binary", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary).toString());
|
||||
assertEquals("Edm.Boolean", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean).toString());
|
||||
assertEquals("Edm.Byte", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Byte).toString());
|
||||
assertEquals("Edm.Date", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Date).toString());
|
||||
assertEquals("Edm.DateTimeOffset",
|
||||
EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.DateTimeOffset).toString());
|
||||
assertEquals("Edm.Decimal", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Decimal).toString());
|
||||
assertEquals("Edm.Double", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Double).toString());
|
||||
assertEquals("Edm.Duration", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Duration).toString());
|
||||
assertEquals("Edm.Guid", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Guid).toString());
|
||||
assertEquals("Edm.Int16", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int16).toString());
|
||||
assertEquals("Edm.Int32", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int32).toString());
|
||||
assertEquals("Edm.Int64", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int64).toString());
|
||||
assertEquals("Edm.SByte", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.SByte).toString());
|
||||
assertEquals("Edm.Single", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Single).toString());
|
||||
assertEquals("Edm.String", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.String).toString());
|
||||
assertEquals("Edm.TimeOfDay", EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.TimeOfDay).toString());
|
||||
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.DateTimeOffset).toString());
|
||||
assertEquals("Edm.Decimal", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal).toString());
|
||||
assertEquals("Edm.Double", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Double).toString());
|
||||
assertEquals("Edm.Duration", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Duration).toString());
|
||||
assertEquals("Edm.Guid", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Guid).toString());
|
||||
assertEquals("Edm.Int16", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16).toString());
|
||||
assertEquals("Edm.Int32", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32).toString());
|
||||
assertEquals("Edm.Int64", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int64).toString());
|
||||
assertEquals("Edm.SByte", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte).toString());
|
||||
assertEquals("Edm.Single", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Single).toString());
|
||||
assertEquals("Edm.String", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String).toString());
|
||||
assertEquals("Edm.TimeOfDay", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.TimeOfDay).toString());
|
||||
|
||||
for (EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
|
||||
if (!kind.isGeospatial()) {
|
||||
final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(kind);
|
||||
assertEquals(instance.toString(), kind.getFullQualifiedName().toString());
|
||||
}
|
||||
final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(kind);
|
||||
assertEquals(instance.toString(), kind.getFullQualifiedName().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compatibility() {
|
||||
for (EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
|
||||
if (!kind.isGeospatial()) {
|
||||
final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(kind);
|
||||
assertTrue(instance.isCompatible(instance));
|
||||
assertFalse(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(
|
||||
(kind == EdmPrimitiveTypeKind.String ? EdmPrimitiveTypeKind.Binary : EdmPrimitiveTypeKind.String))));
|
||||
}
|
||||
final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(kind);
|
||||
assertTrue(instance.isCompatible(instance));
|
||||
assertFalse(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(
|
||||
(kind == EdmPrimitiveTypeKind.String ? EdmPrimitiveTypeKind.Binary : EdmPrimitiveTypeKind.String))));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,71 +118,67 @@ public class CommonPrimitiveTypeTest extends PrimitiveTypeBaseTest {
|
|||
public void defaultType() throws Exception {
|
||||
assertEquals(Byte.class, Uint7.getInstance().getDefaultType());
|
||||
|
||||
assertEquals(byte[].class, EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Binary).getDefaultType());
|
||||
assertEquals(byte[].class, EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary).getDefaultType());
|
||||
assertEquals(Boolean.class,
|
||||
EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Boolean).getDefaultType());
|
||||
assertEquals(Short.class, EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Byte).getDefaultType());
|
||||
assertEquals(Calendar.class, EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Date).getDefaultType());
|
||||
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean).getDefaultType());
|
||||
assertEquals(Short.class, EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Byte).getDefaultType());
|
||||
assertEquals(Calendar.class, EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Date).getDefaultType());
|
||||
assertEquals(Calendar.class,
|
||||
EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.DateTimeOffset).getDefaultType());
|
||||
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.DateTimeOffset).getDefaultType());
|
||||
assertEquals(BigDecimal.class,
|
||||
EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Decimal).getDefaultType());
|
||||
assertEquals(Double.class, EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Double).getDefaultType());
|
||||
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal).getDefaultType());
|
||||
assertEquals(Double.class, EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Double).getDefaultType());
|
||||
assertEquals(BigDecimal.class,
|
||||
EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Duration).getDefaultType());
|
||||
assertEquals(UUID.class, EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Guid).getDefaultType());
|
||||
assertEquals(Short.class, EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int16).getDefaultType());
|
||||
assertEquals(Integer.class, EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int32).getDefaultType());
|
||||
assertEquals(Long.class, EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int64).getDefaultType());
|
||||
assertEquals(Byte.class, EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.SByte).getDefaultType());
|
||||
assertEquals(Float.class, EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Single).getDefaultType());
|
||||
assertEquals(String.class, EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.String).getDefaultType());
|
||||
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Duration).getDefaultType());
|
||||
assertEquals(UUID.class, EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Guid).getDefaultType());
|
||||
assertEquals(Short.class, EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16).getDefaultType());
|
||||
assertEquals(Integer.class, EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32).getDefaultType());
|
||||
assertEquals(Long.class, EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int64).getDefaultType());
|
||||
assertEquals(Byte.class, EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte).getDefaultType());
|
||||
assertEquals(Float.class, EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Single).getDefaultType());
|
||||
assertEquals(String.class, EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String).getDefaultType());
|
||||
assertEquals(Calendar.class,
|
||||
EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.TimeOfDay).getDefaultType());
|
||||
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.TimeOfDay).getDefaultType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validate() throws Exception {
|
||||
for (EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
|
||||
if (!kind.isGeospatial()) {
|
||||
final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(kind);
|
||||
assertTrue(instance.validate(null, null, null, null, null, null));
|
||||
assertTrue(instance.validate(null, true, null, null, null, null));
|
||||
assertFalse(instance.validate(null, false, null, null, null, null));
|
||||
if (kind != EdmPrimitiveTypeKind.Stream) {
|
||||
assertFalse(instance.validate("ä", null, null, null, null, false));
|
||||
}
|
||||
if (kind != EdmPrimitiveTypeKind.String && kind != EdmPrimitiveTypeKind.Binary
|
||||
&& kind != EdmPrimitiveTypeKind.Stream) {
|
||||
final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(kind);
|
||||
assertTrue(instance.validate(null, null, null, null, null, null));
|
||||
assertTrue(instance.validate(null, true, null, null, null, null));
|
||||
assertFalse(instance.validate(null, false, null, null, null, null));
|
||||
if (kind != EdmPrimitiveTypeKind.Stream) {
|
||||
assertFalse(instance.validate("ä", null, null, null, null, false));
|
||||
}
|
||||
if (kind != EdmPrimitiveTypeKind.String && kind != EdmPrimitiveTypeKind.Binary
|
||||
&& kind != EdmPrimitiveTypeKind.Stream) {
|
||||
|
||||
assertFalse(instance.validate("", null, null, null, null, null));
|
||||
}
|
||||
if (kind != EdmPrimitiveTypeKind.String && kind != EdmPrimitiveTypeKind.Stream) {
|
||||
assertFalse(instance.validate("ä", null, null, null, null, null));
|
||||
}
|
||||
assertFalse(instance.validate("", null, null, null, null, null));
|
||||
}
|
||||
if (kind != EdmPrimitiveTypeKind.String && kind != EdmPrimitiveTypeKind.Stream) {
|
||||
assertFalse(instance.validate("ä", null, null, null, null, null));
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Binary).
|
||||
assertTrue(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary).
|
||||
validate("abcd", null, 3, null, null, null));
|
||||
assertFalse(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Binary).
|
||||
assertFalse(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary).
|
||||
validate("abcd", null, 2, null, null, null));
|
||||
|
||||
assertTrue(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Decimal).
|
||||
assertTrue(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal).
|
||||
validate("1", null, null, null, null, null));
|
||||
assertFalse(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Decimal).
|
||||
assertFalse(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal).
|
||||
validate("1.2", null, null, null, 0, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uriLiteral() throws Exception {
|
||||
for (EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
|
||||
if (!kind.isGeospatial()) {
|
||||
final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(kind);
|
||||
assertEquals("test", instance.fromUriLiteral(instance.toUriLiteral("test")));
|
||||
assertNull(instance.toUriLiteral(null));
|
||||
assertNull(instance.fromUriLiteral(null));
|
||||
}
|
||||
final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(kind);
|
||||
assertEquals("test", instance.fromUriLiteral(instance.toUriLiteral("test")));
|
||||
assertNull(instance.toUriLiteral(null));
|
||||
assertNull(instance.fromUriLiteral(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.junit.Test;
|
|||
|
||||
public class EdmBinaryTest extends PrimitiveTypeBaseTest {
|
||||
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Binary);
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary);
|
||||
|
||||
@Test
|
||||
public void validate() throws Exception {
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.junit.Test;
|
|||
|
||||
public class EdmBooleanTest extends PrimitiveTypeBaseTest {
|
||||
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Boolean);
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean);
|
||||
|
||||
@Test
|
||||
public void toUriLiteral() throws Exception {
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.junit.Test;
|
|||
|
||||
public class EdmByteTest extends PrimitiveTypeBaseTest {
|
||||
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Byte);
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Byte);
|
||||
|
||||
@Test
|
||||
public void compatibility() {
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.junit.Test;
|
|||
|
||||
public class EdmDateTest extends PrimitiveTypeBaseTest {
|
||||
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Date);
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Date);
|
||||
|
||||
@Test
|
||||
public void toUriLiteral() throws Exception {
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.junit.Test;
|
|||
|
||||
public class EdmDateTimeOffsetTest extends PrimitiveTypeBaseTest {
|
||||
|
||||
final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.DateTimeOffset);
|
||||
final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.DateTimeOffset);
|
||||
|
||||
@Test
|
||||
public void toUriLiteral() throws Exception {
|
||||
|
|
|
@ -30,18 +30,18 @@ import org.junit.Test;
|
|||
|
||||
public class EdmDecimalTest extends PrimitiveTypeBaseTest {
|
||||
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Decimal);
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal);
|
||||
|
||||
@Test
|
||||
public void compatibility() {
|
||||
assertTrue(instance.isCompatible(Uint7.getInstance()));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Byte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.SByte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int16)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int32)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int64)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Single)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Double)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Byte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int64)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Single)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Double)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -30,17 +30,17 @@ import org.junit.Test;
|
|||
|
||||
public class EdmDoubleTest extends PrimitiveTypeBaseTest {
|
||||
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Double);
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Double);
|
||||
|
||||
@Test
|
||||
public void compatibility() {
|
||||
assertTrue(instance.isCompatible(Uint7.getInstance()));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Byte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.SByte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int16)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int32)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int64)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Single)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Byte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int64)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Single)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.junit.Test;
|
|||
|
||||
public class EdmDurationTest extends PrimitiveTypeBaseTest {
|
||||
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Duration);
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Duration);
|
||||
|
||||
@Test
|
||||
public void toUriLiteral() throws Exception {
|
||||
|
|
|
@ -0,0 +1,174 @@
|
|||
/*
|
||||
* 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.commons.core.edm.primitivetype;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Iterator;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
||||
import org.apache.olingo.commons.api.edm.geo.GeospatialCollection;
|
||||
import org.apache.olingo.commons.api.edm.geo.LineString;
|
||||
import org.apache.olingo.commons.api.edm.geo.MultiLineString;
|
||||
import org.apache.olingo.commons.api.edm.geo.MultiPoint;
|
||||
import org.apache.olingo.commons.api.edm.geo.MultiPolygon;
|
||||
import org.apache.olingo.commons.api.edm.geo.Point;
|
||||
import org.apache.olingo.commons.api.edm.geo.Polygon;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmGeoTest extends PrimitiveTypeBaseTest {
|
||||
|
||||
@Test
|
||||
public void point() throws EdmPrimitiveTypeException {
|
||||
final String input = "geometry'SRID=0;Point(142.1 64.1)'";
|
||||
|
||||
expectContentErrorInValueOfString(EdmGeographyPoint.getInstance(), input);
|
||||
|
||||
final Point point = EdmGeometryPoint.getInstance().valueOfString(input, null, null, null, null, null, Point.class);
|
||||
assertNotNull(point);
|
||||
assertEquals(0, point.getSrid(), 0);
|
||||
assertEquals(142.1, point.getX(), 0);
|
||||
assertEquals(64.1, point.getY(), 0);
|
||||
|
||||
assertEquals(input, EdmGeometryPoint.getInstance().valueToString(point, null, null, null, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiPoint() throws EdmPrimitiveTypeException {
|
||||
final String input = "geography'SRID=0;MultiPoint((142.1 64.1),(1.0 2.0))'";
|
||||
|
||||
expectContentErrorInValueOfString(EdmGeometryMultiPoint.getInstance(), input);
|
||||
|
||||
MultiPoint multipoint = EdmGeographyMultiPoint.getInstance().
|
||||
valueOfString(input, null, null, null, null, null, MultiPoint.class);
|
||||
assertNotNull(multipoint);
|
||||
assertEquals(0, multipoint.getSrid(), 0);
|
||||
assertEquals(142.1, multipoint.iterator().next().getX(), 0);
|
||||
assertEquals(64.1, multipoint.iterator().next().getY(), 0);
|
||||
|
||||
assertEquals(input, EdmGeographyMultiPoint.getInstance().valueToString(multipoint, null, null, null, null, null));
|
||||
|
||||
multipoint = EdmGeographyMultiPoint.getInstance().
|
||||
valueOfString("geography'SRID=0;MultiPoint()'", null, null, null, null, null, MultiPoint.class);
|
||||
assertFalse(multipoint.iterator().hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lineString() throws EdmPrimitiveTypeException {
|
||||
final String input = "geography'SRID=0;LineString(142.1 64.1,3.14 2.78)'";
|
||||
|
||||
expectContentErrorInValueOfString(EdmGeographyPoint.getInstance(), input);
|
||||
expectContentErrorInValueOfString(EdmGeometryLineString.getInstance(), input);
|
||||
|
||||
final LineString lineString = EdmGeographyLineString.getInstance().
|
||||
valueOfString(input, null, null, null, null, null, LineString.class);
|
||||
assertNotNull(lineString);
|
||||
assertEquals(0, lineString.getSrid(), 0);
|
||||
final Iterator<Point> itor = lineString.iterator();
|
||||
assertEquals(142.1, itor.next().getX(), 0);
|
||||
assertEquals(2.78, itor.next().getY(), 0);
|
||||
|
||||
assertEquals(input, EdmGeographyLineString.getInstance().valueToString(lineString, null, null, null, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiLineString() throws EdmPrimitiveTypeException {
|
||||
final String input = "geography'SRID=0;MultiLineString((142.1 64.1,3.14 2.78),(142.1 64.7,3.14 2.78))'";
|
||||
|
||||
expectContentErrorInValueOfString(EdmGeographyPoint.getInstance(), input);
|
||||
expectContentErrorInValueOfString(EdmGeometryLineString.getInstance(), input);
|
||||
|
||||
final MultiLineString multiLineString = EdmGeographyMultiLineString.getInstance().
|
||||
valueOfString(input, null, null, null, null, null, MultiLineString.class);
|
||||
assertNotNull(multiLineString);
|
||||
assertEquals(0, multiLineString.getSrid(), 0);
|
||||
final Iterator<LineString> itor = multiLineString.iterator();
|
||||
assertEquals(142.1, itor.next().iterator().next().getX(), 0);
|
||||
assertEquals(64.7, itor.next().iterator().next().getY(), 0);
|
||||
|
||||
assertEquals(input, EdmGeographyMultiLineString.getInstance().
|
||||
valueToString(multiLineString, null, null, null, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void polygon() throws EdmPrimitiveTypeException {
|
||||
final String input = "geography'SRID=0;Polygon((1.0 1.0,1.0 1.0),(1.0 1.0,2.0 2.0,3.0 3.0,1.0 1.0))'";
|
||||
|
||||
expectContentErrorInValueOfString(EdmGeometryPolygon.getInstance(), input);
|
||||
|
||||
final Polygon polygon = EdmGeographyPolygon.getInstance().
|
||||
valueOfString(input, null, null, null, null, null, Polygon.class);
|
||||
assertNotNull(polygon);
|
||||
assertEquals(0, polygon.getSrid(), 0);
|
||||
Iterator<Point> itor = polygon.getInterior().iterator();
|
||||
assertEquals(1, itor.next().getX(), 0);
|
||||
assertEquals(1, itor.next().getY(), 0);
|
||||
itor = polygon.getExterior().iterator();
|
||||
itor.next();
|
||||
assertEquals(2, itor.next().getX(), 0);
|
||||
assertEquals(3, itor.next().getY(), 0);
|
||||
|
||||
assertEquals(input, EdmGeographyPolygon.getInstance().valueToString(polygon, null, null, null, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiPolygon() throws EdmPrimitiveTypeException {
|
||||
final String input = "geometry'SRID=0;MultiPolygon("
|
||||
+ "((1.0 1.0,1.0 1.0),(1.0 1.0,2.0 2.0,3.0 3.0,1.0 1.0)),"
|
||||
+ "((1.0 1.0,1.0 1.0),(1.0 1.0,2.0 2.0,3.0 3.0,1.0 1.0))"
|
||||
+ ")'";
|
||||
|
||||
expectContentErrorInValueOfString(EdmGeographyPolygon.getInstance(), input);
|
||||
|
||||
final MultiPolygon multiPolygon = EdmGeometryMultiPolygon.getInstance().
|
||||
valueOfString(input, null, null, null, null, null, MultiPolygon.class);
|
||||
assertNotNull(multiPolygon);
|
||||
assertEquals(0, multiPolygon.getSrid(), 0);
|
||||
final Iterator<Polygon> itor = multiPolygon.iterator();
|
||||
assertEquals(1, itor.next().getInterior().iterator().next().getX(), 0);
|
||||
assertEquals(1, itor.next().getInterior().iterator().next().getX(), 0);
|
||||
|
||||
assertEquals(input, EdmGeometryMultiPolygon.getInstance().
|
||||
valueToString(multiPolygon, null, null, null, null, null));
|
||||
|
||||
EdmGeographyMultiPolygon.getInstance().valueOfString(
|
||||
"geography'SRID=0;MultiPolygon(((1 1,1 1),(1 1,2 2,3 3,1 1)))'",
|
||||
null, null, null, null, null, MultiPolygon.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void collection() throws EdmPrimitiveTypeException {
|
||||
final String input = "geometry'SRID=0;Collection(LineString(142.1 64.1,3.14 2.78))'";
|
||||
|
||||
final GeospatialCollection collection = EdmGeometryCollection.getInstance().
|
||||
valueOfString(input, null, null, null, null, null, GeospatialCollection.class);
|
||||
assertNotNull(collection);
|
||||
assertEquals(0, collection.getSrid(), 0);
|
||||
|
||||
final Geospatial item = collection.iterator().next();
|
||||
assertNotNull(item);
|
||||
assertTrue(item instanceof LineString);
|
||||
|
||||
assertEquals(input, EdmGeometryCollection.getInstance().
|
||||
valueToString(collection, null, null, null, null, null));
|
||||
}
|
||||
}
|
|
@ -28,7 +28,7 @@ import org.junit.Test;
|
|||
|
||||
public class EdmGuidTest extends PrimitiveTypeBaseTest {
|
||||
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Guid);
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Guid);
|
||||
|
||||
@Test
|
||||
public void toUriLiteral() {
|
||||
|
|
|
@ -29,13 +29,13 @@ import org.junit.Test;
|
|||
|
||||
public class EdmInt16Test extends PrimitiveTypeBaseTest {
|
||||
|
||||
final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int16);
|
||||
final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16);
|
||||
|
||||
@Test
|
||||
public void testInt16Compatibility() {
|
||||
assertTrue(instance.isCompatible(Uint7.getInstance()));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Byte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.SByte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Byte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -29,14 +29,14 @@ import org.junit.Test;
|
|||
|
||||
public class EdmInt32Test extends PrimitiveTypeBaseTest {
|
||||
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int32);
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32);
|
||||
|
||||
@Test
|
||||
public void compatibility() {
|
||||
assertTrue(instance.isCompatible(Uint7.getInstance()));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Byte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.SByte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int16)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Byte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -29,15 +29,15 @@ import org.junit.Test;
|
|||
|
||||
public class EdmInt64Test extends PrimitiveTypeBaseTest {
|
||||
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int64);
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int64);
|
||||
|
||||
@Test
|
||||
public void compatibility() {
|
||||
assertTrue(instance.isCompatible(Uint7.getInstance()));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Byte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.SByte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int16)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int32)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Byte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -29,26 +29,22 @@ public class EdmNullTest extends PrimitiveTypeBaseTest {
|
|||
@Test
|
||||
public void checkNull() throws Exception {
|
||||
for (EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
|
||||
if (!kind.isGeospatial()) {
|
||||
final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(kind);
|
||||
assertNull(instance.valueToString(null, null, null, null, null, null));
|
||||
assertNull(instance.valueToString(null, true, null, null, null, null));
|
||||
final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(kind);
|
||||
assertNull(instance.valueToString(null, null, null, null, null, null));
|
||||
assertNull(instance.valueToString(null, true, null, null, null, null));
|
||||
|
||||
expectNullErrorInValueToString(instance);
|
||||
}
|
||||
expectNullErrorInValueToString(instance);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkValueOfNull() throws Exception {
|
||||
for (EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
|
||||
if (!kind.isGeospatial()) {
|
||||
final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(kind);
|
||||
assertNull(instance.valueOfString(null, null, null, null, null, null, instance.getDefaultType()));
|
||||
assertNull(instance.valueOfString(null, true, null, null, null, null, instance.getDefaultType()));
|
||||
final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(kind);
|
||||
assertNull(instance.valueOfString(null, null, null, null, null, null, instance.getDefaultType()));
|
||||
assertNull(instance.valueOfString(null, true, null, null, null, null, instance.getDefaultType()));
|
||||
|
||||
expectNullErrorInValueOfString(instance);
|
||||
}
|
||||
expectNullErrorInValueOfString(instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.junit.Test;
|
|||
|
||||
public class EdmSByteTest extends PrimitiveTypeBaseTest {
|
||||
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.SByte);
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte);
|
||||
|
||||
@Test
|
||||
public void compatibility() {
|
||||
|
|
|
@ -30,16 +30,16 @@ import org.junit.Test;
|
|||
|
||||
public class EdmSingleTest extends PrimitiveTypeBaseTest {
|
||||
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Single);
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Single);
|
||||
|
||||
@Test
|
||||
public void compatibility() {
|
||||
assertTrue(instance.isCompatible(Uint7.getInstance()));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Byte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.SByte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int16)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int32)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int64)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Byte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32)));
|
||||
assertTrue(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int64)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.junit.Test;
|
|||
|
||||
public class EdmStringTest extends PrimitiveTypeBaseTest {
|
||||
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.String);
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String);
|
||||
|
||||
@Test
|
||||
public void toUriLiteral() throws Exception {
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.junit.Test;
|
|||
|
||||
public class EdmTimeOfDayTest extends PrimitiveTypeBaseTest {
|
||||
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.TimeOfDay);
|
||||
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.TimeOfDay);
|
||||
|
||||
@Test
|
||||
public void toUriLiteral() throws Exception {
|
||||
|
|
|
@ -30,6 +30,6 @@ public class UInt7Test extends PrimitiveTypeBaseTest {
|
|||
public void compatibility() {
|
||||
assertTrue(Uint7.getInstance().isCompatible(Uint7.getInstance()));
|
||||
assertFalse(Uint7.getInstance().isCompatible(
|
||||
EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.String)));
|
||||
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,9 +40,9 @@ public class EdmEnumTypeImpl extends AbstractEdmEnumType implements EdmEnumType
|
|||
super(edm, enumName, enumType.isFlags());
|
||||
|
||||
if (enumType.getUnderlyingType() == null) {
|
||||
this.underlyingType = EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Int32);
|
||||
this.underlyingType = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32);
|
||||
} else {
|
||||
this.underlyingType = EdmPrimitiveTypeFactory.getNonGeoInstance(
|
||||
this.underlyingType = EdmPrimitiveTypeFactory.getInstance(
|
||||
EdmPrimitiveTypeKind.valueOf(enumType.getUnderlyingType().getName()));
|
||||
// TODO: Should we validate that the underlying type is of byte, sbyte, in16, int32 or int64?
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ public class EdmTypeDefinitionImpl extends AbstractEdmTypeDefinition implements
|
|||
public EdmPrimitiveType getUnderlyingType() {
|
||||
if (edmPrimitiveTypeInstance == null) {
|
||||
try {
|
||||
edmPrimitiveTypeInstance = EdmPrimitiveTypeFactory.getNonGeoInstance(
|
||||
edmPrimitiveTypeInstance = EdmPrimitiveTypeFactory.getInstance(
|
||||
EdmPrimitiveTypeKind.valueOf(typeDefinition.getUnderlyingType().getName()));
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new EdmException("Invalid underlying type: " + typeDefinition.getUnderlyingType(), e);
|
||||
|
|
|
@ -878,10 +878,10 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
|||
|
||||
if (text.equals("false")) {
|
||||
return new LiteralImpl().setText("false").setType(
|
||||
EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Boolean));
|
||||
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean));
|
||||
}
|
||||
return new LiteralImpl().setText("true").setType(
|
||||
EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Boolean));
|
||||
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1551,7 +1551,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
|||
|
||||
@Override
|
||||
public Object visitNaninfinity(final NaninfinityContext ctx) {
|
||||
return new LiteralImpl().setType(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Decimal)).
|
||||
return new LiteralImpl().setType(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal)).
|
||||
setText(ctx.getText());
|
||||
}
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ public class EdmEnumTest extends PrimitiveTypeBaseTest {
|
|||
|
||||
@Test
|
||||
public void underlyingType() throws Exception {
|
||||
assertEquals(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.SByte), instance.getUnderlyingType());
|
||||
assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte), instance.getUnderlyingType());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -78,7 +78,7 @@ public class EdmFunctionImportImplTest {
|
|||
assertEquals(functionName.getName(), function.getName());
|
||||
assertFalse(function.isBound());
|
||||
assertFalse(function.isComposable());
|
||||
assertEquals(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Boolean),
|
||||
assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean),
|
||||
function.getReturnType().getType());
|
||||
assertEquals(entityContainer, functionImport.getEntityContainer());
|
||||
assertNull(functionImport.getReturnedEntitySet());
|
||||
|
|
|
@ -46,7 +46,7 @@ public class EdmReturnTypeImplTest {
|
|||
|
||||
EdmReturnType typeImpl = new EdmReturnTypeImpl(mock(EdmProviderImpl.class), providerType);
|
||||
|
||||
assertEquals(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.String), typeImpl.getType());
|
||||
assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String), typeImpl.getType());
|
||||
assertFalse(typeImpl.isCollection());
|
||||
|
||||
assertNull(typeImpl.getPrecision());
|
||||
|
@ -61,7 +61,7 @@ public class EdmReturnTypeImplTest {
|
|||
|
||||
EdmReturnType typeImpl = new EdmReturnTypeImpl(mock(EdmProviderImpl.class), providerType);
|
||||
|
||||
assertEquals(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.String), typeImpl.getType());
|
||||
assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String), typeImpl.getType());
|
||||
assertTrue(typeImpl.isCollection());
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public class EdmTypeDefinitionImplTest {
|
|||
assertEquals(String.class, typeDefImpl.getDefaultType());
|
||||
assertEquals(EdmTypeKind.DEFINITION, typeDefImpl.getKind());
|
||||
assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String), typeDefImpl.getUnderlyingType());
|
||||
assertTrue(typeDefImpl.isCompatible(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.String)));
|
||||
assertTrue(typeDefImpl.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String)));
|
||||
|
||||
// String validation
|
||||
assertEquals("'StringValue'", typeDefImpl.toUriLiteral("StringValue"));
|
||||
|
|
|
@ -102,7 +102,7 @@ public class UriResourceImplTest {
|
|||
assertEquals(false, impl.isCollection());
|
||||
assertEquals(expression, impl.getExpression());
|
||||
assertEquals("A", impl.getLambdaVariable());
|
||||
assertEquals(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Boolean), impl.getType());
|
||||
assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean), impl.getType());
|
||||
assertEquals("all", impl.toString());
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ public class UriResourceImplTest {
|
|||
assertEquals(false, impl.isCollection());
|
||||
assertEquals(expression, impl.getExpression());
|
||||
assertEquals("A", impl.getLamdaVariable());
|
||||
assertEquals(EdmPrimitiveTypeFactory.getNonGeoInstance(EdmPrimitiveTypeKind.Boolean), impl.getType());
|
||||
assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean), impl.getType());
|
||||
assertEquals("any", impl.toString());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue