Skip to content

Almanach limited next events #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,9 @@ almanachColor20 = pink
almanach.timezone = Europe/Paris
almanach.yeareventspopup.arraypagesize = 15

templatePath=${SILVERPEAS_HOME}/resources/StringTemplates/components/almanach/ (d�fini dans SilverpeasSettings.xml)
customersTemplatePath=${SILVERPEAS_DATA_HOME}/StringTemplates/components/almanach/ (d�fini dans SilverpeasSettings.xml)
templatePath=${SILVERPEAS_HOME}/resources/StringTemplates/components/almanach/ (d\u00e9fini dans SilverpeasSettings.xml)
customersTemplatePath=${SILVERPEAS_DATA_HOME}/StringTemplates/components/almanach/ (d\u00e9fini dans SilverpeasSettings.xml)

# The window of time within which the next events has to be fetched from today (and thus to be rendered),
# expressed in months. No values or 0 means a no limited window of time (a window with an infinite upper bound).
almanach.nextEvents.windowtime=0
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.stratelia.webactiv.persistence.SilverpeasBeanDAOFactory;
import com.stratelia.webactiv.util.DBUtil;
import com.stratelia.webactiv.util.JNDINames;
import com.stratelia.webactiv.util.ResourceLocator;
import com.stratelia.webactiv.util.attachment.control.AttachmentController;
import com.stratelia.webactiv.util.attachment.ejb.AttachmentPK;
import com.stratelia.webactiv.util.attachment.model.AttachmentDetail;
Expand Down Expand Up @@ -79,6 +80,8 @@
public class AlmanachBmEJB implements AlmanachBmBusinessSkeleton, SessionBean {

private static final long serialVersionUID = -8559479482209447676L;
private static final ResourceLocator settings = new ResourceLocator(
"com.stratelia.webactiv.almanach.settings.almanachSettings", "");
private AlmanachContentManager almanachContentManager = null;
private SilverpeasBeanDAO<Periodicity> eventPeriodicityDAO = null;
private SilverpeasBeanDAO<PeriodicityException> periodicityExceptionDAO = null;
Expand Down Expand Up @@ -1003,24 +1006,39 @@ public List<EventOccurrence> getEventOccurrencesInWeek(java.util.Calendar week,

@Override
public List<EventOccurrence> getNextEventOccurrences(String... almanachIds) throws RemoteException {
List<EventOccurrence> occurrences;
try {
com.silverpeas.calendar.Date today = today();
Collection<EventDetail> events = getEventDAO().findAllEventsInRange(date2SQLDate(today), null,
almanachIds);
java.util.Calendar endDate = java.util.Calendar.getInstance();
String upToDay = null;
int numberOfMonths = getAlmanachSettings().getInteger("almanach.nextEvents.windowtime", 0);
if (numberOfMonths > 0) {
endDate.add(java.util.Calendar.MONTH, numberOfMonths);
upToDay = date2SQLDate(endDate.getTime());
}
Collection<EventDetail> events = getEventDAO().findAllEventsInRange(date2SQLDate(today),
upToDay, almanachIds);

EventOccurrenceGenerator occurrenceGenerator = EventOccurrenceGeneratorFactory.getFactory().
getEventOccurrenceGenerator();
return occurrenceGenerator.generateOccurrencesFrom(today, new ArrayList<EventDetail>(events));
if (numberOfMonths > 0) {
com.silverpeas.calendar.Date endDay = new com.silverpeas.calendar.Date(endDate.getTime());
occurrences = occurrenceGenerator.generateOccurrencesInRange(today, endDay, new ArrayList<EventDetail>(events));
} else {
occurrences = occurrenceGenerator.generateOccurrencesFrom(today, new ArrayList<EventDetail>(events));
}
} catch (Exception ex) {
throw new AlmanachRuntimeException("AlmanachBmEJB.getEventOccurrencesInWeek()",
SilverpeasRuntimeException.ERROR, "almanach.EXE_GET_ALL_EVENTS_FAIL",
ex);
}
return occurrences;
}

protected EventDAO getEventDAO() {
return this.eventDAO;
}

protected com.silverpeas.calendar.Date today() {
return com.silverpeas.calendar.Date.today();
}
Expand All @@ -1040,4 +1058,8 @@ && isDefined(event.getStartHour())) {
}
}
}

