Skip to content

Commit 81930f4

Browse files
add new function: create_item_version
1 parent 64e9cda commit 81930f4

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

dspace_rest_client/client.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,53 @@ def create_item(self, parent, item):
872872
return None
873873
return Item(api_resource=parse_json(self.create_dso(url, params=params, data=item.as_dict())))
874874

875+
def create_item_version(self, item_uuid, summary=None):
876+
"""
877+
Create a new version of an existing item.
878+
@param item_uuid: UUID of the item to version
879+
@param summary: Optional summary text for the new version
880+
@return: JSON response containing the new version information or None if an error occurs
881+
"""
882+
url = f"{self.API_ENDPOINT}/versioning/versions"
883+
params = {}
884+
if summary is not None:
885+
params["summary"] = summary
886+
887+
# Construct the item URI
888+
item_uri = f"{self.API_ENDPOINT}/core/items/{item_uuid}"
889+
890+
# Send the POST request with Content-Type:text/uri-list
891+
response = self.api_post_uri(url, params=params, uri_list=item_uri)
892+
893+
if response.status_code == 201:
894+
# 201 Created - Success
895+
new_version = parse_json(response)
896+
logging.info(f"Created new version for item {item_uuid}")
897+
return new_version
898+
elif response.status_code == 401:
899+
# 401 Unauthorized - Not authenticated
900+
logging.error("Unauthorized: You are not authenticated.")
901+
elif response.status_code == 403:
902+
# 403 Forbidden - Insufficient permissions or blocked entity
903+
logging.error(
904+
"Forbidden: You do not have sufficient permissions or versioning is blocked for this entity."
905+
)
906+
elif response.status_code == 400:
907+
# 400 Bad Request - URI doesn't resolve to an item
908+
logging.error("Bad Request: The URI does not resolve to an item.")
909+
elif response.status_code == 422:
910+
# 422 Unprocessable Entity - In-progress submission exists
911+
logging.error(
912+
"Unprocessable Entity: An in-progress submission for a new version already exists."
913+
)
914+
else:
915+
# Other errors
916+
logging.error(
917+
f"Error creating item version: {response.status_code} {response.text}"
918+
)
919+
920+
return None
921+
875922
def update_item(self, item):
876923
"""
877924
Update item. The Item passed to this method contains all the data, identifiers, links necessary to

0 commit comments

Comments
 (0)