public class CdsModelUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
CdsModelUtils.EntityDataVisitor
Functional interface for entity data visitors.
|
static interface |
CdsModelUtils.EntitySingleDataVisitor
Functional interface for entity data visitors.
|
| Modifier and Type | Method and Description |
|---|---|
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 |
getAssociationTarget(String field,
com.sap.cds.reflect.CdsEntity entity)
Returns the target of an 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 |
isAssociationToParent(String field,
com.sap.cds.reflect.CdsEntity entity) |
static boolean |
isAssociationToParentOrChild(String field,
com.sap.cds.reflect.CdsEntity entity)
Checks if the field is a composition or an association to a parent entity
|
static boolean |
isComposition(String field,
com.sap.cds.reflect.CdsEntity entity) |
static boolean |
isStandardCdsEvent(String event) |
static boolean |
isWriteEvent(String event) |
static com.sap.cds.reflect.CdsModel |
loadCdsModel(String resourcePathToCSN)
Loads the CDS model from current classloader's resource at the given location.
|
static Map<com.sap.cds.reflect.CdsElement,com.sap.cds.reflect.CdsElement> |
reduceAssociationElements(com.sap.cds.reflect.CdsStructuredType struct)
Reduces the elements of the entity, to map elements associations with their corresponding key element.
|
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.
|
public static com.sap.cds.reflect.CdsModel loadCdsModel(String resourcePathToCSN)
resourcePathToCSN - The resource path of the CDS model file within the
current classloaderpublic static String getNameOrEmpty(com.sap.cds.reflect.CdsEntity entity)
entity - the entitypublic static com.sap.cds.reflect.CdsEntity getEntityOrThrow(com.sap.cds.reflect.CdsModel model,
String entityName)
entityName - The name of the CDS entity to be resolvedmodel - The model to searchCdsEntity object representing the entity in the CDS modelServiceException - In case the name can't be resolved (error code 404)public static com.sap.cds.reflect.CdsService getServiceOrThrow(com.sap.cds.reflect.CdsModel model,
String serviceName)
serviceName - The name of the service to be resolvedmodel - The model to searchCdsService object representing the service in the CDS modelServiceException - In case the name can't be resolved (error code 404)public static Optional<com.sap.cds.reflect.CdsAction> getAction(com.sap.cds.reflect.CdsModel model, String entityName, String actionName)
actionName - The name of the CDS action to be resolvedmodel - The model to searchentityName - The entity nameCdsAction object representing the entity in the CDS modelServiceException - In case the name can't be resolved (error code 404)public static Optional<com.sap.cds.reflect.CdsFunction> getFunction(com.sap.cds.reflect.CdsModel model, String entityName, String functionName)
functionName - The name of the CDS function to be resolvedmodel - The model to searchentityName - The entity nameCdsFunction object representing the function in the CDS modelServiceException - In case the name can't be resolved (error code 404)public static Map<com.sap.cds.reflect.CdsElement,com.sap.cds.reflect.CdsElement> reduceAssociationElements(com.sap.cds.reflect.CdsStructuredType struct)
struct - the structured type to reduce the association elements fornullpublic static List<com.sap.cds.reflect.CdsElement> getAssociationKeys(com.sap.cds.reflect.CdsElement element)
element - the association element to analyzenull or not an associationpublic static boolean isAssociationToParentOrChild(String field, com.sap.cds.reflect.CdsEntity entity)
field - the field nameentity - the entitytrue if the field is a composition or an association to a parent entitypublic static boolean isAssociationToParent(String field, com.sap.cds.reflect.CdsEntity entity)
public static boolean isComposition(String field, com.sap.cds.reflect.CdsEntity entity)
public static com.sap.cds.reflect.CdsEntity getAssociationTarget(String field, com.sap.cds.reflect.CdsEntity entity)
field - the field nameentity - the entitynull if the field is no association or does not existpublic static void visitDeep(com.sap.cds.reflect.CdsEntity entity,
List<? extends Map<String,Object>> data,
CdsModelUtils.EntityDataVisitor visitor)
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 availableentity - 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 metadatapublic static void visitDeep(com.sap.cds.reflect.CdsEntity entity,
Map<String,Object> data,
CdsModelUtils.EntitySingleDataVisitor visitor)
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 availableentity - the root entitydata - the of the root entityvisitor - the visitor to use to visit the data together with the entity metadatapublic static com.sap.cds.ql.cqn.AnalysisResult getEntityPath(com.sap.cds.ql.cqn.CqnStatement statement,
com.sap.cds.reflect.CdsModel model)
public static com.sap.cds.reflect.CdsEntity getTargetEntity(com.sap.cds.ql.cqn.CqnStatement statement,
com.sap.cds.reflect.CdsModel model)
public static com.sap.cds.ql.cqn.AnalysisResult getEntityPath(com.sap.cds.ql.cqn.CqnStructuredTypeRef ref,
com.sap.cds.reflect.CdsModel model)
public static boolean isStandardCdsEvent(String event)
public static boolean isWriteEvent(String event)
Copyright © 2021. All rights reserved.