diff --git a/iceland/core/src/main/java/org/n52/iceland/cache/ctrl/AbstractSchedulingContentCacheController.java b/iceland/core/src/main/java/org/n52/iceland/cache/ctrl/AbstractSchedulingContentCacheController.java index f9c30ce9f..dfa289e5c 100644 --- a/iceland/core/src/main/java/org/n52/iceland/cache/ctrl/AbstractSchedulingContentCacheController.java +++ b/iceland/core/src/main/java/org/n52/iceland/cache/ctrl/AbstractSchedulingContentCacheController.java @@ -17,9 +17,12 @@ import java.text.ParseException; import java.util.Date; +import java.util.Optional; import java.util.Timer; import java.util.TimerTask; +import javax.inject.Inject; + import org.joda.time.DateTime; import org.n52.faroe.ConfigurationError; import org.n52.faroe.Validation; @@ -44,9 +47,11 @@ public abstract class AbstractSchedulingContentCacheController implements Conten private static final Logger LOGGER = LoggerFactory.getLogger(AbstractSchedulingContentCacheController.class); private boolean initialized; - private long updateInterval; + private long updateInterval = 120; private final Timer timer = new Timer("52n-iceland-capabilities-cache-controller", true); private TimerTask current; + private Optional staticCapabilitiesProvider; + /** * Starts a new timer task @@ -74,20 +79,20 @@ public void setCronExpression(String cronExpression) { Validation.notNullOrEmpty("Cron expression for cache update", cronExpression); try { DateTime now = DateTime.now(); - Date next = new CronExpression(cronExpression).getNextInvalidTimeAfter(DateTime.now().toDate()); - setUpdateInterval(DateTimeHelper.getMinutesSince(now, new DateTime(next))); + CronExpression cronExp = new CronExpression(cronExpression); + Date first = cronExp.getNextValidTimeAfter(now.toDate()); + Date next = cronExp.getNextValidTimeAfter(first); + setUpdateInterval(DateTimeHelper.getMinutesSince(new DateTime(first), new DateTime(next))); } catch (ParseException e) { + throw new ConfigurationError(String.format("The defined cron expression '%s' is invalid!", cronExpression), e); } - // for later usage! -// if (this.cronExpression == null) { -// this.cronExpression = cronExpression; -// reschedule(); -// } else if (!this.cronExpression.equalsIgnoreCase(cronExpression)) { -// this.cronExpression = cronExpression; -// reschedule(); -// } + } + + @Inject + public void setStaticCapabilitiesProvider(Optional staticCapabilitiesProvider) { + this.staticCapabilitiesProvider = staticCapabilitiesProvider; } public void setUpdateInterval(int interval) throws ConfigurationError { @@ -151,6 +156,9 @@ public void run() { update(); LOGGER.info("Timertask: capabilities cache update successful!"); schedule(); + if (staticCapabilitiesProvider.isPresent()) { + staticCapabilitiesProvider.get().create(); + } } catch (OwsExceptionReport e) { LOGGER.error("Fatal error: Timertask couldn't update capabilities cache! " + "Switch log level to DEBUG to get more details."); diff --git a/iceland/core/src/main/java/org/n52/iceland/cache/ctrl/StaticCapabilitiesProvider.java b/iceland/core/src/main/java/org/n52/iceland/cache/ctrl/StaticCapabilitiesProvider.java new file mode 100644 index 000000000..7bb27b636 --- /dev/null +++ b/iceland/core/src/main/java/org/n52/iceland/cache/ctrl/StaticCapabilitiesProvider.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2015-2022 52°North Spatial Information Research GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.n52.iceland.cache.ctrl; + +import org.n52.shetland.ogc.ows.service.GetCapabilitiesResponse; + +public interface StaticCapabilitiesProvider { + + String PROVIDE_STATIC_CAPABILITIES = "service.capabilities.provide.static"; + + default boolean isProvideStaticCapabilities() { + return false; + } + + void create(); + + String get(GetCapabilitiesResponse response); + + String get(String identifier); + +}