Skip to content
Snippets Groups Projects
Commit 18c02891 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

Treat dependencies among identifiables

parent bfa5a598
Branches
Tags
2 merge requests!22Release 0.3,!7Treat dependencies among identifiables
...@@ -30,6 +30,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -30,6 +30,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### ### Changed ###
- identifiables of single CFoods are now treated one after the other. This
allows them to have dependencies among each other if they are ordered
correctly
- identifiables must have at least one property or a name - identifiables must have at least one property or a name
* `caosadvancedtools.serverside.helper.init_data_model` also checks the role * `caosadvancedtools.serverside.helper.init_data_model` also checks the role
and data type of entities. and data type of entities.
......
---
responsible:
- Tom Wood
description: Something.
...
...@@ -7,4 +7,5 @@ python3 -m caosadvancedtools.loadFiles /opt/caosdb/mnt/extroot/SimulationData ...@@ -7,4 +7,5 @@ python3 -m caosadvancedtools.loadFiles /opt/caosdb/mnt/extroot/SimulationData
python3 -m caosadvancedtools.loadFiles /opt/caosdb/mnt/extroot/Publications python3 -m caosadvancedtools.loadFiles /opt/caosdb/mnt/extroot/Publications
python3 -m caosadvancedtools.loadFiles /opt/caosdb/mnt/extroot/Software python3 -m caosadvancedtools.loadFiles /opt/caosdb/mnt/extroot/Software
python3 insert_model.py python3 insert_model.py
python3 insert_some.py
python3 crawl.py / python3 crawl.py /
#!/usr/bin/env python3
import caosdb as db
from caosadvancedtools.scifolder.experiment_cfood import dm
# This inserts two identifiables. When no dependencies are possible among
# identifiables, it should not be possible to find both: the experiment
# identifiable would for example not reference the correct project Record
project = db.Record(name='2010_TestProject')
project.add_parent(name=dm.Project)
project.insert()
pers = db.Record()
pers.add_parent("Person")
pers.add_property("lastname", "Wood")
pers.add_property("firstname", "Tom")
pers.insert()
experiment = db.Record()
experiment.add_parent(name=dm.Experiment)
experiment.description = "Something."
experiment.add_property(
name=dm.date, value='2019-02-04')
experiment.add_property(name=dm.Project, value=project)
experiment.add_property(
name="identifier", value="empty_identifier")
experiment.add_property(
name="responsible", value=pers)
experiment.insert(flags={"force-missing-obligatory": "ignore"})
...@@ -3,6 +3,7 @@ OUT=/tmp/crawler.output ...@@ -3,6 +3,7 @@ OUT=/tmp/crawler.output
ls ls
cat pycaosdb.ini cat pycaosdb.ini
rm -rf cache.db rm -rf cache.db
set -e
echo "Clearing database" echo "Clearing database"
python3 clear_database.py python3 clear_database.py
echo "Testing crawler without cfoods" echo "Testing crawler without cfoods"
...@@ -29,7 +30,6 @@ echo "run crawler" ...@@ -29,7 +30,6 @@ echo "run crawler"
# rename the moved file # rename the moved file
mv extroot/DataAnalysis/2010_TestProject/2019-02-03_something/README.xlsx_back extroot/DataAnalysis/2010_TestProject/2019-02-03_something/README.xlsx mv extroot/DataAnalysis/2010_TestProject/2019-02-03_something/README.xlsx_back extroot/DataAnalysis/2010_TestProject/2019-02-03_something/README.xlsx
# check whether there was something UNAUTHORIZED # check whether there was something UNAUTHORIZED
set -e
grep "There where unauthorized changes" $OUT grep "There where unauthorized changes" $OUT
# get the id of the run which is the last field of the output string # get the id of the run which is the last field of the output string
RUN_ID=$(grep "run id:" $OUT | awk '{ print $NF }') RUN_ID=$(grep "run id:" $OUT | awk '{ print $NF }')
......
...@@ -34,6 +34,14 @@ def get_entity_with_id(eid): ...@@ -34,6 +34,14 @@ def get_entity_with_id(eid):
class CrawlerTest(unittest.TestCase): class CrawlerTest(unittest.TestCase):
def test_experiment(self): def test_experiment(self):
########################
# # dummy for dependency test experiment # #
########################
exp = db.execute_query(
"FIND Experiment with date=2019-02-04 and identifier=empty_identifier",
unique=True)
######################## ########################
# # first experiment # # # # first experiment # #
######################## ########################
......
...@@ -576,44 +576,51 @@ carefully and if the changes are ok, click on the following link: ...@@ -576,44 +576,51 @@ carefully and if the changes are ok, click on the following link:
# looking for matching entities in CaosDB when there is no valid id # looking for matching entities in CaosDB when there is no valid id
# i.e. there was none set from a cache # i.e. there was none set from a cache
existing = []
inserted = []
for ent in identifiables: for ent in identifiables:
if ent.id is None or ent.id < 0: if ent.id is None or ent.id < 0:
logger.debug("Looking for: {}".format( logger.debug("Looking for: {}".format(
ent.id if ent.id is not None else ent.name)) ent.id if ent.id is not None else ent.name))
existing = Crawler.find_existing(ent) found = Crawler.find_existing(ent)
if existing is not None: if found is not None:
ent.id = existing.id ent.id = found.id
else: else:
logger.debug("Id is known of: {}".format(ent)) logger.debug("Id is known of: {}".format(ent))
# insert missing, i.e. those which are not valid # insert missing, i.e. those which are not valid
missing_identifiables = db.Container() if ent.id is None or ent.id < 0:
missing_identifiables.extend([ent for ent in identifiables missing = ent
if ent.id is None or ent.id < 0])
# TODO the following should not be necessary. Fix it
for ent in missing_identifiables:
ent.id = None ent.id = None
else:
missing = None
existing.append(ent)
if len(missing_identifiables) > 0: if missing:
info = "Going to insert the following entities:\n" try:
guard.safe_insert(missing, unique=False,
flags={"force-missing-obligatory": "ignore"})
inserted.append(ent)
except Exception as e:
DataModelProblems.evaluate_exception(e)
if len(existing) > 0:
info = "Identified the following existing entities:\n"
for ent in missing_identifiables: for ent in existing:
info += str(ent)+"\n" info += str(ent)+"\n"
logger.debug(info) logger.debug(info)
else:
logger.debug("Did not identify any existing entities")
if len(inserted) > 0:
info = "Inserted the following entities:\n"
if len(missing_identifiables) == 0: for ent in inserted:
logger.debug("No new entities to be inserted.") info += str(ent)+"\n"
logger.debug(info)
else: else:
try: logger.debug("Did not insert any new entities")
logger.info(
"Inserting {} Records...".format(
len(missing_identifiables)))
guard.safe_insert(missing_identifiables, unique=False,
flags={"force-missing-obligatory": "ignore"})
except Exception as e:
DataModelProblems.evaluate_exception(e)
logger.debug("Retrieving entities from CaosDB...") logger.debug("Retrieving entities from CaosDB...")
identifiables.retrieve(unique=True, raise_exception_on_error=False) identifiables.retrieve(unique=True, raise_exception_on_error=False)
......
...@@ -78,7 +78,7 @@ class ExperimentCFood(AbstractFileCFood, WithREADME): ...@@ -78,7 +78,7 @@ class ExperimentCFood(AbstractFileCFood, WithREADME):
self.experiment, self.project = ( self.experiment, self.project = (
ExperimentCFood.create_identifiable_experiment(self.match)) ExperimentCFood.create_identifiable_experiment(self.match))
self.identifiables.extend([self.experiment, self.project]) self.identifiables.extend([self.project, self.experiment])
self.people = parse_responsibles(self.header) self.people = parse_responsibles(self.header)
self.identifiables.extend(self.people) self.identifiables.extend(self.people)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment