Пример #1
0
 def test_dao_unitdatestructured_datevalue_subelement(self):
     """
     Test dao tuples
     """
     parsed_ead = TestParsedEad.test_dir
     ead_file_path = TestParsedEad.test_dir + 'metadata/descriptive/EAD-example1.xml'
     pead = ParsedEad(parsed_ead, ead_file_path)
     md_tag = "unitdatestructured"
     res = pead.dao_path_mdval_tuples(md_tag, "ead:datesingle")
     self.assertEqual("22.04.2016", res[0]['mdvalue'])
Пример #2
0
 def test_dao_clevel_attribute_value(self):
     """
     Test dao tuples
     """
     parsed_ead = TestParsedEad.test_dir
     ead_file_path = TestParsedEad.test_dir + 'metadata/descriptive/EAD-example1.xml'
     pead = ParsedEad(parsed_ead, ead_file_path)
     md_tag = "[Cc][0,1][0-9]"
     res = pead.dao_path_mdval_tuples(md_tag, "level", True)
     self.assertEqual("item", res[0]['mdvalue'])
Пример #3
0
 def test_first_metadata_value_in_ancestry_path(self):
     """
     Test get closest unittitle element value (c04)
     """
     pead = ParsedEad(
         TestParsedEad.test_dir,
         TestParsedEad.test_dir + 'metadata/descriptive/EAD-example1.xml')
     dao_elements = pead.get_dao_elements()
     for dao_elm in dao_elements:
         self.assertEqual("Record - Adams-Ayers",
                          pead._first_md_val_ancpath(dao_elm, "unittitle"))
Пример #4
0
 def test_get_dao_elements(self):
     """
     Test get dao elements
     """
     pead = ParsedEad(
         TestParsedEad.test_dir,
         TestParsedEad.test_dir + 'metadata/descriptive/EAD-example1.xml')
     dao_elements = pead.get_dao_elements()
     self.assertIsNotNone(dao_elements, "DAO elements must not be None")
     self.assertEqual(len(dao_elements), 2,
                      "DAO elements list must have two DAO element")
Пример #5
0
 def test_first_metadata_value_in_ancestry_path_c01(self):
     """
     Test get closest unittitle element value (c01)
     """
     pead = ParsedEad(
         TestParsedEad.test_dir,
         TestParsedEad.test_dir + 'metadata/descriptive/EAD-example4.xml')
     dao_elements = pead.get_dao_elements()
     for dao_elm in dao_elements:
         self.assertEqual("Correspondence",
                          pead._first_md_val_ancpath(dao_elm, "unittitle"))
Пример #6
0
 def test_first_metadata_value_in_ancestry_path_origination(self):
     """
     Test get closest unittitle element value (c04)
     """
     pead = ParsedEad(
         TestParsedEad.test_dir,
         TestParsedEad.test_dir + 'metadata/descriptive/EAD-example5.xml')
     dao_elements = pead.get_dao_elements()
     for dao_elm in dao_elements:
         self.assertEqual(
             "Test Agency",
             pead._first_md_val_ancpath(dao_elm, "origination",
                                        "ead:corpname/ead:part"))
Пример #7
0
 def test_first_metadata_value_in_ancestry_path_unitdatestructured(self):
     """
     Test get closest unittitle element value (c04)
     """
     pead = ParsedEad(
         TestParsedEad.test_dir,
         TestParsedEad.test_dir + 'metadata/descriptive/EAD-example1.xml')
     dao_elements = pead.get_dao_elements()
     for dao_elm in dao_elements:
         self.assertEqual(
             "22.04.2016",
             pead._first_md_val_ancpath(dao_elm, "unitdatestructured",
                                        "ead:datesingle"))
