data.metadata.metadata_parser
MetadataParserQuery Objects
@dataclass
class MetadataParserQuery()
MetadataParserQuery is a data class that represents a query for metadata parsing.
Attributes:
idstr - The identifier for the metadata query.valuestr - The value associated with the metadata query.
MetadataParser Objects
class MetadataParser()
MetadataParser class provides static methods to filter and retrieve metadata based on profiles and queries.
Methods:
filter_by_profile(profile_name- str | List, metadata: MetadataSet) -> List[Dict[str, Any]]: Filters the metadata entries by the given profile name(s).getattr(metadata- MetadataSet, query: MetadataParserQuery) -> List[Dict[str, Any]]: Retrieves the value from metadata entries based on the given query.getobj(metadata- MetadataSet, id: str): Retrieves the metadata entry with the specified id.
list_values
@staticmethod
def list_values(
profile: PropertyProfile,
metadata: MetadataSet,
shared_objects: SharedPropertyObjectsSet | None = None
) -> MetadataValueList
Retrieves all (filled out) values from a profile in an easy-to-process format.
validate_profile
@staticmethod
def validate_profile(profile: PropertyProfile) -> bool
Validates the given profile dictionary to ensure it contains the required metadata and layout information.
Arguments:
profilePropertyProfile - The profile dictionary to validate. It should contain 'metadata' and optionally 'layout' and 'classes'.
Returns:
bool- True if the profile is valid, False otherwise.
Raises:
ValueError- If the profile is missing required metadata keys or if the layout references missing classes. The profile dictionary should have the following structure:
{
'metadata': {
'id': str,
'displayLabel': str,
'description': str,
...
},
'layout': [
{
'type': str,
...
},
...
],
'classes': {
...
}
}
filter_by_profile
@staticmethod
def filter_by_profile(profile_name: str | List,
metadata: MetadataSet) -> List[PropertyObject]
Filters the metadata by the given profile name(s).
Arguments:
profile_namestr | List - A single profile name or a list of profile names to filter by.metadataList[Dict[str, Any]] - A list of metadata dictionaries, each containing a "profiles" key.
Returns:
List[Dict[str, Any]]: A list of metadata dictionaries that match the given profile name(s).
getattr
@staticmethod
def getattr(metadata: MetadataSet, query: MetadataParserQuery) -> Any
Retrieve a list of dictionaries from metadata based on a query.
Arguments:
metadataList[Dict[str, Any]] - A list of dictionaries containing metadata.queryMetadataParserQuery - An object containing the query parameters with 'id' and 'value' attributes.
Returns:
List[Dict[str, Any]]: A list of dictionaries that match the query criteria, or None if no match is found.
getobj
@staticmethod
def getobj(metadata: MetadataSet, oid: str) -> PropertyObject | None
Retrieve an object from a list of metadata dictionaries by its ID.
Arguments:
metadataList[Dict[str, Any]] - A list of dictionaries containing metadata.oidstr - The ID of the object to retrieve.
Returns:
Dict[str, Any]: The dictionary object with the specified ID.
get_profile_layout
@staticmethod
def get_profile_layout(profile: PropertyProfile) -> ProfileLayout
Extracts the layout information from the given profile metadata.
Arguments:
profile_metadataPropertyProfile - A list of dictionaries containing profile metadata.
Returns:
ProfileLayout- A list of dictionaries representing the layout information.
is_property_filled_out
@staticmethod
def is_property_filled_out(metadata: MetadataSet,
prop_id: str,
shared_objects: SharedPropertyObjectsSet
| None = None,
profile: PropertyProfile | None = None)
Checks if a property is filled out.
Arguments:
metadatadict - The metadata dictionary containing various objects.prop_idstr - The property ID to look up in the metadata.shared_objectslist, optional - A list of shared objects that may be referenced in the metadata. Defaults to an empty list.profiledict, optional - A dictionary containing profile information, including class layouts and templates. Defaults to an empty dictionary.
validate_metadata
@staticmethod
def validate_metadata(
profile: PropertyProfile,
metadata: MetadataSet,
shared_objects: SharedPropertyObjectsSet | None = None) -> None
Validates all property values of a filled-out profile.
Arguments:
profile- The profile.metadata- The profile metadata values.shared_objects- List of shared objects.
is_property_valid
@staticmethod
def is_property_valid(
metadata: MetadataSet,
profile: PropertyProfile,
prop_id: str,
shared_objects: SharedPropertyObjectsSet | None = None) -> bool
Checks if a specific property in the metadata is valid according to the given profile.
Arguments:
metadatadict - The metadata dictionary containing various properties.profiledict - The profile dictionary that defines the layout and requirements for properties.prop_idstr - The identifier of the property to check.
Returns:
bool- True if the property is filled out according to the profile, False otherwise.
Raises:
MetadataPropertyMissingError- If the property is missing in the metadata or not defined in the profile.
Notes:
- The function first checks if the property exists in the metadata.
- It then verifies if the property is defined in the profile layout.
- If the property has required input values, it checks if those values are present and non-empty.
- If the property has a type defined in the profile, it ensures that the property has references.
get_value_list
@staticmethod
def get_value_list(
metadata: MetadataSet,
prop_id: str,
shared_objects: SharedPropertyObjectsSet | None = None,
profile: PropertyProfile | None = None) -> List[Dict[str, str]]
Retrieves a dictionary of values based on the provided metadata, property ID, shared objects, and profile.
Arguments:
metadatadict - The metadata dictionary containing various objects.prop_idstr - The property ID to look up in the metadata.shared_objectslist, optional - A list of shared objects that may be referenced in the metadata. Defaults to an empty list.profilePropertyProfile - A dictionary containing profile information, including class layouts and templates.
Returns:
dict- A dictionary of values where keys are object IDs and values are the transformed values based on the metadata and profile.