use of cz.mzk.recordmanager.server.marc.MarcRecordImpl in project RecordManager2 by moravianlibrary.
the class CosmotronHarvestJobTest method testCopy996ToParentRecord.
@Test
public void testCopy996ToParentRecord() throws Exception {
reset(httpClient);
InputStream response0 = this.getClass().getResourceAsStream("/sample/Identify.xml");
InputStream response1 = this.getClass().getResourceAsStream("/sample/cosmotron/RecordAnd996.xml");
InputStream response2 = this.getClass().getResourceAsStream("/sample/cosmotron/Deleted996.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);
expect(httpClient.executeGet("http://katalog.cbvk.cz/i2/i2.ws.oai.cls?verb=ListRecords&resumptionToken=123456")).andReturn(response2);
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);
InputStream is = new ByteArrayInputStream(hr.getRawRecord());
Record record = marcXmlParser.parseUnderlyingRecord(is);
MarcRecord marcRecord = new MarcRecordImpl(record);
Assert.assertEquals(marcRecord.getDataFields("996").size(), 2);
}
use of cz.mzk.recordmanager.server.marc.MarcRecordImpl in project RecordManager2 by moravianlibrary.
the class CosmotronHarvestJobTest method testHarvestRecords.
@Test
public void testHarvestRecords() throws Exception {
reset(httpClient);
InputStream response0 = this.getClass().getResourceAsStream("/sample/Identify.xml");
InputStream response1 = this.getClass().getResourceAsStream("/sample/ListRecords2.xml");
expect(httpClient.executeGet("http://aleph.mzk.cz/OAI?verb=Identify")).andReturn(response0);
expect(httpClient.executeGet("http://aleph.mzk.cz/OAI?verb=ListRecords&metadataPrefix=marc21")).andReturn(response1);
replay(httpClient);
final Long confID = 300L;
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);
HarvestedRecord hr = recordDao.findByIdAndHarvestConfiguration("MZK01-000213478", confID);
Assert.assertNotNull(hr);
InputStream is = new ByteArrayInputStream(hr.getRawRecord());
Record record = marcXmlParser.parseUnderlyingRecord(is);
MarcRecord marcRecord = new MarcRecordImpl(record);
Assert.assertEquals(marcRecord.getDataFields("996").size(), 5);
}
use of cz.mzk.recordmanager.server.marc.MarcRecordImpl in project RecordManager2 by moravianlibrary.
the class TdkivMarcInterceptor method intercept.
@Override
public byte[] intercept() {
if (super.getRecord() == null) {
return new byte[0];
}
Record newRecord = new RecordImpl();
MarcFactory marcFactory = new MarcFactoryImpl();
newRecord.addVariableField(marcFactory.newControlField("FMT", "VA"));
newRecord.addVariableField(marcFactory.newControlField("003", "CZ-PrNK"));
newRecord.addVariableField(marcFactory.newControlField("005", new SimpleDateFormat(DATE_STRING_005).format(new Date())));
newRecord.addVariableField(marcFactory.newControlField("008", "000804|n|anznnbabn-----------n-a|a------"));
newRecord.addVariableField(marcFactory.newDataField("040", ' ', ' ', "a", "ABA001", "b", "cze", "d", "ABA001"));
newRecord.setLeader(getRecord().getLeader());
for (ControlField cf : super.getRecord().getControlFields()) {
newRecord.addVariableField(cf);
}
for (DataField df : super.getRecord().getDataFields()) {
if (df.getTag().equals("DRL") && df.getSubfield('a') != null && newRecord.getControlNumberField() == null) {
Matcher matcher = RECORD_ID.matcher(df.getSubfield('a').getData());
if (matcher.find()) {
newRecord.addVariableField(marcFactory.newControlField("001", matcher.group(1)));
}
}
if (TAGS.containsKey(df.getTag())) {
df.setTag(TAGS.get(df.getTag()));
} else if (df.getTag().equals("ANG")) {
df.setTag("750");
df.setIndicator1('0');
df.setIndicator2('7');
} else if (df.getTag().equals("DRL")) {
df = marcFactory.newDataField("856", '4', '1', "u", df.getSubfield('a').getData(), "y", TEXT_856y);
} else
continue;
newRecord.addVariableField(df);
}
return new MarcRecordImpl(newRecord).export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8);
}
use of cz.mzk.recordmanager.server.marc.MarcRecordImpl in project RecordManager2 by moravianlibrary.
the class CbvkMarcInterceptor method intercept.
@Override
public byte[] intercept() {
if (super.getRecord() == null) {
return new byte[0];
}
MarcRecord marc = new MarcRecordImpl(super.getRecord());
Record newRecord = new RecordImpl();
newRecord.setLeader(getRecord().getLeader());
for (ControlField cf : super.getRecord().getControlFields()) {
newRecord.addVariableField(cf);
}
Map<String, List<DataField>> dfMap = marc.getAllFields();
for (String tag : new TreeSet<String>(dfMap.keySet())) {
// sorted tags
for (DataField df : dfMap.get(tag)) {
// remove field 520
if (df.getTag().equals("520"))
continue;
processField996(df);
newRecord.addVariableField(df);
}
}
return new MarcRecordImpl(newRecord).export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8);
}
Aggregations