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

com.sap.cds.adapter.odata.v4.query.apply.ApplyHandler Maven / Gradle / Ivy

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

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

import org.apache.olingo.server.api.uri.queryoption.ApplyItem;
import org.apache.olingo.server.api.uri.queryoption.ApplyOption;

import com.sap.cds.adapter.odata.v4.query.ExpressionParser;
import com.sap.cds.ql.Select;
import com.sap.cds.ql.cqn.transformation.CqnTransformation;
import com.sap.cds.ql.impl.SelectBuilder;

public class ApplyHandler {

	private final List> unfoldedItems;
	private static final ApplyHandler NOOP = new ApplyHandler(List.of(), null);

	public ApplyHandler(List items, ExpressionParser expressionParser) {
		unfoldedItems = new ApplyConverter(expressionParser).unfoldAndConvert(items);
	}

	public List getTransformations(int i) {
		return unfoldedItems.get(i);
	}

	public List> transform(Select select) {
		List> selects = new ArrayList<>(unfoldedItems.size());
		for (List transformations : unfoldedItems) {
			SelectBuilder copy = SelectBuilder.copy(select);
			copy.transformations(transformations);
			selects.add(copy);
		}
		return selects;
	}

	public boolean hasConcat() {
		return unfoldedItems.size() > 1;
	}

	public static ApplyHandler create(ApplyOption applyOption, ExpressionParser expressionParser) {
		if (applyOption == null) {
			return NOOP;
		}

		return new ApplyHandler(applyOption.getApplyItems(), expressionParser);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy