Search in sources :

Example 36 with MarcRecord

use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.

the class BmcMarcInterceptor 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 990, 991
            if (!df.getTag().equals("990") && !df.getTag().equals("991"))
                newRecord.addVariableField(df);
        }
    }
    return new MarcRecordImpl(newRecord).export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8);
}
Also used : MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) ControlField(org.marc4j.marc.ControlField) DataField(org.marc4j.marc.DataField) TreeSet(java.util.TreeSet) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) Record(org.marc4j.marc.Record) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) List(java.util.List) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) RecordImpl(cz.mzk.recordmanager.server.marc.marc4j.RecordImpl)

Example 37 with MarcRecord

use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.

the class MarcSolrRecordMapper method parseAsLocalRecord.

protected Map<String, Object> parseAsLocalRecord(HarvestedRecord record) {
    InputStream is = new ByteArrayInputStream(record.getRawRecord());
    MarcRecord rec = marcXmlParser.parseRecord(is);
    MarcFunctionContext ctx = new MarcFunctionContext(rec, record, metadataRecordFactory.getMetadataRecord(record));
    return getHarvestedMappingScript(record).parse(ctx);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) MarcFunctionContext(cz.mzk.recordmanager.server.scripting.marc.MarcFunctionContext)

Example 38 with MarcRecord

use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.

the class AbstractAuthorityVizFields method getEnrichingValues.

@Override
protected List<String> getEnrichingValues(String key, String enrichingField) {
    Map<String, List<String>> cache = cacheMap.get(enrichingField);
    if (cache.containsKey(key)) {
        return new ArrayList<>(cache.get(key));
    } else {
        HarvestedRecord hr = hrdao.findByHarvestConfAndRaw001Id(400L, key);
        if (hr != null) {
            MarcRecord mr = marcXmlParser.parseRecord(new ByteArrayInputStream(hr.getRawRecord()));
            List<String> results = Collections.unmodifiableList(mr.getFields(enrichingField, " ", 'a', 'b', 'c', 'd'));
            if (!results.isEmpty()) {
                cache.put(key, results);
                return new ArrayList<>(results);
            }
        }
    }
    return null;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) ArrayList(java.util.ArrayList) List(java.util.List) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord)

Example 39 with MarcRecord

use of cz.mzk.recordmanager.server.marc.MarcRecord in project RecordManager2 by moravianlibrary.

the class CosmotronHarvestJobTest method testUpdated996.

@Test
public void testUpdated996() 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/Updated996.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);
    Assert.assertNotNull(recordDao.findByIdAndHarvestConfiguration("CbvkUsCat" + Constants.COSMOTRON_RECORD_ID_CHAR + "m0000002", config));
    Cosmotron996 cosmo = cosmotronDao.findByIdAndHarvestConfiguration("CbvkUsCat" + Constants.COSMOTRON_RECORD_ID_CHAR + "0000003", config);
    Assert.assertNotNull(cosmo);
    InputStream is = new ByteArrayInputStream(cosmo.getRawRecord());
    Record record = marcXmlParser.parseUnderlyingRecord(is);
    MarcRecord marcRecord = new MarcRecordImpl(record);
    Assert.assertNotNull(marcRecord.getDataFields("100"));
}
Also used : OAIHarvestConfiguration(cz.mzk.recordmanager.server.model.OAIHarvestConfiguration) HashMap(java.util.HashMap) Cosmotron996(cz.mzk.recordmanager.server.model.Cosmotron996) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) JobExecution(org.springframework.batch.core.JobExecution) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) Record(org.marc4j.marc.Record) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) JobParameters(org.springframework.batch.core.JobParameters) JobParameter(org.springframework.batch.core.JobParameter) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 40 with MarcRecord

use of cz.mzk.recordmanager.server.marc.MarcRecord 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);
}
Also used : OAIHarvestConfiguration(cz.mzk.recordmanager.server.model.OAIHarvestConfiguration) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) JobExecution(org.springframework.batch.core.JobExecution) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) Record(org.marc4j.marc.Record) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) JobParameters(org.springframework.batch.core.JobParameters) JobParameter(org.springframework.batch.core.JobParameter) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Aggregations

MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)46 ByteArrayInputStream (java.io.ByteArrayInputStream)22 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)21 InputStream (java.io.InputStream)19 Record (org.marc4j.marc.Record)19 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)15 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)15 DataField (org.marc4j.marc.DataField)15 Test (org.testng.annotations.Test)15 List (java.util.List)13 ArrayList (java.util.ArrayList)11 TreeSet (java.util.TreeSet)11 ControlField (org.marc4j.marc.ControlField)11 RecordImpl (cz.mzk.recordmanager.server.marc.marc4j.RecordImpl)10 MarcFunctionContext (cz.mzk.recordmanager.server.scripting.marc.MarcFunctionContext)9 JobParameters (org.springframework.batch.core.JobParameters)8 HashMap (java.util.HashMap)7 JobParameter (org.springframework.batch.core.JobParameter)7 MarcFactoryImpl (cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl)5 MarcFactory (org.marc4j.marc.MarcFactory)5