Skip to content

Commit

Permalink
Merge pull request #24 from hydroshare/json-api
Browse files Browse the repository at this point in the history
move rights out of in schemas for aggregations
  • Loading branch information
sblack-usu authored Nov 15, 2021
2 parents 480149b + fc69f13 commit 471476e
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 43 deletions.
63 changes: 57 additions & 6 deletions hsmodels/schemas/aggregations.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
class BaseAggregationMetadataIn(BaseMetadata):

title: str = Field(
title="Aggregation title", description="A string containing a descriptive title for the aggregation"
default=None,
title="Aggregation title",
description="A string containing a descriptive title for the aggregation",
)
subjects: List[str] = Field(
default=[],
Expand All @@ -68,11 +70,6 @@ class BaseAggregationMetadataIn(BaseMetadata):
title="Temporal coverage",
description="An object containing the temporal coverage for a aggregation expressed as a date range",
)
rights: Rights = Field(
default=None,
title="Rights statement",
description="An object containing information about the rights held in and over the aggregation and the license under which a aggregation is shared",
)

_parse_additional_metadata = root_validator(pre=True, allow_reuse=True)(parse_additional_metadata)
_parse_coverages = root_validator(pre=True, allow_reuse=True)(split_coverages)
Expand Down Expand Up @@ -129,6 +126,12 @@ class GeographicRasterMetadata(GeographicRasterMetadataIn):
title="Aggregation URL", description="An object containing the URL of the aggregation", allow_mutation=False
)

rights: Rights = Field(
default=None,
title="Rights statement",
description="An object containing information about the rights held in and over the aggregation and the license under which a aggregation is shared",
)

_parse_url = root_validator(pre=True, allow_reuse=True)(parse_url)


Expand Down Expand Up @@ -178,6 +181,12 @@ class GeographicFeatureMetadata(GeographicFeatureMetadataIn):
title="Aggregation URL", description="An object containing the URL of the aggregation", allow_mutation=False
)

rights: Rights = Field(
default=None,
title="Rights statement",
description="An object containing information about the rights held in and over the aggregation and the license under which a aggregation is shared",
)

_parse_url = root_validator(pre=True, allow_reuse=True)(parse_url)


Expand Down Expand Up @@ -225,6 +234,12 @@ class MultidimensionalMetadata(MultidimensionalMetadataIn):
title="Aggregation URL", description="An object containing the URL of the aggregation", allow_mutation=False
)

rights: Rights = Field(
default=None,
title="Rights statement",
description="An object containing information about the rights held in and over the aggregation and the license under which a aggregation is shared",
)

_parse_url = root_validator(pre=True, allow_reuse=True)(parse_url)


Expand Down Expand Up @@ -257,6 +272,12 @@ class ReferencedTimeSeriesMetadata(ReferencedTimeSeriesMetadataIn):
title="Aggregation URL", description="An object containing the URL of the aggregation", allow_mutation=False
)

rights: Rights = Field(
default=None,
title="Rights statement",
description="An object containing information about the rights held in and over the aggregation and the license under which a aggregation is shared",
)

_parse_url = root_validator(pre=True, allow_reuse=True)(parse_url)


Expand Down Expand Up @@ -289,6 +310,12 @@ class FileSetMetadata(FileSetMetadataIn):
title="Aggregation URL", description="An object containing the URL of the aggregation", allow_mutation=False
)

rights: Rights = Field(
default=None,
title="Rights statement",
description="An object containing information about the rights held in and over the aggregation and the license under which a aggregation is shared",
)

_parse_url = root_validator(pre=True, allow_reuse=True)(parse_url)


Expand Down Expand Up @@ -320,6 +347,12 @@ class SingleFileMetadata(SingleFileMetadataIn):
title="Aggregation URL", description="An object containing the URL of the aggregation", allow_mutation=False
)

rights: Rights = Field(
default=None,
title="Rights statement",
description="An object containing information about the rights held in and over the aggregation and the license under which a aggregation is shared",
)

_parse_url = root_validator(pre=True, allow_reuse=True)(parse_url)


Expand Down Expand Up @@ -364,6 +397,12 @@ class TimeSeriesMetadata(TimeSeriesMetadataIn):
title="Aggregation URL", description="An object containing the URL of the aggregation", allow_mutation=False
)

rights: Rights = Field(
default=None,
title="Rights statement",
description="An object containing information about the rights held in and over the aggregation and the license under which a aggregation is shared",
)

_parse_url = root_validator(pre=True, allow_reuse=True)(parse_url)


Expand Down Expand Up @@ -445,6 +484,12 @@ class ModelProgramMetadata(ModelProgramMetadataIn):
title="Aggregation URL", description="An object containing the URL of the aggregation", allow_mutation=False
)

rights: Rights = Field(
default=None,
title="Rights statement",
description="An object containing information about the rights held in and over the aggregation and the license under which a aggregation is shared",
)

