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

com.sap.ipe.ble.irp.handler.services.DeepSelectionService Maven / Gradle / Ivy

There is a newer version: 1.0.3
Show newest version
package com.sap.ipe.ble.irp.handler.services;

import com.sap.cds.ql.CQL;
import com.sap.cds.ql.Predicate;
import com.sap.cds.ql.Select;
import com.sap.cds.ql.Selectable;
import com.sap.cds.ql.cqn.CqnSelect;
import com.sap.cds.reflect.CdsEntity;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/***
 * DeepSelectionService is used to select the composition data
 * Based on the annotation deepSelect is set to true or false
 */
@Service
public class DeepSelectionService{

    /***
     * This method is used to select the composition data
     * @param contextParameters parameters needed for selection of data
     * @param entity entity from which data needs to be selected
     * @return query from which the data needs to be fetched
     */
    public CqnSelect getDeepSelectData(Map contextParameters, CdsEntity entity) {
        CqnSelect query;
        List items = new ArrayList<>();

        items.add(CQL.star());
        items.addAll(entity.compositions().map(c -> CQL.to(c.getName()).expand()).collect(Collectors.toList()));
        Select select = Select.from(entity).columns(items);
        query = select.where(b -> {
            Predicate predicate = null;
            Stream keySet = contextParameters.keySet().stream();
            for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
                String parameterName = iterator.next();
                Predicate data = b.get(parameterName).eq(contextParameters.get(parameterName));
                predicate = predicate == null ? data : predicate.and(data);
            }
            return predicate;
        });
        return query;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy