ITK-dev-shared-components 1.1.0__tar.gz → 1.3.0__tar.gz
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.
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/PKG-INFO +9 -2
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/README.md +8 -0
- itk_dev_shared_components-1.3.0/itk_dev_shared_components/kmd_nova/__init__.py +3 -0
- itk_dev_shared_components-1.3.0/itk_dev_shared_components/kmd_nova/authentication.py +59 -0
- itk_dev_shared_components-1.3.0/itk_dev_shared_components/kmd_nova/cpr.py +36 -0
- itk_dev_shared_components-1.3.0/itk_dev_shared_components/kmd_nova/nova_cases.py +228 -0
- itk_dev_shared_components-1.3.0/itk_dev_shared_components/kmd_nova/nova_documents.py +189 -0
- itk_dev_shared_components-1.3.0/itk_dev_shared_components/kmd_nova/nova_objects.py +77 -0
- itk_dev_shared_components-1.3.0/itk_dev_shared_components/kmd_nova/nova_tasks.py +138 -0
- itk_dev_shared_components-1.3.0/itk_dev_shared_components/kmd_nova/util.py +36 -0
- itk_dev_shared_components-1.3.0/itk_dev_shared_components/misc/cpr_util.py +58 -0
- itk_dev_shared_components-1.3.0/itk_dev_shared_components/sap/__init__.py +0 -0
- itk_dev_shared_components-1.3.0/itk_dev_shared_components/sap/fmcacov.py +76 -0
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/itk_dev_shared_components/sap/gridview_util.py +3 -1
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/itk_dev_shared_components/sap/opret_kundekontakt.py +2 -6
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/itk_dev_shared_components/sap/sap_login.py +0 -52
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/itk_dev_shared_components.egg-info/PKG-INFO +10 -3
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/itk_dev_shared_components.egg-info/SOURCES.txt +11 -0
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/itk_dev_shared_components.egg-info/requires.txt +0 -1
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/pyproject.toml +1 -2
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/LICENSE +0 -0
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/itk_dev_shared_components/__init__.py +0 -0
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/itk_dev_shared_components/graph/__init__.py +0 -0
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/itk_dev_shared_components/graph/authentication.py +0 -0
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/itk_dev_shared_components/graph/mail.py +0 -0
- {itk_dev_shared_components-1.1.0/itk_dev_shared_components/sap → itk_dev_shared_components-1.3.0/itk_dev_shared_components/misc}/__init__.py +0 -0
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/itk_dev_shared_components/sap/multi_session.py +0 -0
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/itk_dev_shared_components/sap/sap_util.py +0 -0
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/itk_dev_shared_components/sap/tree_util.py +0 -0
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/itk_dev_shared_components.egg-info/dependency_links.txt +0 -0
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/itk_dev_shared_components.egg-info/top_level.txt +0 -0
- {itk_dev_shared_components-1.1.0 → itk_dev_shared_components-1.3.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: itk_dev_shared_components
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.0
|
|
4
4
|
Summary: Shared components to use in RPA projects
|
|
5
5
|
Author-email: ITK Development <itk-rpa@mkb.aarhus.dk>
|
|
6
6
|
Project-URL: Homepage, https://github.com/itk-dev-rpa/itk-dev-shared-components
|
|
@@ -12,7 +12,6 @@ Requires-Python: >=3.7
|
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
Requires-Dist: pywin32>=306
|
|
15
|
-
Requires-Dist: selenium>=4.10.0
|
|
16
15
|
Requires-Dist: msal>=1.24.1
|
|
17
16
|
Requires-Dist: requests>=2.31.0
|
|
18
17
|
Requires-Dist: beautifulsoup4>=4.12.2
|
|
@@ -56,3 +55,11 @@ Some examples are:
|
|
|
56
55
|
- List and get emails.
|
|
57
56
|
- Get attachment data.
|
|
58
57
|
- Move and delete emails.
|
|
58
|
+
|
|
59
|
+
### KMD Nova
|
|
60
|
+
|
|
61
|
+
Helper functions for using the KMD Nova api.
|
|
62
|
+
Some examples are:
|
|
63
|
+
|
|
64
|
+
- Get cases and documents.
|
|
65
|
+
- Create cases, documents and tasks.
|
|
@@ -37,3 +37,11 @@ Some examples are:
|
|
|
37
37
|
- List and get emails.
|
|
38
38
|
- Get attachment data.
|
|
39
39
|
- Move and delete emails.
|
|
40
|
+
|
|
41
|
+
### KMD Nova
|
|
42
|
+
|
|
43
|
+
Helper functions for using the KMD Nova api.
|
|
44
|
+
Some examples are:
|
|
45
|
+
|
|
46
|
+
- Get cases and documents.
|
|
47
|
+
- Create cases, documents and tasks.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""This module contains functionality to authenticate against the KMD Nova api."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime, timedelta
|
|
4
|
+
import urllib
|
|
5
|
+
|
|
6
|
+
import requests
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# pylint: disable-next=too-few-public-methods
|
|
10
|
+
class NovaAccess:
|
|
11
|
+
"""An object that handles access to the KMD Nova api."""
|
|
12
|
+
def __init__(self, client_id: str, client_secret: str, domain: str = "https://cap-novaapi.kmd.dk") -> None:
|
|
13
|
+
self.client_id = client_id
|
|
14
|
+
self.client_secret = client_secret
|
|
15
|
+
self._bearer_token, self.token_expiry_date = self._get_new_token()
|
|
16
|
+
self.domain = domain
|
|
17
|
+
|
|
18
|
+
def _get_new_token(self) -> tuple[str, datetime]:
|
|
19
|
+
"""
|
|
20
|
+
This method requests a new token from the API.
|
|
21
|
+
When the token expiry date is passed, requests with the token to the API will return HTTP 401 status code.
|
|
22
|
+
|
|
23
|
+
Returns:
|
|
24
|
+
tuple: token and expiry datetime
|
|
25
|
+
|
|
26
|
+
Raises:
|
|
27
|
+
requests.exceptions.HTTPError: If the request failed.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
url = "https://novaauth.kmd.dk/realms/NovaIntegration/protocol/openid-connect/token"
|
|
31
|
+
payload = {
|
|
32
|
+
"client_secret": self.client_secret,
|
|
33
|
+
"grant_type": "client_credentials",
|
|
34
|
+
"client_id": self.client_id,
|
|
35
|
+
"scope": "client"
|
|
36
|
+
}
|
|
37
|
+
payload = urllib.parse.urlencode(payload)
|
|
38
|
+
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
|
|
39
|
+
|
|
40
|
+
response = requests.post(url, headers=headers, data=payload, timeout=60)
|
|
41
|
+
response.raise_for_status()
|
|
42
|
+
response_json = response.json()
|
|
43
|
+
bearer_token = response_json['access_token']
|
|
44
|
+
token_life_seconds = response_json['expires_in']
|
|
45
|
+
token_expiry_date = datetime.now() + timedelta(seconds=int(token_life_seconds))
|
|
46
|
+
return bearer_token, token_expiry_date
|
|
47
|
+
|
|
48
|
+
def get_bearer_token(self) -> str:
|
|
49
|
+
"""Return the bearer token. If the token is about to expire,
|
|
50
|
+
a new token is requested form the auth service.
|
|
51
|
+
|
|
52
|
+
Returns:
|
|
53
|
+
Bearer token
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
if self.token_expiry_date + timedelta(seconds=30) < datetime.now():
|
|
57
|
+
self._bearer_token, self.token_expiry_date = self._get_new_token()
|
|
58
|
+
|
|
59
|
+
return self._bearer_token
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""This module has functions to do with cpr related calls
|
|
2
|
+
to the KMD Nova api."""
|
|
3
|
+
|
|
4
|
+
import uuid
|
|
5
|
+
import urllib.parse
|
|
6
|
+
|
|
7
|
+
import requests
|
|
8
|
+
|
|
9
|
+
from itk_dev_shared_components.kmd_nova.authentication import NovaAccess
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def get_address_by_cpr(cpr: str, nova_access: NovaAccess) -> dict:
|
|
13
|
+
"""Gets the street address of a citizen by their CPR number.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
cpr: CPR number of the citizen.
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
A dict with the address information.
|
|
20
|
+
|
|
21
|
+
Raises:
|
|
22
|
+
requests.exceptions.HTTPError: If the request failed.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
url = urllib.parse.urljoin(nova_access.domain, "api/Cpr/GetAddressByCpr")
|
|
26
|
+
params = {
|
|
27
|
+
"TransactionId": str(uuid.uuid4()),
|
|
28
|
+
"Cpr": cpr,
|
|
29
|
+
"api-version": "1.0-Cpr"
|
|
30
|
+
}
|
|
31
|
+
headers = {'Authorization': f"Bearer {nova_access.get_bearer_token()}"}
|
|
32
|
+
|
|
33
|
+
response = requests.get(url, params=params, headers=headers, timeout=60)
|
|
34
|
+
response.raise_for_status()
|
|
35
|
+
address = response.json()
|
|
36
|
+
return address
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"""This module has functions to do with case related calls
|
|
2
|
+
to the KMD Nova api."""
|
|
3
|
+
|
|
4
|
+
import uuid
|
|
5
|
+
import base64
|
|
6
|
+
import urllib.parse
|
|
7
|
+
|
|
8
|
+
import requests
|
|
9
|
+
|
|
10
|
+
from itk_dev_shared_components.kmd_nova.authentication import NovaAccess
|
|
11
|
+
from itk_dev_shared_components.kmd_nova.nova_objects import NovaCase, CaseParty, JournalNote
|
|
12
|
+
from itk_dev_shared_components.kmd_nova.util import datetime_from_iso_string
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def get_cases(nova_access: NovaAccess, cpr: str = None, case_number: str = None, case_title: str = None, limit: int = 100) -> list[NovaCase]:
|
|
16
|
+
"""Search for cases on different search terms.
|
|
17
|
+
Currently supports search on cpr number, case number and case title. At least one search term must be given.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
nova_access: The NovaAccess object used to authenticate.
|
|
21
|
+
cpr: The cpr number to search on. E.g. "0123456789"
|
|
22
|
+
case_number: The case number to search on. E.g. "S2022-12345"
|
|
23
|
+
case_title: The case title to search on.
|
|
24
|
+
limit: The maximum number of cases to find (1-500).
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
A list of NovaCase objects.
|
|
28
|
+
|
|
29
|
+
Raises:
|
|
30
|
+
ValueError: If no search terms are given.
|
|
31
|
+
requests.exceptions.HTTPError: If the request failed.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
if not any((cpr, case_number, case_title)):
|
|
35
|
+
raise ValueError("No search terms given.")
|
|
36
|
+
|
|
37
|
+
url = urllib.parse.urljoin(nova_access.domain, "api/Case/GetList")
|
|
38
|
+
params = {"api-version": "1.0-Case"}
|
|
39
|
+
|
|
40
|
+
payload = {
|
|
41
|
+
"common": {
|
|
42
|
+
"transactionId": str(uuid.uuid4())
|
|
43
|
+
},
|
|
44
|
+
"paging": {
|
|
45
|
+
"startRow": 1,
|
|
46
|
+
"numberOfRows": limit
|
|
47
|
+
},
|
|
48
|
+
"caseAttributes": {
|
|
49
|
+
"userFriendlyCaseNumber": case_number,
|
|
50
|
+
"title": case_title
|
|
51
|
+
},
|
|
52
|
+
"caseParty": {
|
|
53
|
+
"identificationType": "CprNummer",
|
|
54
|
+
"identification": cpr
|
|
55
|
+
},
|
|
56
|
+
"caseGetOutput": {
|
|
57
|
+
"numberOfSecondaryParties": True,
|
|
58
|
+
"caseParty": {
|
|
59
|
+
"identificationType": True,
|
|
60
|
+
"identification": True,
|
|
61
|
+
"participantRole": True,
|
|
62
|
+
"name": True,
|
|
63
|
+
"index": True
|
|
64
|
+
},
|
|
65
|
+
"caseAttributes": {
|
|
66
|
+
"title": True,
|
|
67
|
+
"userFriendlyCaseNumber": True,
|
|
68
|
+
"caseDate": True
|
|
69
|
+
},
|
|
70
|
+
"state": {
|
|
71
|
+
"activeCode": True,
|
|
72
|
+
"progressState": True
|
|
73
|
+
},
|
|
74
|
+
"numberOfDocuments": True,
|
|
75
|
+
"numberOfJournalNotes": True,
|
|
76
|
+
"caseClassification": {
|
|
77
|
+
"kleNumber": {
|
|
78
|
+
"code": True
|
|
79
|
+
},
|
|
80
|
+
"proceedingFacet": {
|
|
81
|
+
"code": True
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"sensitivity": {
|
|
85
|
+
"sensitivity": True
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
headers = {'Content-Type': 'application/json', 'Authorization': f"Bearer {nova_access.get_bearer_token()}"}
|
|
91
|
+
|
|
92
|
+
response = requests.put(url, params=params, headers=headers, json=payload, timeout=60)
|
|
93
|
+
response.raise_for_status()
|
|
94
|
+
|
|
95
|
+
if response.json()['pagingInformation']['numberOfRows'] == 0:
|
|
96
|
+
return []
|
|
97
|
+
|
|
98
|
+
# Convert json to NovaCase objects
|
|
99
|
+
cases = []
|
|
100
|
+
for case_dict in response.json()['cases']:
|
|
101
|
+
case = NovaCase(
|
|
102
|
+
uuid = case_dict['common']['uuid'],
|
|
103
|
+
title = case_dict['caseAttributes']['title'],
|
|
104
|
+
case_date = datetime_from_iso_string(case_dict['caseAttributes']['caseDate']),
|
|
105
|
+
case_number = case_dict['caseAttributes']['userFriendlyCaseNumber'],
|
|
106
|
+
active_code = case_dict['state']['activeCode'],
|
|
107
|
+
progress_state = case_dict['state']['progressState'],
|
|
108
|
+
case_parties = _extract_case_parties(case_dict),
|
|
109
|
+
document_count = case_dict['numberOfDocuments'],
|
|
110
|
+
note_count = case_dict['numberOfJournalNotes'],
|
|
111
|
+
kle_number = case_dict['caseClassification']['kleNumber']['code'],
|
|
112
|
+
proceeding_facet = case_dict['caseClassification']['proceedingFacet']['code'],
|
|
113
|
+
sensitivity = case_dict["sensitivity"]["sensitivity"]
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
cases.append(case)
|
|
117
|
+
|
|
118
|
+
return cases
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _extract_case_parties(case_dict: dict) -> list[CaseParty]:
|
|
122
|
+
"""Extract the case parties from a HTTP request response.
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
case_dict: The dictionary describing the case party.
|
|
126
|
+
|
|
127
|
+
Returns:
|
|
128
|
+
A case party object describing the case party.
|
|
129
|
+
"""
|
|
130
|
+
parties = []
|
|
131
|
+
for party_dict in case_dict['caseParties']:
|
|
132
|
+
party = CaseParty(
|
|
133
|
+
uuid = party_dict['index'],
|
|
134
|
+
identification_type = party_dict['identificationType'],
|
|
135
|
+
identification = party_dict['identification'],
|
|
136
|
+
role = party_dict['participantRole'],
|
|
137
|
+
name = party_dict.get('name', None)
|
|
138
|
+
)
|
|
139
|
+
parties.append(party)
|
|
140
|
+
|
|
141
|
+
return parties
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _extract_journal_notes(case_dict: dict) -> list:
|
|
145
|
+
"""Extract the journal notes from a HTTP request response.
|
|
146
|
+
|
|
147
|
+
Args:
|
|
148
|
+
case_dict: The dictionary describing the journal note.
|
|
149
|
+
|
|
150
|
+
Returns:
|
|
151
|
+
A journal note object describing the journal note.
|
|
152
|
+
"""
|
|
153
|
+
notes = []
|
|
154
|
+
for note_dict in case_dict['journalNotes']['journalNotes']:
|
|
155
|
+
note = JournalNote(
|
|
156
|
+
uuid = note_dict['uuid'],
|
|
157
|
+
title = note_dict['journalNoteAttributes']['title'],
|
|
158
|
+
journal_date = note_dict['journalNoteAttributes']['journalNoteDate'],
|
|
159
|
+
note_format = note_dict['journalNoteAttributes']['format'],
|
|
160
|
+
note = base64.b64decode(note_dict['journalNoteAttributes']['note']),
|
|
161
|
+
approved = note_dict['journalNoteAttributes'].get('approved', False)
|
|
162
|
+
)
|
|
163
|
+
notes.append(note)
|
|
164
|
+
return notes
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def add_case(case: NovaCase, nova_access: NovaAccess, security_unit_id: int = 818485, security_unit_name: str = "Borgerservice"):
|
|
168
|
+
"""Add a case to KMD Nova. The case will be created as 'Active'.
|
|
169
|
+
|
|
170
|
+
Args:
|
|
171
|
+
case: The case object describing the case.
|
|
172
|
+
nova_access: The NovaAccess object used to authenticate.
|
|
173
|
+
security_unit_id: The id of the security unit that has access to the case. Defaults to 818485.
|
|
174
|
+
security_unit_name: The name of the security unit that has access to the case. Defaults to "Borgerservice".
|
|
175
|
+
|
|
176
|
+
Raises:
|
|
177
|
+
requests.exceptions.HTTPError: If the request failed.
|
|
178
|
+
"""
|
|
179
|
+
url = urllib.parse.urljoin(nova_access.domain, "api/Case/Import")
|
|
180
|
+
params = {"api-version": "1.0-Case"}
|
|
181
|
+
|
|
182
|
+
payload = {
|
|
183
|
+
"common": {
|
|
184
|
+
"transactionId": str(uuid.uuid4()),
|
|
185
|
+
"uuid": case.uuid
|
|
186
|
+
},
|
|
187
|
+
"caseAttributes": {
|
|
188
|
+
"title": case.title,
|
|
189
|
+
"caseDate": case.case_date.isoformat()
|
|
190
|
+
},
|
|
191
|
+
"caseClassification": {
|
|
192
|
+
"kleNumber": {
|
|
193
|
+
"code": case.kle_number
|
|
194
|
+
},
|
|
195
|
+
"proceedingFacet": {
|
|
196
|
+
"code": case.proceeding_facet
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
"state": case.progress_state,
|
|
200
|
+
"sensitivity": case.sensitivity,
|
|
201
|
+
"caseParties": [
|
|
202
|
+
{
|
|
203
|
+
"name": party.name,
|
|
204
|
+
"identificationType": party.identification_type,
|
|
205
|
+
"identification": party.identification,
|
|
206
|
+
"participantRole": party.role
|
|
207
|
+
} for party in case.case_parties
|
|
208
|
+
],
|
|
209
|
+
"securityUnit": {
|
|
210
|
+
"losIdentity": {
|
|
211
|
+
"administrativeUnitId": security_unit_id,
|
|
212
|
+
"fullName": security_unit_name,
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
"SensitivityCtrlBy": "Bruger",
|
|
216
|
+
"SecurityUnitCtrlBy": "Regler",
|
|
217
|
+
"ResponsibleDepartmentCtrlBy": "Regler",
|
|
218
|
+
"caseAvailability": {
|
|
219
|
+
"unit": "År",
|
|
220
|
+
"scale": 5
|
|
221
|
+
},
|
|
222
|
+
"AvailabilityCtrlBy": "Regler"
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
headers = {'Content-Type': 'application/json', 'Authorization': f"Bearer {nova_access.get_bearer_token()}"}
|
|
226
|
+
|
|
227
|
+
response = requests.post(url, params=params, headers=headers, json=payload, timeout=60)
|
|
228
|
+
response.raise_for_status()
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""This module has functions to do with document related calls
|
|
2
|
+
to the KMD Nova api."""
|
|
3
|
+
|
|
4
|
+
import uuid
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
import mimetypes
|
|
7
|
+
from typing import BinaryIO
|
|
8
|
+
import urllib.parse
|
|
9
|
+
|
|
10
|
+
import requests
|
|
11
|
+
|
|
12
|
+
from itk_dev_shared_components.kmd_nova.authentication import NovaAccess
|
|
13
|
+
from itk_dev_shared_components.kmd_nova.nova_objects import Document
|
|
14
|
+
from itk_dev_shared_components.kmd_nova. util import datetime_from_iso_string
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def get_documents(case_uuid: str, nova_access: NovaAccess) -> list[Document]:
|
|
18
|
+
"""Get all documents attached to the given case.
|
|
19
|
+
To get the actual document file use download_document_file.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
case_uuid: The uuid of the case to get documents from.
|
|
23
|
+
nova_access: The NovaAccess object used to authenticate.
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
A list of Document objects describing the documents.
|
|
27
|
+
|
|
28
|
+
Raises:
|
|
29
|
+
requests.exceptions.HTTPError: If the request failed.
|
|
30
|
+
"""
|
|
31
|
+
url = urllib.parse.urljoin(nova_access.domain, "api/Document/GetList")
|
|
32
|
+
params = {"api-version": "1.0-Case"}
|
|
33
|
+
|
|
34
|
+
payload = {
|
|
35
|
+
"common": {
|
|
36
|
+
"transactionId": str(uuid.uuid4())
|
|
37
|
+
},
|
|
38
|
+
"caseUuid": case_uuid,
|
|
39
|
+
"getOutput": {
|
|
40
|
+
"title": True,
|
|
41
|
+
"sensitivity": True,
|
|
42
|
+
"documentType": True,
|
|
43
|
+
"description": True,
|
|
44
|
+
"approved": True,
|
|
45
|
+
"documentDate": True,
|
|
46
|
+
"fileExtension": True,
|
|
47
|
+
"documentCategory": True
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
headers = {'Content-Type': 'application/json', 'Authorization': f"Bearer {nova_access.get_bearer_token()}"}
|
|
52
|
+
|
|
53
|
+
response = requests.put(url, params=params, headers=headers, json=payload, timeout=60)
|
|
54
|
+
response.raise_for_status()
|
|
55
|
+
|
|
56
|
+
documents = []
|
|
57
|
+
for document_dict in response.json()['documents']:
|
|
58
|
+
doc = Document(
|
|
59
|
+
uuid = document_dict['documentUuid'],
|
|
60
|
+
document_number = document_dict['documentNumber'],
|
|
61
|
+
title = document_dict['title'],
|
|
62
|
+
sensitivity = document_dict['sensitivity'],
|
|
63
|
+
document_type = document_dict['documentType'],
|
|
64
|
+
description = document_dict.get('description', None),
|
|
65
|
+
approved = document_dict['approved'],
|
|
66
|
+
document_date = datetime_from_iso_string(document_dict['documentDate']),
|
|
67
|
+
file_extension = document_dict['fileExtension'],
|
|
68
|
+
category_name = document_dict.get('documentCategoryName'),
|
|
69
|
+
category_uuid = document_dict.get('documentCategoryUuid')
|
|
70
|
+
)
|
|
71
|
+
documents.append(doc)
|
|
72
|
+
|
|
73
|
+
return documents
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def download_document_file(document_uuid: str, nova_access: NovaAccess, checkout: bool = False, checkout_comment: str = None) -> bytes:
|
|
77
|
+
"""Download the file attached to a KMD Nova Document.
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
document_uuid: The uuid of the Nova document.
|
|
81
|
+
nova_access: The NovaAccess object used to authenticate.
|
|
82
|
+
checkout: Whether to mark the document as checked out. Defaults to False.
|
|
83
|
+
checkout_comment: A comment to the checkout. Defaults to None.
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
The document file as raw bytes.
|
|
87
|
+
|
|
88
|
+
Raises:
|
|
89
|
+
requests.exceptions.HTTPError: If the request failed.
|
|
90
|
+
"""
|
|
91
|
+
url = urllib.parse.urljoin(nova_access.domain, "api/Document/GetFile")
|
|
92
|
+
params = {"api-version": "1.0-Case"}
|
|
93
|
+
|
|
94
|
+
payload = {
|
|
95
|
+
"common": {
|
|
96
|
+
"transactionId": str(uuid.uuid4()),
|
|
97
|
+
"uuid": document_uuid
|
|
98
|
+
},
|
|
99
|
+
"checkOutDocument": checkout,
|
|
100
|
+
"checkOutComment": checkout_comment
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
headers = {'Content-Type': 'application/json', 'Authorization': f"Bearer {nova_access.get_bearer_token()}"}
|
|
104
|
+
response = requests.put(url, params=params, headers=headers, json=payload, timeout=60)
|
|
105
|
+
response.raise_for_status()
|
|
106
|
+
|
|
107
|
+
return response.content
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def upload_document(file: BinaryIO, file_name: str, nova_access: NovaAccess) -> str:
|
|
111
|
+
"""Upload a document to Nova. This only uploads the document file.
|
|
112
|
+
To attach the document to a case use attach_document_to_case after calling this.
|
|
113
|
+
The uuid returned should be used to create a new Document object.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
file: The file to upload as a file-like object in binary mode.
|
|
117
|
+
file_name: The name of the file including the file extension.
|
|
118
|
+
nova_access: The NovaAccess object used to authenticate.
|
|
119
|
+
|
|
120
|
+
Returns:
|
|
121
|
+
The uuid identifying the document in Nova.
|
|
122
|
+
|
|
123
|
+
Raises:
|
|
124
|
+
requests.exceptions.HTTPError: If the request failed.
|
|
125
|
+
"""
|
|
126
|
+
transaction_id = urllib.parse.quote(str(uuid.uuid4()))
|
|
127
|
+
document_id = urllib.parse.quote(str(uuid.uuid4()))
|
|
128
|
+
|
|
129
|
+
url = urllib.parse.urljoin(nova_access.domain, f"api/Document/UploadFile/{transaction_id}/{document_id}")
|
|
130
|
+
params = {"api-version": "1.0-Case"}
|
|
131
|
+
|
|
132
|
+
headers = {'Authorization': f"Bearer {nova_access.get_bearer_token()}", 'accept': '*/*'}
|
|
133
|
+
|
|
134
|
+
mime_type = mimetypes.guess_type(file_name)[0]
|
|
135
|
+
|
|
136
|
+
if mime_type is None:
|
|
137
|
+
mime_type = 'application/octet-stream'
|
|
138
|
+
|
|
139
|
+
files = {"file": (file_name, file, mime_type)}
|
|
140
|
+
response = requests.post(url, params=params, headers=headers, files=files, timeout=60)
|
|
141
|
+
|
|
142
|
+
response.raise_for_status()
|
|
143
|
+
|
|
144
|
+
return document_id
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def attach_document_to_case(case_uuid: str, document: Document, nova_access: NovaAccess, security_unit_id: int = 818485, security_unit_name: str = "Borgerservice") -> None:
|
|
148
|
+
"""Attach a document to a case in Nova.
|
|
149
|
+
The document file first needs to be uploaded using upload_document,
|
|
150
|
+
which also creates the document uuid.
|
|
151
|
+
|
|
152
|
+
Args:
|
|
153
|
+
case_uuid: The uuid of the case to attach the document to.
|
|
154
|
+
document: The document object to attach to the case.
|
|
155
|
+
nova_access: The NovaAccess object used to authenticate.
|
|
156
|
+
security_unit_id: The id of the security unit that has access to the document. Defaults to 818485.
|
|
157
|
+
security_unit_name: The name of the security unit that has access to the document. Defaults to "Borgerservice".
|
|
158
|
+
|
|
159
|
+
Raises:
|
|
160
|
+
requests.exceptions.HTTPError: If the request failed.
|
|
161
|
+
"""
|
|
162
|
+
url = urllib.parse.urljoin(nova_access.domain, "api/Document/Import")
|
|
163
|
+
params = {"api-version": "1.0-Case"}
|
|
164
|
+
|
|
165
|
+
payload = {
|
|
166
|
+
"common": {
|
|
167
|
+
"transactionId": str(uuid.uuid4()),
|
|
168
|
+
"uuid": document.uuid
|
|
169
|
+
},
|
|
170
|
+
"caseUuid": case_uuid,
|
|
171
|
+
"title": document.title,
|
|
172
|
+
"sensitivity": document.sensitivity,
|
|
173
|
+
"documentDate": datetime.now().isoformat(),
|
|
174
|
+
"documentType": document.document_type,
|
|
175
|
+
"description": document.description,
|
|
176
|
+
"documentCategoryUuid": document.category_uuid,
|
|
177
|
+
"securityUnit": {
|
|
178
|
+
"losIdentity": {
|
|
179
|
+
"administrativeUnitId": security_unit_id,
|
|
180
|
+
"fullName": security_unit_name,
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
"approved": document.approved,
|
|
184
|
+
"accessToDocuments": True
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
headers = {'Content-Type': 'application/json', 'Authorization': f"Bearer {nova_access.get_bearer_token()}"}
|
|
188
|
+
response = requests.post(url, params=params, headers=headers, json=payload, timeout=60)
|
|
189
|
+
response.raise_for_status()
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""This module contains dataclasses relating to KMD Nova cases."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Literal, Optional
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
# All classes in this module are pure dataclasses made to contain data.
|
|
8
|
+
# pylint: disable=too-many-instance-attributes
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(slots=True, kw_only=True)
|
|
12
|
+
class CaseParty:
|
|
13
|
+
"""A dataclass representing a case party in a KMD Nova case."""
|
|
14
|
+
uuid: Optional[str] = None
|
|
15
|
+
role: Literal["Primær", "Sekundær"]
|
|
16
|
+
identification_type: Literal["CprNummer", "CvrNummer", "Frit", "PNummer", "EsrNummer", "BfeNummer"]
|
|
17
|
+
identification: str
|
|
18
|
+
name: Optional[str] = None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass(slots=True, kw_only=True)
|
|
22
|
+
class Document:
|
|
23
|
+
"""A dataclass representing a KMD Nova Document."""
|
|
24
|
+
uuid: str
|
|
25
|
+
title: str
|
|
26
|
+
sensitivity: Literal["Fortrolige", "IkkeFortrolige", "SærligFølsomme", "Følsomme"]
|
|
27
|
+
document_type: Literal["Indgående", "Udgående", "Internt", "Dagsordenpunkt", "Dagsorden", "Referat", "Andet", "GisKort", "NovaDagsordenspunkt"]
|
|
28
|
+
description: str
|
|
29
|
+
approved: bool
|
|
30
|
+
document_number: Optional[str] = None
|
|
31
|
+
document_date: Optional[datetime] = None
|
|
32
|
+
file_extension: Optional[str] = None
|
|
33
|
+
category_name: Optional[str] = None
|
|
34
|
+
category_uuid: Optional[str] = None
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass(slots=True, kw_only=True)
|
|
38
|
+
class JournalNote:
|
|
39
|
+
"""A dataclass representing a KMD Nova journal note."""
|
|
40
|
+
uuid: str
|
|
41
|
+
title: str
|
|
42
|
+
journal_date: str
|
|
43
|
+
note_format: str
|
|
44
|
+
note: bytes
|
|
45
|
+
approved: bool
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@dataclass(slots=True, kw_only=True)
|
|
49
|
+
class Task:
|
|
50
|
+
"""A dataclass representing a KMD Nova task."""
|
|
51
|
+
uuid: str
|
|
52
|
+
title: str
|
|
53
|
+
description: Optional[str] = None
|
|
54
|
+
case_worker_ident: Optional[str] = None
|
|
55
|
+
case_worker_uuid: str
|
|
56
|
+
status_code: Literal['N', 'S', 'F'] # Not Started, Started, Finished
|
|
57
|
+
deadline: datetime
|
|
58
|
+
created_date: Optional[datetime] = None
|
|
59
|
+
started_date: Optional[datetime] = None
|
|
60
|
+
closed_date: Optional[datetime] = None
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@dataclass(slots=True, kw_only=True)
|
|
64
|
+
class NovaCase:
|
|
65
|
+
"""A dataclass representing a KMD Nova case."""
|
|
66
|
+
uuid: str
|
|
67
|
+
title: str
|
|
68
|
+
case_number: Optional[str] = None
|
|
69
|
+
case_date: datetime
|
|
70
|
+
active_code: Optional[str] = None
|
|
71
|
+
progress_state: Literal["Opstaaet", "Oplyst", "Afgjort", "Bestilt", "Udfoert", "Afsluttet"]
|
|
72
|
+
case_parties: list[CaseParty]
|
|
73
|
+
document_count: Optional[int] = 0
|
|
74
|
+
note_count: Optional[int] = 0
|
|
75
|
+
kle_number: str
|
|
76
|
+
proceeding_facet: str
|
|
77
|
+
sensitivity: Literal["Fortrolige", "IkkeFortrolige", "SærligFølsomme", "Følsomme"]
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""This module has functions to do with task related calls
|
|
2
|
+
to the KMD Nova api."""
|
|
3
|
+
import uuid
|
|
4
|
+
import urllib.parse
|
|
5
|
+
|
|
6
|
+
import requests
|
|
7
|
+
|
|
8
|
+
from itk_dev_shared_components.kmd_nova.authentication import NovaAccess
|
|
9
|
+
from itk_dev_shared_components.kmd_nova.nova_objects import Task
|
|
10
|
+
from itk_dev_shared_components.kmd_nova.util import datetime_from_iso_string, datetime_to_iso_string
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def attach_task_to_case(case_uuid: str, task: Task, nova_access: NovaAccess) -> None:
|
|
14
|
+
"""Attach a Task object to a case in Nova.
|
|
15
|
+
|
|
16
|
+
The Task object must have the following values set:
|
|
17
|
+
uuid, title, status_code, deadline, case_worker_uuid.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
case_uuid: The id of the case to attach the task to.
|
|
21
|
+
task: A Task object describing the task.
|
|
22
|
+
nova_access: The NovaAccess object used to authenticate.
|
|
23
|
+
|
|
24
|
+
Raises:
|
|
25
|
+
requests.exceptions.HTTPError: If the request failed.
|
|
26
|
+
"""
|
|
27
|
+
url = urllib.parse.urljoin(nova_access.domain, "api/Task/Import")
|
|
28
|
+
params = {"api-version": "1.0-Task"}
|
|
29
|
+
|
|
30
|
+
payload = {
|
|
31
|
+
"common": {
|
|
32
|
+
"transactionId": str(uuid.uuid4()),
|
|
33
|
+
"uuid": task.uuid
|
|
34
|
+
},
|
|
35
|
+
"caseUuid": case_uuid,
|
|
36
|
+
"title": task.title,
|
|
37
|
+
"description": task.description, # Optional
|
|
38
|
+
"caseworkerPersonId": task.case_worker_uuid, # Optional
|
|
39
|
+
"statusCode": task.status_code,
|
|
40
|
+
"deadline": datetime_to_iso_string(task.deadline),
|
|
41
|
+
"startDate": datetime_to_iso_string(task.started_date), # Optional
|
|
42
|
+
"closeDate": datetime_to_iso_string(task.closed_date), # Optional
|
|
43
|
+
"taskTypeName": "Aktivitet"
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
headers = {'Content-Type': 'application/json', 'Authorization': f"Bearer {nova_access.get_bearer_token()}"}
|
|
47
|
+
response = requests.post(url, params=params, headers=headers, json=payload, timeout=60)
|
|
48
|
+
response.raise_for_status()
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def get_tasks(case_uuid: str, nova_access: NovaAccess, limit: int = 100) -> list[Task]:
|
|
52
|
+
"""Get tasks attached to a case.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
case_uuid: The id of the case.
|
|
56
|
+
nova_access: The NovaAccess object used to authenticate.
|
|
57
|
+
limit: The max number of tasks to get. Defaults to 100.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
A list of Task objects.
|
|
61
|
+
|
|
62
|
+
Raises:
|
|
63
|
+
requests.exceptions.HTTPError: If the request failed.
|
|
64
|
+
"""
|
|
65
|
+
url = urllib.parse.urljoin(nova_access.domain, "api/Task/GetList")
|
|
66
|
+
params = {"api-version": "1.0-Task"}
|
|
67
|
+
|
|
68
|
+
payload = {
|
|
69
|
+
"common": {
|
|
70
|
+
"transactionId": str(uuid.uuid4())
|
|
71
|
+
},
|
|
72
|
+
"caseUuid": case_uuid,
|
|
73
|
+
"paging": {
|
|
74
|
+
"startRow": 1,
|
|
75
|
+
"numberOfRows": limit
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
headers = {'Content-Type': 'application/json', 'Authorization': f"Bearer {nova_access.get_bearer_token()}"}
|
|
80
|
+
response = requests.put(url, params=params, headers=headers, json=payload, timeout=60)
|
|
81
|
+
response.raise_for_status()
|
|
82
|
+
|
|
83
|
+
if 'taskList' not in response.json():
|
|
84
|
+
return []
|
|
85
|
+
|
|
86
|
+
tasks = []
|
|
87
|
+
for task_dict in response.json()['taskList']:
|
|
88
|
+
task = Task(
|
|
89
|
+
uuid = task_dict['taskUuid'],
|
|
90
|
+
title = task_dict['taskTitle'],
|
|
91
|
+
description = task_dict.get('taskDescription'),
|
|
92
|
+
case_worker_ident = task_dict['caseWorker']['ident'],
|
|
93
|
+
case_worker_uuid = task_dict['caseWorker']['id'],
|
|
94
|
+
status_code = task_dict['taskStatusCode'],
|
|
95
|
+
deadline = datetime_from_iso_string(task_dict.get('taskDeadline')),
|
|
96
|
+
created_date = datetime_from_iso_string(task_dict.get('taskCreateDate')),
|
|
97
|
+
started_date = datetime_from_iso_string(task_dict.get('taskStartDate')),
|
|
98
|
+
closed_date = datetime_from_iso_string(task_dict.get('taskCloseDate'))
|
|
99
|
+
)
|
|
100
|
+
tasks.append(task)
|
|
101
|
+
|
|
102
|
+
return tasks
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def update_task(task: Task, case_uuid: str, nova_access: NovaAccess):
|
|
106
|
+
"""Update a task that already exists in KMD Nova with new
|
|
107
|
+
information.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
task: The Task object describing the updated task.
|
|
111
|
+
case_uuid: The id of the case the task belongs to.
|
|
112
|
+
nova_access: The NovaAccess object used to authenticate.
|
|
113
|
+
|
|
114
|
+
Raises:
|
|
115
|
+
requests.exceptions.HTTPError: If the request failed.
|
|
116
|
+
"""
|
|
117
|
+
url = urllib.parse.urljoin(nova_access.domain, "api/Task/Update")
|
|
118
|
+
params = {"api-version": "1.0-Task"}
|
|
119
|
+
|
|
120
|
+
payload = {
|
|
121
|
+
"common": {
|
|
122
|
+
"transactionId": str(uuid.uuid4())
|
|
123
|
+
},
|
|
124
|
+
"uuid": task.uuid,
|
|
125
|
+
"caseUuid": case_uuid,
|
|
126
|
+
"title": task.title,
|
|
127
|
+
"description": task.description,
|
|
128
|
+
"caseworkerPersonId": task.case_worker_uuid,
|
|
129
|
+
"statusCode": task.status_code,
|
|
130
|
+
"deadline": datetime_to_iso_string(task.deadline),
|
|
131
|
+
"startDate": datetime_to_iso_string(task.started_date),
|
|
132
|
+
"closeDate": datetime_to_iso_string(task.closed_date),
|
|
133
|
+
"taskType": "Aktivitet"
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
headers = {'Content-Type': 'application/json', 'Authorization': f"Bearer {nova_access.get_bearer_token()}"}
|
|
137
|
+
response = requests.put(url, params=params, headers=headers, json=payload, timeout=60)
|
|
138
|
+
response.raise_for_status()
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""This module contains helper functions regarding the KMD Nova API."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def datetime_from_iso_string(date_string: Optional[str]) -> Optional[datetime]:
|
|
8
|
+
"""A helper function to convert an ISO date string to a datetime.
|
|
9
|
+
If the date string is None, None is returned.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
date_string: A date string in ISO format.
|
|
13
|
+
|
|
14
|
+
Returns:
|
|
15
|
+
A datetime object representing the date string.
|
|
16
|
+
"""
|
|
17
|
+
if not date_string:
|
|
18
|
+
return None
|
|
19
|
+
|
|
20
|
+
return datetime.fromisoformat(date_string)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def datetime_to_iso_string(datetime_: Optional[datetime]) -> Optional[str]:
|
|
24
|
+
"""A helper function to convert a datetime to an ISO formatted string.
|
|
25
|
+
If the the datetime is None, None is returned.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
datetime_: The datetime object to convert.
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
A datetime string in ISO format.
|
|
32
|
+
"""
|
|
33
|
+
if datetime_:
|
|
34
|
+
return datetime_.isoformat()
|
|
35
|
+
|
|
36
|
+
return None
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""This module contains helper functions regarding cpr numbers."""
|
|
2
|
+
|
|
3
|
+
from datetime import date
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def get_age(cpr: str, current_date: date = date.today()) -> int:
|
|
7
|
+
"""Get the age of a person based on their cpr number
|
|
8
|
+
using the 7th digit to infer the century.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
cpr: The cpr number in the format 'ddmmyyxxxx'.
|
|
12
|
+
current_date: The date where the age is calculated from. Defaults to the current date.
|
|
13
|
+
|
|
14
|
+
Returns:
|
|
15
|
+
The age in integer years based on the cpr number.
|
|
16
|
+
|
|
17
|
+
Raises:
|
|
18
|
+
ValueError: If the given cpr is not in 'ddmmyyxxxx' format.
|
|
19
|
+
"""
|
|
20
|
+
if len(cpr) != 10 or not cpr.isnumeric():
|
|
21
|
+
raise ValueError("The given CPR number is not in 'ddmmyyxxxx' format.")
|
|
22
|
+
|
|
23
|
+
# A dictionary mapping from a year (0-99) and control digit (0-9) to a century.
|
|
24
|
+
# https://cpr.dk/media/12066/personnummeret-i-cpr.pdf
|
|
25
|
+
# The keys of the dict corespond to the control digit.
|
|
26
|
+
# The first value of the tuples is the cutoff year. If the input year is equal to or below the first value
|
|
27
|
+
# the first century is used. If the year is above the first value, the second century is used.
|
|
28
|
+
# E.g. If the control is 4 and the year is smaller or equal to 36 -> 2000-2036
|
|
29
|
+
# E.g. If the control is 7 and the year is larger than 57 -> 1858-1899
|
|
30
|
+
cpr_reg = {
|
|
31
|
+
0: (99, 1900, '-'),
|
|
32
|
+
1: (99, 1900, '-'),
|
|
33
|
+
2: (99, 1900, '-'),
|
|
34
|
+
3: (99, 1900, '-'),
|
|
35
|
+
4: (36, 2000, 1900),
|
|
36
|
+
5: (57, 2000, 1800),
|
|
37
|
+
6: (57, 2000, 1800),
|
|
38
|
+
7: (57, 2000, 1800),
|
|
39
|
+
8: (57, 2000, 1800),
|
|
40
|
+
9: (36, 2000, 1900),
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
day = int(cpr[0:2])
|
|
44
|
+
month = int(cpr[2:4])
|
|
45
|
+
year = int(cpr[4:6])
|
|
46
|
+
control = int(cpr[6])
|
|
47
|
+
|
|
48
|
+
t = cpr_reg[control]
|
|
49
|
+
if year <= t[0]:
|
|
50
|
+
year += t[1]
|
|
51
|
+
else:
|
|
52
|
+
year += t[2]
|
|
53
|
+
|
|
54
|
+
birthdate = date(year, month, day)
|
|
55
|
+
|
|
56
|
+
age = current_date.year - birthdate.year - ((current_date.month, current_date.day) < (birthdate.month, birthdate.day))
|
|
57
|
+
|
|
58
|
+
return age
|
|
File without changes
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""This module contains functions to help with actions in the fmcacov transaction."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def open_forretningspartner(session, fp: str) -> None:
|
|
5
|
+
"""Start the transaction FMCACOV and open the given forretningspartner.
|
|
6
|
+
If the fp-number also matches a cvr-number the fp-number will be opened.
|
|
7
|
+
|
|
8
|
+
Args:
|
|
9
|
+
session: The SAP session to perform the action.
|
|
10
|
+
fp: The forretningspartner number.
|
|
11
|
+
|
|
12
|
+
Raises:
|
|
13
|
+
ValueError: If the forretningspartner wasn't found.
|
|
14
|
+
"""
|
|
15
|
+
session.StartTransaction('fmcacov')
|
|
16
|
+
|
|
17
|
+
# Find forretningspartner
|
|
18
|
+
session.findById("wnd[0]/usr/ctxtGPART_DYN").text = fp
|
|
19
|
+
session.findById("wnd[0]").sendVKey(0)
|
|
20
|
+
|
|
21
|
+
# Detect window "Forretningspartner * Entries"
|
|
22
|
+
if session.findById('wnd[1]/usr', False) is not None:
|
|
23
|
+
# Pop-up detected
|
|
24
|
+
for row_id in range(3, 5):
|
|
25
|
+
fp_row = session.FindById(f'wnd[1]/usr/lbl[103,{row_id}]')
|
|
26
|
+
if fp_row.text == fp:
|
|
27
|
+
fp_row.SetFocus()
|
|
28
|
+
# Press 'Accept' button.
|
|
29
|
+
session.FindById('wnd[1]/tbar[0]/btn[0]').press()
|
|
30
|
+
break
|
|
31
|
+
else:
|
|
32
|
+
# Range exhausted
|
|
33
|
+
raise ValueError(f"Forretningspartner '{fp}' was not found in pop-up.")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def dismiss_key_popup(session, fp: str = "25564617") -> None:
|
|
37
|
+
"""Once a day a popup appears asking to generate a new "afstemningsnøgle".
|
|
38
|
+
This function forces it to appear and clicks "Ja" on it.
|
|
39
|
+
This is done by pretending to do "Kontovedligehold" on the given forretningspartner.
|
|
40
|
+
The function should start and end at the home screen.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
session: The SAP session object.
|
|
44
|
+
fp: The forretningspartner to used. Defaults to "25564617" a fictional person in AAK.
|
|
45
|
+
|
|
46
|
+
Raises:
|
|
47
|
+
RuntimeError: If a popup other than the expected ones appear.
|
|
48
|
+
"""
|
|
49
|
+
open_forretningspartner(session, fp)
|
|
50
|
+
|
|
51
|
+
# Right click the first row in the postliste and click "Kontovedligehold med filter"
|
|
52
|
+
postliste = session.findById("wnd[0]/usr/tabsDATA_DISP/tabpDATA_DISP_FC1/ssubDATA_DISP_SCA:RFMCA_COV:0202/cntlRFMCA_COV_0100_CONT5/shellcont/shell")
|
|
53
|
+
postliste.setCurrentCell(0, "VTREF")
|
|
54
|
+
postliste.contextMenu()
|
|
55
|
+
postliste.selectContextMenuItem("ACC_MAINT_FILTER")
|
|
56
|
+
|
|
57
|
+
# Check if the key popup appeared
|
|
58
|
+
popup = session.findbyid("wnd[1]", False)
|
|
59
|
+
if popup:
|
|
60
|
+
if popup.text == "Kontrol af afstemningsnøgle":
|
|
61
|
+
# Press "Ja"
|
|
62
|
+
session.findbyid("wnd[1]/usr/btnSPOP-OPTION1").press()
|
|
63
|
+
else:
|
|
64
|
+
raise RuntimeError(f"Another popup is blocking: {popup.text}")
|
|
65
|
+
|
|
66
|
+
# Check and dismiss confirmation dialog
|
|
67
|
+
confirmation_text = session.findbyid("wnd[1]/usr/txtMESSTXT1").text
|
|
68
|
+
if 'oprettet' in confirmation_text:
|
|
69
|
+
session.findById("wnd[1]/tbar[0]/btn[0]").press()
|
|
70
|
+
else:
|
|
71
|
+
raise RuntimeError(f"Confirmation dialog wasn't as expected: {confirmation_text}.")
|
|
72
|
+
|
|
73
|
+
# Go back to home screen (Afbryd x 3)
|
|
74
|
+
session.findById("wnd[0]/tbar[0]/btn[12]").press()
|
|
75
|
+
session.findById("wnd[0]/tbar[0]/btn[12]").press()
|
|
76
|
+
session.findById("wnd[0]/tbar[0]/btn[12]").press()
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"""This module provides static functions to perform common tasks with SAP GuiGridView COM objects."""
|
|
2
2
|
|
|
3
|
+
from typing import Iterator
|
|
4
|
+
|
|
3
5
|
|
|
4
6
|
def scroll_entire_table(grid_view, return_to_top=False) -> None:
|
|
5
7
|
"""This function scrolls through the entire table to load all cells.
|
|
@@ -72,7 +74,7 @@ def get_row(grid_view, row: int, scroll_to_row=False) -> tuple[str]:
|
|
|
72
74
|
return tuple(row_data)
|
|
73
75
|
|
|
74
76
|
|
|
75
|
-
def iterate_rows(grid_view) -> tuple[str]:
|
|
77
|
+
def iterate_rows(grid_view) -> Iterator[tuple[str]]:
|
|
76
78
|
"""This generator yields each row of the table in order.
|
|
77
79
|
This is preferable to loading all rows as this will only load a row when it's needed.
|
|
78
80
|
As a side effect this function scrolls the yielded row into view, so the
|
|
@@ -5,7 +5,7 @@ from datetime import date
|
|
|
5
5
|
|
|
6
6
|
import win32clipboard
|
|
7
7
|
|
|
8
|
-
from itk_dev_shared_components.sap import tree_util
|
|
8
|
+
from itk_dev_shared_components.sap import tree_util, fmcacov
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
def opret_kundekontakter(session, fp: str, aftaler: list[str] | None,
|
|
@@ -24,11 +24,7 @@ def opret_kundekontakter(session, fp: str, aftaler: list[str] | None,
|
|
|
24
24
|
Raises:
|
|
25
25
|
RuntimeError: If the kundekontakt wasn't created.
|
|
26
26
|
"""
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
# Find forretningspartner
|
|
30
|
-
session.findById("wnd[0]/usr/ctxtGPART_DYN").text = fp
|
|
31
|
-
session.findById("wnd[0]").sendVKey(0)
|
|
27
|
+
fmcacov.open_forretningspartner(session, fp)
|
|
32
28
|
|
|
33
29
|
# Click 'Opret kundekontakt-flere
|
|
34
30
|
session.findById("wnd[0]/shellcont/shell").nodeContextMenu("GP0000000001")
|
|
@@ -2,67 +2,15 @@
|
|
|
2
2
|
as well as a function to change user passwords."""
|
|
3
3
|
|
|
4
4
|
import os
|
|
5
|
-
import pathlib
|
|
6
5
|
import subprocess
|
|
7
6
|
import time
|
|
8
7
|
|
|
9
|
-
from selenium import webdriver
|
|
10
|
-
from selenium.webdriver.common.by import By
|
|
11
8
|
import pywintypes
|
|
12
9
|
import win32com.client
|
|
13
10
|
|
|
14
11
|
from itk_dev_shared_components.sap import multi_session
|
|
15
12
|
|
|
16
13
|
|
|
17
|
-
def login_using_portal(username: str, password: str):
|
|
18
|
-
"""Open KMD Portal in Edge, login and start SAP GUI.
|
|
19
|
-
Args:
|
|
20
|
-
user: KMD Portal username.
|
|
21
|
-
password: KMD Portal password.
|
|
22
|
-
"""
|
|
23
|
-
driver = webdriver.Chrome()
|
|
24
|
-
driver.implicitly_wait(10)
|
|
25
|
-
driver.get('https://portal.kmd.dk/irj/portal')
|
|
26
|
-
driver.maximize_window()
|
|
27
|
-
|
|
28
|
-
# Login
|
|
29
|
-
user_field = driver.find_element(By.ID, 'logonuidfield')
|
|
30
|
-
pass_field = driver.find_element(By.ID, 'logonpassfield')
|
|
31
|
-
login_button = driver.find_element(By.ID, 'buttonLogon')
|
|
32
|
-
user_field.clear()
|
|
33
|
-
user_field.send_keys(username)
|
|
34
|
-
pass_field.clear()
|
|
35
|
-
pass_field.send_keys(password)
|
|
36
|
-
login_button.click()
|
|
37
|
-
|
|
38
|
-
# Opus
|
|
39
|
-
mine_genveje = driver.find_element(By.CSS_SELECTOR, "div[title='Mine Genveje']")
|
|
40
|
-
mine_genveje.click()
|
|
41
|
-
|
|
42
|
-
# Wait for download and launch file
|
|
43
|
-
_wait_for_download()
|
|
44
|
-
|
|
45
|
-
driver.quit()
|
|
46
|
-
_wait_for_sap_session(10)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def _wait_for_download():
|
|
50
|
-
"""Private function that checks if the SAP.erp file has been downloaded.
|
|
51
|
-
Raises:
|
|
52
|
-
TimeoutError: If the file hasn't been downloaded within 5 seconds.
|
|
53
|
-
"""
|
|
54
|
-
downloads_folder = str(pathlib.Path.home() / "Downloads")
|
|
55
|
-
for _ in range(10):
|
|
56
|
-
for file in os.listdir(downloads_folder):
|
|
57
|
-
if file.endswith(".sap"):
|
|
58
|
-
path = os.path.join(downloads_folder, file)
|
|
59
|
-
os.startfile(path)
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
time.sleep(0.5)
|
|
63
|
-
raise TimeoutError(f".sap file not found in {downloads_folder}")
|
|
64
|
-
|
|
65
|
-
|
|
66
14
|
def login_using_cli(username: str, password: str, client: str = '751', system: str = 'P02', timeout: int = 10) -> None:
|
|
67
15
|
"""Open and login to SAP with commandline expressions.
|
|
68
16
|
Args:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
|
-
Name:
|
|
3
|
-
Version: 1.
|
|
2
|
+
Name: itk_dev_shared_components
|
|
3
|
+
Version: 1.3.0
|
|
4
4
|
Summary: Shared components to use in RPA projects
|
|
5
5
|
Author-email: ITK Development <itk-rpa@mkb.aarhus.dk>
|
|
6
6
|
Project-URL: Homepage, https://github.com/itk-dev-rpa/itk-dev-shared-components
|
|
@@ -12,7 +12,6 @@ Requires-Python: >=3.7
|
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
Requires-Dist: pywin32>=306
|
|
15
|
-
Requires-Dist: selenium>=4.10.0
|
|
16
15
|
Requires-Dist: msal>=1.24.1
|
|
17
16
|
Requires-Dist: requests>=2.31.0
|
|
18
17
|
Requires-Dist: beautifulsoup4>=4.12.2
|
|
@@ -56,3 +55,11 @@ Some examples are:
|
|
|
56
55
|
- List and get emails.
|
|
57
56
|
- Get attachment data.
|
|
58
57
|
- Move and delete emails.
|
|
58
|
+
|
|
59
|
+
### KMD Nova
|
|
60
|
+
|
|
61
|
+
Helper functions for using the KMD Nova api.
|
|
62
|
+
Some examples are:
|
|
63
|
+
|
|
64
|
+
- Get cases and documents.
|
|
65
|
+
- Create cases, documents and tasks.
|
|
@@ -10,7 +10,18 @@ itk_dev_shared_components.egg-info/top_level.txt
|
|
|
10
10
|
itk_dev_shared_components/graph/__init__.py
|
|
11
11
|
itk_dev_shared_components/graph/authentication.py
|
|
12
12
|
itk_dev_shared_components/graph/mail.py
|
|
13
|
+
itk_dev_shared_components/kmd_nova/__init__.py
|
|
14
|
+
itk_dev_shared_components/kmd_nova/authentication.py
|
|
15
|
+
itk_dev_shared_components/kmd_nova/cpr.py
|
|
16
|
+
itk_dev_shared_components/kmd_nova/nova_cases.py
|
|
17
|
+
itk_dev_shared_components/kmd_nova/nova_documents.py
|
|
18
|
+
itk_dev_shared_components/kmd_nova/nova_objects.py
|
|
19
|
+
itk_dev_shared_components/kmd_nova/nova_tasks.py
|
|
20
|
+
itk_dev_shared_components/kmd_nova/util.py
|
|
21
|
+
itk_dev_shared_components/misc/__init__.py
|
|
22
|
+
itk_dev_shared_components/misc/cpr_util.py
|
|
13
23
|
itk_dev_shared_components/sap/__init__.py
|
|
24
|
+
itk_dev_shared_components/sap/fmcacov.py
|
|
14
25
|
itk_dev_shared_components/sap/gridview_util.py
|
|
15
26
|
itk_dev_shared_components/sap/multi_session.py
|
|
16
27
|
itk_dev_shared_components/sap/opret_kundekontakt.py
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "itk_dev_shared_components"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.3.0"
|
|
8
8
|
authors = [
|
|
9
9
|
{ name="ITK Development", email="itk-rpa@mkb.aarhus.dk" },
|
|
10
10
|
]
|
|
@@ -18,7 +18,6 @@ classifiers = [
|
|
|
18
18
|
]
|
|
19
19
|
dependencies = [
|
|
20
20
|
"pywin32 >= 306",
|
|
21
|
-
"selenium >= 4.10.0",
|
|
22
21
|
"msal >= 1.24.1",
|
|
23
22
|
"requests >= 2.31.0",
|
|
24
23
|
"beautifulsoup4 >= 4.12.2"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|