Vector calactivityVector = null;
Vector unscheduledactivity = null;
Vector scheduledactivitydaily = null;
HashMap unsheduledMap = new HashMap();
HashMap scheduledMap = new HashMap();
TreeMap allDayMap = new TreeMap();
try {
CvCalendarHome cvCalendarHome = (CvCalendarHome)CVUtility.getHomeObject(
"com.centraview.calendar.CvCalendarHome", "CvCalendar");
CvCalendar cvCalendar = cvCalendarHome.create();
cvCalendar.setDataSource(dataSource);
HashMap cvCalendarMap = cvCalendar.getAllCalendar(userID, userID, starttimeuser, endTimeuser,
search);
calactivityVector = (Vector)cvCalendarMap.get("scheduleactivityvector");
unscheduledactivity = (Vector)cvCalendarMap.get("unscheduleactivityvector");
scheduledactivitydaily = (Vector)cvCalendarMap.get("scheduleactivityvectordaily");
} catch (Exception e) {
logger.error("[Exception][CalendarValueList.getCalendarList] Exception Thrown: ", e);
}
CalendarList calendarlist = new CalendarList();
int totalnumberofrows = 0;
long timeInMillisStart = starttimeuser.getTimeInMillis();
long timeInMillisEnd = endTimeuser.getTimeInMillis();
// We must have to do the ZoneOffSet and DayLight Saving to Offset.
// off zone time values we must have to add to TimeInMillis
double differenceTimeInMills = ((timeInMillisEnd + endTimeuser.get(Calendar.ZONE_OFFSET) + endTimeuser
.get(Calendar.DST_OFFSET)) - (timeInMillisStart + starttimeuser.get(Calendar.ZONE_OFFSET) + starttimeuser
.get(Calendar.DST_OFFSET)));
// noOfDiff is the number of timespan (in minutes) length blocks
// that make up the entire endtime-starttime.
// daily view will be one of: 1440/60 = 24, 1440/30 = 48, 1440/15 = 96
// weekly (columnar) will be: 10080/60 = 168 (24 rows * 7columns)
// weekly (non-columnar) will be: 10080/1440 = 7 (7 days)
// monthly will be between: 40320/1440 = 28 and 44640/1440 = 31
// 1440 is the number of minutes in one day. (24*60 = 1440)
// actually it appears that timespan is minutes per HTML block.
// 60000 is used for getting the number of milliseconds per minute out of
// there.
// so you can simply divide minutes per block into the time difference.
double noOfDiff = Math.ceil(differenceTimeInMills / (timespan * 60000));
// The Math.ceil function is unecessary and probably just a holdover from
// when the
// original authors couldn't figure out how to use the Gregorian calendar
// and thus
// often found themselves with numbers that didn't come out even.
totalnumberofrows = (int)noOfDiff;
// The following loop goes through and for each row, inserts
// a blank CalendarListElement
// Not sure what this accomplishes.
long start = 0, end = 0;
// TDColumn simply is used to represent how many elements in a row
// on the displayed table. It is really only useful in one of the daily
// views.
TreeMap TDColumn = calendarlist.getTDIndicesTreeMap();
for (int i = 0; i < totalnumberofrows; i++) {
// Fill it up with a bunch-a-blank'uns.
start = timeInMillisStart + ((i) * timespan * 60000);
end = timeInMillisStart + ((i + 1) * timespan * 60000);
calendarlist.put(new Integer(i), new CalendarListElement(start, end));
// pre-populate the row to contain zero items.
TDColumn.put(new Integer(i), new Integer(0));
}
GregorianCalendar listRenderCalendar = new GregorianCalendar(tz);
listRenderCalendar.setTime(starttimeuser.getTime());
int counthour = 0;
for (int i = 0; i < totalnumberofrows; i++) {
// The Calendar fields will be used to track the current place in
// the displayed calendar, we will increment through the blocks
// and compare the activites returned from the list.
int calendarDate = listRenderCalendar.get(Calendar.DATE);
int calendarMonth = listRenderCalendar.get(Calendar.MONTH);
int calendarYear = listRenderCalendar.get(Calendar.YEAR);
Iterator activityIterator = calactivityVector.iterator();
int uniqueId = 0;
while (activityIterator.hasNext()) {
uniqueId++;
CalendarActivityObject activityobject = (CalendarActivityObject)activityIterator.next();
GregorianCalendar starttime = activityobject.getStartTime();
GregorianCalendar endtime = activityobject.getEndTime();
// If somehow we squeezed an illegally formed activity in we should skip
// it.
if ((starttime.getTimeInMillis() > endTimeuser.getTimeInMillis())) {
continue;
}
// calendarStartingBlock is the starting block for an activity on the
// displayed table.
int calendarStartingBlock = 0;
// The critical info on the currently selected activity.
int activityDate = starttime.get(Calendar.DATE);
int activityMonth = starttime.get(Calendar.MONTH);
int activityYear = starttime.get(Calendar.YEAR);
int activityHour = starttime.get(Calendar.HOUR);
int activityMinute = starttime.get(Calendar.MINUTE);
int activityAMPM = starttime.get(Calendar.AM_PM);
if (activityAMPM == 1) {
activityHour = activityHour + 12;
}
boolean flag = false;
// If the selected activity has the same month, date, and year
// and we are looking at the Daily View.
if (activityDate == calendarDate && activityMonth == calendarMonth
&& activityYear == calendarYear
&& (totalnumberofrows == 24 || totalnumberofrows == 48 || totalnumberofrows == 96)) {
// if it is daily hourly blocks then the starting block is the
// starting hour
calendarStartingBlock = (activityHour);
// otherwise we need calculate the starting block because the number
// of blocks may
// have doubled or quadrupled (30 or 15 minute intervals)
// It needs to be the floor function of the division also.
if (totalnumberofrows == 48) {
int diffMinute = (int)Math.floor(activityMinute / 30.0);
calendarStartingBlock = (calendarStartingBlock * 2) + diffMinute;
} else if (totalnumberofrows == 96) {
int diffMinute = (int)Math.floor(activityMinute / 15.0);
calendarStartingBlock = (calendarStartingBlock * 4) + diffMinute;
}
flag = true;
} else if (activityDate == calendarDate && activityMonth == calendarMonth
&& activityYear == calendarYear) {
// it is still the same, but we are not one of the daily views.
flag = true; // no setup required for numberof rows = 28 through 31
// ??
calendarStartingBlock = (activityDate - 1);
if (totalnumberofrows == 168) // if weekly columnar
{
calendarStartingBlock = starttime.get(Calendar.DAY_OF_WEEK);
if (calendarStartingBlock == Calendar.SUNDAY) // if SUNDAY
{
calendarStartingBlock = 6; // then move to the end.
} else {
// else normalize monday to be zero (coupled to UI) // normalize
calendarStartingBlock = calendarStartingBlock - Calendar.MONDAY;
}
calendarStartingBlock = (calendarStartingBlock * 24) + (activityHour);
// Display as an allday activity on top
if (activityobject.getAllDayEvent()) {
activityobject.setAllDayTime();
flag = false;
allDayMap.put(activityobject.getActivityID(), activityobject);
}
}
if (totalnumberofrows == 7) {
// if weekly non-columnar
calendarStartingBlock = starttime.get(GregorianCalendar.DAY_OF_WEEK);
if (calendarStartingBlock == Calendar.SUNDAY) // if SUNDAY
{
calendarStartingBlock = 6; // then move to the end.
} else {
// else normalize monday to be zero (coupled to UI) // normalize
calendarStartingBlock = calendarStartingBlock - Calendar.MONDAY;
}
}
}
if (flag) // It matches one of our calendar blocks, we need to display
// it
{
// Get the blank element we stuck in there before as a placeholder
CalendarListElement element = (CalendarListElement)calendarlist.get(new Integer(
calendarStartingBlock));
// monthly will only use the element at 0 on calendarlist (I guess the
// rest is designed for that)
if (element != null) // if the element is null then our
// calendarStartingBlock is totally out of
// whack.
{
int numberOfRows = 1; // assume it only takes one row
// We probably should take account if the activity spans to a
// different day.
// right now this doesn't seem to accomodate that.
int activityEndHour = endtime.get(Calendar.HOUR);
int activityEndAMPM = endtime.get(Calendar.AM_PM);
if (activityEndAMPM == 1) {
activityEndHour = activityEndHour + 12;
}
// calculate the number of rows the activity spans, if it is one of
// the daily views
// use ceiling function, so that any activity that impinges on the
// above activity
// will fill that row also.
if (totalnumberofrows == 24 || totalnumberofrows == 48 || totalnumberofrows == 96) {
// We must have to do the ZoneOffSet and DayLight Saving to
// Offset.
// off zone time values we must have to add to TimeInMillis
long startTimeValue = starttime.getTimeInMillis()
+ starttime.get(Calendar.ZONE_OFFSET) + starttime.get(Calendar.DST_OFFSET);
long endTimeValue = endtime.getTimeInMillis() + endtime.get(Calendar.ZONE_OFFSET)
+ endtime.get(Calendar.DST_OFFSET);
double activityDuration = endTimeValue - startTimeValue;
numberOfRows = (int)Math.ceil(activityDuration / (timespan * 60000));
// When we have Scheduling and activity for two whole day event
// then our numberOfRows Calculation will return us "48"
// We can show only 24 hours in the Daily view. so reseting it
// back to 24.
if (totalnumberofrows == 24) {
if (numberOfRows >= 24) {
numberOfRows = 24;
}
} // end if (totalnumberofrows == 24)
} // end if (totalnumberofrows == 24 || totalnumberofrows == 48 ||
// totalnumberofrows == 96)
if (activityobject.getAllDayEvent()) {
activityobject.setAllDayTime();
}
CalendarMember calendarItem = new CalendarMember(activityobject, 0, numberOfRows);
// activity is the key to the element HashMap, it must be unique
// between returned
// activities, other wise activities with same start time and name
// will only show
// up once on a calendar. So we are using the activityId which must
// be unique.
Integer activity = new Integer(uniqueId);
// at a minimum now this element which exists at the
// starting row (calendarStartingBlock)
// has two values, the blank one we prepopulated before.
// And the one we are adding now
element.put(activity, calendarItem);
// we need to increment the rowItem counter for each row that this
// activity inpinges
// on. So if the nuOfrows at least 1, then we need to iterate
// through
// and increment the counter for it.
if (numberOfRows >= 1) {
for (int row = calendarStartingBlock; row < (calendarStartingBlock + numberOfRows); row++) {
Integer rowInteger = new Integer(row);
if (TDColumn.get(rowInteger) != null) {
int totalRowItems = ((Integer)TDColumn.get(rowInteger)).intValue();
totalRowItems++;
TDColumn.put(rowInteger, new Integer(totalRowItems));
}
}
}
} // end if (element != null)
activityIterator.remove();