Search in sources :

Example 41 with MarcRecord

use of cz.mzk.recordmanager.server.marc.MarcRecord 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 42 with MarcRecord

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

the class MarcScriptFactoryTest method test2.

@Test
public void test2() {
    MarcRecord record = parser.parseRecord(this.getClass().getResourceAsStream("/records/marcxml/MZK01-000087310.xml"));
    InputStream is1 = getClass().getResourceAsStream("/groovy/ExtendedMarc.groovy");
    InputStream is2 = getClass().getResourceAsStream("/groovy/BaseMarc.groovy");
    MappingScript<MarcFunctionContext> script = factory.create(is1, is2);
    MarcFunctionContext ctx = new MarcFunctionContext(record, metadataRecordFactory.getMetadataRecord(record));
    Map<String, Object> entries = script.parse(ctx);
    Collection<?> author2Roles = (Collection<?>) entries.get("author2_role");
    Assert.assertTrue(author2Roles.isEmpty());
}
Also used : InputStream(java.io.InputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) Collection(java.util.Collection) MarcFunctionContext(cz.mzk.recordmanager.server.scripting.marc.MarcFunctionContext) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 43 with MarcRecord

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

the class BoundingBoxMarcFunctionsTest method testAustralia.

@Test
public void testAustralia() throws Exception {
    List<String> data = new ArrayList<String>();
    data.add("034 $aa $b6000000 $dE1023922  $eE1784848 $fN0023252 $gS0474141");
    MarcRecord record = MarcRecordFactory.recordFactory(data);
    String result = functions.getBoundingBox(new MarcFunctionContext(record, null, null));
    Assert.assertEquals(result, "102.65611111111112 -47.69472222222222 178.81333333333333 2.5477777777777777");
}
Also used : ArrayList(java.util.ArrayList) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) MarcFunctionContext(cz.mzk.recordmanager.server.scripting.marc.MarcFunctionContext) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 44 with MarcRecord

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

the class BoundingBoxMarcFunctionsTest method testSantiago.

@Test
public void testSantiago() throws Exception {
    List<String> data = new ArrayList<String>();
    data.add("034 $aa $b5100000 $dW0720810 $eW0475023 $fS0135757 $gS0345432");
    MarcRecord record = MarcRecordFactory.recordFactory(data);
    String result = functions.getBoundingBox(new MarcFunctionContext(record, null, null));
    Assert.assertEquals(result, "-72.13611111111112 -34.90888888888889 -47.83972222222222 -13.965833333333332");
}
Also used : ArrayList(java.util.ArrayList) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) MarcFunctionContext(cz.mzk.recordmanager.server.scripting.marc.MarcFunctionContext) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 45 with MarcRecord

use of cz.mzk.recordmanager.server.marc.MarcRecord 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);
}
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)

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