Search in sources :

Example 41 with MetadataRecord

use of cz.mzk.recordmanager.server.metadata.MetadataRecord in project RecordManager2 by moravianlibrary.

the class DublinCoreRecordImplTest method getISSNsTest.

@Test
public void getISSNsTest() throws Exception {
    DublinCoreRecord dcr = new DublinCoreRecordImpl();
    MetadataRecord metadataRecord;
    String issn1str = "issn:0322-9580";
    String issn2str = "ISSN:1211-068X";
    String notIssn = "hi:I:am:very:specific:identifier";
    dcr.addIdentifier(issn1str);
    dcr.addIdentifier(notIssn);
    dcr.addIdentifier(issn2str);
    metadataRecord = metadataFactory.getMetadataRecord(dcr);
    List<Issn> issns = metadataRecord.getISSNs();
    Assert.assertTrue(issns.contains(Issn.create("0322-9580", 1L, "")));
    Assert.assertFalse(issns.contains(Issn.create(notIssn, 2L, "")));
    Assert.assertTrue(issns.contains(Issn.create("1211-068X", 2L, "")));
}
Also used : MetadataRecord(cz.mzk.recordmanager.server.metadata.MetadataRecord) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 42 with MetadataRecord

use of cz.mzk.recordmanager.server.metadata.MetadataRecord in project RecordManager2 by moravianlibrary.

the class MarcXmlParserTest method testRecordNLK.

/**
 * test record with Alphanumeric field names
 */
@Test
public void testRecordNLK() {
    InputStream is = this.getClass().getResourceAsStream("/records/marcxml/NLK-192047.xml");
    MarcRecord marc = parser.parseRecord(is);
    MetadataRecord metadataRecord = metadataFactory.getMetadataRecord(marc);
    Assert.assertNotNull(marc);
    Assert.assertEquals(marc.getField("020", 'a'), "3-540-08474-6");
    Assert.assertEquals(marc.getField("HGS", 'a'), "0");
    Assert.assertEquals(metadataRecord.getPublicationYear(), new Long(1978));
    Assert.assertEquals(metadataRecord.getDetectedFormatList().size(), 1);
    Assert.assertEquals(metadataRecord.getDetectedFormatList().get(0), HarvestedRecordFormatEnum.BOOKS);
    Title expectedTitle = new Title();
    expectedTitle.setTitleStr("Cardiomyopathy and myocardial biopsy /");
    expectedTitle.setOrderInRecord(1L);
    Assert.assertEquals(metadataRecord.getTitle().get(0), expectedTitle);
}
Also used : InputStream(java.io.InputStream) Title(cz.mzk.recordmanager.server.model.Title) MetadataRecord(cz.mzk.recordmanager.server.metadata.MetadataRecord) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 43 with MetadataRecord

use of cz.mzk.recordmanager.server.metadata.MetadataRecord in project RecordManager2 by moravianlibrary.

the class MarcXmlParserTest method testRecordKFBZ.

@Test
public void testRecordKFBZ() {
    InputStream is = this.getClass().getResourceAsStream("/records/marcxml/KFBZ-kpw0120405.xml");
    MarcRecord marc = parser.parseRecord(is);
    MetadataRecord metadataRecord = metadataFactory.getMetadataRecord(marc);
    Assert.assertNotNull(marc);
    Assert.assertEquals(marc.getField("020", 'a'), "80-200-0358-4");
    Title expectedTitle = new Title();
    expectedTitle.setTitleStr("Česká nedělní postila = Postilla " + "de tempore Bohemica : vyloženie svatých čtení nedělních /");
    expectedTitle.setOrderInRecord(1L);
    Assert.assertEquals(metadataRecord.getTitle().get(0), expectedTitle);
    Assert.assertEquals(metadataRecord.getPublicationYear(), new Long(1992));
    Assert.assertEquals(metadataRecord.getDetectedFormatList().size(), 1);
    Assert.assertEquals(metadataRecord.getDetectedFormatList().get(0), HarvestedRecordFormatEnum.BOOKS);
}
Also used : InputStream(java.io.InputStream) Title(cz.mzk.recordmanager.server.model.Title) MetadataRecord(cz.mzk.recordmanager.server.metadata.MetadataRecord) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 44 with MetadataRecord

use of cz.mzk.recordmanager.server.metadata.MetadataRecord in project RecordManager2 by moravianlibrary.

the class MarcXmlParserTest method testMZKRecordMZK.