Пример #8
0
 def test_c_level(self):
     """
     Test get closest unittitle element value (c01)
     """
     pead = ParsedEad(
         TestParsedEad.test_dir,
         TestParsedEad.test_dir + 'metadata/descriptive/EAD-example1.xml')
     dao_elements = pead.get_dao_elements()
     for dao_elm in dao_elements:
         self.assertEqual(
             "item",
             pead._first_md_val_ancpath(dao_elm, "[Cc][0,1][0-9]", "level",
                                        True))
Пример #9
0
 def test_dao_title_tuples(self):
     """
     Test dao tuples
     """
     parsed_ead = TestParsedEad.test_dir
     ead_file_path = TestParsedEad.test_dir + 'metadata/descriptive/EAD-example1.xml'
     pead = ParsedEad(parsed_ead, ead_file_path)
     md_tag = "unittitle"
     res = pead.dao_path_mdval_tuples(md_tag)
     self.assertEqual(
         "metadata/descriptive/representations/rep1/data/Example1.docx",
         res[0]['path'])
     self.assertEqual(
         "metadata/descriptive/representations/rep2/data/Example1.pdf",
         res[1]['path'])
     self.assertEqual("Record - Adams-Ayers", res[0]['mdvalue'])
     self.assertEqual("Record - Adams-Ayers", res[1]['mdvalue'])
Пример #10
0
 def test_get_root_element(self):
     """
     Must not validate if the files listed in the EAD file does not match the actual file size
     """
     pead = ParsedEad(
         TestParsedEad.test_dir,
         TestParsedEad.test_dir + 'metadata/descriptive/EAD-example1.xml')
     actual = pead.ead_tree.getroot().tag
     self.assertEqual(actual, "{http://ead3.archivists.org/schema/}ead",
                      "Root tag 'ead' not found")
Пример #11
0
def get_basic_metadata(request, file_path):
    user_data_path = os.path.join(ip_data_path, request.user.username)
    vars = environment_variables(request)
    if not vars['selected_ip']:
        return {}
    selected_ip = vars['selected_ip']
    print(file_path)
    archive_file_path = os.path.join(user_data_path, selected_ip.ip_filename)
    t = tarfile.open(archive_file_path, 'r')
    file_content = read_textfile_from_tar(t, file_path)
    tmp_file_path = "/tmp/%s" % randomword(10)
    res_events = []
    try:
        title = ""
        date = ""
        with open(tmp_file_path, 'w') as tmp_file:
            tmp_file.write(file_content)
        if fnmatch.fnmatch(file_path, metadata_file_pattern_ead):
            pead = ParsedEad("/tmp", tmp_file_path)
            dao_elements = pead.get_dao_elements()
            actual = pead.ead_tree.getroot().tag
            unit_titles = []
            unit_dates = []
            for dao_elm in dao_elements:
                unit_titles.append(
                    pead._first_md_val_ancpath(dao_elm, "unittitle"))
                unit_dates.append(
                    pead._first_md_val_ancpath(dao_elm, "unitdate"))
            title = unit_titles[0]
            date = unit_dates[0]
            events = ""
        elif fnmatch.fnmatch(file_path, metadata_file_pattern_premis):
            structure = get_ip_structure(request)
            logical_view = search(structure, "logical_view_data")
            events = search(logical_view, "events")
            for event in events:
                if len(event):
                    res_events.append({
                        'type':
                        event[0]['type'],
                        'datetime':
                        event[0]['datetime'],
                        'agent':
                        event[0]['linking_agent_id']['value']
                    })
            title = "Root PREMIS"
            date = "20.09.2017"

        md_type = ead_md_type if fnmatch.fnmatch(file_path, metadata_file_pattern_ead)  \
            else premis_md_type if fnmatch.fnmatch(file_path, metadata_file_pattern_premis) else "Other"

        return JsonResponse(
            {
                'success': True,
                'type': md_type,
                'title': title,
                'date': date,
                'events': res_events,
                'file_path': file_path
            },
            status=200)
    except Exception as error:
        logger.exception(error)
        return JsonResponse({
            'success': False,
            'error': str(error)
        },
                            status=500)