def add_items_to_collection(cid=""): """ Adds new items to a collection. """ abort_if_fails_collection_edit_auth(request) try: if "tiids" in request.json: collection_object = collection.add_items_to_collection_object( cid=cid, tiids=request.json["tiids"], alias_tuples=None) else: #to be depricated collection_object = collection.add_items_to_collection( cid=cid, aliases=request.json["aliases"], myredis=myredis) except (AttributeError, TypeError) as e: # we got missing or improperly formated data. logger.error(u"PUT /collection/{id}/items threw an error: '{error_str}'. input: {json}.".format( id=cid, error_str=e, json=request.json)) abort_custom(500, "Error adding items to collection") (coll_doc, is_updating) = collection.get_collection_with_items_for_client(cid, myrefsets, myredis, mydao, include_history=False) resp = make_response(json.dumps(coll_doc, sort_keys=True, indent=4), 200) return resp
def add_items_to_collection(cid=""): """ Adds new items to a collection. """ abort_if_fails_collection_edit_auth(request) try: if "tiids" in request.json: collection_object = collection.add_items_to_collection_object( cid=cid, tiids=request.json["tiids"], alias_tuples=None) else: #to be depricated collection_object = collection.add_items_to_collection( cid=cid, aliases=request.json["aliases"], myredis=myredis) except (AttributeError, TypeError) as e: # we got missing or improperly formated data. logger.error( u"PUT /collection/{id}/items threw an error: '{error_str}'. input: {json}." .format(id=cid, error_str=e, json=request.json)) abort_custom(500, "Error adding items to collection") (coll_doc, is_updating) = collection.get_collection_with_items_for_client( cid, myrefsets, myredis, mydao, include_history=False) resp = make_response(json.dumps(coll_doc, sort_keys=True, indent=4), 200) return resp
def test_add_items_to_collection(self): self.create_test_collection() cid = "testcollectionid" # try a doi assert_equals(len(collection.Collection.query.get(cid).tiids), 2) collection_object = collection.add_items_to_collection( cid=cid, aliases=[("doi", "10.1371/journal.pone.0004803")], myredis=self.r) assert_equals(len(collection_object.tiids), 3) assert_equals(len(collection.Collection.query.get(cid).tiids), 3) test_biblio = { "authors": "Milojevi\u0107, Hemminger, Priem, Chen, Leydesdorff, Weingart", "first_author": "Milojevi\u0107", "first_page": "1", "genre": "unknown", "journal": "Proceedings of the American Society for Information Science and Technology", "number": "1", "title": "Information visualization state of the art and future directions", "volume": "49", "year": "2012" } # try a biblio collection_object = collection.add_items_to_collection( cid=cid, aliases=[("biblio", test_biblio)], myredis=self.r) assert_equals(len(collection_object.tiids), 4) assert_equals(len(collection.Collection.query.get(cid).tiids), 4) # try the biblio again... now it adds a new one collection_object = collection.add_items_to_collection( cid=cid, aliases=[("biblio", test_biblio)], myredis=self.r) assert_equals(len(collection_object.tiids), 5) assert_equals(len(collection.Collection.query.get(cid).tiids), 5)