diff options
Diffstat (limited to 'moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/tsl')
-rw-r--r-- | moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/tsl/timer/TSLUpdaterTimerTask.java | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/tsl/timer/TSLUpdaterTimerTask.java b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/tsl/timer/TSLUpdaterTimerTask.java index 1a377b6..b5303fd 100644 --- a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/tsl/timer/TSLUpdaterTimerTask.java +++ b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/tsl/timer/TSLUpdaterTimerTask.java @@ -1,5 +1,6 @@ package at.gv.egovernment.moa.spss.tsl.timer;
+import java.util.Date;
import java.util.TimerTask;
import at.gv.egovernment.moa.sig.tsl.exception.TslException;
@@ -12,17 +13,63 @@ import at.gv.egovernment.moaspss.logging.Logger; public class TSLUpdaterTimerTask extends TimerTask {
+ private static final String COUNTRY_CODE_EU = "EU";
+
+ private Date configuratedTslUpdateDate;
+ private final long configuratedTslUpdateInterval;
+
+
+ /**
+ * Create a TSL Update Task for scheduler.
+ *
+ * @param start Date when TSL should forced to reloaded first time
+ * @param period TSL force reload interval
+ */
+ public TSLUpdaterTimerTask(Date start, long period) {
+ this.configuratedTslUpdateDate = start;
+ this.configuratedTslUpdateInterval = period;
+
+ }
+
@Override
public void run() {
+
+ Date now = new Date();
+
+ if (!ServiceStatusContainer.getStatus()) {
+ Logger.info("EU TSL is not loaded. Starting TSL reload process ... ");
+ performTslUpdate();
+
+ } else if (this.configuratedTslUpdateDate.before(now)) {
+ performTslUpdate();
+ this.configuratedTslUpdateDate = new Date(now.getTime() + this.configuratedTslUpdateInterval);
+
+ } else {
+ Logger.trace("EU TSL is loaded and next TSL force update is at: " + this.configuratedTslUpdateDate);
+
+ }
+
+ }
+ private void performTslUpdate() {
try {
Logger.info("Start TSL Update");
TSLServiceFactory.getTSLServiceClient().updateTSLInformation();
Logger.info("Finished TSL Update");
+ boolean isEuTslLoaded = TSLServiceFactory.getTSLServiceClient().getCurrentTSLClientStatus().stream()
+ .filter(el -> COUNTRY_CODE_EU.equalsIgnoreCase(el.getCountryCode()))
+ .findFirst()
+ .map(el -> el.isProcessed() && el.isVerified())
+ .orElse(false);
+
+ Logger.debug("Current EU-TSL status is: "
+ + (isEuTslLoaded ? ServiceStatusContainer.STATUS_OK : ServiceStatusContainer.STATUS_ERROR_EUTSL));
+
// set global TSL client status
- ServiceStatusContainer.setStatus(true);
- ServiceStatusContainer.setStatusMsg(ServiceStatusContainer.STATUS_OK);
+ ServiceStatusContainer.setStatus(isEuTslLoaded);
+ ServiceStatusContainer.setStatusMsg(
+ isEuTslLoaded ? ServiceStatusContainer.STATUS_OK : ServiceStatusContainer.STATUS_ERROR_EUTSL);
} catch (final TslUpdateException e) {
final MessageProvider msg = MessageProvider.getInstance();
@@ -42,8 +89,7 @@ public class TSLUpdaterTimerTask extends TimerTask { ServiceStatusContainer.setStatusMsg(
new LogMsg(msg.getMessage("tsl.00", null)).toString());
- }
-
+ }
}
-
+
}
|