diff --git a/CHANGELOG.md b/CHANGELOG.md index 2df7b49795e2770aa4f75c90325366411ca2859e..fd606c341a231d95c5d2f4d8c181ac0ab294b1da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 h5py is now an optional dependency - table importer implementations for csv and tsv - string-in-list check for table imports -* AbtractCFood has new property, `update_flags`. +- AbtractCFood has new property, `update_flags`. ### Changed ### diff --git a/integrationtests/insert_model.py b/integrationtests/insert_model.py index ae3dd7701b44f5008bd976d81f8ecc8d9a02bf89..26bf478cdf0d3709e7c0c086fecf722b8c7f90fa 100755 --- a/integrationtests/insert_model.py +++ b/integrationtests/insert_model.py @@ -5,18 +5,29 @@ from caosadvancedtools.cfoods.h5 import H5CFood from caosadvancedtools.models.data_model import DataModel from caosadvancedtools.models.parser import parse_model_from_yaml -model = parse_model_from_yaml("model.yml") -model.sync_data_model(noquestion=True) - -if len(db.execute_query("FIND Property alias")) == 0: - al = db.Property(name="alias") - al.add_parent(name="name") - al.insert() - -h5model = db.Container() -h5file = h5py.File('extroot/ExperimentalData/2010_TestProject/2019-02-03/hdf5_dummy_file.hdf5', 'r') -H5CFood.create_structure(h5file, create_recordTypes=True, collection=h5model, - root_name="ExampleH5") -print(h5model) -h5model = DataModel(h5model) -h5model.sync_data_model(noquestion=True) + +def main(): + + # for testing existing data model parts with the YAML Interface + db.RecordType(name="TestRT1", datatype=db.TEXT).insert() + db.Property(name="TestP1", datatype=db.TEXT).insert() + + model = parse_model_from_yaml("model.yml") + model.sync_data_model(noquestion=True) + + if len(db.execute_query("FIND Property alias")) == 0: + al = db.Property(name="alias") + al.add_parent(name="name") + al.insert() + + h5model = db.Container() + h5file = h5py.File( + 'extroot/ExperimentalData/2010_TestProject/2019-02-03/hdf5_dummy_file.hdf5', 'r') + H5CFood.create_structure(h5file, create_recordTypes=True, collection=h5model, + root_name="ExampleH5") + h5model = DataModel(h5model) + h5model.sync_data_model(noquestion=True) + + +if __name__ == "__main__": + main() diff --git a/integrationtests/model.yml b/integrationtests/model.yml index e1753a9f84d6eff7a9a59c5d17ca4f9f9da7c4c6..cad7958803edf1a01f0649353443ffab350cc5e5 100644 --- a/integrationtests/model.yml +++ b/integrationtests/model.yml @@ -69,3 +69,6 @@ Report: - Publication hdf5File: datatype: REFERENCE +extern: + - TestRT1 + - TestP1 diff --git a/integrationtests/test_crawl_with_datamodel_problems.py b/integrationtests/test_crawl_with_datamodel_problems.py index 2831bb67ec67f8c2b19519ef5457829712669a6e..61fec39026a1a3480ecc5b52551c712d7a459b08 100644 --- a/integrationtests/test_crawl_with_datamodel_problems.py +++ b/integrationtests/test_crawl_with_datamodel_problems.py @@ -34,6 +34,8 @@ from caosadvancedtools.models.parser import parse_model_from_yaml from caosadvancedtools.scifolder import (AnalysisCFood, ExperimentCFood, PublicationCFood, SimulationCFood) +from insert_model import main as insert_model + def setup_module(): """Clear problems and remove all entities except for built-in ones.""" @@ -67,8 +69,7 @@ def test_crawler_with_data_model_problems(): prefix="", dryrun=False, forceAllowSymlinks=False) # load and damage the model - model = parse_model_from_yaml("model.yml") - model.sync_data_model(noquestion=True) + insert_model() deleted_entities = {"Experiment", "Poster", "results"} for ent in deleted_entities: diff --git a/src/doc/yaml_interface.rst b/src/doc/yaml_interface.rst index 06248f2b5c17f40b6f15f5f55664c5a4a5530a86..dcf4c5d6c7a674bd8d32d92df0a509e511af26f5 100644 --- a/src/doc/yaml_interface.rst +++ b/src/doc/yaml_interface.rst @@ -39,6 +39,9 @@ Let's start with an example taken from https://gitlab.indiscale.com/caosdb/src/c table: datatype: FILE description: 'A table document associated with this recording' + extern: + - Textfile + This example defines 3 ``RecordType``s: @@ -46,6 +49,9 @@ This example defines 3 ``RecordType``s: - A ``Project`` with one obligatory property ``datatype`` - A Person with a ``firstName`` and a ``lastName`` (as recommended properties) - A ``LabbookEntry`` with multiple recommended properties of different data types +- It is assumed that the server knows a RecordType or Property with the name + "Textfile". + One major advantage of using this interface (in contrast to the standard python interface) is that properties can be defined and added to record types "on-the-fly". E.g. the three lines for ``firstName`` as sub entries of ``Person`` have two effects on CaosDB: @@ -60,6 +66,8 @@ Note the difference between the three property declarations of ``LabbookEntry``: - ``responsible``: This defines and adds a property with name "responsible" to ``LabbookEntry`, which has a datatype ``Person``. ``Person`` is defined above. - ``firstName``: This defines and adds a property with the standard data type ``TEXT`` to record type ``Person``. +If the data model depends on already existing parts, those can be added using the ``extern`` keyword. + Datatypes ---------