Package com.sap.cds.services.impl.utils
Class CdsModelUtils
java.lang.Object
com.sap.cds.services.impl.utils.CdsModelUtils
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Functional interface for entity data visitors.static interface
Functional interface for entity data visitors. -
Method Summary
Modifier and TypeMethodDescriptionstatic com.sap.cds.reflect.impl.CdsModelReader.Config
buildCdsModelReaderConfig
(CdsRuntime runtime) Builds theCdsModelReader.Config
based on the properties available in theCdsRuntime
static boolean
eventIsGranted
(String event, String grant) static Optional<com.sap.cds.reflect.CdsAction>
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 providedstatic 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
isDraftEvent
(String event) static boolean
isInternalOperationType
(com.sap.cds.reflect.CdsDefinition type) static boolean
isStandardCdsEvent
(String event) static boolean
isWriteEvent
(String event) 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.
-
Method Details
-
loadCdsModel
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 theCdsModelReader.Config
based on the properties available in theCdsRuntime
- Parameters:
runtime
- theCdsRuntime
- 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 configresourcePathToCSN
- The resource path of the CDS model file within the current classloader- Returns:
- The loaded model
-
getNameOrEmpty
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 resolvedmodel
- 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 resolvedmodel
- 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 resolvedmodel
- The model to searchentityName
- 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 resolvedmodel
- The model to searchentityName
- 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. TheCdsModelUtils.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 entitydata
- the list of entity data sets for the root entityvisitor
- 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. TheCdsModelUtils.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, thevisitor
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 entitydata
- the of the root entityvisitor
- 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
-
isWriteEvent
-
isDraftEvent
-
eventIsGranted
-
isInternalOperationType
public static boolean isInternalOperationType(com.sap.cds.reflect.CdsDefinition type)
-