org.opencms.ade.publish
Class A_CmsPublishGroupHelper<RESOURCE,GROUP>

java.lang.Object
  extended by org.opencms.ade.publish.A_CmsPublishGroupHelper<RESOURCE,GROUP>
Type Parameters:
RESOURCE - the resource class type
GROUP - the resource group class type
Direct Known Subclasses:
CmsDefaultPublishGroupHelper

public abstract class A_CmsPublishGroupHelper<RESOURCE,GROUP>
extends java.lang.Object

Helper class for splitting a publish list into publish groups.

Since:
8.0.0

Nested Class Summary
static class A_CmsPublishGroupHelper.GroupAge
          An enum representing the age of a publish list resource.
 
Field Summary
protected static int GROUP_SESSIONS_GAP
          The gap between session groups.
 
Constructor Summary
A_CmsPublishGroupHelper(java.util.Locale locale)
          Creates a new publish group helper for a given locale.
 
Method Summary
 java.util.Map<java.lang.Long,java.lang.Integer> computeDays(java.util.List<java.lang.Long> sortedDates)
          Given a descending list of dates represented as longs, this method computes a map from the dates to their age in (local) days.
 java.util.Map<java.lang.Long,java.lang.Integer> computeDaysForResources(java.util.List<RESOURCE> resources)
          Computes a map from modification date to number of (local) days since the modification date.
protected abstract  GROUP createGroup(java.lang.String name, java.util.List<RESOURCE> resources)
          Creates a named group of resources.
protected abstract  long getDateLastModified(RESOURCE res)
          Gets the last modification date of a resource.
 int getDayDifference(long first, long second)
          Gets the difference in days between to dates given as longs.
 java.util.List<GROUP> getGroups(java.util.List<RESOURCE> resources)
          Splits a list of resources into groups.
 java.util.List<java.lang.Long> getModificationDates(java.util.List<RESOURCE> resources)
          Given a list of resources, this method returns a list of their modification dates.
 java.lang.String getPublishGroupName(java.util.List<RESOURCE> resources, A_CmsPublishGroupHelper.GroupAge age)
          Returns the localized name for a given publish group based on its age.
protected abstract  java.lang.String getRootPath(RESOURCE res)
          Gets the root path of a resource.
 java.util.Calendar getStartOfDay(long time)
          Returns a calendar object representing the start of the day in which a given time lies.
 java.util.List<java.util.List<RESOURCE>> partitionMediumResources(java.util.List<RESOURCE> resources, java.util.Map<java.lang.Long,java.lang.Integer> days)
          Computes publish groups for a list of resources with age "medium".
 java.util.Map<A_CmsPublishGroupHelper.GroupAge,java.util.List<RESOURCE>> partitionPublishResourcesByAge(java.util.List<RESOURCE> resources, java.util.Map<java.lang.Long,java.lang.Integer> days)
          Partitions a list of resources by their age in (local) days since the last modification.
 java.util.List<java.util.List<RESOURCE>> partitionYoungResources(java.util.List<RESOURCE> resources)
          Partitions the list of young resources into publish groups.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GROUP_SESSIONS_GAP

protected static final int GROUP_SESSIONS_GAP
The gap between session groups.

See Also:
Constant Field Values
Constructor Detail

A_CmsPublishGroupHelper

public A_CmsPublishGroupHelper(java.util.Locale locale)
Creates a new publish group helper for a given locale.

Parameters:
locale - the locale to use
Method Detail

computeDays

public java.util.Map<java.lang.Long,java.lang.Integer> computeDays(java.util.List<java.lang.Long> sortedDates)
Given a descending list of dates represented as longs, this method computes a map from the dates to their age in (local) days.

Parameters:
sortedDates - a descending list of dates represented as longs
Returns:
a map from dates to ages (measured in days)

computeDaysForResources

public java.util.Map<java.lang.Long,java.lang.Integer> computeDaysForResources(java.util.List<RESOURCE> resources)
Computes a map from modification date to number of (local) days since the modification date.

Parameters:
resources - a list of resources
Returns:
a map from modification dates to the number of days since the modification date

getDayDifference

public int getDayDifference(long first,
                            long second)
Gets the difference in days between to dates given as longs.

The first date must be later than the second date.

Parameters:
first - the first date
second - the second date
Returns:
the difference between the two dates in days

getGroups

public java.util.List<GROUP> getGroups(java.util.List<RESOURCE> resources)
Splits a list of resources into groups.

Parameters:
resources - the list of resources
Returns:
the list of groups

getModificationDates

public java.util.List<java.lang.Long> getModificationDates(java.util.List<RESOURCE> resources)
Given a list of resources, this method returns a list of their modification dates.

Parameters:
resources - a list of resources
Returns:
the modification dates of the resources, in the same order as the resources

getPublishGroupName

public java.lang.String getPublishGroupName(java.util.List<RESOURCE> resources,
                                            A_CmsPublishGroupHelper.GroupAge age)
Returns the localized name for a given publish group based on its age.

Parameters:
resources - the resources of the publish group
age - the age of the publish group
Returns:
the localized name of the publish group

getStartOfDay

public java.util.Calendar getStartOfDay(long time)
Returns a calendar object representing the start of the day in which a given time lies.

Parameters:
time - a long representing a time
Returns:
a calendar object which represents the day in which the time lies

partitionMediumResources

public java.util.List<java.util.List<RESOURCE>> partitionMediumResources(java.util.List<RESOURCE> resources,
                                                                         java.util.Map<java.lang.Long,java.lang.Integer> days)
Computes publish groups for a list of resources with age "medium".

Parameters:
resources - the list of resources
days - a map from modification dates to the number of days since the modification
Returns:
a list of publish groups

partitionPublishResourcesByAge

public java.util.Map<A_CmsPublishGroupHelper.GroupAge,java.util.List<RESOURCE>> partitionPublishResourcesByAge(java.util.List<RESOURCE> resources,
                                                                                                               java.util.Map<java.lang.Long,java.lang.Integer> days)
Partitions a list of resources by their age in (local) days since the last modification.

Parameters:
resources - the list of resources to partition
days - the map from modification dates to the number of (local) days since the modification
Returns:
a map from age enum values to the list of resources which fall into the corresponding age group

partitionYoungResources

public java.util.List<java.util.List<RESOURCE>> partitionYoungResources(java.util.List<RESOURCE> resources)
Partitions the list of young resources into publish groups.

Parameters:
resources - the list of resources to partition
Returns:
a partition of the resources into publish groups

createGroup

protected abstract GROUP createGroup(java.lang.String name,
                                     java.util.List<RESOURCE> resources)
Creates a named group of resources.

Parameters:
name - the name of the group
resources - the resources which should be put in the group
Returns:
the named group

getDateLastModified

protected abstract long getDateLastModified(RESOURCE res)
Gets the last modification date of a resource.

Parameters:
res - the resource
Returns:
the last modification date of res

getRootPath

protected abstract java.lang.String getRootPath(RESOURCE res)
Gets the root path of a resource.

Parameters:
res - the resource
Returns:
the root path of res