_parse_url = root_validator(pre=True, allow_reuse=True)(parse_url)


Expand Down Expand Up @@ -496,4 +541,10 @@ class ModelInstanceMetadata(ModelInstanceMetadataIn):
title="Aggregation URL", description="An object containing the URL of the aggregation", allow_mutation=False
)

rights: Rights = Field(
default=None,
title="Rights statement",
description="An object containing information about the rights held in and over the aggregation and the license under which a aggregation is shared",
)

_parse_url = root_validator(pre=True, allow_reuse=True)(parse_url)
7 changes: 7 additions & 0 deletions hsmodels/schemas/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ def parse_spatial_reference(cls, value):


def parse_multidimensional_spatial_reference(cls, value):
# This is a workaround for form submissions that do not include type
if isinstance(value, dict) and "type" not in value:
if "north" in value or "east" in value:
# it's a type point
value["type"] = "point"
else:
value["type"] = "box"
if value['type'] == enums.MultidimensionalSpatialReferenceType.box:
d = to_coverage_dict(value['value'])
return fields.MultidimensionalBoxSpatialReference(**d)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='hsmodels',
version='0.4.0',
version='0.4.1',
packages=find_packages(include=['hsmodels', 'hsmodels.*', 'hsmodels.schemas.*', 'hsmodels.schemas.rdf.*'],
exclude=("tests",)),
install_requires=[
Expand Down
4 changes: 0 additions & 4 deletions tests/data/json/fileset.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,5 @@
"period_coverage": {
"start": "2020-11-03T00:00:00",
"end": "2020-11-19T00:00:00"
},
"rights": {
"statement": "my statement",
"url": "http://studio.bakajo.com"
}
}
4 changes: 0 additions & 4 deletions tests/data/json/geographicfeature.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
"start": "2020-11-05T00:00:00",
"end": "2020-11-26T00:00:00"
},
"rights": {
"statement": "my statement",
"url": "http://studio.bakajo.com"
},
"field_information": [
{
"field_name": "Id",
Expand Down
4 changes: 0 additions & 4 deletions tests/data/json/geographicraster.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
"start": "2020-11-05T00:00:00",
"end": "2020-11-26T00:00:00"
},
"rights": {
"statement": "my statement",
"url": "http://studio.bakajo.com"
},
"band_information": {
"name": "Band_1",
"variable_name": "variablename",
Expand Down
4 changes: 0 additions & 4 deletions tests/data/json/modelinstance.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
"start": "2021-10-08T00:00:00",
"end": "2021-10-15T00:00:00"
},
"rights": {
"statement": "This resource is shared under the Creative Commons Attribution CC BY.",
"url": "http://creativecommons.org/licenses/by/4.0/"
},
"includes_model_output": false,
"executed_by": "https://www.hydroshare.org/resource/636729f24c03497e9b844ec3be63e823/data/contents/modelprogram_resmap.xml#aggregation",
"program_schema_json": "https://www.hydroshare.org/resource/636729f24c03497e9b844ec3be63e823/data/contents/modelinstance_schema.json",
Expand Down
4 changes: 0 additions & 4 deletions tests/data/json/modelprogram.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
"1": "2",
"3": "4"
},
"rights": {
"statement": "This resource is shared under the Creative Commons Attribution CC BY.",
"url": "http://creativecommons.org/licenses/by/4.0/"
},
"version": "1",
"name": "Unknown Model Program",
"programming_languages": [
Expand Down
4 changes: 0 additions & 4 deletions tests/data/json/multidimensional.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
"start": "2008-10-05T00:00:00",
"end": "2009-06-18T00:00:00"
},
"rights": {
"statement": "my statement",
"url": "http://studio.bakajo.com"
},
"variables": [
{
"name": "x",
Expand Down
4 changes: 0 additions & 4 deletions tests/data/json/referencedtimeseries.refts.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,5 @@
"period_coverage": {
"start": "2016-04-06T00:00:00",
"end": "2017-02-09T00:00:00"
},
"rights": {
"statement": "my statement",
"url": "http://studio.bakajo.com"
}
}
4 changes: 0 additions & 4 deletions tests/data/json/singlefile.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,5 @@
"period_coverage": {
"start": "2020-11-03T00:00:00",
"end": "2020-11-19T00:00:00"
},
"rights": {
"statement": "my statement",
"url": "http://studio.bakajo.com"
}
}
4 changes: 0 additions & 4 deletions tests/data/json/timeseries.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
"start": "2008-01-01T00:00:00",
"end": "2008-01-30T23:30:00"
},
"rights": {
"statement": "This resource is shared under the Creative Commons Attribution CC BY.",
"url": "http://creativecommons.org/licenses/by/4.0/"
},
"time_series_results": [
{
"series_id": "182d8fa3-1ebc-11e6-ad49-f45c8999816f",
Expand Down

0 comments on commit 471476e

Please sign in to comment.