|
58 | 58 | ) |
59 | 59 | from energyml.utils.uri import Uri, create_uri_from_content_type_or_qualified_type |
60 | 60 | from energyml.utils.constants import ( |
61 | | - CORE_PROPERTIES_FOLDER_NAME, |
62 | 61 | EPCRelsRelationshipType, |
63 | 62 | EpcExportVersion, |
64 | 63 | MimeType, |
65 | 64 | OptimizedRegex, |
66 | | - file_extension_to_mime_type, |
67 | 65 | date_to_datetime, |
68 | 66 | ) |
69 | 67 | from energyml.utils.epc_utils import ( |
|
72 | 70 | gen_core_props_path, |
73 | 71 | make_path_relative_to_filepath_list, |
74 | 72 | make_path_relative_to_other_file, |
| 73 | + as_identifier, |
75 | 74 | ) |
76 | 75 |
|
77 | 76 | from energyml.utils.introspection import ( |
@@ -1623,7 +1622,7 @@ def put_object(self, obj: Any, dataspace: Optional[str] = None) -> Optional[str] |
1623 | 1622 | identifier = uri.as_identifier() |
1624 | 1623 | existing_metadata = self._metadata_mgr.get_metadata(identifier) |
1625 | 1624 | file_path = gen_energyml_object_path(obj, self._metadata_mgr._export_version) |
1626 | | - is_update = existing_metadata is not None |
| 1625 | + # is_update = existing_metadata is not None |
1627 | 1626 |
|
1628 | 1627 | # Write object data and metadata to EPC |
1629 | 1628 | try: |
@@ -2082,38 +2081,23 @@ def _update_access_order(self, identifier: str) -> None: |
2082 | 2081 | def _id_from_uri_or_identifier( |
2083 | 2082 | self, identifier: Union[str, Uri, Any], get_first_if_simple_uuid: bool = True |
2084 | 2083 | ) -> Optional[str]: |
2085 | | - if identifier is None: |
2086 | | - return None |
2087 | | - elif isinstance(identifier, str): |
2088 | | - if OptimizedRegex.UUID.fullmatch(identifier) is not None: |
2089 | | - if not get_first_if_simple_uuid: |
2090 | | - logging.warning( |
2091 | | - f"Identifier {identifier} is a simple UUID, but get_first_if_simple_uuid is False, cannot resolve to full identifier" |
2092 | | - ) |
2093 | | - return None |
2094 | | - # If it's a simple UUID, we need to find the corresponding identifier from metadata |
2095 | | - t_metadata_identifiers = self._metadata_mgr.get_uuid_identifiers(identifier) |
2096 | | - if t_metadata_identifiers is not None and len(t_metadata_identifiers) > 0: |
2097 | | - return t_metadata_identifiers[ |
2098 | | - 0 |
2099 | | - ] # If multiple metadata entries for the same UUID, we take the first one (this should not happen in a well-formed EPC file) |
2100 | | - else: |
2101 | | - logging.warning(f"No metadata found for UUID {identifier}, cannot get relationships") |
2102 | | - return None |
| 2084 | + try: |
| 2085 | + return as_identifier(identifier) |
| 2086 | + except Exception: |
| 2087 | + if not get_first_if_simple_uuid: |
| 2088 | + logging.warning( |
| 2089 | + f"Identifier {identifier} is a simple UUID, but get_first_if_simple_uuid is False, cannot resolve to full identifier" |
| 2090 | + ) |
| 2091 | + return None |
| 2092 | + # If it's a simple UUID, we need to find the corresponding identifier from metadata |
| 2093 | + t_metadata_identifiers = self._metadata_mgr.get_uuid_identifiers(identifier) |
| 2094 | + if t_metadata_identifiers is not None and len(t_metadata_identifiers) > 0: |
| 2095 | + return t_metadata_identifiers[ |
| 2096 | + 0 |
| 2097 | + ] # If multiple metadata entries for the same UUID, we take the first one (this should not happen in a well-formed EPC file) |
2103 | 2098 | else: |
2104 | | - return identifier |
2105 | | - elif isinstance(identifier, Uri): |
2106 | | - return identifier.as_identifier() |
2107 | | - elif isinstance(identifier, ResourceMetadata): |
2108 | | - return self._id_from_uri_or_identifier(identifier.identifier) |
2109 | | - elif isinstance(identifier, EpcObjectMetadata): |
2110 | | - return self._id_from_uri_or_identifier(identifier.uri) |
2111 | | - else: |
2112 | | - # Try to get URI from object |
2113 | | - obj_uri = get_obj_uri(obj=identifier, dataspace=None) |
2114 | | - if obj_uri is not None: |
2115 | | - return obj_uri.as_identifier() |
2116 | | - return str(identifier) |
| 2099 | + logging.warning(f"No metadata found for UUID {identifier}, cannot get relationships") |
| 2100 | + return None |
2117 | 2101 |
|
2118 | 2102 | def _rebuild_all_rels_sequential(self, clean_first: bool = True) -> Dict[str, int]: |
2119 | 2103 | """ |
|
0 commit comments