* @param individualId
* @return
* @exception Exception
*/
public UserPrefererences getUserPreferences(int individualId) {
UserPrefererences up = new UserPrefererences();
CVDal cvdl = new CVDal(dataSource);
try {
cvdl.setSql("preference.getpreference");
cvdl.setInt(1, individualId);
Collection col = cvdl.executeQuery();
if (col == null) {
throw new Exception("User preference not found");
}
Iterator it = col.iterator();
while (it.hasNext()) {
HashMap hm = (HashMap) it.next();
String preferencename = (String) hm.get("preference_name");
if (preferencename != null) {
if (preferencename.equals("acknowledgeddays")) {
String strlng = (String) hm.get("preference_value");
up.setAcknowledgedDays(Integer.parseInt(strlng));
}
if (preferencename.equals("acknowledgedvisability")) {
up.setAcknowledgedVisibility((String) hm.get("preference_value"));
}
if (preferencename.equals("activitytype")) {
String stracttype = (String) hm.get("preference_value");
up.setActivityPortletAccountType(Integer.parseInt(stracttype));
}
if (preferencename.equals("emailvisability")) {
up.setEmailVisibility((String) hm.get("preference_value"));
}
if (preferencename.equals("opportunityvisible")) {
boolean isVisible = false;
if (((String) hm.get("preference_value")).equalsIgnoreCase("Yes")) {
isVisible = true;
}
up.setOpportunityVisible(isVisible);
}
if (preferencename.equals("taskvisible")) {
boolean isVisible = false;
if (((String) hm.get("preference_value")).equalsIgnoreCase("Yes")) {
isVisible = true;
}
up.setTaskVisible(isVisible);
}
if (preferencename.equals("supportvisible")) {
boolean isVisible = false;
if (((String) hm.get("preference_value")).equalsIgnoreCase("Yes")) {
isVisible = true;
}
up.setSupportVisible(isVisible);
}
if (preferencename.equals("emailaccountid")) {
String strepaid = (String) hm.get("preference_value");
try {
up.setEmailPortletAccountID(Integer.parseInt(strepaid));
} catch (NumberFormatException nfe) {
// "I get paid, to do the wild thing." -Tone Loc
}
}
if (preferencename.equals("calactivitytype")) {
String strlngObj = (String) hm.get("preference_value");
up.setCalenderPortletActivityType(Integer.parseInt(strlngObj));
}
if (preferencename.equals("newsdays")) {
String strnd = (String) hm.get("preference_value");
up.setNewPortletDays(Integer.parseInt(strnd));
}
if (individualId != 0) {
up.setIndividualID(individualId);
}
if (preferencename.equals("caldefaultview")) {
up.setCalendarDefaultView((String) hm.get("preference_value"));
}
if (preferencename.equals("calendarrefreshmin")) {
up.setCalendarRefreshMin((String) hm.get("preference_value"));
}
if (preferencename.equals("calendarrefreshsec")) {
up.setCalendarRefreshSec((String) hm.get("preference_value"));
}
if (preferencename.equals("email")) {
up.setEmail((String) hm.get("preference_value"));
}
if (preferencename.equals("todayscalendar")) {
up.setTodaysCalendar((String) hm.get("preference_value"));
}
if (preferencename.equals("unscheduledactivities")) {
up.setUnscheduledActivities((String) hm.get("preference_value"));
}
if (preferencename.equals("scheduledopportunities")) {
up.setScheduledOpportunities((String) hm.get("preference_value"));
}
if (preferencename.equals("projecttasks")) {
up.setProjectTasks((String) hm.get("preference_value"));
}
if (preferencename.equals("supporttickets")) {
up.setSupportTickets((String) hm.get("preference_value"));
}
if (preferencename.equals("companynews")) {
up.setCompanyNews((String) hm.get("preference_value"));
}
if (preferencename.equals("DEFAULTFOLDERID")) {
up.setDefaultFolderID(Integer.parseInt((String) hm.get("preference_value")));
}
if (preferencename.equals("TIMEZONE")) {
up.setTimeZone((String) hm.get("preference_value"));
}
if (preferencename.equals("DATEFORMAT")) {
up.setDateFormat((String) hm.get("preference_value"));
}
if (preferencename.equals("contenttype")) {
up.setContentType((String) hm.get("preference_value"));
}
if (preferencename.equals("allRecordsPublic")) {
up.setAllRecordsPublic((String) hm.get("preference_value"));
}
if (preferencename.equals("syncAsPrivate")) {
up.setSyncAsPrivate((String) hm.get("preference_value"));
}
if (preferencename.equals("emailCheckInterval")) {
// default to 10 if no valid value is found
int interval = 10;
try {
interval = Integer.parseInt((String) hm.get("preference_value"));
} catch (NumberFormatException nfe) { /* default already set */}
up.setEmailCheckInterval(interval);
}
if (preferencename.equals("homesettingrefreshmin")) {
up.setHomeRefreshMin((String) hm.get("preference_value"));
}
if (preferencename.equals("homesettingrefreshsec")) {
up.setHomeRefreshSec((String) hm.get("preference_value"));
}
if (preferencename.equals("showticketcharts")) {
boolean isVisible = false;
if (((String) hm.get("preference_value")).equalsIgnoreCase("Yes")) {
isVisible = true;
}
up.setShowTicketCharts(isVisible);
}
if (preferencename.equals("showsalescharts")) {
boolean isVisible = false;
if (((String) hm.get("preference_value")).equalsIgnoreCase("Yes")) {
isVisible = true;
}
up.setShowSalesCharts(isVisible);
}
} // end if (preferencename != null)
} // end while (it.hasNext())
// Get all the views.
ListPreference listPreference = null;
ListView listView = null;
// Step One: we will get all the Default Views for the Individual, who is
// logged in.
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("SELECT listviews.viewid, listviews.listtype, listviews.sorttype, listviews.sortmember AS sortelement, listviews.noofrecords AS recordsperpage, listviews.viewname, listviews.searchid FROM listviews, defaultviews WHERE listviews.listtype = defaultviews.listtype AND listviews.viewid = defaultviews.viewid");
Collection ownerViewCollection = cvdl.executeQuery();
Iterator ownerViewIterator = ownerViewCollection.iterator();
while (ownerViewIterator.hasNext()) {
HashMap ownerViewHM = (HashMap) ownerViewIterator.next();
String listType = (String) ownerViewHM.get("listtype");
int viewId = ((Number) ownerViewHM.get("viewid")).intValue();
listPreference = new ListPreference(listType);
// Step Two:
// We must get all the Views which exist for each ListType from the
// query for default views.
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("SELECT viewid, viewname, searchid FROM listviews WHERE listtype = ? and ownerid IS NULL UNION SELECT viewid, viewname, searchid FROM listviews WHERE listtype = ? and ownerid = ?");
cvdl.setString(1, listType);
cvdl.setString(2, listType);
cvdl.setInt(3, individualId);
Collection allViewCollection = cvdl.executeQuery();
Iterator allViewIterator = allViewCollection.iterator();
while (allViewIterator.hasNext()) {
HashMap allViewHM = (HashMap) allViewIterator.next();
int allViewId = ((Number) allViewHM.get("viewid")).intValue();
listView = new ListView(allViewId);
listView.setListType(listType);
listView.setViewName((String) allViewHM.get("viewname"));
listView.setViewID(allViewId);
listView.setSearchID(((Number) allViewHM.get("searchid")).intValue());
// Get all columns for the View. Which we are processing.
cvdl.setSqlQueryToNull();
cvdl.setSql("view.getownerallcolumn");
cvdl.setInt(1, allViewId);
cvdl.setString(2, listType);
Collection viewColumnCollection = cvdl.executeQuery();
Iterator viewColumnIterator = viewColumnCollection.iterator();
while (viewColumnIterator.hasNext()) {
HashMap viewColumnHM = (HashMap) viewColumnIterator.next();
listView.addColumnName((String) viewColumnHM.get("columnname"));
}// end of while (viewColumnIterator.hasNext())
listPreference.addListView(listView);
}// end of while (allViewIterator.hasNext())
listPreference.setDefaultView(viewId);
listPreference.setRecordsPerPage(((Long) ownerViewHM.get("recordsperpage")).intValue());
listPreference.setSortElement((String) ownerViewHM.get("sortelement"));
String sortType = (String) ownerViewHM.get("sorttype");
boolean sortTypeBoolean = true;
if (sortType.equals("A")) {
sortTypeBoolean = true;
} else {
sortTypeBoolean = false;
}
listPreference.setSortOrder(sortTypeBoolean);
up.addListPreferences(listPreference);
} // end of while (ownerViewIterator.hasNext())
} catch (Exception e) {
logger.error("[getUserPreferences] Exception thrown.", e);
} finally {
cvdl.destroy();