Author: knguyen
Date: Tue Sep 11 17:32:57 2007
New Revision: 18422

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D18422&repname=
=3Djahia
Log:
JAHIA-2208: give the user, the choice to choose if the next publication per=
iod should occur yesterday (for period that overlaps on two days), now or o=
nly at the next full period.

Modified:
    branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/conf/java/JahiaEngines=
Resources.properties
    branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/conf/java/JahiaEngines=
Resources_en.properties
    branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/conf/java/JahiaEngines=
Resources_fr.properties
    branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/java/org/jahia/engines=
/timebasedpublishing/TimeBasedPublishingEngine.java
    branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/java/org/jahia/service=
s/timebasedpublishing/DayInWeekBean.java
    branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/java/org/jahia/service=
s/timebasedpublishing/RangeRetentionRule.java
    branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/webapp/jsp/jahia/engin=
es/timebasedpublishing/rangerule.jsp

Modified: branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/conf/java/JahiaE=
nginesResources.properties
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-VODAFO=
NE-5-0-2-SP%20BRANCH/core/src/conf/java/JahiaEnginesResources.properties&re=
v=3D18422&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/conf/java/JahiaEngines=
Resources.properties (original)
+++ branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/conf/java/JahiaEngines=
Resources.properties Tue Sep 11 17:32:57 2007
@@ -1129,6 +1129,9 @@
 org.jahia.engines.timebasedpublishing.days.sun =3D sun
 org.jahia.engines.timebasedpublishing.from =3D from
 org.jahia.engines.timebasedpublishing.until =3D until
+org.jahia.engines.timebasedpublishing.firstOccurence =3D first occurence
+org.jahia.engines.timebasedpublishing.allowedToStartImmediately =3D allowe=
d to start immediately
+org.jahia.engines.timebasedpublishing.onlyAtNextFullPeriod =3D only at nex=
t full publish period
 org.jahia.engines.title.label =3D Title
 org.jahia.engines.title.AddContainer =3D Add content object
 org.jahia.engines.title.ContainerListProperties =3D Property of content ob=
ject list

Modified: branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/conf/java/JahiaE=
nginesResources_en.properties
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-VODAFO=
NE-5-0-2-SP%20BRANCH/core/src/conf/java/JahiaEnginesResources_en.properties=
&rev=3D18422&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/conf/java/JahiaEngines=
Resources_en.properties (original)
+++ branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/conf/java/JahiaEngines=
Resources_en.properties Tue Sep 11 17:32:57 2007
@@ -1129,6 +1129,9 @@
 org.jahia.engines.timebasedpublishing.days.sun =3D sun
 org.jahia.engines.timebasedpublishing.from =3D from
 org.jahia.engines.timebasedpublishing.until =3D until
+org.jahia.engines.timebasedpublishing.firstOccurence =3D first occurence
+org.jahia.engines.timebasedpublishing.allowedToStartImmediately =3D allowe=
d to start immediately
+org.jahia.engines.timebasedpublishing.onlyAtNextFullPeriod =3D only at nex=
t full publish period
 org.jahia.engines.title.label =3D Title
 org.jahia.engines.title.AddContainer =3D Add content object
 org.jahia.engines.title.ContainerListProperties =3D Property of content ob=
ject list

Modified: branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/conf/java/JahiaE=
nginesResources_fr.properties
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-VODAFO=
NE-5-0-2-SP%20BRANCH/core/src/conf/java/JahiaEnginesResources_fr.properties=
&rev=3D18422&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/conf/java/JahiaEngines=
Resources_fr.properties (original)
+++ branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/conf/java/JahiaEngines=
Resources_fr.properties Tue Sep 11 17:32:57 2007
@@ -886,6 +886,9 @@
 org.jahia.engines.timebasedpublishing.days.sun =3D dim
 org.jahia.engines.timebasedpublishing.from =3D de
 org.jahia.engines.timebasedpublishing.until =3D jusqu'=C3=A0
+org.jahia.engines.timebasedpublishing.firstOccurence =3D premi=C3=A8re occ=
urence
+org.jahia.engines.timebasedpublishing.allowedToStartImmediately =3D peut c=
ommencer imm=C3=A9diatement
+org.jahia.engines.timebasedpublishing.onlyAtNextFullPeriod =3D d=C3=A9bute=
 seulement =C3=A0 la prochaine p=C3=A9riode compl=C3=A8te
 org.jahia.engines.title.AddContainer =3D Ajouter un objet de contenu
 org.jahia.engines.title.ContainerListProperties =3D Propri=C3=A9t=C3=A9s d=
