From b2521f65d9b9aa57c47a5c12a3bb93b5ffec52b1 Mon Sep 17 00:00:00 2001 From: kmika11 Date: Wed, 24 Jul 2024 12:02:28 -0400 Subject: [PATCH 01/12] Update models.py added astrophysics metadata block to Dataset() class --- pyDataverse/models.py | 161 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 160 insertions(+), 1 deletion(-) diff --git a/pyDataverse/models.py b/pyDataverse/models.py index 2a835e2..9921361 100644 --- a/pyDataverse/models.py +++ b/pyDataverse/models.py @@ -446,6 +446,32 @@ class Dataset(DVObject): __attr_import_dv_up_journal_fields_arrays = { "journalVolumeIssue": ["journalVolume", "journalIssue", "journalPubDate"] } + + __attr_import_dv_up_astrophysics_fields_values = [ + "astroType", + "astroFacility", + "astroInstrumnet", + "astroObject", + "resolution.Spatial", + "resolution.Temporal", + "coverage.Spectral.Bandpass", + "coverage.Spectral.CentralWavelength", + "coverage.Spatial", + "coverage.Depth", + "coverage.ObjectDensity", + "coverage.ObjectCount", + "coverage.SkyFraction", + "coverage.Polarization", + "redshiftType", + "resolution.Redshift" + ] + + __attr_import_dv_up_astrophysics_fields_arrays ={ + "coverage.Spectral.Wavelength": ["coverage.Spectral.MinimumWavelength", "coverage.Spectral.MaximumWavelength"], + "coverage.Temporal": ["coverage.Temporal.StartTime", "coverage.Temporal.StopTime"], + "coverage.RedshiftValue": ["coverage.Redshift.MinimumValue", "coverage.Redshift.MaximumValue"] + + } __attr_dict_dv_up_required = [ "author", "datasetContact", @@ -461,9 +487,21 @@ class Dataset(DVObject): "authorAffiliation", "authorIdentifier", "authorName", + "astroType", + "astroFacility", + "astroInstrumnet", + "astroObject", "characteristicOfSources", "city", "contributorName", + "coverage.Spectral.Bandpass", + "coverage.Spectral.CentralWavelength", + "coverage.Spatial", + "coverage.Depth", + "coverage.ObjectDensity", + "coverage.ObjectCount", + "coverage.SkyFraction", + "coverage.Polarization", "dateOfDeposit", "dataSources", "depositor", @@ -480,6 +518,10 @@ class Dataset(DVObject): "publicationURL", "relatedDatasets", "relatedMaterial", + "resolution.Spatial", + "resolution.Temporal", + "redshiftType", + "resolution.Redshift" "seriesInformation", "seriesName", "state", @@ -501,6 +543,9 @@ class Dataset(DVObject): + __attr_import_dv_up_geospatial_fields_arrays["geographicBoundingBox"] + __attr_import_dv_up_socialscience_fields_values + __attr_import_dv_up_journal_fields_arrays["journalVolumeIssue"] + + __attr_import_dv_up_astrophysics_fields_arrays['coverage.Temporal'] + + __attr_import_dv_up_astrophysics_fields_arrays['coverage.Spectral'] + + __attr_import_dv_up_astrophysics_fields_arrays['coverage.RedshiftValue'] + [ "socialScienceNotesType", "socialScienceNotesSubject", @@ -512,10 +557,12 @@ class Dataset(DVObject): list(__attr_import_dv_up_citation_fields_arrays.keys()) + list(__attr_import_dv_up_geospatial_fields_arrays.keys()) + list(__attr_import_dv_up_journal_fields_arrays.keys()) + + list(__attr_import_dv_up_astrophysics_fields_arrays.keys()) + ["series", "socialScienceNotes", "targetSampleSize"] ) __attr_dict_dv_up_type_class_controlled_vocabulary = [ "authorIdentifierScheme", + "astroType" "contributorType", "country", "journalArticleType", @@ -529,6 +576,7 @@ class Dataset(DVObject): "geospatial_displayName", "socialscience_displayName", "journal_displayName", + "astrophysics_displayName" ] def __init__(self, data=None): @@ -637,7 +685,27 @@ def __init__(self, data=None): "journal_displayName", "journalVolumeIssue", "journalArticleType", - ] + "astrophysics_displayName" + "astroType", + "astroFacility", + "astroInstrumnet", + "astroObject", + "resolution.Spatial", + "resolution.Temporal", + "coverage.Spectral.Bandpass", + "coverage.Spectral.CentralWavelength", + "coverage.Spatial", + "coverage.Depth", + "coverage.ObjectDensity", + "coverage.ObjectCount", + "coverage.SkyFraction", + "coverage.Polarization", + "redshiftType", + "resolution.Redshift" + "coverage.Spectral.Wavelength", + "coverage.Temporal", + "coverage.RedshiftValue" + ] def validate_json(self, filename_schema=None): """Validate JSON formats of Dataset. @@ -1032,6 +1100,40 @@ def from_json( else: # TODO: Exception pass + + #astrophysics + if "astrophysics" in json_dict["datasetVersion"]["metadataBlocks"]: + astrophysics = json_dict["datasetVersion"]["metadataBlocks"]["astrophysics"] + + if "displayName" in astrophysics: + self.__setattr__("astrophysics_displayName", astrophysics["displayName"]) + + for field in astrophysics["fields"]: + if ( + field["typeName"] + in self.__attr_import_dv_up_astrophysics_fields_values + ): + data[field["typeName"]] = field["value"] + elif ( + field["typeName"] + in self.__attr_import_dv_up_astrophysics_fields_arrays + ): + data[field["typeName"]] = self.__parse_field_array( + field["value"], + self.__attr_import_dv_up_astrophysics_fields_arrays[ + field["typeName"] + ], + ) + else: + print( + "Attribute {0} not valid for import (dv_up).".format( + field["typeName"] + ) + ) + else: + # TODO: Exception + pass + elif data_format == "dataverse_download": print("INFO: Not implemented yet.") elif data_format == "dspace": @@ -1475,6 +1577,61 @@ def json(self, data_format=None, validate=True, filename_schema=None): "value": self.__generate_field_arrays(key, val), } ) + + # astrophysics + for attr in ( + self.__attr_import_dv_up_astrophysics_fields_values + + list(self.__attr_import_dv_up_astrophysics_fields_arrays.keys()) + + ["astrophysics_displayName"] + ): + if attr in data_dict: + astrophysics = {} + if attr != "astrophysics_displayName": + astrophysics["fields"] = [] + break + + if "astrophysics_displayName" in data_dict: + astrophysics["displayName"] = data_dict["astrophysics_displayName"] + + # Generate first level attributes + for attr in self.__attr_import_dv_up_astrophysics_fields_values: + if attr in data_dict: + v = data_dict[attr] + if isinstance(v, list): + multiple = True + else: + multiple = False + if attr in self.__attr_dict_dv_up_type_class_primitive: + type_class = "primitive" + elif attr in self.__attr_dict_dv_up_type_class_compound: + type_class = "compound" + elif ( + attr in self.__attr_dict_dv_up_type_class_controlled_vocabulary + ): + type_class = "controlledVocabulary" + astrophysics["fields"].append( + { + "typeName": attr, + "multiple": multiple, + "typeClass": type_class, + "value": v, + } + ) + + # Generate fields attributes + for ( + key, + val, + ) in self.__attr_import_dv_up_astrophysics_fields_arrays.items(): + if key in data_dict: + astrophysics["fields"].append( + { + "typeName": key, + "multiple": True, + "typeClass": "compound", + "value": self.__generate_field_arrays(key, val), + } + ) data["datasetVersion"]["metadataBlocks"]["citation"] = citation if "socialscience" in locals(): @@ -1485,6 +1642,8 @@ def json(self, data_format=None, validate=True, filename_schema=None): data["datasetVersion"]["metadataBlocks"]["geospatial"] = geospatial if "journal" in locals(): data["datasetVersion"]["metadataBlocks"]["journal"] = journal + if "astrophysics" in locals(): + data["datasetVersion"]["metadataBlocks"]["astrophysics"] = astrophysics elif data_format == "dspace": data = None print("INFO: Not implemented yet.") From 1e9f7dbfb140d95b162820bb5d0265b38e58e645 Mon Sep 17 00:00:00 2001 From: kmika11 Date: Thu, 25 Jul 2024 14:34:45 -0400 Subject: [PATCH 02/12] Update dataset_upload_default_schema.json updated dataset_uploade_default_schema.json with astro metadata fields --- .../json/dataset_upload_default_schema.json | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/pyDataverse/schemas/json/dataset_upload_default_schema.json b/pyDataverse/schemas/json/dataset_upload_default_schema.json index 398e51e..5d63dd3 100644 --- a/pyDataverse/schemas/json/dataset_upload_default_schema.json +++ b/pyDataverse/schemas/json/dataset_upload_default_schema.json @@ -431,6 +431,124 @@ } } } + }, + "astrophysics": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics", + "type": "object", + "properties": { + "displayName": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/displayName", + "type": "string" + }, + "fields": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields", + "type": "array", + "items": { + "anyOf": [ + { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0", + "type": "object", + "properties": { + "typeName": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/typeName", + "type": "string" + }, + "multiple": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/multiple", + "type": "boolean" + }, + "typeClass": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/typeClass", + "type": "string" + }, + "value": { + "anyOf": [ + { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value", + "type": "array" + }, + { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0", + "type": "object", + "properties": { + "coverage.Spectral.Wavelength": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength", + "type": "object", + "properties": { + "typeName": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/typeName", + "type": "string" + }, + "multiple": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/multiple", + "type": "boolean" + }, + "typeClass": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/typeClass", + "type": "string" + }, + "value": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/value", + "type": "string" + } + } + }, + "coverage.Temporal": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal", + "type": "object", + "properties": { + "typeName": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/typeName", + "type": "string" + }, + "multiple": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/multiple", + "type": "boolean" + }, + "typeClass": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/typeClass", + "type": "string" + }, + "value": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/value", + "type": "string" + } + } + }, + "coverage.RedshiftValue": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue", + "type": "object", + "properties": { + "typeName": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/typeName", + "type": "string" + }, + "multiple": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/multiple", + "type": "boolean" + }, + "typeClass": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/typeClass", + "type": "string" + }, + "value": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/value", + "type": "string" + } + } + } + } + } + ], + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items" + } + } + } + ], + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items" + } + } + } } } } @@ -438,3 +556,8 @@ } } } + + + + + From 65ad6dcc078ebd917434e9c21fc4e0890eba85d9 Mon Sep 17 00:00:00 2001 From: kmika11 Date: Thu, 25 Jul 2024 15:30:45 -0400 Subject: [PATCH 03/12] fixed typos in dataset_upload_default_schema.json --- .../json/dataset_upload_default_schema.json | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/pyDataverse/schemas/json/dataset_upload_default_schema.json b/pyDataverse/schemas/json/dataset_upload_default_schema.json index 5d63dd3..f706828 100644 --- a/pyDataverse/schemas/json/dataset_upload_default_schema.json +++ b/pyDataverse/schemas/json/dataset_upload_default_schema.json @@ -472,67 +472,67 @@ "type": "object", "properties": { "coverage.Spectral.Wavelength": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength", + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength", "type": "object", "properties": { "typeName": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/typeName", + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/typeName", "type": "string" }, "multiple": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/multiple", + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/multiple", "type": "boolean" }, "typeClass": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/typeClass", + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/typeClass", "type": "string" }, "value": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/value", + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/value", "type": "string" } } }, "coverage.Temporal": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal", + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal", "type": "object", "properties": { "typeName": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/typeName", + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/typeName", "type": "string" }, "multiple": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/multiple", + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/multiple", "type": "boolean" }, "typeClass": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/typeClass", + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/typeClass", "type": "string" - }, + }, "value": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/value", + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/value", "type": "string" } } }, "coverage.RedshiftValue": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue", + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue", "type": "object", "properties": { "typeName": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/typeName", + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/typeName", "type": "string" }, "multiple": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/multiple", + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/multiple", "type": "boolean" }, "typeClass": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/typeClass", + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/typeClass", "type": "string" }, "value": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/value", + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/value", "type": "string" } } @@ -561,3 +561,4 @@ + From f1d6ee50e4c68be0ee0463dc267743f9e2a6d2c7 Mon Sep 17 00:00:00 2001 From: kmika11 Date: Thu, 25 Jul 2024 16:37:56 -0400 Subject: [PATCH 04/12] fixed typos in models.py --- pyDataverse/models.py | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/pyDataverse/models.py b/pyDataverse/models.py index 9921361..6a2508c 100644 --- a/pyDataverse/models.py +++ b/pyDataverse/models.py @@ -466,11 +466,10 @@ class Dataset(DVObject): "resolution.Redshift" ] - __attr_import_dv_up_astrophysics_fields_arrays ={ + __attr_import_dv_up_astrophysics_fields_arrays = { "coverage.Spectral.Wavelength": ["coverage.Spectral.MinimumWavelength", "coverage.Spectral.MaximumWavelength"], "coverage.Temporal": ["coverage.Temporal.StartTime", "coverage.Temporal.StopTime"], "coverage.RedshiftValue": ["coverage.Redshift.MinimumValue", "coverage.Redshift.MaximumValue"] - } __attr_dict_dv_up_required = [ "author", @@ -543,9 +542,9 @@ class Dataset(DVObject): + __attr_import_dv_up_geospatial_fields_arrays["geographicBoundingBox"] + __attr_import_dv_up_socialscience_fields_values + __attr_import_dv_up_journal_fields_arrays["journalVolumeIssue"] - + __attr_import_dv_up_astrophysics_fields_arrays['coverage.Temporal'] - + __attr_import_dv_up_astrophysics_fields_arrays['coverage.Spectral'] - + __attr_import_dv_up_astrophysics_fields_arrays['coverage.RedshiftValue'] + + __attr_import_dv_up_astrophysics_fields_arrays["coverage.Temporal"] + + __attr_import_dv_up_astrophysics_fields_arrays["coverage.Spectral.Wavelength"] + + __attr_import_dv_up_astrophysics_fields_arrays["coverage.RedshiftValue"] + [ "socialScienceNotesType", "socialScienceNotesSubject", @@ -562,7 +561,7 @@ class Dataset(DVObject): ) __attr_dict_dv_up_type_class_controlled_vocabulary = [ "authorIdentifierScheme", - "astroType" + "astroType", "contributorType", "country", "journalArticleType", @@ -685,7 +684,7 @@ def __init__(self, data=None): "journal_displayName", "journalVolumeIssue", "journalArticleType", - "astrophysics_displayName" + "astrophysics_displayName", "astroType", "astroFacility", "astroInstrumnet", @@ -701,11 +700,11 @@ def __init__(self, data=None): "coverage.SkyFraction", "coverage.Polarization", "redshiftType", - "resolution.Redshift" + "resolution.Redshift", "coverage.Spectral.Wavelength", "coverage.Temporal", "coverage.RedshiftValue" - ] + ] def validate_json(self, filename_schema=None): """Validate JSON formats of Dataset. @@ -1103,33 +1102,34 @@ def from_json( #astrophysics if "astrophysics" in json_dict["datasetVersion"]["metadataBlocks"]: - astrophysics = json_dict["datasetVersion"]["metadataBlocks"]["astrophysics"] - - if "displayName" in astrophysics: - self.__setattr__("astrophysics_displayName", astrophysics["displayName"]) - + astrophysics = json_dict["datasetVersion"]["metadataBlocks"]["astrophysics"] + + if "displayName" in astrophysics: + self.__setattr__("astrophysics_displayName", astrophysics["displayName"]) + for field in astrophysics["fields"]: if ( field["typeName"] in self.__attr_import_dv_up_astrophysics_fields_values - ): + ): data[field["typeName"]] = field["value"] - elif ( - field["typeName"] - in self.__attr_import_dv_up_astrophysics_fields_arrays - ): + elif ( + field["typeName"] + in self.__attr_import_dv_up_astrophysics_fields_arrays + ): data[field["typeName"]] = self.__parse_field_array( field["value"], self.__attr_import_dv_up_astrophysics_fields_arrays[ field["typeName"] - ], + ], ) - else: + else: print( "Attribute {0} not valid for import (dv_up).".format( - field["typeName"] + field["typeName"] ) ) + else: # TODO: Exception pass From d85cd5de57df4087b910b1440ce423490f3202df Mon Sep 17 00:00:00 2001 From: kmika11 Date: Fri, 26 Jul 2024 13:41:31 -0400 Subject: [PATCH 05/12] fixed indentation errors in dataset_upload_default_schema.json --- .../json/dataset_upload_default_schema.json | 134 ++++++++---------- 1 file changed, 57 insertions(+), 77 deletions(-) diff --git a/pyDataverse/schemas/json/dataset_upload_default_schema.json b/pyDataverse/schemas/json/dataset_upload_default_schema.json index f706828..0f75582 100644 --- a/pyDataverse/schemas/json/dataset_upload_default_schema.json +++ b/pyDataverse/schemas/json/dataset_upload_default_schema.json @@ -465,79 +465,65 @@ "anyOf": [ { "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value", - "type": "array" - }, - { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0", - "type": "object", - "properties": { - "coverage.Spectral.Wavelength": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength", - "type": "object", - "properties": { - "typeName": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/typeName", - "type": "string" - }, - "multiple": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/multiple", - "type": "boolean" - }, - "typeClass": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/typeClass", - "type": "string" - }, - "value": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/value", - "type": "string" - } - } - }, - "coverage.Temporal": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal", - "type": "object", - "properties": { - "typeName": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/typeName", - "type": "string" - }, - "multiple": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/multiple", - "type": "boolean" - }, - "typeClass": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/typeClass", - "type": "string" - }, - "value": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/value", - "type": "string" - } - } - }, - "coverage.RedshiftValue": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue", - "type": "object", - "properties": { - "typeName": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/typeName", - "type": "string" - }, - "multiple": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/multiple", - "type": "boolean" - }, - "typeClass": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/typeClass", - "type": "string" - }, - "value": { - "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/value", - "type": "string" + "type": "array", + "items": { + "anyOf": [ + { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0", + "type": "object", + "properties":{ + "coverage.Spectral.Wavelength": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength", + "type": "object", + "properties": { + "typeName": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/typeName", + "type": "string" + }, + "multiple": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/multiple", + "type": "boolean" + }, + "typeClass": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/typeClass", + "type": "string" + }, + "value":{ + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Spectral.Wavelength/properties/value", + "type": "string" + } + } + }, + "coverage.Temporal": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal", + "type": "object", + "properties": { + "typeName": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/typeName", + "type": "string" + }, + "multiple": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/multiple", + "type": "boolean" + }, + "typeClass": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/typeClass", + "type": "string" + }, + "value":{ + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.Temporal/properties/value", + "type": "string" + } + } + } } } - } + ] } + }, + { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value", + "type": "string" } ], "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items" @@ -555,10 +541,4 @@ } } } -} - - - - - - +} \ No newline at end of file From b6a8a83cbb9bdaf920112b1edfa3730085fcd1ec Mon Sep 17 00:00:00 2001 From: kmika11 Date: Fri, 26 Jul 2024 15:26:14 -0400 Subject: [PATCH 06/12] left out a whole array in astrophysics block in dataset_upload_default_schema.json --- .../json/dataset_upload_default_schema.json | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pyDataverse/schemas/json/dataset_upload_default_schema.json b/pyDataverse/schemas/json/dataset_upload_default_schema.json index 0f75582..75eb4d6 100644 --- a/pyDataverse/schemas/json/dataset_upload_default_schema.json +++ b/pyDataverse/schemas/json/dataset_upload_default_schema.json @@ -515,6 +515,28 @@ "type": "string" } } + }, + "coverage.RedshiftValue": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue", + "type": "object", + "properties": { + "typeName": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/typeName", + "type": "string" + }, + "multiple": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/multiple", + "type": "boolean" + }, + "typeClass": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/typeClass", + "type": "string" + }, + "value": { + "$id": "#/properties/datasetVersion/properties/metadataBlocks/properties/astrophysics/properties/fields/items/anyOf/0/properties/value/items/anyOf/0/properties/coverage.RedshiftValue/properties/value", + "type": "string" + } + } } } } From d6363d03b0297b4355a54cd3909561233835f0f4 Mon Sep 17 00:00:00 2001 From: kmika11 Date: Fri, 26 Jul 2024 16:05:30 -0400 Subject: [PATCH 07/12] added None checks to json function in models.py --- pyDataverse/models.py | 532 +++++++++++++++++++----------------------- 1 file changed, 240 insertions(+), 292 deletions(-) diff --git a/pyDataverse/models.py b/pyDataverse/models.py index 6a2508c..214193d 100644 --- a/pyDataverse/models.py +++ b/pyDataverse/models.py @@ -320,6 +320,12 @@ class Dataset(DVObject): __attr_import_dv_up_journal_fields_arrays : dict Attributes of Dataverse API Upload Dataset JSON metadata standard inside [\'datasetVersion\'][\'metadataBlocks\'][\'journal\'][\'fields\']. + __attr_import_dv_up_astrophysics_fields_values : list + Attributes of Dataverse API Upload Dataset JSON metadata standard inside + [\'datasetVersion\'][\'metadataBlocks\'][\'astrophysics\'][\'fields\']. + __attr_import_dv_up_astrophysics_fields_arrays : dict + Attributes of Dataverse API Upload Dataset JSON metadata standard inside + [\'datasetVersion\'][\'metadataBlocks\'][\'astrophysics\'][\'fields\'] __attr_dict_dv_up_required :list Required attributes for valid `dv_up` metadata dict creation. __attr_dict_dv_up_type_class_primitive : list @@ -687,7 +693,7 @@ def __init__(self, data=None): "astrophysics_displayName", "astroType", "astroFacility", - "astroInstrumnet", + "astroInstrument", "astroObject", "resolution.Spatial", "resolution.Temporal", @@ -1113,7 +1119,7 @@ def from_json( in self.__attr_import_dv_up_astrophysics_fields_values ): data[field["typeName"]] = field["value"] - elif ( + elif( field["typeName"] in self.__attr_import_dv_up_astrophysics_fields_arrays ): @@ -1272,7 +1278,7 @@ def json(self, data_format=None, validate=True, filename_schema=None): # dataset # Generate first level attributes for attr in self.__attr_import_dv_up_datasetVersion_values: - if attr in data_dict: + if attr in data_dict and data_dict[attr] is not None: data["datasetVersion"][attr] = data_dict[attr] # citation @@ -1281,19 +1287,14 @@ def json(self, data_format=None, validate=True, filename_schema=None): # Generate first level attributes for attr in self.__attr_import_dv_up_citation_fields_values: - if attr in data_dict: + if attr in data_dict and data_dict[attr] is not None: v = data_dict[attr] - if isinstance(v, list): - multiple = True - else: - multiple = False + multiple = isinstance(v, list) if attr in self.__attr_dict_dv_up_type_class_primitive: type_class = "primitive" elif attr in self.__attr_dict_dv_up_type_class_compound: type_class = "compound" - elif ( - attr in self.__attr_dict_dv_up_type_class_controlled_vocabulary - ): + elif attr in self.__attr_dict_dv_up_type_class_controlled_vocabulary: type_class = "controlledVocabulary" citation["fields"].append( { @@ -1305,12 +1306,8 @@ def json(self, data_format=None, validate=True, filename_schema=None): ) # Generate fields attributes - for ( - key, - val, - ) in self.__attr_import_dv_up_citation_fields_arrays.items(): - if key in data_dict: - v = data_dict[key] + for key, val in self.__attr_import_dv_up_citation_fields_arrays.items(): + if key in data_dict and data_dict[key] is not None: citation["fields"].append( { "typeName": key, @@ -1324,325 +1321,275 @@ def json(self, data_format=None, validate=True, filename_schema=None): if "series" in data_dict: series = data_dict["series"] tmp_dict = {} - if "seriesName" in series: - if series["seriesName"] is not None: - tmp_dict["seriesName"] = {} - tmp_dict["seriesName"]["typeName"] = "seriesName" - tmp_dict["seriesName"]["multiple"] = False - tmp_dict["seriesName"]["typeClass"] = "primitive" - tmp_dict["seriesName"]["value"] = series["seriesName"] - if "seriesInformation" in series: - if series["seriesInformation"] is not None: - tmp_dict["seriesInformation"] = {} - tmp_dict["seriesInformation"]["typeName"] = "seriesInformation" - tmp_dict["seriesInformation"]["multiple"] = False - tmp_dict["seriesInformation"]["typeClass"] = "primitive" - tmp_dict["seriesInformation"]["value"] = series[ - "seriesInformation" - ] - citation["fields"].append( - { - "typeName": "series", + if "seriesName" in series and series["seriesName"] is not None: + tmp_dict["seriesName"] = { + "typeName": "seriesName", "multiple": False, - "typeClass": "compound", - "value": tmp_dict, + "typeClass": "primitive", + "value": series["seriesName"], } - ) + if "seriesInformation" in series and series["seriesInformation"] is not None: + tmp_dict["seriesInformation"] = { + "typeName": "seriesInformation", + "multiple": False, + "typeClass": "primitive", + "value": series["seriesInformation"], + } + if tmp_dict: + citation["fields"].append( + { + "typeName": "series", + "multiple": False, + "typeClass": "compound", + "value": tmp_dict, + } + ) # geospatial + geospatial = None for attr in ( self.__attr_import_dv_up_geospatial_fields_values + list(self.__attr_import_dv_up_geospatial_fields_arrays.keys()) + ["geospatial_displayName"] ): if attr in data_dict: - geospatial = {} - if attr != "geospatial_displayName": - geospatial["fields"] = [] - break - - if "geospatial_displayName" in data_dict: - geospatial["displayName"] = data_dict["geospatial_displayName"] - - # Generate first level attributes - for attr in self.__attr_import_dv_up_geospatial_fields_values: - if attr in data_dict: - v = data_dict[attr] - if isinstance(v, list): - multiple = True - else: - multiple = False - if attr in self.__attr_dict_dv_up_type_class_primitive: - type_class = "primitive" - elif attr in self.__attr_dict_dv_up_type_class_compound: - type_class = "compound" - elif ( - attr in self.__attr_dict_dv_up_type_class_controlled_vocabulary - ): - type_class = "controlledVocabulary" - geospatial["fields"].append( - { - "typeName": attr, - "multiple": multiple, - "typeClass": type_class, - "value": v, - } - ) + geospatial = {"fields": []} + break + + if geospatial is not None: + if "geospatial_displayName" in data_dict: + geospatial["displayName"] = data_dict["geospatial_displayName"] + + # Generate first level attributes + for attr in self.__attr_import_dv_up_geospatial_fields_values: + if attr in data_dict and data_dict[attr] is not None: + v = data_dict[attr] + multiple = isinstance(v, list) + if attr in self.__attr_dict_dv_up_type_class_primitive: + type_class = "primitive" + elif attr in self.__attr_dict_dv_up_type_class_compound: + type_class = "compound" + elif attr in self.__attr_dict_dv_up_type_class_controlled_vocabulary: + type_class = "controlledVocabulary" + geospatial["fields"].append( + { + "typeName": attr, + "multiple": multiple, + "typeClass": type_class, + "value": v, + } + ) - # Generate fields attributes - for ( - key, - val, - ) in self.__attr_import_dv_up_geospatial_fields_arrays.items(): - if key in data_dict: - geospatial["fields"].append( - { - "typeName": key, - "multiple": True, - "typeClass": "compound", - "value": self.__generate_field_arrays(key, val), - } - ) + # Generate fields attributes + for key, val in self.__attr_import_dv_up_geospatial_fields_arrays.items(): + if key in data_dict and data_dict[key] is not None: + geospatial["fields"].append( + { + "typeName": key, + "multiple": True, + "typeClass": "compound", + "value": self.__generate_field_arrays(key, val), + } + ) # socialscience + socialscience = None for attr in self.__attr_import_dv_up_socialscience_fields_values + [ "socialscience_displayName" ]: if attr in data_dict: - socialscience = {} - if attr != "socialscience_displayName": - socialscience["fields"] = [] - break - - if "socialscience_displayName" in data_dict: - socialscience["displayName"] = data_dict["socialscience_displayName"] + socialscience = {"fields": []} + break + + if socialscience is not None: + if "socialscience_displayName" in data_dict: + socialscience["displayName"] = data_dict["socialscience_displayName"] + + # Generate first level attributes + for attr in self.__attr_import_dv_up_socialscience_fields_values: + if attr in data_dict and data_dict[attr] is not None: + v = data_dict[attr] + multiple = isinstance(v, list) + if attr in self.__attr_dict_dv_up_type_class_primitive: + type_class = "primitive" + elif attr in self.__attr_dict_dv_up_type_class_compound: + type_class = "compound" + elif attr in self.__attr_dict_dv_up_type_class_controlled_vocabulary: + type_class = "controlledVocabulary" + socialscience["fields"].append( + { + "typeName": attr, + "multiple": multiple, + "typeClass": type_class, + "value": v, + } + ) - # Generate first level attributes - for attr in self.__attr_import_dv_up_socialscience_fields_values: - if attr in data_dict: - v = data_dict[attr] - if isinstance(v, list): - multiple = True - else: - multiple = False - if attr in self.__attr_dict_dv_up_type_class_primitive: - type_class = "primitive" - elif attr in self.__attr_dict_dv_up_type_class_compound: - type_class = "compound" - elif ( - attr in self.__attr_dict_dv_up_type_class_controlled_vocabulary - ): - type_class = "controlledVocabulary" - socialscience["fields"].append( - { - "typeName": attr, - "multiple": multiple, - "typeClass": type_class, - "value": v, + # Generate targetSampleSize attributes + if "targetSampleSize" in data_dict: + target_sample_size = data_dict["targetSampleSize"] + tmp_dict = {} + if "targetSampleActualSize" in target_sample_size and target_sample_size["targetSampleActualSize"] is not None: + tmp_dict["targetSampleActualSize"] = { + "typeName": "targetSampleActualSize", + "multiple": False, + "typeClass": "primitive", + "value": target_sample_size["targetSampleActualSize"], } - ) - - # Generate targetSampleSize attributes - if "targetSampleSize" in data_dict: - target_sample_size = data_dict["targetSampleSize"] - tmp_dict = {} - if "targetSampleActualSize" in target_sample_size: - if target_sample_size["targetSampleActualSize"] is not None: - tmp_dict["targetSampleActualSize"] = {} - tmp_dict["targetSampleActualSize"]["typeName"] = ( - "targetSampleActualSize" - ) - tmp_dict["targetSampleActualSize"]["multiple"] = False - tmp_dict["targetSampleActualSize"]["typeClass"] = "primitive" - tmp_dict["targetSampleActualSize"]["value"] = ( - target_sample_size["targetSampleActualSize"] - ) - if "targetSampleSizeFormula" in target_sample_size: - if target_sample_size["targetSampleSizeFormula"] is not None: - tmp_dict["targetSampleSizeFormula"] = {} - tmp_dict["targetSampleSizeFormula"]["typeName"] = ( - "targetSampleSizeFormula" - ) - tmp_dict["targetSampleSizeFormula"]["multiple"] = False - tmp_dict["targetSampleSizeFormula"]["typeClass"] = "primitive" - tmp_dict["targetSampleSizeFormula"]["value"] = ( - target_sample_size["targetSampleSizeFormula"] + if "targetSampleSizeFormula" in target_sample_size and target_sample_size["targetSampleSizeFormula"] is not None: + tmp_dict["targetSampleSizeFormula"] = { + "typeName": "targetSampleSizeFormula", + "multiple": False, + "typeClass": "primitive", + "value": target_sample_size["targetSampleSizeFormula"], + } + if tmp_dict: + socialscience["fields"].append( + { + "typeName": "targetSampleSize", + "multiple": False, + "typeClass": "compound", + "value": tmp_dict, + } ) - socialscience["fields"].append( - { - "typeName": "targetSampleSize", - "multiple": False, - "typeClass": "compound", - "value": tmp_dict, - } - ) - # Generate socialScienceNotes attributes - if "socialScienceNotes" in data_dict: - social_science_notes = data_dict["socialScienceNotes"] - tmp_dict = {} - if "socialScienceNotesType" in social_science_notes: - if social_science_notes["socialScienceNotesType"] is not None: - tmp_dict["socialScienceNotesType"] = {} - tmp_dict["socialScienceNotesType"]["typeName"] = ( - "socialScienceNotesType" - ) - tmp_dict["socialScienceNotesType"]["multiple"] = False - tmp_dict["socialScienceNotesType"]["typeClass"] = "primitive" - tmp_dict["socialScienceNotesType"]["value"] = ( - social_science_notes["socialScienceNotesType"] - ) - if "socialScienceNotesSubject" in social_science_notes: - if social_science_notes["socialScienceNotesSubject"] is not None: - tmp_dict["socialScienceNotesSubject"] = {} - tmp_dict["socialScienceNotesSubject"]["typeName"] = ( - "socialScienceNotesSubject" - ) - tmp_dict["socialScienceNotesSubject"]["multiple"] = False - tmp_dict["socialScienceNotesSubject"]["typeClass"] = "primitive" - tmp_dict["socialScienceNotesSubject"]["value"] = ( - social_science_notes["socialScienceNotesSubject"] - ) - if "socialScienceNotesText" in social_science_notes: - if social_science_notes["socialScienceNotesText"] is not None: - tmp_dict["socialScienceNotesText"] = {} - tmp_dict["socialScienceNotesText"]["typeName"] = ( - "socialScienceNotesText" - ) - tmp_dict["socialScienceNotesText"]["multiple"] = False - tmp_dict["socialScienceNotesText"]["typeClass"] = "primitive" - tmp_dict["socialScienceNotesText"]["value"] = ( - social_science_notes["socialScienceNotesText"] + # Generate socialScienceNotes attributes + if "socialScienceNotes" in data_dict: + social_science_notes = data_dict["socialScienceNotes"] + tmp_dict = {} + if "socialScienceNotesType" in social_science_notes and social_science_notes["socialScienceNotesType"] is not None: + tmp_dict["socialScienceNotesType"] = { + "typeName": "socialScienceNotesType", + "multiple": False, + "typeClass": "primitive", + "value": social_science_notes["socialScienceNotesType"], + } + if "socialScienceNotesSubject" in social_science_notes and social_science_notes["socialScienceNotesSubject"] is not None: + tmp_dict["socialScienceNotesSubject"] = { + "typeName": "socialScienceNotesSubject", + "multiple": False, + "typeClass": "primitive", + "value": social_science_notes["socialScienceNotesSubject"], + } + if "socialScienceNotesText" in social_science_notes and social_science_notes["socialScienceNotesText"] is not None: + tmp_dict["socialScienceNotesText"] = { + "typeName": "socialScienceNotesText", + "multiple": False, + "typeClass": "primitive", + "value": social_science_notes["socialScienceNotesText"], + } + if tmp_dict: + socialscience["fields"].append( + { + "typeName": "socialScienceNotes", + "multiple": False, + "typeClass": "compound", + "value": tmp_dict, + } ) - socialscience["fields"].append( - { - "typeName": "socialScienceNotes", - "multiple": False, - "typeClass": "compound", - "value": tmp_dict, - } - ) # journal + journal = None for attr in ( self.__attr_import_dv_up_journal_fields_values + list(self.__attr_import_dv_up_journal_fields_arrays.keys()) + ["journal_displayName"] ): if attr in data_dict: - journal = {} - if attr != "journal_displayName": - journal["fields"] = [] - break - - if "journal_displayName" in data_dict: - journal["displayName"] = data_dict["journal_displayName"] - - # Generate first level attributes - for attr in self.__attr_import_dv_up_journal_fields_values: - if attr in data_dict: - v = data_dict[attr] - if isinstance(v, list): - multiple = True - else: - multiple = False - if attr in self.__attr_dict_dv_up_type_class_primitive: - type_class = "primitive" - elif attr in self.__attr_dict_dv_up_type_class_compound: - type_class = "compound" - elif ( - attr in self.__attr_dict_dv_up_type_class_controlled_vocabulary - ): - type_class = "controlledVocabulary" - journal["fields"].append( - { - "typeName": attr, - "multiple": multiple, - "typeClass": type_class, - "value": v, - } - ) + journal = {"fields": []} + break + + if journal is not None: + if "journal_displayName" in data_dict: + journal["displayName"] = data_dict["journal_displayName"] + + # Generate first level attributes + for attr in self.__attr_import_dv_up_journal_fields_values: + if attr in data_dict and data_dict[attr] is not None: + v = data_dict[attr] + multiple = isinstance(v, list) + if attr in self.__attr_dict_dv_up_type_class_primitive: + type_class = "primitive" + elif attr in self.__attr_dict_dv_up_type_class_compound: + type_class = "compound" + elif attr in self.__attr_dict_dv_up_type_class_controlled_vocabulary: + type_class = "controlledVocabulary" + journal["fields"].append( + { + "typeName": attr, + "multiple": multiple, + "typeClass": type_class, + "value": v, + } + ) - # Generate fields attributes - for ( - key, - val, - ) in self.__attr_import_dv_up_journal_fields_arrays.items(): - if key in data_dict: - journal["fields"].append( - { - "typeName": key, - "multiple": True, - "typeClass": "compound", - "value": self.__generate_field_arrays(key, val), - } - ) + # Generate fields attributes + for key, val in self.__attr_import_dv_up_journal_fields_arrays.items(): + if key in data_dict and data_dict[key] is not None: + journal["fields"].append( + { + "typeName": key, + "multiple": True, + "typeClass": "compound", + "value": self.__generate_field_arrays(key, val), + } + ) # astrophysics + astrophysics = None for attr in ( self.__attr_import_dv_up_astrophysics_fields_values + list(self.__attr_import_dv_up_astrophysics_fields_arrays.keys()) + ["astrophysics_displayName"] ): if attr in data_dict: - astrophysics = {} - if attr != "astrophysics_displayName": - astrophysics["fields"] = [] - break - - if "astrophysics_displayName" in data_dict: - astrophysics["displayName"] = data_dict["astrophysics_displayName"] - - # Generate first level attributes - for attr in self.__attr_import_dv_up_astrophysics_fields_values: - if attr in data_dict: - v = data_dict[attr] - if isinstance(v, list): - multiple = True - else: - multiple = False - if attr in self.__attr_dict_dv_up_type_class_primitive: - type_class = "primitive" - elif attr in self.__attr_dict_dv_up_type_class_compound: - type_class = "compound" - elif ( - attr in self.__attr_dict_dv_up_type_class_controlled_vocabulary - ): - type_class = "controlledVocabulary" - astrophysics["fields"].append( - { - "typeName": attr, - "multiple": multiple, - "typeClass": type_class, - "value": v, - } - ) + astrophysics = {"fields": []} + break + + if astrophysics is not None: + if "astrophysics_displayName" in data_dict: + astrophysics["displayName"] = data_dict["astrophysics_displayName"] + + # Generate first level attributes + for attr in self.__attr_import_dv_up_astrophysics_fields_values: + if attr in data_dict and data_dict[attr] is not None: + v = data_dict[attr] + multiple = isinstance(v, list) + if attr in self.__attr_dict_dv_up_type_class_primitive: + type_class = "primitive" + elif attr in self.__attr_dict_dv_up_type_class_compound: + type_class = "compound" + elif attr in self.__attr_dict_dv_up_type_class_controlled_vocabulary: + type_class = "controlledVocabulary" + astrophysics["fields"].append( + { + "typeName": attr, + "multiple": multiple, + "typeClass": type_class, + "value": v, + } + ) - # Generate fields attributes - for ( - key, - val, - ) in self.__attr_import_dv_up_astrophysics_fields_arrays.items(): - if key in data_dict: - astrophysics["fields"].append( - { - "typeName": key, - "multiple": True, - "typeClass": "compound", - "value": self.__generate_field_arrays(key, val), - } - ) + # Generate fields attributes + for key, val in self.__attr_import_dv_up_astrophysics_fields_arrays.items(): + if key in data_dict and data_dict[key] is not None: + astrophysics["fields"].append( + { + "typeName": key, + "multiple": True, + "typeClass": "compound", + "value": self.__generate_field_arrays(key, val), + } + ) data["datasetVersion"]["metadataBlocks"]["citation"] = citation - if "socialscience" in locals(): - data["datasetVersion"]["metadataBlocks"]["socialscience"] = ( - socialscience - ) - if "geospatial" in locals(): + if socialscience is not None: + data["datasetVersion"]["metadataBlocks"]["socialscience"] = socialscience + if geospatial is not None: data["datasetVersion"]["metadataBlocks"]["geospatial"] = geospatial - if "journal" in locals(): + if journal is not None: data["datasetVersion"]["metadataBlocks"]["journal"] = journal - if "astrophysics" in locals(): + if astrophysics is not None: data["datasetVersion"]["metadataBlocks"]["astrophysics"] = astrophysics elif data_format == "dspace": data = None @@ -1658,6 +1605,7 @@ def json(self, data_format=None, validate=True, filename_schema=None): return json_str + class Datafile(DVObject): """Base class for the Dataverse data type `Datafile`. From e666fb197713dd1152173d456ccd04eacc4d91bb Mon Sep 17 00:00:00 2001 From: kmika11 Date: Mon, 29 Jul 2024 10:08:14 -0400 Subject: [PATCH 08/12] update models.py added __attr_import_dv_up_astrophysics_fields_values to __attr_dict_dv_up_type_class_primitive and edited the coverage.Spectral.Wavelength element --- pyDataverse/models.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyDataverse/models.py b/pyDataverse/models.py index 9921361..d4c0e16 100644 --- a/pyDataverse/models.py +++ b/pyDataverse/models.py @@ -543,9 +543,10 @@ class Dataset(DVObject): + __attr_import_dv_up_geospatial_fields_arrays["geographicBoundingBox"] + __attr_import_dv_up_socialscience_fields_values + __attr_import_dv_up_journal_fields_arrays["journalVolumeIssue"] - + __attr_import_dv_up_astrophysics_fields_arrays['coverage.Temporal'] - + __attr_import_dv_up_astrophysics_fields_arrays['coverage.Spectral'] - + __attr_import_dv_up_astrophysics_fields_arrays['coverage.RedshiftValue'] + + __attr_import_dv_up_astrophysics_fields_values + + __attr_import_dv_up_astrophysics_fields_arrays["coverage.Temporal"] + + __attr_import_dv_up_astrophysics_fields_arrays["coverage.Spectral.Wavelength"] + + __attr_import_dv_up_astrophysics_fields_arrays["coverage.RedshiftValue"] + [ "socialScienceNotesType", "socialScienceNotesSubject", From 83d586b5fd1fdb46ef5d6d51b9a4642ede025126 Mon Sep 17 00:00:00 2001 From: kmika11 Date: Mon, 29 Jul 2024 10:32:19 -0400 Subject: [PATCH 09/12] edit models.py --- pyDataverse/models.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pyDataverse/models.py b/pyDataverse/models.py index d4c0e16..4e3f80f 100644 --- a/pyDataverse/models.py +++ b/pyDataverse/models.py @@ -320,6 +320,12 @@ class Dataset(DVObject): __attr_import_dv_up_journal_fields_arrays : dict Attributes of Dataverse API Upload Dataset JSON metadata standard inside [\'datasetVersion\'][\'metadataBlocks\'][\'journal\'][\'fields\']. + __attr_import_dv_up_astrophysics_fields_values : list + Attributes of Dataverse API Upload Dataset JSON metadata standard inside + [\'datasetVersion\'][\'metadataBlocks\'][\'astrophysics\'][\'fields\']. + __attr_import_dv_up_astrophysics_fields_arrays : dict + Attributes of Dataverse API Upload Dataset JSON metadata standard inside + [\'datasetVersion\'][\'metadataBlocks\'][\'astrophysics\'][\'fields\']. __attr_dict_dv_up_required :list Required attributes for valid `dv_up` metadata dict creation. __attr_dict_dv_up_type_class_primitive : list @@ -518,10 +524,6 @@ class Dataset(DVObject): "publicationURL", "relatedDatasets", "relatedMaterial", - "resolution.Spatial", - "resolution.Temporal", - "redshiftType", - "resolution.Redshift" "seriesInformation", "seriesName", "state", @@ -1642,9 +1644,11 @@ def json(self, data_format=None, validate=True, filename_schema=None): if "geospatial" in locals(): data["datasetVersion"]["metadataBlocks"]["geospatial"] = geospatial if "journal" in locals(): + print("'Journal' matadata block exists in locals()") data["datasetVersion"]["metadataBlocks"]["journal"] = journal if "astrophysics" in locals(): data["datasetVersion"]["metadataBlocks"]["astrophysics"] = astrophysics + print("'Astrophysics' metadata block in locals()") elif data_format == "dspace": data = None print("INFO: Not implemented yet.") From e90458baf15896db8d747dfaf79e99d92e897c57 Mon Sep 17 00:00:00 2001 From: kmika11 Date: Mon, 29 Jul 2024 10:36:37 -0400 Subject: [PATCH 10/12] Update models.py --- pyDataverse/models.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/pyDataverse/models.py b/pyDataverse/models.py index 5fd38fa..89d8062 100644 --- a/pyDataverse/models.py +++ b/pyDataverse/models.py @@ -1116,22 +1116,22 @@ def from_json( in self.__attr_import_dv_up_astrophysics_fields_values ): data[field["typeName"]] = field["value"] - elif( - field["typeName"] - in self.__attr_import_dv_up_astrophysics_fields_arrays - ): + elif( + field["typeName"] + in self.__attr_import_dv_up_astrophysics_fields_arrays + ): data[field["typeName"]] = self.__parse_field_array( - field["value"], - self.__attr_import_dv_up_astrophysics_fields_arrays[ - field["typeName"] - ], - ) - else: - print( - "Attribute {0} not valid for import (dv_up).".format( + field["value"], + self.__attr_import_dv_up_astrophysics_fields_arrays[ field["typeName"] - ) + ], + ) + else: + print( + "Attribute {0} not valid for import (dv_up).".format( + field["typeName"] ) + ) else: # TODO: Exception @@ -1585,7 +1585,6 @@ def json(self, data_format=None, validate=True, filename_schema=None): if geospatial is not None: data["datasetVersion"]["metadataBlocks"]["geospatial"] = geospatial if journal is not None: - if "journal" in locals(): print("'Journal' matadata block exists in locals()") data["datasetVersion"]["metadataBlocks"]["journal"] = journal if astrophysics is not None: From 818f3c1129ea7d29d17ca6cd316b65e6eeb06bec Mon Sep 17 00:00:00 2001 From: kmika11 Date: Mon, 29 Jul 2024 11:15:47 -0400 Subject: [PATCH 11/12] Update models.py --- pyDataverse/models.py | 409 +++++++++++++++++++++++------------------- 1 file changed, 220 insertions(+), 189 deletions(-) diff --git a/pyDataverse/models.py b/pyDataverse/models.py index 89d8062..3221361 100644 --- a/pyDataverse/models.py +++ b/pyDataverse/models.py @@ -1318,32 +1318,32 @@ def json(self, data_format=None, validate=True, filename_schema=None): if "series" in data_dict: series = data_dict["series"] tmp_dict = {} - if "seriesName" in series and series["seriesName"] is not None: - tmp_dict["seriesName"] = { - "typeName": "seriesName", + if "seriesName" in series: + if series["seriesName"] is not None: + tmp_dict["seriesName"] = {} + tmp_dict["seriesName"]["typeName"] = "seriesName" + tmp_dict["seriesName"]["multiple"] = False + tmp_dict["seriesName"]["typeClass"] = "primitive" + tmp_dict["seriesName"]["value"] = series["seriesName"] + if "seriesInformation" in series: + if series["seriesInformation"] is not None: + tmp_dict["seriesInformation"] = {} + tmp_dict["seriesInformation"]["typeName"] = "seriesInformation" + tmp_dict["seriesInformation"]["multiple"] = False + tmp_dict["seriesInformation"]["typeClass"] = "primitive" + tmp_dict["seriesInformation"]["value"] = series[ + "seriesInformation" + ] + citation["fields"].append( + { + "typeName": "series", "multiple": False, - "typeClass": "primitive", - "value": series["seriesName"], + "typeClass": "compound", + "value": tmp_dict, } - if "seriesInformation" in series and series["seriesInformation"] is not None: - tmp_dict["seriesInformation"] = { - "typeName": "seriesInformation", - "multiple": False, - "typeClass": "primitive", - "value": series["seriesInformation"], - } - if tmp_dict: - citation["fields"].append( - { - "typeName": "series", - "multiple": False, - "typeClass": "compound", - "value": tmp_dict, - } - ) + ) # geospatial - geospatial = None for attr in ( self.__attr_import_dv_up_geospatial_fields_values + list(self.__attr_import_dv_up_geospatial_fields_arrays.keys()) @@ -1353,9 +1353,8 @@ def json(self, data_format=None, validate=True, filename_schema=None): geospatial = {"fields": []} break - if geospatial is not None: - if "geospatial_displayName" in data_dict: - geospatial["displayName"] = data_dict["geospatial_displayName"] + if "geospatial_displayName" in data_dict: + geospatial["displayName"] = data_dict["geospatial_displayName"] # Generate first level attributes for attr in self.__attr_import_dv_up_geospatial_fields_values: @@ -1394,202 +1393,234 @@ def json(self, data_format=None, validate=True, filename_schema=None): for attr in self.__attr_import_dv_up_socialscience_fields_values + [ "socialscience_displayName" ]: - if attr in data_dict: - socialscience = {"fields": []} - break + if attr in data_dict: + socialscience = {} + if attr != "socialscience_displayName": + socialscience["fields"] = [] + break - if socialscience is not None: - if "socialscience_displayName" in data_dict: - socialscience["displayName"] = data_dict["socialscience_displayName"] + if "socialscience_displayName" in data_dict: + socialscience["displayName"] = data_dict["socialscience_displayName"] - # Generate first level attributes - for attr in self.__attr_import_dv_up_socialscience_fields_values: - if attr in data_dict and data_dict[attr] is not None: - v = data_dict[attr] - multiple = isinstance(v, list) - if attr in self.__attr_dict_dv_up_type_class_primitive: - type_class = "primitive" - elif attr in self.__attr_dict_dv_up_type_class_compound: - type_class = "compound" - elif attr in self.__attr_dict_dv_up_type_class_controlled_vocabulary: - type_class = "controlledVocabulary" - socialscience["fields"].append( - { - "typeName": attr, - "multiple": multiple, - "typeClass": type_class, - "value": v, - } - ) - - # Generate targetSampleSize attributes - if "targetSampleSize" in data_dict: - target_sample_size = data_dict["targetSampleSize"] - tmp_dict = {} - if "targetSampleActualSize" in target_sample_size and target_sample_size["targetSampleActualSize"] is not None: - tmp_dict["targetSampleActualSize"] = { - "typeName": "targetSampleActualSize", - "multiple": False, - "typeClass": "primitive", - "value": target_sample_size["targetSampleActualSize"], - } - if "targetSampleSizeFormula" in target_sample_size and target_sample_size["targetSampleSizeFormula"] is not None: - tmp_dict["targetSampleSizeFormula"] = { - "typeName": "targetSampleSizeFormula", - "multiple": False, - "typeClass": "primitive", - "value": target_sample_size["targetSampleSizeFormula"], + # Generate first level attributes + for attr in self.__attr_import_dv_up_socialscience_fields_values: + if attr in data_dict and data_dict[attr] is not None: + v = data_dict[attr] + multiple = isinstance(v, list) + if attr in self.__attr_dict_dv_up_type_class_primitive: + type_class = "primitive" + elif attr in self.__attr_dict_dv_up_type_class_compound: + type_class = "compound" + elif attr in self.__attr_dict_dv_up_type_class_controlled_vocabulary: + type_class = "controlledVocabulary" + socialscience["fields"].append( + { + "typeName": attr, + "multiple": multiple, + "typeClass": type_class, + "value": v, } - if tmp_dict: - socialscience["fields"].append( - { - "typeName": "targetSampleSize", - "multiple": False, - "typeClass": "compound", - "value": tmp_dict, - } + ) + + + + # Generate targetSampleSize attributes + if "targetSampleSize" in data_dict: + target_sample_size = data_dict["targetSampleSize"] + tmp_dict = {} + if "targetSampleActualSize" in target_sample_size: + if target_sample_size["targetSampleActualSize"] is not None: + tmp_dict["targetSampleActualSize"] = {} + tmp_dict["targetSampleActualSize"]["typeName"] = ( + "targetSampleActualSize" ) + tmp_dict["targetSampleActualSize"]["multiple"] = False + tmp_dict["targetSampleActualSize"]["typeClass"] = "primitive" + tmp_dict["targetSampleActualSize"]["value"] = ( + target_sample_size["targetSampleActualSize"] + ) + if "targetSampleSizeFormula" in target_sample_size: + if target_sample_size["targetSampleSizeFormula"] is not None: + tmp_dict["targetSampleSizeFormula"] = {} + tmp_dict["targetSampleSizeFormula"]["typeName"] = ( + "targetSampleSizeFormula" + ) + tmp_dict["targetSampleSizeFormula"]["multiple"] = False + tmp_dict["targetSampleSizeFormula"]["typeClass"] = "primitive" + tmp_dict["targetSampleSizeFormula"]["value"] = ( + target_sample_size["targetSampleSizeFormula"] + ) + socialscience["fields"].append( + { + "typeName": "targetSampleSize", + "multiple": False, + "typeClass": "compound", + "value": tmp_dict, + } + ) - # Generate socialScienceNotes attributes - if "socialScienceNotes" in data_dict: - social_science_notes = data_dict["socialScienceNotes"] - tmp_dict = {} - if "socialScienceNotesType" in social_science_notes and social_science_notes["socialScienceNotesType"] is not None: - tmp_dict["socialScienceNotesType"] = { - "typeName": "socialScienceNotesType", - "multiple": False, - "typeClass": "primitive", - "value": social_science_notes["socialScienceNotesType"], - } - if "socialScienceNotesSubject" in social_science_notes and social_science_notes["socialScienceNotesSubject"] is not None: - tmp_dict["socialScienceNotesSubject"] = { - "typeName": "socialScienceNotesSubject", - "multiple": False, - "typeClass": "primitive", - "value": social_science_notes["socialScienceNotesSubject"], - } - if "socialScienceNotesText" in social_science_notes and social_science_notes["socialScienceNotesText"] is not None: - tmp_dict["socialScienceNotesText"] = { - "typeName": "socialScienceNotesText", - "multiple": False, - "typeClass": "primitive", - "value": social_science_notes["socialScienceNotesText"], - } - if tmp_dict: - socialscience["fields"].append( - { - "typeName": "socialScienceNotes", - "multiple": False, - "typeClass": "compound", - "value": tmp_dict, - } + # Generate socialScienceNotes attributes + if "socialScienceNotes" in data_dict: + social_science_notes = data_dict["socialScienceNotes"] + tmp_dict = {} + if "socialScienceNotesType" in social_science_notes: + if social_science_notes["socialScienceNotesType"] is not None: + tmp_dict["socialScienceNotesType"] = {} + tmp_dict["socialScienceNotesType"]["typeName"] = ( + "socialScienceNotesType" + ) + tmp_dict["socialScienceNotesType"]["multiple"] = False + tmp_dict["socialScienceNotesType"]["typeClass"] = "primitive" + tmp_dict["socialScienceNotesType"]["value"] = ( + social_science_notes["socialScienceNotesType"] + ) + if "socialScienceNotesSubject" in social_science_notes: + if social_science_notes["socialScienceNotesSubject"] is not None: + tmp_dict["socialScienceNotesSubject"] = {} + tmp_dict["socialScienceNotesSubject"]["typeName"] = ( + "socialScienceNotesSubject" + ) + tmp_dict["socialScienceNotesSubject"]["multiple"] = False + tmp_dict["socialScienceNotesSubject"]["typeClass"] = "primitive" + tmp_dict["socialScienceNotesSubject"]["value"] = ( + social_science_notes["socialScienceNotesSubject"] + ) + if "socialScienceNotesText" in social_science_notes: + if social_science_notes["socialScienceNotesText"] is not None: + tmp_dict["socialScienceNotesText"] = {} + tmp_dict["socialScienceNotesText"]["typeName"] = ( + "socialScienceNotesText" ) + tmp_dict["socialScienceNotesText"]["multiple"] = False + tmp_dict["socialScienceNotesText"]["typeClass"] = "primitive" + tmp_dict["socialScienceNotesText"]["value"] = ( + social_science_notes["socialScienceNotesText"] + ) + socialscience["fields"].append( + { + "typeName": "socialScienceNotes", + "multiple": False, + "typeClass": "compound", + "value": tmp_dict, + } + ) # journal - journal = None for attr in ( self.__attr_import_dv_up_journal_fields_values + list(self.__attr_import_dv_up_journal_fields_arrays.keys()) + ["journal_displayName"] ): if attr in data_dict: - journal = {"fields": []} - break + journal = {} + if attr != "journal_displayName": + journal["fields"] = [] + break - if journal is not None: - if "journal_displayName" in data_dict: - journal["displayName"] = data_dict["journal_displayName"] - # Generate first level attributes - for attr in self.__attr_import_dv_up_journal_fields_values: - if attr in data_dict and data_dict[attr] is not None: - v = data_dict[attr] - multiple = isinstance(v, list) - if attr in self.__attr_dict_dv_up_type_class_primitive: - type_class = "primitive" - elif attr in self.__attr_dict_dv_up_type_class_compound: - type_class = "compound" - elif attr in self.__attr_dict_dv_up_type_class_controlled_vocabulary: - type_class = "controlledVocabulary" - journal["fields"].append( - { - "typeName": attr, - "multiple": multiple, - "typeClass": type_class, - "value": v, - } - ) + if "journal_displayName" in data_dict: + journal["displayName"] = data_dict["journal_displayName"] + + # Generate first level attributes + for attr in self.__attr_import_dv_up_journal_fields_values: + if attr in data_dict: + v = data_dict[attr] + if isinstance(v, list): + multiple = True + else: + multiple = False + if attr in self.__attr_dict_dv_up_type_class_primitive: + type_class = "primitive" + elif attr in self.__attr_dict_dv_up_type_class_compound: + type_class = "compound" + elif attr in self.__attr_dict_dv_up_type_class_controlled_vocabulary: + type_class = "controlledVocabulary" + journal["fields"].append( + { + "typeName": attr, + "multiple": multiple, + "typeClass": type_class, + "value": v, + } + ) + + # Generate fields attributes + for key, val in self.__attr_import_dv_up_journal_fields_arrays.items(): + if key in data_dict: + journal["fields"].append( + { + "typeName": key, + "multiple": True, + "typeClass": "compound", + "value": self.__generate_field_arrays(key, val), + } + ) + - # Generate fields attributes - for key, val in self.__attr_import_dv_up_journal_fields_arrays.items(): - if key in data_dict and data_dict[key] is not None: - journal["fields"].append( - { - "typeName": key, - "multiple": True, - "typeClass": "compound", - "value": self.__generate_field_arrays(key, val), - } - ) - # astrophysics - astrophysics = None for attr in ( self.__attr_import_dv_up_astrophysics_fields_values + list(self.__attr_import_dv_up_astrophysics_fields_arrays.keys()) + ["astrophysics_displayName"] ): if attr in data_dict: - astrophysics = {"fields": []} - break + astrophysics = {} + if attr != "astrophysics_displayName": + astrophysics["fields"] = [] + break - if astrophysics is not None: - if "astrophysics_displayName" in data_dict: - astrophysics["displayName"] = data_dict["astrophysics_displayName"] - # Generate first level attributes - for attr in self.__attr_import_dv_up_astrophysics_fields_values: - if attr in data_dict and data_dict[attr] is not None: - v = data_dict[attr] - multiple = isinstance(v, list) - if attr in self.__attr_dict_dv_up_type_class_primitive: - type_class = "primitive" - elif attr in self.__attr_dict_dv_up_type_class_compound: - type_class = "compound" - elif attr in self.__attr_dict_dv_up_type_class_controlled_vocabulary: - type_class = "controlledVocabulary" - astrophysics["fields"].append( - { - "typeName": attr, - "multiple": multiple, - "typeClass": type_class, - "value": v, - } - ) + if "astrophysics_displayName" in data_dict: + astrophysics["displayName"] = data_dict["astrophysics_displayName"] - # Generate fields attributes - for key, val in self.__attr_import_dv_up_astrophysics_fields_arrays.items(): - if key in data_dict and data_dict[key] is not None: - astrophysics["fields"].append( - { - "typeName": key, - "multiple": True, - "typeClass": "compound", - "value": self.__generate_field_arrays(key, val), - } - ) + # Generate first level attributes + for attr in self.__attr_import_dv_up_astrophysics_fields_values: + if attr in data_dict: + v = data_dict[attr] + if isinstance(v, list): + multiple = True + else: + multiple = False + if attr in self.__attr_dict_dv_up_type_class_primitive: + type_class = "primitive" + elif attr in self.__attr_dict_dv_up_type_class_compound: + type_class = "compound" + elif attr in self.__attr_dict_dv_up_type_class_controlled_vocabulary: + type_class = "controlledVocabulary" + astrophysics["fields"].append( + { + "typeName": attr, + "multiple": multiple, + "typeClass": type_class, + "value": v, + } + ) + + # Generate fields attributes + for key, val in self.__attr_import_dv_up_astrophysics_fields_arrays.items(): + if key in data_dict: + astrophysics["fields"].append( + { + "typeName": key, + "multiple": True, + "typeClass": "compound", + "value": self.__generate_field_arrays(key, val), + } + ) data["datasetVersion"]["metadataBlocks"]["citation"] = citation - if socialscience is not None: - data["datasetVersion"]["metadataBlocks"]["socialscience"] = socialscience - if geospatial is not None: + if "socialscience" in locals(): + data["datasetVersion"]["metadataBlocks"]["socialscience"] = ( + socialscience + ) + if "geospatial" in locals(): data["datasetVersion"]["metadataBlocks"]["geospatial"] = geospatial - if journal is not None: - print("'Journal' matadata block exists in locals()") + if "journal" in locals(): + print("'Journal' matadata added to dataset") data["datasetVersion"]["metadataBlocks"]["journal"] = journal - if astrophysics is not None: + if "astrophysics" in locals(): + print("'Astrophysics' metadata added to dataset") data["datasetVersion"]["metadataBlocks"]["astrophysics"] = astrophysics - print("'Astrophysics' metadata block in locals()") elif data_format == "dspace": data = None print("INFO: Not implemented yet.") From 82358c2a6c8ec7b653e701c46b957f17fe232c0c Mon Sep 17 00:00:00 2001 From: kmika11 Date: Mon, 29 Jul 2024 11:28:08 -0400 Subject: [PATCH 12/12] update models.py to test if astrophysics in locals(): --- pyDataverse/models.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyDataverse/models.py b/pyDataverse/models.py index 3221361..b955af9 100644 --- a/pyDataverse/models.py +++ b/pyDataverse/models.py @@ -1609,6 +1609,7 @@ def json(self, data_format=None, validate=True, filename_schema=None): ) data["datasetVersion"]["metadataBlocks"]["citation"] = citation + data["datasetVersion"]["metadataBlocks"]["astrophysics"] = astrophysics if "socialscience" in locals(): data["datasetVersion"]["metadataBlocks"]["socialscience"] = ( socialscience @@ -1618,9 +1619,9 @@ def json(self, data_format=None, validate=True, filename_schema=None): if "journal" in locals(): print("'Journal' matadata added to dataset") data["datasetVersion"]["metadataBlocks"]["journal"] = journal - if "astrophysics" in locals(): - print("'Astrophysics' metadata added to dataset") - data["datasetVersion"]["metadataBlocks"]["astrophysics"] = astrophysics + #if "astrophysics" in locals(): + # print("'Astrophysics' metadata added to dataset") + # data["datasetVersion"]["metadataBlocks"]["astrophysics"] = astrophysics elif data_format == "dspace": data = None print("INFO: Not implemented yet.")