From 916196281335fd93ddc5671b0a2a99a2900a7cfc Mon Sep 17 00:00:00 2001 From: Dave Hladky Date: Wed, 30 Oct 2013 13:56:39 -0500 Subject: [PATCH] Issue #2448 Fixed retrievals before activePeriod begins and after activePeriod expires. Change-Id: I75269bad24731990720d30683ebf5f27344661f3 Former-commit-id: 060e719f27c20f24bae9a5603cc51d90434b8fa4 --- .../registry/RecurringSubscription.java | 14 ++- .../uf/common/time/util/TimeUtil.java | 45 ++++++++++ .../bandwidth/BandwidthManager.java | 5 +- .../bandwidth/EdexBandwidthManager.java | 2 +- .../bandwidth/dao/BandwidthAllocation.java | 13 +-- .../bandwidth/dao/BandwidthDataSetUpdate.java | 10 +-- .../bandwidth/dao/BandwidthSubscription.java | 8 +- .../retrieval/BandwidthReservation.java | 6 +- .../bandwidth/retrieval/RetrievalPlan.java | 17 ++-- .../bandwidth/util/BandwidthDaoUtil.java | 88 +++++++++++-------- .../bandwidth/util/BandwidthUtil.java | 50 +++++------ .../retrieval/wfs/WfsRequestBuilder.java | 6 +- .../retrieval/wfs/WfsRetrievalGenerator.java | 17 +++- .../bandwidth/AbstractBandwidthDaoTest.java | 13 +-- 14 files changed, 186 insertions(+), 108 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/RecurringSubscription.java b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/RecurringSubscription.java index fe0b2b1286..806b1ada4c 100644 --- a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/RecurringSubscription.java +++ b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/RecurringSubscription.java @@ -61,6 +61,7 @@ import com.raytheon.uf.common.time.util.TimeUtil; * May 21, 2013 2020 mpduff Rename UserSubscription to SiteSubscription. * Sept 30,2013 1797 dhladky Generics * Oct 23, 2013 2484 dhladky Unique ID for subscriptions updated. + * Oct 30, 2013 2448 dhladky Fixed pulling data before and after activePeriod starting and ending. * * * @@ -868,18 +869,23 @@ public abstract class RecurringSubscription if (activePeriodStart == null && activePeriodEnd == null) { return true; } else if (activePeriodStart != null && activePeriodEnd != null) { + Calendar startCal = TimeUtil.newGmtCalendar(); startCal.setTime(activePeriodStart); startCal = TimeUtil.minCalendarFields(startCal, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND, Calendar.MILLISECOND); + // add the current year for true comparison + startCal = TimeUtil.addCurrentYearCalendar(startCal); + activePeriodStart = startCal.getTime(); Calendar endCal = TimeUtil.newGmtCalendar(); endCal.setTime(activePeriodEnd); endCal = TimeUtil.maxCalendarFields(endCal, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND, Calendar.MILLISECOND); - + // add the current year for true comparison + endCal = TimeUtil.addCurrentYearCalendar(endCal); // If the period crosses a year boundary, add a year to the end if (endCal.before(startCal)) { endCal.add(Calendar.YEAR, 1); @@ -887,12 +893,14 @@ public abstract class RecurringSubscription activePeriodEnd = endCal.getTime(); - // Only concerned with month and day, need to set the years equal + // Only concerned with month and day, need to set the + // years on equal footing for comparison sake. Calendar c = TimeUtil.newGmtCalendar(); c.setTime(checkDate); + // set the date to compare with the current date from the start c.set(Calendar.YEAR, startCal.get(Calendar.YEAR)); Date date = c.getTime(); - + return (activePeriodStart.before(date) && activePeriodEnd .after(date)); } diff --git a/edexOsgi/com.raytheon.uf.common.time/src/com/raytheon/uf/common/time/util/TimeUtil.java b/edexOsgi/com.raytheon.uf.common.time/src/com/raytheon/uf/common/time/util/TimeUtil.java index 8b5eb52eca..34355bbd41 100644 --- a/edexOsgi/com.raytheon.uf.common.time/src/com/raytheon/uf/common/time/util/TimeUtil.java +++ b/edexOsgi/com.raytheon.uf.common.time/src/com/raytheon/uf/common/time/util/TimeUtil.java @@ -52,6 +52,7 @@ import com.raytheon.uf.common.time.domain.api.ITimePoint; * Mar 20, 2013 1774 randerso Add SECONDS_PER_DAY, changed SECONDS_PER_HOUR to int. * Apr 24, 2013 1628 mschenke Added GMT TimeZone Object constant * Jun 05, 2013 DR 16279 D. Friedman Add timeOfDayToAbsoluteTime + * Oct 30, 2013 2448 dhladky Added current year addition to calendar object. * * * @author njensen @@ -458,4 +459,48 @@ public final class TimeUtil { */ private TimeUtil() { } + + /** + * New Calendar from a Date + * @param date + * @return + */ + public static Calendar newCalendar(final Date date) { + Calendar t = null; + if (date != null) { + t = TimeUtil.newCalendar(); + t.setTime(date); + } + return t; + } + + /** + * New Calendar from an existing calendar + * @param calendar + * @return + */ + public static Calendar newCalendar(final Calendar calendar) { + Calendar t = null; + if (calendar != null) { + t = TimeUtil.newCalendar(); + t.setTimeInMillis(calendar.getTimeInMillis()); + } + return t; + } + + /** + * Adds the current year to the calendar object that does not already have it set. + * Some calendar objects are only concerned with the day and month. When a + * comparison of years is necessary, you must add the current year to that calendar object. + * @param calendar + * @return + */ + public static Calendar addCurrentYearCalendar(final Calendar calendar) { + + Calendar yearTime = TimeUtil.newGmtCalendar(); + calendar.set(Calendar.YEAR, yearTime.get(Calendar.YEAR)); + + return calendar; + } + } diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java index 7ae9e3be38..37cafa8fa2 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java @@ -123,6 +123,7 @@ import com.raytheon.uf.edex.registry.ebxml.exception.EbxmlRegistryException; * adhoc subscription. * Sept 25, 2013 1797 dhladky separated time from gridded time * 10/23/2013 2385 bphillip Change schedule method to scheduleAdhoc + * Oct 30, 2013 2448 dhladky Moved methods to TimeUtil. * * * @author dhladky @@ -307,7 +308,7 @@ public abstract class BandwidthManager .getBandwidthSubscription(); Calendar retrievalTime = bandwidthSubscription .getBaseReferenceTime(); - Calendar startTime = BandwidthUtil.copy(retrievalTime); + Calendar startTime = TimeUtil.newCalendar(retrievalTime); int delayMinutes = retrieval.getDataSetAvailablityDelay(); int maxLatency = retrieval.getSubscriptionLatency(); @@ -472,7 +473,7 @@ public abstract class BandwidthManager for (SubscriptionRetrieval retrieval : retrievals) { retrieval.setStartTime(now); - Calendar endTime = BandwidthUtil.copy(now); + Calendar endTime = TimeUtil.newCalendar(now); endTime.add(Calendar.MINUTE, retrieval.getSubscriptionLatency()); retrieval.setEndTime(endTime); // Store the SubscriptionRetrieval - retrievalManager expects diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/EdexBandwidthManager.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/EdexBandwidthManager.java index b953de7833..767ed19da0 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/EdexBandwidthManager.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/EdexBandwidthManager.java @@ -262,7 +262,7 @@ public abstract class EdexBandwidthManager return; } - Calendar next = BandwidthUtil.copy(dao.getBaseReferenceTime()); + Calendar next = TimeUtil.newCalendar(dao.getBaseReferenceTime()); // See how far into the future the plan goes.. int days = retrievalManager.getPlan(dao.getRoute()).getPlanDays(); diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthAllocation.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthAllocation.java index ad32d09262..b10ba0b8d0 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthAllocation.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthAllocation.java @@ -21,9 +21,9 @@ import javax.persistence.Table; import com.raytheon.uf.common.datadelivery.registry.Network; import com.raytheon.uf.common.datadelivery.registry.Subscription.SubscriptionPriority; import com.raytheon.uf.common.dataplugin.persist.IPersistableDataObject; -import com.raytheon.uf.common.serialization.ISerializableObject; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; +import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.common.util.IDeepCopyable; import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalStatus; import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; @@ -41,6 +41,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; * Oct 12, 2012 0726 djohnson Add SW history, use string version of enum. * Jun 24, 2013 2106 djohnson Add copy constructor. * Jul 11, 2013 2106 djohnson Use SubscriptionPriority enum. + * Oct 30, 2013 2448 dhladky Moved methods to TimeUtil. * * * @@ -55,7 +56,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; @DynamicSerialize @SequenceGenerator(name = "BANDWIDTH_SEQ", sequenceName = "bandwidth_seq", allocationSize = 1, initialValue = 1) public class BandwidthAllocation implements IPersistableDataObject, - ISerializableObject, Serializable, IDeepCopyable { + Serializable, IDeepCopyable { private static final long serialVersionUID = 743702044231376839L; @@ -130,19 +131,19 @@ public class BandwidthAllocation implements IPersistableDataObject, public BandwidthAllocation(BandwidthAllocation from) { final Calendar fromActualEnd = from.getActualEnd(); if (fromActualEnd != null) { - this.setActualEnd(BandwidthUtil.copy(fromActualEnd)); + this.setActualEnd(TimeUtil.newCalendar(fromActualEnd)); } final Calendar fromActualStart = from.getActualStart(); if (fromActualStart != null) { - this.setActualStart(BandwidthUtil.copy(fromActualStart)); + this.setActualStart(TimeUtil.newCalendar(fromActualStart)); } final Calendar fromStartTime = from.getStartTime(); if (fromStartTime != null) { - this.setStartTime(BandwidthUtil.copy(fromStartTime)); + this.setStartTime(TimeUtil.newCalendar(fromStartTime)); } final Calendar fromEndTime = from.getEndTime(); if (fromEndTime != null) { - this.setEndTime(BandwidthUtil.copy(fromEndTime)); + this.setEndTime(TimeUtil.newCalendar(fromEndTime)); } this.setAgentType(from.getAgentType()); diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthDataSetUpdate.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthDataSetUpdate.java index e17babe191..7f246f6929 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthDataSetUpdate.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthDataSetUpdate.java @@ -15,9 +15,9 @@ import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; import com.raytheon.uf.common.dataplugin.persist.IPersistableDataObject; -import com.raytheon.uf.common.serialization.ISerializableObject; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; +import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.common.util.IDeepCopyable; import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; @@ -33,6 +33,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; * ------------ ---------- ----------- -------------------------- * Oct 19, 2012 0726 djohnson Added SW history. * Jun 24, 2013 2106 djohnson Add copy constructor. + * Oct 30, 2013 2448 dhladky Moved methods to TimeUtil. * * * @@ -45,7 +46,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; @SequenceGenerator(name = "BANDWIDTH_SEQ", sequenceName = "bandwidth_datasetupdate_seq", allocationSize = 1) @DynamicSerialize public class BandwidthDataSetUpdate implements IPersistableDataObject, - Serializable, ISerializableObject, IDeepCopyable { + Serializable, IDeepCopyable { private static final long serialVersionUID = 20120723L; @@ -92,13 +93,12 @@ public class BandwidthDataSetUpdate implements IPersistableDataObject, * the instance to copy */ public BandwidthDataSetUpdate(BandwidthDataSetUpdate bandwidthDataSetUpdate) { - this.dataSetBaseTime = BandwidthUtil - .copy(bandwidthDataSetUpdate.dataSetBaseTime); + this.dataSetBaseTime = TimeUtil.newCalendar(bandwidthDataSetUpdate.dataSetBaseTime); this.dataSetName = bandwidthDataSetUpdate.dataSetName; this.dataSetType = bandwidthDataSetUpdate.dataSetType; this.id = bandwidthDataSetUpdate.id; this.providerName = bandwidthDataSetUpdate.providerName; - this.updateTime = BandwidthUtil.copy(bandwidthDataSetUpdate.updateTime); + this.updateTime = TimeUtil.newCalendar(bandwidthDataSetUpdate.updateTime); this.url = bandwidthDataSetUpdate.url; } diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthSubscription.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthSubscription.java index fcb84e9860..b6bde27d57 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthSubscription.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthSubscription.java @@ -16,9 +16,9 @@ import javax.persistence.Table; import com.raytheon.uf.common.datadelivery.registry.Network; import com.raytheon.uf.common.datadelivery.registry.Subscription.SubscriptionPriority; import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject; -import com.raytheon.uf.common.serialization.ISerializableObject; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; +import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.common.util.IDeepCopyable; import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; @@ -37,6 +37,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; * Jun 13, 2013 2095 djohnson Add flag for whether or not data set update should be looked for on aggregating. * Jun 24, 2013 2106 djohnson Add copy constructor. * Jul 11, 2013 2106 djohnson Use SubscriptionPriority enum, remove the Subscription. + * Oct 30, 2013 2448 dhladky Moved methods to TimeUtil. * * * @@ -48,8 +49,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; @DynamicSerialize @SequenceGenerator(name = "BANDWIDTH_SEQ", sequenceName = "bandwidth_seq", allocationSize = 1, initialValue = 1) public class BandwidthSubscription extends PersistableDataObject - implements Serializable, ISerializableObject, - IDeepCopyable { + implements Serializable, IDeepCopyable { private static final long serialVersionUID = 20120723L; @@ -117,7 +117,7 @@ public class BandwidthSubscription extends PersistableDataObject * @param bandwidthSubscription */ public BandwidthSubscription(BandwidthSubscription bandwidthSubscription) { - this.baseReferenceTime = BandwidthUtil.copy(bandwidthSubscription + this.baseReferenceTime = TimeUtil.newCalendar(bandwidthSubscription .getBaseReferenceTime()); this.checkForDataSetUpdate = bandwidthSubscription.checkForDataSetUpdate; this.cycle = bandwidthSubscription.cycle; diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/BandwidthReservation.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/BandwidthReservation.java index 89709ab864..d9e2ea0781 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/BandwidthReservation.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/BandwidthReservation.java @@ -5,6 +5,7 @@ import java.util.Calendar; import com.raytheon.uf.common.datadelivery.registry.Network; import com.raytheon.uf.common.datadelivery.registry.Subscription.SubscriptionPriority; +import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.common.util.IDeepCopyable; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation; import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; @@ -22,6 +23,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; * Nov 09, 2012 1286 djohnson Add getters for bytes. * Jun 24, 2013 2106 djohnson Add copy constructor. * Jul 11, 2013 2106 djohnson Use SubscriptionPriority enum. + * Oct 30, 2013 2448 dhladky Moved methods to TimeUtil. * * * @@ -85,12 +87,12 @@ public class BandwidthReservation implements Serializable, */ public BandwidthReservation(BandwidthReservation from) { this.bandwidthBucket = from.bandwidthBucket; - this.endTime = BandwidthUtil.copy(from.endTime); + this.endTime = TimeUtil.newCalendar(from.endTime); this.id = from.id; this.network = from.network; this.priority = from.priority; this.size = from.size; - this.startTime = BandwidthUtil.copy(from.startTime); + this.startTime = TimeUtil.newCalendar(from.startTime); } @Override diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/RetrievalPlan.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/RetrievalPlan.java index 3e0bc83dc7..4c7befba90 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/RetrievalPlan.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/RetrievalPlan.java @@ -39,6 +39,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; * Oct 23, 2012 1286 djohnson Add ability to get/set the default bandwidth. * Nov 20, 2012 1286 djohnson Handle null bucketIds being returned. * Jun 25, 2013 2106 djohnson Separate state into other classes, promote BandwidthBucket to a class proper. + * Oct 30, 2013 2448 dhladky Moved methods to TimeUtil. * * * @@ -52,7 +53,7 @@ public class RetrievalPlan { private static final IUFStatusHandler statusHandler = UFStatus .getHandler(RetrievalPlan.class); - private IBandwidthDao bandwidthDao; + private IBandwidthDao bandwidthDao; // which retrieval plan private Network network; @@ -110,7 +111,7 @@ public class RetrievalPlan { if (found) { Calendar currentBucket = BandwidthUtil.now(); planStart = BandwidthUtil.now(); - planEnd = BandwidthUtil.copy(planStart); + planEnd = TimeUtil.newCalendar(planStart); planEnd.add(Calendar.DAY_OF_YEAR, planDays); // Make the buckets... @@ -183,7 +184,7 @@ public class RetrievalPlan { // The end of the plan should always be planDays from // now... Calendar currentBucket = BandwidthUtil.now(); - Calendar newEndOfPlan = BandwidthUtil.copy(currentBucket); + Calendar newEndOfPlan = TimeUtil.newCalendar(currentBucket); newEndOfPlan.add(Calendar.DAY_OF_YEAR, planDays); resize(currentBucket, newEndOfPlan); @@ -299,7 +300,7 @@ public class RetrievalPlan { this.map = map; } - public void setBandwidthDao(IBandwidthDao bandwidthDao) { + public void setBandwidthDao(IBandwidthDao bandwidthDao) { this.bandwidthDao = bandwidthDao; } @@ -411,13 +412,13 @@ public class RetrievalPlan { public Calendar getPlanEnd() { // Don't want an inadvertent change to plan end, so make a copy of the // Calendar Object and return that. - return BandwidthUtil.copy(planEnd); + return TimeUtil.newCalendar(planEnd); } public Calendar getPlanStart() { // Don't want an inadvertent change to plan start, so make a copy of the // Calendar Object and return that. - return BandwidthUtil.copy(planStart); + return TimeUtil.newCalendar(planStart); } /** @@ -577,8 +578,8 @@ public class RetrievalPlan { this.bucketMinutes = fromPlan.bucketMinutes; this.bytesPerBucket = fromPlan.bytesPerBucket; this.planDays = fromPlan.planDays; - this.planEnd = BandwidthUtil.copy(fromPlan.planEnd); - this.planStart = BandwidthUtil.copy(fromPlan.planStart); + this.planEnd = TimeUtil.newCalendar(fromPlan.planEnd); + this.planStart = TimeUtil.newCalendar(fromPlan.planStart); this.requestMap.clear(); this.requestMap.putAll(fromPlan.requestMap); this.associator.copyState(fromPlan.associator); diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/util/BandwidthDaoUtil.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/util/BandwidthDaoUtil.java index 77e140b0a4..6a4c722543 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/util/BandwidthDaoUtil.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/util/BandwidthDaoUtil.java @@ -69,6 +69,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalStatus; * no metadata found. * Sept 24, 2013 1797 dhladky separated time from GriddedTime * Oct 10, 2013 1797 bgonzale Refactored registry Time objects. + * Oct 30, 2013 2448 dhladky Fixed pulling data before and after activePeriod starting and ending. * * * @@ -161,92 +162,101 @@ public class BandwidthDaoUtil { Calendar planEnd = plan.getPlanEnd(); Calendar planStart = plan.getPlanStart(); + Calendar activePeriodStart = null; + Calendar activePeriodEnd = null; // Make sure the RetrievalPlan's start and end times intersect // the Subscription's active period. - Date activePeriodEnd = subscription.getActivePeriodEnd(); - - if (activePeriodEnd != null) { - Date activePeriodStart = subscription.getActivePeriodStart(); - Calendar active = BandwidthUtil.copy(activePeriodStart); - + if (subscription.getActivePeriodEnd() != null + && subscription.getActivePeriodStart() != null) { + + activePeriodStart = TimeUtil.newCalendar(subscription + .getActivePeriodStart()); // Substitute the active periods month and day for the // plan start month and day. - Calendar s = BandwidthUtil.copy(planStart); - s.set(Calendar.MONTH, active.get(Calendar.MONTH)); - s.set(Calendar.DAY_OF_MONTH, active.get(Calendar.DAY_OF_MONTH)); - - // If the active period start in outside the plan bounds, + Calendar start = BandwidthUtil.planToPeriodCompareCalendar(planStart, activePeriodStart); + // If the active period start is outside the plan bounds, // there is no intersection - just return an empty set. - if (s.before(planStart) && s.after(planEnd)) { + if (start.after(planEnd)) { return subscriptionTimes; } // Do the same for active plan end.. - activePeriodStart = subscription.getActivePeriodEnd(); - active = BandwidthUtil.copy(activePeriodStart); - + activePeriodEnd = TimeUtil.newCalendar(subscription.getActivePeriodEnd()); // Substitute the active periods month and day for the // plan ends month and day. - s = BandwidthUtil.copy(planStart); - s.set(Calendar.MONTH, active.get(Calendar.MONTH)); - s.set(Calendar.DAY_OF_MONTH, active.get(Calendar.DAY_OF_MONTH)); - + Calendar end = BandwidthUtil.planToPeriodCompareCalendar(planStart, activePeriodEnd); // If the active period end is before the start of the plan, // there is no intersection - just return an empty set. - if (s.before(planStart)) { + if (end.before(planStart)) { return subscriptionTimes; } } // Now check the Subscription start and end times for intersection // with the RetrievalPlan... - // Figure out the 'active' period for a subscription.. - - Calendar subscriptionEndDate = BandwidthUtil.copy(subscription + Calendar subscriptionEnd = TimeUtil.newCalendar(subscription .getSubscriptionEnd()); - Calendar subscriptionStartDate = null; + Calendar subscriptionStart = null; // Check to see if this is a non-expiring subscription - if (subscriptionEndDate == null) { + if (subscriptionEnd == null) { // If there is no subscription start end dates then the largest // window that can be scheduled is the RetrievalPlan size.. - subscriptionEndDate = BandwidthUtil.copy(planEnd); - subscriptionStartDate = BandwidthUtil.copy(planStart); + subscriptionEnd = TimeUtil.newCalendar(planEnd); + subscriptionStart = TimeUtil.newCalendar(planStart); } else { // If there is a start and end time, then modify the start and // end times to 'fit' within the RetrievalPlan times - subscriptionStartDate = BandwidthUtil.copy(BandwidthUtil.max( + subscriptionStart = TimeUtil.newCalendar(BandwidthUtil.max( subscription.getSubscriptionStart(), planStart)); - subscriptionEndDate = BandwidthUtil.copy(BandwidthUtil.min( + subscriptionEnd = TimeUtil.newCalendar(BandwidthUtil.min( subscription.getSubscriptionEnd(), planEnd)); } // Create a Set of Calendars for all the baseReferenceTimes that a // Subscription can contain... - TimeUtil.minCalendarFields(subscriptionStartDate, Calendar.MILLISECOND, + TimeUtil.minCalendarFields(subscriptionStart, Calendar.MILLISECOND, Calendar.SECOND, Calendar.MINUTE, Calendar.HOUR_OF_DAY); + TimeUtil.maxCalendarFields(subscriptionEnd, Calendar.MILLISECOND, + Calendar.SECOND, Calendar.MINUTE, Calendar.HOUR_OF_DAY); + + // setup active period checks if necessary + if (activePeriodStart != null && activePeriodEnd != null) { + // need to add the current year in order to make the checks relevant + activePeriodStart = TimeUtil.addCurrentYearCalendar(activePeriodStart); + activePeriodEnd = TimeUtil.addCurrentYearCalendar(activePeriodEnd); + } - outerloop: while (!subscriptionStartDate.after(subscriptionEndDate)) { + outerloop: while (!subscriptionStart.after(subscriptionEnd)) { for (Integer cycle : hours) { - subscriptionStartDate.set(Calendar.HOUR_OF_DAY, cycle); + subscriptionStart.set(Calendar.HOUR_OF_DAY, cycle); for (Integer minute : minutes) { - subscriptionStartDate.set(Calendar.MINUTE, minute); - if (subscriptionStartDate.after(subscriptionEndDate)) { + subscriptionStart.set(Calendar.MINUTE, minute); + if (subscriptionStart.after(subscriptionEnd)) { break outerloop; - } else { + } + else { Calendar time = TimeUtil.newCalendar(); - time.setTimeInMillis(subscriptionStartDate + time.setTimeInMillis(subscriptionStart .getTimeInMillis()); + // Last check for time window, this checks fine grain by hour and minute + if (activePeriodStart != null && activePeriodEnd != null) { + if (time.after(activePeriodEnd) || time.before(activePeriodStart)) { + // discard this retrieval time, outside activePeriod window + continue; + } + } + subscriptionTimes.add(time); } } } // Start the next day.. - subscriptionStartDate.add(Calendar.DAY_OF_YEAR, 1); - subscriptionStartDate.set(Calendar.HOUR_OF_DAY, hours.first()); + subscriptionStart.add(Calendar.DAY_OF_YEAR, 1); + subscriptionStart.set(Calendar.HOUR_OF_DAY, hours.first()); } // Now walk the subscription times and throw away anything outside the @@ -257,7 +267,7 @@ public class BandwidthDaoUtil { while (itr.hasNext()) { Calendar time = itr.next(); - Calendar withAvailabilityDelay = BandwidthUtil.copy(time); + Calendar withAvailabilityDelay = TimeUtil.newCalendar(time); withAvailabilityDelay.add(Calendar.MINUTE, availabilityDelay); // We allow base reference times that are still possible to retrieve diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/util/BandwidthUtil.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/util/BandwidthUtil.java index 3fe7b9213f..26bf352156 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/util/BandwidthUtil.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/util/BandwidthUtil.java @@ -28,6 +28,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthSubscription; * Jun 13, 2013 2095 djohnson Point subscriptions don't check for dataset updates on aggregation. * Jun 25, 2013 2106 djohnson CheapClone was cheap in ease, not performance. * Jul 11, 2013 2106 djohnson Use SubscriptionPriority enum. + * Oct 30, 2013 2448 dhladky Moved methods to TimeUtil. * * * @@ -59,18 +60,18 @@ public class BandwidthUtil { private BandwidthUtil() { }; - public static int getSubscriptionLatency(Subscription subscription) { + public static int getSubscriptionLatency(Subscription subscription) { return instance.subscriptionLatencyCalculator.getLatency(subscription); } public static Calendar min(Date lhs, Calendar rhs) { - return min(copy(lhs), rhs); + return min(TimeUtil.newCalendar(lhs), rhs); } public static Calendar max(Date lhs, Calendar rhs) { - return max(copy(lhs), rhs); + return max(TimeUtil.newCalendar(lhs), rhs); } - + public static Calendar max(Calendar lhs, Calendar rhs) { Calendar calendar = null; if (lhs != null && rhs != null) { @@ -95,24 +96,6 @@ public class BandwidthUtil { return calendar; } - public static Calendar copy(final Date date) { - Calendar t = null; - if (date != null) { - t = TimeUtil.newCalendar(); - t.setTime(date); - } - return t; - } - - public static Calendar copy(final Calendar calendar) { - Calendar t = null; - if (calendar != null) { - t = TimeUtil.newCalendar(); - t.setTimeInMillis(calendar.getTimeInMillis()); - } - return t; - } - /** * Seconds and milliseconds on a Calendar are not used in bandwidth * management and can alter some of the time arithmetic that is used @@ -137,7 +120,7 @@ public class BandwidthUtil { * * @return The delay in minutes. */ - public static int getDataSetAvailablityDelay(Subscription subscription) { + public static int getDataSetAvailablityDelay(Subscription subscription) { return instance.dataSetAvailabilityCalculator .getDataSetAvailablityDelay(subscription); } @@ -205,7 +188,7 @@ public class BandwidthUtil { * on error serializing the subscription */ public static BandwidthSubscription getSubscriptionDaoForSubscription( - Subscription subscription, Calendar baseReferenceTime) { + Subscription subscription, Calendar baseReferenceTime) { BandwidthSubscription dao = new BandwidthSubscription(); dao.setDataSetName(subscription.getDataSetName()); @@ -231,13 +214,13 @@ public class BandwidthUtil { * @return the dao */ public static BandwidthDataSetUpdate newDataSetMetaDataDao( - DataSetMetaData dataSetMetaData) { + DataSetMetaData dataSetMetaData) { BandwidthDataSetUpdate dao = new BandwidthDataSetUpdate(); // Set the fields we need to have.. dao.setDataSetName(dataSetMetaData.getDataSetName()); dao.setProviderName(dataSetMetaData.getProviderName()); dao.setUpdateTime(BandwidthUtil.now()); - dao.setDataSetBaseTime(BandwidthUtil.copy(dataSetMetaData.getDate())); + dao.setDataSetBaseTime(TimeUtil.newCalendar(dataSetMetaData.getDate())); dao.setUrl(dataSetMetaData.getUrl()); return dao; @@ -280,8 +263,21 @@ public class BandwidthUtil { * @return true if the subscription should be rescheduled */ public static boolean subscriptionRequiresReschedule( - Subscription subscription, Subscription old) { + Subscription subscription, Subscription old) { return instance.subscriptionRescheduleStrategy .subscriptionRequiresReschedule(subscription, old); } + + + /** + * Sets up the activePeriod Start/End to plan Start/End calendar + */ + public static Calendar planToPeriodCompareCalendar(Calendar planCalendar, Calendar activePeriod) { + + Calendar cal = TimeUtil.newCalendar(planCalendar); + cal.set(Calendar.MONTH, activePeriod.get(Calendar.MONTH)); + cal.set(Calendar.DAY_OF_MONTH, activePeriod.get(Calendar.DAY_OF_MONTH)); + + return cal; + } } diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval.wfs/src/com/raytheon/uf/edex/datadelivery/retrieval/wfs/WfsRequestBuilder.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval.wfs/src/com/raytheon/uf/edex/datadelivery/retrieval/wfs/WfsRequestBuilder.java index 33c9b73b31..6cef654ca6 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval.wfs/src/com/raytheon/uf/edex/datadelivery/retrieval/wfs/WfsRequestBuilder.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval.wfs/src/com/raytheon/uf/edex/datadelivery/retrieval/wfs/WfsRequestBuilder.java @@ -37,6 +37,7 @@ import com.vividsolutions.jts.geom.Coordinate; * end since the times will be correct now. * Oct 1, 2013 1797 dhladky Generics * Oct 10, 2013 1797 bgonzale Refactored registry Time objects. + * Oct 28, 2013 2448 dhladky Request start time incorrectly used subscription start time. * * * @@ -195,8 +196,9 @@ public class WfsRequestBuilder extends Reque String endDateString = null; String startDateString = null; - endDateString = ogcDateFormat.get().format(inTime.getEnd()); - startDateString = ogcDateFormat.get().format(inTime.getStart()); + // need to grab the request start and end times + endDateString = ogcDateFormat.get().format(inTime.getRequestEnd()); + startDateString = ogcDateFormat.get().format(inTime.getRequestStart()); StringBuilder sb = new StringBuilder(256); sb.append(PROPRERTYISGREATERTHAN_OPEN).append(NEW_LINE); diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval.wfs/src/com/raytheon/uf/edex/datadelivery/retrieval/wfs/WfsRetrievalGenerator.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval.wfs/src/com/raytheon/uf/edex/datadelivery/retrieval/wfs/WfsRetrievalGenerator.java index a420bfddf8..51ec6a0b3b 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval.wfs/src/com/raytheon/uf/edex/datadelivery/retrieval/wfs/WfsRetrievalGenerator.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval.wfs/src/com/raytheon/uf/edex/datadelivery/retrieval/wfs/WfsRetrievalGenerator.java @@ -2,6 +2,7 @@ package com.raytheon.uf.edex.datadelivery.retrieval.wfs; import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.List; import com.raytheon.uf.common.datadelivery.registry.Coverage; @@ -17,6 +18,7 @@ import com.raytheon.uf.common.datadelivery.retrieval.xml.Retrieval; import com.raytheon.uf.common.datadelivery.retrieval.xml.RetrievalAttribute; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.edex.datadelivery.retrieval.RetrievalGenerator; import com.raytheon.uf.edex.datadelivery.retrieval.adapters.RetrievalAdapter; @@ -37,7 +39,8 @@ import com.raytheon.uf.edex.datadelivery.retrieval.adapters.RetrievalAdapter; * Jun 04, 2013 1763 dhladky Readied for WFS Retrievals. * Jun 18, 2013 2120 dhladky Fixed times. * Sep 18, 2013 2383 bgonzale Added subscription name to log output. - * Oct 2, 2013 1797 dhladky Generics time gridded time separation + * Oct 2, 2013 1797 dhladky Generics time gridded time separation. + * Oct 28, 2013 2448 dhladky Request start time incorrectly used subscription start time. * * * @@ -85,8 +88,6 @@ class WfsRetrievalGenerator extends RetrievalGenerator { if (sub != null) { - PointTime subTime = sub.getTime(); - if (sub.getUrl() == null) { statusHandler .info("Skipping subscription " @@ -94,6 +95,16 @@ class WfsRetrievalGenerator extends RetrievalGenerator { + " that is unfulfillable with the current metadata (null URL.)"); return Collections.emptyList(); } + + PointTime subTime = sub.getTime(); + // Gets the most recent time, which is kept as the end time. + Date endDate = subTime.getEnd(); + // We add a little extra padding in the interval to prevent gaps in data. + long intervalMillis = (long) (subTime.getInterval() * TimeUtil.MILLIS_PER_MINUTE * 1.5); + // create the request start and end times. + subTime.setRequestEnd(endDate); + Date requestStartDate = new Date(endDate.getTime() - intervalMillis); + subTime.setRequestStart(requestStartDate); // with point data they all have the same data Parameter param = null; diff --git a/tests/unit/com/raytheon/uf/edex/datadelivery/bandwidth/AbstractBandwidthDaoTest.java b/tests/unit/com/raytheon/uf/edex/datadelivery/bandwidth/AbstractBandwidthDaoTest.java index e28e7db08c..240f15f3f8 100644 --- a/tests/unit/com/raytheon/uf/edex/datadelivery/bandwidth/AbstractBandwidthDaoTest.java +++ b/tests/unit/com/raytheon/uf/edex/datadelivery/bandwidth/AbstractBandwidthDaoTest.java @@ -77,6 +77,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; * Nov 12, 2012 1286 djohnson Initial creation * Jun 03, 2013 2038 djohnson Add test getting retrievals by dataset, provider, and status. * Oct 21, 2013 2292 mpduff Implement multiple data types. + * Oct 30, 2013 2248 dhladky Moved methods to TimeUtil * * * @@ -238,7 +239,7 @@ public abstract class AbstractBandwidthDaoTest