Search in sources :

Example 26 with Record

use of org.marc4j.marc.Record 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 27 with Record

use of org.marc4j.marc.Record 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)

Example 28 with Record

use of org.marc4j.marc.Record 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);
}
Also used : 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)

Example 29 with Record

use of org.marc4j.marc.Record in project RecordManager2 by moravianlibrary.

the class MarcInterceptorFactory method getInterceptor.

public MarcRecordInterceptor getInterceptor(ImportConfiguration configuration, String recordId, byte[] rawRecord) {
    String prefix = configuration.getIdPrefix();
    try {
        Record record = parseRecord(rawRecord);
        switch(prefix) {
            case Constants.PREFIX_CASLIN:
                MarcRecordInterceptor mri = new SkatMarcInterceptor(record);
                appCtx.getAutowireCapableBeanFactory().autowireBean(mri);
                return mri;
            case Constants.PREFIX_MZKNORMS:
                return new MzkNormsMarcInterceptor(record);
            case Constants.PREFIX_NLK:
                return new NlkMarcInterceptor(record, configuration, recordId);
            case Constants.PREFIX_OPENLIB:
                return new OpenlibMarcInterceptor(record);
            case Constants.PREFIX_KKVY:
                return new KkvyMarcInterceptor(record, configuration, recordId);
            case Constants.PREFIX_CBVK:
                return new CbvkMarcInterceptor(record, configuration, recordId);
            case Constants.PREFIX_BMC:
                return new BmcMarcInterceptor(record);
            case Constants.PREFIX_TDKIV:
                return new TdkivMarcInterceptor(record);
            case Constants.PREFIX_CELITEBIB:
                return new CelitebibMarcInterceptor(record);
            default:
                return new DefaultMarcInterceptor(record, configuration, recordId);
        }
    } catch (InvalidMarcException ime) {
        return null;
    }
}
Also used : InvalidMarcException(cz.mzk.recordmanager.server.marc.InvalidMarcException) Record(org.marc4j.marc.Record)

Example 30 with Record

use of org.marc4j.marc.Record 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);
}
Also used : ControlField(org.marc4j.marc.ControlField) DataField(org.marc4j.marc.DataField) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) Matcher(java.util.regex.Matcher) Record(org.marc4j.marc.Record) MarcFactory(org.marc4j.marc.MarcFactory) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) RecordImpl(cz.mzk.recordmanager.server.marc.marc4j.RecordImpl) MarcFactoryImpl(cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

Record (org.marc4j.marc.Record)32 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)21 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)20 DataField (org.marc4j.marc.DataField)13 ControlField (org.marc4j.marc.ControlField)12 RecordImpl (cz.mzk.recordmanager.server.marc.marc4j.RecordImpl)11 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)10 List (java.util.List)10 TreeSet (java.util.TreeSet)9 InputStream (java.io.InputStream)8 MarcFactory (org.marc4j.marc.MarcFactory)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 MarcFactoryImpl (cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl)6 Date (java.util.Date)6 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)5 HashMap (java.util.HashMap)5 Matcher (java.util.regex.Matcher)5 MarcWriter (org.marc4j.MarcWriter)5 MarcXmlWriter (org.marc4j.MarcXmlWriter)5 JobExecution (org.springframework.batch.core.JobExecution)5