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