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

com.sap.cds.reflect.impl.CdsBoundOperationReader Maven / Gradle / Ivy

There is a newer version: 3.8.0
Show newest version
/*********************************************************************
 * (C) 2023 SAP SE or an SAP affiliate company. All rights reserved. *
 *********************************************************************/
package com.sap.cds.reflect.impl;

import static com.sap.cds.util.CdsModelUtils.getDoc;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.databind.JsonNode;
import com.sap.cds.reflect.CdsAction;
import com.sap.cds.reflect.CdsFunction;
import com.sap.cds.reflect.impl.reader.model.CdsConstants;

public class CdsBoundOperationReader {

	private final List> actionList = new ArrayList<>();
	private final List> functionList = new ArrayList<>();

	private final CdsModelReader.Config config;

	public CdsBoundOperationReader(CdsModelReader.Config config, JsonNode csn) {
		this.config = config;
		if (csn.has(CdsConstants.ACTIONS)) {
			JsonNode jsonNode = csn.get(CdsConstants.ACTIONS);
			jsonNode.fields().forEachRemaining(this::addToList);
		}
	}

	private void addToList(Map.Entry defEntry) {
		String defName = defEntry.getKey();
		JsonNode defCsn = defEntry.getValue();
		JsonNode kind = defCsn.get(CdsConstants.KIND);
		if (kind != null) {
			if (kind.asText().equals(CdsConstants.ACTION)) {
				CdsOperationBuilder action = new CdsActionBuilder(true,
				  CdsAnnotationReader.read(config, defCsn), defName, defName, config.readDocs() ? getDoc(defCsn) : null);
				actionList.add(action);
			}
			if (kind.asText().equals(CdsConstants.FUNCTION)) {
				CdsOperationBuilder function = new CdsFunctionBuilder(true,
				  CdsAnnotationReader.read(config, defCsn), defName, defName, config.readDocs() ? getDoc(defCsn) : null);
				functionList.add(function);
			}
		}
	}

	public List> getActions() {
		return actionList;
	}

	public List> getFunctions() {
		return functionList;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy