use of cz.mzk.recordmanager.server.model.DownloadImportConfiguration in project RecordManager2 by moravianlibrary.
the class ImportRecordsFileReader method initializeDownloadReader.
protected void initializeDownloadReader() throws IOException {
DownloadImportConfiguration config = dicDao.get(confId);
if (config == null) {
throw new IllegalArgumentException(String.format("Configuration with id=%s not found.", confId));
}
String url = config.getUrl();
if (url == null || url.isEmpty()) {
throw new IllegalArgumentException(String.format("Missing url in DownloadImportConfiguration with id=%s.", confId));
}
this.format = IOFormat.stringToExportFormat(config.getFormat());
this.reader = getMarcReader(httpClient.executeGet(url));
}
use of cz.mzk.recordmanager.server.model.DownloadImportConfiguration in project RecordManager2 by moravianlibrary.
the class AntikvariatyRecordsReader method initializeReader.
protected void initializeReader() throws Exception {
DownloadImportConfiguration config = configDao.get(configId);
if (config == null) {
throw new IllegalArgumentException(String.format("Configuration with id=%s not found.", configId));
}
String url = config.getUrl();
if (url == null || url.isEmpty()) {
throw new IllegalArgumentException(String.format("Missing url in DownloadImportConfiguration with id=%s.", configId));
}
try {
reader = new StaxEventItemReader<AntikvariatyRecord>();
reader.setResource(new InputStreamResource(httpClient.executeGet(url)));
reader.setFragmentRootElementName("record");
Jaxb2Marshaller unmarshaller = new Jaxb2Marshaller();
unmarshaller.setClassesToBeBound(AntikvariatyRecord.class);
unmarshaller.afterPropertiesSet();
reader.setUnmarshaller(unmarshaller);
reader.setSaveState(false);
reader.open(null);
reader.afterPropertiesSet();
} catch (Exception ex) {
throw new RuntimeException("StaxEventItemReader can not be created", ex);
}
}
use of cz.mzk.recordmanager.server.model.DownloadImportConfiguration in project RecordManager2 by moravianlibrary.
the class OAIItemProcessor method beforeStep.
@Override
public void beforeStep(StepExecution stepExecution) {
try (SessionBinder session = sync.register()) {
Long confId = stepExecution.getJobParameters().getLong("configurationId");
OAIHarvestConfiguration hc = configDao.get(confId);
if (hc != null) {
format = formatResolver.resolve(hc.getMetadataPrefix());
String regex = MoreObjects.firstNonNull(hc.getRegex(), DEFAULT_EXTRACT_ID_PATTERN);
configuration = hc;
idExtractor = new RegexpExtractor(regex);
} else {
DownloadImportConfiguration dic = downloadImportConfDao.get(confId);
if (dic != null) {
format = formatResolver.resolve(Constants.METADATA_FORMAT_XML_MARC);
String regex = MoreObjects.firstNonNull(dic.getRegex(), DEFAULT_EXTRACT_ID_PATTERN);
configuration = dic;
idExtractor = new RegexpExtractor(regex);
}
}
try {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformer = transformerFactory.newTransformer();
} catch (TransformerConfigurationException tce) {
throw new RuntimeException(tce);
}
}
}
use of cz.mzk.recordmanager.server.model.DownloadImportConfiguration in project RecordManager2 by moravianlibrary.
the class ImportAntikvariatyTest method simpleTest.
@Test
public void simpleTest() throws Exception {
final Long confId = 500L;
DownloadImportConfiguration config = configDao.get(confId);
Assert.assertNotNull(config);
Assert.assertNotNull(config.getUrl());
reset(httpClient);
InputStream response0 = this.getClass().getResourceAsStream("/antikvariaty/antikvariaty-base.xml");
expect(httpClient.executeGet("http://local.antikvariaty.mzk/file.xml")).andReturn(response0);
replay(httpClient);
Job job = jobRegistry.getJob(Constants.JOB_ID_IMPORT_ANTIKVARIATY);
Map<String, JobParameter> params = new HashMap<String, JobParameter>();
params.put(Constants.JOB_PARAM_CONF_ID, new JobParameter(confId));
JobParameters jobParams = new JobParameters(params);
jobLauncher.run(job, jobParams);
AntikvariatyRecord toBeChangedRecord = antikDao.get(1L);
Assert.assertNotNull(toBeChangedRecord);
Assert.assertTrue(toBeChangedRecord.getCatalogueIds().size() == 1);
Assert.assertEquals(toBeChangedRecord.getCatalogueIds().get(0), "zb00026");
Assert.assertNotNull(toBeChangedRecord.getUpdated());
Assert.assertNotNull(toBeChangedRecord.getTitle());
Assert.assertNotNull(toBeChangedRecord.getUrl());
Assert.assertNotNull(toBeChangedRecord.getPublicationYear());
reset(httpClient);
response0 = this.getClass().getResourceAsStream("/antikvariaty/antikvariaty-update.xml");
expect(httpClient.executeGet("http://local.antikvariaty.mzk/file.xml")).andReturn(response0);
replay(httpClient);
job = jobRegistry.getJob(Constants.JOB_ID_IMPORT_ANTIKVARIATY);
params = new HashMap<String, JobParameter>();
params.put(Constants.JOB_PARAM_CONF_ID, new JobParameter(confId));
params.put(Constants.JOB_PARAM_REPEAT, new JobParameter(1L));
jobParams = new JobParameters(params);
jobLauncher.run(job, jobParams);
AntikvariatyRecord updatedRecord = antikDao.get(1L);
Assert.assertNotNull(updatedRecord);
Assert.assertTrue(updatedRecord.getCatalogueIds().size() == 1);
Assert.assertEquals(updatedRecord.getCatalogueIds().get(0), "xxxxxxxxxxxxxxx");
Assert.assertTrue(updatedRecord.getUpdated().compareTo(toBeChangedRecord.getUpdated()) > 0);
}
use of cz.mzk.recordmanager.server.model.DownloadImportConfiguration in project RecordManager2 by moravianlibrary.
the class ImportRecordsWriter method beforeStep.
@Override
public void beforeStep(StepExecution stepExecution) {
try (SessionBinder session = sync.register()) {
OAIHarvestConfiguration hc = oaiHarvestConfigurationDao.get(configurationId);
String regex = null;
if (hc != null) {
regex = hc.getRegex();
harvestConfiguration = hc;
} else {
DownloadImportConfiguration dic = downloadImportConfigurationDao.get(configurationId);
if (dic != null) {
regex = dic.getRegex();
harvestConfiguration = dic;
}
}
if (regex != null) {
regexpExtractor = new RegexpExtractor(regex);
}
}
}
Aggregations