2
2
3
3
import logging
4
4
from flask import Blueprint , jsonify , request , Response
5
+ from pymongo .errors import PyMongoError
5
6
from typing import Any , Tuple
6
7
from .db import db , get_runid , get_data_tags
7
8
from .minio import put_minio_object
@@ -109,14 +110,6 @@ def add() -> Tuple[Response, int]:
109
110
if not portal_runid :
110
111
return jsonify ("Missing value for HTTP Header X-Ips-Portal-Runid" ), 400
111
112
112
- # Jupyter links are optional to associate with a data event.
113
- # If they DO exist, we use a non-printable delimiter to separate links in the header value
114
- juypter_links_header = request .headers .get ("X-Ips-Jupyter-Links" )
115
- if juypter_links_header :
116
- jupyter_links = juypter_links_header .split ("\x01 " )
117
- else :
118
- jupyter_links = []
119
-
120
113
# runid is needed because the portal_runid is not a valid bucket name for MINIO
121
114
runid = get_runid (portal_runid )
122
115
if runid is None :
@@ -147,7 +140,6 @@ def add() -> Tuple[Response, int]:
147
140
"tags" : {
148
141
"tag" : resolved_tag ,
149
142
"data_location_url" : data_location_url ,
150
- "jupyter_urls" : jupyter_links ,
151
143
}
152
144
},
153
145
},
@@ -182,14 +174,6 @@ def add_url() -> Tuple[Response, int]:
182
174
if not isinstance (url , str ):
183
175
errors .append ({"url" : "Must be provided and a string" })
184
176
185
- if not isinstance (data .get ('tags' ), list ):
186
- errors .append ({"tags" : "Must be provided and a non-empty list" })
187
- else :
188
- try :
189
- tag_lookups = set (map (float , data .get ('tags' )))
190
- except ValueError :
191
- errors .append ({"tags" : "Must be floating point values" })
192
-
193
177
portal_runid = data .get ('portal_runid' )
194
178
if not isinstance (portal_runid , str ):
195
179
errors .append ({"portal_runid" : "Must be provided" })
@@ -203,16 +187,14 @@ def add_url() -> Tuple[Response, int]:
203
187
if errors :
204
188
return jsonify (errors ), 400
205
189
206
- # TODO figure out how to do this entirely in Mongo
207
- for tags_prop in result ['tags' ]: # type: ignore[index]
208
- if tags_prop ['tag' ] in tag_lookups and url not in tags_prop ['jupyter_urls' ]:
209
- tags_prop ['jupyter_urls' ].append (url )
210
- db .data .replace_one (
211
- {'_id' : result ['_id' ]}, # type: ignore[index]
212
- result # type: ignore[arg-type]
213
- )
214
-
215
- return jsonify ([]), 200
190
+ try :
191
+ db .data .update_one (
192
+ {"portal_runid" : portal_runid },
193
+ {"$set" : {"jupyter_url" : url }},
194
+ )
195
+ return jsonify ([]), 200
196
+ except PyMongoError :
197
+ return jsonify ([{"portal_runid" , "does not exist" }]), 400
216
198
217
199
218
200
@bp .route ("/api/data/query" , methods = ["POST" ])
0 commit comments