private ResourceLocator getAlmanachSettings() {
return settings;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,18 @@ List<EventOccurrence> generateOccurrencesInWeek(final Calendar week,
final List<EventDetail> events);

/**
* Generates the occurrences of the specified events that occur from the specified date.
* Generates the occurrences of the specified events that occur between the two specified dates.
* @param date the inclusive date from which the event occurrences occur.
* @param date the date to which the event occurrences occur.
* @param events the events for which the occurrences have to be generated.
* @return a list of occurrences occuring from the specified date.
*/
List<EventOccurrence> generateOccurrencesInRange(final Date startDate, final Date endDate,
final List<EventDetail> events);

/**
* Generates the occurrences of the specified events that occur from the specified date with no
* limit in the future.
* @param date the inclusive date from which the event occurrences occur.
* @param events the events for which the occurrences have to be generated.
* @return a list of occurrences occuring from the specified date.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,19 @@ public List<EventOccurrence> generateOccurrencesInWeek(java.util.Calendar week,
return generateOccurrencesOf(events, occuringIn(theWeek));
}

@Override
public List<EventOccurrence> generateOccurrencesInRange(Date startDate, Date endDate,
List<EventDetail> events) {
Period period = new Period(new DateTime(startDate), new DateTime(endDate));
return generateOccurrencesOf(events, occuringIn(period));
}

@Override
public List<EventOccurrence> generateOccurrencesFrom(Date date, List<EventDetail> events) {
java.util.Calendar endDate = java.util.Calendar.getInstance();
// a hack as the iCal4J Period objects don't support null end date or infinite end date.
java.util.Calendar rangeEndDate = java.util.Calendar.getInstance();
rangeEndDate.setTime(date);
rangeEndDate.add(java.util.Calendar.YEAR, 100);
Period period = new Period(new DateTime(date), new DateTime(rangeEndDate.getTime()));
return generateOccurrencesOf(events, occuringIn(period));
endDate.add(java.util.Calendar.YEAR, 100);
return generateOccurrencesInRange(date, new Date(endDate.getTime()), events);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,45 @@ public void generateOccurrencesFromAGivenDateWithPeriodicAndNonPeriodicEvents()
List<EventOccurrence> occurrences = generator.generateOccurrencesFrom(aDate(), events);
assertThat(occurrences.size(), is(11));
}

@Test
public void generateOccurrencesInRangeWithNoEvents() throws Exception {
List<EventDetail> events = new ArrayList<EventDetail>();
List<EventOccurrence> occurrences = generator.generateOccurrencesInRange(startDate(), endDate(), events);
assertThat(occurrences.isEmpty(), is(true));
}

@Test
public void generateOccurrencesInRangeWithNonPeriodicEvents() throws Exception {
List<EventDetail> events = new ArrayList<EventDetail>();
events.add(anEventDetailOfId(NON_PERIODIC_EVENTS[0]).build()); // it has no occurrences from the given date
events.add(anEventDetailOfId(NON_PERIODIC_EVENTS[1]).build());
List<EventOccurrence> occurrences = generator.generateOccurrencesInRange(startDate(), endDate(), events);
assertThat(occurrences.size(), is(1));
assertThat(occurrences.get(0), is(anOccurrenceOfEvent(NON_PERIODIC_EVENTS[1],
startingAt("2011-04-15"),
endingAt("2011-04-15"))));
}

@Test
public void generateOccurrencesInRangeWithPeriodicEvents() throws Exception {
List<EventDetail> events = new ArrayList<EventDetail>();
events.add(anEventDetailOfId(PERIODIC_EVENTS[0]).build()); // it has 5 occurrences from the given date
events.add(anEventDetailOfId(PERIODIC_EVENTS[1]).build()); // it has 5 occurrences from the given date
List<EventOccurrence> occurrences = generator.generateOccurrencesInRange(startDate(), endDate(), events);
assertThat(occurrences.size(), is(10));
}

@Test
public void generateOccurrencesInRangeWithPeriodicAndNonPeriodicEvents() throws Exception {
List<EventDetail> events = new ArrayList<EventDetail>();
events.add(anEventDetailOfId(PERIODIC_EVENTS[0]).build()); // it has 5 occurrences from the given date
events.add(anEventDetailOfId(NON_PERIODIC_EVENTS[0]).build()); // it has no occurrences from the given date
events.add(anEventDetailOfId(PERIODIC_EVENTS[1]).build()); // it has 5 occurrences from the given date
events.add(anEventDetailOfId(NON_PERIODIC_EVENTS[1]).build());
List<EventOccurrence> occurrences = generator.generateOccurrencesInRange(startDate(), endDate(), events);
assertThat(occurrences.size(), is(11));
}

private Calendar aPeriod() {
Calendar date = Calendar.getInstance();
Expand All @@ -264,4 +303,15 @@ private Calendar aPeriod() {
private Date aDate() {
return new Date(dateToUseInTests());
}

private Date startDate() {
return aDate();
}

private Date endDate() {
Calendar endDate = Calendar.getInstance();
endDate.setTime(aDate());
endDate.add(Calendar.MONTH, 3);
return new Date(endDate.getTime());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ almanachColor2 = #0b4d3e
almanachColor3 = #647aa6
# Kaki
almanachColor4 = #8a8256
# Bleu cr�puscule
# Bleu cr\u00e9puscule
almanachColor5 = #004a82
# Gris-Noir
almanachColor6 = #404040
# Rouge fonc
# Rouge fonc\u00e9
almanachColor7 = #a41212
# Vert
almanachColor8 = #2c630b
Expand All @@ -55,3 +55,5 @@ almanachColor19 = grey
almanachColor20 = pink

almanach.timezone = Europe/Paris

almanach.nextEvents.windowtime=0
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@
$.each(monthsHavingEvents, function(index, monthWithEvents) {
$("<a>").attr("href", "#").html(monthWithEvents).click(function() {
selectMonth($(this), monthWithEvents);
}).appendTo(monthNavSection);
}).appendTo(monthNavSection.append(" "));
})
</c:if>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
background-color:#EAEAEA;
padding: 5px;
width:99%;
height:24px;
min-height:24px;
position:relative;
}

Expand Down Expand Up @@ -68,6 +68,12 @@
right:2px;
}

.eventsView #others {
position:relative;
float:right;
margin-bottom: 5px;
}

#currentScope {
width: auto;
text-align: center;
Expand Down Expand Up @@ -395,4 +401,8 @@ div.eventBeginDate {
border:inherit;
padding:inherit;
margin:inherit;
}
}

.sousNavBulle a {
white-space: nowrap;
}