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, "")));
}
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);
}
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);
}
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');
}
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;
}
}
}
}
Aggregations