Skip to content

Commit

Permalink
A stab at a getter
Browse files Browse the repository at this point in the history
  • Loading branch information
dragon-dxw committed Dec 12, 2023
1 parent f32b001 commit 082e02b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion smoketest/smoketest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ def test_append_history():
api_client.append_history(
URI, HistoryEvent({"id": "1"}, ["flag"], "<kittens>1<cat/></kittens>")
)
# assert api_client.get_history() ...
event = api_client.get_history(URI)[-1]
assert event.attributes["id"] == "1"
13 changes: 13 additions & 0 deletions src/caselawclient/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from xml.etree.ElementTree import Element

import environ
import lxml.etree
import requests
from requests.auth import HTTPBasicAuth
from requests.structures import CaseInsensitiveDict
Expand Down Expand Up @@ -743,6 +744,7 @@ def original_judgment_transformation(
)

def get_property(self, judgment_uri: DocumentURIString, name: str) -> str:
"""This only gets the text of a property"""
uri = self._format_uri_for_marklogic(judgment_uri)
vars: query_dicts.GetPropertyDict = {
"uri": uri,
Expand Down Expand Up @@ -963,3 +965,14 @@ def append_history(self, uri: DocumentURIString, history: HistoryEvent) -> None:
"payload": history.payload,
}
self._send_to_eval(vars, "append_history.xqy")

def get_history(self, uri: DocumentURIString) -> list[HistoryEvent]:
formatted_uri = self._format_uri_for_marklogic(uri)
vars: query_dicts.GetHistoryDict = {"uri": formatted_uri}
response = self._send_to_eval(vars, "get_history.xqy")
bytes = get_single_bytestring_from_marklogic_response(response)
breakpoint()
events = []
for event in lxml.etree.fromstring(bytes).xpath("/history/event"):
events.append(HistoryEvent.from_xml(event))
return events
5 changes: 5 additions & 0 deletions src/caselawclient/models/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ def __init__(
self.payload = lxml.etree.tostring(payload)
else:
self.payload = payload

@classmethod
def from_xml(cls, element: lxml.etree._Element) -> "HistoryEvent":
flags = [a for a in element.attrib.keys() if element.attrib[a] == "true"]
return cls(element.attrib, flags, element)
5 changes: 5 additions & 0 deletions src/caselawclient/xquery_type_dicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class DocumentExistsDict(MarkLogicAPIDict):
uri: MarkLogicDocumentURIString


# get_history.xqy
class GetHistoryDict(MarkLogicAPIDict):
uri: MarkLogicDocumentURIString


# get_judgment.xqy
class GetJudgmentDict(MarkLogicAPIDict):
show_unpublished: Optional[bool]
Expand Down

0 comments on commit 082e02b

Please sign in to comment.