Skip to content
This repository has been archived by the owner on Mar 26, 2019. It is now read-only.

Commit

Permalink
#298, TO BE CONTINUED
Browse files Browse the repository at this point in the history
  • Loading branch information
seustachi committed Nov 14, 2014
1 parent 14f0509 commit e8fe49e
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 4 deletions.
17 changes: 17 additions & 0 deletions HDX-System/resources/config_sample/log4j.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
<param name="ConversionPattern" value="%-5p %d{yy-MM-dd HH:mm:ss}: %m (%F:%L) [%t]%n" />
</layout>
</appender>

<appender name="hdx-ckan-updater-job" class="org.apache.log4j.RollingFileAppender">
<!-- <param name="file" value="D:\\HDX\\logs\\hdx.log" /> -->
<!-- <param name="file" value="${HDX_FOLDER}/logs/hdx.log" /> -->
<param name="file" value="/opt/ocha/hdx/logs/ckanUpdaterJob.log" />
<param name="MaxFileSize" value="500KB" />
<param name="MaxBackupIndex" value="20" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %d{yy-MM-dd HH:mm:ss}: %m (%F:%L) [%t]%n" />
</layout>
</appender>

<appender name="hdx-console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
Expand Down Expand Up @@ -71,6 +82,12 @@
<appender-ref ref="hdx-file-core" />
<appender-ref ref="hdx-console" />
</logger>

<logger name="ckan-updater-logger" additivity="false">
<level value="debug" />
<appender-ref ref="hdx-ckan-updater-job" />
<appender-ref ref="hdx-console" />
</logger>

<!-- =================================== === ROOT Logger settings =================================== -->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
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;
import org.springframework.scheduling.annotation.Scheduled;

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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -12,4 +14,26 @@ public interface DataSerieToCuratedDatasetDAO {
*/
public List<DataSerieToCuratedDataset> 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);

}
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -20,4 +23,28 @@ public List<DataSerieToCuratedDataset> getDatasetsWithUnsyncedMetadata() {
return query.getResultList();
}

@Override
@Transactional
public void updateLastMetadataTimestamp(final DataSerie dataSerie, final Date newTimestamp) {
final TypedQuery<DataSerieToCuratedDataset> 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<DataSerieToCuratedDataset> 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions HDX-System/src/main/resources/ctx-service.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
<bean id="apiV2BackendService" class="org.ocha.hdx.service.ApiV2BackendServiceImpl" />

<bean id="intermediaryBackendServiceImpl" class="org.ocha.hdx.service.IntermediaryBackendServiceImpl" />

<bean id="ckanSynchronizerService" class="org.ocha.hdx.service.CkanSynchronizerServiceImpl" />

<!-- Helpers -->
<bean id="readmeHelper" class="org.ocha.hdx.exporter.helper.ReadmeHelperImpl" />
Expand Down

0 comments on commit e8fe49e

Please sign in to comment.