Search in sources :

Example 1 with AuthorityRecord

use of cz.mzk.recordmanager.server.model.AuthorityRecord in project RecordManager2 by moravianlibrary.

the class OAIAuthItemWriter method write.

protected void write(OAIRecord record) throws TransformerException {
    String recordId = record.getHeader().getIdentifier();
    AuthorityRecord authRec = recordDao.findByIdAndHarvestConfiguration(recordId, configuration);
    if (authRec == null) {
        authRec = new AuthorityRecord();
        authRec.setOaiRecordId(record.getHeader().getIdentifier());
        authRec.setHarvestedFrom(configuration);
        authRec.setFormat(format);
    }
    if (record.getHeader().isDeleted()) {
        authRec.setDeleted(new Date());
        authRec.setRawRecord(new byte[0]);
        recordDao.persist(authRec);
        return;
    } else {
        Element element = record.getMetadata().getElement();
        authRec.setRawRecord(asByteArray(element));
        authRec.setAuthorityCode(getAuthorityCode(authRec.getRawRecord()));
    }
    recordDao.persist(authRec);
}
Also used : AuthorityRecord(cz.mzk.recordmanager.server.model.AuthorityRecord) Element(org.w3c.dom.Element) Date(java.util.Date)

Example 2 with AuthorityRecord

use of cz.mzk.recordmanager.server.model.AuthorityRecord in project RecordManager2 by moravianlibrary.

the class OAIHarvestAuthorityJobTest method testHarvestAuthorityRecords.

@Test
public void testHarvestAuthorityRecords() throws Exception {
    reset(httpClient);
    InputStream response0 = this.getClass().getResourceAsStream("/auth/Identify.xml");
    InputStream response1 = this.getClass().getResourceAsStream("/auth/ListRecords1.xml");
    expect(httpClient.executeGet("http://aleph.nkp.cz/OAI?verb=Identify")).andReturn(response0);
    expect(httpClient.executeGet("http://aleph.nkp.cz/OAI?verb=ListRecords&metadataPrefix=marc21&set=AUTH")).andReturn(response1);
    replay(httpClient);
    final Long configId = oaiConfiguration.getId();
    Map<String, JobParameter> params = new HashMap<String, JobParameter>();
    params.put("configurationId", new JobParameter(configId));
    JobParameters jobParams = new JobParameters(params);
    JobExecution exec = jobExecutor.execute(Constants.JOB_ID_HARVEST_AUTH, jobParams);
    Assert.assertEquals(exec.getExitStatus(), ExitStatus.COMPLETED);
    AuthorityRecord authRec = authorityRecordDao.findByIdAndHarvestConfiguration("oai:aleph-nkp.cz:AUT10-000000001", oaiConfiguration);
    Assert.assertNotNull(authRec);
    Assert.assertEquals(authRec.getAuthorityCode(), "jk01010001");
    authRec = authorityRecordDao.findByIdAndHarvestConfiguration("oai:aleph-nkp.cz:AUT10-000000006", oaiConfiguration);
    Assert.assertEquals(authRec.getAuthorityCode(), "jk01010009");
    Assert.assertNotNull(authRec);
    authRec = authorityRecordDao.findByIdAndHarvestConfiguration("oai:aleph-nkp.cz:AUT10-000000007", oaiConfiguration);
    Assert.assertEquals(authRec.getAuthorityCode(), "jk01010010");
    Assert.assertNotNull(authRec);
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) HashMap(java.util.HashMap) InputStream(java.io.InputStream) AuthorityRecord(cz.mzk.recordmanager.server.model.AuthorityRecord) JobParameters(org.springframework.batch.core.JobParameters) JobParameter(org.springframework.batch.core.JobParameter) Test(org.testng.annotations.Test) AbstractTest(cz.mzk.recordmanager.server.AbstractTest)

Aggregations

AuthorityRecord (cz.mzk.recordmanager.server.model.AuthorityRecord)2 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 JobExecution (org.springframework.batch.core.JobExecution)1 JobParameter (org.springframework.batch.core.JobParameter)1 JobParameters (org.springframework.batch.core.JobParameters)1 Test (org.testng.annotations.Test)1 Element (org.w3c.dom.Element)1