Search in sources :

Example 1 with MetadataRecord

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

the class ImportCosmotron996RecordsWriter method write.

@Override
public void write(List<? extends List<Record>> items) throws Exception {
    if (harvestConfiguration == null) {
        harvestConfiguration = oaiHarvestConfigurationDao.get(configurationId);
    }
    for (List<Record> records : items) {
        for (Record currentRecord : records) {
            try {
                MarcRecord marc = new MarcRecordImpl(currentRecord);
                String parentId = CosmotronUtils.getParentId(marc);
                MetadataRecord metadata = metadataFactory.getMetadataRecord(marc, harvestConfiguration);
                String recordId = metadata.getUniqueId();
                Cosmotron996 c996 = cosmotron996Dao.findByIdAndHarvestConfiguration(recordId, configurationId);
                if (c996 == null) {
                    c996 = new Cosmotron996();
                    c996.setRecordId(recordId);
                    c996.setHarvestedFrom(configurationId);
                }
                c996.setParentRecordId(parentId);
                c996.setUpdated(new Date());
                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                MarcWriter marcWriter = new MarcXmlWriter(outStream, true);
                marcWriter.write(currentRecord);
                marcWriter.close();
                byte[] recordContent = outStream.toByteArray();
                if (harvestConfiguration.isInterceptionEnabled()) {
                    MarcRecordInterceptor interceptor = marcInterceptorFactory.getInterceptor(harvestConfiguration, recordId, recordContent);
                    if (interceptor != null) {
                        recordContent = interceptor.intercept();
                    }
                }
                c996.setDeleted(null);
                c996.setRawRecord(recordContent);
                cosmotron996Dao.persist(c996);
            } catch (Exception e) {
                logger.warn("Error occured in processing record");
                throw e;
            }
        }
    }
}
Also used : MarcRecordInterceptor(cz.mzk.recordmanager.server.marc.intercepting.MarcRecordInterceptor) Cosmotron996(cz.mzk.recordmanager.server.model.Cosmotron996) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Date(java.util.Date) MarcXmlWriter(org.marc4j.MarcXmlWriter) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) MarcWriter(org.marc4j.MarcWriter) MetadataRecord(cz.mzk.recordmanager.server.metadata.MetadataRecord) Record(org.marc4j.marc.Record) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) MetadataRecord(cz.mzk.recordmanager.server.metadata.MetadataRecord)

Example 2 with MetadataRecord

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

the class DublinCoreRecordImplTest method getISMNsTest.

@Test
public void getISMNsTest() throws Exception {
    DublinCoreRecord dcr = new DublinCoreRecordImpl();
    MetadataRecord metadataRecord;
    String ismn1str = "ismn:M-66051-073-5(comment)";
    // bad
    String ismn2str = "ismn:M-66051-0753-5";
    dcr.addIdentifier(ismn1str);
    dcr.addIdentifier(ismn2str);
    metadataRecord = metadataFactory.getMetadataRecord(dcr);
    List<Ismn> ismns = metadataRecord.getISMNs();
    Assert.assertTrue(ismns.contains(Ismn.create(9790660510735L, 1L, "")));
    Assert.assertTrue(ismns.size() == 1);
}
Also used : MetadataRecord(cz.mzk.recordmanager.server.metadata.MetadataRecord) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 3 with MetadataRecord

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

the class DublinCoreRecordImplTest method getPublicationYearTest.

/* --- _Metadata_ DublinCoreRecord tests --- */
@Test
public void getPublicationYearTest() throws Exception {
    DublinCoreRecord dcr = new DublinCoreRecordImpl();
    MetadataRecord metadataRecord;
    dcr.addDate("1982");
    metadataRecord = metadataFactory.getMetadataRecord(dcr);
    Assert.assertEquals(metadataRecord.getPublicationYear().longValue(), 1982);
}
Also used : MetadataRecord(cz.mzk.recordmanager.server.metadata.MetadataRecord) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 4 with MetadataRecord

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

the class ImportTezaurusRecordsWriter method write.

@Override
public void write(List<? extends List<Record>> items) throws Exception {
    if (config == null) {
        config = oaiHarvestConfDao.get(confId);
    }
    for (List<Record> records : items) {
        for (Record currentRecord : records) {
            try {
                MarcRecord marc = new MarcRecordImpl(currentRecord);
                MetadataRecord metadata = metadataFactory.getMetadataRecord(marc, config);
                String recordId = metadata.getUniqueId();
                TezaurusRecord tr = tezaurusDao.findByIdAndHarvestConfiguration(recordId, config);
                if (tr == null) {
                    tr = new TezaurusRecord();
                    tr.setRecordId(recordId);
                    tr.setHarvestedFrom(config);
                }
                tr.setTezaurusKey(metadata.getTezaurusKey());
                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                MarcWriter marcWriter = new MarcXmlWriter(outStream, true);
                marcWriter.write(currentRecord);
                marcWriter.close();
                byte[] recordContent = outStream.toByteArray();
                tr.setRawRecord(recordContent);
                tezaurusDao.persist(tr);
            } catch (Exception e) {
                logger.warn("Error occured in processing record");
                throw e;
            }
        }
    }
}
Also used : MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) TezaurusRecord(cz.mzk.recordmanager.server.model.TezaurusRecord) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) MarcWriter(org.marc4j.MarcWriter) MetadataRecord(cz.mzk.recordmanager.server.metadata.MetadataRecord) Record(org.marc4j.marc.Record) TezaurusRecord(cz.mzk.recordmanager.server.model.TezaurusRecord) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MetadataRecord(cz.mzk.recordmanager.server.metadata.MetadataRecord) MarcXmlWriter(org.marc4j.MarcXmlWriter)

Example 5 with MetadataRecord

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

the class MarcRecordImplTest method getLanguagesTest.

@Test
public void getLanguagesTest() throws Exception {
    MarcRecordImpl mri;
    MetadataRecord metadataRecord;
    List<String> data = new ArrayList<>();
    data.add("041 $aeng$acze");
    mri = MarcRecordFactory.recordFactory(data);
    metadataRecord = metadataFactory.getMetadataRecord(mri);
    Assert.assertEquals(metadataRecord.getLanguages().size(), 2);
    data = new ArrayList<>();
    data.add("041 $abel");
    mri = MarcRecordFactory.recordFactory(data);
    metadataRecord = metadataFactory.getMetadataRecord(mri);
    Assert.assertEquals(metadataRecord.getLanguages().size(), 1);
    Assert.assertTrue(metadataRecord.getLanguages().contains("oth"));
    data = new ArrayList<>();
    data.add("008 960925s1891    gw ||||| |||||||||||eng|d");
    mri = MarcRecordFactory.recordFactory(data);
    metadataRecord = metadataFactory.getMetadataRecord(mri);
    Assert.assertEquals(metadataRecord.getLanguages().size(), 1);
    Assert.assertTrue(metadataRecord.getLanguages().get(0).contains("eng"));
    data = new ArrayList<>();
    data.add("008 960925s1891    gw ||||| |||||||||||bel|d");
    mri = MarcRecordFactory.recordFactory(data);
    metadataRecord = metadataFactory.getMetadataRecord(mri);
    Assert.assertEquals(metadataRecord.getLanguages().size(), 0);
}
Also used : ArrayList(java.util.ArrayList) MetadataRecord(cz.mzk.recordmanager.server.metadata.MetadataRecord) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

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