@Test
public void testMZKRecordMZK() {
    InputStream is = this.getClass().getResourceAsStream("/records/marcxml/MZK01-001439241.xml");
    MarcRecord marc = parser.parseRecord(is);
    MetadataRecord metadataRecord = metadataFactory.getMetadataRecord(marc);
    Assert.assertNotNull(marc);
    Assert.assertEquals(marc.getField("040", 'a'), "BOA001");
    Title expectedTitle = new Title();
    expectedTitle.setTitleStr("Česká republika : města a obce " + "České republiky : tradice, historie, památky, " + "turistika, současnost /");
    expectedTitle.setOrderInRecord(1L);
    Assert.assertEquals(metadataRecord.getTitle().get(0), expectedTitle);
    List<String> fields650 = marc.getFields("650", " ", 'a', 'z');
    Assert.assertEquals(fields650.size(), 4);
    Assert.assertTrue(fields650.contains("obce Česko"));
    Assert.assertEquals(metadataRecord.getPublicationYear(), new Long(2014));
    Assert.assertEquals(metadataRecord.getDetectedFormatList().size(), 1);
    Assert.assertEquals(metadataRecord.getDetectedFormatList().get(0), HarvestedRecordFormatEnum.BOOKS);
    DataFieldMatcher matcher = field -> field.getIndicator1() == ' ' && field.getIndicator2() == '7';
    marc.getFields("072", matcher, " ", 'x');
}
Also used : MetadataRecordFactory(cz.mzk.recordmanager.server.metadata.MetadataRecordFactory) List(java.util.List) MetadataRecord(cz.mzk.recordmanager.server.metadata.MetadataRecord) Assert(org.testng.Assert) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest) HarvestedRecordFormatEnum(cz.mzk.recordmanager.server.model.HarvestedRecordFormat.HarvestedRecordFormatEnum) Title(cz.mzk.recordmanager.server.model.Title) InputStream(java.io.InputStream) InputStream(java.io.InputStream) Title(cz.mzk.recordmanager.server.model.Title) MetadataRecord(cz.mzk.recordmanager.server.metadata.MetadataRecord) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 45 with MetadataRecord

use of cz.mzk.recordmanager.server.metadata.MetadataRecord in project RecordManager2 by moravianlibrary.

the class ImportRecordsWriter method writeInner.

protected void writeInner(List<? extends List<Record>> items) throws Exception {
    for (List<Record> records : items) {
        for (Record currentRecord : records) {
            try {
                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                MarcWriter marcWriter = new MarcXmlWriter(outStream, true);
                marcWriter.setConverter(ISOCharConvertor.INSTANCE);
                marcWriter.write(currentRecord);
                marcWriter.close();
                // need recordId before interception
                byte[] recordContent = outStream.toByteArray();
                MetadataRecord metadata = parseMetadata(recordContent);
                String recordId = metadata.getUniqueId();
                if (regexpExtractor != null) {
                    recordId = regexpExtractor.extract(recordId);
                }
                if (harvestConfiguration.isInterceptionEnabled()) {
                    MarcRecordInterceptor interceptor = marcInterceptorFactory.getInterceptor(harvestConfiguration, recordId, recordContent);
                    if (interceptor != null) {
                        byte[] recordContentNew = interceptor.intercept();
                        if (!Arrays.equals(recordContent, recordContentNew)) {
                            // if record content was changed, parse metadata again
                            metadata = parseMetadata(recordContentNew);
                            // set intercepted content
                            recordContent = recordContentNew;
                        }
                    }
                }
                HarvestedRecord hr = harvestedRecordDao.findByIdAndHarvestConfiguration(recordId, configurationId);
                if (hr == null) {
                    HarvestedRecordUniqueId id = new HarvestedRecordUniqueId(harvestConfiguration, recordId);
                    hr = new HarvestedRecord(id);
                    // TODO detect format
                    hr.setFormat("marc21-xml");
                    hr.setHarvestedFrom(harvestConfiguration);
                }
                hr.setUpdated(new Date());
                hr.setDeleted(null);
                hr.setRawRecord(recordContent);
                harvestedRecordDao.persist(hr);
                dedupKeysParser.parse(hr, metadata);
                if (harvestConfiguration.isFilteringEnabled() && !hr.getShouldBeProcessed()) {
                    logger.debug("Filtered record: " + hr.getUniqueId());
                    hr.setDeleted(new Date());
                }
                harvestedRecordDao.persist(hr);
                progress.incrementAndLogProgress();
            } catch (Exception e) {
                logger.warn("Error occured in processing record");
                throw e;
            }
        }
    }
}
Also used : MarcRecordInterceptor(cz.mzk.recordmanager.server.marc.intercepting.MarcRecordInterceptor) HarvestedRecordUniqueId(cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MarcXmlWriter(org.marc4j.MarcXmlWriter) Date(java.util.Date) MarcWriter(org.marc4j.MarcWriter) MetadataRecord(cz.mzk.recordmanager.server.metadata.MetadataRecord) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) Record(org.marc4j.marc.Record) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) MetadataRecord(cz.mzk.recordmanager.server.metadata.MetadataRecord) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord)

Aggregations

MetadataRecord (cz.mzk.recordmanager.server.metadata.MetadataRecord)46 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)42 Test (org.testng.annotations.Test)42 ArrayList (java.util.ArrayList)32 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)3 Title (cz.mzk.recordmanager.server.model.Title)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3 MarcWriter (org.marc4j.MarcWriter)3 MarcXmlWriter (org.marc4j.MarcXmlWriter)3 Record (org.marc4j.marc.Record)3 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)2 MarcRecordInterceptor (cz.mzk.recordmanager.server.marc.intercepting.MarcRecordInterceptor)2 HarvestedRecordFormatEnum (cz.mzk.recordmanager.server.model.HarvestedRecordFormat.HarvestedRecordFormatEnum)2 Date (java.util.Date)2 MetadataRecordFactory (cz.mzk.recordmanager.server.metadata.MetadataRecordFactory)1 Cosmotron996 (cz.mzk.recordmanager.server.model.Cosmotron996)1 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)1 HarvestedRecordUniqueId (cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId)1 TezaurusRecord (cz.mzk.recordmanager.server.model.TezaurusRecord)1