e la liste d'objets de contenu
 org.jahia.engines.title.DeleteContainer =3D Supprimer l'objet de contenu

Modified: branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/java/org/jahia/e=
ngines/timebasedpublishing/TimeBasedPublishingEngine.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-VODAFO=
NE-5-0-2-SP%20BRANCH/core/src/java/org/jahia/engines/timebasedpublishing/Ti=
meBasedPublishingEngine.java&rev=3D18422&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/java/org/jahia/engines=
/timebasedpublishing/TimeBasedPublishingEngine.java (original)
+++ branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/java/org/jahia/engines=
/timebasedpublishing/TimeBasedPublishingEngine.java Tue Sep 11 17:32:57 2007
@@ -92,6 +92,7 @@
             throws JahiaException, JahiaSessionExpirationException {
 =

         final HashMap subEngineMap =3D getSubEngineMap(jParams, engineMap,=
 objectKey);
+        /*
         final RangeRetentionRule currentRule =3D (RangeRetentionRule) subE=
ngineMap.get(ENGINE_NAME + ".currentRule");
         if (currentRule !=3D null) {
             try {
@@ -101,7 +102,7 @@
                 throw new JahiaException("Error creating rule clone","Erro=
r creating rule clone",JahiaException.ENGINE_ERROR,
                         JahiaException.ERROR_SEVERITY,t);
             }
-        }
+        }*/
         engineMap.put("fieldsEditCallingEngineName", ENGINE_NAME);
 =

         final LockPrerequisitesResult results =3D LockPrerequisites.getIns=
tance().getLockPrerequisitesResult((LockKey) engineMap.get("LockKey"));
@@ -207,6 +208,19 @@
 =

         long timeOffSet =3D 0;
         String oldRecurrenceType =3D jParams.getParameter("oldRuleType");
+
+        Boolean oldEnableImmediatePublication =3D (Boolean)subEngineMap.ge=
t(ENGINE_NAME + ".enableImmediatePublication");
+        if ( oldEnableImmediatePublication =3D=3D null ){
+            oldEnableImmediatePublication =3D Boolean.TRUE;
+        }
+        String enableImmediatePublicationStr =3D jParams.getParameter("ena=
bleImmediatePublication");
+        boolean enableImmediatePublication =3D true;
+        if ( enableImmediatePublicationStr !=3D null ){
+            enableImmediatePublication =3D "true".equals(enableImmediatePu=
blicationStr);
+            subEngineMap.put(ENGINE_NAME + ".enableImmediatePublication",
+                    new Boolean(enableImmediatePublication));
+        }
+
         if ( RetentionRule.RULE_START_AND_END_DATE.equals(oldRecurrenceTyp=
e) ){
             CalendarHandler calHandler =3D null;
             calHandler =3D (CalendarHandler) subEngineMap.get(ENGINE_NAME =
+ ".fromDateCalHandler");
@@ -241,7 +255,7 @@
             if ( l =3D=3D null ){
                 l =3D new Long(0);
             }
-            timeOffSet -=3D 2*l.longValue();
+            timeOffSet -=3D l.longValue();
 =

             // update daily recurrence parameters
             String value =3D jParams.getParameter("fromHours");
@@ -268,7 +282,7 @@
             if ( l =3D=3D null ){
                 l =3D new Long(0);
             }
-            timeOffSet -=3D 2*l.longValue();
+            timeOffSet -=3D l.longValue();
 =

             // update weekly recurrence parameters
             Iterator it =3D rule.getDaysInWeek().iterator();
@@ -287,35 +301,121 @@
         }
 =

         // compute next publish and next unpublish date
-        updateNextPublishAndExpireDate(rule,objectKey,timeOffSet);
+        updateNextPublishAndExpireDate(rule,objectKey,timeOffSet,enableImm=
ediatePublication,
+                oldEnableImmediatePublication.booleanValue() !=3D enableIm=
mediatePublication);
 =

     }
 =

-    private void updateNextPublishAndExpireDate(RangeRetentionRule rule,Ob=
jectKey objectKey, long timeOffSet)
+    private void updateNextPublishAndExpireDate(RangeRetentionRule rule,Ob=
jectKey objectKey, long timeOffSet,
+                                                boolean enableImmediatePub=
lication,
+                                                boolean enableImmediatePub=
licationHasChange)
     throws JahiaException {
         final RangeRetentionRule oldRule =3D (RangeRetentionRule) oldRules=
.get(objectKey.toString());
-        if ( isSame(oldRule,rule) ){
+        if ( isSame(oldRule,rule) && !enableImmediatePublicationHasChange =
){
             return;
         }
-        Calendar cal =3D Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+        Calendar cal =3D Calendar.getInstance(TimeZone.getDefault());
+        int serverDefaultOffSet =3D cal.getTimeZone().getRawOffset();
+        int serverDsts =3D cal.getTimeZone().getDSTSavings();
+        int timeOffSetInt =3D 0;
+        if ( timeOffSet !=3D 0 ){
+            Long l =3D new Long((timeOffSet+serverDefaultOffSet+serverDsts=
)/(60*60*1000));
+            timeOffSetInt =3D -l.intValue();
+        }
         if ( RetentionRule.RULE_DAILY.equals(rule.getRuleType()) ){
+            int fromTime =3D rule.getDailyFromHours() * 60 + rule.getDaily=
FromMinutes();
+            int toTime =3D rule.getDailyToHours() * 60 + rule.getDailyToMi=
nutes();
+            int currentTime =3D cal.get(Calendar.HOUR_OF_DAY) + timeOffSet=
Int;
+            if ( currentTime < 0 ){
+                currentTime =3D 24-currentTime;
+            }
+            currentTime =3D currentTime * 60  + cal.get(Calendar.MINUTE);
+            boolean inPeriod =3D (fromTime<toTime && fromTime<=3DcurrentTi=
me && currentTime<=3DtoTime)
+                    || (fromTime>toTime && (currentTime>=3DfromTime || cur=
rentTime<=3DtoTime) );
             cal.set(Calendar.SECOND,0);
             cal.set(Calendar.MILLISECOND,0);
             cal.set(Calendar.HOUR_OF_DAY,rule.getDailyFromHours());
             cal.set(Calendar.MINUTE,rule.getDailyFromMinutes());
+            if ( rule.getDailyFromHours() =3D=3D rule.getDailyToHours() ){
+                if ( rule.getDailyToMinutes()<rule.getDailyFromMinutes() ){
+                    if ( inPeriod ){
+                        if ( enableImmediatePublication ){
+                            cal.setTimeInMillis(cal.getTimeInMillis()-8640=
0000);
+                        } else if ( fromTime<=3DcurrentTime ) {
+                            cal.setTimeInMillis(cal.getTimeInMillis()+8640=
0000);
+                        }
+                    }
+                } else {
+                    if ( inPeriod ){
+                        if ( !enableImmediatePublication ){
+                            cal.setTimeInMillis(cal.getTimeInMillis()+8640=
0000);
+                        }
+                    }
+                }
+            } else if ( rule.getDailyFromHours() > rule.getDailyToHours() =
){
+                if ( inPeriod ){
+                    if ( enableImmediatePublication ){
+                        cal.setTimeInMillis(cal.getTimeInMillis()-86400000=
);
+                    } else if ( fromTime<=3DcurrentTime ) {
+                        cal.setTimeInMillis(cal.getTimeInMillis()+86400000=
);
+                    }
+                }
+            } else {
+                if ( inPeriod ){
+                    if ( !enableImmediatePublication ){
+                        cal.setTimeInMillis(cal.getTimeInMillis()+86400000=
);
+                    }
+                }
+            }
             rule.setValidFromDate(new Long(cal.getTimeInMillis()+timeOffSe=
t));
+            cal =3D Calendar.getInstance(TimeZone.getDefault());
+            cal.set(Calendar.SECOND,0);
+            cal.set(Calendar.MILLISECOND,0);
             cal.set(Calendar.HOUR_OF_DAY,rule.getDailyToHours());
             cal.set(Calendar.MINUTE,rule.getDailyToMinutes());
             if ( rule.getDailyFromHours() =3D=3D rule.getDailyToHours() ){
                 if ( rule.getDailyToMinutes()<rule.getDailyFromMinutes() ){
+                    if ( inPeriod ){
+                        if ( !enableImmediatePublication ){
+                            if (fromTime<=3DcurrentTime){
+                                cal.setTimeInMillis(cal.getTimeInMillis()+=
86400000*2);
+                            } else {
+                                cal.setTimeInMillis(cal.getTimeInMillis()+=
86400000);
+                            }
+                        }
+                    } else {
+                        cal.setTimeInMillis(cal.getTimeInMillis()+86400000=
);
+                    }
+                } else {
+                    if ( inPeriod ){
+                        if ( !enableImmediatePublication ){
                     cal.setTimeInMillis(cal.getTimeInMillis()+86400000);
                 }
+                    }
+                }
             } else if ( rule.getDailyFromHours() > rule.getDailyToHours() =
){
+                if ( inPeriod ){
+                    if ( !enableImmediatePublication ){
+                        if (fromTime<=3DcurrentTime){
+                            cal.setTimeInMillis(cal.getTimeInMillis()+8640=
0000*2);
+                        } else {
                 cal.setTimeInMillis(cal.getTimeInMillis()+86400000);
             }
+                    }
+                } else {
+                    cal.setTimeInMillis(cal.getTimeInMillis()+86400000);
+                }
+            } else {
+                if ( inPeriod ){
+                    if ( !enableImmediatePublication ){
+                        cal.setTimeInMillis(cal.getTimeInMillis()+86400000=
);
+                    }
+                }
+            }
             rule.setValidToDate(new Long(cal.getTimeInMillis()+timeOffSet)=
);
         } else if ( RetentionRule.RULE_XDAYINWEEK.equals(rule.getRuleType(=
)) ){
-            DayInWeekBean.computeRuleNextEventDate(rule,cal.getTimeInMilli=
s(),cal,timeOffSet,false);                        =

+            DayInWeekBean.computeRuleNextEventDate(rule,0,cal,timeOffSet,
+                    enableImmediatePublication);
         }
     }
 =

@@ -328,6 +428,19 @@
 =

         final RangeRetentionRule oldRule =3D (RangeRetentionRule) oldRules=
.get(objectKey.toString());
 =

+        try {
+            Boolean enableImmediatePublication =3D (Boolean)subEngineMap.g=
et(ENGINE_NAME + ".enableImmediatePublication");
+            ContentObject contentObject =3D ContentObject.getContentObject=
Instance(objectKey);
+            String val =3D contentObject
+                    .getProperty(TimeBasedPublishingEngine.ENGINE_NAME+".e=
nableImmediatePublication");
+            boolean oldValue =3D ("true".equals(val) || val=3D=3Dnull);
+            if ( enableImmediatePublication.booleanValue() !=3D oldValue ){
+                contentObject.setProperty(TimeBasedPublishingEngine.ENGINE=
_NAME+".enableImmediatePublication",
+                        enableImmediatePublication.toString());
+            }
+        } catch ( Throwable t ){
+        }
+
         if (currentRuleDef !=3D null) {
             final RangeRetentionRule rule =3D (RangeRetentionRule) subEngi=
neMap.get(ENGINE_NAME + ".currentRule");
             logger.debug("old: " + oldRule);
@@ -357,7 +470,8 @@
         return true;
     }
 =

-    private HashMap getSubEngineMap(ProcessingContext jParams, HashMap eng=
ineMap, ObjectKey objectKey) {
+    private HashMap getSubEngineMap(ProcessingContext jParams, HashMap eng=
ineMap, ObjectKey objectKey)
+            throws JahiaException {
         HashMap subEngineMap =3D (HashMap) engineMap.get(SUB_ENGINE_MAP_NA=
ME);
         if (subEngineMap =3D=3D null) {
             subEngineMap =3D new HashMap();
@@ -372,8 +486,12 @@
                 rule =3D baseDef.createRule();
                 rule.setInherited(Boolean.TRUE);
             }
-
-            subEngineMap.put(ENGINE_NAME + ".currentRule", rule);
+            try {
+                subEngineMap.put(ENGINE_NAME + ".currentRule", rule.clone(=
));
+            } catch ( Throwable t ){
+                throw new JahiaException("Error cloning rule","Error cloni=
ng rule",JahiaException.APPLICATION_ERROR,
+                    JahiaException.ERROR_SEVERITY,t);
+            }
             oldRules.put(objectKey.toString(), rule);
             subEngineMap.put(ENGINE_NAME + ".currentRuleDef", rule.getRete=
ntionRuleDef());
             // todo supoort ofr other rule
@@ -381,6 +499,15 @@
             subEngineMap.put(ENGINE_NAME + ".toDateCalHandler", getCalHand=
ler(rule, "toDate", jParams));
 =

             subEngineMap.put(ENGINE_NAME + ".ruleDefs", tbpServ.getRetenti=
onRuleDefs());
+
+            try {
+                ContentObject contentObject =3D ContentObject.getContentOb=
jectInstance(objectKey);
+                String val =3D contentObject
+                        .getProperty(TimeBasedPublishingEngine.ENGINE_NAME=
+".enableImmediatePublication");
+                boolean enableImmediatePublication =3D ("true".equals(val)=
 || val=3D=3Dnull);
+                subEngineMap.put(ENGINE_NAME + ".enableImmediatePublicatio=
n", new Boolean(enableImmediatePublication));
+            } catch ( Throwable t ){
+            }
         }
         return subEngineMap;
     }

Modified: branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/java/org/jahia/s=
ervices/timebasedpublishing/DayInWeekBean.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-VODAFO=
NE-5-0-2-SP%20BRANCH/core/src/java/org/jahia/services/timebasedpublishing/D=
ayInWeekBean.java&rev=3D18422&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/java/org/jahia/service=
s/timebasedpublishing/DayInWeekBean.java (original)
+++ branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/java/org/jahia/service=
s/timebasedpublishing/DayInWeekBean.java Tue Sep 11 17:32:57 2007
@@ -182,92 +182,151 @@
     }
 =

     public static void computeRuleNextEventDate(RangeRetentionRule newRule,
-                                                long startDate, Calendar c=
al, long timeOffSet, boolean skipToday){
+                                                long startDate, Calendar c=
al, long timeOffSet,
+                                                boolean enableImmediatePub=
lication){
         DayInWeekBean dayBean =3D null;
         long nextPublishTime =3D 0;
         long nextExpireTime =3D 0;
         Iterator it =3D newRule.getDaysInWeek().iterator();
-        List nextPublishDates =3D new ArrayList();
-        List nextExpireDates =3D new ArrayList();
+        SortedSet nextPublishDates =3D new TreeSet();
+        SortedSet nextExpireDates =3D new TreeSet();
         while ( it.hasNext() ){
             dayBean =3D (DayInWeekBean)it.next();
             if ( dayBean.isSelected() ){
-                computeNextEventsTime(cal,dayBean,nextPublishDates,nextExp=
ireDates,timeOffSet,skipToday);
+                computeNextEventsTime(cal,dayBean,nextPublishDates,nextExp=
ireDates,timeOffSet);
             }
         }
-        // get the next nearest expire date
+        // get the next nearest publish date
         Date date =3D null;
-        long now =3D 0;
-        Calendar tmpCal =3D (Calendar)cal.clone();
-        it =3D nextExpireDates.iterator();
+        it =3D nextPublishDates.iterator();
+        if ( !enableImmediatePublication ){
+            List inversedDateList =3D new ArrayList();
+            while ( it.hasNext() ){
+                inversedDateList.add(0,it.next());
+            }
+            it =3D inversedDateList.iterator();
+        }
+        long now =3D cal.getTimeInMillis()+timeOffSet;
         if ( it.hasNext() ){
-            now =3D cal.getTimeInMillis();
             while ( it.hasNext() ){
                 date =3D (Date)it.next();
-                tmpCal.setTimeInMillis(date.getTime());
-                if ( date.getTime()< nextExpireTime || nextExpireTime=3D=
=3D0 ){
-                    nextExpireTime =3D date.getTime();
+                if (date.getTime()>startDate ){
+                    if ( nextPublishTime =3D=3D 0 ){
+                        nextPublishTime =3D date.getTime();
+                    } else if ( enableImmediatePublication && date.getTime=
()<now && date.getTime()>nextPublishTime ){
+                        nextPublishTime =3D date.getTime();
+                    } else if ( !enableImmediatePublication && date.getTim=
e()>now && date.getTime()<nextPublishTime ){
+                        nextPublishTime =3D date.getTime();
+                    }
                 }
             }
-            newRule.setValidToDate(new Long(nextExpireTime));
+            newRule.setValidFromDate(new Long(nextPublishTime));
         } else {
-            newRule.setValidToDate(new Long(0));
+            newRule.setValidFromDate(new Long(0));
         }
-        // get the next nearest publish date
-        it =3D nextPublishDates.iterator();
-        if ( it.hasNext() ){
-            now =3D cal.getTimeInMillis();
+
+        // get the next nearest expire date
+        it =3D nextExpireDates.iterator();
+        if ( nextPublishTime >0 && it.hasNext() ){
             while ( it.hasNext() ){
                 date =3D (Date)it.next();
-                tmpCal.setTimeInMillis(date.getTime());
-                if (date.getTime()< nextPublishTime || nextPublishTime=3D=
=3D0 ){
-                    nextPublishTime =3D date.getTime();
+                if ( date.getTime()>nextPublishTime ){
+                    nextExpireTime =3D date.getTime();
+                    break;
                 }
             }
-            newRule.setValidFromDate(new Long(nextPublishTime));
+            newRule.setValidToDate(new Long(nextExpireTime));
         } else {
-            newRule.setValidFromDate(new Long(0));
+            newRule.setValidToDate(new Long(0));
         }
     }
 =

     private static void computeNextEventsTime(Calendar nowCalendar,
                                        DayInWeekBean dayBean,
-                                       List nextPublishDates,
-                                       List nextExpireDates,
-                                       long timeOffSet,
-                                       boolean skipToday){
+                                       Set nextPublishDates,
+                                       Set nextExpireDates,
+                                       long timeOffSet){
+
         if ( ((dayBean.getFromHours()+dayBean.getFromMinutes())=3D=3D0)
               && ((dayBean.getToHours()+dayBean.getToMinutes())=3D=3D0) ) {
             return;
         }
-        Calendar cal =3D (Calendar)nowCalendar.clone();
+
+        Calendar nowCal =3D (Calendar)nowCalendar.clone();
         int todayDayInWeek =3D nowCalendar.get(Calendar.DAY_OF_WEEK);
         int dayInWeek =3D DayInWeekBean.getJavaCalendarDayOfWeek(dayBean);
-        cal.set(Calendar.DAY_OF_WEEK,dayInWeek);
-        if ( dayInWeek<todayDayInWeek || (skipToday && dayInWeek=3D=3Dtoda=
yDayInWeek ) ){
-            cal.add(Calendar.WEEK_OF_MONTH,1); // add one week
-        }
-        cal.set(Calendar.HOUR_OF_DAY,dayBean.getFromHours());
-        cal.set(Calendar.MINUTE,dayBean.getFromMinutes());
-        cal.setTimeInMillis(cal.getTimeInMillis()+timeOffSet);
-        nextPublishDates.add(cal.getTime());
-
-        cal =3D (Calendar)nowCalendar.clone();
-        cal.set(Calendar.DAY_OF_WEEK,dayInWeek);
-        if ( dayInWeek<todayDayInWeek || (skipToday && dayInWeek=3D=3Dtoda=
yDayInWeek) ){
-            cal.add(Calendar.WEEK_OF_MONTH,1); // add one week
-        }
-        cal.set(Calendar.HOUR_OF_DAY,dayBean.getToHours());
-        cal.set(Calendar.MINUTE,dayBean.getToMinutes());
-        if ( dayBean.getFromHours() =3D=3D dayBean.getToHours() ){
-            if ( dayBean.getToMinutes()<dayBean.getFromMinutes() ){
-                cal.setTimeInMillis(cal.getTimeInMillis()+86400000);
+        nowCal.set(Calendar.DAY_OF_WEEK,dayInWeek);
+        if ( dayInWeek<=3DtodayDayInWeek ){
+            nowCal.add(Calendar.WEEK_OF_MONTH,1); // add one week
+        }
+        nowCal.set(Calendar.HOUR_OF_DAY,dayBean.getFromHours());
+        nowCal.set(Calendar.MINUTE,dayBean.getFromMinutes());
+        nowCal.set(Calendar.SECOND,0);
+        nowCal.set(Calendar.MILLISECOND,0);
+        nowCal.setTimeInMillis(nowCal.getTimeInMillis()+timeOffSet);
+        nextPublishDates.add(nowCal.getTime());
+
+        nowCal =3D (Calendar)nowCalendar.clone();
+        nowCal.set(Calendar.HOUR_OF_DAY,dayBean.getToHours());
+        nowCal.set(Calendar.MINUTE,dayBean.getToMinutes());
+        nowCal.set(Calendar.SECOND,0);
+        nowCal.set(Calendar.MILLISECOND,0);
+        nowCal.set(Calendar.DAY_OF_WEEK,dayInWeek);
+        if ( dayInWeek<=3DtodayDayInWeek ){
+            nowCal.add(Calendar.WEEK_OF_MONTH,1); // add one week
+        }
+        if ( (dayBean.getFromHours() =3D=3D dayBean.getToHours() &&
+             dayBean.getToMinutes()< dayBean.getFromMinutes())
+                || dayBean.getFromHours()>dayBean.getToHours() ){
+            nowCal.setTimeInMillis(nowCal.getTimeInMillis()+86400000);
+        }
+        nowCal.setTimeInMillis(nowCal.getTimeInMillis()+timeOffSet);
+        nextExpireDates.add(nowCal.getTime());
+
+
+        int fromTime =3D dayBean.getFromHours() * 60 + dayBean.getFromMinu=
tes();
+        int toTime =3D dayBean.getToHours() * 60 + dayBean.getToMinutes();
+
+        nowCal =3D (Calendar)nowCalendar.clone();
+        if ( todayDayInWeek =3D=3D dayInWeek ){
+            nowCal.set(Calendar.DAY_OF_WEEK,dayInWeek);
+            nowCal.set(Calendar.HOUR_OF_DAY,dayBean.getFromHours());
+            nowCal.set(Calendar.MINUTE,dayBean.getFromMinutes());
+            nowCal.set(Calendar.SECOND,0);
+            nowCal.set(Calendar.MILLISECOND,0);
+            nowCal.setTimeInMillis(nowCal.getTimeInMillis()+timeOffSet);
+            nextPublishDates.add(nowCal.getTime());
+            nowCal =3D (Calendar)nowCalendar.clone();
+            nowCal.set(Calendar.HOUR_OF_DAY,dayBean.getToHours());
+            nowCal.set(Calendar.MINUTE,dayBean.getToMinutes());
+            nowCal.set(Calendar.SECOND,0);
+            nowCal.set(Calendar.MILLISECOND,0);
+            if ( (dayBean.getFromHours() =3D=3D dayBean.getToHours() &&
+                 dayBean.getToMinutes()< dayBean.getFromMinutes())
+                    || dayBean.getFromHours()>dayBean.getToHours() ){
+                nowCal.setTimeInMillis(nowCal.getTimeInMillis()+86400000);
+            }
+            nowCal.setTimeInMillis(nowCal.getTimeInMillis()+timeOffSet);
+            nextExpireDates.add(nowCal.getTime());
+        } else if ( (todayDayInWeek - dayInWeek =3D=3D 1)
+                || (todayDayInWeek =3D=3D Calendar.SUNDAY && dayInWeek =3D=
=3D Calendar.SATURDAY) ){
+            if ( fromTime>toTime ){
+                // add yesterday
+                nowCal.set(Calendar.HOUR_OF_DAY,dayBean.getFromHours());
+                nowCal.set(Calendar.MINUTE,dayBean.getFromMinutes());
+                nowCal.set(Calendar.SECOND,0);
+                nowCal.set(Calendar.MILLISECOND,0);
+                nowCal.setTimeInMillis(nowCal.getTimeInMillis()+timeOffSet=
-86400000);
+                nextPublishDates.add(nowCal.getTime());
+                nowCal =3D (Calendar)nowCalendar.clone();
+                nowCal.set(Calendar.HOUR_OF_DAY,dayBean.getToHours());
+                nowCal.set(Calendar.MINUTE,dayBean.getToMinutes());
+                nowCal.set(Calendar.SECOND,0);
+                nowCal.set(Calendar.MILLISECOND,0);
+                nowCal.setTimeInMillis(nowCal.getTimeInMillis()+timeOffSet=
);
+                nextExpireDates.add(nowCal.getTime());
             }
-        } else if ( dayBean.getFromHours() > dayBean.getToHours() ){
-            cal.setTimeInMillis(cal.getTimeInMillis()+86400000);
         }
-        cal.setTimeInMillis(cal.getTimeInMillis()+timeOffSet);
-        nextExpireDates.add(cal.getTime());
     }
 =

     public boolean equals(Object obj) {

Modified: branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/java/org/jahia/s=
ervices/timebasedpublishing/RangeRetentionRule.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-VODAFO=
NE-5-0-2-SP%20BRANCH/core/src/java/org/jahia/services/timebasedpublishing/R=
angeRetentionRule.java&rev=3D18422&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/java/org/jahia/service=
s/timebasedpublishing/RangeRetentionRule.java (original)
+++ branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/java/org/jahia/service=
s/timebasedpublishing/RangeRetentionRule.java Tue Sep 11 17:32:57 2007
@@ -253,7 +253,6 @@
      *
      * @param context
      * @return the next fire time. 0 if no fire time
-     *
      * @throws Exception
      */
     public long scheduleNextJob(ProcessingContext context) throws Exceptio=
n {
@@ -280,7 +279,7 @@
             timeShift =3D 86400000;
             setValidToDate(new Long(cal.getTimeInMillis()+offSet+timeShift=
));
         } else if ( RetentionRule.RULE_XDAYINWEEK.equals(getRuleType()) ){
-            DayInWeekBean.computeRuleNextEventDate(this,cal.getTimeInMilli=
s(),cal,offSet,true);
+            DayInWeekBean.computeRuleNextEventDate(this,cal.getTimeInMilli=
s(),cal,offSet,false);
         }
         boolean canSchedule =3D  postScheduleNextJob();
         if ( !canSchedule ){

Modified: branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/webapp/jsp/jahia=
/engines/timebasedpublishing/rangerule.jsp
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-VODAFO=
NE-5-0-2-SP%20BRANCH/core/src/webapp/jsp/jahia/engines/timebasedpublishing/=
rangerule.jsp&rev=3D18422&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/webapp/jsp/jahia/engin=
es/timebasedpublishing/rangerule.jsp (original)
+++ branches/JAHIA-VODAFONE-5-0-2-SP BRANCH/core/src/webapp/jsp/jahia/engin=
es/timebasedpublishing/rangerule.jsp Tue Sep 11 17:32:57 2007
@@ -32,6 +32,9 @@
             get(TimeBasedPublishingEngine.ENGINE_NAME + ".toDateCalHandler=
");
     final BaseRetentionRule currentRule =3D (BaseRetentionRule) subEngineM=
ap.
             get(TimeBasedPublishingEngine.ENGINE_NAME + ".currentRule");
+    Boolean enableImmediatePublication =3D (Boolean) subEngineMap.
+            get(TimeBasedPublishingEngine.ENGINE_NAME + ".enableImmediateP=
ublication");       =

+    request.setAttribute("enableImmediatePublication", enableImmediatePubl=
ication);
     if (currentRule !=3D null) {
         inherited =3D currentRule.getInherited().booleanValue();
     }
@@ -156,6 +159,15 @@
             request.setAttribute("minutes",String.valueOf(currentRule.getD=
ailyToMinutes()));
           %>
           <jsp:include page=3D"hours_input.jsp" flush=3D"true" />
+          <br/>
+          <br/>
+        </td>
+    </tr>
+    <tr class=3D"ruleSettings">
+        <td class=3D"t1"><jahia:engineResourceBundle
+                resourceName=3D"org.jahia.engines.timebasedpublishing.firs=
tOccurence" defaultValue=3D"first occurence"/></td>
+        <td class=3D"t22">
+          <jsp:include page=3D"enable_immediatepublication.jsp" flush=3D"t=
rue"/>
         </td>
     </tr>
     <% } else if (RetentionRule.RULE_XDAYINWEEK.equals(currentRule.getRule=
Type())) {%>
@@ -203,11 +215,19 @@
               request.setAttribute("hiddenCalendar", Boolean.TRUE);
           %>
           <jsp:include page=3D"calendar.jsp" flush=3D"true"/>
+          <br/>
           <%
             request.removeAttribute("hiddenCalendar");
           %>
         </td>
     </tr>
+    <tr class=3D"ruleSettings">
+        <td class=3D"t1"><jahia:engineResourceBundle
+                resourceName=3D"org.jahia.engines.timebasedpublishing.firs=
tOccurence" defaultValue=3D"first occurence"/></td>
+        <td class=3D"t22">
+          <jsp:include page=3D"enable_immediatepublication.jsp" flush=3D"t=
rue"/>
+        </td>
+    </tr>
     <% } %>
 </table>
 =


_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list

Reply via email to