Search in sources :

Example 26 with MarcRecord

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

Example 27 with MarcRecord

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

the class GetStatusesMarcFunctions method getStatuses.

public List<String> getStatuses(MarcFunctionContext ctx) {
    MarcRecord record = ctx.record();
    List<String> statuses = new ArrayList<String>();
    statuses.addAll(ctx.metadataRecord().getDefaultStatuses());
    if (statuses.isEmpty())
        statuses.addAll(getStatusFrom856(record, "856"));
    statuses.addAll(getStatuses(record, "996"));
    return statuses;
}
Also used : ArrayList(java.util.ArrayList) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord)

Example 28 with MarcRecord

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

the class PublishDateMarcFunctions method getPublishDateFromFields.

public Set<String> getPublishDateFromFields(MarcFunctionContext ctx) {
    MarcRecord record = ctx.record();
    Set<String> years = new TreeSet<>();
    for (DataField datafield : record.getDataFields("264")) {
        if (datafield.getIndicator2() == '1') {
            if (datafield.getSubfield('c') != null) {
                years.add(datafield.getSubfield('c').getData());
            }
        }
    }
    years.addAll(record.getFields("260", 'c'));
    years.addAll(record.getFields("773", '9'));
    years.addAll(record.getFields("996", 'y'));
    Set<String> results = new TreeSet<>();
    years.forEach(y -> {
        Matcher matcher;
        if ((matcher = FOUR_DIGIT_YEAR_PATTERN.matcher(y)).find())
            results.add(matcher.group(1));
    });
    return results;
}
Also used : DataField(org.marc4j.marc.DataField) Matcher(java.util.regex.Matcher) TreeSet(java.util.TreeSet) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord)

Example 29 with MarcRecord

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

the class ImportRecordsJobTest method testSimpleImportOsobnosti.

@Test
public void testSimpleImportOsobnosti() throws Exception {
    Job job = jobRegistry.getJob(Constants.JOB_ID_IMPORT);
    Map<String, JobParameter> params = new HashMap<>();
    params.put(Constants.JOB_PARAM_CONF_ID, new JobParameter(300L));
    params.put(Constants.JOB_PARAM_IN_FILE, new JobParameter(testFileOsobnosti1));
    params.put(Constants.JOB_PARAM_FORMAT, new JobParameter("osobnosti"));
    JobParameters jobParams = new JobParameters(params);
    jobLauncher.run(job, jobParams);
    HarvestedRecord hr = harvestedRecordDao.findByIdAndHarvestConfiguration("5", 300L);
    Assert.assertNotNull(hr);
    InputStream is = new ByteArrayInputStream(hr.getRawRecord());
    MarcRecord mr = new MarcRecordImpl(marcXmlParser.parseUnderlyingRecord(is));
    Assert.assertFalse(mr.getDataFields("100").isEmpty());
    Assert.assertFalse(mr.getDataFields("670").isEmpty());
    Assert.assertEquals(mr.getDataFields("856").size(), 1);
}
Also used : MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) JobParameters(org.springframework.batch.core.JobParameters) Job(org.springframework.batch.core.Job) 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 30 with MarcRecord

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

the class ImportRecordsJobTest method testSimpleImportPatents.

@Test
public void testSimpleImportPatents() throws Exception {
    Job job = jobRegistry.getJob(Constants.JOB_ID_IMPORT);
    Map<String, JobParameter> params = new HashMap<>();
    params.put(Constants.JOB_PARAM_CONF_ID, new JobParameter(300L));
    params.put(Constants.JOB_PARAM_IN_FILE, new JobParameter(testFilePatents1));
    params.put(Constants.JOB_PARAM_FORMAT, new JobParameter("patents"));
    JobParameters jobParams = new JobParameters(params);
    jobLauncher.run(job, jobParams);
    HarvestedRecord hr = harvestedRecordDao.findByIdAndHarvestConfiguration("St36_CZ_305523_B6", 300L);
    Assert.assertNotNull(hr);
    InputStream is = new ByteArrayInputStream(hr.getRawRecord());
    MarcRecord mr = new MarcRecordImpl(marcXmlParser.parseUnderlyingRecord(is));
    Assert.assertFalse(mr.getDataFields("100").isEmpty());
    Assert.assertFalse(mr.getDataFields("520").isEmpty());
}
Also used : MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) JobParameters(org.springframework.batch.core.JobParameters) Job(org.springframework.batch.core.Job) 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