All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.cds.adapter.odata.v4.ODataV4IndexContentProvider Maven / Gradle / Ivy

There is a newer version: 3.6.0
Show newest version
/**************************************************************************
 * (C) 2019-2024 SAP SE or an SAP affiliate company. All rights reserved. *
 **************************************************************************/
package com.sap.cds.adapter.odata.v4;

import java.io.PrintWriter;
import java.util.stream.Stream;

import com.sap.cds.adapter.IndexContentProvider;
import com.sap.cds.reflect.CdsDefinition;
import com.sap.cds.reflect.CdsEntity;
import com.sap.cds.reflect.CdsService;
import com.sap.cds.services.runtime.CdsRuntime;
import com.sap.cds.services.utils.DraftUtils;
import com.sap.cds.services.utils.ODataUtils;
import com.sap.cds.services.utils.model.CdsAnnotations;
import com.sap.cds.services.utils.path.CdsResourcePath;
import com.sap.cds.services.utils.path.CdsServicePath;

public class ODataV4IndexContentProvider implements IndexContentProvider {

	private static final String SERVICE = "" +
			"                

\n" + " %s\n" + " / $metadata\n" + "

\n"; private static final String ENTITY_START = "" + "
    \n"; private static final String ENTITY = "" + "
  • \n" + " %s\n" + "
  • \n"; private static final String ENTITY_END = "" + "
\n"; private final CdsRuntime runtime; public ODataV4IndexContentProvider(CdsRuntime runtime) { this.runtime = runtime; } @Override public String getSectionTitle() { return "OData V4 endpoints"; } @Override public void writeContent(PrintWriter out, String contextPath) { Stream cdsServicePaths = CdsServicePath.servicePaths(runtime, CdsODataV4ServletFactory.PROTOCOL_KEY); CdsODataV4ServletFactory servletFactory = new CdsODataV4ServletFactory(); servletFactory.setCdsRuntime(runtime); String basePath = servletFactory.getBasePath(); String theBasePath = contextPath + (basePath.equals("/") ? "" : basePath); cdsServicePaths.filter(p -> p.getCdsDefinition() instanceof CdsService).forEach(s -> { String path = theBasePath + "/" + s.getPath(); out.format(SERVICE, path, path, path); out.write(ENTITY_START); s.subPaths().filter(e -> isExposedEntity(e.getCdsDefinition())).forEach(e -> { String entityPath = path + "/" + ODataUtils.toODataName(e.getPath()); out.format(ENTITY, entityPath, e.getPath()); }); out.write(ENTITY_END); }); } private boolean isExposedEntity(CdsDefinition definition) { if(definition instanceof CdsEntity) { boolean autoexposed = CdsAnnotations.AUTOEXPOSED.isTrue(definition); boolean autoexpose = CdsAnnotations.AUTOEXPOSE.isTrue(definition); String name = definition.getName(); return !(name.endsWith("_drafts") || name.endsWith("_texts") || name.endsWith(".texts") || name.endsWith("DraftAdministrativeData") || (!DraftUtils.isDraftEnabled((CdsEntity) definition) && autoexposed && !autoexpose)); } return false; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy