API Reference¶
This API reference provides comprehensive documentation for all public classes and functions in the BAM Masterdata package. For more detailed examples and usage patterns, see the How-to Guides and Tutorial sections.
Warning
This documentation page is currently broken, as we shifted from MkDocs to Zensical for our documentation engine.
bam_masterdata.metadata.entities
¶
BaseEntity
¶
Bases: BaseModel
Base class used to define ObjectType and VocabularyType classes. It extends the BaseModel
adding new methods that are useful for interfacing with openBIS.
Source code in bam_masterdata/metadata/entities.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 | |
cls_name
property
¶
Returns the entity name of the class as a string to speed up checks. This is a property to be overwritten by each of the abstract entity types.
get_property_metadata()
¶
Dictionary containing the metadata of the properties assigned to the entity type.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing the keys of the |
dict
|
values of the definitions of |
|
dict
|
{ "name": PropertyTypeAssignment( code="$NAME", data_type=VARCHAR, mandatory=True, property_label="Name" ), "age": PropertyTypeAssignment( code="AGE", data_type=INTEGER, mandatory=False, property_label="Age" ), |
|
dict
|
} |
Source code in bam_masterdata/metadata/entities.py
model_to_dict()
¶
Returns the model as a dictionary storing the data defs and the property or vocabulary term
assignments.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The dictionary representation of the model. |
Source code in bam_masterdata/metadata/entities.py
model_to_json(indent=None)
¶
Returns the model as a string in JSON format storing the data defs and the property or
vocabulary term assignments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indent
|
Optional[int]
|
The indent to print in JSON. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The JSON representation of the model. |
Source code in bam_masterdata/metadata/entities.py
model_to_rdf(namespace, graph, logger)
¶
Convert the entity to RDF triples and add them to the graph. The function uses the
_add_properties_rdf method to convert the properties assigned to the entity to RDF triples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
Namespace
|
The namespace to use for the RDF graph. |
required |
graph
|
Graph
|
The RDF graph to which the entity is added. |
required |
logger
|
BoundLoggerLazyProxy
|
The logger to log messages. |
required |
Source code in bam_masterdata/metadata/entities.py
to_dict()
¶
Returns the entity as a dictionary storing the value of the properties assigned to the entity.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The dictionary representation of the entity. |
Source code in bam_masterdata/metadata/entities.py
to_hdf5(hdf_file, group_name='')
¶
Serialize the entity to a HDF5 file under the group specified in the input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hdf_file
|
File
|
The HDF5 file to store the entity. |
required |
group_name
|
str
|
The group name to serialize the data. |
''
|
Source code in bam_masterdata/metadata/entities.py
to_json(indent=None)
¶
Returns the entity as a string in JSON format storing the value of the properties assigned to the entity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indent
|
Optional[int]
|
The indent to print in JSON. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The JSON representation of the entity. |
Source code in bam_masterdata/metadata/entities.py
ObjectType
¶
Bases: BaseEntity
Base class used to define object types. All object types must inherit from this class. The
object types are defined in the module bam_masterdata/object_types.py.
The ObjectType class contains a list of all properties defined for a ObjectType, for
internally represent the model in other formats (e.g., JSON or Excel).
Note this is also used for CollectionType and DatasetType, as they also contain a list of
properties.
Source code in bam_masterdata/metadata/entities.py
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 | |
base_name
property
¶
Returns the entity name of the class as a string.
get_vocabulary_class(vocabulary_code, vocab_path)
¶
Get the class instance of the vocabulary type defined by vocabulary_code in the Python module
specified by vocab_path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vocabulary_code
|
str
|
Code of the vocabulary type to get. |
required |
vocab_path
|
str
|
Path to the module containing the vocabulary type definitions. |
required |
Returns:
| Type | Description |
|---|---|
VocabularyType | None
|
VocabularyType | None: The class of the vocabulary type if found, otherwise None. |
Source code in bam_masterdata/metadata/entities.py
model_validator_after_init(data)
classmethod
¶
Validate the model after instantiation of the class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The data containing the fields values to validate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The data with the validated fields. |
Source code in bam_masterdata/metadata/entities.py
to_openbis_sync(openbis)
¶
Synchronizes this ObjectType definition and its PropertyTypeAssignment with the openbis instance.
Supported operations: - create new object types - add new assigned properties to existing object types - modify specific fields in object types or assigned properties
Not supported operations: - deletion of object types - deletion of previously assigned properties - assigned properties code changes - assigned properties unit changes - assigned properties data type changes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
BoundLoggerLazyProxy
|
The logger to log messages. |
required |
openbis
|
Openbis
|
The openBIS instance to synchronize this object type to. |
required |
Returns:
| Type | Description |
|---|---|
SyncResult
|
The result of the synchronization process. Useful for structuring logging. |
Source code in bam_masterdata/metadata/entities.py
CollectionType
¶
Bases: ObjectType
Source code in bam_masterdata/metadata/entities.py
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 | |
base_name
property
¶
Returns the entity name of the class as a string.
add(object_type, destination=None)
¶
Add an object type to the collection type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object_type
|
ObjectType
|
The object type to add to the collection type. |
required |
destination
|
Destination | None
|
Optional openBIS destination override for this object. If omitted, the default destination configured in RunParsers is used. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The unique identifier of the object type assigned in openBIS. |
Source code in bam_masterdata/metadata/entities.py
add_relationship(parent, child)
¶
Add a relationship between two object types in the collection type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
str | dict
|
Either the unique identifier of the parent object type or a dictionary representation of the parent object type. |
required |
child
|
str | dict
|
Either the unique identifier of the child object type or a dictionary representation of the child object type. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The unique identifier of the created relationship, generated from the resolved parent and child identifiers. |
Source code in bam_masterdata/metadata/entities.py
remove(object_id='')
¶
Remove an object type from the collection type by its unique identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object_id
|
str
|
The ID of the object type to be removed from the collection. |
''
|
Source code in bam_masterdata/metadata/entities.py
remove_relationship(relationship_id)
¶
Remove a relationship from the collection type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
relationship_id
|
str
|
The unique identifier of the relationship to remove. |
required |
Source code in bam_masterdata/metadata/entities.py
DatasetType
¶
Bases: ObjectType
Source code in bam_masterdata/metadata/entities.py
base_name
property
¶
Returns the entity name of the class as a string.
VocabularyType
¶
Bases: BaseEntity
Base class used to define vocabulary types. All vocabulary types must inherit from this class. The
vocabulary types are defined in the module bam_masterdata/vocabulary_types.py.
The VocabularyType class contains a list of all terms defined for a VocabularyType, for
internally represent the model in other formats (e.g., JSON or Excel).
Source code in bam_masterdata/metadata/entities.py
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 | |
base_name
property
¶
Returns the entity name of the class as a string.
model_validator_after_init(data)
classmethod
¶
Validate the model after instantiation of the class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The data containing the fields values to validate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The data with the validated fields. |
Source code in bam_masterdata/metadata/entities.py
to_openbis_sync(openbis)
¶
Synchronizes this VocabularyType definition and its VocabularyTerms with the openBIS instance.
Supported operations: - create new vocabularies - modify vocabulary descriptions - add new vocabulary terms - modify vocabulary term labels - modify vocabulary term descriptions
Forbidden operations:
- delete vocabularies
- delete vocabulary terms
- modify vocabulary codes
- modify vocabulary term codes
- modify other vocabulary term metadata, such as official
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
openbis
|
Openbis
|
The openBIS instance to synchronize this vocabulary to. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SyncResult |
SyncResult
|
Metadata describing the synchronization operations. |
Source code in bam_masterdata/metadata/entities.py
bam_masterdata.metadata.definitions
¶
EntityDef
¶
Bases: BaseModel
Abstract base class for all masterdata entity definitions. The entity definitions are immutable properties.
This class provides a common interface (with common attributes like code and
description.) for all entity definitions.
Source code in bam_masterdata/metadata/definitions.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
excel_headers_map
property
¶
Maps the field keys of the Pydantic model into the openBIS Excel style headers.
excel_name
property
¶
Returns the name of the entity in a format suitable for the openBIS Excel file.
model_id(data)
classmethod
¶
Populate id based on the entity code and entity type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The data containing the fields values to validate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The data with the validated fields. |
Source code in bam_masterdata/metadata/definitions.py
strip_description(value)
classmethod
¶
Strip leading and trailing whitespace from descriptions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Description string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The trimmed description. |
Source code in bam_masterdata/metadata/definitions.py
validate_code(value)
classmethod
¶
Validate entity codes against the allowed openBIS format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Candidate code string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The validated code. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the code is empty or contains invalid characters. |
Source code in bam_masterdata/metadata/definitions.py
validate_iri(value)
classmethod
¶
Validate the optional ontology IRI against the expected BAM pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | None
|
Candidate IRI string, or None. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The validated IRI (or None). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the IRI does not match the required pattern. |
Source code in bam_masterdata/metadata/definitions.py
ObjectTypeDef
¶
Bases: BaseObjectTypeDef
Definition class for an object type. It adds the fields of generated_code_prefix, auto_generate_codes,
and validation_script to the common attributes of a base object type definition. E.g.:
class Instrument(BaseModel):
defs = ObjectTypeDef(
code='INSTRUMENT',
description='
Measuring Instrument//Messgerät
',
generated_code_prefix='INS',
)
Source code in bam_masterdata/metadata/definitions.py
model_validator_after_init(data)
classmethod
¶
Ensure generated_code_prefix is set after initialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The data containing the fields values to validate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The data with the validated fields. |
Source code in bam_masterdata/metadata/definitions.py
CollectionTypeDef
¶
DatasetTypeDef
¶
Bases: BaseObjectTypeDef
Definition class for a data set type. E.g.:
```python class RawData(BaseModel): defs = DatasetTypeDef( code='RAW_DATA', description='...', )
Source code in bam_masterdata/metadata/definitions.py
VocabularyTypeDef
¶
Bases: EntityDef
Definition class for a vocabulary type. It adds the fields of url_template to the common attributes of
an entity definition. E.g.:
class DocumentType(VocabularyType):
defs = VocabularyTypeDef(
code='DOCUMENT_TYPE',
description='Document type//Dokumententypen',
)
Source code in bam_masterdata/metadata/definitions.py
PropertyTypeDef
¶
Bases: EntityDef
Definition class for a property type. It adds the fields of property_label, data_type,
vocabulary_code, metadata, dynamic_script, and multivalued to the common attributes of
an entity definition.
This class is used as an abstract layer for PropertyTypeAssignment, as in openBIS a PropertyType
definition has less fields than when it is actually assigned to an entity type.
Source code in bam_masterdata/metadata/definitions.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
apply_units_to_property_label(data)
classmethod
¶
Enforce the in [units] suffix in property_label when units are provided.
If the label already contains a bracketed unit, it must include the
exact in [units] format or validation fails. Otherwise, the suffix
is appended.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The data containing the fields values to validate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The data with the updated label (if needed). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a bracketed unit exists without the |
Source code in bam_masterdata/metadata/definitions.py
validate_units(value)
classmethod
¶
Validate the optional units string using pint's unit registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | None
|
Units string in pint format, or None. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The validated units string (or None). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the units string is not recognized by pint. |
Source code in bam_masterdata/metadata/definitions.py
PropertyTypeAssignment
¶
Bases: PropertyTypeDef
Base class used to define properties inside ObjectType, CollectionType, or DatasetType.
This is used to construct these types by assigning property types to them. It adds the fields
of mandatory, show_in_edit_views, section, unique, and internal_assignment to the common
attributes of a property type definition. E.g.:
class Instrument(ObjectType):
defs = ObjectTypeDef(
code='INSTRUMENT',
description='
Measuring Instrument//Messgerät
',
generated_code_prefix='INS',
)
alias = PropertyTypeAssignment(
code='ALIAS',
data_type='VARCHAR',
property_label='Alternative name',
description='
e.g. abbreviation or nickname//z.B. Abkürzung oder Spitzname//z.B. Abkürzung oder Spitzname
',
mandatory=False,
show_in_edit_views=True,
section='General information',
)
# ... other property type assignments here ...
Source code in bam_masterdata/metadata/definitions.py
VocabularyTerm
¶
Bases: VocabularyTypeDef
Base class used to define terms inside a VocabularyType. This is used to construct the vocabulary types
by assigning vocabulary terms to them. It adds the fields of label and official to the common attributes
of a vocabulary type definition. E.g.:
```python class DocumentType(VocabularyType): defs = VocabularyTypeDef( code='DOCUMENT_TYPE', description='Document type//Dokumententypen', )
acceptance_certificate = VocabularyTerm(
code='ACCEPTANCE_CERTIFICATE',
label='Acceptance Certificate',
description='Acceptance Certificate//Abnahmezeugnis',
)
calibration_certificate = VocabularyTerm(
code='CALIBRATION_CERTIFICATE',
label='Calibration Certificate',
description='Calibration Certificate//Kalibrierschein',
)
# ... other vocabulary term definitions here ...
Source code in bam_masterdata/metadata/definitions.py
bam_masterdata.metadata.entities_dict
¶
EntitiesDict
¶
Class to convert the entities in the datamodel defined in Python to a dictionary. The entities are read from the Python
files defined in python_path.
Source code in bam_masterdata/metadata/entities_dict.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
single_json()
¶
Returns a single dictionary containing all the entities in the datamodel defined in the Python files
in python_path. The format of this dictionary is:
{
"collection_type": {
"COLLECTION": {
"defs": {
"code": "COLLECTION",
"description": "",
...
},
"properties": [
{
"code": "$DEFAULT_COLLECTION_VIEW",
"description": "Default view for experiments of the type collection",
...
},
{...},
...
]
}
},
"object_type": {...},
...
}
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing all the entities in the datamodel. |
Source code in bam_masterdata/metadata/entities_dict.py
to_dict(module_path)
¶
Returns a dictionary containing entities read from the module_path Python file. The Python modules
are imported using the function import_module and their contents are inspected (using inspect) to
find the classes in the datamodel containing defs and with a model_to_dict method defined.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_path
|
str
|
Path to the Python module file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing the entities in the datamodel defined in one Python module file. |
Source code in bam_masterdata/metadata/entities_dict.py
bam_masterdata.cli.fill_masterdata
¶
MasterdataCodeGenerator
¶
Class to generate Python code for the masterdata datamodel based on the entities existing in an openBIS instance.
Source code in bam_masterdata/cli/fill_masterdata.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
add_properties(entities, parent_code, data, lines)
¶
Add the properties of the entity to the lines list. The properties are added as
PropertyTypeAssignment objects.
Note: the assigned properties do not have the information of code for the entity when
data_type is OBJECT or CONTROLLEDVOCABULARY. These are instead defined in property_types.py.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entities
|
dict
|
The dictionary of entities (objects, collections, datasets, vocabularies). |
required |
parent_code
|
code
|
The code of the parent class. |
required |
data
|
dict
|
The data information for the entity as obtained from openBIS. |
required |
lines
|
list
|
A list of strings to be printed to the Python module. |
required |
Source code in bam_masterdata/cli/fill_masterdata.py
determine_parent_class(code, class_names, default, lines)
¶
Determine the parent class information of the entity based on its code. It returns
the parent_code and parent class, as well as the class_name of the entity. The
class will inherit from parent_class.
If the parent class does not exist, a note is added to the lines list for debugging purposes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
The code of the entity. |
required |
class_names
|
dict
|
A dictionary with the class names of the entities. |
required |
default
|
str
|
The default parent class if the parent class does not exist. |
required |
lines
|
list
|
A list of strings to be printed to the Python module. |
required |
Returns: tuple: The parent code, parent class, and class name of the entity.
Source code in bam_masterdata/cli/fill_masterdata.py
generate_collection_types()
¶
Generate Python code for the collection types in the Openbis datamodel. The code is generated
as a string which is then printed out to the specific Python module in bam_masterdata/datamodel/collection_types.py.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Python code for the collection types. |
Source code in bam_masterdata/cli/fill_masterdata.py
generate_dataset_types()
¶
Generate Python code for the dataset types in the Openbis datamodel. The code is generated
as a string which is then printed out to the specific Python module in bam_masterdata/datamodel/dataset_types.py.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Python code for the dataset types. |
Source code in bam_masterdata/cli/fill_masterdata.py
generate_object_types()
¶
Generate Python code for the object types in the Openbis datamodel. The code is generated
as a string which is then printed out to the specific Python module in bam_masterdata/datamodel/object_types.py.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Python code for the object types. |
Source code in bam_masterdata/cli/fill_masterdata.py
generate_vocabulary_types()
¶
Generate Python code for the vocabulary types in the Openbis datamodel. The code is generated
as a string which is then printed out to the specific Python module in bam_masterdata/datamodel/vocabulary_types.py.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Python code for the vocabulary types. |
Source code in bam_masterdata/cli/fill_masterdata.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
get_property_object_code(prop_data)
¶
Get the object code (or vocabulary code) used for reference for the assigned property with prop_code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prop_data
|
dict
|
The data information for the property as obtained from openBIS. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The object/vocabulary code used for reference for the assigned property. |
Source code in bam_masterdata/cli/fill_masterdata.py
bam_masterdata.excel.excel_to_entities
¶
MasterdataExcelExtractor
¶
Source code in bam_masterdata/excel/excel_to_entities.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | |
__init__(excel_path, **kwargs)
¶
Initialize the MasterdataExtractor.
Source code in bam_masterdata/excel/excel_to_entities.py
block_to_entity_dict(sheet, start_index_row, last_non_empty_row, complete_dict)
¶
Extracts entity attributes from an Excel sheet block and returns them as a dictionary.
Source code in bam_masterdata/excel/excel_to_entities.py
excel_to_entities()
¶
Extracts entities from an Excel file and returns them as a dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
dict[str, dict[str, Any]]: A dictionary where each key is a normalized sheet name and the value is a dictionary |
dict[str, dict[str, Any]]
|
containing the extracted entities. Returns an empty dictionary if all sheets are empty. |
Source code in bam_masterdata/excel/excel_to_entities.py
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | |
extract_value(sheet, row, column, validation_pattern=None, is_description=False, is_data=False, is_url=False)
¶
Extracts and validates a value from a specified cell in the Excel sheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
row
|
int
|
The row number of the cell (1-based index). |
required |
column
|
int
|
The column number of the cell (1-based index). |
required |
validation_pattern
|
str
|
Optional regex pattern to validate the cell value. |
None
|
is_description
|
bool
|
Flag indicating if the value is a description. |
False
|
is_data
|
bool
|
Flag indicating if the value is a data type. |
False
|
is_url
|
bool
|
Flag indicating if the value is a URL. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The extracted and validated cell value as a string. Returns an empty string if the value is invalid or not provided. |
Source code in bam_masterdata/excel/excel_to_entities.py
get_and_check_property(value, term, coordinate, sheet_title, is_description=False, is_code=False, is_data=False, is_url=False)
¶
Gets a property and checks its format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | bool | None
|
The string to convert. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The property. |
Source code in bam_masterdata/excel/excel_to_entities.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_last_non_empty_row(sheet, start_index)
¶
Finds the last non-empty row before encountering a completely empty row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
start_index
|
int
|
The row number to start checking from (1-based index). |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
The row number of the last non-empty row before an empty row is encountered, |
int | None
|
or None if no non-empty rows are found starting from the given index. |
Source code in bam_masterdata/excel/excel_to_entities.py
index_to_excel_column(index)
¶
Converts a 1-based index to an Excel column name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The 1-based index to convert. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The corresponding Excel column name. |
Source code in bam_masterdata/excel/excel_to_entities.py
process_entity(sheet, start_index_row, header_terms, expected_terms, entity_type)
¶
Process an entity type block in the Excel sheet and return its attributes as a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
start_index_row
|
int
|
The row where the current entity type begins (1-based index). |
required |
header_terms
|
list[str]
|
List of header terms in the entity block. |
required |
expected_terms
|
list[str]
|
List of expected terms to extract from the entity block. |
required |
entity_type
|
str
|
The type of the entity (e.g., SAMPLE_TYPE, OBJECT_TYPE). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary containing the attributes of the entity. |
Source code in bam_masterdata/excel/excel_to_entities.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
process_term(term, cell_value, coordinate, sheet_title)
¶
Processes a term by converting it to a boolean if necessary or checking its validity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
term
|
str
|
The term being processed. |
required |
cell_value
|
Any
|
The value of the cell. |
required |
coordinate
|
str
|
The coordinate of the cell in the sheet. |
required |
sheet_title
|
str
|
The title of the sheet. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The processed value, either as a boolean or the original value after validation. |
Source code in bam_masterdata/excel/excel_to_entities.py
properties_to_dict(sheet, start_index_row, last_non_empty_row)
¶
Extracts properties from an Entity type block in the Excel sheet and returns them as a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
start_index_row
|
int
|
Row where the current entity type begins (1-based index). |
required |
last_non_empty_row
|
int
|
Row where the current entity type finish (1-based index). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
A dictionary where each key is a property code and the value is a dictionary |
dict[str, dict[str, Any]]
|
containing the attributes of the property. |
Source code in bam_masterdata/excel/excel_to_entities.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | |
str_to_bool(value, term, coordinate, sheet_title)
¶
Converts a string to a boolean value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | bool | None
|
The string to convert. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
The boolean value. |
Source code in bam_masterdata/excel/excel_to_entities.py
terms_to_dict(sheet, start_index_row, last_non_empty_row)
¶
Extracts terms from a Vocabulary block in the Excel sheet and returns them as a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
start_index_row
|
int
|
Row where the current entity type begins (1-based index). |
required |
last_non_empty_row
|
int
|
Row where the current entity type finish (1-based index). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
A dictionary where each key is a vocabulary term code and the value is a dictionary |
dict[str, dict[str, Any]]
|
containing the attributes of the vocabulary term. |
Source code in bam_masterdata/excel/excel_to_entities.py
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 | |
bam_masterdata.cli.entities_to_excel
¶
entities_to_excel(worksheet, module_path, definitions_module)
¶
Export entities to the Excel file. The Python modules are imported using the function import_module,
and their contents are inspected (using inspect) to find the classes in the datamodel containing
defs and with a model_to_json method defined. Each row is then appended to the worksheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
worksheet
|
Worksheet
|
The worksheet to append the entities. |
required |
module_path
|
str
|
Path to the Python module file. |
required |
definitions_module
|
Any
|
The module containing the definitions of the entities. This is used to match the header definitions of the entities. |
required |
Source code in bam_masterdata/cli/entities_to_excel.py
bam_masterdata.cli.entities_to_rdf
¶
entities_to_rdf(graph, module_path, logger)
¶
Convert the entities defined in the specified module to RDF triples and add them to the graph. The function
uses the model_to_rdf method defined in each class to convert the class attributes to RDF triples. The
function also adds the PropertyType and other entity types as placeholders in the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Graph
|
The RDF graph to which the entities are added. |
required |
module_path
|
str
|
The path to the module containing the entities to be converted. |
required |
logger
|
BoundLoggerLazyProxy
|
The logger to log messages. |
required |
Source code in bam_masterdata/cli/entities_to_rdf.py
rdf_graph_init(g)
¶
Initialize the RDF graph with base namespaces, annotation properties, and internal BAM properties. This
function also creates placeholders for PropertyType and other entity types. The graph is to be printed out
in RDF/XML format in the entities_to_rdf function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
The RDF graph to be initialized. |
required |
Source code in bam_masterdata/cli/entities_to_rdf.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
bam_masterdata.cli.run_parser
¶
ResolvedDestination
dataclass
¶
Runtime openBIS destination for an object.
Unlike Destination in bam_masterdata/metadata/destination.py, this contains resolved pybis entities and is used
internally by RunParsers only.
Source code in bam_masterdata/cli/run_parser.py
RunParsers
¶
Run configured parsers and persist the resulting data model to openBIS.
The class parses input files into an internal collection of objects and relationships, creates or updates the corresponding objects in openBIS, attaches datasets, and creates parent-child relationships between objects.
Objects can be stored directly under a project or inside a collection, depending on the
configured collection_name.
Source code in bam_masterdata/cli/run_parser.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 | |
parsing()
¶
Runs the parser specific class for each of the files specified in self.files_parser and adds them to the collection.
Source code in bam_masterdata/cli/run_parser.py
run()
¶
Runs the complete parsing and openBIS import workflow.
Parses all configured files into the internal collection, creates or updates the corresponding objects in openBIS, stores their local-to-openBIS identifier mapping, attaches object-level and collection-level datasets, and finally creates the parent-child relationships defined during parsing.
Existing openBIS objects are updated rather than recreated when their identifier already exists.
Source code in bam_masterdata/cli/run_parser.py
RunParsersWithTransactions
¶
Bases: RunParsers
Run parsers and persist objects and relationships to openBIS using transactions.
Object creation and updates are committed in one transaction. Relationships are committed in a separate transaction after object creation has completed.
Dataset uploads are currently performed outside transactions.
Source code in bam_masterdata/cli/run_parser.py
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
run()
¶
Runs the parsing and transactional openBIS import workflow.
Parses the configured files, creates or updates all generated objects in a single transaction, uploads attached datasets, and finally commits parent-child relationships in a separate transaction.
Dataset uploads are currently performed outside transactions.
Source code in bam_masterdata/cli/run_parser.py
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
bam_masterdata.excel.excel_to_entities
¶
MasterdataExcelExtractor
¶
Source code in bam_masterdata/excel/excel_to_entities.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | |
__init__(excel_path, **kwargs)
¶
Initialize the MasterdataExtractor.
Source code in bam_masterdata/excel/excel_to_entities.py
block_to_entity_dict(sheet, start_index_row, last_non_empty_row, complete_dict)
¶
Extracts entity attributes from an Excel sheet block and returns them as a dictionary.
Source code in bam_masterdata/excel/excel_to_entities.py
excel_to_entities()
¶
Extracts entities from an Excel file and returns them as a dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
dict[str, dict[str, Any]]: A dictionary where each key is a normalized sheet name and the value is a dictionary |
dict[str, dict[str, Any]]
|
containing the extracted entities. Returns an empty dictionary if all sheets are empty. |
Source code in bam_masterdata/excel/excel_to_entities.py
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | |
extract_value(sheet, row, column, validation_pattern=None, is_description=False, is_data=False, is_url=False)
¶
Extracts and validates a value from a specified cell in the Excel sheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
row
|
int
|
The row number of the cell (1-based index). |
required |
column
|
int
|
The column number of the cell (1-based index). |
required |
validation_pattern
|
str
|
Optional regex pattern to validate the cell value. |
None
|
is_description
|
bool
|
Flag indicating if the value is a description. |
False
|
is_data
|
bool
|
Flag indicating if the value is a data type. |
False
|
is_url
|
bool
|
Flag indicating if the value is a URL. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The extracted and validated cell value as a string. Returns an empty string if the value is invalid or not provided. |
Source code in bam_masterdata/excel/excel_to_entities.py
get_and_check_property(value, term, coordinate, sheet_title, is_description=False, is_code=False, is_data=False, is_url=False)
¶
Gets a property and checks its format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | bool | None
|
The string to convert. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The property. |
Source code in bam_masterdata/excel/excel_to_entities.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_last_non_empty_row(sheet, start_index)
¶
Finds the last non-empty row before encountering a completely empty row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
start_index
|
int
|
The row number to start checking from (1-based index). |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
The row number of the last non-empty row before an empty row is encountered, |
int | None
|
or None if no non-empty rows are found starting from the given index. |
Source code in bam_masterdata/excel/excel_to_entities.py
index_to_excel_column(index)
¶
Converts a 1-based index to an Excel column name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The 1-based index to convert. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The corresponding Excel column name. |
Source code in bam_masterdata/excel/excel_to_entities.py
process_entity(sheet, start_index_row, header_terms, expected_terms, entity_type)
¶
Process an entity type block in the Excel sheet and return its attributes as a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
start_index_row
|
int
|
The row where the current entity type begins (1-based index). |
required |
header_terms
|
list[str]
|
List of header terms in the entity block. |
required |
expected_terms
|
list[str]
|
List of expected terms to extract from the entity block. |
required |
entity_type
|
str
|
The type of the entity (e.g., SAMPLE_TYPE, OBJECT_TYPE). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary containing the attributes of the entity. |
Source code in bam_masterdata/excel/excel_to_entities.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
process_term(term, cell_value, coordinate, sheet_title)
¶
Processes a term by converting it to a boolean if necessary or checking its validity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
term
|
str
|
The term being processed. |
required |
cell_value
|
Any
|
The value of the cell. |
required |
coordinate
|
str
|
The coordinate of the cell in the sheet. |
required |
sheet_title
|
str
|
The title of the sheet. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The processed value, either as a boolean or the original value after validation. |
Source code in bam_masterdata/excel/excel_to_entities.py
properties_to_dict(sheet, start_index_row, last_non_empty_row)
¶
Extracts properties from an Entity type block in the Excel sheet and returns them as a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
start_index_row
|
int
|
Row where the current entity type begins (1-based index). |
required |
last_non_empty_row
|
int
|
Row where the current entity type finish (1-based index). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
A dictionary where each key is a property code and the value is a dictionary |
dict[str, dict[str, Any]]
|
containing the attributes of the property. |
Source code in bam_masterdata/excel/excel_to_entities.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | |
str_to_bool(value, term, coordinate, sheet_title)
¶
Converts a string to a boolean value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | bool | None
|
The string to convert. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
The boolean value. |
Source code in bam_masterdata/excel/excel_to_entities.py
terms_to_dict(sheet, start_index_row, last_non_empty_row)
¶
Extracts terms from a Vocabulary block in the Excel sheet and returns them as a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Worksheet
|
The worksheet object. |
required |
start_index_row
|
int
|
Row where the current entity type begins (1-based index). |
required |
last_non_empty_row
|
int
|
Row where the current entity type finish (1-based index). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
A dictionary where each key is a vocabulary term code and the value is a dictionary |
dict[str, dict[str, Any]]
|
containing the attributes of the vocabulary term. |
Source code in bam_masterdata/excel/excel_to_entities.py
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 | |
bam_masterdata.openbis.login
¶
ologin(url='')
¶
Connect to openBIS using the credentials stored in the environment variables.
If an existing Openbis session is provided, the session is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
(str, Openbis)
|
The URL of the openBIS instance. Defaults to the value of the |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
Openbis |
Openbis
|
Openbis object for the specific openBIS instance defined in |
Source code in bam_masterdata/openbis/login.py
bam_masterdata.openbis.get_entities
¶
OpenbisEntities
¶
Class to get openBIS entities and their attributes as dictionaries to be printed in the
Python modules of bam_masterdata/datamodel/.
Source code in bam_masterdata/openbis/get_entities.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
get_collection_dict()
¶
Get the collection types from openBIS and return them as a dictionary where the keys
are the collection type code and the value is a dictionary of attributes assigned to that
collection type.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionary of collection types with their attributes. |
Source code in bam_masterdata/openbis/get_entities.py
get_dataset_dict()
¶
Get the dataset types from openBIS and return them as a dictionary where the keys
are the dataset type code and the value is a dictionary of attributes assigned to that
dataset type.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionary of dataset types with their attributes. |
Source code in bam_masterdata/openbis/get_entities.py
get_object_dict()
¶
Get the object types from openBIS and return them as a dictionary where the keys
are the object type code and the value is a dictionary of attributes assigned to that
object type.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionary of object types with their attributes. |
Source code in bam_masterdata/openbis/get_entities.py
get_property_dict()
¶
Get the property types from openBIS and return them as a dictionary where the keys
are the property type code and the value is a dictionary of attributes assigned to that
property type.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionary of property types with their attributes. |
Source code in bam_masterdata/openbis/get_entities.py
get_vocabulary_dict()
¶
Get the vocabulary types from openBIS and return them as a dictionary where the keys
are the vocabulary type code and the value is a dictionary of attributes assigned to that
vocabulary type.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionary of vocabulary types with their attributes. |
Source code in bam_masterdata/openbis/get_entities.py
bam_masterdata.checker.checker
¶
MasterdataChecker
¶
Source code in bam_masterdata/checker/checker.py
__init__()
¶
Initialize the comparator with validation rules and set the datamodel directory.
check(mode='all')
¶
Run validations.
Modes: - "self" -> Validate only the current data model. - "incoming" -> Validate only the new entity structure. - "validate" -> Validate both the current model and new entities. - "compare" -> Compare new entities against the current model. - "all" -> Run both validation types. - "individual" -> Run individual repositories validations.
Before running, ensure that required models are loaded based on the mode.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Validation results. |
Source code in bam_masterdata/checker/checker.py
load_current_model(datamodel_dir='./bam_masterdata/datamodel/')
¶
Load and transform the current data model (Pydantic classes) into JSON.
Uses the default datamodel directory unless overridden.
Source code in bam_masterdata/checker/checker.py
load_new_entities(source)
¶
Load new entities from various sources (Python classes, Excel, etc.).
Source code in bam_masterdata/checker/checker.py
bam_masterdata.checker.masterdata_validator
¶
MasterdataValidator
¶
Source code in bam_masterdata/checker/masterdata_validator.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 | |
__init__(new_entities, current_model, validation_rules)
¶
Initialize the validator with new and current entity data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_entities
|
dict
|
The incoming datamodel. |
required |
current_model
|
dict
|
The existing datamodel. |
required |
validation_rules
|
dict
|
The validation rules to apply. |
required |
Source code in bam_masterdata/checker/masterdata_validator.py
validate(mode='all')
¶
Run validations based on mode: - "self": Validate current model structure and format. - "incoming": Validate new entities structure and format. - "validate": Validate both current and incoming models but do not compare. - "compare": Validate new entities against the current model. - "all": Run both. - "individual": Validate new entities and compare them with the current model.
Returns: dict: Validation results.
Source code in bam_masterdata/checker/masterdata_validator.py
bam_masterdata.checker.source_loader
¶
SourceLoader
¶
Load the entities from a source written in different formats (Python classes, Excel, etc.) as defined
in the source_path into a dictionary.
Source code in bam_masterdata/checker/source_loader.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
entities_to_json()
¶
Transforms the dictionary of entities returned by the Excel extractor into a dictionary in JSON format for later check.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing the transformed entities. |
Source code in bam_masterdata/checker/source_loader.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
load()
¶
Load entities from the source path into a dictionary.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing the entities. |
Source code in bam_masterdata/checker/source_loader.py
bam_masterdata.parsing.parsing
¶
AbstractParser
¶
Bases: ABC
Example Abstract base class for parsers. Each parser should inherit from this class and implement
the parse() method to populate collection.
Source code in bam_masterdata/parsing/parsing.py
parse(files, collection, logger)
abstractmethod
¶
Parse the input files and populate the provided collection with object types, their metadata,
and their relationships.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
files
|
list[str]
|
List of file paths to be parsed. |
required |
collection
|
CollectionType
|
Collection to be populated with parsed data. |
required |
logger
|
BoundLoggerLazyProxy
|
Logger for logging messages during parsing. |
required |
Source code in bam_masterdata/parsing/parsing.py
bam_masterdata.utils.utils
¶
code_to_class_name(code, logger=logger, entity_type='object')
¶
Converts an openBIS code to a class name by capitalizing each word and removing special characters. In
the special case the entity is a property type, it retains the full name separated by points instead of
only keeping the last name (e.g., "TEM.INSTRUMENT" -> "TemInstrument" instead of "Instrument").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
The openBIS code to convert to a class name. |
required |
logger
|
BoundLoggerLazyProxy
|
The logger to log messages. Default is |
logger
|
entity_type
|
str
|
The type of entity to convert. Default is "object". |
'object'
|
Returns: str: The class name derived from the openBIS code.
Source code in bam_masterdata/utils/utils.py
delete_and_create_dir(directory_path, logger=logger, force_delete=False)
¶
Deletes the directory at directory_path and creates a new one in the same path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory_path
|
str
|
The directory path to delete and create the folder. |
required |
logger
|
BoundLoggerLazyProxy
|
The logger to log messages. Default is |
logger
|
force_delete
|
bool
|
If True, the directory will be forcibly deleted if it exists. |
False
|
Source code in bam_masterdata/utils/utils.py
duplicated_property_types(module_path, logger)
¶
Find the duplicated property types in a module specified by module_path and returns a dictionary
containing the duplicated property types class names as keys and the lines where they matched as values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_path
|
str
|
The path to the module containing the property types. |
required |
logger
|
BoundLoggerLazyProxy
|
The logger to log messages. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing the duplicated property types class names as keys and the |
dict
|
lines where they matched as values. |
Source code in bam_masterdata/utils/utils.py
format_json_id(value)
¶
Converts snake_case or UPPER_CASE to PascalCase while keeping special cases like '$NAME' untouched.
Source code in bam_masterdata/utils/utils.py
import_module(module_path)
¶
Dynamically imports a module from the given file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_path
|
str
|
Path to the Python module file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
module |
Any
|
Imported module object. |
Source code in bam_masterdata/utils/utils.py
is_reduced_version(generated_code_value, code)
¶
Check if generated_code_value is a reduced version of code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
generated_code_value
|
str
|
The potentially reduced code. |
required |
code
|
str
|
The original full code. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if generated_code_value is a reduced version of code, False otherwise. |
Source code in bam_masterdata/utils/utils.py
listdir_py_modules(directory_path, logger=logger)
¶
Recursively goes through the directory_path and returns a list of all .py files that do not start with '_'. If
directory_path is a single Python module file, it will return a list with that file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory_path
|
str
|
The directory path to search through. |
required |
logger
|
BoundLoggerLazyProxy
|
The logger to log messages. Default is |
logger
|
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: A list of all .py files that do not start with '_' |
Source code in bam_masterdata/utils/utils.py
store_log_message(logger, entity_ref, message, level='error')
¶
Logs a message and stores it inside the entity's _log_msgs list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_ref
|
dict
|
The entity dictionary where _log_msgs should be stored. |
required |
message
|
str
|
The log message. |
required |
level
|
str
|
Log level ('error', 'warning', 'critical', 'info'). |
'error'
|
Source code in bam_masterdata/utils/utils.py
bam_masterdata.utils.paths
¶
find_dir(possible_locations)
¶
Search for a valid directory in a list of possible locations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
possible_locations
|
list[Path]
|
A list of possible locations to search for a directory. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If no valid directory is found. |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The path of the valid directory. |
Source code in bam_masterdata/utils/paths.py
bam_masterdata.utils.users
¶
UserID
¶
Source code in bam_masterdata/utils/users.py
get_userid_from_fullname(name)
¶
Return the userId matching the given fullname (case-insensitive). It uses the _split_name function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Full name, e.g., "John Doe" or "Doe, John". |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The userId if a match is found, otherwise None. |
Source code in bam_masterdata/utils/users.py
get_userid_from_names(firstname, lastname)
¶
Return the userId matching the given first and last name (case-insensitive).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
firstname
|
str
|
First name. |
required |
lastname
|
str
|
Last name. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The userId if a match is found, otherwise None. |
Source code in bam_masterdata/utils/users.py
get_bam_username(firstname, lastname)
¶
Tries to get the BAM username from the first and last names. The BAM username guess is defined by concatenating the first letter of the first name with the, max. 7 digits of the last name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
firstname
|
str
|
The first name. |
required |
lastname
|
str
|
The last name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The guessed BAM username. |