diff --git a/cds_ils/importer/XMLRecordToJson.py b/cds_ils/importer/XMLRecordToJson.py index d6bae4d51..b4229985a 100644 --- a/cds_ils/importer/XMLRecordToJson.py +++ b/cds_ils/importer/XMLRecordToJson.py @@ -53,15 +53,20 @@ def dump(self): else: is_deletable = False + init_fields = {} if "im" in marc_record.get("leader", []): - eitem_type = "audiobook" + init_fields.update({"_eitem": {"_type": "audiobook"}}) + elif "gm" in marc_record.get("leader", []): + init_fields.update( + {"document_type": "MULTIMEDIA", "_eitem": {"_type": "video"}} + ) else: - eitem_type = "e-book" + init_fields.update({"_eitem": {"_type": "e-book"}}) # MARCXML -> JSON fields translation val = self.dojson_model.do( marc_record, exception_handlers=xml_import_handlers, - init_fields={"_eitem": {"_type": eitem_type}}, + init_fields=init_fields, ) if not self.ignore_missing: diff --git a/cds_ils/importer/providers/cds/rules/values_mapping.py b/cds_ils/importer/providers/cds/rules/values_mapping.py index a40cad332..7ffb81fba 100644 --- a/cds_ils/importer/providers/cds/rules/values_mapping.py +++ b/cds_ils/importer/providers/cds/rules/values_mapping.py @@ -111,6 +111,7 @@ "AUDIOBOOK", "ELECTRONIC AUDIO BK", ], + "VIDEO": ["VIDEO", "ELECTRONIC VIDEO"], "AUDIO_CD": ["AUDIO CD"], "DISKETTE": ["DISKETTE"], "DVD": ["DVD"], diff --git a/cds_ils/vocabularies/data/document_identifiers_materials.json b/cds_ils/vocabularies/data/document_identifiers_materials.json index 6ea8f9699..8f152626b 100644 --- a/cds_ils/vocabularies/data/document_identifiers_materials.json +++ b/cds_ils/vocabularies/data/document_identifiers_materials.json @@ -88,5 +88,10 @@ "key": "VHS", "type": "doc_identifiers_materials", "text": "VHS" + }, + { + "key": "VIDEO", + "type": "doc_identifiers_materials", + "text": "Video" } ] diff --git a/tests/importer/data/documents_with_video.json b/tests/importer/data/documents_with_video.json new file mode 100644 index 000000000..067cd12e2 --- /dev/null +++ b/tests/importer/data/documents_with_video.json @@ -0,0 +1,60 @@ +[ + { + "_eitem": { + "_type": "video", + "urls": [ + { + "description": "video", + "value": "https://learning.oreilly.com/library/view/-/9781804615362/?ar" + } + ] + }, + "abstract": "JavaScript is the base for many other languages; if you know JavaScript, you can work with a lot of other languages and dependent frameworks easily. This course is based on the newer features that were released with the ECMAScript specification 6 and above. So, we will only discuss things from ES6 and above. In the first section of this course, you will touch base on JavaScript history, and you will get in place all the required stuff that you should have in your machine for this course. In the second section of the course, you will focus on variables and scope, and you will see the newer patterns to work with variables. Following that, in the third section, we will discuss functions and arguments, which is a critical part of this course because JavaScript treats functions as a first-class citizens, so knowing what changes have been incorporated into them in newer versions is also very essential. In the fourth section, you will learn about operators and how to better use and code them. Then you will understand the new functionality of error handling; in an application where errors are not handled properly, the usability of such an application is nearly impossible. Then we have a section dedicated to async patterns and promises where you will see a few of the latest functions in comparison with similar older functions. By the end of the course, you will get to know the hacks and tricks to improve your coding skills. What You Will Learn Learn various JavaScript hacks Learn various JavaScript concepts Understand the spread operators in JavaScript Explore optional chaining operators Explain prototypal chains Understand error handling in JavaScript Audience This course can be taken by any advanced and intermediate JavaScript learners. This course expects you to have a clear understanding of the basics of JavaScript. About The Author Basics Strong: Basics Strong is a team of technocrats from IITs who focus on solving problems using technology. They work on mission-critical projects in AI, machine learning, and BlockChain as a domain and use Java, Python, JavaScript, and a lot of tools and technologies. They love to code and program. The team believes that a strong foundation in the basics of programming concepts can help you solve any technical problem and excel in your career. Therefore, they create courses that help you build your basics and come up with ways to make complicated concepts easy to learn. All their courses are carefully crafted to include hands-on examples and comprehensive working files for practical learning.", + "agency_code": "OCoLC", + "alternative_identifiers": [ + { "scheme": "SAFARI", "value": "on1351466591" } + ], + "alternative_titles": [ + { "type": "SUBTITLE", "value": "modern and advanced JavaScript" } + ], + "authors": [ + { + "full_name": "ILS,CDS Else,Someone", + "roles": ["AUTHOR"], + "type": "PERSON" + } + ], + "document_type": "MULTIMEDIA", + "edition": "1st", + "identifiers": [ + { + "material": "VIDEO", + "scheme": "ISBN", + "value": "9781804615362" + }, + { + "material": "VIDEO", + "scheme": "ISBN", + "value": "1804615366" + } + ], + "imprint": { + "place": "Place of publication not identified", + "publisher": "Packt Publishing" + }, + "keywords": [ + { + "source": "SAFARI", + "value": "JavaScript (Computer program language" + } + ], + "languages": ["ENG"], + "provider_recid": "on1351466591", + "publication_year": "2022", + "subjects": [ + { "scheme": "LOC", "value": "QA76.73.J39" }, + { "scheme": "DEWEY", "value": "005.2/762" } + ], + "title": "Quick JavaScript crash course" + } +] diff --git a/tests/importer/data/safari_video.xml b/tests/importer/data/safari_video.xml new file mode 100644 index 000000000..617538e19 --- /dev/null +++ b/tests/importer/data/safari_video.xml @@ -0,0 +1,140 @@ + + + + 00000ngm a22000007i 4500 + on1351466591 + OCoLC + 20221129213020.0 + m o c + vz czazuu + cr cnannnuuuuu + 221122s2022 xx 215 o vleng d + + ORMDA + eng + rda + pn + ORMDA + + + 9781804615362 + (electronic video) + + + 1804615366 + (electronic video) + + + (OCoLC)1351466591 + + + 9781804615362 + O'Reilly Media + + + QA76.73.J39 + + + 005.2/762 + 23/eng/20221122 + + + MAIN + + + Quick JavaScript crash course : + modern and advanced JavaScript. + + + [First edition]. + + + [Place of publication not identified] : + Packt Publishing, + [2022] + + + ILS,CDS Else,Someone + + + 1 online resource (1 video file (3 hr., 35 min.)) : + sound, color. + + + 033500 + + + two-dimensional moving image + tdi + rdacontent + + + computer + c + rdamedia + + + online resource + cr + rdacarrier + + + digital + rdatr + + + video file + rdaft + + + Instructional films + lcgft + + + Basics Strong, presenter. + + + Published in October 2022. + + + JavaScript is the base for many other languages; if you know JavaScript, you can work with a lot of other languages and dependent frameworks easily. This course is based on the newer features that were released with the ECMAScript specification 6 and above. So, we will only discuss things from ES6 and above. In the first section of this course, you will touch base on JavaScript history, and you will get in place all the required stuff that you should have in your machine for this course. In the second section of the course, you will focus on variables and scope, and you will see the newer patterns to work with variables. Following that, in the third section, we will discuss functions and arguments, which is a critical part of this course because JavaScript treats functions as a first-class citizens, so knowing what changes have been incorporated into them in newer versions is also very essential. In the fourth section, you will learn about operators and how to better use and code them. Then you will understand the new functionality of error handling; in an application where errors are not handled properly, the usability of such an application is nearly impossible. Then we have a section dedicated to async patterns and promises where you will see a few of the latest functions in comparison with similar older functions. By the end of the course, you will get to know the hacks and tricks to improve your coding skills. What You Will Learn Learn various JavaScript hacks Learn various JavaScript concepts Understand the spread operators in JavaScript Explore optional chaining operators Explain prototypal chains Understand error handling in JavaScript Audience This course can be taken by any advanced and intermediate JavaScript learners. This course expects you to have a clear understanding of the basics of JavaScript. About The Author Basics Strong: Basics Strong is a team of technocrats from IITs who focus on solving problems using technology. They work on mission-critical projects in AI, machine learning, and BlockChain as a domain and use Java, Python, JavaScript, and a lot of tools and technologies. They love to code and program. The team believes that a strong foundation in the basics of programming concepts can help you solve any technical problem and excel in your career. Therefore, they create courses that help you build your basics and come up with ways to make complicated concepts easy to learn. All their courses are carefully crafted to include hands-on examples and comprehensive working files for practical learning. + + + Online resource; title from title details screen (O'Reilly, viewed November 21, 2022). + + + O'Reilly + O'Reilly Online Learning Platform: Academic Edition (SAML SSO Access) + + + JavaScript (Computer program language) + + + Instructional films. + lcgft + + + Nonfiction films. + lcgft + + + Internet videos. + lcgft + + + Basisc Strong (Firm), + presenter. + + + Packt Publishing, + publisher. + + + https://learning.oreilly.com/library/view/-/9781804615362/?ar + + + 92 + CHCER + + + diff --git a/tests/importer/test_importer.py b/tests/importer/test_importer.py index 9c1df0f18..bd4e57611 100644 --- a/tests/importer/test_importer.py +++ b/tests/importer/test_importer.py @@ -230,3 +230,44 @@ def test_import_audiobook(app, db): assert eitem["created_by"] == {"type": "import", "value": "safari"} assert created_document["created_by"] == {"type": "import", "value": "safari"} + + +def test_import_video(app, db): + document_cls = current_app_ils.document_record_cls + eitem_search_cls = current_app_ils.eitem_search_cls + eitem_cls = current_app_ils.eitem_record_cls + + json_data = load_json_from_datadir("documents_with_video.json", relpath="importer") + importer = Importer(json_data[0], "safari") + + report = importer.import_record() + assert report["document_json"] + assert report["action"] == "create" + + created_document = document_cls.get_record_by_pid(report["document_json"]["pid"]) + assert created_document["document_type"] == "MULTIMEDIA" + time.sleep(1) + search = eitem_search_cls().search_by_document_pid( + document_pid=created_document["pid"] + ) + results = search.execute() + assert results.hits.total.value == 1 + + eitem_pid = results.hits[0].pid + eitem = eitem_cls.get_record_by_pid(eitem_pid) + + assert eitem["document_pid"] == created_document["pid"] + assert eitem["eitem_type"] == "VIDEO" + + assert "_eitem" not in created_document + assert "agency_code" not in created_document + assert "identifiers" in created_document + + for urls in eitem["urls"]: + urls["description"] == "video" + + for isbn in created_document["identifiers"]: + assert isbn["material"] == "VIDEO" + + assert eitem["created_by"] == {"type": "import", "value": "safari"} + assert created_document["created_by"] == {"type": "import", "value": "safari"} diff --git a/tests/importer/test_safari_dojson.py b/tests/importer/test_safari_dojson.py index 49ca1d818..9311839ea 100644 --- a/tests/importer/test_safari_dojson.py +++ b/tests/importer/test_safari_dojson.py @@ -13,17 +13,18 @@ def check_transformation(marcxml_body, json_body): """Check transformation.""" blob = create_record(marcxml.format(marcxml_body)) + init_fields = {} if "im" in blob.get("leader", []): - eitem_type = "audiobook" + init_fields.update({"_eitem": {"_type": "audiobook"}}) + elif "gm" in blob.get("leader", []): + init_fields.update( + {"document_type": "MULTIMEDIA", "_eitem": {"_type": "video"}} + ) else: - eitem_type = "e-book" + init_fields.update({"_eitem": {"_type": "e-book"}}) record = {} - record.update( - **model.do( - blob, ignore_missing=True, init_fields={"_eitem": {"_type": eitem_type}} - ) - ) + record.update(**model.do(blob, ignore_missing=True, init_fields=init_fields)) expected = {} expected.update(**json_body) @@ -459,3 +460,113 @@ def test_safari_audiobook(app): "title": "Managing your anxiety", }, ) + + +def test_safari_video(app): + """Test video import.""" + dirname = os.path.join(os.path.dirname(__file__), "data") + with open(os.path.join(dirname, "safari_video.xml"), "r") as fp: + example = fp.read() + with app.app_context(): + check_transformation( + example, + { + "_eitem": { + "_type": "video", + "urls": [ + { + "description": "video", + "value": "https://learning.oreilly.com/library/view/-/9781804615362/?ar", + } + ], + }, + "abstract": "JavaScript is the base for many other languages; if you know " + "JavaScript, you can work with a lot of other languages and " + "dependent frameworks easily. This course is based on the newer " + "features that were released with the ECMAScript specification 6 " + "and above. So, we will only discuss things from ES6 and above. " + "In the first section of this course, you will touch base on " + "JavaScript history, and you will get in place all the required " + "stuff that you should have in your machine for this course. In " + "the second section of the course, you will focus on variables " + "and scope, and you will see the newer patterns to work with " + "variables. Following that, in the third section, we will discuss " + "functions and arguments, which is a critical part of this course " + "because JavaScript treats functions as a first-class citizens, " + "so knowing what changes have been incorporated into them in " + "newer versions is also very essential. In the fourth section, " + "you will learn about operators and how to better use and code " + "them. Then you will understand the new functionality of error " + "handling; in an application where errors are not handled " + "properly, the usability of such an application is nearly " + "impossible. Then we have a section dedicated to async patterns " + "and promises where you will see a few of the latest functions in " + "comparison with similar older functions. By the end of the " + "course, you will get to know the hacks and tricks to improve " + "your coding skills. What You Will Learn Learn various JavaScript " + "hacks Learn various JavaScript concepts Understand the spread " + "operators in JavaScript Explore optional chaining operators " + "Explain prototypal chains Understand error handling in " + "JavaScript Audience This course can be taken by any advanced and " + "intermediate JavaScript learners. This course expects you to " + "have a clear understanding of the basics of JavaScript. About " + "The Author Basics Strong: Basics Strong is a team of technocrats " + "from IITs who focus on solving problems using technology. They " + "work on mission-critical projects in AI, machine learning, and " + "BlockChain as a domain and use Java, Python, JavaScript, and a " + "lot of tools and technologies. They love to code and program. " + "The team believes that a strong foundation in the basics of " + "programming concepts can help you solve any technical problem " + "and excel in your career. Therefore, they create courses that " + "help you build your basics and come up with ways to make " + "complicated concepts easy to learn. All their courses are " + "carefully crafted to include hands-on examples and comprehensive " + "working files for practical learning.", + "agency_code": "OCoLC", + "alternative_identifiers": [ + {"scheme": "SAFARI", "value": "on1351466591"} + ], + "alternative_titles": [ + {"type": "SUBTITLE", "value": "modern and advanced JavaScript"} + ], + "authors": [ + { + "full_name": "ILS,CDS Else,Someone", + "roles": ["AUTHOR"], + "type": "PERSON", + } + ], + "document_type": "MULTIMEDIA", + "edition": "1st", + "identifiers": [ + { + "material": "VIDEO", + "scheme": "ISBN", + "value": "9781804615362", + }, + { + "material": "VIDEO", + "scheme": "ISBN", + "value": "1804615366", + }, + ], + "imprint": { + "place": "Place of publication not identified", + "publisher": "Packt Publishing", + }, + "keywords": [ + { + "source": "SAFARI", + "value": "JavaScript (Computer program language", + } + ], + "languages": ["ENG"], + "provider_recid": "on1351466591", + "publication_year": "2022", + "subjects": [ + {"scheme": "LOC", "value": "QA76.73.J39"}, + {"scheme": "DEWEY", "value": "005.2/762"}, + ], + "title": "Quick JavaScript crash course", + }, + )