[OLINGO-575] Delete V3 Primitive types

This commit is contained in:
Christian Amend 2015-03-05 10:33:06 +01:00
parent 93f2ed5cf2
commit 3c36eaeaef
17 changed files with 136 additions and 431 deletions

View File

@ -273,18 +273,15 @@ public final class CoreUtils {
EdmPrimitiveTypeKind bckCandidate = null;
for (EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
if (kind.getSupportedVersions().contains(client.getServiceVersion())) {
final Class<?> target = EdmPrimitiveTypeFactory.getInstance(kind).getDefaultType();
if (clazz.equals(target)) {
return new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()).setTypeExpression(kind.toString()).build();
} else if (target.isAssignableFrom(clazz)) {
bckCandidate = kind;
} else if (target == Timestamp.class
&& (kind == EdmPrimitiveTypeKind.DateTime || kind == EdmPrimitiveTypeKind.DateTimeOffset)) {
} else if (target == Timestamp.class && kind == EdmPrimitiveTypeKind.DateTimeOffset) {
bckCandidate = kind;
}
}
}
if (bckCandidate == null) {

View File

@ -1,18 +1,18 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* 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
*
* 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
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@ -31,7 +31,6 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.annotation.EdmConstantAnnotationExpression;
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.core.domain.ODataCollectionValueImpl;
import org.apache.olingo.commons.core.domain.ODataEnumValueImpl;
import org.apache.olingo.commons.core.domain.ODataPrimitiveValueImpl;
@ -62,42 +61,41 @@ public class EdmConstantAnnotationExpressionImpl implements EdmConstantAnnotatio
} else {
EdmPrimitiveTypeKind kind;
switch (constExprConstruct.getType()) {
case Binary:
kind = EdmPrimitiveTypeKind.Binary;
break;
case Bool:
kind = EdmPrimitiveTypeKind.Boolean;
break;
case Date:
kind = EdmPrimitiveTypeKind.Date;
break;
case DateTimeOffset:
kind = EdmPrimitiveTypeKind.DateTimeOffset;
break;
case Decimal:
kind = EdmPrimitiveTypeKind.Decimal;
break;
case Duration:
kind = EdmPrimitiveTypeKind.Duration;
break;
case Float:
kind = EdmPrimitiveTypeKind.Single;
break;
case Guid:
kind = EdmPrimitiveTypeKind.Guid;
break;
case Int:
kind = EdmPrimitiveTypeKind.Int32;
break;
case TimeOfDay:
kind = EdmPrimitiveTypeKind.TimeOfDay;
break;
case String:
default:
kind = EdmPrimitiveTypeKind.String;
case Binary:
kind = EdmPrimitiveTypeKind.Binary;
break;
case Bool:
kind = EdmPrimitiveTypeKind.Boolean;
break;
case Date:
kind = EdmPrimitiveTypeKind.Date;
break;
case DateTimeOffset:
kind = EdmPrimitiveTypeKind.DateTimeOffset;
break;
case Decimal:
kind = EdmPrimitiveTypeKind.Decimal;
break;
case Duration:
kind = EdmPrimitiveTypeKind.Duration;
break;
case Float:
kind = EdmPrimitiveTypeKind.Single;
break;
case Guid:
kind = EdmPrimitiveTypeKind.Guid;
break;
case Int:
kind = EdmPrimitiveTypeKind.Int32;
break;
case TimeOfDay:
kind = EdmPrimitiveTypeKind.TimeOfDay;
break;
case String:
default:
kind = EdmPrimitiveTypeKind.String;
}
final ODataPrimitiveValueImpl.BuilderImpl primitiveValueBuilder =
new ODataPrimitiveValueImpl.BuilderImpl(ODataServiceVersion.V40);
final ODataPrimitiveValueImpl.BuilderImpl primitiveValueBuilder = new ODataPrimitiveValueImpl.BuilderImpl();
primitiveValueBuilder.setType(kind);
try {
final EdmPrimitiveType primitiveType = EdmPrimitiveTypeFactory.getInstance(kind);

View File

@ -1,18 +1,18 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* 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
*
* 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
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@ -56,7 +56,6 @@ 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.EdmDateTime;
import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTimeOffset;
import org.apache.olingo.commons.core.edm.primitivetype.EdmDecimal;
import org.apache.olingo.commons.core.edm.primitivetype.EdmDouble;
@ -64,7 +63,6 @@ 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.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -146,112 +144,48 @@ public final class URIUtils {
return uri.normalize();
}
// TODO: Delete prefix method since these are not relevant in V4
private static String prefix(final ODataServiceVersion version, final EdmPrimitiveTypeKind typeKind) {
String result = StringUtils.EMPTY;
if (version.compareTo(ODataServiceVersion.V40) < 0) {
switch (typeKind) {
case Guid:
result = "guid'";
break;
case DateTime:
result = "datetime'";
break;
case DateTimeOffset:
result = "datetimeoffset'";
break;
case Binary:
result = "X'";
break;
default:
}
}
return result;
}
//TODO: Delete suffix method since these are not relevant in V4
private static String suffix(final ODataServiceVersion version, final EdmPrimitiveTypeKind typeKind) {
String result = StringUtils.EMPTY;
if (version.compareTo(ODataServiceVersion.V40) < 0) {
switch (typeKind) {
case Guid:
case DateTime:
case DateTimeOffset:
result = "'";
break;
case Decimal:
result = "M";
break;
case Double:
result = "D";
break;
case Single:
result = "f";
break;
case Int64:
result = "L";
break;
default:
}
}
return result;
}
private static String timestamp(final ODataServiceVersion version, final Timestamp timestamp)
throws UnsupportedEncodingException, EdmPrimitiveTypeException {
throws UnsupportedEncodingException, EdmPrimitiveTypeException {
return version.compareTo(ODataServiceVersion.V40) < 0
? prefix(version, EdmPrimitiveTypeKind.DateTime)
+ URLEncoder.encode(EdmDateTime.getInstance().
valueToString(timestamp, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null),
Constants.UTF8)
+ suffix(version, EdmPrimitiveTypeKind.DateTime)
: URLEncoder.encode(EdmDateTimeOffset.getInstance().
valueToString(timestamp, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null),
Constants.UTF8);
return URLEncoder.encode(EdmDateTimeOffset.getInstance().
valueToString(timestamp, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null),
Constants.UTF8);
}
private static String calendar(final ODataServiceVersion version, final Calendar calendar)
throws UnsupportedEncodingException, EdmPrimitiveTypeException {
throws UnsupportedEncodingException, EdmPrimitiveTypeException {
return version.compareTo(ODataServiceVersion.V40) < 0
? prefix(version, EdmPrimitiveTypeKind.DateTime)
+ URLEncoder.encode(EdmDateTime.getInstance().
valueToString(calendar, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null),
Constants.UTF8)
+ suffix(version, EdmPrimitiveTypeKind.DateTime)
: URLEncoder.encode(EdmDateTimeOffset.getInstance().
valueToString(calendar, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null),
Constants.UTF8);
return URLEncoder.encode(EdmDateTimeOffset.getInstance().
valueToString(calendar, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null),
Constants.UTF8);
}
private static String duration(final ODataServiceVersion version, final Duration duration)
throws UnsupportedEncodingException, EdmPrimitiveTypeException {
throws UnsupportedEncodingException, EdmPrimitiveTypeException {
return version.compareTo(ODataServiceVersion.V40) < 0
? 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,
return EdmDuration.getInstance().toUriLiteral(URLEncoder.encode(EdmDuration.getInstance().
valueToString(duration, null, null,
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null), Constants.UTF8));
}
private static String quoteString(final String string, final boolean singleQuoteEscape)
throws UnsupportedEncodingException {
throws UnsupportedEncodingException {
return ENUM_VALUE.matcher(string).matches()
? string
: singleQuoteEscape
? string
: singleQuoteEscape
? "'" + string + "'"
: "\"" + string + "\"";
}
@ -276,7 +210,7 @@ public final class URIUtils {
} else if (version.compareTo(ODataServiceVersion.V40) >= 0 && obj instanceof Collection) {
final StringBuffer buffer = new StringBuffer("[");
for (@SuppressWarnings("unchecked")
final Iterator<Object> itor = ((Collection<Object>) obj).iterator(); itor.hasNext();) {
final Iterator<Object> itor = ((Collection<Object>) obj).iterator(); itor.hasNext();) {
buffer.append(escape(version, itor.next(), false));
if (itor.hasNext()) {
buffer.append(',');
@ -288,8 +222,8 @@ public final class URIUtils {
} else if (version.compareTo(ODataServiceVersion.V40) >= 0 && obj instanceof Map) {
final StringBuffer buffer = new StringBuffer("{");
for (@SuppressWarnings("unchecked")
final Iterator<Map.Entry<String, Object>> itor =
((Map<String, Object>) obj).entrySet().iterator(); itor.hasNext();) {
final Iterator<Map.Entry<String, Object>> itor =
((Map<String, Object>) obj).entrySet().iterator(); itor.hasNext();) {
final Map.Entry<String, Object> entry = itor.next();
buffer.append("\"").append(entry.getKey()).append("\"");
@ -303,45 +237,49 @@ public final class URIUtils {
value = buffer.toString();
} else {
value = (obj instanceof ParameterAlias)
value =
(obj instanceof ParameterAlias)
? "@" + ((ParameterAlias) obj).getAlias()
: (obj instanceof Boolean)
? BooleanUtils.toStringTrueFalse((Boolean) obj)
: (obj instanceof UUID)
? prefix(version, EdmPrimitiveTypeKind.Guid)
+ obj.toString()
+ suffix(version, EdmPrimitiveTypeKind.Guid)
: (obj instanceof byte[])
? EdmBinary.getInstance().toUriLiteral(Hex.encodeHexString((byte[]) obj))
: (obj instanceof Timestamp)
? timestamp(version, (Timestamp) obj)
: (obj instanceof Calendar)
? calendar(version, (Calendar) obj)
: (obj instanceof Duration)
? duration(version, (Duration) obj)
: (obj instanceof BigDecimal)
? EdmDecimal.getInstance().valueToString(obj, null, null,
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null)
+ suffix(version, EdmPrimitiveTypeKind.Decimal)
: (obj instanceof Double)
? EdmDouble.getInstance().valueToString(obj, null, null,
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null)
+ suffix(version, EdmPrimitiveTypeKind.Double)
: (obj instanceof Float)
? EdmSingle.getInstance().valueToString(obj, null, null,
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null)
+ suffix(version, EdmPrimitiveTypeKind.Single)
: (obj instanceof Long)
? 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)
? quoteString((String) obj, singleQuoteEscape)
: obj.toString();
? BooleanUtils.toStringTrueFalse((Boolean) obj)
: (obj instanceof UUID)
? prefix(version, EdmPrimitiveTypeKind.Guid)
+ obj.toString()
+ suffix(version, EdmPrimitiveTypeKind.Guid)
: (obj instanceof byte[])
? EdmBinary.getInstance().toUriLiteral(Hex.encodeHexString((byte[]) obj))
: (obj instanceof Timestamp)
? timestamp(version, (Timestamp) obj)
: (obj instanceof Calendar)
? calendar(version, (Calendar) obj)
: (obj instanceof Duration)
? duration(version, (Duration) obj)
: (obj instanceof BigDecimal)
? EdmDecimal.getInstance().valueToString(obj, null, null,
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null)
+ suffix(version, EdmPrimitiveTypeKind.Decimal)
: (obj instanceof Double)
? EdmDouble.getInstance().valueToString(obj, null, null,
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null)
+ suffix(version, EdmPrimitiveTypeKind.Double)
: (obj instanceof Float)
? EdmSingle.getInstance().valueToString(obj, null, null,
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null)
+ suffix(version, EdmPrimitiveTypeKind.Single)
: (obj instanceof Long)
? 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)
? quoteString((String) obj, singleQuoteEscape)
: obj.toString();
}
} catch (Exception e) {
LOG.warn("While escaping '{}', using toString()", obj, e);
@ -384,7 +322,6 @@ public final class URIUtils {
entity = new InputStreamEntity(input, -1);
}
if (!useChunked && entity.getContentLength() < 0) {
LOG.error("Could not determine length - request will be sent as chunked.");
useChunked = true;
@ -411,7 +348,7 @@ public final class URIUtils {
}
public static URI buildFunctionInvokeURI(
final URI uri, final Map<String, ODataValue> parameters, final ODataServiceVersion serviceVersion) {
final URI uri, final Map<String, ODataValue> parameters, final ODataServiceVersion serviceVersion) {
if (serviceVersion.compareTo(ODataServiceVersion.V40) >= 0) {
final String rawQuery = uri.getRawQuery();
@ -432,21 +369,21 @@ public final class URIUtils {
} else if (param.getValue().isCollection()) {
value = param.getValue().asCollection().asJavaCollection();
} else if (param.getValue() instanceof org.apache.olingo.commons.api.domain.ODataValue
&& ((org.apache.olingo.commons.api.domain.ODataValue) param.getValue()).isEnum()) {
&& ((org.apache.olingo.commons.api.domain.ODataValue) param.getValue()).isEnum()) {
value = ((org.apache.olingo.commons.api.domain.ODataValue) param.getValue()).asEnum().toString();
}
inlineParams.append(URIUtils.escape(serviceVersion, value)).append(',');
}
if (inlineParams.length() > 0) {
inlineParams.deleteCharAt(inlineParams.length() - 1);
}
try {
return URI.create(baseURI + "(" + URLEncoder.encode(inlineParams.toString(), Constants.UTF8) + ")"
+ (StringUtils.isNotBlank(rawQuery) ? "?" + rawQuery : StringUtils.EMPTY));
+ (StringUtils.isNotBlank(rawQuery) ? "?" + rawQuery : StringUtils.EMPTY));
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException("While adding GET parameters", e);
}

View File

@ -20,22 +20,16 @@ package org.apache.olingo.commons.api.edm;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public enum EdmPrimitiveTypeKind {
Binary,
Boolean,
Byte,
SByte,
Date(new ODataServiceVersion[] { ODataServiceVersion.V40 }),
DateTime(new ODataServiceVersion[] { ODataServiceVersion.V30 }),
Date,
DateTimeOffset,
Time(new ODataServiceVersion[] { ODataServiceVersion.V30 }),
TimeOfDay(new ODataServiceVersion[] { ODataServiceVersion.V40 }),
Duration(new ODataServiceVersion[] { ODataServiceVersion.V40 }),
TimeOfDay,
Duration,
Decimal,
Single,
Double,
@ -62,20 +56,6 @@ public enum EdmPrimitiveTypeKind {
GeometryMultiPolygon,
GeometryCollection;
private final List<ODataServiceVersion> versions;
EdmPrimitiveTypeKind() {
versions = Collections.unmodifiableList(
Arrays.asList(new ODataServiceVersion[] { ODataServiceVersion.V30, ODataServiceVersion.V40 }));
}
EdmPrimitiveTypeKind(final ODataServiceVersion[] versions) {
this.versions = Collections.unmodifiableList(Arrays.asList(versions.clone()));
}
public List<ODataServiceVersion> getSupportedVersions() {
return versions;
}
/**
* Checks if is a geospatial type.
@ -95,13 +75,9 @@ public enum EdmPrimitiveTypeKind {
return new FullQualifiedName(EdmPrimitiveType.EDM_NAMESPACE, toString());
}
public static EdmPrimitiveTypeKind valueOf(final ODataServiceVersion version, final String name) {
final EdmPrimitiveTypeKind kind = valueOf(name);
if (!kind.versions.contains(version)) {
throw new IllegalArgumentException(kind + " not allowed in " + version);
}
return kind;
}
// public static EdmPrimitiveTypeKind valueOf(final ODataServiceVersion version, final String name) {
// return valueOf(name);
// }
/**
* Gets <tt>EdmPrimitiveTypeKind</tt> from a full-qualified type name, for the given OData protocol version.
@ -131,9 +107,9 @@ public enum EdmPrimitiveTypeKind {
}
final EdmPrimitiveTypeKind kind = valueOf(fqn.substring(4));
if (!kind.versions.contains(version)) {
throw new IllegalArgumentException(kind + " not allowed in " + version);
}
// if (!kind.versions.contains(version)) {
// throw new IllegalArgumentException(kind + " not allowed in " + version);
// }
return kind;
}

View File

@ -109,7 +109,7 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory {
@Override
public ODataPrimitiveValue.Builder newPrimitiveValueBuilder() {
return new ODataPrimitiveValueImpl.BuilderImpl(version);
return new ODataPrimitiveValueImpl.BuilderImpl();
}
@Override

View File

@ -30,7 +30,6 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
public class ODataPrimitiveValueImpl extends AbstractODataValue implements ODataValue, ODataPrimitiveValue {
@ -39,13 +38,10 @@ public class ODataPrimitiveValueImpl extends AbstractODataValue implements OData
private final ODataPrimitiveValueImpl instance;
public BuilderImpl(final ODataServiceVersion version) {
this.version = version;
public BuilderImpl() {
instance = new ODataPrimitiveValueImpl();
}
private final ODataServiceVersion version;
@Override
public BuilderImpl setType(final EdmType type) {
EdmPrimitiveTypeKind primitiveTypeKind = null;
@ -60,10 +56,6 @@ public class ODataPrimitiveValueImpl extends AbstractODataValue implements OData
@Override
public BuilderImpl setType(final EdmPrimitiveTypeKind type) {
if (type != null && !type.getSupportedVersions().contains(version)) {
throw new IllegalArgumentException(String.format(
"Type %s not supported by OData version %s", type.toString(), version));
}
if (type == EdmPrimitiveTypeKind.Stream) {
throw new IllegalArgumentException(String.format(
"Cannot build a primitive value for %s", EdmPrimitiveTypeKind.Stream.toString()));

View File

@ -1,135 +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.EdmPrimitiveTypeException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
/**
* Implementation of the EDM primitive type DateTime.
*/
public final class EdmDateTime extends SingletonPrimitiveType {
public static final ThreadLocal<SimpleDateFormat> DATE_FORMAT = new ThreadLocal<SimpleDateFormat>() {
@Override
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
}
};
private static final EdmDateTime INSTANCE = new EdmDateTime();
public static EdmDateTime getInstance() {
return INSTANCE;
}
@Override
public Class<?> getDefaultType() {
return Timestamp.class;
}
@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 String[] dateParts = value.split("\\.");
final Date date;
try {
date = DATE_FORMAT.get().parse(dateParts[0]);
} catch (ParseException e) {
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e);
}
TimeZone timezone = null;
String decimals = null;
if (dateParts.length > 1) {
int idx = dateParts[1].indexOf('+');
if (idx == -1) {
idx = dateParts[1].indexOf('-');
}
if (idx == -1) {
decimals = dateParts[1];
} else {
timezone = TimeZone.getTimeZone(dateParts[1].substring(idx));
decimals = dateParts[1].substring(0, idx);
}
}
final Calendar calendar = timezone == null ? Calendar.getInstance() : Calendar.getInstance(timezone);
calendar.setTime(date);
final Timestamp timestamp = new Timestamp(date.getTime());
if (decimals != null) {
if (decimals.length() > (precision == null ? 0 : precision)) {
throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints.");
}
final String milliSeconds = decimals.length() > 3
? decimals.substring(0, 3)
: decimals + "000".substring(decimals.length());
calendar.set(Calendar.MILLISECOND, Short.parseShort(milliSeconds));
if (!decimals.isEmpty()) {
final int nanos = Integer.parseInt(decimals.length() > 9 ? decimals.substring(0, 9) :
decimals + "000000000".substring(decimals.length()));
timestamp.setNanos(nanos);
}
}
if (returnType.isAssignableFrom(Calendar.class)) {
return returnType.cast(calendar);
} else if (returnType.isAssignableFrom(Timestamp.class)) {
return returnType.cast(timestamp);
} else {
throw new EdmPrimitiveTypeException("The literal '" + value
+ "' cannot be converted to value type " + 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 Calendar) {
final Calendar calendar = (Calendar) value;
Date date = calendar.getTime();
Integer fractionalSecs = calendar.get(Calendar.MILLISECOND);
final StringBuilder result = new StringBuilder().append(DATE_FORMAT.get().format(date));
EdmDateTimeOffset.appendMilliseconds(result, fractionalSecs, precision);
return result.toString();
} else if (value instanceof Timestamp) {
final Timestamp timestamp = (Timestamp) value;
Date date = new Date(timestamp.getTime());
Integer fractionalSecs = timestamp.getNanos();
final StringBuilder result = new StringBuilder().append(DATE_FORMAT.get().format(date));
EdmDateTimeOffset.appendFractionalSeconds(result, fractionalSecs, precision);
return result.toString();
} else {
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}
}

View File

@ -41,12 +41,8 @@ public final class EdmPrimitiveTypeFactory {
return EdmSByte.getInstance();
case Date:
return EdmDate.getInstance();
case DateTime:
return EdmDateTime.getInstance();
case DateTimeOffset:
return EdmDateTimeOffset.getInstance();
case Time:
return EdmTime.getInstance();
case TimeOfDay:
return EdmTimeOfDay.getInstance();
case Duration:

View File

@ -1,36 +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;
/**
* Implementation of the EDM primitive type Time.
*/
public final class EdmTime extends EdmDuration {
private static final EdmTime INSTANCE = new EdmTime();
public static EdmTime getInstance() {
return INSTANCE;
}
{
uriPrefix = "time'";
uriSuffix = "'";
}
}

View File

@ -29,7 +29,6 @@ public class DeserializerException extends ODataTranslatedException {
public static enum MessageKeys implements MessageKey {
NOT_IMPLEMENTED,
IO_EXCEPTION,
//TODO: create texts for the following message keys:
/** parameter: format */ UNSUPPORTED_FORMAT,
JSON_SYNTAX_EXCEPTION,
/** parameter: propertyName */ INVALID_NULL_PROPERTY,

View File

@ -18,7 +18,6 @@
*/
package org.apache.olingo.server.api.edm.provider;
//TODO: Do we really need this class?
public class EntitySetPath {
private String bindingParameter;

View File

@ -30,7 +30,6 @@ public class Term {
private FullQualifiedName baseTerm;
// TODO: AppliesTo is a list of csdl elements => should we put this list inside an enum?
private String appliesTo;
private boolean isCollection;

View File

@ -49,7 +49,13 @@ public interface FixedFormatSerializer {
InputStream primitiveValue(EdmPrimitiveType type, Object value, PrimitiveValueSerializerOptions options)
throws SerializerException;
// TODO: Document
// TODO: Return type
/**
* Serializes a batch response
* @param batchResponses
* @param boundary
* @return
* @throws BatchSerializerException
*/
InputStream batchResponse(List<ODataResponsePart> batchResponses, String boundary) throws BatchSerializerException;
}

View File

@ -43,7 +43,6 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.core.data.ComplexValueImpl;
import org.apache.olingo.commons.core.data.EntityImpl;
import org.apache.olingo.commons.core.data.EntitySetImpl;
@ -598,7 +597,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
throws DeserializerException {
EdmPrimitiveTypeKind primKind;
try {
primKind = EdmPrimitiveTypeKind.valueOf(ODataServiceVersion.V40, edmPrimitiveTypeName);
primKind = EdmPrimitiveTypeKind.valueOf(edmPrimitiveTypeName);
} catch (IllegalArgumentException e) {
throw new DeserializerException("Unknown Primitive Type: " + edmPrimitiveTypeName, e,
DeserializerException.MessageKeys.UNKNOWN_PRIMITIVE_TYPE, edmPrimitiveTypeName, propertyName);

View File

@ -37,12 +37,12 @@ public class EdmMappingTest {
@Test
public void initialMappingMustBeNull() {
Property property = new Property().setType(EdmPrimitiveTypeKind.DateTime.getFullQualifiedName());
Property property = new Property().setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName());
EdmProperty edmProperty = new EdmPropertyImpl(null, new FullQualifiedName("namespace.name"), property);
assertNull(edmProperty.getMapping());
Parameter parameter = new Parameter().setType(EdmPrimitiveTypeKind.DateTime.getFullQualifiedName());
Parameter parameter = new Parameter().setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName());
EdmParameter edmParameter = new EdmParameterImpl(null, parameter);
assertNull(edmParameter.getMapping());
@ -52,7 +52,7 @@ public class EdmMappingTest {
public void getDataClassForPrimTypeViaMapping() {
Mapping mapping = new Mapping().setMappedJavaClass(Date.class);
Property property = new Property()
.setType(EdmPrimitiveTypeKind.DateTime.getFullQualifiedName())
.setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName())
.setMapping(mapping);
EdmProperty edmProperty = new EdmPropertyImpl(null, new FullQualifiedName("namespace.name"), property);
@ -60,7 +60,7 @@ public class EdmMappingTest {
assertEquals(Date.class, edmProperty.getMapping().getMappedJavaClass());
Parameter parameter = new Parameter()
.setType(EdmPrimitiveTypeKind.DateTime.getFullQualifiedName())
.setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName())
.setMapping(mapping);
EdmParameter edmParameter = new EdmParameterImpl(null, parameter);

View File

@ -36,7 +36,6 @@ import org.apache.olingo.commons.core.edm.primitivetype.EdmInt64;
import org.apache.olingo.commons.core.edm.primitivetype.EdmSByte;
import org.apache.olingo.commons.core.edm.primitivetype.EdmSingle;
import org.apache.olingo.commons.core.edm.primitivetype.EdmString;
import org.apache.olingo.commons.core.edm.primitivetype.EdmTime;
import org.apache.olingo.commons.core.edm.primitivetype.EdmTimeOfDay;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.primitive.EdmNull;
@ -107,10 +106,6 @@ public class UntypedOperand extends VisitorOperand {
return new TypedOperand(newValue, EdmTimeOfDay.getInstance());
}
if ((newValue = tryCast(literal, EdmTime.getInstance())) != null) {
return new TypedOperand(newValue, EdmTime.getInstance());
}
if ((newValue = tryCast(literal, EdmDuration.getInstance())) != null) {
return new TypedOperand(newValue, EdmDuration.getInstance());
}

View File

@ -334,23 +334,6 @@ public class ResourceValidator implements TestValidator {
return this;
}
// TODO remove
/*
* public ResourceValidator isCollection(final boolean isCollection) {
* if (!(uriPathInfo instanceof UriResourcePartTyped)) {
* fail("invalid resource kind: " + uriPathInfo.getKind().toString());
* }
* UriResourcePartTyped uriPathInfoTyped = (UriResourcePartTyped) uriPathInfo;
*
* EdmType type = uriPathInfoTyped.getType();
* if (type == null) {
* fail("isCollection: type == null");
* }
* assertEquals(isCollection, uriPathInfoTyped.isCollection());
* return this;
* }
*/
public ResourceValidator isFilterString(final String expectedFilterTreeAsString) {
ExpressionImpl filterTree = (ExpressionImpl) uriInfo.getFilterOption().getExpression();