ds-caselaw-marklogic-api-client 28.1.0__py3-none-any.whl → 28.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ds-caselaw-marklogic-api-client might be problematic. Click here for more details.

caselawclient/Client.py CHANGED
@@ -1217,3 +1217,7 @@ class MarklogicApiClient:
1217
1217
  ),
1218
1218
  )
1219
1219
  return IdentifierResolutions.from_marklogic_output(raw_results)
1220
+
1221
+ def get_next_document_sequence_number(self) -> int:
1222
+ """Increment the MarkLogic sequence number by one and return the value."""
1223
+ return int(self._eval_and_decode({}, "get_next_document_sequence_number.xqy"))
@@ -15,6 +15,7 @@ from caselawclient.errors import (
15
15
  NotSupportedOnVersion,
16
16
  OnlySupportedOnVersion,
17
17
  )
18
+ from caselawclient.models.identifiers.fclid import FindCaseLawIdentifier, FindCaseLawIdentifierSchema
18
19
  from caselawclient.models.identifiers.unpacker import unpack_all_identifiers_from_etree
19
20
  from caselawclient.models.utilities import VersionsDict, extract_version, render_versions
20
21
  from caselawclient.models.utilities.aws import (
@@ -432,6 +433,12 @@ class Document:
432
433
  if not self.is_publishable:
433
434
  raise CannotPublishUnpublishableDocument
434
435
 
436
+ ## If it doesn't already have one, get a new FCLID for this document and assign
437
+ if len(self.identifiers.of_type(FindCaseLawIdentifier)) < 1:
438
+ document_fclid = FindCaseLawIdentifierSchema.mint(self.api_client)
439
+ self.identifiers.add(document_fclid)
440
+ self.save_identifiers()
441
+
435
442
  publish_documents(uri_for_s3(self.uri))
436
443
  self.api_client.set_published(self.uri, True)
437
444
  announce_document_event(
@@ -127,6 +127,11 @@ class Identifiers(dict[str, Identifier]):
127
127
  else:
128
128
  super().__delitem__(key)
129
129
 
130
+ def of_type(self, identifier_type: type[Identifier]) -> list[Identifier]:
131
+ """Return a list of all identifiers of a given type."""
132
+ uuids = self.keys()
133
+ return [self[uuid] for uuid in list(uuids) if isinstance(self[uuid], identifier_type)]
134
+
130
135
  def delete_type(self, deleted_identifier_type: type[Identifier]) -> None:
131
136
  "For when we want an identifier to be the only valid identifier of that type, delete the others first"
132
137
  uuids = self.keys()
@@ -0,0 +1,48 @@
1
+ import re
2
+ from typing import TYPE_CHECKING
3
+
4
+ from sqids import Sqids
5
+
6
+ from . import Identifier, IdentifierSchema
7
+
8
+ if TYPE_CHECKING:
9
+ from caselawclient.Client import MarklogicApiClient
10
+
11
+
12
+ VALID_FCLID_PATTERN = re.compile(r"^[bcdfghjkmnpqrstvwxyz23456789]{4,}$")
13
+
14
+ FCLID_MINIMUM_LENGTH = 8
15
+ FCLID_ALPHABET = "bcdfghjkmnpqrstvwxyz23456789"
16
+
17
+ sqids = Sqids(
18
+ min_length=FCLID_MINIMUM_LENGTH,
19
+ alphabet=FCLID_ALPHABET,
20
+ )
21
+
22
+
23
+ class FindCaseLawIdentifierSchema(IdentifierSchema):
24
+ """
25
+ Identifier schema describing a Find Case Law Identifier.
26
+ """
27
+
28
+ name = "Find Case Law Identifier"
29
+ namespace = "fclid"
30
+
31
+ @classmethod
32
+ def validate_identifier(cls, value: str) -> bool:
33
+ return bool(VALID_FCLID_PATTERN.match(value))
34
+
35
+ @classmethod
36
+ def compile_identifier_url_slug(cls, value: str) -> str:
37
+ return "tna." + value
38
+
39
+ @classmethod
40
+ def mint(cls, api_client: "MarklogicApiClient") -> "FindCaseLawIdentifier":
41
+ """Generate a totally new Find Case Law identifier."""
42
+ next_sequence_number = api_client.get_next_document_sequence_number()
43
+ new_identifier = sqids.encode([next_sequence_number])
44
+ return FindCaseLawIdentifier(value=new_identifier)
45
+
46
+
47
+ class FindCaseLawIdentifier(Identifier):
48
+ schema = FindCaseLawIdentifierSchema
@@ -3,9 +3,11 @@ from typing import Optional
3
3
  from lxml import etree
4
4
 
5
5
  from . import IDENTIFIER_UNPACKABLE_ATTRIBUTES, Identifier, Identifiers, InvalidIdentifierXMLRepresentationException
6
+ from .fclid import FindCaseLawIdentifier
6
7
  from .neutral_citation import NeutralCitationNumber
7
8
 
8
9
  IDENTIFIER_NAMESPACE_MAP: dict[str, type[Identifier]] = {
10
+ "fclid": FindCaseLawIdentifier,
9
11
  "ukncn": NeutralCitationNumber,
10
12
  }
11
13
 
@@ -0,0 +1,14 @@
1
+ xquery version "1.0-ml";
2
+ declare option xdmp:transaction-mode "update";
3
+
4
+ let $_ := xdmp:set-transaction-mode("update")
5
+ let $state_doc := fn:doc("state.xml")
6
+ let $counter_node := $state_doc/state/document_counter
7
+
8
+ let $current_counter := $counter_node/text()
9
+ let $new_counter := fn:sum(($current_counter, 1))
10
+
11
+ let $_ := xdmp:node-replace($counter_node, <document_counter>{$new_counter}</document_counter>)
12
+ let $_ := xdmp:commit()
13
+
14
+ return $new_counter
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ds-caselaw-marklogic-api-client
3
- Version: 28.1.0
3
+ Version: 28.2.0
4
4
  Summary: An API client for interacting with the underlying data in Find Caselaw.
5
5
  Home-page: https://github.com/nationalarchives/ds-caselaw-custom-api-client
6
6
  Keywords: national archives,caselaw
@@ -11,7 +11,7 @@ Classifier: Programming Language :: Python :: 3.9
11
11
  Classifier: Programming Language :: Python :: 3.10
12
12
  Classifier: Programming Language :: Python :: 3.11
13
13
  Requires-Dist: boto3 (>=1.26.112,<2.0.0)
14
- Requires-Dist: certifi (>=2024.8.30,<2024.9.0)
14
+ Requires-Dist: certifi (>=2024.12.14,<2024.13.0)
15
15
  Requires-Dist: charset-normalizer (>=3.0.0,<4.0.0)
16
16
  Requires-Dist: django-environ (>=0.11.0,<0.12.0)
17
17
  Requires-Dist: ds-caselaw-utils (>=2.0.0,<3.0.0)
@@ -25,6 +25,7 @@ Requires-Dist: pytz (>=2024.1,<2025.0)
25
25
  Requires-Dist: requests (>=2.28.2,<3.0.0)
26
26
  Requires-Dist: requests-toolbelt (>=0.10.1,<1.1.0)
27
27
  Requires-Dist: saxonche (>=12.5.0,<13.0.0)
28
+ Requires-Dist: sqids (>=0.5.0,<0.6.0)
28
29
  Requires-Dist: typing-extensions (>=4.7.1,<5.0.0)
29
30
  Description-Content-Type: text/markdown
30
31
 
@@ -1,4 +1,4 @@
1
- caselawclient/Client.py,sha256=OFqiKNYuz8C7UF6AP36Bie64UP3p8mKLZ-NQIc_LEWc,43636
1
+ caselawclient/Client.py,sha256=6BaVpKSvMcNhSaDXzTkN1h4iV7KFrY7SgSHNGqGQ_2o,43863
2
2
  caselawclient/__init__.py,sha256=DY-caubLDQWWingSdsBWgovDNXh8KcnkI6kwz08eIFk,612
3
3
  caselawclient/client_helpers/__init__.py,sha256=fyDNKCdrTb2N0Ks23YDhmvlXKfLTHnYQCXhnZb-QQbg,3832
4
4
  caselawclient/client_helpers/search_helpers.py,sha256=R99HyRLeYHgsw2L3DOidEqlKLLvs6Tga5rKTuWQViig,1525
@@ -7,15 +7,16 @@ caselawclient/errors.py,sha256=tV0vs3wYSd331BzmfuRiZV6GAdsd91rtN65ymRaSx3s,3164
7
7
  caselawclient/factories.py,sha256=6-xZMVmvtXA8AnyWJgJTums1EWfM6lPIhrWQu0NopJo,4472
8
8
  caselawclient/identifier_resolution.py,sha256=IOqrZcIHoHhNOCAkNveOBcWddBNpkOB8cz1r0zFa8mQ,1829
9
9
  caselawclient/models/__init__.py,sha256=kd23EUpvaC7aLHdgk8farqKAQEx3lf7RvNT2jEatvlg,68
10
- caselawclient/models/documents/__init__.py,sha256=OF-0tTSA5VO6qi630zONrL2lC768yTkwHWmNyRxZ_D8,18762
10
+ caselawclient/models/documents/__init__.py,sha256=DS2jqj4ShRHxAWIqQeeyCCcXctLor4xUvT3sc903D2E,19186
11
11
  caselawclient/models/documents/body.py,sha256=mtdjmG1WU2qSpyRLS8-PWcSoXpDa2Qz6xlcTbxZgxvA,5603
12
12
  caselawclient/models/documents/exceptions.py,sha256=rw1xId16vBKvBImgFmFUpeFgKqU7VTNtVLIEVBPGKyk,374
13
13
  caselawclient/models/documents/statuses.py,sha256=Cp4dTQmJOtsU41EJcxy5dV1841pGD2PNWH0VrkDEv4Q,579
14
14
  caselawclient/models/documents/transforms/html.xsl,sha256=oSSO-IBX4qLiSWexQYmWJfGNevF09aCBx4D1NYqXxpo,38322
15
15
  caselawclient/models/documents/xml.py,sha256=HlmPb63lLMnySSOLP4iexcAyQiLByKBZtTd25f8sY8M,1268
16
- caselawclient/models/identifiers/__init__.py,sha256=Ft0cFE7LlCecsS5In_hi9So0x6La1kRJ8Who-VgC4YM,4795
16
+ caselawclient/models/identifiers/__init__.py,sha256=CxKu5iZqPb6BOjrQ3upkzyjU3YSsJhBZd7VATYxDI-A,5061
17
+ caselawclient/models/identifiers/fclid.py,sha256=pAxZKKlKRSHwJqrEHOSlbuCt3gBOgS3sNv98bBjuNBc,1295
17
18
  caselawclient/models/identifiers/neutral_citation.py,sha256=yddlfumdnkrNpoTIOf8dB1foA7hE41-zmlfa17-Ulug,1790
18
- caselawclient/models/identifiers/unpacker.py,sha256=V79m4rd0FZx5TRueL1m3MbrSUWO8c0f5NoNxSP3dlFw,1757
19
+ caselawclient/models/identifiers/unpacker.py,sha256=01gWWlOd_2PxT1GJzOIXbp0G4iGGIxHaTaJMBOQ1TDs,1834
19
20
  caselawclient/models/judgments.py,sha256=NVOg4ZTU7Jtr33UuswL2TXCaN6_W0fKFPK4EdQ-jUhE,1915
20
21
  caselawclient/models/neutral_citation_mixin.py,sha256=5ktKCPIDidVRwxVTzx5e242O1BxOdP--1dnatZyTbYI,1773
21
22
  caselawclient/models/press_summaries.py,sha256=06flQ8wSLnNxoQtXO0ckmotFKszYZcub0oPcDzYbVQw,1879
@@ -45,6 +46,7 @@ caselawclient/xquery/get_judgment.xqy,sha256=8V-sEFKmtpf2LIZD9QKVRfpblEsmDpP4BA6
45
46
  caselawclient/xquery/get_judgment_checkout_status.xqy,sha256=mdY9UXLyzQdB7byEERPqentlr0YDLbXRVqH0h4UuZTQ,193
46
47
  caselawclient/xquery/get_judgment_version.xqy,sha256=wF9k9-CBrqo8VbxxyTrD-AGzR3-3jMm25tRVCjxPLrU,292
47
48
  caselawclient/xquery/get_last_modified.xqy,sha256=8fCm_7o_kkytCEmEeSTLWzLP7iOjuPV01IfHDgf6HaQ,172
49
+ caselawclient/xquery/get_next_document_sequence_number.xqy,sha256=LkGoaS7jZfaKDuZLi0apP5qHP1rpcM1HbqX3RUwquKY,450
48
50
  caselawclient/xquery/get_pending_enrichment_for_version.xqy,sha256=8J5Pi-jMXJd_BgtpK4g6C9uR99HP57JpFv5WkoPfNuo,2016
49
51
  caselawclient/xquery/get_pending_parse_for_version.xqy,sha256=9cjVZtHeBBjm-a7RMsn1PVJt_Ug78YFlmp5CN8VJ1jQ,1197
50
52
  caselawclient/xquery/get_properties_for_search_results.xqy,sha256=Tlv3EKwVV_q-JyQyhjWVHIleicPDpucxP4ScuQjpgSw,625
@@ -75,7 +77,7 @@ caselawclient/xquery/validate_document.xqy,sha256=PgaDcnqCRJPIVqfmWsNlXmCLNKd21q
75
77
  caselawclient/xquery/xslt.xqy,sha256=w57wNijH3dkwHkpKeAxqjlghVflQwo8cq6jS_sm-erM,199
76
78
  caselawclient/xquery/xslt_transform.xqy,sha256=smyFFxqmtkuOzBd2l7uw6K2oAsYctudrP8omdv_XNAM,2463
77
79
  caselawclient/xquery_type_dicts.py,sha256=kybL-YzwK34Fr6MeWfqVOJHYrs0ZNeDWXDsp8o2Yb1U,6114
78
- ds_caselaw_marklogic_api_client-28.1.0.dist-info/LICENSE.md,sha256=fGMzyyLuQW-IAXUeDSCrRdsYW536aEWThdbpCjo6ZKg,1108
79
- ds_caselaw_marklogic_api_client-28.1.0.dist-info/METADATA,sha256=e9Z30AABT4vao0GmVnuD8LPfK2dRXHXkBltukUpNzVM,4232
80
- ds_caselaw_marklogic_api_client-28.1.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
81
- ds_caselaw_marklogic_api_client-28.1.0.dist-info/RECORD,,
80
+ ds_caselaw_marklogic_api_client-28.2.0.dist-info/LICENSE.md,sha256=fGMzyyLuQW-IAXUeDSCrRdsYW536aEWThdbpCjo6ZKg,1108
81
+ ds_caselaw_marklogic_api_client-28.2.0.dist-info/METADATA,sha256=i7v85V8SC6lm8oYboo4aGxSmVVaO4QZwj3WVSWDU5Cs,4272
82
+ ds_caselaw_marklogic_api_client-28.2.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
83
+ ds_caselaw_marklogic_api_client-28.2.0.dist-info/RECORD,,