private ThemeStylesheetUserPreferences _getThemeStylesheetUserPreferences(
IPerson person, int profileId, int stylesheetId) throws Exception
{
int userId = person.getID();
ThemeStylesheetUserPreferences tsup;
Connection con = RDBMServices.getConnection();
try
{
// get stylesheet description
ThemeStylesheetDescription tsd = getThemeStylesheetDescription(stylesheetId);
// get user defined defaults
int layoutId = this.getLayoutID(userId, profileId);
// if no layout then get the default user id for this user
int origId = userId;
int origProfileId = profileId;
if (layoutId == 0)
{ // First time, grab the default layout for this user
String sQuery = "SELECT USER_DFLT_USR_ID FROM UP_USER WHERE USER_ID=?";
if (log.isDebugEnabled())
log.debug(sQuery + " VALUE = " + userId);
final PreparedStatement pstmt1 = con.prepareStatement(sQuery);
try {
pstmt1.setInt(1,userId);
final ResultSet rs = pstmt1.executeQuery();
try
{
rs.next();
userId = rs.getInt(1);
// get the profile ID for the default user
UserProfile profile = getUserProfileById(person, profileId);
IPerson defaultProfilePerson = new PersonImpl();
defaultProfilePerson.setID(userId);
profileId = getUserProfileByFname(defaultProfilePerson, profile.getProfileFname()).getProfileId();
} finally
{
close(rs);
}
}
finally {
close(pstmt1);
}
}
// create the stylesheet user prefs object then fill
// it with defaults from the stylesheet definition object
tsup = new ThemeStylesheetUserPreferences();
tsup.setStylesheetId(stylesheetId);
// fill stylesheet description with defaults
for (Enumeration e = tsd.getStylesheetParameterNames(); e
.hasMoreElements();)
{
String pName = (String) e.nextElement();
tsup.putParameterValue(pName, tsd
.getStylesheetParameterDefaultValue(pName));
}
for (Enumeration e = tsd.getChannelAttributeNames(); e
.hasMoreElements();)
{
String pName = (String) e.nextElement();
tsup.addChannelAttribute(pName, tsd
.getChannelAttributeDefaultValue(pName));
}
// Now load in the stylesheet parameter preferences
// from the up_ss_user_param but only if they are defined
// parameters in the stylesheet's .sdf file.
//
// First, get the parameters for the effective user ID,
// then for the original user ID. These will differ if
// the user has no layout in the database and is using
// the default user layout. The params from the original
// user ID take precedence.
String sQuery2 =
"SELECT PARAM_NAME, PARAM_VAL " +
"FROM UP_SS_USER_PARM " +
"WHERE USER_ID=?" +
" AND PROFILE_ID=?" +
" AND SS_ID=?" +
" AND SS_TYPE=2";
if (log.isDebugEnabled())
log.debug(sQuery2 + " VALUES " + userId + "," + profileId + "," + stylesheetId);
final PreparedStatement pstmt2 = con.prepareStatement(sQuery2);
try
{
pstmt2.setInt(1, userId);
pstmt2.setInt(2,profileId);
pstmt2.setInt(3,stylesheetId);
final ResultSet rs = pstmt2.executeQuery();
try {
while (rs.next())
{
// stylesheet param
String pName = rs.getString(1);
if (tsd.containsParameterName(pName))
tsup.putParameterValue(pName, rs.getString(2));
}
}
finally {
close(rs);
}
if (userId != origId) {
pstmt2.setInt(1, origId);
pstmt2.setInt(2, origProfileId);
final ResultSet rs2 = pstmt2.executeQuery();
try {
while (rs2.next()) {
String pName = rs2.getString(1);
if (tsd.containsParameterName(pName))
tsup.putParameterValue(pName, rs2.getString(2));
}
}
finally {
close(rs2);
}
}
} finally
{
close(pstmt2);
}
Map<Integer, String> originIds = getOriginIds(con, userId, profileId, 2, stylesheetId);
// Now load in the channel attributes preferences from the
// up_ss_user_atts table
final String sQuery3 = "SELECT PARAM_TYPE, PARAM_NAME, PARAM_VAL, " +
"ULS.STRUCT_ID, CHAN_ID " +
"FROM UP_SS_USER_ATTS UUSA, UP_LAYOUT_STRUCT ULS " +
"WHERE UUSA.USER_ID=?" +
" AND PROFILE_ID=?" +
" AND SS_ID=?" +
" AND SS_TYPE=2" +
" AND UUSA.STRUCT_ID = ULS.STRUCT_ID" +
" AND UUSA.USER_ID = ULS.USER_ID";
if (log.isDebugEnabled())
log.debug("SQL to load theme channel attribute prefs: "
+ sQuery3 + " VALUES " + userId + "," + profileId + "," + stylesheetId);
final PreparedStatement pstmt3 = con.prepareStatement(sQuery3);
try {
pstmt3.setInt(1,userId);
pstmt3.setInt(2,profileId);
pstmt3.setInt(3,stylesheetId);
final ResultSet rs = pstmt3.executeQuery();
try {
while (rs.next())
{
int param_type = rs.getInt(1);
if (rs.wasNull())
{
param_type = 0;
}
int structId = rs.getInt(4);
String originId = null;
if (originIds != null)
originId = originIds.get(new Integer(structId));
if (rs.wasNull())
{
structId = 0;
}
int chanId = rs.getInt(5);
if (rs.wasNull())
{
chanId = 0;
}
// only use channel attributes ignoring any others.
// we should never get any others in here unless there
// is db corruption and since all are flushed when
// writting back to the db it should be self correcting
// if it ever does occur somehow.
if (param_type == 3)
{
// channel attribute
String channelStructId = null;
if ( originId != null )
channelStructId = originId;
else
channelStructId = getStructId(structId,chanId);
tsup.setChannelAttributeValue(channelStructId, rs.getString(2), rs.getString(3));
}
}
} finally
{
close(rs);