Class CdsModelUtils

java.lang.Object
com.sap.cds.services.impl.utils.CdsModelUtils

public class CdsModelUtils extends Object
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Functional interface for entity data visitors.
    static interface 
    Functional interface for entity data visitors.
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.sap.cds.reflect.impl.CdsModelReader.Config
    Builds the CdsModelReader.Config based on the properties available in the CdsRuntime
    static boolean
    eventIsGranted(String event, String grant)
     
    static Optional<com.sap.cds.reflect.CdsAction>
    getAction(com.sap.cds.reflect.CdsModel model, String entityName, String actionName)
    Tries to resolve the CDS action with the given full-qualified name in the given CDS model.
    static List<com.sap.cds.reflect.CdsElement>
    getAssociationKeys(com.sap.cds.reflect.CdsElement element)
    Returns the elements of the association target, that represent the keys of this association.
    static com.sap.cds.reflect.CdsEntity
    getEntityOrThrow(com.sap.cds.reflect.CdsModel model, String entityName)
    Tries to resolve the CDS entity with the given full-qualified name in the given CDS model.
    static com.sap.cds.ql.cqn.AnalysisResult
    getEntityPath(com.sap.cds.ql.cqn.CqnStatement statement, com.sap.cds.reflect.CdsModel model)
     
    static com.sap.cds.ql.cqn.AnalysisResult
    getEntityPath(com.sap.cds.ql.cqn.CqnStructuredTypeRef ref, com.sap.cds.reflect.CdsModel model)
     
    static Optional<com.sap.cds.reflect.CdsFunction>
    getFunction(com.sap.cds.reflect.CdsModel model, String entityName, String functionName)
    Tries to resolve the CDS function with the given full-qualified name in the given CDS model.
    static String
    getNameOrEmpty(com.sap.cds.reflect.CdsEntity entity)
    Returns the qualified name of the entity or an empty string, if no entity is provided
    static com.sap.cds.reflect.CdsService
    getServiceOrThrow(com.sap.cds.reflect.CdsModel model, String serviceName)
    Tries to resolve the service with the given full-qualified name in the given CDS model.
    static com.sap.cds.reflect.CdsEntity
    getTargetEntity(com.sap.cds.ql.cqn.CqnStatement statement, com.sap.cds.reflect.CdsModel model)
     
    static boolean
     
    static boolean
    isInternalOperationType(com.sap.cds.reflect.CdsDefinition type)
     
    static boolean
     
    static boolean
     
    static com.sap.cds.reflect.CdsModel
    loadCdsModel(com.sap.cds.reflect.impl.CdsModelReader.Config config, String resourcePathToCSN)
    Loads the CDS model from current classloader's resource at the given location.
    static com.sap.cds.reflect.CdsModel
    loadCdsModel(String resourcePathToCSN)
    Loads the CDS model from current classloader's resource at the given location.
    static void
    visitDeep(com.sap.cds.reflect.CdsEntity entity, List<? extends Map<String,Object>> data, CdsModelUtils.EntityDataVisitor visitor)
    Traverses the given entity data together with the entity metadata.
    static void
    visitDeep(com.sap.cds.reflect.CdsEntity entity, Map<String,Object> data, CdsModelUtils.EntitySingleDataVisitor visitor)
    Traverses the given entity data together with the entity metadata.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • loadCdsModel

      public static com.sap.cds.reflect.CdsModel loadCdsModel(String resourcePathToCSN)
      Loads the CDS model from current classloader's resource at the given location.
      Parameters:
      resourcePathToCSN - The resource path of the CDS model file within the current classloader
      Returns:
      The loaded model
    • buildCdsModelReaderConfig

      public static com.sap.cds.reflect.impl.CdsModelReader.Config buildCdsModelReaderConfig(CdsRuntime runtime)
      Builds the CdsModelReader.Config based on the properties available in the CdsRuntime
      Parameters:
      runtime - the CdsRuntime
      Returns:
      the CdsModelReader.Config
    • loadCdsModel

      public static com.sap.cds.reflect.CdsModel loadCdsModel(com.sap.cds.reflect.impl.CdsModelReader.Config config, String resourcePathToCSN)
      Loads the CDS model from current classloader's resource at the given location.
      Parameters:
      config - The CDS model reader config
      resourcePathToCSN - The resource path of the CDS model file within the current classloader
      Returns:
      The loaded model
    • getNameOrEmpty

      public static String getNameOrEmpty(com.sap.cds.reflect.CdsEntity entity)
      Returns the qualified name of the entity or an empty string, if no entity is provided
      Parameters:
      entity - the entity
      Returns:
      the qualified name of the entity or an empty string
    • getEntityOrThrow

      public static com.sap.cds.reflect.CdsEntity getEntityOrThrow(com.sap.cds.reflect.CdsModel model, String entityName)
      Tries to resolve the CDS entity with the given full-qualified name in the given CDS model.
      Parameters:
      entityName - The name of the CDS entity to be resolved
      model - The model to search
      Returns:
      The CdsEntity object representing the entity in the CDS model
      Throws:
      ServiceException - In case the name can't be resolved (error code 404)
    • getServiceOrThrow

      public static com.sap.cds.reflect.CdsService getServiceOrThrow(com.sap.cds.reflect.CdsModel model, String serviceName)
      Tries to resolve the service with the given full-qualified name in the given CDS model.
      Parameters:
      serviceName - The name of the service to be resolved
      model - The model to search
      Returns:
      The CdsService object representing the service in the CDS model
      Throws:
      ServiceException - In case the name can't be resolved (error code 404)
    • getAction

      public static Optional<com.sap.cds.reflect.CdsAction> getAction(com.sap.cds.reflect.CdsModel model, String entityName, String actionName)
      Tries to resolve the CDS action with the given full-qualified name in the given CDS model.
      Parameters:
      actionName - The name of the CDS action to be resolved
      model - The model to search
      entityName - The entity name
      Returns:
      The CdsAction object representing the entity in the CDS model
      Throws:
      ServiceException - In case the name can't be resolved (error code 404)
    • getFunction

      public static Optional<com.sap.cds.reflect.CdsFunction> getFunction(com.sap.cds.reflect.CdsModel model, String entityName, String functionName)
      Tries to resolve the CDS function with the given full-qualified name in the given CDS model.
      Parameters:
      functionName - The name of the CDS function to be resolved
      model - The model to search
      entityName - The entity name
      Returns:
      The CdsFunction object representing the function in the CDS model
      Throws:
      ServiceException - In case the name can't be resolved (error code 404)
    • getAssociationKeys

      public static List<com.sap.cds.reflect.CdsElement> getAssociationKeys(com.sap.cds.reflect.CdsElement element)
      Returns the elements of the association target, that represent the keys of this association. This can be either the keys of the association target (in case of managed associations). In cases of unmanaged associations these are the elements of the association target, mentioned in the ON condition of the association. The elements returned by this method can be assumed to be auto-filled in by CDS4J as they can be inferred from the association parent.
      Parameters:
      element - the association element to analyze
      Returns:
      the keys of the association, or an empty list of the element is null or not an association
    • visitDeep

      public static void visitDeep(com.sap.cds.reflect.CdsEntity entity, List<? extends Map<String,Object>> data, CdsModelUtils.EntityDataVisitor visitor)
      Traverses the given entity data together with the entity metadata. The CdsModelUtils.EntityDataVisitor is called for the given data and entity and then for each association with the respective entity data of the association. This happens recursively until either no further associations can be found, or no more nested data is available
      Parameters:
      entity - the root entity
      data - the list of entity data sets for the root entity
      visitor - the visitor to use to visit the data together with the entity metadata
    • visitDeep

      public static void visitDeep(com.sap.cds.reflect.CdsEntity entity, Map<String,Object> data, CdsModelUtils.EntitySingleDataVisitor visitor)
      Traverses the given entity data together with the entity metadata. The CdsModelUtils.EntitySingleDataVisitor is called for the given data and entity and then for each association with the respective entity data of the association. For "to many" associations, the visitor is called for each element. This happens recursively until either no further associations can be found, or no more nested data is available
      Parameters:
      entity - the root entity
      data - the of the root entity
      visitor - the visitor to use to visit the data together with the entity metadata
    • getEntityPath

      public static com.sap.cds.ql.cqn.AnalysisResult getEntityPath(com.sap.cds.ql.cqn.CqnStatement statement, com.sap.cds.reflect.CdsModel model)
    • getTargetEntity

      public static com.sap.cds.reflect.CdsEntity getTargetEntity(com.sap.cds.ql.cqn.CqnStatement statement, com.sap.cds.reflect.CdsModel model)
    • getEntityPath

      public static com.sap.cds.ql.cqn.AnalysisResult getEntityPath(com.sap.cds.ql.cqn.CqnStructuredTypeRef ref, com.sap.cds.reflect.CdsModel model)
    • isStandardCdsEvent

      public static boolean isStandardCdsEvent(String event)
    • isWriteEvent

      public static boolean isWriteEvent(String event)
    • isDraftEvent

      public static boolean isDraftEvent(String event)
    • eventIsGranted

      public static boolean eventIsGranted(String event, String grant)
    • isInternalOperationType

      public static boolean isInternalOperationType(com.sap.cds.reflect.CdsDefinition type)