From 26c67648468471149e32016f4892d484a5447bb8 Mon Sep 17 00:00:00 2001 From: Christian Amend Date: Mon, 26 Oct 2015 16:01:16 +0100 Subject: [PATCH] [OLINGO-587] Enable title for service document --- .../apache/olingo/commons/api/Constants.java | 2 ++ .../commons/api/edm/EdmBindingTarget.java | 6 ++++++ .../commons/api/edm/EdmFunctionImport.java | 6 ++++++ .../api/edm/provider/CsdlBindingTarget.java | 19 +++++++++++++++++++ .../api/edm/provider/CsdlEntitySet.java | 6 ++++++ .../api/edm/provider/CsdlFunctionImport.java | 19 +++++++++++++++++++ .../api/edm/provider/CsdlSingleton.java | 6 ++++++ .../core/edm/AbstractEdmBindingTarget.java | 5 +++++ .../commons/core/edm/EdmEntitySetImpl.java | 1 + .../core/edm/EdmFunctionImportImpl.java | 5 +++++ .../edm/provider/EdmEntitySetImplTest.java | 2 ++ .../provider/EdmFunctionImportImplTest.java | 2 ++ .../edm/provider/EdmSingletonImplTest.java | 2 ++ .../json/ServiceDocumentJsonSerializer.java | 18 +++++++++++------- .../xml/ServiceDocumentXmlSerializer.java | 16 ++++++++++------ 15 files changed, 102 insertions(+), 13 deletions(-) diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java index 291e2e594..beff60d5c 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java @@ -215,6 +215,8 @@ public interface Constants { String VALUE = "value"; String JSON_URL = "url"; + + String JSON_TITLE = "title"; String JSON_COORDINATES = "coordinates"; diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmBindingTarget.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmBindingTarget.java index 4f4d1452d..e3fbc3728 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmBindingTarget.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmBindingTarget.java @@ -26,6 +26,12 @@ import java.util.List; */ public interface EdmBindingTarget extends EdmNamed, EdmAnnotatable { + /** + * Returns a human readable title or null if not set. + * @return a human readable title or null + */ + String getTitle(); + /** * Returns the target for a given path. * diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmFunctionImport.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmFunctionImport.java index 9fcf365bc..d0f82dbd2 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmFunctionImport.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmFunctionImport.java @@ -45,6 +45,12 @@ public interface EdmFunctionImport extends EdmOperationImport { */ FullQualifiedName getFunctionFqn(); + /** + * Returns a human readable title or null if not set. + * @return a human readable title or null + */ + String getTitle(); + /** * @return true if the function import must be included in the service document */ diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlBindingTarget.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlBindingTarget.java index 9043eb79e..67d8f5aeb 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlBindingTarget.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlBindingTarget.java @@ -34,6 +34,11 @@ public abstract class CsdlBindingTarget extends CsdlAbstractEdmItem implements C * The Name. */ protected String name; + + /** + * The human readable title. + */ + protected String title; /** * The Type. @@ -139,4 +144,18 @@ public abstract class CsdlBindingTarget extends CsdlAbstractEdmItem implements C this.annotations = annotations; return this; } + + public String getTitle() { + return title; + } + + /** + * A human readable title for this instance + * @param title + * @return this instance + */ + public CsdlBindingTarget setTitle(String title) { + this.title = title; + return this; + } } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlEntitySet.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlEntitySet.java index 12b59ce3e..a8d17b20a 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlEntitySet.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlEntitySet.java @@ -83,4 +83,10 @@ public class CsdlEntitySet extends CsdlBindingTarget { this.includeInServiceDocument = includeInServiceDocument; return this; } + + @Override + public CsdlEntitySet setTitle(String title) { + super.setTitle(title); + return this; + } } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlFunctionImport.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlFunctionImport.java index e293af18b..1b4e56de4 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlFunctionImport.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlFunctionImport.java @@ -34,6 +34,11 @@ public class CsdlFunctionImport extends CsdlOperationImport { // Default include in service document is false for function imports private boolean includeInServiceDocument; + /** + * Humanreadable title + */ + private String title; + @Override public String getName() { return name; @@ -116,4 +121,18 @@ public class CsdlFunctionImport extends CsdlOperationImport { this.annotations = annotations; return this; } + + public String getTitle() { + return title; + } + + /** + * A human readable title for this instance + * @param title + * @return this instance + */ + public CsdlFunctionImport setTitle(String title) { + this.title = title; + return this; + } } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlSingleton.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlSingleton.java index b05766f2e..091f61ddb 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlSingleton.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/CsdlSingleton.java @@ -59,4 +59,10 @@ public class CsdlSingleton extends CsdlBindingTarget { super.setAnnotations(annotations); return this; } + + @Override + public CsdlSingleton setTitle(String title) { + super.setTitle(title); + return this; + } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmBindingTarget.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmBindingTarget.java index 94956e2e2..90ac9f8ee 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmBindingTarget.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmBindingTarget.java @@ -119,4 +119,9 @@ public abstract class AbstractEdmBindingTarget extends AbstractEdmNamed implemen return bindingTarget; } + + @Override + public String getTitle() { + return target.getTitle(); + } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntitySetImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntitySetImpl.java index 0ba3ae169..a0bf7d3e5 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntitySetImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntitySetImpl.java @@ -36,4 +36,5 @@ public class EdmEntitySetImpl extends AbstractEdmBindingTarget implements EdmEnt public boolean isIncludeInServiceDocument() { return entitySet.isIncludeInServiceDocument(); } + } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmFunctionImportImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmFunctionImportImpl.java index 574c2f8f0..06e839b04 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmFunctionImportImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmFunctionImportImpl.java @@ -56,4 +56,9 @@ public class EdmFunctionImportImpl extends AbstractEdmOperationImport implements public boolean isIncludeInServiceDocument() { return functionImport.isIncludeInServiceDocument(); } + + @Override + public String getTitle() { + return functionImport.getTitle(); + } } diff --git a/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntitySetImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntitySetImplTest.java index cf02023b9..ddd4edef4 100644 --- a/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntitySetImplTest.java +++ b/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntitySetImplTest.java @@ -66,6 +66,7 @@ public class EdmEntitySetImplTest { final String entitySetName = "entitySet"; final CsdlEntitySet entitySetProvider = new CsdlEntitySet() .setName(entitySetName) + .setTitle("title") .setType(typeName) .setNavigationPropertyBindings(Arrays.asList( new CsdlNavigationPropertyBinding().setPath("path") @@ -75,6 +76,7 @@ public class EdmEntitySetImplTest { final EdmEntitySet entitySet = new EdmEntitySetImpl(edm, entityContainer, entitySetProvider); assertEquals(entitySetName, entityContainer.getEntitySet(entitySetName).getName()); assertEquals(entitySetName, entitySet.getName()); + assertEquals("title", entitySet.getTitle()); final EdmEntityType entityType = entitySet.getEntityType(); assertEquals(typeName.getNamespace(), entityType.getNamespace()); assertEquals(typeName.getName(), entityType.getName()); diff --git a/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImplTest.java index 526badfee..828405a1f 100644 --- a/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImplTest.java +++ b/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImplTest.java @@ -71,6 +71,7 @@ public class EdmFunctionImportImplTest { final String functionImportName = "functionImport"; final CsdlFunctionImport functionImportProvider = new CsdlFunctionImport() .setName(functionImportName) + .setTitle("title") .setFunction(functionName) .setIncludeInServiceDocument(true); when(provider.getFunctionImport(containerName, functionImportName)).thenReturn(functionImportProvider); @@ -78,6 +79,7 @@ public class EdmFunctionImportImplTest { final EdmFunctionImport functionImport = new EdmFunctionImportImpl(edm, entityContainer, functionImportProvider); assertEquals(functionImportName, entityContainer.getFunctionImport(functionImportName).getName()); assertEquals("functionImport", functionImport.getName()); + assertEquals("title", functionImport.getTitle()); assertEquals(new FullQualifiedName("ns", functionImportName), functionImport.getFullQualifiedName()); assertTrue(functionImport.isIncludeInServiceDocument()); final EdmFunction function = functionImport.getUnboundFunction(Collections. emptyList()); diff --git a/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSingletonImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSingletonImplTest.java index d1aeb20e7..673131ef5 100644 --- a/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSingletonImplTest.java +++ b/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSingletonImplTest.java @@ -64,6 +64,7 @@ public class EdmSingletonImplTest { final CsdlSingleton singletonProvider = new CsdlSingleton() .setName(singletonName) + .setTitle("title") .setType(typeName) .setNavigationPropertyBindings( Arrays.asList( @@ -74,6 +75,7 @@ public class EdmSingletonImplTest { final EdmSingleton singleton = new EdmSingletonImpl(edm, entityContainer, singletonProvider); assertEquals(singletonName, entityContainer.getSingleton(singletonName).getName()); assertEquals(singletonName, singleton.getName()); + assertEquals("title", singleton.getTitle()); final EdmEntityType entityType = singleton.getEntityType(); assertEquals(typeName.getNamespace(), entityType.getNamespace()); assertEquals(typeName.getName(), entityType.getName()); 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 2cae47636..a9793b94b 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 @@ -81,29 +81,33 @@ public class ServiceDocumentJsonSerializer { private void writeEntitySets(final JsonGenerator gen, final EdmEntityContainer container) throws IOException { for (EdmEntitySet edmEntitySet : container.getEntitySets()) { if (edmEntitySet.isIncludeInServiceDocument()) { - writeElement(gen, null, edmEntitySet.getName(), edmEntitySet.getName()); + writeElement(gen, null, edmEntitySet.getName(), edmEntitySet.getName(), edmEntitySet.getName()); } } } private void writeFunctionImports(final JsonGenerator gen, final EdmEntityContainer container) throws IOException { - for (EdmFunctionImport edmFunctionImport : container.getFunctionImports()) { - if (edmFunctionImport.isIncludeInServiceDocument()) { - writeElement(gen, FUNCTION_IMPORT, edmFunctionImport.getName(), edmFunctionImport.getName()); + for (EdmFunctionImport edmFI : container.getFunctionImports()) { + if (edmFI.isIncludeInServiceDocument()) { + writeElement(gen, FUNCTION_IMPORT, edmFI.getName(), edmFI.getName(), edmFI.getTitle()); } } } private void writeSingletons(final JsonGenerator gen, final EdmEntityContainer container) throws IOException { for (EdmSingleton edmSingleton : container.getSingletons()) { - writeElement(gen, SINGLETON, edmSingleton.getName(), edmSingleton.getName()); + writeElement(gen, SINGLETON, edmSingleton.getName(), edmSingleton.getName(), edmSingleton.getTitle()); } } - private void writeElement(JsonGenerator gen, final String kind, final String reference, final String title) + private void writeElement(JsonGenerator gen, final String kind, final String reference, final String name, + final String title) throws IOException { gen.writeStartObject(); - gen.writeObjectField(Constants.JSON_NAME, title); + gen.writeObjectField(Constants.JSON_NAME, name); + if (title != null) { + gen.writeObjectField(Constants.JSON_TITLE, title); + } gen.writeObjectField(Constants.JSON_URL, reference); if (kind != null) { gen.writeObjectField(KIND, kind); 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 6d130bae8..a5490e618 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 @@ -97,7 +97,7 @@ public class ServiceDocumentXmlSerializer { throws XMLStreamException { for (EdmEntitySet edmEntitySet : container.getEntitySets()) { if (edmEntitySet.isIncludeInServiceDocument()) { - writeElement(writer, true, "collection", edmEntitySet.getName(), edmEntitySet.getName()); + writeElement(writer, true, "collection", edmEntitySet.getName(), edmEntitySet.getTitle()); } } } @@ -106,7 +106,7 @@ public class ServiceDocumentXmlSerializer { throws XMLStreamException { for (EdmFunctionImport edmFunctionImport : container.getFunctionImports()) { if (edmFunctionImport.isIncludeInServiceDocument()) { - writeElement(writer, false, "function-import", edmFunctionImport.getName(), edmFunctionImport.getName()); + writeElement(writer, false, "function-import", edmFunctionImport.getName(), edmFunctionImport.getTitle()); } } } @@ -114,20 +114,24 @@ public class ServiceDocumentXmlSerializer { private void writeSingletons(final XMLStreamWriter writer, final EdmEntityContainer container) throws XMLStreamException { for (EdmSingleton edmSingleton : container.getSingletons()) { - writeElement(writer, false, "singleton", edmSingleton.getName(), edmSingleton.getName()); + writeElement(writer, false, "singleton", edmSingleton.getName(), edmSingleton.getTitle()); } } - private void writeElement(XMLStreamWriter writer, final boolean isApp, final String kind, final String reference, + private void writeElement(XMLStreamWriter writer, final boolean isApp, final String kind, final String name, final String title) throws XMLStreamException { if (isApp) { writer.writeStartElement(APP, kind, NS_APP); } else { writer.writeStartElement(METADATA, kind, NS_METADATA); } - writer.writeAttribute(Constants.ATTR_HREF, reference); + writer.writeAttribute(Constants.ATTR_HREF, name); writer.writeStartElement(ATOM, Constants.ATOM_ELEM_TITLE, NS_ATOM); - writer.writeCharacters(title); + if (title != null) { + writer.writeCharacters(title); + } else { + writer.writeCharacters(name); + } writer.writeEndElement(); writer.writeEndElement(); }