@@ -128,20 +128,21 @@ def push_metadata_to_queue(
128128 redis_store : redis .Redis ,
129129 params : Dict [str , Union [str , List [str ]]],
130130 metadata : pd .DataFrame ,
131- source : Literal [ "crossref" , "altmetric" ]
131+ source_list : List [ str ]
132132) -> str :
133133 """
134134 Sending metadata for processing into Redis queue and returning the request_id.
135135
136136 :param redis_store: Object of the Redis store.
137137 :param params: Request params.
138138 :param metadata: DataFrame with default metadata.
139- :param source : define from which service additional metadata will be received.
139+ :param source_list : define from which service additional metadata will be received (available values: "crossref", "altmetric") .
140140 :return: request_id for the receiving of the request result.
141141 """
142+ check_metadata_enrichment_source (source_list )
142143
143144 request_id = str (uuid .uuid4 ())
144- params ["metrics_sources" ] = [ source ]
145+ params ["metrics_sources" ] = source_list
145146 task_data = json .dumps ({
146147 "id" : request_id ,
147148 "params" : params ,
@@ -152,6 +153,17 @@ def push_metadata_to_queue(
152153 return request_id
153154
154155
156+ def check_metadata_enrichment_source (source_list : List [str ]) -> None :
157+ """
158+ Checks that source for metadata enrichment contains correct values.
159+
160+ :param source_list: List of sources from where metadata will be enriched.
161+ :return: None.
162+ """
163+ if not all (source in ("crossref" , "altmetric" ) for source in source_list ):
164+ raise ValueError ("Source list must contain only 'crossref' or 'altmetric'" )
165+
166+
155167def fetch_enriched_metadata (redis_store : redis .Redis , request_id : str , timeout : int = 600 ) -> pd .DataFrame :
156168 """
157169 Getting enriched metadata from Redis.
@@ -216,7 +228,7 @@ def enrich_metadata(
216228 redis : redis .Redis ,
217229 params : Dict [str , Union [str , List [str ]]],
218230 metadata : pd .DataFrame ,
219- source : Literal [ "crossref" , "altmetric" ],
231+ source_list : List [ str ],
220232 integration : Literal ["pubmed" , "orcid" ]
221233) -> pd .DataFrame :
222234 """
@@ -225,13 +237,15 @@ def enrich_metadata(
225237 :param redis: store object of Redis.
226238 :param params: params of the request.
227239 :param metadata: DataFrame with default metadata.
228- :param source: define from which service additional metadata will be received.
240+ :param source: define from which service additional metadata will be received (available values: "crossref", "altmetric") .
229241 :return: Enriched DataFrame with metadata.
230242 """
243+ # Checks that source list contains valid values
244+ check_metadata_enrichment_source (source_list )
231245
232246 # Creates a request to metrics for metadata enrichment
233247 # and returns request_id for receiving the result later
234- request_id = push_metadata_to_queue (redis , params , metadata , source )
248+ request_id = push_metadata_to_queue (redis , params , metadata , source_list )
235249
236250 # Getting the result after metadata enrichment at metrics
237251 enriched_metadata = fetch_enriched_metadata (redis , request_id )
0 commit comments