continue;
}
}
// If we made it this far then we can get the activity detail and populate the object.
GregorianCalendar activityRecordStart = new GregorianCalendar(TimeZone.getTimeZone("EST"));
if (activityRecord.get("Start") != null)
{
Timestamp activityStartDate = (Timestamp)activityRecord.get("Start");
activityRecordStart.setTimeInMillis(activityStartDate.getTime());
}
GregorianCalendar activityRecordEnd = new GregorianCalendar(TimeZone.getTimeZone("EST"));
if (activityRecord.get("End") != null)
{
Timestamp activityEndDate = (Timestamp)activityRecord.get("End");
activityRecordEnd.setTimeInMillis(activityEndDate.getTime());
}
int activityType = ((Number)activityRecord.get("Type")).intValue();
// its a Special Case for the Forcast Sales. We will not have the end date for it..
// we have to display as the whole day event, for that reason if we set the start as end date.
if(activityType == 3){
activityRecordEnd.set(GregorianCalendar.DAY_OF_MONTH,activityRecordStart.get(GregorianCalendar.DAY_OF_MONTH));
activityRecordEnd.set(GregorianCalendar.MONTH,activityRecordStart.get(GregorianCalendar.MONTH));
activityRecordEnd.set(GregorianCalendar.YEAR,activityRecordStart.get(GregorianCalendar.YEAR));
activityRecordEnd.set(GregorianCalendar.HOUR_OF_DAY,23);
}
// And what if they were null ... it means we have fubar data, and thats just the way it is.
// if this is a recurring record, do some stuff.
if ((activityRecord.get("startdate") != null))
{
RecurrenceVO recurrenceVO = new RecurrenceVO();
recurrenceVO.setRecurrenceId(((Long)activityRecord.get("RecurrenceID")).intValue());
recurrenceVO.setStartDate((Date)activityRecord.get("startdate"));
recurrenceVO.setUntil((Date)activityRecord.get("Until"));
recurrenceVO.setTimePeriod((String)activityRecord.get("TimePeriod"));
recurrenceVO.setOn(((Number)activityRecord.get("RecurrOn")).intValue());
recurrenceVO.setEvery(((Integer)activityRecord.get("Every")).intValue());
recurrenceVO.fillRecurrenceHashMap();
HashMap recurrenceRuleMap = recurrenceVO.getRecurrenceHM();
if (recurrenceRuleMap != null && recurrenceRuleMap.size() > 0)
{
Date recurrStartDate = (Date)activityRecord.get("startdate");
// For very long recurrences we only need to calculate out 18 months before of the
// passedStartDate otherwise we spend all our time calculating recurring tasks.
Calendar compareCalendar = (Calendar)passedStartDate.clone();
compareCalendar.add(Calendar.MONTH, -18);
Date compareDate = new Date(compareCalendar.getTimeInMillis());
if (recurrStartDate.before(compareDate))
{
recurrStartDate = compareDate;
}
GregorianCalendar recurringStartDate = new GregorianCalendar(TimeZone.getTimeZone("EST"));
if (recurrStartDate != null)
{
recurringStartDate.setTime(recurrStartDate);
recurringStartDate.set(Calendar.HOUR, activityRecordStart.get(Calendar.HOUR));
recurringStartDate.set(Calendar.MINUTE, activityRecordStart.get(Calendar.MINUTE));
recurringStartDate.set(Calendar.AM_PM, activityRecordStart.get(Calendar.AM_PM));
}
Date recurrEndDate = (Date)activityRecord.get("Until");
// if there is no end date (the recurrence is open ended)
// then coerce it to the passed in end date, for calculation purposes
// Also for very long recurrences we only need to calculate out 2 months ahead of the
// passedEndDate otherwise we spend all our time calculating recurring tasks.
compareCalendar = (Calendar)passedEndDate.clone();
compareCalendar.add(Calendar.MONTH, 2);
compareDate = new Date(compareCalendar.getTimeInMillis());
if (recurrEndDate == null || recurrEndDate.after(compareDate))
{
recurrEndDate = compareDate;
}
// get an RFC 2445 compliant recurrance rule string.
String rfcRuleString = recurrenceVO.getRecurrenceRule(recurrenceRuleMap);
// This object can take a rule string, a start and end date
// and supply a list of dates where the activity occurs.
long start = System.currentTimeMillis();
try{
RecurranceRuleRfc rfcRecurranceRule = new RecurranceRuleRfc(rfcRuleString, recurrStartDate, recurrEndDate);
List matchingDates = rfcRecurranceRule.getAllMatchingDates();
// Iterate the list and add new activity objects onto the list.
start = System.currentTimeMillis();
for (int i = 0; i < matchingDates.size(); i++)
{
java.util.Date matchingDate = (java.util.Date)matchingDates.get(i);
GregorianCalendar recurringInstanceStartDate = new GregorianCalendar(passedStartDate.getTimeZone());
// This is the start Calendar for this instance of the recurrance
recurringInstanceStartDate.setTime(matchingDate); // This will set the MONTH/DATE/YEAR
// Get the Time of Day from the activity Record
recurringInstanceStartDate.set(Calendar.HOUR, activityRecordStart.get(Calendar.HOUR));
recurringInstanceStartDate.set(Calendar.MINUTE, activityRecordStart.get(Calendar.MINUTE));
recurringInstanceStartDate.set(Calendar.AM_PM, activityRecordStart.get(Calendar.AM_PM));
// This is the End Calendar for this instance of the recurrance
GregorianCalendar recurringInstanceEndDate = new GregorianCalendar(passedEndDate.getTimeZone());
// The only real way to set the instance end time
// is to find out the duration of the activityRecord and set the
// end time of this instance to be offset from the start time of
// the same instance by the calculated duration.
long activityDuration = activityRecordEnd.getTimeInMillis() - activityRecordStart.getTimeInMillis();
recurringInstanceEndDate.setTimeInMillis(recurringInstanceStartDate.getTimeInMillis() + activityDuration);
CalendarActivityObject recurringInstanceObject = new CalendarActivityObject(recurringInstanceStartDate, recurringInstanceEndDate, activityId, (String)activityRecord.get("Title"), (String)activityRecord.get("ActivityName"), userId, individualId, "",false,null,null);
recurringInstanceObject.setActivityDetail((String)activityRecord.get("Details"));
// set visibility
recurringInstanceObject.setActivityVisibility((String)activityRecord.get("visibility"));
// set owner
recurringInstanceObject.setActivityOwnerId(((Number)activityRecord.get("Owner")).intValue());
ArrayList activityAttendeeInfo = remote.getActivityAttendee(activityId.intValue());
recurringInstanceObject.setActivityAttendee(activityAttendeeInfo);
//Find the Entity
HashMap activityLinkInfo = remote.getActivityLink(activityId.intValue());
String entityName = (String)activityLinkInfo.get("EntityName");
int entityID = -1;
try
{
Integer.parseInt((String)activityLinkInfo.get("EntityID"));
}catch(NumberFormatException nfe){
// "Don't stand so, don't stand so, close to me..."
}
//Set the Entity
recurringInstanceObject.setEntityName(entityName);
recurringInstanceObject.setEntityID(entityID);
retVec.add(recurringInstanceObject);
} // end for (int ctr = 0; ctr < results.size(); ctr++)
}catch (Exception e){
logger.debug("[Exception][CvCalendarEJB.fillReturnVector] Exception Thrown: " , e);
}
} // end if (mapRecurrence != null)
}else if (activityRecordStart.before(passedEndDate) && activityRecordEnd.after(passedStartDate)){
// else it is not a recurring type of activity.
// We will collect the number of days in the StartDate and EndDate ArrayList
// in between the Starting Time Activity and Ending Time of Activity.
GregorianCalendar tempStartTime = new GregorianCalendar(TimeZone.getTimeZone("EST"));
tempStartTime.setTimeInMillis(activityRecordStart.getTimeInMillis());
GregorianCalendar tempEndTime = new GregorianCalendar(TimeZone.getTimeZone("EST"));
ArrayList StartDate = new ArrayList();
ArrayList EndDate = new ArrayList();
StartDate.add(new Long(tempStartTime.getTimeInMillis()));
while (tempStartTime.before(activityRecordEnd))
{
tempEndTime.setTimeInMillis(tempStartTime.getTimeInMillis());
tempEndTime.set(GregorianCalendar.HOUR,11);
tempEndTime.set(GregorianCalendar.MINUTE,59);
tempEndTime.set(GregorianCalendar.SECOND,59);
tempEndTime.set(GregorianCalendar.AM_PM,GregorianCalendar.PM);
tempStartTime.add(GregorianCalendar.DAY_OF_MONTH,1);
tempStartTime.set(GregorianCalendar.HOUR,0);
tempStartTime.set(GregorianCalendar.MINUTE,0);
tempStartTime.set(GregorianCalendar.SECOND,0);
tempStartTime.set(GregorianCalendar.AM_PM,GregorianCalendar.AM);
if (! tempStartTime.before(activityRecordEnd))
{
break;
}else{
EndDate.add(new Long(tempEndTime.getTimeInMillis()));
StartDate.add(new Long(tempStartTime.getTimeInMillis()));
} // end of if(!tempStartTime.before(activityRecordEnd))
} // end of while (tempStartTime.before(activityRecordEnd))
tempEndTime.setTimeInMillis(activityRecordEnd.getTimeInMillis());
EndDate.add(new Long(tempEndTime.getTimeInMillis()));
for(int i = 0; i<StartDate.size();i++)
{
long startTimeInMills = ((Long) StartDate.get(i)).longValue();
long endTimeInMills = ((Long) EndDate.get(i)).longValue();
GregorianCalendar ActivityStart = new GregorianCalendar(TimeZone.getTimeZone("EST"));
ActivityStart.setTimeInMillis(startTimeInMills);
GregorianCalendar ActivityEnd = new GregorianCalendar(TimeZone.getTimeZone("EST"));
ActivityEnd.setTimeInMillis(endTimeInMills);
CalendarActivityObject cvo = null;
// Activity for only one day
if (StartDate.size() == 1)