Search in sources :

Example 1 with AntikvariatyRecord

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);
        }
    }
}
Also used : AntikvariatyRecord(cz.mzk.recordmanager.server.model.AntikvariatyRecord) Date(java.util.Date)

Example 2 with AntikvariatyRecord

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);
    }
}
Also used : Jaxb2Marshaller(org.springframework.oxm.jaxb.Jaxb2Marshaller) DownloadImportConfiguration(cz.mzk.recordmanager.server.model.DownloadImportConfiguration) AntikvariatyRecord(cz.mzk.recordmanager.server.model.AntikvariatyRecord) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 3 with AntikvariatyRecord

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;
}
Also used : AntikvariatyRecord(cz.mzk.recordmanager.server.model.AntikvariatyRecord)

Example 4 with AntikvariatyRecord

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();
}
Also used : AntikvariatyRecord(cz.mzk.recordmanager.server.model.AntikvariatyRecord) Date(java.util.Date)

Example 5 with AntikvariatyRecord

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;
}
Also used : AntikvariatyRecord(cz.mzk.recordmanager.server.model.AntikvariatyRecord)

Aggregations

AntikvariatyRecord (cz.mzk.recordmanager.server.model.AntikvariatyRecord)6 DownloadImportConfiguration (cz.mzk.recordmanager.server.model.DownloadImportConfiguration)2 Date (java.util.Date)2 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Job (org.springframework.batch.core.Job)1 JobParameter (org.springframework.batch.core.JobParameter)1 JobParameters (org.springframework.batch.core.JobParameters)1 InputStreamResource (org.springframework.core.io.InputStreamResource)1 Jaxb2Marshaller (org.springframework.oxm.jaxb.Jaxb2Marshaller)1 Test (org.testng.annotations.Test)1