use of cz.mzk.recordmanager.server.model.AntikvariatyRecord in project RecordManager2 by moravianlibrary.
the class AntikvariatyRecordsWriter method write.
@Override
public void write(List<? extends AntikvariatyRecord> items) throws Exception {
for (AntikvariatyRecord newRecord : items) {
Long recId = newRecord.getId();
if (recId == null) {
continue;
}
AntikvariatyRecord oldRecord = antikvariatyRecordDao.get(recId);
if (oldRecord == null) {
// persist new record
antikvariatyRecordDao.persist(newRecord);
continue;
}
Date newUpdated = newRecord.getUpdated() == null ? new Date(0L) : newRecord.getUpdated();
if (oldRecord.getUpdated() == null || newUpdated.compareTo(oldRecord.getUpdated()) > 0) {
// replace existing record
antikvariatyRecordDao.delete(oldRecord);
antikvariatyRecordDao.persist(newRecord);
}
}
}
use of cz.mzk.recordmanager.server.model.AntikvariatyRecord 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.AntikvariatyRecord in project RecordManager2 by moravianlibrary.
the class AntikvariatyRecordsReader method read.
@Override
public AntikvariatyRecord read() throws Exception {
if (reader == null) {
initializeReader();
}
AntikvariatyRecord item = reader.read();
if (item != null) {
fixCatalogueIds(item);
shortenTitle(item);
progressLogger.incrementAndLogProgress();
}
return item;
}
use of cz.mzk.recordmanager.server.model.AntikvariatyRecord in project RecordManager2 by moravianlibrary.
the class AntikvariatyRecordsWriter method write.
@Override
public void write(List<? extends AntikvariatyRecord> items) {
for (AntikvariatyRecord newRecord : items) {
Long recId = newRecord.getId();
if (recId == null) {
continue;
}
newRecord.setLastHarvest(new Date());
newRecord.setUpdated(new Date());
AntikvariatyRecord oldRecord = antikvariatyRecordDao.get(recId);
if (oldRecord == null) {
// persist new record
antikvariatyRecordDao.persist(newRecord);
continue;
}
if (!oldRecord.equals(newRecord)) {
// replace existing record
antikvariatyRecordDao.delete(oldRecord);
antikvariatyRecordDao.persist(newRecord);
} else {
oldRecord.setLastHarvest(new Date());
oldRecord.setUpdatedOriginal(newRecord.getUpdatedOriginal());
antikvariatyRecordDao.saveOrUpdate(oldRecord);
}
}
sessionFactory.getCurrentSession().flush();
sessionFactory.getCurrentSession().clear();
}
use of cz.mzk.recordmanager.server.model.AntikvariatyRecord in project RecordManager2 by moravianlibrary.
the class AntikvariatyRecordsReader method read.
@Override
public AntikvariatyRecord read() throws Exception {
if (reader == null) {
initializeReader();
}
AntikvariatyRecord item = reader.read();
if (item != null) {
fixCatalogueIds(item);
shortenTitle(item);
}
return item;
}
Aggregations