use of org.marc4j.marc.Record in project RecordManager2 by moravianlibrary.
the class MarcFactoryImpl method newRecord.
/**
* Returns a new {@link Record} with the supplied {@link Leader}.
*/
@Override
public Record newRecord(Leader leader) {
Record record = new RecordImpl();
record.setLeader(leader);
return record;
}
use of org.marc4j.marc.Record in project RecordManager2 by moravianlibrary.
the class FilterCaslinRecordsWriter method write.
@Override
public void write(List<? extends HarvestedRecordUniqueId> items) throws Exception {
for (HarvestedRecordUniqueId uniqueId : items) {
try {
HarvestedRecord hr = hrDao.get(uniqueId);
if (hr == null || hr.getRawRecord().length == 0)
continue;
MarcRecord marc = marcXmlParser.parseRecord(new ByteArrayInputStream(hr.getRawRecord()));
Record record = marcXmlParser.parseUnderlyingRecord(new ByteArrayInputStream(hr.getRawRecord()));
Boolean updated = false;
Record newRecord = new RecordImpl();
MarcFactory marcFactory = new MarcFactoryImpl();
newRecord.setLeader(record.getLeader());
for (ControlField cf : record.getControlFields()) {
newRecord.addVariableField(cf);
}
Map<String, List<DataField>> dfMap = marc.getAllFields();
for (String tag : new TreeSet<String>(dfMap.keySet())) {
for (DataField df : dfMap.get(tag)) {
// add $q0 when sigla is in db
if (df.getTag().equals("996")) {
if (caslinFilter.filter(df.getSubfield('e').getData()) && (df.getSubfield('q') == null || !df.getSubfield('q').getData().equals("0"))) {
df.addSubfield(marcFactory.newSubfield('q', "0"));
updated = true;
}
}
newRecord.addVariableField(df);
}
}
hr.setRawRecord(new MarcRecordImpl(newRecord).export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8));
if (hr.getDeleted() == null && !mrFactory.getMetadataRecord(hr).matchFilter()) {
hr.setDeleted(new Date());
updated = true;
}
if (updated) {
hr.setUpdated(new Date());
hrDao.persist(hr);
}
} catch (Exception ex) {
logger.error(String.format("Exception thrown when filtering harvested_record with id=%s", uniqueId), ex);
}
}
}
use of org.marc4j.marc.Record in project RecordManager2 by moravianlibrary.
the class AgrovocConvertorWriter method after.
@AfterStep
protected void after() {
try {
writer = new PrintWriter(filename, "UTF-8");
for (String key : altLabel.keySet()) {
if (!prefLabel.containsKey(key)) {
continue;
}
Record record = factory.newRecord();
record.setLeader(factory.newLeader("-----nz--a22-----n--4500"));
record.addVariableField(factory.newControlField("001", key));
record.addVariableField(factory.newDataField("150", ' ', ' ', "a", prefLabel.get(key).get(0)));
addLabel(record, key, altLabel);
writer.println((new MarcRecordImpl(record)).export(IOFormat.LINE_MARC));
}
writer.close();
} catch (FileNotFoundException | UnsupportedEncodingException e) {
e.printStackTrace();
}
}
use of org.marc4j.marc.Record in project RecordManager2 by moravianlibrary.
the class GenerateItemIdWriter method write.
@Override
public void write(List<? extends HarvestedRecordUniqueId> items) throws Exception {
for (HarvestedRecordUniqueId uniqueId : items) {
try {
progress.incrementAndLogProgress();
HarvestedRecord hr = hrDao.get(uniqueId);
if (hr == null || hr.getRawRecord() == null || hr.getRawRecord().length == 0 || !hr.getFormat().equals("marc21-xml") || hr.getHarvestedFrom().getItemId() == null) {
continue;
}
Record record = marcXmlParser.parseUnderlyingRecord(new ByteArrayInputStream(hr.getRawRecord()));
hr.setRawRecord(new DefaultMarcInterceptor(record, hr.getHarvestedFrom(), uniqueId.getRecordId()).intercept());
} catch (Exception ex) {
logger.error(String.format("Exception thrown in harvested_record with id=%s", uniqueId), ex);
}
}
}
use of org.marc4j.marc.Record in project RecordManager2 by moravianlibrary.
the class CosmotronHarvestJobTest method test996BeforeRecord.
@Test
public void test996BeforeRecord() throws Exception {
reset(httpClient);
InputStream response0 = this.getClass().getResourceAsStream("/sample/Identify.xml");
InputStream response1 = this.getClass().getResourceAsStream("/sample/cosmotron/996BeforeRecord.xml");
expect(httpClient.executeGet("http://katalog.cbvk.cz/i2/i2.ws.oai.cls?verb=Identify")).andReturn(response0);
expect(httpClient.executeGet("http://katalog.cbvk.cz/i2/i2.ws.oai.cls?verb=ListRecords&metadataPrefix=oai_marcxml_cpk")).andReturn(response1);
replay(httpClient);
final Long confID = 328L;
Map<String, JobParameter> params = new HashMap<>();
params.put(Constants.JOB_PARAM_CONF_ID, new JobParameter(confID));
JobExecution exec = jobExecutor.execute(Constants.JOB_ID_HARVEST_COSMOTRON, new JobParameters(params));
Assert.assertEquals(exec.getExitStatus(), ExitStatus.COMPLETED);
OAIHarvestConfiguration config = configDao.get(confID);
HarvestedRecord hr = recordDao.findByIdAndHarvestConfiguration("CbvkUsCat" + Constants.COSMOTRON_RECORD_ID_CHAR + "m0000002", config);
Assert.assertNotNull(hr);
Assert.assertNotNull(cosmotronDao.findByIdAndHarvestConfiguration("CbvkUsCat" + Constants.COSMOTRON_RECORD_ID_CHAR + "0000003", config));
Assert.assertNotNull(cosmotronDao.findByIdAndHarvestConfiguration("CbvkUsCat" + Constants.COSMOTRON_RECORD_ID_CHAR + "0000004", config));
Assert.assertNotNull(cosmotronDao.findByIdAndHarvestConfiguration("CbvkUsCat" + Constants.COSMOTRON_RECORD_ID_CHAR + "0000005", config));
InputStream is = new ByteArrayInputStream(hr.getRawRecord());
Record record = marcXmlParser.parseUnderlyingRecord(is);
MarcRecord marcRecord = new MarcRecordImpl(record);
Assert.assertEquals(marcRecord.getDataFields("996").size(), 3);
}
Aggregations