Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add push to openbis to update masterdata in openBIS #13

Open
9 tasks
Tracked by #11
JosePizarro3 opened this issue Dec 10, 2024 · 3 comments · May be fixed by #47
Open
9 tasks
Tracked by #11

Add push to openbis to update masterdata in openBIS #13

JosePizarro3 opened this issue Dec 10, 2024 · 3 comments · May be fixed by #47
Assignees
Labels
schema Masterdata schema template defined in openBIS

Comments

@JosePizarro3
Copy link
Contributor

JosePizarro3 commented Dec 10, 2024

We need to create a script to check and update the datamodel in the openBIS instance.

We could use the pyBIS methods new_... to create new object types/property types/vocabulary types if these do not exist in the instance. For this, the masterdata_checker is necessary.

@carlosmada22

TODO:

  • Create CLI push_to_openbis which accepts:
    • --excel-file (same behavior as in import-from-excel):
    • --python-path
      • individual Python modules
      • directory with all Python modules to be checked
  • Applies checker
  • For each entity, uses _log_msgs:
    • If checker has been successful (no critical, error, warning), creates or updates entity in openBIS
    • Else: logger.info("The checking of the entity type {cls_name} did not pass. Please, check your entity definitions.
@JosePizarro3
Copy link
Contributor Author

This is part of #11

@JosePizarro3 JosePizarro3 added the schema Masterdata schema template defined in openBIS label Dec 18, 2024
@JosePizarro3 JosePizarro3 changed the title Update data model in openBIS instance Add push to openbis to update masterdata in openBIS Dec 18, 2024
@JosePizarro3 JosePizarro3 self-assigned this Dec 18, 2024
@JosePizarro3
Copy link
Contributor Author

JosePizarro3 commented Jan 9, 2025

@carlosmada22 I am not 100% sure we can export the Python directly into openBIS. The methods new_xxx_type() are related with parsing, not with defining entities in the schema.

Ok, I saw the documentation: https://openbis.readthedocs.io/en/latest/software-developer-documentation/apis/python-v3-api.html#create-sample-types-object-types
It is indeed possible by just simply doing save() at the end.

@JosePizarro3
Copy link
Contributor Author

A small snippet for something that works creating entities and assigning properties:

from datetime import datetime

o = ologin()
code = "TEST_OBJECT_FROM_PYTHON"
objects_obis = [
    entity.get("code") for entity in o.get_object_types().df.to_dict(orient="records")
]
if code in objects_obis:
    obj = o.get_object_type(code)
    obj.description = f"New description changed at <<{datetime.now()}>> Testing object creation from pybis"
else:
    obj = o.new_object_type(
        code=code,
        description=f"<<{datetime.now()}>> Testing object creation from pybis",
        generatedCodePrefix="TEST2025JAN",
        autoGeneratedCode=True,
        validationPlugin="",
    )
obj.save()

## Assign properties to the object
properties_obis = [
    entity.get("code") for entity in o.get_property_types().df.to_dict(orient="records")
]
code_prop_1 = "$NAME"
if code_prop_1 in properties_obis:
    obj.assign_property(
        prop="$NAME",
        section="General information",
        mandatory=True,
        showInEditView=True,
    )
else:
    prop = o.new_property_type(
        code=code_prop_1,
        description="Name",
        dataType="VARCHAR",
        label="Name",
    )
    prop.save()
    obj.assign_property(
        prop="$NAME",
        section="General information",
        mandatory=True,
        showInEditView=True,
    )
code_prop_2 = "CHEMICAL"
if code_prop_2 in properties_obis:
    obj.assign_property(
        prop="CHEMICAL",
        section="General information",
        mandatory=True,
        showInEditView=True,
    )
else:
    prop = o.new_property_type(
        code=code_prop_2,
        description="Chemical",
        dataType="SAMPLE",
        label="Chemical",
    )
    prop.save()
    obj.assign_property(
        prop="CHEMICAL",
        section="General information",
        mandatory=True,
        showInEditView=True,
    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
schema Masterdata schema template defined in openBIS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant