From e8fe49e2c2b0b327623cd899259a5922591aec05 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 14 Nov 2014 13:57:31 +0100 Subject: [PATCH] #298, TO BE CONTINUED --- HDX-System/resources/config_sample/log4j.xml | 17 ++++++++++++ .../org/ocha/hdx/jobs/MetadataUpdater.java | 8 +++--- .../ckan/DataSerieToCuratedDatasetDAO.java | 24 +++++++++++++++++ .../DataSerieToCuratedDatasetDAOImpl.java | 27 +++++++++++++++++++ .../service/CkanSynchronizerServiceImpl.java | 4 +++ HDX-System/src/main/resources/ctx-service.xml | 2 ++ 6 files changed, 78 insertions(+), 4 deletions(-) diff --git a/HDX-System/resources/config_sample/log4j.xml b/HDX-System/resources/config_sample/log4j.xml index 47e9cd9c..e7bbb17b 100644 --- a/HDX-System/resources/config_sample/log4j.xml +++ b/HDX-System/resources/config_sample/log4j.xml @@ -15,6 +15,17 @@ + + + + + + + + + + + @@ -71,6 +82,12 @@ + + + + + + diff --git a/HDX-System/src/main/java/org/ocha/hdx/jobs/MetadataUpdater.java b/HDX-System/src/main/java/org/ocha/hdx/jobs/MetadataUpdater.java index fdeb5bcf..cbd047ec 100644 --- a/HDX-System/src/main/java/org/ocha/hdx/jobs/MetadataUpdater.java +++ b/HDX-System/src/main/java/org/ocha/hdx/jobs/MetadataUpdater.java @@ -1,6 +1,6 @@ package org.ocha.hdx.jobs; -import org.ocha.hdx.service.HDXService; +import org.ocha.hdx.service.CkanSynchronizerService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -8,16 +8,16 @@ public class MetadataUpdater implements Runnable { - private static final Logger log = LoggerFactory.getLogger(MetadataUpdater.class); + private static final Logger log = LoggerFactory.getLogger("ckan-updater-logger"); @Autowired - private HDXService hdxService; + private CkanSynchronizerService ckanSynchronizerServiceImpl; @Override @Scheduled(fixedDelay = 100000, initialDelay = 100000) public void run() { try { - // ... + ckanSynchronizerServiceImpl.updateMetadataToCkan(); } catch (final Throwable e) { log.error(e.toString(), e); diff --git a/HDX-System/src/main/java/org/ocha/hdx/persistence/dao/ckan/DataSerieToCuratedDatasetDAO.java b/HDX-System/src/main/java/org/ocha/hdx/persistence/dao/ckan/DataSerieToCuratedDatasetDAO.java index d35dacb4..1d2e235c 100644 --- a/HDX-System/src/main/java/org/ocha/hdx/persistence/dao/ckan/DataSerieToCuratedDatasetDAO.java +++ b/HDX-System/src/main/java/org/ocha/hdx/persistence/dao/ckan/DataSerieToCuratedDatasetDAO.java @@ -1,7 +1,9 @@ package org.ocha.hdx.persistence.dao.ckan; +import java.util.Date; import java.util.List; +import org.ocha.hdx.model.DataSerie; import org.ocha.hdx.persistence.entity.ckan.DataSerieToCuratedDataset; public interface DataSerieToCuratedDatasetDAO { @@ -12,4 +14,26 @@ public interface DataSerieToCuratedDatasetDAO { */ public List getDatasetsWithUnsyncedMetadata(); + /** + * updates the lastMetadataUpdate field for the DataSerieToCuratedDataset found with DataSerie + * + * @param dataSerie + * to find the unique corresponding DataSerieToCuratedDataset + * @param newTimestamp + * the new lastMetadataUpdate ts + * @return + */ + public void updateLastMetadataTimestamp(final DataSerie dataSerie, final Date newTimestamp); + + /** + * updates the lastDataUpdate field for the DataSerieToCuratedDataset found with DataSerie + * + * @param dataSerie + * to find the unique corresponding DataSerieToCuratedDataset + * @param newTimestamp + * the new lastDataUpdate ts + * @return + */ + public void updateLastDataTimestamp(final DataSerie dataSerie, final Date newTimestamp); + } diff --git a/HDX-System/src/main/java/org/ocha/hdx/persistence/dao/ckan/DataSerieToCuratedDatasetDAOImpl.java b/HDX-System/src/main/java/org/ocha/hdx/persistence/dao/ckan/DataSerieToCuratedDatasetDAOImpl.java index 6e195f2a..c5c1d2df 100644 --- a/HDX-System/src/main/java/org/ocha/hdx/persistence/dao/ckan/DataSerieToCuratedDatasetDAOImpl.java +++ b/HDX-System/src/main/java/org/ocha/hdx/persistence/dao/ckan/DataSerieToCuratedDatasetDAOImpl.java @@ -1,12 +1,15 @@ package org.ocha.hdx.persistence.dao.ckan; +import java.util.Date; import java.util.List; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.TypedQuery; +import org.ocha.hdx.model.DataSerie; import org.ocha.hdx.persistence.entity.ckan.DataSerieToCuratedDataset; +import org.springframework.transaction.annotation.Transactional; public class DataSerieToCuratedDatasetDAOImpl implements DataSerieToCuratedDatasetDAO { @@ -20,4 +23,28 @@ public List getDatasetsWithUnsyncedMetadata() { return query.getResultList(); } + @Override + @Transactional + public void updateLastMetadataTimestamp(final DataSerie dataSerie, final Date newTimestamp) { + final TypedQuery query = em.createQuery( + "SELECT dstcd FROM DataSerieToCuratedDataset dstcd WHERE dstcd.source.code = :sourceCode And dstcd.indicatorType.code = :indicatorTypeCode", DataSerieToCuratedDataset.class); + query.setParameter("sourceCode", dataSerie.getSourceCode()); + query.setParameter("indicatorTypeCode", dataSerie.getIndicatorCode()); + + final DataSerieToCuratedDataset singleResult = query.getSingleResult(); + singleResult.setLastMetadataUpdate(newTimestamp); + } + + @Override + @Transactional + public void updateLastDataTimestamp(final DataSerie dataSerie, final Date newTimestamp) { + final TypedQuery query = em.createQuery( + "SELECT dstcd FROM DataSerieToCuratedDataset dstcd WHERE dstcd.source.code = :sourceCode And dstcd.indicatorType.code = :indicatorTypeCode", DataSerieToCuratedDataset.class); + query.setParameter("sourceCode", dataSerie.getSourceCode()); + query.setParameter("indicatorTypeCode", dataSerie.getIndicatorCode()); + + final DataSerieToCuratedDataset singleResult = query.getSingleResult(); + singleResult.setLastDataUpdate(newTimestamp); + } + } diff --git a/HDX-System/src/main/java/org/ocha/hdx/service/CkanSynchronizerServiceImpl.java b/HDX-System/src/main/java/org/ocha/hdx/service/CkanSynchronizerServiceImpl.java index 9cab2dec..82df9ca9 100644 --- a/HDX-System/src/main/java/org/ocha/hdx/service/CkanSynchronizerServiceImpl.java +++ b/HDX-System/src/main/java/org/ocha/hdx/service/CkanSynchronizerServiceImpl.java @@ -4,10 +4,14 @@ import org.ocha.hdx.persistence.dao.ckan.DataSerieToCuratedDatasetDAO; import org.ocha.hdx.persistence.entity.ckan.DataSerieToCuratedDataset; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; public class CkanSynchronizerServiceImpl extends CkanClient implements CkanSynchronizerService { + private static final Logger log = LoggerFactory.getLogger("ckan-updater-logger"); + @Autowired private DataSerieToCuratedDatasetDAO dataSerieToCuratedDatasetDAO; diff --git a/HDX-System/src/main/resources/ctx-service.xml b/HDX-System/src/main/resources/ctx-service.xml index 90ec5b6a..4f40f673 100644 --- a/HDX-System/src/main/resources/ctx-service.xml +++ b/HDX-System/src/main/resources/ctx-service.xml @@ -76,6 +76,8 @@ + +