[OLINGO-587] Enable title for service document
This commit is contained in:
parent
837c3565a1
commit
26c6764846
|
@ -215,6 +215,8 @@ public interface Constants {
|
|||
String VALUE = "value";
|
||||
|
||||
String JSON_URL = "url";
|
||||
|
||||
String JSON_TITLE = "title";
|
||||
|
||||
String JSON_COORDINATES = "coordinates";
|
||||
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,4 +119,9 @@ public abstract class AbstractEdmBindingTarget extends AbstractEdmNamed implemen
|
|||
|
||||
return bindingTarget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return target.getTitle();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,4 +36,5 @@ public class EdmEntitySetImpl extends AbstractEdmBindingTarget implements EdmEnt
|
|||
public boolean isIncludeInServiceDocument() {
|
||||
return entitySet.isIncludeInServiceDocument();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -56,4 +56,9 @@ public class EdmFunctionImportImpl extends AbstractEdmOperationImport implements
|
|||
public boolean isIncludeInServiceDocument() {
|
||||
return functionImport.isIncludeInServiceDocument();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return functionImport.getTitle();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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.<String> emptyList());
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue