stylesheetId ) );
}
public StructureStylesheetUserPreferences _getStructureStylesheetUserPreferences (IPerson person, int profileId, int stylesheetId) throws Exception {
int userId = person.getID();
StructureStylesheetUserPreferences ssup;
Connection con = RDBMServices.getConnection();
try {
Statement stmt = con.createStatement();
try {
// get stylesheet description
StructureStylesheetDescription ssd = getStructureStylesheetDescription(stylesheetId);
// 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.
String subSelectString = "SELECT LAYOUT_ID FROM UP_USER_PROFILE WHERE USER_ID=" + userId + " AND PROFILE_ID=" +
profileId;
if (LOG.isDebugEnabled())
LOG.debug("RDBMUserLayoutStore::getUserLayout()1 " + subSelectString);
int layoutId;
ResultSet rs = stmt.executeQuery(subSelectString);
try {
rs.next();
layoutId = rs.getInt(1);
if (rs.wasNull()) {
layoutId = 0;
}
} finally {
rs.close();
stmt.close();
}
// if no layout then get the default user id for this user
int origId = userId;
if (layoutId == 0) {
stmt = con.createStatement();
String sQuery = "SELECT USER_DFLT_USR_ID FROM UP_USER WHERE USER_ID=" + userId;
if (LOG.isDebugEnabled())
LOG.debug("RDBMUserLayoutStore::getUserLayout(): " + sQuery);
rs = stmt.executeQuery(sQuery);
try {
rs.next();
userId = rs.getInt(1);
} finally {
rs.close();
stmt.close();
}
}
// create the stylesheet user prefs object then fill
// 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.
//
// 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=" + profileId +
" AND SS_ID=" + stylesheetId +
" AND SS_TYPE=1";
PreparedStatement pstmt = con.prepareStatement(pstmtQuery);
try {
pstmt.setInt(1, userId);
rs = pstmt.executeQuery();
while (rs.next()) {
ssup.putParameterValue(rs.getString(1), rs.getString(2));
}
if (userId != origId) {
pstmt.setInt(1, origId);
rs = pstmt.executeQuery();
while (rs.next()) {
ssup.putParameterValue(rs.getString(1), rs.getString(2));
}
}
}
finally {
rs.close();
pstmt.close();
}
// now load in the folder and channel attributes from the
// up_ss_user_atts table pulling in dlm:origin from the
// up_layout_param table indicating these values are for an
// overriden value on an incorporated element.
/***** replaced by Anthony for supporting differing outerjoin
syntax for multiple databases. See below.
sQuery = "SELECT PARAM_NAME, PARAM_VAL, PARAM_TYPE, ULS.STRUCT_ID, CHAN_ID, ULP.STRUCT_PARM_NM, ULP.STRUCT_PARM_VAL FROM UP_SS_USER_ATTS UUSA, UP_LAYOUT_STRUCT ULS, UP_LAYOUT_PARAM ULP WHERE UUSA.USER_ID=" + userId + " AND PROFILE_ID="
+ profileId + " AND SS_ID=" + stylesheetId + " AND SS_TYPE=1 AND UUSA.STRUCT_ID = ULS.STRUCT_ID AND UUSA.USER_ID = ULS.USER_ID AND UUSA.STRUCT_ID = ULP.STRUCT_ID(+) AND UUSA.USER_ID = ULP.USER_ID(+)";
*****/
String sQuery = null;
IDatabaseMetadata db = RDBMServices.getDbMetaData();
if (db.supportsOuterJoins())
{
if (db.getJoinQuery()
instanceof DatabaseMetaDataImpl.JdbcDb)
{
if (LOG.isDebugEnabled())
LOG.debug("RDBMUserLayoutStore::getStructureStylesheetUserPreferences() : instanceof jdbcdb");
sQuery = "SELECT PARAM_NAME, PARAM_VAL, PARAM_TYPE, ULS.STRUCT_ID, CHAN_ID, ULP.STRUCT_PARM_NM, ULP.STRUCT_PARM_VAL FROM UP_LAYOUT_STRUCT ULS, UP_SS_USER_ATTS UUSA LEFT OUTER JOIN UP_LAYOUT_PARAM ULP ON UUSA.STRUCT_ID = ULP.STRUCT_ID AND UUSA.USER_ID=" + userId + " AND UUSA.USER_ID = ULP.USER_ID AND PROFILE_ID=" + profileId + " AND SS_ID=" + stylesheetId + " AND SS_TYPE=1 AND UUSA.STRUCT_ID = ULS.STRUCT_ID AND UUSA.USER_ID = ULS.USER_ID AND UUSA.USER_ID = ULP.USER_ID";
}
else if (db.getJoinQuery()
instanceof DatabaseMetaDataImpl.PostgreSQLDb)
{
if (LOG.isDebugEnabled())
LOG.debug("RDBMUserLayoutStore::getStructureStylesheetUserPreferences() : instanceof jpostgressqldbdbcdb");
sQuery = "SELECT PARAM_NAME, PARAM_VAL, PARAM_TYPE," +
" ULS.STRUCT_ID, CHAN_ID, ULP.STRUCT_PARM_NM," +
" ULP.STRUCT_PARM_VAL " +
"FROM UP_LAYOUT_STRUCT ULS, " +
" UP_SS_USER_ATTS UUSA LEFT OUTER JOIN" +
" UP_LAYOUT_PARAM ULP " +
"ON UUSA.STRUCT_ID = ULP.STRUCT_ID" +
" AND UUSA.USER_ID = ULP.USER_ID " +
"WHERE UUSA.USER_ID=" + userId +
" AND PROFILE_ID=" + profileId +
" AND SS_ID=" + stylesheetId +
" AND SS_TYPE=1" +
" AND UUSA.STRUCT_ID = ULS.STRUCT_ID" +
" AND UUSA.USER_ID = ULS.USER_ID";
}
else if (db.getJoinQuery()
instanceof DatabaseMetaDataImpl.OracleDb)
{
if (LOG.isDebugEnabled())
LOG.debug("RDBMUserLayoutStore::getStructureStylesheetUserPreferences() : instanceof oracledb");
sQuery = "SELECT /*+ USE_NL(UP_LAYOUT_STRUCT) */ PARAM_NAME, PARAM_VAL, PARAM_TYPE, ULS.STRUCT_ID, CHAN_ID, ULP.STRUCT_PARM_NM, ULP.STRUCT_PARM_VAL FROM UP_SS_USER_ATTS UUSA, UP_LAYOUT_STRUCT ULS, UP_LAYOUT_PARAM ULP WHERE UUSA.USER_ID=" + userId + " AND PROFILE_ID="
+ profileId + " AND SS_ID=" + stylesheetId + " AND SS_TYPE=1 AND UUSA.STRUCT_ID = ULS.STRUCT_ID AND UUSA.USER_ID = ULS.USER_ID AND UUSA.STRUCT_ID = ULP.STRUCT_ID(+) AND UUSA.USER_ID = ULP.USER_ID(+)";
} else
{
throw new Exception("Unknown database driver");
}
}
if (LOG.isDebugEnabled())
LOG.debug("RDBMUserLayoutStore::getStructureStylesheetUserPreferences(): " + sQuery);
stmt = con.createStatement();
rs = stmt.executeQuery(sQuery);
try {
while (rs.next()) {
int param_type = rs.getInt(3);
int structId = rs.getInt(4);
if (rs.wasNull()) {
structId = 0;
}
String ulp_parmName = rs.getString(6);
String originId = rs.getString(7);
int chanId = rs.getInt(5);
if (rs.wasNull()) {
chanId = 0;
}
if (param_type == 1) {
// stylesheet param
if (LOG.isDebugEnabled())
LOG.debug("RDBMUserLayoutStore::getStructureStylesheetUserPreferences() : stylesheet global params should be specified in the user defaults table ! UP_SS_USER_ATTS is corrupt. (userId="
+ Integer.toString(userId) + ", profileId=" + Integer.toString(profileId) + ", stylesheetId=" + Integer.toString(stylesheetId)
+ ", param_name=\"" + rs.getString(1) + "\", param_type=" + Integer.toString(param_type));
}
else if (param_type == 2) {
// folder attribute
String folderStructId = null;
if ( ulp_parmName != null &&
(ulp_parmName.equals( Constants.ATT_ORIGIN ) ||
ulp_parmName.equals( Constants.LEGACY_ATT_ORIGIN )))
folderStructId = originId;
else
folderStructId = getStructId(structId,chanId);
ssup.setFolderAttributeValue(folderStructId, rs.getString(1), rs.getString(2));
}
else if (param_type == 3) {
// channel attribute
String channelStructId = null;
if ( ulp_parmName != null &&
(ulp_parmName.equals( Constants.ATT_ORIGIN ) ||
ulp_parmName.equals( Constants.LEGACY_ATT_ORIGIN )))
channelStructId = originId;
else
channelStructId = getStructId(structId,chanId);
ssup.setChannelAttributeValue(channelStructId, rs.getString(1), rs.getString(2));
}
else {
// unknown param type
LOG.error("RDBMUserLayoutStore::getStructureStylesheetUserPreferences() : unknown param type encountered! DB corrupt. (userId="
+ Integer.toString(userId)