com.sap.cds.adapter.odata.v4.serializer.json.EntityCollection2JsonBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cds-adapter-odata-v4 Show documentation
Show all versions of cds-adapter-odata-v4 Show documentation
OData V4 adapter for CDS Services Java
/**************************************************************************
* (C) 2019-2024 SAP SE or an SAP affiliate company. All rights reserved. *
**************************************************************************/
package com.sap.cds.adapter.odata.v4.serializer.json;
import java.net.URI;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.format.ContentType;
import com.sap.cds.adapter.odata.v4.serializer.json.options.Struct2JsonOptions;
import com.sap.cds.adapter.odata.v4.serializer.json.options.StructCollection2JsonOptions;
public class EntityCollection2JsonBuilder extends StructCollection2JsonBuilder {
public static EntityCollection2Json createRoot(
StructCollection2JsonOptions opts,
EdmStructuredType entityType,
ContentType contentType,
URI nextLinkUri,
long inlineCount) { // the overall count of the request, NOT the rowCount
return create(opts, entityType, contentType, nextLinkUri, inlineCount, null);
}
public static EntityCollection2Json createExpanded(
StructCollection2JsonOptions opts,
EdmStructuredType entityType,
ContentType contentType,
String navigationPropertyName) {
return create(opts, entityType, contentType, null, null, navigationPropertyName);
}
private static EntityCollection2Json create(
StructCollection2JsonOptions options,
EdmStructuredType entityType,
ContentType contentType,
URI nextLinkUri,
Long inlineCount,
String navigationPropertyName) {
EntityCollection2Json collection2Json = new EntityCollection2Json();
collection2Json.navigationPropertyName = navigationPropertyName;
collection2Json.writeOnlyReferences = options.getWriteOnlyReferences();
Struct2JsonOptions entityOptions = Struct2JsonOptions
.with(contentType, options.getODataVersion(), options.getGlobals())
.contextURL(options.getContextURL())
.expand(options.getExpand())
.select(options.getSelect())
.writeOnlyReferences(options.getWriteOnlyReferences())
.autoExpand(options.isAutoExpand())
.build();
collection2Json.entity2Json = Entity2JsonBuilder.createNested(entityOptions, entityType, contentType);
addCountAndNextLink(collection2Json, options, nextLinkUri, navigationPropertyName, inlineCount);
return collection2Json;
}
}