From 77c0ef5ccc81f224489a812545b2b22d2475a538 Mon Sep 17 00:00:00 2001 From: Christian Amend Date: Mon, 24 Aug 2015 16:12:35 +0200 Subject: [PATCH] [OLINGO-659] Small codestyle fixes --- .../core/serialization/ODataBinderImpl.java | 41 +++++++++---------- .../commons/core/edm/EdmEnumTypeImpl.java | 9 ++++ .../api/serializer/SerializerException.java | 1 + .../json/ServiceDocumentJsonSerializer.java | 7 +++- .../xml/MetadataDocumentXmlSerializer.java | 7 +++- .../xml/ServiceDocumentXmlSerializer.java | 30 ++++++++------ .../server-core-exceptions-i18n.properties | 1 + 7 files changed, 61 insertions(+), 35 deletions(-) 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 a870306c9..da799d416 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 @@ -30,26 +30,6 @@ import org.apache.olingo.client.api.EdmEnabledODataClient; import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.data.ServiceDocument; import org.apache.olingo.client.api.data.ServiceDocumentItem; -import org.apache.olingo.client.api.serialization.ODataBinder; -import org.apache.olingo.client.api.serialization.ODataSerializerException; -import org.apache.olingo.client.core.uri.URIUtils; -import org.apache.olingo.commons.api.Constants; -import org.apache.olingo.commons.api.data.Annotatable; -import org.apache.olingo.commons.api.data.Annotation; -import org.apache.olingo.commons.api.data.ComplexValue; -import org.apache.olingo.commons.api.data.ContextURL; -import org.apache.olingo.commons.api.data.DeletedEntity; -import org.apache.olingo.commons.api.data.Delta; -import org.apache.olingo.commons.api.data.DeltaLink; -import org.apache.olingo.commons.api.data.Entity; -import org.apache.olingo.commons.api.data.EntityCollection; -import org.apache.olingo.commons.api.data.Link; -import org.apache.olingo.commons.api.data.Linked; -import org.apache.olingo.commons.api.data.Operation; -import org.apache.olingo.commons.api.data.Property; -import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.data.Valuable; -import org.apache.olingo.commons.api.data.ValueType; import org.apache.olingo.client.api.domain.ClientAnnotatable; import org.apache.olingo.client.api.domain.ClientAnnotation; import org.apache.olingo.client.api.domain.ClientCollectionValue; @@ -69,10 +49,30 @@ import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.api.domain.ClientServiceDocument; import org.apache.olingo.client.api.domain.ClientValuable; import org.apache.olingo.client.api.domain.ClientValue; +import org.apache.olingo.client.api.serialization.ODataBinder; +import org.apache.olingo.client.api.serialization.ODataSerializerException; import org.apache.olingo.client.core.domain.ClientAnnotationImpl; import org.apache.olingo.client.core.domain.ClientDeletedEntityImpl; import org.apache.olingo.client.core.domain.ClientDeltaLinkImpl; import org.apache.olingo.client.core.domain.ClientPropertyImpl; +import org.apache.olingo.client.core.uri.URIUtils; +import org.apache.olingo.commons.api.Constants; +import org.apache.olingo.commons.api.data.Annotatable; +import org.apache.olingo.commons.api.data.Annotation; +import org.apache.olingo.commons.api.data.ComplexValue; +import org.apache.olingo.commons.api.data.ContextURL; +import org.apache.olingo.commons.api.data.DeletedEntity; +import org.apache.olingo.commons.api.data.Delta; +import org.apache.olingo.commons.api.data.DeltaLink; +import org.apache.olingo.commons.api.data.Entity; +import org.apache.olingo.commons.api.data.EntityCollection; +import org.apache.olingo.commons.api.data.Link; +import org.apache.olingo.commons.api.data.Linked; +import org.apache.olingo.commons.api.data.Operation; +import org.apache.olingo.commons.api.data.Property; +import org.apache.olingo.commons.api.data.ResWrap; +import org.apache.olingo.commons.api.data.Valuable; +import org.apache.olingo.commons.api.data.ValueType; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmBindingTarget; import org.apache.olingo.commons.api.edm.EdmComplexType; @@ -90,7 +90,6 @@ import org.apache.olingo.commons.api.edm.EdmStructuredType; import org.apache.olingo.commons.api.edm.EdmTerm; import org.apache.olingo.commons.api.edm.EdmType; 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.format.ContentType; import org.apache.olingo.commons.core.edm.EdmTypeInfo; diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java index 9b56ed258..2cc1d39d7 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java @@ -266,12 +266,21 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType { return getFullQualifiedName(); } + @Override + public int hashCode() { + return this.getFullQualifiedName().getFullQualifiedNameAsString().hashCode(); + } + @Override public boolean equals(Object obj){ if(obj == null){ return false; } + if(obj == this){ + return true; + } + if(obj instanceof EdmEnumType){ EdmEnumType other = (EdmEnumType) obj; if(this.getFullQualifiedName().equals(other.getFullQualifiedName())){ diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java index 64eb5d27d..6db82309e 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java @@ -27,6 +27,7 @@ public class SerializerException extends ODataLibraryException { /** Keys for exception texts in the resource bundle. */ public enum MessageKeys implements MessageKey { + NULL_METADATA_OR_EDM, NOT_IMPLEMENTED, /** parameter: format */ UNSUPPORTED_FORMAT, diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java index 30162c1ec..0136df4d1 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java @@ -27,6 +27,7 @@ import org.apache.olingo.commons.api.edm.EdmEntitySet; import org.apache.olingo.commons.api.edm.EdmFunctionImport; import org.apache.olingo.commons.api.edm.EdmSingleton; import org.apache.olingo.server.api.ServiceMetadata; +import org.apache.olingo.server.api.serializer.SerializerException; import com.fasterxml.jackson.core.JsonGenerator; @@ -42,7 +43,11 @@ public class ServiceDocumentJsonSerializer { private final boolean isODataMetadataNone; public ServiceDocumentJsonSerializer(final ServiceMetadata metadata, final String serviceRoot, - final boolean isODataMetadataNone) { + final boolean isODataMetadataNone) throws SerializerException { + if (metadata == null || metadata.getEdm() == null) { + throw new SerializerException("Service Metadata and EDM must not be null for a service.", + SerializerException.MessageKeys.NULL_METADATA_OR_EDM); + } this.metadata = metadata; this.serviceRoot = serviceRoot; this.isODataMetadataNone = isODataMetadataNone; diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java index 045783cfc..81d516b93 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java @@ -56,6 +56,7 @@ import org.apache.olingo.server.api.edmx.EdmxReference; import org.apache.olingo.server.api.edmx.EdmxReferenceInclude; import org.apache.olingo.server.api.edmx.EdmxReferenceIncludeAnnotation; import org.apache.olingo.server.api.serializer.ODataSerializer; +import org.apache.olingo.server.api.serializer.SerializerException; public class MetadataDocumentXmlSerializer { @@ -123,7 +124,11 @@ public class MetadataDocumentXmlSerializer { private final ServiceMetadata serviceMetadata; private final Map namespaceToAlias = new HashMap(); - public MetadataDocumentXmlSerializer(final ServiceMetadata serviceMetadata) { + public MetadataDocumentXmlSerializer(final ServiceMetadata serviceMetadata) throws SerializerException { + if (serviceMetadata == null || serviceMetadata.getEdm() == null) { + throw new SerializerException("Service Metadata and EDM must not be null for a service.", + SerializerException.MessageKeys.NULL_METADATA_OR_EDM); + } this.serviceMetadata = serviceMetadata; } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java index ed60f3647..b9312276b 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java @@ -30,6 +30,7 @@ import org.apache.olingo.commons.api.edm.EdmSingleton; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.edmx.EdmxReference; import org.apache.olingo.server.api.serializer.ODataSerializer; +import org.apache.olingo.server.api.serializer.SerializerException; public class ServiceDocumentXmlSerializer { public static final String KIND = "kind"; @@ -37,7 +38,7 @@ public class ServiceDocumentXmlSerializer { public static final String FUNCTION_IMPORT = "FunctionImport"; public static final String SINGLETON = "Singleton"; public static final String SERVICE_DOCUMENT = "ServiceDocument"; - + private static final String APP = "app"; private static final String NS_APP = "http://www.w3.org/2007/app"; private static final String ATOM = "atom"; @@ -48,7 +49,12 @@ public class ServiceDocumentXmlSerializer { private final ServiceMetadata metadata; private final String serviceRoot; - public ServiceDocumentXmlSerializer(final ServiceMetadata metadata, final String serviceRoot) { + public ServiceDocumentXmlSerializer(final ServiceMetadata metadata, final String serviceRoot) + throws SerializerException { + if (metadata == null || metadata.getEdm() == null) { + throw new SerializerException("Service Metadata and EDM must not be null for a service.", + SerializerException.MessageKeys.NULL_METADATA_OR_EDM); + } this.metadata = metadata; this.serviceRoot = serviceRoot; } @@ -56,15 +62,15 @@ public class ServiceDocumentXmlSerializer { public void writeServiceDocument(final XMLStreamWriter writer) throws XMLStreamException { final String metadataUri = (serviceRoot == null ? "" : serviceRoot.endsWith("/") ? serviceRoot : (serviceRoot + "/")) - + Constants.METADATA; - + + Constants.METADATA; + writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0"); writer.writeStartElement(APP, "service", NS_APP); writer.writeNamespace(ATOM, NS_ATOM); writer.writeNamespace(APP, NS_APP); writer.writeNamespace(METADATA, NS_METADATA); writer.writeAttribute(METADATA, NS_METADATA, "context", metadataUri); - + if (metadata != null && metadata.getServiceMetadataETagSupport() != null && metadata.getServiceMetadataETagSupport().getMetadataETag() != null) { @@ -73,25 +79,25 @@ public class ServiceDocumentXmlSerializer { } writer.writeStartElement(APP, "workspace", NS_APP); - + final Edm edm = metadata.getEdm(); writer.writeStartElement(ATOM, "title", NS_APP); writer.writeCharacters(edm.getEntityContainer(null).getFullQualifiedName().getFullQualifiedNameAsString()); writer.writeEndElement(); - + writeEntitySets(writer, edm); writeFunctionImports(writer, edm); writeSingletons(writer, edm); writeServiceDocuments(writer); writer.writeEndElement(); // end workspace - writer.writeEndElement(); // end service + writer.writeEndElement(); // end service } private void writeServiceDocuments(XMLStreamWriter writer) throws XMLStreamException { - + for (EdmxReference reference : this.metadata.getReferences()) { - writer.writeStartElement(METADATA , "service-document", NS_METADATA); + writer.writeStartElement(METADATA, "service-document", NS_METADATA); writer.writeAttribute("href", reference.getUri().toASCIIString()); writer.writeStartElement(ATOM, "title", NS_ATOM); writer.writeCharacters(reference.getUri().toASCIIString()); @@ -124,7 +130,7 @@ public class ServiceDocumentXmlSerializer { writer.writeStartElement(ATOM, "title", NS_ATOM); writer.writeCharacters(edmFunctionImport.getName()); writer.writeEndElement(); - writer.writeEndElement(); + writer.writeEndElement(); } } } @@ -135,7 +141,7 @@ public class ServiceDocumentXmlSerializer { writer.writeStartElement(METADATA, "singleton", NS_METADATA); writer.writeAttribute("href", edmSingleton.getName()); writer.writeStartElement(ATOM, "title", NS_ATOM); - writer.writeCharacters( edmSingleton.getName()); + writer.writeCharacters(edmSingleton.getName()); writer.writeEndElement(); writer.writeEndElement(); } diff --git a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties index 0e3ab995c..f6440fb13 100644 --- a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties +++ b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties @@ -86,6 +86,7 @@ ContentNegotiatorException.UNSUPPORTED_CONTENT_TYPE=The content type '%1$s' is n ContentNegotiatorException.NO_CONTENT_TYPE_SUPPORTED=No content type has been specified as supported. ContentNegotiatorException.UNSUPPORTED_FORMAT_OPTION=The $format option '%1$s' is not supported. +SerializerException.NULL_METADATA_OR_EDM=The server does not define any service metadata. SerializerException.NOT_IMPLEMENTED=The requested serialization method has not been implemented yet. SerializerException.UNSUPPORTED_FORMAT=The format '%1$s' is not supported. SerializerException.JSON_METADATA=The metadata document cannot be provided in JSON format.