return originIds;
}
private StructureStylesheetUserPreferences _getStructureStylesheetUserPreferences (IPerson person, int profileId, int stylesheetId) throws Exception {
int userId = person.getID();
StructureStylesheetUserPreferences ssup;
// get stylesheet description
StructureStylesheetDescription ssd = getStructureStylesheetDescription(stylesheetId);
Connection con = RDBMServices.getConnection();
try {
int origId;
int origProfileId;
String sQuery = "SELECT USER_DFLT_USR_ID FROM UP_USER WHERE USER_ID = ?";
final PreparedStatement pstmt1 = con.prepareStatement(sQuery);
try {
// now look to see if this user has a layout or not. This is
// important because preference values are stored by layout
// element and if the user doesn't have a layout yet then the
// default user's preferences need to be loaded.
int layoutId = this.getLayoutID(userId, profileId);
// if no layout then get the default user id for this user
origId = userId;
origProfileId = profileId;
if (layoutId == 0) {
pstmt1.setInt(1,userId);
if (LOG.isDebugEnabled())
LOG.debug(sQuery + " VALUE " + 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
ssup = new StructureStylesheetUserPreferences();
ssup.setStylesheetId(stylesheetId);
// fill stylesheet description with defaults
for (Enumeration e = ssd.getStylesheetParameterNames(); e.hasMoreElements();) {
String pName = (String)e.nextElement();
ssup.putParameterValue(pName, ssd.getStylesheetParameterDefaultValue(pName));
}
for (Enumeration e = ssd.getChannelAttributeNames(); e.hasMoreElements();) {
String pName = (String)e.nextElement();
ssup.addChannelAttribute(pName, ssd.getChannelAttributeDefaultValue(pName));
}
for (Enumeration e = ssd.getFolderAttributeNames(); e.hasMoreElements();) {
String pName = (String)e.nextElement();
ssup.addFolderAttribute(pName, ssd.getFolderAttributeDefaultValue(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 pstmtQuery =
"SELECT PARAM_NAME, PARAM_VAL " +
"FROM UP_SS_USER_PARM " +
"WHERE USER_ID=?" +
" AND PROFILE_ID=?"+
" AND SS_ID=?" +
" AND SS_TYPE=1";
final PreparedStatement pstmt2 = con.prepareStatement(pstmtQuery);
try {
pstmt2.setInt(1, userId);
pstmt2.setInt(2,profileId);
pstmt2.setInt(3,stylesheetId);
final ResultSet rs1 = pstmt2.executeQuery();
try {
while (rs1.next()) {
String pName = rs1.getString(1);
if (ssd.containsParameterName(pName))
ssup.putParameterValue(pName, rs1.getString(2));
}
}
finally {
close(rs1);
}
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 (ssd.containsParameterName(pName))
ssup.putParameterValue(pName, rs2.getString(2));
}
}
finally {
close(rs2);
}
}
}
finally {
close(pstmt2);
}
Map<Integer, String> originIds = getOriginIds(con, userId, profileId, 1, stylesheetId);
/*
* now go get the overridden values and compare them against the
* map for their origin ids.
*/
sQuery = "SELECT PARAM_NAME, PARAM_VAL, PARAM_TYPE," +
" ULS.STRUCT_ID, CHAN_ID " +
"FROM UP_LAYOUT_STRUCT ULS, " +
" UP_SS_USER_ATTS UUSA " +
"WHERE UUSA.USER_ID=?"+
" AND PROFILE_ID=?" +
" AND SS_ID=?" +
" AND SS_TYPE=1" +
" AND UUSA.STRUCT_ID = ULS.STRUCT_ID" +
" AND UUSA.USER_ID = ULS.USER_ID";
if (LOG.isDebugEnabled())
LOG.debug(sQuery + "VALUES ");
final PreparedStatement pstmt4 = con.prepareStatement(sQuery);
try {
pstmt4.setInt(1,userId);
pstmt4.setInt(2,profileId);
pstmt4.setInt(3,stylesheetId);
final ResultSet rs = pstmt4.executeQuery();
try {
while (rs.next()) {
// get the LONG column first so Oracle doesn't toss a
// java.sql.SQLException: Stream has already been closed
String param_val = rs.getString(2);
int structId = rs.getInt(4);
String originId = null;
if (originIds != null)
originId = originIds.get(new Integer(structId));
int param_type = rs.getInt(3);
if (rs.wasNull()) {
structId = 0;
}
String pName = rs.getString(1);
int chanId = rs.getInt(5);
if (rs.wasNull()) {
chanId = 0;
}
/*
* ignore unexpected param_types since persisting
* removes all entries in table and it will get resolved
* without a log entry to point out the error.
*/
if (param_type == 2) {
// folder attribute
String folderStructId = null;
if ( originId != null )
folderStructId = originId;
else
folderStructId = getStructId(structId,chanId);
if (ssd.containsFolderAttribute(pName))
ssup.setFolderAttributeValue(folderStructId, pName, param_val);
}
else if (param_type == 3) {
// channel attribute
String channelStructId = null;
if ( originId != null )
channelStructId = originId;
else
channelStructId = getStructId(structId,chanId);
if (ssd.containsChannelAttribute(pName))
ssup.setChannelAttributeValue(channelStructId, pName, param_val);
}
}
} finally {
close(rs);
}