populateForm.resetForm(request, form);
ActivityForm activityForm = (ActivityForm)form;
// set up the date formatter default to the request locale.
Locale locale = request.getLocale();
activityForm.setLocale(locale);
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
DateFormat tf = DateFormat.getTimeInstance(DateFormat.SHORT, locale);
int activityType = 1;
String unScheduleActivity = "";
if (request.getParameter("unScheduleActivity") != null) {
unScheduleActivity = request.getParameter("unScheduleActivity").toString();
}
UserObject userObject = (UserObject)session.getAttribute("userobject");
int individualID = userObject.getIndividualID();
String userName = userObject.getfirstName() + " " + userObject.getlastName();
if (request.getParameter("entityID") != null) {
activityForm.setActivityEntityID(request.getParameter("entityID"));
}
if (request.getParameter("entityName") != null) {
activityForm.setActivityEntityName(request.getParameter("entityName"));
}
if (request.getParameter("individualID") != null) {
activityForm.setActivityIndividualID(request.getParameter("individualID"));
}
if (request.getParameter("individualName") != null) {
activityForm.setActivityIndividualName(request.getParameter("individualName"));
}
if (request.getParameter("ProjectID") != null && request.getParameter("ProjectTitle") != null) {
String projectID = request.getParameter("ProjectID");
String projectTitle = request.getParameter("ProjectTitle");
activityForm.setActivityRelatedFieldID(projectID);
activityForm.setActivityRelatedFieldValue(projectTitle);
activityForm.setActivityRelatedTypeValue("Project");
activityForm.setActivityRelatedTypeID("36");
}
if (request.getParameter("oppID") != null) {
String opportunityID = request.getParameter("oppID");
activityForm.setActivityRelatedFieldID(opportunityID);
activityForm.setActivityRelatedTypeValue("Opportunity");
activityForm.setActivityRelatedTypeID("30");
if (opportunityID != null && !(opportunityID.equals(""))) {
int oppID = Integer.parseInt(opportunityID);
SaleFacadeHome saleFacade = (SaleFacadeHome)CVUtility.getHomeObject(
"com.centraview.sale.salefacade.SaleFacadeHome", "SaleFacade");
SaleFacade remote = saleFacade.create();
remote.setDataSource(dataSource);
HashMap relatedOpportunityInfo = remote.getOpportunityRelatedInfo(individualID, oppID);
if (relatedOpportunityInfo != null && relatedOpportunityInfo.size() != 0) {
String title = (String)relatedOpportunityInfo.get("Title");
if (title != null && !title.equals("") && !title.equals("NULL")) {
activityForm.setActivityRelatedFieldValue(title);
}
if (relatedOpportunityInfo.get("EntityId") != null) {
int entityid = ((Number)relatedOpportunityInfo.get("EntityId")).intValue();
if (entityid != 0) {
activityForm.setActivityEntityID(entityid + "");
String entityName = (String)relatedOpportunityInfo.get("EntityName");
if (entityName != null && !entityName.equals("") && !entityName.equals("NULL")) {
activityForm.setActivityEntityName(entityName);
}
}
}
if (relatedOpportunityInfo.get("IndividualId") != null) {
int individualid = ((Number)relatedOpportunityInfo.get("IndividualId")).intValue();
if (individualid != 0) {
activityForm.setActivityIndividualID(individualid + "");
String individualName = (String)relatedOpportunityInfo.get("individualname");
if (individualName != null && !individualName.equals("")
&& !individualName.equals("NULL")) {
activityForm.setActivityIndividualName(individualName);
}
}
}
} // end if (relatedOpportunityInfo != null &&
// relatedOpportunityInfo.size() != 0)
} // end if (opportunityID != null && !(opportunityID.equals("")))
} // end if (request.getParameter("oppID") != null)
if (request.getParameter("oppName") != null) {
activityForm.setActivityRelatedFieldValue(request.getParameter("oppName"));
}
activityForm.setActivityOwnerID(String.valueOf(individualID));
activityForm.setActivityOwnerName(userName);
activityForm.setActivityPriority("2");
activityForm.setActivityVisibility("PUBLIC");
// All the following mess is to set a start and end time on the form.
if ((request.getParameter("DAY") != null) && (request.getParameter("MONTH") != null)
&& (request.getParameter("YEAR") != null)) {
// to digit
String startMonthName = request.getParameter("MONTH");
int startMonth = getCalendarMonth(startMonthName);
String startDayString = request.getParameter("DAY");
int startDay = Integer.parseInt(startDayString);
String startYearString = request.getParameter("YEAR");
int startYear = Integer.parseInt(startYearString);
Calendar start = new GregorianCalendar(startYear, startMonth, startDay, 8, 0);
String startTimeString = tf.format(start.getTime());
if (CVUtility.notEmpty(request.getParameter("STIME"))) {
startTimeString = request.getParameter("STIME");
}
Calendar passedTime = new GregorianCalendar();
passedTime.setTime(tf.parse(startTimeString));
start.set(Calendar.HOUR, passedTime.get(Calendar.HOUR));
start.set(Calendar.MINUTE, passedTime.get(Calendar.MINUTE));
start.set(Calendar.AM_PM, passedTime.get(Calendar.AM_PM));
activityForm.setActivityStartDate(df.format(start.getTime()));
activityForm.setActivityStartTime(tf.format(start.getTime()));
// add an hour onto the start time for the default end time.
Calendar end = new GregorianCalendar();
end.setTime(start.getTime());
end.add(Calendar.HOUR, 1);
String endTimeString = tf.format(end.getTime());
if (CVUtility.notEmpty(request.getParameter("ETIME"))) {
endTimeString = request.getParameter("ETIME");
}
passedTime.setTime(tf.parse(endTimeString));
end.set(Calendar.HOUR, passedTime.get(Calendar.HOUR));
end.set(Calendar.MINUTE, passedTime.get(Calendar.MINUTE));
end.set(Calendar.AM_PM, passedTime.get(Calendar.AM_PM));
activityForm.setActivityEndDate(df.format(end.getTime()));
activityForm.setActivityEndTime(tf.format(end.getTime()));
} else if (unScheduleActivity != null && !(unScheduleActivity.equals("unSchedule"))) {
// In the case the start time wasn't requested from the parent window,
// set the start time to now() rounded up to the nearest hour, and the
// end time to be the start time plus 1 hour.
UserPrefererences userPref = userObject.getUserPref();
String userTimeZoneId = userPref.getTimeZone();
TimeZone userTimeZone = TimeZone.getTimeZone(userTimeZoneId);
Calendar now = Calendar.getInstance(userTimeZone, locale);
// round up the hour if we are at the 1 minute mark of the hour or
// higher. just clear the second and millisecond fields, its only
// scheduling not physics.
now.clear(Calendar.SECOND);
now.clear(Calendar.MILLISECOND);
if (now.get(Calendar.MINUTE) > 0) {
now.clear(Calendar.MINUTE);
now.add(Calendar.HOUR, 1);
}
activityForm.setActivityStartDate(df.format(now.getTime()));
activityForm.setActivityStartTime(tf.format(now.getTime()));
// Increment now by 1 hour to get the end time.
now.add(Calendar.HOUR, 1);
activityForm.setActivityEndDate(df.format(now.getTime()));
activityForm.setActivityEndTime(tf.format(now.getTime()));
}
String typeOfActivity = "";
if (request.getParameter(ConstantKeys.TYPEOFACTIVITY) == null) {
typeOfActivity = ConstantKeys.APPOINTMENT;