Skip to content

Commit c432975

Browse files
committed
add function to remove an existing mapping between an item and a collection
1 parent 7bb4e2b commit c432975

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

dspace_rest_client/client.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,46 @@ def add_item_mapped_collection(self, item, collection_url):
16261626
)
16271627
return False
16281628

1629+
def delete_item_mapped_collection(self, item, collection_uuid):
1630+
"""
1631+
Remove an existing mapping between an item and a collection
1632+
@param item: Item object
1633+
@param collection_uuid: UUID of the collection to unmap
1634+
@return: True if successful, False otherwise
1635+
"""
1636+
if not isinstance(item, Item):
1637+
logging.error("Need a valid item")
1638+
return False
1639+
1640+
url = f"{self.API_ENDPOINT}/core/items/{item.uuid}/mappedCollections/{collection_uuid}"
1641+
try:
1642+
response = self.api_delete(url, None, retry=False)
1643+
if response.status_code == 204:
1644+
logging.info(
1645+
f"Successfully removed mapping for item {item.uuid} from collection {collection_uuid}."
1646+
)
1647+
return True
1648+
elif response.status_code == 401:
1649+
logging.error(f"Unauthorized access for item {item.uuid}")
1650+
elif response.status_code == 403:
1651+
logging.error(f"Forbidden access for item {item.uuid}")
1652+
elif response.status_code == 405:
1653+
logging.error(f"Method not allowed for item {item.uuid}")
1654+
elif response.status_code == 422:
1655+
logging.error(
1656+
f"Unprocessable entity for item {item.uuid}: Collection issues"
1657+
)
1658+
else:
1659+
logging.error(
1660+
f"Unexpected response for item {item.uuid}: {response.status_code}"
1661+
)
1662+
return False
1663+
except Exception as e:
1664+
logging.error(
1665+
f"Error removing mapping for item {item.uuid} from collection {collection_uuid}: {e}"
1666+
)
1667+
return False
1668+
16291669
def get_item_relationships(self, item):
16301670
"""
16311671
Get the relationships of a given item

0 commit comments

Comments
 (0)