Search in sources :

Example 1 with MarcFunctionContext

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

the class MarcSolrRecordMapper method parseAsDedupRecord.

protected Map<String, Object> parseAsDedupRecord(HarvestedRecord record) {
    InputStream is = new ByteArrayInputStream(record.getRawRecord());
    MarcRecord rec = marcXmlParser.parseRecord(is);
    MappingScript<MarcFunctionContext> script = getDedupMappingScript(record);
    MarcFunctionContext ctx = new MarcFunctionContext(rec, record, metadataRecordFactory.getMetadataRecord(record));
    Map<String, Object> result = script.parse(ctx);
    return result;
}
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 2 with MarcFunctionContext

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

the class MarcScriptFactoryTest method test1.

@Test
@SuppressWarnings("unchecked")
public void test1() {
    MarcRecord record = parser.parseRecord(this.getClass().getResourceAsStream("/records/marcxml/MZK01-001439241.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);
    Assert.assertEquals(entries.get("author"), null);
    Assert.assertEquals(entries.get("published"), "Rožnov pod Radhoštěm : Proxima Bohemia, 2014");
    Assert.assertEquals(entries.get("title"), "Česká republika : města a obce České republiky : tradice, historie, památky, turistika, současnost /");
    Assert.assertNotNull(entries.get("language"));
    Assert.assertTrue(entries.get("language") instanceof List<?>);
    List<String> languages = (List<String>) entries.get("language");
    Assert.assertEquals(languages.size(), 1);
    Assert.assertEquals(languages.get(0), "Czech");
}
Also used : InputStream(java.io.InputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) List(java.util.List) MarcFunctionContext(cz.mzk.recordmanager.server.scripting.marc.MarcFunctionContext) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Example 3 with MarcFunctionContext

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

the class BoundingBoxMarcFunctionsTest method testPrague.

@Test
public void testPrague() throws Exception {
    List<String> data = new ArrayList<String>();
    data.add("034 $aa $b20000 $dE0141016 $eE0144724 $fN0501302 $gN0495545");
    MarcRecord record = MarcRecordFactory.recordFactory(data);
    String result = functions.getBoundingBox(new MarcFunctionContext(record, null, null));
    Assert.assertEquals(result, "14.171111111111111 49.92916666666667 14.79 50.217222222222226");
}
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 4 with MarcFunctionContext

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

the class BoundingBoxMarcFunctionsTest method testInvalidRecord.

@Test
public void testInvalidRecord() throws Exception {
    List<String> data = new ArrayList<String>();
    data.add("034 $aa $dE0142526 $eE0142526 $fN0500516 $gN0500516");
    MarcRecord record = MarcRecordFactory.recordFactory(data);
    String result = functions.getBoundingBox(new MarcFunctionContext(record, null, null));
    Assert.assertNull(result);
}
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 5 with MarcFunctionContext

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

the class BoundingBoxMarcFunctionsTest method testCzechRepublic.

@Test
public void testCzechRepublic() throws Exception {
    List<String> data = new ArrayList<String>();
    data.add("034 $aa $b200000 $dE0115843 $eE0185426 $fN0510158 $gN0483256");
    MarcRecord record = MarcRecordFactory.recordFactory(data);
    String result = functions.getBoundingBoxAsPolygon(new MarcFunctionContext(record, null, null));
    Assert.assertEquals(result, "POLYGON((11.979 48.549, 18.907 48.549, 18.907 51.033, 11.979 51.033, 11.979 48.549))");
}
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)

Aggregations

MarcFunctionContext (cz.mzk.recordmanager.server.scripting.marc.MarcFunctionContext)17 ArrayList (java.util.ArrayList)13 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)9 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)7 Test (org.testng.annotations.Test)7 InputStream (java.io.InputStream)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)1 Collection (java.util.Collection)1 List (java.util.List)1