@@ -74,15 +74,9 @@ def validate_uuid(uuid):
74
74
75
75
76
76
def validate_gwlfe_prepare (data ):
77
- area_of_interest = data .get ('area_of_interest' )
78
- wkaoi = data .get ('wkaoi' )
79
- huc = data .get ('huc' )
80
77
layer_overrides = data .get ('layer_overrides' , {})
81
78
82
- if not check_gwlfe_only_one ([area_of_interest , wkaoi , huc ]):
83
- error = ('Invalid parameter: One and only one type of area object'
84
- ' (area_of_interest, wkaoi, or huc) is allowed' )
85
- raise ValidationError (error )
79
+ check_exactly_one_provided (['area_of_interest' , 'wkaoi' , 'huc' ], data )
86
80
87
81
not_valid_layers = check_layer_overrides_keys (layer_overrides )
88
82
@@ -102,30 +96,21 @@ def validate_gwlfe_prepare(data):
102
96
raise ValidationError (error )
103
97
104
98
105
- def validate_gwlfe_run (input , job_uuid ):
106
- if not check_gwlfe_only_one ([input , job_uuid ]):
107
- error = ('Invalid parameter: Only one type of prepared input'
108
- '(input JSON or job_uuid) is allowed' )
109
- raise ValidationError (error )
110
-
111
- if not check_gwlfe_run_input (input ):
112
- error = ("Invalid input: Please use the full result "
113
- "of gwlf-e/prepare endpoint's result object" )
114
- raise ValidationError (error )
115
-
116
-
117
- def check_gwlfe_only_one (params ):
118
- if sum (map (check_is_none , params )) == 1 :
119
- return True
120
- else :
121
- return False
99
+ def validate_gwlfe_run (input ):
100
+ missing_keys = [k for k in GWLFE_INPUT_KEYS if k not in input ]
101
+ if missing_keys :
102
+ raise ValidationError (f'Provided `input` is missing: { missing_keys } ' )
122
103
123
104
124
- def check_is_none (v ):
125
- if v is None :
126
- return 0
127
- else :
128
- return 1
105
+ def check_exactly_one_provided (one_of : list , params : dict ):
106
+ # Dictionary for just the keys of which we want one of
107
+ one_of_params = {k : params .get (k ) for k in one_of }
108
+ # List of keys with not None values
109
+ not_none_keys = [k for k , v in one_of_params .items () if v is not None ]
110
+ if len (not_none_keys ) != 1 :
111
+ raise ValidationError (
112
+ f'Must provide exactly one of: { one_of } . '
113
+ f'You provided values for: { not_none_keys } ' )
129
114
130
115
131
116
def check_layer_overrides_keys (layers ):
@@ -144,11 +129,6 @@ def check_streams_layer_overrides(layers):
144
129
return layers ['__STREAMS__' ] in STREAM_LAYER_OVERRIDES
145
130
146
131
147
- def check_gwlfe_run_input (input ):
148
- result = all (el in input for el in settings .GWLFE_DEFAULTS .keys ())
149
- return result
150
-
151
-
152
132
def create_layer_overrides_keys_not_valid_msg (layers ):
153
133
error = 'These layers are not standard layers for layer overrides: '
154
134
for layler in layers :
@@ -171,3 +151,14 @@ def create_layer_overrides_land_not_valid_msg(values):
171
151
]
172
152
173
153
STREAM_LAYER_OVERRIDES = ['drb' , 'nhdhr' , 'nhd' ]
154
+
155
+ # These are not present in GWLFE_DEFAULTS, but are necessary for running GWLF-E
156
+ GWLFE_INPUT_KEYS = list (settings .GWLFE_DEFAULTS .keys ()) + [
157
+ 'AEU' , 'Acoef' , 'AgLength' , 'AgSlope3' , 'AgSlope3To8' , 'Area' , 'AvKF' ,
158
+ 'AvSlope' , 'CN' , 'DayHrs' , 'GrNitrConc' , 'GrPhosConc' , 'Grow' , 'KF' , 'KV' ,
159
+ 'LS' , 'ManNitr' , 'ManPhos' , 'MaxWaterCap' , 'NumNormalSys' , 'P' , 'PhosConc' ,
160
+ 'PointFlow' , 'PointNitr' , 'PointPhos' , 'Prec' , 'RecessionCoef' ,
161
+ 'SedAFactor' , 'SedDelivRatio' , 'SedNitr' , 'SedPhos' , 'StreamLength' ,
162
+ 'Temp' , 'TotArea' , 'UrbAreaTotal' , 'UrbLength' , 'WeatherStations' ,
163
+ 'WxYrBeg' , 'WxYrEnd' , 'WxYrs' , 'n23' , 'n23b' , 'n24' , 'n24b' , 'n41' , 'n41j' ,
164
+ 'n41k' , 'n41l' , 'n42' , 'n42b' , 'n46e' , 'n46f' ]
0 commit comments