@@ -1585,6 +1585,47 @@ def get_item_mapped_collections(self, item):
15851585 )
15861586 return None
15871587
1588+ def add_item_mapped_collection (self , item , collection_url ):
1589+ """
1590+ Add a new mapping between an item and a collection
1591+ @param item: Item object
1592+ @param collection_url: URL of the collection to map
1593+ @return: True if successful, False otherwise
1594+ """
1595+ if not isinstance (item , Item ):
1596+ logging .error ("Need a valid item" )
1597+ return False
1598+
1599+ url = f"{ self .API_ENDPOINT } /core/items/{ item .uuid } /mappedCollections"
1600+ try :
1601+ headers = {"Content-Type" : "text/uri-list" }
1602+ response = self .api_post_uri (url , None , collection_url , retry = False )
1603+ if response .status_code == 204 :
1604+ logging .info (
1605+ f"Successfully added mapping for item { item .uuid } to collection { collection_url } ."
1606+ )
1607+ return True
1608+ elif response .status_code == 401 :
1609+ logging .error (f"Unauthorized access for item { item .uuid } " )
1610+ elif response .status_code == 403 :
1611+ logging .error (f"Forbidden access for item { item .uuid } " )
1612+ elif response .status_code == 405 :
1613+ logging .error (f"Method not allowed for item { item .uuid } " )
1614+ elif response .status_code == 422 :
1615+ logging .error (
1616+ f"Unprocessable entity for item { item .uuid } : Collection issues"
1617+ )
1618+ else :
1619+ logging .error (
1620+ f"Unexpected response for item { item .uuid } : { response .status_code } "
1621+ )
1622+ return False
1623+ except Exception as e :
1624+ logging .error (
1625+ f"Error adding mapping for item { item .uuid } to collection { collection_url } : { e } "
1626+ )
1627+ return False
1628+
15881629 def get_item_relationships (self , item ):
15891630 """
15901631 Get the relationships of a given item
0 commit comments