dspace-api-toolkit 0.1.1__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.
- dspace_api/__init__.py +75 -0
- dspace_api/_base.py +407 -0
- dspace_api/_containers.py +217 -0
- dspace_api/_version.py +4 -0
- dspace_api/auth.py +467 -0
- dspace_api/authorizations.py +486 -0
- dspace_api/bundles.py +1193 -0
- dspace_api/collections.py +1069 -0
- dspace_api/communities.py +363 -0
- dspace_api/config.py +254 -0
- dspace_api/discovery.py +920 -0
- dspace_api/entity_types.py +127 -0
- dspace_api/epersons.py +647 -0
- dspace_api/exceptions.py +110 -0
- dspace_api/groups.py +599 -0
- dspace_api/items.py +549 -0
- dspace_api/metadata.py +742 -0
- dspace_api/permissions.py +1052 -0
- dspace_api/projection.py +292 -0
- dspace_api/relationships.py +694 -0
- dspace_api/session.py +538 -0
- dspace_api/site.py +98 -0
- dspace_api/utils.py +519 -0
- dspace_api/versions.py +292 -0
- dspace_api/vocabulary.py +365 -0
- dspace_api/workflow.py +893 -0
- dspace_api/workspaces.py +1404 -0
- dspace_api_toolkit-0.1.1.dist-info/METADATA +211 -0
- dspace_api_toolkit-0.1.1.dist-info/RECORD +32 -0
- dspace_api_toolkit-0.1.1.dist-info/WHEEL +5 -0
- dspace_api_toolkit-0.1.1.dist-info/licenses/LICENSE +28 -0
- dspace_api_toolkit-0.1.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Entity types for DSpace API (DSpace 7+ / DSpace-CRIS 7+)
|
|
4
|
+
|
|
5
|
+
Mostly used to gate "create" actions in a UI or script: which entity types
|
|
6
|
+
can the current user submit, and into which collections.
|
|
7
|
+
|
|
8
|
+
GET /core/entitytypes[/{id}]
|
|
9
|
+
GET /core/entitytypes/label/{label}
|
|
10
|
+
GET /core/entitytypes/{id}/relationshiptypes
|
|
11
|
+
GET /core/entitytypes/search/findAllByAuthorizedCollection
|
|
12
|
+
GET /core/entitytypes/search/findAllByAuthorizedExternalSource
|
|
13
|
+
GET /core/collections/search/findSubmitAuthorizedByEntityType?entityType=
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from typing import Any, Dict, List, Optional, Set
|
|
17
|
+
|
|
18
|
+
from ._base import BaseManager
|
|
19
|
+
from .projection import EmbedArg, ProjectionArg
|
|
20
|
+
from .config import Endpoints
|
|
21
|
+
|
|
22
|
+
# Endpoints for entity types and collections
|
|
23
|
+
ENTITY_TYPES = getattr(Endpoints, "ENTITY_TYPES", "/core/entitytypes")
|
|
24
|
+
COLLECTIONS = getattr(Endpoints, "COLLECTIONS", "/core/collections")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class EntityTypeManager(BaseManager):
|
|
28
|
+
"""Entity type lookups and per-user submission authorization"""
|
|
29
|
+
|
|
30
|
+
def get_entity_types(self) -> List[Dict[str, Any]]:
|
|
31
|
+
"""List all entity types.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
List[Dict[str, Any]]: A list of entity type data.
|
|
35
|
+
"""
|
|
36
|
+
return list(self._iter_embedded(self._url(ENTITY_TYPES), "entitytypes", "List entity types"))
|
|
37
|
+
|
|
38
|
+
def get_entity_type(self, entity_type_id) -> Dict[str, Any]:
|
|
39
|
+
"""Get an entity type by its ID.
|
|
40
|
+
|
|
41
|
+
Parameters:
|
|
42
|
+
entity_type_id (int): The ID of the entity type.
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
Dict[str, Any]: The entity type data.
|
|
46
|
+
"""
|
|
47
|
+
return self._get_json(self._url(ENTITY_TYPES, f"/{entity_type_id}"), f"Get entity type {entity_type_id}")
|
|
48
|
+
|
|
49
|
+
def get_relationship_types(self, entity_type) -> List[Dict[str, Any]]:
|
|
50
|
+
"""Relationship types with this entity type (id, label or dict) on either side.
|
|
51
|
+
|
|
52
|
+
Parameters:
|
|
53
|
+
entity_type (Union[int, str, Dict[str, Any]]): The entity type to check.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
List[Dict[str, Any]]: A list of relationship type data.
|
|
57
|
+
"""
|
|
58
|
+
if isinstance(entity_type, dict):
|
|
59
|
+
type_id = entity_type["id"]
|
|
60
|
+
elif isinstance(entity_type, int) or str(entity_type).isdigit():
|
|
61
|
+
type_id = entity_type
|
|
62
|
+
else:
|
|
63
|
+
type_id = self.get_entity_type_by_label(entity_type)["id"]
|
|
64
|
+
url = self._url(ENTITY_TYPES, f"/{type_id}/relationshiptypes")
|
|
65
|
+
return list(self._iter_embedded(url, "relationshiptypes", f"Relationship types of entity type {type_id}"))
|
|
66
|
+
|
|
67
|
+
def get_entity_type_by_label(self, label: str) -> Dict[str, Any]:
|
|
68
|
+
"""Get an entity type by its label.
|
|
69
|
+
|
|
70
|
+
Parameters:
|
|
71
|
+
label (str): The label of the entity type.
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
Dict[str, Any]: The entity type data.
|
|
75
|
+
"""
|
|
76
|
+
return self._get_json(self._url(ENTITY_TYPES, f"/label/{label}"), f"Get entity type {label}")
|
|
77
|
+
|
|
78
|
+
def get_authorized_collection_entity_types(self) -> List[Dict[str, Any]]:
|
|
79
|
+
"""Entity types the current user can submit (submit right on at least one collection of that type).
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
List[Dict[str, Any]]: A list of entity type data.
|
|
83
|
+
"""
|
|
84
|
+
url = self._url(ENTITY_TYPES, "/search/findAllByAuthorizedCollection")
|
|
85
|
+
return list(self._iter_embedded(url, "entitytypes", "Find entity types by authorized collection"))
|
|
86
|
+
|
|
87
|
+
def get_authorized_external_source_entity_types(self) -> List[Dict[str, Any]]:
|
|
88
|
+
"""Entity types the current user can import from an external source (ORCID, Crossref, ...).
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
List[Dict[str, Any]]: A list of entity type data.
|
|
92
|
+
"""
|
|
93
|
+
url = self._url(ENTITY_TYPES, "/search/findAllByAuthorizedExternalSource")
|
|
94
|
+
return list(self._iter_embedded(url, "entitytypes", "Find entity types by authorized external source"))
|
|
95
|
+
|
|
96
|
+
def can_submit(self, entity_type: str) -> bool:
|
|
97
|
+
"""True if the current user may create items of this type somewhere."""
|
|
98
|
+
return entity_type in self.authorized_labels()
|
|
99
|
+
|
|
100
|
+
def authorized_labels(self) -> Set[str]:
|
|
101
|
+
"""Get the labels of entity types the current user can submit to.
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
Set[str]: A set of entity type labels.
|
|
105
|
+
"""
|
|
106
|
+
return {t.get("label") for t in self.get_authorized_collection_entity_types()}
|
|
107
|
+
|
|
108
|
+
def get_submit_collections(self, entity_type: str, query: Optional[str] = None,
|
|
109
|
+
max_results: Optional[int] = None,
|
|
110
|
+
all_languages: Optional[bool] = None, projection: ProjectionArg = None, embed: EmbedArg = None) -> List[Dict[str, Any]]:
|
|
111
|
+
"""Collections of this entity type the current user can submit to.
|
|
112
|
+
|
|
113
|
+
Parameters:
|
|
114
|
+
entity_type (str): The entity type label.
|
|
115
|
+
query (Optional[str], optional): Search query for collections. Defaults to None.
|
|
116
|
+
max_results (Optional[int], optional): Maximum number of results to return. Defaults to None.
|
|
117
|
+
all_languages (Optional[bool], optional): Whether to include all languages. Defaults to None.
|
|
118
|
+
projection (ProjectionArg, optional): Projection to apply. Defaults to None.
|
|
119
|
+
embed (EmbedArg, optional): Embed options. Defaults to None.
|
|
120
|
+
|
|
121
|
+
Returns:
|
|
122
|
+
List[Dict[str, Any]]: A list of collection data.
|
|
123
|
+
"""
|
|
124
|
+
params = [("entityType", entity_type)] + ([("query", query)] if query else [])
|
|
125
|
+
url = self._url(COLLECTIONS, "/search/findSubmitAuthorizedByEntityType")
|
|
126
|
+
return list(self._iter_embedded(url, "collections", f"Find {entity_type} submit collections", params,
|
|
127
|
+
max_results=max_results, all_languages=all_languages, projection=projection, embed=embed))
|