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
fix: catch network interruptions during onto creation (DEV-1073) #210
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,10 +35,10 @@ The following options are available: | |
- `-s` | `--server` _server_: URL of the DSP server (default: 0.0.0.0:3333) | ||
- `-u` | `--user` _username_: username used for authentication with the DSP API (default: root@example.com) | ||
- `-p` | `--password` _password_: password used for authentication with the DSP API (default: test) | ||
- `-V` | `--validate`: If set, only the validation of the JSON file is performed. | ||
- `-l` | `--lists`: If set, only the lists are created using a [simplified schema](./dsp-tools-create.md#lists). Please | ||
note that in this case the project must already exist. | ||
- `-v` | `--verbose`: If set, some information about the progress is printed to the console. | ||
- `-V` | `--validate-only`: If set, only the validation of the JSON file is performed. | ||
- `-l` | `--lists-only`: If set, only the lists are created. Please note that in this case the project must already exist. | ||
- `-v` | `--verbose`: If set, more information about the progress is printed to the console. | ||
- `-d` | `--dump`: If set, dump test files for DSP-API requests. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This option already existed in the code, but was not documented |
||
|
||
The command is used to read the definition of a data model (provided in a JSON file) and create it on the DSP server. | ||
The following example shows how to load the ontology defined in `data_model_definition.json` onto the DSP | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,9 @@ | |
from knora.dsplib.utils.excel_to_json_resources import resources_excel2json | ||
from knora.dsplib.utils.id_to_iri import id_to_iri | ||
from knora.dsplib.utils.onto_create_lists import create_lists | ||
from knora.dsplib.utils.onto_create_ontology import create_ontology | ||
from knora.dsplib.utils.onto_create_ontology import create_project | ||
from knora.dsplib.utils.onto_get import get_ontology | ||
from knora.dsplib.utils.onto_validate import validate_ontology | ||
from knora.dsplib.utils.onto_validate import validate_project | ||
from knora.dsplib.utils.xml_upload import xml_upload | ||
|
||
|
||
|
@@ -55,12 +55,10 @@ def program(user_args: list[str]) -> None: | |
parser_create.add_argument('-s', '--server', type=str, default=default_localhost, help=url_text) | ||
parser_create.add_argument('-u', '--user', default=default_user, help=username_text) | ||
parser_create.add_argument('-p', '--password', default=default_pw, help=password_text) | ||
parser_create.add_argument('-V', '--validate', action='store_true', | ||
parser_create.add_argument('-V', '--validate-only', action='store_true', | ||
help='Do only validation of JSON, no upload of the ' | ||
'ontology') | ||
parser_create.add_argument('-L', '--listfile', type=str, default='lists-only.json', | ||
help='Name of list node informationfile') | ||
parser_create.add_argument('-l', '--lists', action='store_true', help='Upload only the list(s)') | ||
parser_create.add_argument('-l', '--lists-only', action='store_true', help='Upload only the list(s)') | ||
parser_create.add_argument('-v', '--verbose', action='store_true', help=verbose_text) | ||
parser_create.add_argument('-d', '--dump', action='store_true', help='dump test files for DSP-API requests') | ||
parser_create.add_argument('datamodelfile', help='path to data model file') | ||
|
@@ -142,31 +140,27 @@ def program(user_args: list[str]) -> None: | |
exit(0) | ||
|
||
if args.action == 'create': | ||
if args.lists: | ||
if args.validate: | ||
if args.lists_only: | ||
if args.validate_only: | ||
validate_list_with_schema(args.datamodelfile) | ||
else: | ||
create_lists(input_file=args.datamodelfile, | ||
lists_file=args.listfile, | ||
server=args.server, | ||
user=args.user, | ||
password=args.password, | ||
verbose=args.verbose, | ||
dump=args.dump) | ||
else: | ||
if args.validate: | ||
if validate_ontology(args.datamodelfile): | ||
if args.validate_only: | ||
if validate_project(args.datamodelfile): | ||
print('Data model is syntactically correct and passed validation.') | ||
exit(0) | ||
else: | ||
exit(1) | ||
Comment on lines
+154
to
-161
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The behaviour of |
||
else: | ||
create_ontology(input_file=args.datamodelfile, | ||
lists_file=args.listfile, | ||
server=args.server, | ||
user_mail=args.user, | ||
password=args.password, | ||
verbose=args.verbose, | ||
dump=args.dump if args.dump else False) | ||
create_project(input_file=args.datamodelfile, | ||
server=args.server, | ||
user_mail=args.user, | ||
password=args.password, | ||
verbose=args.verbose, | ||
dump=args.dump if args.dump else False) | ||
elif args.action == 'get': | ||
get_ontology(project_identifier=args.project, | ||
outfile=args.datamodelfile, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,23 +240,18 @@ def delete(self): | |
return Group.fromJsonObj(self._con, result['group']) | ||
|
||
@staticmethod | ||
def getAllGroups(con: Connection) -> Optional[list[Group]]: | ||
try: | ||
result = con.get(Group.ROUTE) | ||
return [Group.fromJsonObj(con, group_item) for group_item in result["groups"]] | ||
except BaseError: | ||
# return None if no groups are found or an error happened | ||
return None | ||
Comment on lines
-247
to
-249
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want the error to escalate, so that I can handle it in the higher-level methods |
||
def getAllGroups(con: Connection) -> list[Group]: | ||
result = con.get(Group.ROUTE) | ||
return [Group.fromJsonObj(con, group_item) for group_item in result["groups"]] | ||
|
||
@staticmethod | ||
def getAllGroupsForProject(con: Connection, proj_shortcode: str) -> Optional[list[Group]]: | ||
all_groups: Optional[list[Group]] = Group.getAllGroups(con) | ||
if all_groups: | ||
project_groups = [] | ||
for group in all_groups: | ||
if group.project == "http://rdfh.ch/projects/" + proj_shortcode: | ||
project_groups.append(group) | ||
return project_groups | ||
all_groups = Group.getAllGroups(con) | ||
project_groups = [] | ||
for group in all_groups: | ||
if group.project == "http://rdfh.ch/projects/" + proj_shortcode: | ||
project_groups.append(group) | ||
return project_groups | ||
|
||
def createDefinitionFileObj(self): | ||
group = { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small change to make it more clear