com.sap.cds.adapter.odata.v4.serializer.json.Apply2JsonBuilder 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.IConstants;
import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.core.serializer.utils.ContextURLBuilder;
import com.sap.cds.adapter.odata.v4.serializer.json.options.Apply2JsonOptions;
import com.sap.cds.adapter.odata.v4.serializer.json.primitive.Number2Json;
import com.sap.cds.adapter.odata.v4.serializer.json.primitive.String2Json;
public class Apply2JsonBuilder {
public static Apply2Json create(Apply2JsonOptions options, URI nextLinkUri, long inlineCount) {
Apply2Json apply2Json = new Apply2Json();
addAnnotations(options, nextLinkUri, inlineCount, apply2Json);
return apply2Json;
}
private static void addAnnotations(Apply2JsonOptions options, URI nextLinkUri, long inlineCount,
Apply2Json apply2Json) {
IConstants constants = options.getConstants();
ServiceMetadata metadata = options.getGlobals().getServiceMetadata();
if (options.getCount() != null && options.getCount().getValue()) {
if (inlineCount > -1) {
apply2Json.count = Number2Json.constant(options.getConstants().getCount(), inlineCount);
}
}
if (!options.isODataMetadataNone()) {
if (options.getContextURL() != null) {
apply2Json.context = String2Json.constant(constants.getContext(),
ContextURLBuilder.create(options.getContextURL()).toASCIIString());
if (metadata.getServiceMetadataETagSupport() != null
&& metadata.getServiceMetadataETagSupport().getMetadataETag() != null) {
apply2Json.metadataEtag = String2Json.constant(constants.getMetadataEtag(),
metadata.getServiceMetadataETagSupport().getMetadataETag());
}
}
}
if (nextLinkUri != null) {
apply2Json.nextLink = String2Json.constant(constants.getNextLink(), nextLinkUri.toASCIIString());
}
}
}