Skip to content

Commit

Permalink
Processing can fully execute (outputing is missing)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alban Peyrat (Archi) authored and Alban-Peyrat committed Dec 22, 2023
1 parent e5d5e65 commit 45db76c
Show file tree
Hide file tree
Showing 11 changed files with 718 additions and 72 deletions.
26 changes: 13 additions & 13 deletions api/abes/Abes_id2ppn.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def compute_isbn_13_check_digit(chars):

class Id2ppn_Result(object):
def __init__(self, status: Id2ppn_Status, error: Id2ppn_Errors, format: str, id: str, mod_id: str, isbn_validity=Isbn_Validity.SKIPPED, url=None, HTTP_status_code=0, result=None):
self.status = status.value
self.status = status
self.error = error
self.error_msg = error.value
self.format = format
Expand All @@ -123,7 +123,7 @@ def get_result(self):

def get_status(self):
"""Return the init status as a string."""
return self.status
return self.status.value

def get_error_msg(self):
"""Return the error message as a string."""
Expand All @@ -138,7 +138,7 @@ def get_nb_results(self):
- total results
- results with holdings
- results without holding"""
if self.status != Id2ppn_Status.SUCCESS.value:
if self.status != Id2ppn_Status.SUCCESS:
return 0, 0, 0
if self.format == "text/json":
res = []
Expand Down Expand Up @@ -167,24 +167,24 @@ def get_results(self, merge=False):
res = []
res_no_hold = []

if self.status != Id2ppn_Status.SUCCESS.value:
if self.status != Id2ppn_Status.SUCCESS:
return res, res_no_hold

if self.format == "text/json":
rep = json.loads(self.result)["sudoc"]["query"]
if "result" in rep:
for ppn in rep["result"]:
# ahahahah si ya 1 résultat ça renvoie pas une liste :)
if len(rep["result"]) > 1:
# Returns an object if only one match
if len(rep["result"]) > 1:
for ppn in rep["result"]:
res.append(str(ppn["ppn"]))
else:
res.append(str(rep["result"]["ppn"]))
else:
res.append(str(rep["result"]["ppn"]))
if "resultNoHolding" in rep:
for ppn in rep["resultNoHolding"]:
if len(rep["resultNoHolding"]) > 1:
if len(rep["resultNoHolding"]) > 1:
for ppn in rep["resultNoHolding"]:
res_no_hold.append(str(ppn["ppn"]))
else:
res_no_hold.append(str(rep["resultNoHolding"]["ppn"]))
else:
res_no_hold.append(str(rep["resultNoHolding"]["ppn"]))

else:
root = ET.fromstring(self.result)
Expand Down
6 changes: 6 additions & 0 deletions api/abes/Sudoc_SRU.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,12 @@ def __init__(self, status: Status, error: Errors, result: str, record_schema: st
result = self.fix_angle_brackets()
result = re.sub("</a>\s*<TR>", "</a></TD></TR>", result)
result = re.sub("(?<=</TR>)\s*(?=(<srw:record>|<\/srw:records>))", self.closing_tags_fix, result)
# Fix srw:query not correcting < and > and failing parsing
fix_srw_query_pattern = r"(<srw:query>.*<\/srw:query>)"
has_matched = re.search(fix_srw_query_pattern, result)
if has_matched:
fixed_query = f"<srw:query>{has_matched.group(1)[11:-12].replace('<', '&lt;').replace('>', '&gt;')}</srw:query>"
result = re.sub(fix_srw_query_pattern, fixed_query, result)
self.result_as_parsed_xml = ET.fromstring(result)

# Generate the result property
Expand Down
43 changes: 21 additions & 22 deletions doc/match_records.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,32 @@ Connectors, to work with `Find_And_Compare_Records`, need to be able to :
## Add an operation

* `Operations` define where and how `Find_And_Compare_Records` should look for matching records
* _In `bi_classes.py`_
* First, add a new entry in the `Enum Operations`
* Then, add this entry in the `dict TRY_OPERATIONS` :
* The key is the `Enum Operations` entry (everything, not only the name or value)
* The value must be a `list` of `Enum Actions`
* The order is important as if an action is successful, it will not execute the remaining ones
* _In `fcr_enum.py`_ :
* Add a new entry in the `Enum Operations`
* Add a new entry in the `Enum Try_Operations` using :
* A `Operations` entry's __name__ as a key
* A list of `Enum Actions` as value
* The order is important as if an action is successful, it will not execute the remaining ones

## Add an action

* `Actions` define where `Find_And_Compare_Records` will be looking for and what will the query be
* You can have multiple actions requesting from the same API if you want to modify the query : for example, you can have an action that queries `isbn2ppn` without modifying the input query, and another action that still queries `isbn2ppn` but this time the input query is changed into the 13/10 digits form of the ISBN
* _In `bi_classes.py`_
* Add a new entry in the `Enum Actions`
* _In `matched_records.py`_
* First, if needed, import the connector to the webservice or other
* Then, add in the `Match_records.request_action()` method a new `elif action == Actions.YOUR_NEW_ACTION`
* In this `elif`, you call the API or other
* Call `thistry.define_used_query` with as argument the used query as a `string`
* Then, if an error occured, call `thisTry.error_occured()` with as argument :
* A `Enum Matched_Records_Errors` entry
* Or a `str` error message
* If there are other types of status than `Success` or `Error`, call `thisTry.define_special_status()` with :
* A `Try_Status` entry as first argument (if incorrect, then `Try_Status.UNKNOWN` will be set)
* A message as second argument
* If matched ids were returned, call `thisTry.add_returned_ids()` with the list of matched ids as argument
* Note that this will switch the status to `SUCCESS`, so if you do not want that to happen, assign the list of returned ids directly to `thisTry.returned_ids`
* If matched records were also returned, call `thistry.add_returned_records` with the list of matched records as argument
* _In `fcr_enum.py`_, add a new entry in the `Enum Actions`
* _In `fcr_classes.py`_ :
* First, if needed, import the connector to the webservice or other
* Then, add in the `Match_records.request_action()` method a new `elif action == Actions.YOUR_NEW_ACTION`
* In this `elif`, you call the API or other
* Call `thistry.define_used_query` with as argument the used query as a `string`
* Then, if an error occured, call `thisTry.error_occured()` with as argument :
* A `Enum Matched_Records_Errors` entry
* Or a `str` error message
* If there are other types of status than `Success` or `Error`, call `thisTry.define_special_status()` with :
* A `Try_Status` entry as first argument (if incorrect, then `Try_Status.UNKNOWN` will be set)
* A message as second argument
* If matched ids were returned, call `thisTry.add_returned_ids()` with the list of matched ids as argument
* Note that this will switch the status to `SUCCESS`, so if you do not want that to happen, assign the list of returned ids directly to `thisTry.returned_ids`
* If matched records were also returned, call `thistry.add_returned_records` with the list of matched records as argument

## Add a type of error

Expand Down
14 changes: 11 additions & 3 deletions doc/processings.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
in database_record, add a case with the processig, calling for ude gets wanted
# Add a new processing

wanted data is in FCR_Mapped_Fields
* In `fcr_enum.py` :
* Add a new entry in the `Enum FCR_Processings`, using as value a dict :
* Use as keys `FCR_Mapped_Fields` entries you want to export at the end
* Use as value for those keys `FCR_Processing_Data_Target` entries to specify from which base you want the data to be extracted
* Add a new key in `PROCESSING_OPERATION_MAPPING` using :
* A `FCR_Processings` entry as a key
* A `Operations` entry as a value
* In `main_gui.py` : see [in GUI doc](./GUI.md#hide-elements-for-some-processings)

Add a key in fcr_classes.PROCESSING_OPERATION_MAPPING (key = FCR_Procesings entry) with an Operation as value (the whole thing, not jsut the name)

<!-- in database_record, add a case with the processig, calling for ude gets wanted -->
Loading

0 comments on commit 45db76c

Please sign in to comment.