diff --git a/schema/openapi3_0.yaml b/schema/openapi3_0.yaml index 91f0e7bf9134354b451a78d2583f435650c41630..6965381280593f78196b301f4c5da738c01d7ea5 100644 --- a/schema/openapi3_0.yaml +++ b/schema/openapi3_0.yaml @@ -769,7 +769,10 @@ components: - type: object properties: dataset: - $ref: '#/components/schemas/ScpsUrbandatasetSchema20' + anyOf: + - $ref: '#/components/schemas/ScpsUrbandatasetSchema20' + - type: object + properties: {} required: - dataset securitySchemes: diff --git a/scp_udg_client_app/commands/fetch.py b/scp_udg_client_app/commands/fetch.py index c1bc89ee7230b4747173c552e0dc629dcb8a5bb3..ee9eeeb2447a16b7d48f2bcc4d41587295ddcae5 100755 --- a/scp_udg_client_app/commands/fetch.py +++ b/scp_udg_client_app/commands/fetch.py @@ -23,7 +23,7 @@ def fetch_and_save_datasets(api_client, request, resource_id, inbox_dir): for dataset in response.dataset: save_dataset(dataset, resource_id, inbox_dir) else: - logger.warning("Dataset non trovati!") + logger.warning(response.to_str()) @click.command() @@ -32,7 +32,7 @@ def fetch_and_save_datasets(api_client, request, resource_id, inbox_dir): help="Read configuration from a Java .properties FILE.") @click.option('--udg-endpoint', type=UrlParamType(may_have_port=True), default=Configuration().host, show_default=True, help="URL endpoint for the Urban Dataset Gateway API.") -@click.option('--resource-id', prompt=True, prompt_required=False, callback=validate_resource_id) +@click.option('--resource-id', prompt=True, prompt_required=False, callback=validate_resource_id, show_default=True) @click.option('--username', 'user_name') @click.option('--password', 'user_password') @click.option('--access-token', hidden=True, prompt=True, prompt_required=False) @@ -53,7 +53,7 @@ def fetch(ctx, udg_endpoint, resource_id, access_token, user_name, user_password """Fetch and save datasets from an UDG endpoint.""" api_client = create_api_client_instance(udg_endpoint, access_token) - if not active_login(api_client, user_name, user_password): + if user_name and not active_login(api_client, user_name, user_password): logger.warning("Login fallito!") return diff --git a/scp_udg_client_app/commands/fetch_last.py b/scp_udg_client_app/commands/fetch_last.py index fb19c25943a33c97337d2dac801af78686655187..f9cdb098b855d96b9108e3da5dc0c7ecec4ede86 100755 --- a/scp_udg_client_app/commands/fetch_last.py +++ b/scp_udg_client_app/commands/fetch_last.py @@ -12,6 +12,9 @@ from scp_udg_client_app.helpers import create_api_client_instance, active_login, # Setting up Logger logger = logging.getLogger() +# Introduce constant +RESPONSE_CODE_SUCCESS = "03" + @click.command() @click_config_file.configuration_option(cmd_name="scp-udg-client", provider=javaproperties_provider, @@ -19,16 +22,17 @@ logger = logging.getLogger() help="Read configuration from a Java .properties FILE.") @click.option('--udg-endpoint', type=UrlParamType(may_have_port=True), default=Configuration().host, show_default=True, help="URL endpoint for the Urban Dataset Gateway API.") -@click.option('--resource-id', prompt=True, prompt_required=False, callback=validate_resource_id) +@click.option('--resource-id', prompt=True, prompt_required=False, callback=validate_resource_id, show_default=True) @click.option('--username', 'user_name') @click.option('--password', 'user_password') @click.option('--access-token', hidden=True, prompt=True, prompt_required=False) @click.option('--inbox-dir', type=click.Path(resolve_path=True, file_okay=False), default="Inbox", show_default=True) +@click.pass_context def fetch_last(ctx, udg_endpoint, resource_id, access_token, user_name, user_password, inbox_dir): """Fetch and save the last dataset from an UDG endpoint.""" api_client = create_api_client_instance(udg_endpoint, access_token) - if not active_login(api_client, user_name, user_password): + if user_name and not active_login(api_client, user_name, user_password): logger.warning("Login fallito!") return @@ -40,10 +44,10 @@ def fetch_last(ctx, udg_endpoint, resource_id, access_token, user_name, user_pas def process_response(response, resource_id, inbox_dir): - if response.code == "03": - save_dataset(response.dataset, resource_id, inbox_dir) + if response.code == RESPONSE_CODE_SUCCESS: + save_dataset(response.dataset.actual_instance, resource_id, inbox_dir) else: - logger.warning("Dataset non trovato!") + logger.warning(response.to_json()) if __name__ == '__main__':