Repository: olingo-odata4 Updated Branches: refs/heads/master 3344e05b3 -> 96223df38
[OLINGO-1191]Code improvements Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/96223df3 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/96223df3 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/96223df3 Branch: refs/heads/master Commit: 96223df38d29ca5fb138983b649aa8f8f69e0880 Parents: 3344e05 Author: Archana Rai <[email protected]> Authored: Tue Oct 24 10:52:54 2017 +0530 Committer: Archana Rai <[email protected]> Committed: Tue Oct 24 10:52:54 2017 +0530 ---------------------------------------------------------------------- .../header/ODataErrorResponseChecker.java | 2 +- .../client/core/edm/xml/ClientCsdlOnDelete.java | 8 ++--- .../core/edm/xml/annotation/ClientCsdlNull.java | 6 ++-- .../core/serialization/JsonSerializer.java | 2 +- .../core/serialization/ODataBinderImpl.java | 14 ++++---- .../core/edm/AbstractEdmAnnotatable.java | 9 +++--- .../commons/core/edm/EdmAnnotationImpl.java | 6 ++-- .../commons/core/edm/EdmEntityTypeImpl.java | 2 +- .../commons/core/edm/EdmProviderImpl.java | 21 ++++++------ .../olingo/commons/core/edm/FunctionMapKey.java | 13 ++++---- .../core/edm/annotation/EdmRecordImpl.java | 14 ++++---- .../olingo/server/core/MetadataParser.java | 8 ++--- .../olingo/server/core/OData4HttpHandler.java | 9 +++--- .../server/core/SchemaBasedEdmProvider.java | 20 +++++------- .../server/core/responses/ServiceResponse.java | 6 ++-- .../olingo/server/core/ODataDispatcher.java | 20 ++++++------ .../apache/olingo/server/core/ODataImpl.java | 2 +- .../deserializer/batch/BatchParserCommon.java | 12 +++---- .../deserializer/batch/BatchQueryOperation.java | 4 +-- .../batch/BatchTransformatorCommon.java | 11 +++---- .../server/core/deserializer/batch/Header.java | 2 +- .../json/EdmAssistedJsonSerializer.java | 34 +++++++++----------- .../JsonDeltaSerializerWithNavigations.java | 6 ++-- .../olingo/server/core/uri/parser/Parser.java | 16 ++++----- .../server/core/uri/parser/UriTokenizer.java | 12 +++---- .../server/core/uri/validator/UriValidator.java | 2 +- 26 files changed, 113 insertions(+), 148 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java index 2884acc..d79174c 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java @@ -80,7 +80,7 @@ public final class ODataErrorResponseChecker { statusLine.getReasonPhrase()); } - if (statusLine.getStatusCode() >= 500 && (error.getDetails() == null || error.getDetails().size() == 0) && + if (statusLine.getStatusCode() >= 500 && (error.getDetails() == null || error.getDetails().isEmpty()) && (error.getInnerError() == null || error.getInnerError().size() == 0)) { result = new ODataServerErrorException(statusLine); } else { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ClientCsdlOnDelete.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ClientCsdlOnDelete.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ClientCsdlOnDelete.java index 68ac862..d645f15 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ClientCsdlOnDelete.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ClientCsdlOnDelete.java @@ -43,11 +43,9 @@ class ClientCsdlOnDelete extends CsdlOnDelete implements Serializable { for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); - if (token == JsonToken.FIELD_NAME) { - if ("Action".equals(jp.getCurrentName())) { - CsdlOnDeleteAction action = CsdlOnDeleteAction.valueOf(jp.nextTextValue()); - ondelete.setAction(action); - } + if (token == JsonToken.FIELD_NAME && "Action".equals(jp.getCurrentName())) { + CsdlOnDeleteAction action = CsdlOnDeleteAction.valueOf(jp.nextTextValue()); + ondelete.setAction(action); } } return ondelete; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ClientCsdlNull.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ClientCsdlNull.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ClientCsdlNull.java index 0b0d979..c6e1578 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ClientCsdlNull.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ClientCsdlNull.java @@ -42,10 +42,8 @@ class ClientCsdlNull extends CsdlNull implements Serializable { final ClientCsdlNull _null = new ClientCsdlNull(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); - if (token == JsonToken.FIELD_NAME) { - if ("Annotation".equals(jp.getCurrentName())) { - _null.getAnnotations().add(jp.readValueAs(ClientCsdlAnnotation.class)); - } + if (token == JsonToken.FIELD_NAME && "Annotation".equals(jp.getCurrentName())) { + _null.getAnnotations().add(jp.readValueAs(ClientCsdlAnnotation.class)); } } return _null; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/JsonSerializer.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/JsonSerializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/JsonSerializer.java index 90aba4f..d7198d9 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/JsonSerializer.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/JsonSerializer.java @@ -377,7 +377,7 @@ public class JsonSerializer implements ODataSerializer { private boolean isIEEE754Compatible() { final String parameter = contentType.getParameters().get(ContentType.PARAMETER_IEEE754_COMPATIBLE); - return parameter == null ? false : "true".equals(parameter.toLowerCase()); + return parameter == null ? false : "true".equalsIgnoreCase(parameter); } private boolean isODataMetadataNone() { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java index c2080fa..bc96429 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java @@ -715,14 +715,12 @@ public class ODataBinderImpl implements ODataBinder { if (idx != -1) { String navigationName = property.getName().substring(0, idx); edmProperty = ((EdmEntityType) edmType).getProperty(navigationName); - if (edmProperty != null) { - if (edmProperty instanceof EdmNavigationProperty) { - ClientLink link = entity.getNavigationLink(navigationName); - if (link == null) { - countMap.put(navigationName, (Integer)property.getValue()); - } else { - link.asInlineEntitySet().getEntitySet().setCount((Integer)property.getValue()); - } + if (edmProperty != null && edmProperty instanceof EdmNavigationProperty) { + ClientLink link = entity.getNavigationLink(navigationName); + if (link == null) { + countMap.put(navigationName, (Integer) property.getValue()); + } else { + link.asInlineEntitySet().getEntitySet().setCount((Integer) property.getValue()); } } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmAnnotatable.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmAnnotatable.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmAnnotatable.java index 658ca0b..8582030 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmAnnotatable.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmAnnotatable.java @@ -44,11 +44,10 @@ public abstract class AbstractEdmAnnotatable implements EdmAnnotatable { public EdmAnnotation getAnnotation(final EdmTerm term, String qualifier) { EdmAnnotation result = null; for (EdmAnnotation annotation : getAnnotations()) { - if (term.getFullQualifiedName().equals(annotation.getTerm().getFullQualifiedName())) { - if (qualifierEqual(qualifier, annotation.getQualifier())) { - result = annotation; - break; - } + if (term.getFullQualifiedName().equals(annotation.getTerm().getFullQualifiedName()) + && qualifierEqual(qualifier, annotation.getQualifier())) { + result = annotation; + break; } } return result; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmAnnotationImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmAnnotationImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmAnnotationImpl.java index 09bfefd..c4ab910 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmAnnotationImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmAnnotationImpl.java @@ -58,10 +58,8 @@ public class EdmAnnotationImpl extends AbstractEdmAnnotatable implements EdmAnno @Override public EdmExpression getExpression() { - if (expression == null) { - if (annotation.getExpression() != null) { - expression = AbstractEdmExpression.getExpression(edm, annotation.getExpression()); - } + if (expression == null && annotation.getExpression() != null) { + expression = AbstractEdmExpression.getExpression(edm, annotation.getExpression()); } return expression; } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntityTypeImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntityTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntityTypeImpl.java index c532cb3..07285be 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntityTypeImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntityTypeImpl.java @@ -59,7 +59,7 @@ public class EdmEntityTypeImpl extends AbstractEdmStructuredType implements EdmE entityBaseType = (EdmEntityType) baseType; } if (baseType == null - || (baseType.isAbstract() && ((EdmEntityType) baseType).getKeyPropertyRefs().size() == 0)) { + || (baseType.isAbstract() && ((EdmEntityType) baseType).getKeyPropertyRefs().isEmpty())) { final List<CsdlPropertyRef> key = entityType.getKey(); if (key != null) { final List<EdmKeyPropertyRef> edmKey = new ArrayList<EdmKeyPropertyRef>(); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmProviderImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmProviderImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmProviderImpl.java index 1cdcc17..6f5ea64 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmProviderImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmProviderImpl.java @@ -230,21 +230,20 @@ public class EdmProviderImpl extends AbstractEdm { for (CsdlFunction function : functions) { if (function.isBound()) { List<CsdlParameter> providerParameters = function.getParameters(); - if (providerParameters == null || providerParameters.size() == 0) { + if (providerParameters == null || providerParameters.isEmpty()) { throw new EdmException("No parameter specified for bound function: " + functionName); } final CsdlParameter bindingParameter = providerParameters.get(0); if (bindingParameterTypeName.equals(bindingParameter.getTypeFQN()) - && isBindingParameterCollection.booleanValue() == bindingParameter.isCollection()) { + && isBindingParameterCollection.booleanValue() == bindingParameter.isCollection() + && parameterNamesCopy.size() == providerParameters.size() - 1) { - if (parameterNamesCopy.size() == providerParameters.size() - 1) { - final List<String> providerParameterNames = new ArrayList<String>(); - for (int i = 1; i < providerParameters.size(); i++) { - providerParameterNames.add(providerParameters.get(i).getName()); - } - if (parameterNamesCopy.containsAll(providerParameterNames)) { - return new EdmFunctionImpl(this, functionName, function); - } + final List<String> providerParameterNames = new ArrayList<String>(); + for (int i = 1; i < providerParameters.size(); i++) { + providerParameterNames.add(providerParameters.get(i).getName()); + } + if (parameterNamesCopy.containsAll(providerParameterNames)) { + return new EdmFunctionImpl(this, functionName, function); } } } @@ -382,7 +381,7 @@ public class EdmProviderImpl extends AbstractEdm { CsdlTerm providerTerm = provider.getTerm(termName); if (providerTerm != null) { return new EdmTermImpl(this, termName.getNamespace(), providerTerm); - } else if (termSchemaDefinition != null && termSchemaDefinition.size() > 0) { + } else if (termSchemaDefinition != null && !termSchemaDefinition.isEmpty()) { for (CsdlSchema schema : termSchemaDefinition) { if (schema.getNamespace().equalsIgnoreCase(termName.getNamespace())) { List<CsdlTerm> terms = schema.getTerms(); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/FunctionMapKey.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/FunctionMapKey.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/FunctionMapKey.java index b2afdd0..ed35149 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/FunctionMapKey.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/FunctionMapKey.java @@ -77,16 +77,15 @@ public final class FunctionMapKey { && (isBindingParameterCollection == null && other.isBindingParameterCollection == null) || (isBindingParameterCollection != null - && isBindingParameterCollection.equals(other.isBindingParameterCollection))) { + && isBindingParameterCollection.equals(other.isBindingParameterCollection)) + && parameterNames.size() == other.parameterNames.size()) { - if (parameterNames.size() == other.parameterNames.size()) { - for (String name : parameterNames) { - if (!other.parameterNames.contains(name)) { - return false; - } + for (String name : parameterNames) { + if (!other.parameterNames.contains(name)) { + return false; } - return true; } + return true; } return false; } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmRecordImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmRecordImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmRecordImpl.java index 811f82b..8e1d946 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmRecordImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmRecordImpl.java @@ -58,15 +58,13 @@ public class EdmRecordImpl extends AbstractEdmAnnotatableDynamicExpression imple @Override public EdmStructuredType getType() { - if (type == null) { + if (type == null && record.getType() != null) { // record MAY have a type information. - if (record.getType() != null) { - final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(record.getType()).build(); - if (typeInfo.isEntityType() || typeInfo.isComplexType()) { - type = typeInfo.isEntityType() ? typeInfo.getEntityType() : typeInfo.getComplexType(); - } else { - throw new EdmException("Record expressions must specify a complex or entity type."); - } + final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(record.getType()).build(); + if (typeInfo.isEntityType() || typeInfo.isComplexType()) { + type = typeInfo.isEntityType() ? typeInfo.getEntityType() : typeInfo.getComplexType(); + } else { + throw new EdmException("Record expressions must specify a complex or entity type."); } } return type; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/MetadataParser.java ---------------------------------------------------------------------- diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/MetadataParser.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/MetadataParser.java index 873be7d..58868c8 100644 --- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/MetadataParser.java +++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/MetadataParser.java @@ -673,11 +673,9 @@ public class MetadataParser { readAttributeExpressions(element, target); for (ConstantExpressionType type:ConstantExpressionType.values()) { - if (name.equals(type.name())) { - if (reader.peek().isCharacters()) { - CsdlExpression expr = new CsdlConstantExpression(type, elementValue(reader, element)); - write(target, expr); - } + if (name.equals(type.name()) && reader.peek().isCharacters()) { + CsdlExpression expr = new CsdlConstantExpression(type, elementValue(reader, element)); + write(target, expr); } } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4HttpHandler.java ---------------------------------------------------------------------- diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4HttpHandler.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4HttpHandler.java index 7f2b53d..5c2c204 100644 --- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4HttpHandler.java +++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4HttpHandler.java @@ -98,11 +98,10 @@ public class OData4HttpHandler extends ODataHttpHandlerImpl { final String maxVersion = request.getHeader(HttpHeader.ODATA_MAX_VERSION); response.setHeader(HttpHeader.ODATA_VERSION, ODataServiceVersion.V40.toString()); - if (maxVersion != null) { - if (ODataServiceVersion.isBiggerThan(ODataServiceVersion.V40.toString(), maxVersion)) { - throw new ODataHandlerException("ODataVersion not supported: " + maxVersion, //$NON-NLS-1$ - ODataHandlerException.MessageKeys.ODATA_VERSION_NOT_SUPPORTED, maxVersion); - } + if (maxVersion != null + && ODataServiceVersion.isBiggerThan(ODataServiceVersion.V40.toString(), maxVersion)) { + throw new ODataHandlerException("ODataVersion not supported: " + maxVersion, //$NON-NLS-1$ + ODataHandlerException.MessageKeys.ODATA_VERSION_NOT_SUPPORTED, maxVersion); } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/SchemaBasedEdmProvider.java ---------------------------------------------------------------------- diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/SchemaBasedEdmProvider.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/SchemaBasedEdmProvider.java index 829323f..128aecb 100644 --- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/SchemaBasedEdmProvider.java +++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/SchemaBasedEdmProvider.java @@ -336,12 +336,10 @@ public class SchemaBasedEdmProvider implements CsdlEdmProvider { @Override public CsdlEntityType getEntityType(final FullQualifiedName fqn) throws ODataException { CsdlSchema schema = getSchema(fqn.getNamespace()); - if (schema != null) { - if (schema.getEntityTypes() != null) { - for (CsdlEntityType type : schema.getEntityTypes()) { - if (type.getName().equals(fqn.getName())) { - return type; - } + if (schema != null && schema.getEntityTypes() != null) { + for (CsdlEntityType type : schema.getEntityTypes()) { + if (type.getName().equals(fqn.getName())) { + return type; } } } @@ -351,12 +349,10 @@ public class SchemaBasedEdmProvider implements CsdlEdmProvider { @Override public CsdlComplexType getComplexType(final FullQualifiedName fqn) throws ODataException { CsdlSchema schema = getSchema(fqn.getNamespace()); - if (schema != null) { - if (schema.getComplexTypes() != null) { - for (CsdlComplexType type : schema.getComplexTypes()) { - if (type.getName().equals(fqn.getName())) { - return type; - } + if (schema != null && schema.getComplexTypes() != null) { + for (CsdlComplexType type : schema.getComplexTypes()) { + if (type.getName().equals(fqn.getName())) { + return type; } } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponse.java ---------------------------------------------------------------------- diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponse.java index d0a9f23..50a4303 100644 --- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponse.java +++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponse.java @@ -59,10 +59,8 @@ public abstract class ServiceResponse { protected void close() { if (!this.closed) { - if (this.strictApplyPreferences) { - if (!preferences.isEmpty()) { - assert(this.response.getAllHeaders().get("Preference-Applied") != null); - } + if (this.strictApplyPreferences && !preferences.isEmpty()) { + assert (this.response.getAllHeaders().get("Preference-Applied") != null); } this.closed = true; } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataDispatcher.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataDispatcher.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataDispatcher.java index d460ee7..63f45c5 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataDispatcher.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataDispatcher.java @@ -571,17 +571,15 @@ public class ODataDispatcher { /*Delete method is not allowed for Entities navigating to Singleton*/ private void validateIsSingleton(HttpMethod method) throws ODataHandlerException { - final int lastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 1; - final UriResource pathSegment = uriInfo.getUriResourceParts().get(lastPathSegmentIndex); - if(pathSegment instanceof UriResourceNavigation){ - if(uriInfo.getUriResourceParts().get(lastPathSegmentIndex-1) instanceof UriResourceEntitySet){ - if(((UriResourceEntitySet)uriInfo.getUriResourceParts(). - get(lastPathSegmentIndex-1)).getEntitySet().getRelatedBindingTarget( - pathSegment.getSegmentValue())instanceof EdmSingleton){ - throwMethodNotAllowed(method); - } - } - } + final int lastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 1; + final UriResource pathSegment = uriInfo.getUriResourceParts().get(lastPathSegmentIndex); + if (pathSegment instanceof UriResourceNavigation + && uriInfo.getUriResourceParts().get(lastPathSegmentIndex - 1) instanceof UriResourceEntitySet + && ((UriResourceEntitySet) uriInfo.getUriResourceParts().get(lastPathSegmentIndex - 1)).getEntitySet() + .getRelatedBindingTarget( + pathSegment.getSegmentValue()) instanceof EdmSingleton) { + throwMethodNotAllowed(method); + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java index c657952..c3507fb 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java @@ -137,7 +137,7 @@ public class ODataImpl extends OData { public EdmDeltaSerializer createEdmDeltaSerializer(final ContentType contentType, final List<String> versions) throws SerializerException { if (contentType.isCompatible(ContentType.APPLICATION_JSON)) { - if(versions!=null && versions.size()>0){ + if(versions!=null && !versions.isEmpty()){ return getMaxVersion(versions)>4 ? new JsonDeltaSerializerWithNavigations(contentType): new JsonDeltaSerializer(contentType); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommon.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommon.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommon.java index d1f4392..fee4697 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommon.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommon.java @@ -140,12 +140,12 @@ public class BatchParserCommon { } // Remove preamble - if (messageParts.size() > 0) { + if (!messageParts.isEmpty()) { messageParts.remove(0); } if (!isEndReached) { - final int lineNumber = (message.size() > 0) ? message.get(0).getLineNumber() : 0; + final int lineNumber = (!message.isEmpty()) ? message.get(0).getLineNumber() : 0; throw new BatchDeserializerException("Missing close boundary delimiter", BatchDeserializerException.MessageKeys.MISSING_CLOSE_DELIMITER, Integer.toString(lineNumber)); } @@ -154,7 +154,7 @@ public class BatchParserCommon { } private static void removeEndingCRLFFromList(final List<Line> list) { - if (list.size() > 0) { + if (!list.isEmpty()) { Line lastLine = list.remove(list.size() - 1); list.add(removeEndingCRLF(lastLine)); } @@ -170,7 +170,7 @@ public class BatchParserCommon { } public static Header consumeHeaders(final List<Line> remainingMessage) { - final int headerLineNumber = remainingMessage.size() != 0 ? remainingMessage.get(0).getLineNumber() : 0; + final int headerLineNumber = !remainingMessage.isEmpty() ? remainingMessage.get(0).getLineNumber() : 0; final Header headers = new Header(headerLineNumber); final Iterator<Line> iter = remainingMessage.iterator(); Line currentLine; @@ -197,11 +197,11 @@ public class BatchParserCommon { public static void consumeBlankLine(final List<Line> remainingMessage, final boolean isStrict) throws BatchDeserializerException { - if (remainingMessage.size() > 0 && remainingMessage.get(0).toString().matches("\\s*\r?\n\\s*")) { + if (!remainingMessage.isEmpty() && remainingMessage.get(0).toString().matches("\\s*\r?\n\\s*")) { remainingMessage.remove(0); } else { if (isStrict) { - final int lineNumber = (remainingMessage.size() > 0) ? remainingMessage.get(0).getLineNumber() : 0; + final int lineNumber = (!remainingMessage.isEmpty()) ? remainingMessage.get(0).getLineNumber() : 0; throw new BatchDeserializerException("Missing blank line", BatchDeserializerException.MessageKeys.MISSING_BLANK_LINE, "[None]", Integer.toString(lineNumber)); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchQueryOperation.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchQueryOperation.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchQueryOperation.java index ba32ced..a40ecb7 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchQueryOperation.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchQueryOperation.java @@ -46,13 +46,13 @@ public class BatchQueryOperation implements BatchPart { } protected Line consumeHttpStatusLine(final List<Line> message) throws BatchDeserializerException { - if (message.size() > 0 && !message.get(0).toString().trim().equals("")) { + if (!message.isEmpty() && !message.get(0).toString().trim().equals("")) { final Line method = message.get(0); message.remove(0); return method; } else { - final int line = (message.size() > 0) ? message.get(0).getLineNumber() : 0; + final int line = (!message.isEmpty()) ? message.get(0).getLineNumber() : 0; throw new BatchDeserializerException("Missing http request line", BatchDeserializerException.MessageKeys.INVALID_STATUS_LINE, "" + line); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java index 8b8e1d9..feb4569 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java @@ -81,12 +81,11 @@ public class BatchTransformatorCommon { public static void validateHost(final Header headers, final String baseUri) throws BatchDeserializerException { final HeaderField hostField = headers.getHeaderField(HttpHeader.HOST); - if (hostField != null) { - if (hostField.getValues().size() > 1 - || !URI.create(baseUri).getAuthority().equalsIgnoreCase(hostField.getValues().get(0).trim())) { - throw new BatchDeserializerException("Invalid Host header", - MessageKeys.INVALID_HOST, Integer.toString(headers.getLineNumber())); - } + if (hostField != null && + (hostField.getValues().size() > 1 + || !URI.create(baseUri).getAuthority().equalsIgnoreCase(hostField.getValues().get(0).trim()))) { + throw new BatchDeserializerException("Invalid Host header", + MessageKeys.INVALID_HOST, Integer.toString(headers.getLineNumber())); } } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/Header.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/Header.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/Header.java index 73a73a9..679fb84 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/Header.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/Header.java @@ -60,7 +60,7 @@ public class Header implements Iterable<HeaderField>, Cloneable { public boolean exists(final String name) { final HeaderField field = headers.get(name.toLowerCase(Locale.ENGLISH)); - return field != null && field.getValues().size() != 0; + return field != null && !field.getValues().isEmpty(); } public void removeHeader(final String name) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializer.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializer.java index 3d86953..fd68672 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializer.java @@ -180,13 +180,12 @@ public class EdmAssistedJsonSerializer implements EdmAssistedSerializer { valuable(json, property, name, edmProperty == null ? null : edmProperty.getType(), edmProperty); } - if (!isODataMetadataNone) { - if (entity.getEditLink() != null && entity.getEditLink().getHref() != null) { - json.writeStringField(Constants.JSON_EDIT_LINK, entity.getEditLink().getHref()); + if (!isODataMetadataNone && + entity.getEditLink() != null && entity.getEditLink().getHref() != null) { + json.writeStringField(Constants.JSON_EDIT_LINK, entity.getEditLink().getHref()); - if (entity.isMediaEntity()) { - json.writeStringField(Constants.JSON_MEDIA_READ_LINK, entity.getEditLink().getHref() + "/$value"); - } + if (entity.isMediaEntity()) { + json.writeStringField(Constants.JSON_MEDIA_READ_LINK, entity.getEditLink().getHref() + "/$value"); } } @@ -367,23 +366,22 @@ public class EdmAssistedJsonSerializer implements EdmAssistedSerializer { && !(valuable instanceof Annotation) && !valuable.isComplex()) { String typeName = valuable.getType(); - if (typeName == null && type == null) { - if (valuable.isPrimitive()) { - if (valuable.isCollection()) { - if (!valuable.asCollection().isEmpty()) { - final EdmPrimitiveTypeKind kind = EdmTypeInfo.determineTypeKind(valuable.asCollection().get(0)); - if (kind != null) { - typeName = "Collection(" + kind.getFullQualifiedName().getFullQualifiedNameAsString() + ')'; - } - } - } else { - final EdmPrimitiveTypeKind kind = EdmTypeInfo.determineTypeKind(valuable.asPrimitive()); + if (typeName == null && type == null && valuable.isPrimitive()) { + if (valuable.isCollection()) { + if (!valuable.asCollection().isEmpty()) { + final EdmPrimitiveTypeKind kind = EdmTypeInfo.determineTypeKind(valuable.asCollection().get(0)); if (kind != null) { - typeName = kind.getFullQualifiedName().getFullQualifiedNameAsString(); + typeName = "Collection(" + kind.getFullQualifiedName().getFullQualifiedNameAsString() + ')'; } } + } else { + final EdmPrimitiveTypeKind kind = EdmTypeInfo.determineTypeKind(valuable.asPrimitive()); + if (kind != null) { + typeName = kind.getFullQualifiedName().getFullQualifiedNameAsString(); + } } } + if (typeName != null) { json.writeStringField(name + Constants.JSON_TYPE, constructTypeExpression(typeName)); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/JsonDeltaSerializerWithNavigations.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/JsonDeltaSerializerWithNavigations.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/JsonDeltaSerializerWithNavigations.java index d2831b7..673a6dd 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/JsonDeltaSerializerWithNavigations.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/JsonDeltaSerializerWithNavigations.java @@ -213,14 +213,14 @@ public class JsonDeltaSerializerWithNavigations implements EdmDeltaSerializer { json.writeStringField(Constants.ELEM_REASON, ((DeletedEntity) deletedEntity).getReason().name()); List<Annotation> annotations = deletedEntity.getAnnotations(); - if (annotations != null && annotations.size() > 0) { + if (annotations != null && !annotations.isEmpty()) { for (Annotation annotation : annotations) { json.writeStringField(Constants.AT + annotation.getTerm(), annotation.getValue().toString()); } } json.writeEndObject(); List<Property> properties = deletedEntity.getProperties(); - if (properties != null && properties.size() > 0) { + if (properties != null && !properties.isEmpty()) { for (Property property : properties) { json.writeStringField(property.getName(), property.getValue().toString()); } @@ -491,7 +491,7 @@ public class JsonDeltaSerializerWithNavigations implements EdmDeltaSerializer { final Set<String> selected = all ? new HashSet<String>() : ExpandSelectHelper.getSelectedPropertyNames(select .getSelectItems()); for (final String propertyName : type.getPropertyNames()) { - if ((all || selected.contains(propertyName)) && properties.size() > 0) { + if ((all || selected.contains(propertyName)) && !properties.isEmpty()) { final EdmProperty edmProperty = type.getStructuralProperty(propertyName); final Property property = findProperty(propertyName, properties); final Set<List<String>> selectedPaths = all || edmProperty.isPrimitive() ? null : ExpandSelectHelper http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java index db70142..9bee0b6 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java @@ -261,16 +261,12 @@ public class Parser { if (lastSegment instanceof UriResourcePartTyped) { final UriResourcePartTyped typed = (UriResourcePartTyped) lastSegment; contextType = ParserHelper.getTypeInformation(typed); - if (contextType != null) { - if ((lastSegment instanceof UriResourceEntitySet && - (((UriResourceEntitySet) lastSegment).getTypeFilterOnCollection() != null - || ((UriResourceEntitySet) lastSegment).getTypeFilterOnEntry() != null)) - || contextUriInfo.getIdOption() != null) { - if (contextType instanceof EdmEntityType) { - contextUriInfo.setEntityTypeCast((EdmEntityType) contextType); - } - } - } + if (contextType != null && ((lastSegment instanceof UriResourceEntitySet && + (((UriResourceEntitySet) lastSegment).getTypeFilterOnCollection() != null + || ((UriResourceEntitySet) lastSegment).getTypeFilterOnEntry() != null)) + || contextUriInfo.getIdOption() != null) && contextType instanceof EdmEntityType) { + contextUriInfo.setEntityTypeCast((EdmEntityType) contextType); + } contextIsCollection = typed.isCollection(); } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriTokenizer.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriTokenizer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriTokenizer.java index 37d49ca..2363254 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriTokenizer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriTokenizer.java @@ -1065,10 +1065,8 @@ public class UriTokenizer { if (nextConstantIgnoreCase("duration") && nextCharacter('\'')) { nextSign(); if (nextCharacter('P') || nextCharacter('p')) { - if (nextIntegerValue(false)) { - if (!(nextCharacter('D') || nextCharacter('d'))) { - return false; - } + if (nextIntegerValue(false) && (!(nextCharacter('D') || nextCharacter('d')))) { + return false; } if (nextCharacter('T') || nextCharacter('t')) { boolean hasNumber = false; @@ -1085,10 +1083,8 @@ public class UriTokenizer { } } if (hasNumber || nextIntegerValue(false)) { - if (nextCharacter('.')) { - if (!nextIntegerValue(false)) { - return false; - } + if (nextCharacter('.') && !nextIntegerValue(false)) { + return false; } if (!(nextCharacter('S') || nextCharacter('s'))) { return false; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96223df3/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java index f94425f..b5b62ee 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java @@ -412,7 +412,7 @@ public class UriValidator { private void validatePropertyOperations(final UriInfo uriInfo, final HttpMethod method) throws UriValidationException { final List<UriResource> parts = uriInfo.getUriResourceParts(); - final UriResource last = parts.size() > 0 ? parts.get(parts.size() - 1) : null; + final UriResource last = !parts.isEmpty() ? parts.get(parts.size() - 1) : null; final UriResource previous = parts.size() > 1 ? parts.get(parts.size() - 2) : null; if (last != null && (last.getKind() == UriResourceKind.primitiveProperty
