From c5e689483d9e36970a785970bf7c5a1d92770ca0 Mon Sep 17 00:00:00 2001 From: "Eric J. Bowersox" Date: Sun, 1 Jun 2003 10:10:54 +0000 Subject: [PATCH] added the functionality required to power the Sidebox Configure button on the Front Page --- conf/venice-db-init-mysql.sql | 7 +- .../venice/script/LibraryVeniceCast.java | 9 + .../venice/sidebox/SideboxDescriptor.java | 59 ++ .../venice/sidebox/SideboxManager.java | 48 ++ .../venice/sidebox/SideboxMessages.properties | 3 + .../venice/sidebox/SideboxOps.java | 17 + .../venice/sidebox/SideboxOps_mysql.java | 556 ++++++++++++++++++ .../venice/sidebox/SideboxService.java | 18 + venice-data/scripts/new_account_2.js | 7 +- venice-data/scripts/sidebox_config.js | 71 +++ venice-data/scripts/sidebox_config_add.js | 36 ++ venice-data/scripts/sidebox_config_del.js | 36 ++ venice-data/scripts/sidebox_config_move.js | 37 ++ venice-data/scripts/top.js | 4 +- venice-data/velocity/sidebox_config.vm | 109 ++++ venice-web/images/icn_down.gif | Bin 0 -> 90 bytes venice-web/images/icn_up.gif | Bin 0 -> 92 bytes venice-web/images/icn_x.gif | Bin 0 -> 96 bytes 18 files changed, 1012 insertions(+), 5 deletions(-) create mode 100644 src/venice-base/com/silverwrist/venice/sidebox/SideboxDescriptor.java create mode 100644 venice-data/scripts/sidebox_config.js create mode 100644 venice-data/scripts/sidebox_config_add.js create mode 100644 venice-data/scripts/sidebox_config_del.js create mode 100644 venice-data/scripts/sidebox_config_move.js create mode 100644 venice-data/velocity/sidebox_config.vm create mode 100644 venice-web/images/icn_down.gif create mode 100644 venice-web/images/icn_up.gif create mode 100644 venice-web/images/icn_x.gif diff --git a/conf/venice-db-init-mysql.sql b/conf/venice-db-init-mysql.sql index 6a8d324..d933ae8 100644 --- a/conf/venice-db-init-mysql.sql +++ b/conf/venice-db-init-mysql.sql @@ -313,8 +313,9 @@ CREATE TABLE sbox_master ( sb_name VARCHAR(255) BINARY NOT NULL, # name of the sidebox type_nsid INT NOT NULL, # namespace ID of the type of the sidebox type_name VARCHAR(255) BINARY NOT NULL, # name of the type of the sidebox - descr TINYTEXT NOT NULL, # description of the sidebox - UNIQUE INDEX by_name (sb_nsid, sb_name) + descr VARCHAR(255) NOT NULL, # description of the sidebox + UNIQUE INDEX by_name (sb_nsid, sb_name), + INDEX by_descr (descr) ); # This table indicates in what contexts a sidebox may be used. @@ -414,6 +415,8 @@ INSERT INTO globalprop (nsid, prop_name, prop_value) VALUES (6, 'std.button.height', 'I24' ), (6, 'bn.0transparent', '!transparent.gif' ), (6, 'bnc.0transparent', '!' ), + (6, 'bn.add', '!add.jpg' ), + (6, 'bnc.add', '!Add' ), (6, 'bn.cancel', '!cancel.jpg' ), (6, 'bnc.cancel', '!Cancel' ), (6, 'bn.configure', '!configure.jpg' ), diff --git a/src/venice-base/com/silverwrist/venice/script/LibraryVeniceCast.java b/src/venice-base/com/silverwrist/venice/script/LibraryVeniceCast.java index df50ca3..f00503a 100644 --- a/src/venice-base/com/silverwrist/venice/script/LibraryVeniceCast.java +++ b/src/venice-base/com/silverwrist/venice/script/LibraryVeniceCast.java @@ -24,6 +24,7 @@ import com.silverwrist.venice.app.AdvancedUserService; import com.silverwrist.venice.community.CategoryService; import com.silverwrist.venice.community.CommunityService; import com.silverwrist.venice.iface.*; +import com.silverwrist.venice.sidebox.SideboxDescriptor; import com.silverwrist.venice.sidebox.SideboxService; public class LibraryVeniceCast @@ -138,4 +139,12 @@ public class LibraryVeniceCast } // end queryUserDefaultPropertyNamespace + public final SideboxDescriptor toSideboxDescriptor(Object obj) + { + if (obj instanceof SideboxDescriptor) + return (SideboxDescriptor)obj; + throw new ClassCastException("LibraryVeniceCast.toSideboxDescriptor: invalid cast"); + + } // end toSideboxDescriptor + } // end class LibraryVeniceCast diff --git a/src/venice-base/com/silverwrist/venice/sidebox/SideboxDescriptor.java b/src/venice-base/com/silverwrist/venice/sidebox/SideboxDescriptor.java new file mode 100644 index 0000000..06a6052 --- /dev/null +++ b/src/venice-base/com/silverwrist/venice/sidebox/SideboxDescriptor.java @@ -0,0 +1,59 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.sidebox; + +public class SideboxDescriptor +{ + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private int m_sbid; + private String m_descr; + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + SideboxDescriptor(int sbid, String descr) + { + m_sbid = sbid; + m_descr = descr; + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Public getters + *-------------------------------------------------------------------------------- + */ + + public int getID() + { + return m_sbid; + + } // end getID + + public String getDescription() + { + return m_descr; + + } // end getDescription + +} // end class SideboxDescriptor diff --git a/src/venice-base/com/silverwrist/venice/sidebox/SideboxManager.java b/src/venice-base/com/silverwrist/venice/sidebox/SideboxManager.java index 523ca68..03672ec 100644 --- a/src/venice-base/com/silverwrist/venice/sidebox/SideboxManager.java +++ b/src/venice-base/com/silverwrist/venice/sidebox/SideboxManager.java @@ -357,4 +357,52 @@ public class SideboxManager implements NamedObject, ComponentInitialize, Compone } // end getSideboxes + public List getSideboxDescriptors(DynamoUser user, String context_namespace, String context_name, + Object context_param) throws DatabaseException + { + List rc = m_ops.getSideboxDescriptors(user.getUID(),m_ns_cache.namespaceNameToId(context_namespace),context_name, + context_param); + if (rc.isEmpty()) + return Collections.EMPTY_LIST; + return Collections.unmodifiableList(rc); + + } // end getSideboxDescriptors + + public List getAllSideboxDescriptors(String context_namespace, String context_name) throws DatabaseException + { + List rc = m_ops.getAllSideboxDescriptors(m_ns_cache.namespaceNameToId(context_namespace),context_name); + if (rc.isEmpty()) + return Collections.EMPTY_LIST; + return Collections.unmodifiableList(rc); + + } // end getAllSideboxDescriptors + + public void moveSideboxItemToPosition(DynamoUser user, String context_namespace, String context_name, + Object context_param, int sbid, int new_pos) throws DatabaseException + { + m_ops.moveSideboxItemToPosition(user.getUID(),m_ns_cache.namespaceNameToId(context_namespace),context_name, + context_param,sbid,new_pos); + + } // end moveSideboxItemToPosition + + public void removeSidebox(DynamoUser user, String context_namespace, String context_name, Object context_param, + int sbid) throws DatabaseException + { + m_ops.removeSidebox(user.getUID(),m_ns_cache.namespaceNameToId(context_namespace),context_name,context_param,sbid); + + } // end removeSidebox + + public void addSidebox(DynamoUser user, String context_namespace, String context_name, Object context_param, + int sbid) throws DatabaseException + { + m_ops.addSidebox(user.getUID(),m_ns_cache.namespaceNameToId(context_namespace),context_name,context_param,sbid); + + } // end addSidebox + + public void copyUserConfig(DynamoUser from, DynamoUser to) throws DatabaseException + { + m_ops.copyUserConfig(from.getUID(),to.getUID()); + + } // end copyUserConfig + } // end class SideboxManager diff --git a/src/venice-base/com/silverwrist/venice/sidebox/SideboxMessages.properties b/src/venice-base/com/silverwrist/venice/sidebox/SideboxMessages.properties index db5c447..09ba8c8 100644 --- a/src/venice-base/com/silverwrist/venice/sidebox/SideboxMessages.properties +++ b/src/venice-base/com/silverwrist/venice/sidebox/SideboxMessages.properties @@ -19,3 +19,6 @@ context.param.ser=Unable to serialize context parameter of class {0}. no.sidebox=Unable to find definition for sidebox with ID #{0}. property.deserialize=The value of property "{0}" could not be deserialized. no.sbtype=Unable to find sidebox type factory for type namespace {0}, name {1}. +sbox.not.in.list=The sidebox with ID #{0} does not exist in the current list. +sbox.already.in.list=The sidebox with ID #{0} already exists in the current list. +sbox.impermissible=The sidebox with ID #{0} is not permitted in the current list. diff --git a/src/venice-base/com/silverwrist/venice/sidebox/SideboxOps.java b/src/venice-base/com/silverwrist/venice/sidebox/SideboxOps.java index 7fd358b..3907419 100644 --- a/src/venice-base/com/silverwrist/venice/sidebox/SideboxOps.java +++ b/src/venice-base/com/silverwrist/venice/sidebox/SideboxOps.java @@ -17,6 +17,7 @@ */ package com.silverwrist.venice.sidebox; +import java.util.*; import com.silverwrist.dynamo.db.OpsBase; import com.silverwrist.dynamo.except.*; import com.silverwrist.dynamo.iface.*; @@ -49,6 +50,22 @@ abstract class SideboxOps extends OpsBase abstract Object getSideboxProperty(int sbid, PropertyKey key) throws DatabaseException; + abstract List getSideboxDescriptors(int uid, int context_nsid, String context_name, Object context_param) + throws DatabaseException; + + abstract List getAllSideboxDescriptors(int context_nsid, String context_name) throws DatabaseException; + + abstract void moveSideboxItemToPosition(int uid, int context_nsid, String context_name, Object context_param, + int sbid, int new_pos) throws DatabaseException; + + abstract void removeSidebox(int uid, int context_nsid, String context_name, Object context_param, int sbid) + throws DatabaseException; + + abstract void addSidebox(int uid, int context_nsid, String context_name, Object context_param, int sbid) + throws DatabaseException; + + abstract void copyUserConfig(int uid_from, int uid_to) throws DatabaseException; + /*-------------------------------------------------------------------------------- * External static operations *-------------------------------------------------------------------------------- diff --git a/src/venice-base/com/silverwrist/venice/sidebox/SideboxOps_mysql.java b/src/venice-base/com/silverwrist/venice/sidebox/SideboxOps_mysql.java index b4f029d..5ae7fce 100644 --- a/src/venice-base/com/silverwrist/venice/sidebox/SideboxOps_mysql.java +++ b/src/venice-base/com/silverwrist/venice/sidebox/SideboxOps_mysql.java @@ -301,4 +301,560 @@ public class SideboxOps_mysql extends SideboxOps } // end getSideboxProperty + List getSideboxDescriptors(int uid, int context_nsid, String context_name, Object context_param) + throws DatabaseException + { + String context_param_ser = serializeContextParam(context_param); + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; + + try + { // get a connection + conn = getConnection(); + + // create and execute the statement + if (context_param_ser==null) + stmt = conn.prepareStatement("SELECT m.sbid, m.descr FROM sbox_deploy d, sbox_master m WHERE m.sbid = d.sbid " + + "AND d.uid = ? AND d.ctx_nsid = ? AND d.ctx_name = ? AND d.param IS NULL " + + "ORDER BY d.seq;"); + else + { // use the version with the parameter + stmt = conn.prepareStatement("SELECT m.sbid, m.descr FROM sbox_deploy d, sbox_master m WHERE m.sbid = d.sbid " + + "AND d.uid = ? AND d.ctx_nsid = ? AND d.ctx_name = ? AND d.param = ? " + + "ORDER BY d.seq;"); + stmt.setString(4,context_param_ser); + + } // end else + + stmt.setInt(1,uid); + stmt.setInt(2,context_nsid); + stmt.setString(3,context_name); + rs = stmt.executeQuery(); + + // Build the return list. + ArrayList rc = new ArrayList(); + while (rs.next()) + rc.add(new SideboxDescriptor(rs.getInt(1),rs.getString(2))); + rc.trimToSize(); + return rc; + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + SQLUtils.shutdown(rs); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(conn); + + } // end finally + + } // end getSideboxDescriptors + + List getAllSideboxDescriptors(int context_nsid, String context_name) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; + + try + { // get a connection + conn = getConnection(); + + // create and execute the statement + stmt = conn.prepareStatement("SELECT m.sbid, m.descr FROM sbox_master m, sbox_context c WHERE m.sbid = c.sbid " + + "AND c.ctx_nsid = ? AND c.ctx_name = ? ORDER BY m.descr"); + stmt.setInt(1,context_nsid); + stmt.setString(2,context_name); + rs = stmt.executeQuery(); + + // Build the return list. + ArrayList rc = new ArrayList(); + while (rs.next()) + rc.add(new SideboxDescriptor(rs.getInt(1),rs.getString(2))); + rc.trimToSize(); + return rc; + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + SQLUtils.shutdown(rs); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(conn); + + } // end finally + + } // end getAllSideboxDescriptors + + void moveSideboxItemToPosition(int uid, int context_nsid, String context_name, Object context_param, int sbid, + int new_pos) throws DatabaseException + { + String context_param_ser = serializeContextParam(context_param); + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + PreparedStatement stmt_ren = null; + ResultSet rs = null; + + try + { // get a connection + conn = getConnection(); + + // lock the deploy table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES sbox_deploy WRITE;"); + + // locate the current position of the sidebox in the list + if (context_param_ser==null) + stmt = conn.prepareStatement("SELECT seq FROM sbox_deploy WHERE sbid = ? AND uid = ? AND ctx_nsid = ? " + + "AND ctx_name = ? AND param IS NULL;"); + else + { // add context parameter to statement + stmt = conn.prepareStatement("SELECT seq FROM sbox_deploy WHERE sbid = ? AND uid = ? AND ctx_nsid = ? " + + "AND ctx_name = ? AND param = ?;"); + stmt.setString(5,context_param_ser); + + } // end else + + stmt.setInt(1,sbid); + stmt.setInt(2,uid); + stmt.setInt(3,context_nsid); + stmt.setString(4,context_name); + rs = stmt.executeQuery(); + if (!(rs.next())) + { // sidebox does not exist here - throw exception + DatabaseException de = new DatabaseException(SideboxOps_mysql.class,"SideboxMessages","sbox.not.in.list"); + de.setParameter(0,String.valueOf(sbid)); + throw de; + + } // end if + + int old_pos = rs.getInt(1); + if (old_pos==new_pos) + return; // this is a no-op + + SQLUtils.shutdown(rs); // prep for next statement + rs = null; + SQLUtils.shutdown(stmt); + + if (new_pos<0) + new_pos = 0; // range-check on low end + else + { // need to range-check on high end - create statement to get max index + if (context_param_ser==null) + stmt = conn.prepareStatement("SELECT MAX(seq) FROM sbox_deploy WHERE uid = ? AND ctx_nsid = ? " + + "AND ctx_name = ? AND param IS NULL;"); + else + { // add context parameter to statement + stmt = conn.prepareStatement("SELECT MAX(seq) FROM sbox_deploy WHERE uid = ? AND ctx_nsid = ? " + + "AND ctx_name = ? AND param = ?;"); + stmt.setString(4,context_param_ser); + + } // end else + + stmt.setInt(1,uid); + stmt.setInt(2,context_nsid); + stmt.setString(3,context_name); + rs = stmt.executeQuery(); + int max_pos = SQLUtils.getReturnCountInt(rs,1); + SQLUtils.shutdown(rs); // prep for next statement + rs = null; + SQLUtils.shutdown(stmt); + if (new_pos>max_pos) + new_pos = max_pos; + + } // end else + + // Start by renumbering the original item to index -1, normally unused. + if (context_param_ser==null) + stmt_ren = conn.prepareStatement("UPDATE sbox_deploy SET seq = ? WHERE sbid = ? AND uid = ? AND ctx_nsid = ? " + + "AND ctx_name = ? AND param IS NULL;"); + else + { // include the context parameter + stmt_ren = conn.prepareStatement("UPDATE sbox_deploy SET seq = ? WHERE sbid = ? AND uid = ? AND ctx_nsid = ? " + + "AND ctx_name = ? AND param = ?;"); + stmt_ren.setString(6,context_param_ser); + + } // end else + + stmt_ren.setInt(1,-1); + stmt_ren.setInt(2,sbid); + stmt_ren.setInt(3,uid); + stmt_ren.setInt(4,context_nsid); + stmt_ren.setString(5,context_name); + stmt_ren.executeUpdate(); + + // Now renumber the items in between the new position and the old position. + if (new_pos= ? AND seq <= ? AND uid = ? " + + "AND ctx_nsid = ? AND ctx_name = ? AND param IS NULL;"); + else + { // include the context parameter + stmt = conn.prepareStatement("UPDATE sbox_deploy SET seq = seq + 1 WHERE seq >= ? AND seq <= ? AND uid = ? " + + "AND ctx_nsid = ? AND ctx_name = ? AND param = ?;"); + stmt.setString(6,context_param_ser); + + } // end else + + stmt.setInt(1,new_pos); + stmt.setInt(2,old_pos); + stmt.setInt(3,uid); + stmt.setInt(4,context_nsid); + stmt.setString(5,context_name); + + } // end if + else + { // prepare statement to shift some items up + if (context_param_ser==null) + stmt = conn.prepareStatement("UPDATE sbox_deploy SET seq = seq - 1 WHERE seq >= ? AND seq <= ? AND uid = ? " + + "AND ctx_nsid = ? AND ctx_name = ? AND param IS NULL;"); + else + { // include the context parameter + stmt = conn.prepareStatement("UPDATE sbox_deploy SET seq = seq - 1 WHERE seq >= ? AND seq <= ? AND uid = ? " + + "AND ctx_nsid = ? AND ctx_name = ? AND param = ?;"); + stmt.setString(6,context_param_ser); + + } // end else + + stmt.setInt(1,old_pos); + stmt.setInt(2,new_pos); + stmt.setInt(3,uid); + stmt.setInt(4,context_nsid); + stmt.setString(5,context_name); + + } // end else + + stmt.executeUpdate(); + + // Now move the old element back into place in its new position, using the statement we've already prepared + // and just changing its parameters. + stmt_ren.setInt(1,new_pos); + stmt_ren.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(rs); + SQLUtils.shutdown(stmt_ren); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(conn); + + } // end finally + + } // end moveSideboxItemToPosition + + void removeSidebox(int uid, int context_nsid, String context_name, Object context_param, int sbid) + throws DatabaseException + { + String context_param_ser = serializeContextParam(context_param); + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + ResultSet rs = null; + + try + { // get a connection + conn = getConnection(); + + // lock the deploy table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES sbox_deploy WRITE;"); + + // look for the item in the list, and get its old position + // locate the current position of the sidebox in the list + if (context_param_ser==null) + stmt = conn.prepareStatement("SELECT seq FROM sbox_deploy WHERE sbid = ? AND uid = ? AND ctx_nsid = ? " + + "AND ctx_name = ? AND param IS NULL;"); + else + { // add context parameter to statement + stmt = conn.prepareStatement("SELECT seq FROM sbox_deploy WHERE sbid = ? AND uid = ? AND ctx_nsid = ? " + + "AND ctx_name = ? AND param = ?;"); + stmt.setString(5,context_param_ser); + + } // end else + + stmt.setInt(1,sbid); + stmt.setInt(2,uid); + stmt.setInt(3,context_nsid); + stmt.setString(4,context_name); + rs = stmt.executeQuery(); + if (!(rs.next())) + { // sidebox does not exist here - throw exception + DatabaseException de = new DatabaseException(SideboxOps_mysql.class,"SideboxMessages","sbox.not.in.list"); + de.setParameter(0,String.valueOf(sbid)); + throw de; + + } // end if + + int old_pos = rs.getInt(1); + + SQLUtils.shutdown(rs); // prep for next statement + rs = null; + SQLUtils.shutdown(stmt); + + // Erase this row from the table. + if (context_param_ser==null) + stmt = conn.prepareStatement("DELETE FROM sbox_deploy WHERE sbid = ? AND uid = ? AND ctx_nsid = ? " + + "AND ctx_name = ? AND param IS NULL;"); + else + { // include the context parameter + stmt = conn.prepareStatement("DELETE FROM sbox_deploy WHERE sbid = ? AND uid = ? AND ctx_nsid = ? " + + "AND ctx_name = ? AND param = ?;"); + stmt.setString(5,context_param_ser); + + } // end else + + stmt.setInt(1,sbid); + stmt.setInt(2,uid); + stmt.setInt(3,context_nsid); + stmt.setString(4,context_name); + stmt.executeUpdate(); + + // Now renumber all the following rows to close the gap. + SQLUtils.shutdown(stmt); + if (context_param_ser==null) + stmt = conn.prepareStatement("UPDATE sbox_deploy SET seq = seq - 1 WHERE seq >= ? AND uid = ? " + + "AND ctx_nsid = ? AND ctx_name = ? AND param IS NULL;"); + else + { // include the context parameter + stmt = conn.prepareStatement("UPDATE sbox_deploy SET seq = seq - 1 WHERE seq >= ? AND uid = ? " + + "AND ctx_nsid = ? AND ctx_name = ? AND param = ?;"); + stmt.setString(5,context_param_ser); + + } // end else + + stmt.setInt(1,old_pos); + stmt.setInt(2,uid); + stmt.setInt(3,context_nsid); + stmt.setString(4,context_name); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(rs); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(conn); + + } // end finally + + } // end removeSidebox + + void addSidebox(int uid, int context_nsid, String context_name, Object context_param, int sbid) + throws DatabaseException + { + String context_param_ser = serializeContextParam(context_param); + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + ResultSet rs = null; + + try + { // get a connection + conn = getConnection(); + + // lock the deploy table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES sbox_deploy WRITE, sbox_context READ;"); + + // see if the given sidebox is already in the list + if (context_param_ser==null) + stmt = conn.prepareStatement("SELECT seq FROM sbox_deploy WHERE sbid = ? AND uid = ? AND ctx_nsid = ? " + + "AND ctx_name = ? AND param IS NULL;"); + else + { // add context parameter to statement + stmt = conn.prepareStatement("SELECT seq FROM sbox_deploy WHERE sbid = ? AND uid = ? AND ctx_nsid = ? " + + "AND ctx_name = ? AND param = ?;"); + stmt.setString(5,context_param_ser); + + } // end else + + stmt.setInt(1,sbid); + stmt.setInt(2,uid); + stmt.setInt(3,context_nsid); + stmt.setString(4,context_name); + rs = stmt.executeQuery(); + if (rs.next()) + { // already in list - throw exception + DatabaseException de = new DatabaseException(SideboxOps_mysql.class,"SideboxMessages","sbox.already.in.list"); + de.setParameter(0,String.valueOf(sbid)); + throw de; + + } // end if + + SQLUtils.shutdown(rs); // prep for next statement + rs = null; + SQLUtils.shutdown(stmt); + + // Make sure this sidebox is permissible in this context. + stmt = conn.prepareStatement("SELECT sbid FROM sbox_context WHERE sbid = ? AND ctx_nsid = ? AND ctx_name = ?;"); + stmt.setInt(1,sbid); + stmt.setInt(2,context_nsid); + stmt.setString(3,context_name); + rs = stmt.executeQuery(); + if (!(rs.next())) + { // impermissible in this list - throw an exception + DatabaseException de = new DatabaseException(SideboxOps_mysql.class,"SideboxMessages","sbox.impermissible"); + de.setParameter(0,String.valueOf(sbid)); + throw de; + + } // end if + + SQLUtils.shutdown(rs); // prep for next statement + rs = null; + SQLUtils.shutdown(stmt); + + // Get the number of items we already have in the list, which is also the index of the new item (as + // elements start numbering with 0). + if (context_param_ser==null) + stmt = conn.prepareStatement("SELECT COUNT(*) FROM sbox_deploy WHERE uid = ? AND ctx_nsid = ? " + + "AND ctx_name = ? AND param IS NULL;"); + else + { // add context parameter to statement + stmt = conn.prepareStatement("SELECT COUNT(*) FROM sbox_deploy WHERE uid = ? AND ctx_nsid = ? " + + "AND ctx_name = ? AND param = ?;"); + stmt.setString(4,context_param_ser); + + } // end else + + stmt.setInt(1,uid); + stmt.setInt(2,context_nsid); + stmt.setString(3,context_name); + rs = stmt.executeQuery(); + int new_seq = SQLUtils.getReturnCountInt(rs,1); + + SQLUtils.shutdown(rs); // prep for next statement + rs = null; + SQLUtils.shutdown(stmt); + + // Insert the new sidebox into the table. + stmt = conn.prepareStatement("INSERT INTO sbox_deploy (uid, ctx_nsid, ctx_name, param, seq, sbid) " + + "VALUES (?, ?, ?, ?, ?, ?);"); + stmt.setInt(1,uid); + stmt.setInt(2,context_nsid); + stmt.setString(3,context_name); + stmt.setString(4,context_param_ser); + stmt.setInt(5,new_seq); + stmt.setInt(6,sbid); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(rs); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(conn); + + } // end finally + + } // end addSidebox + + void copyUserConfig(int uid_from, int uid_to) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + ResultSet rs = null; + + try + { // get a connection + conn = getConnection(); + + // lock the deploy table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES sbox_deploy WRITE;"); + + // start by getting the configuration for the existing user + stmt = conn.prepareStatement("SELECT ctx_nsid, ctx_name, param, seq, sbid FROM sbox_deploy WHERE uid = ?;"); + stmt.setInt(1,uid_from); + rs = stmt.executeQuery(); + LinkedList items = new LinkedList(); + while (rs.next()) + { // save in a cheap and simple fashion + Object[] tmp = new Object[5]; + tmp[0] = rs.getObject(1); + tmp[1] = rs.getObject(2); + tmp[2] = rs.getObject(3); + tmp[3] = rs.getObject(4); + tmp[4] = rs.getObject(5); + items.addLast(tmp); + + } // end while + + SQLUtils.shutdown(rs); // prep for next statement + rs = null; + SQLUtils.shutdown(stmt); + + // erase existing config for destination user + stmt = conn.prepareStatement("DELETE FROM sbox_deploy WHERE uid = ?;"); + stmt.setInt(1,uid_to); + stmt.executeUpdate(); + + // now copy over the configuration + SQLUtils.shutdown(stmt); + stmt = conn.prepareStatement("INSERT INTO sbox_deploy (uid, ctx_nsid, ctx_name, param, seq, sbid) " + + "VALUES (?, ?, ?, ?, ?, ?);"); + stmt.setInt(1,uid_to); + while (!(items.isEmpty())) + { // add the items in, one at a time + Object[] tmp = (Object[])(items.removeFirst()); + stmt.setObject(2,tmp[0],Types.INTEGER); + stmt.setObject(3,tmp[1],Types.VARCHAR); + stmt.setObject(4,tmp[2],Types.VARCHAR); + stmt.setObject(5,tmp[3],Types.INTEGER); + stmt.setObject(6,tmp[4],Types.INTEGER); + stmt.executeUpdate(); + + } // end while + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(rs); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(conn); + + } // end finally + + } // end copyUserConfig + } // end class SideboxOps_mysql diff --git a/src/venice-base/com/silverwrist/venice/sidebox/SideboxService.java b/src/venice-base/com/silverwrist/venice/sidebox/SideboxService.java index a751ba6..a1b677e 100644 --- a/src/venice-base/com/silverwrist/venice/sidebox/SideboxService.java +++ b/src/venice-base/com/silverwrist/venice/sidebox/SideboxService.java @@ -18,7 +18,9 @@ package com.silverwrist.venice.sidebox; import java.util.List; +import com.silverwrist.dynamo.except.DatabaseException; import com.silverwrist.dynamo.except.DynamoException; +import com.silverwrist.dynamo.iface.DynamoUser; import com.silverwrist.dynamo.iface.Request; public interface SideboxService @@ -26,4 +28,20 @@ public interface SideboxService public List getSideboxes(Request req, String context_namespace, String context_name, Object context_param) throws DynamoException; + public List getSideboxDescriptors(DynamoUser user, String context_namespace, String context_name, + Object context_param) throws DatabaseException; + + public List getAllSideboxDescriptors(String context_namespace, String context_name) throws DatabaseException; + + public void moveSideboxItemToPosition(DynamoUser user, String context_namespace, String context_name, + Object context_param, int sbid, int new_pos) throws DatabaseException; + + public void removeSidebox(DynamoUser user, String context_namespace, String context_name, Object context_param, + int sbid) throws DatabaseException; + + public void addSidebox(DynamoUser user, String context_namespace, String context_name, Object context_param, + int sbid) throws DatabaseException; + + public void copyUserConfig(DynamoUser from, DynamoUser to) throws DatabaseException; + } // end interface SideboxService diff --git a/venice-data/scripts/new_account_2.js b/venice-data/scripts/new_account_2.js index 3f2b54f..318dfd3 100644 --- a/venice-data/scripts/new_account_2.js +++ b/venice-data/scripts/new_account_2.js @@ -10,7 +10,7 @@ // // The Initial Developer of the Original Code is Eric J. Bowersox , // for Silverwrist Design Studios. Portions created by Eric J. Bowersox are -// Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. +// Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. // // Contributor(s): @@ -115,6 +115,11 @@ if (op=="create") udpns = vcast.queryUserDefaultPropertyNamespace(req); umgmt.loadUserDefaults(new_user,udpns.getDefaultPropertyNamespaces()); + // Copy the default sidebox configuration for this user. + sideboxes = vcast.querySideboxService(req_help.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE, + "venice-sidebox")); + sideboxes.copyUserConfig(umgmt.getAnonymousUser(),new_user); + // Set the "profile last updated" date for the user. temp_profile.setObject(VeniceNamespaces.USER_PROFILE_NAMESPACE,"last.update",new_user.getCreationDate()); diff --git a/venice-data/scripts/sidebox_config.js b/venice-data/scripts/sidebox_config.js new file mode 100644 index 0000000..77d23e8 --- /dev/null +++ b/venice-data/scripts/sidebox_config.js @@ -0,0 +1,71 @@ +// The contents of this file are subject to the Mozilla Public License Version 1.1 +// (the "License"); you may not use this file except in compliance with the License. +// You may obtain a copy of the License at . +// +// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT +// WARRANTY OF ANY KIND, either express or implied. See the License for the specific +// language governing rights and limitations under the License. +// +// The Original Code is the Venice Web Communities System. +// +// The Initial Developer of the Original Code is Eric J. Bowersox , +// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are +// Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. +// +// Contributor(s): + +importPackage(java.util); +importClass(Packages.com.silverwrist.dynamo.Namespaces); +importPackage(Packages.com.silverwrist.dynamo.iface); +importPackage(Packages.com.silverwrist.dynamo.util); +importClass(Packages.com.silverwrist.venice.VeniceNamespaces); +importPackage(Packages.com.silverwrist.venice.content); +importPackage(Packages.com.silverwrist.venice.iface); +importPackage(Packages.com.silverwrist.venice.sidebox); + +req = bsf.lookupBean("request"); // get request +rhelp = bsf.lookupBean("request_help"); // get request helper +user = vlib.getUser(req); // get user + +// Get the list of the user's sideboxes. +sideboxes = vcast.querySideboxService(req_help.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"venice-sidebox")); +list = sideboxes.getSideboxDescriptors(user,VeniceNamespaces.SIDEBOX_CONTEXT_NAMESPACE,"top",null); + +// Create a set that contains all the IDs of the sideboxes. +matchset = new HashSet(); +it = list.iterator(); +while (it.hasNext()) +{ // add the IDs to the set + d = vcast.toSideboxDescriptor(it.next()); + matchset.add(cast.toIntegerObject(d.getID())); + +} // end while + +// Get the list of all possible sideboxes. +all_list = sideboxes.getAllSideboxDescriptors(VeniceNamespaces.SIDEBOX_CONTEXT_NAMESPACE,"top"); + +// Use that list and the match set to generate the "not list". +not_list = null; +if (list.size()==all_list.size()) + not_list = Collections.EMPTY_LIST; +else if (list.size()==0) + not_list = all_list; +else +{ // need to generate the "not list" + not_list = new ArrayList(all_list.size()); + it = all_list.iterator(); + while (it.hasNext()) + { // check the list... + d = vcast.toSideboxDescriptor(it.next()); + if (!(matchset.contains(cast.toIntegerObject(d.getID())))) + not_list.add(d); + + } // end while + +} // end else + +// Generate the output object. +rc = new VelocityView("Your Sidebox Configuration: Front Page","sidebox_config.vm"); +rc.setParameter("list",list); +rc.setParameter("notlist",not_list); +dynamo.scriptOutput(rc); diff --git a/venice-data/scripts/sidebox_config_add.js b/venice-data/scripts/sidebox_config_add.js new file mode 100644 index 0000000..410d21f --- /dev/null +++ b/venice-data/scripts/sidebox_config_add.js @@ -0,0 +1,36 @@ +// The contents of this file are subject to the Mozilla Public License Version 1.1 +// (the "License"); you may not use this file except in compliance with the License. +// You may obtain a copy of the License at . +// +// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT +// WARRANTY OF ANY KIND, either express or implied. See the License for the specific +// language governing rights and limitations under the License. +// +// The Original Code is the Venice Web Communities System. +// +// The Initial Developer of the Original Code is Eric J. Bowersox , +// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are +// Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. +// +// Contributor(s): + +importClass(Packages.com.silverwrist.dynamo.Namespaces); +importPackage(Packages.com.silverwrist.dynamo.iface); +importPackage(Packages.com.silverwrist.dynamo.util); +importClass(Packages.com.silverwrist.venice.VeniceNamespaces); +importPackage(Packages.com.silverwrist.venice.iface); +importPackage(Packages.com.silverwrist.venice.sidebox); + +req = bsf.lookupBean("request"); // get request +rhelp = bsf.lookupBean("request_help"); // get request helper +user = vlib.getUser(req); // get user + +// Get the parameters. +sbid = rhelp.getParameterInt("sbid",-1); + +// Execute the operation. +sideboxes = vcast.querySideboxService(req_help.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"venice-sidebox")); +sideboxes.addSidebox(user,VeniceNamespaces.SIDEBOX_CONTEXT_NAMESPACE,"top",null,sbid); + +// Redisplay the standard context display. +dynamo.scriptOutput(dynamo.exec("/scripts/sidebox_config.js")); diff --git a/venice-data/scripts/sidebox_config_del.js b/venice-data/scripts/sidebox_config_del.js new file mode 100644 index 0000000..7eac6d5 --- /dev/null +++ b/venice-data/scripts/sidebox_config_del.js @@ -0,0 +1,36 @@ +// The contents of this file are subject to the Mozilla Public License Version 1.1 +// (the "License"); you may not use this file except in compliance with the License. +// You may obtain a copy of the License at . +// +// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT +// WARRANTY OF ANY KIND, either express or implied. See the License for the specific +// language governing rights and limitations under the License. +// +// The Original Code is the Venice Web Communities System. +// +// The Initial Developer of the Original Code is Eric J. Bowersox , +// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are +// Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. +// +// Contributor(s): + +importClass(Packages.com.silverwrist.dynamo.Namespaces); +importPackage(Packages.com.silverwrist.dynamo.iface); +importPackage(Packages.com.silverwrist.dynamo.util); +importClass(Packages.com.silverwrist.venice.VeniceNamespaces); +importPackage(Packages.com.silverwrist.venice.iface); +importPackage(Packages.com.silverwrist.venice.sidebox); + +req = bsf.lookupBean("request"); // get request +rhelp = bsf.lookupBean("request_help"); // get request helper +user = vlib.getUser(req); // get user + +// Get the parameters. +sbid = rhelp.getParameterInt("sbid",-1); + +// Execute the operation. +sideboxes = vcast.querySideboxService(req_help.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"venice-sidebox")); +sideboxes.removeSidebox(user,VeniceNamespaces.SIDEBOX_CONTEXT_NAMESPACE,"top",null,sbid); + +// Redisplay the standard context display. +dynamo.scriptOutput(dynamo.exec("/scripts/sidebox_config.js")); diff --git a/venice-data/scripts/sidebox_config_move.js b/venice-data/scripts/sidebox_config_move.js new file mode 100644 index 0000000..b81f292 --- /dev/null +++ b/venice-data/scripts/sidebox_config_move.js @@ -0,0 +1,37 @@ +// The contents of this file are subject to the Mozilla Public License Version 1.1 +// (the "License"); you may not use this file except in compliance with the License. +// You may obtain a copy of the License at . +// +// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT +// WARRANTY OF ANY KIND, either express or implied. See the License for the specific +// language governing rights and limitations under the License. +// +// The Original Code is the Venice Web Communities System. +// +// The Initial Developer of the Original Code is Eric J. Bowersox , +// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are +// Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. +// +// Contributor(s): + +importClass(Packages.com.silverwrist.dynamo.Namespaces); +importPackage(Packages.com.silverwrist.dynamo.iface); +importPackage(Packages.com.silverwrist.dynamo.util); +importClass(Packages.com.silverwrist.venice.VeniceNamespaces); +importPackage(Packages.com.silverwrist.venice.iface); +importPackage(Packages.com.silverwrist.venice.sidebox); + +req = bsf.lookupBean("request"); // get request +rhelp = bsf.lookupBean("request_help"); // get request helper +user = vlib.getUser(req); // get user + +// Get the parameters. +sbid = rhelp.getParameterInt("sbid",-1); +new_pos = rhelp.getParameterInt("to",-1); + +// Execute the operation. +sideboxes = vcast.querySideboxService(req_help.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"venice-sidebox")); +sideboxes.moveSideboxItemToPosition(user,VeniceNamespaces.SIDEBOX_CONTEXT_NAMESPACE,"top",null,sbid,new_pos); + +// Redisplay the standard context display. +dynamo.scriptOutput(dynamo.exec("/scripts/sidebox_config.js")); diff --git a/venice-data/scripts/top.js b/venice-data/scripts/top.js index 6405872..b446a9e 100644 --- a/venice-data/scripts/top.js +++ b/venice-data/scripts/top.js @@ -64,8 +64,8 @@ rc.pageTitle = globals.getObject(VeniceNamespaces.FRAME_LAF_NAMESPACE,"frontpage rc.pageQID = "top"; if (!(user.isAnonymous())) { // they only get to configure if they're logged in - rc.configureURL = "TODO"; - rc.configureURLType = "ABSOLUTE"; + rc.configureURL = "sidebox_config.js.vs"; + rc.configureURLType = "SERVLET"; } // end if diff --git a/venice-data/velocity/sidebox_config.vm b/venice-data/velocity/sidebox_config.vm new file mode 100644 index 0000000..ae11d8b --- /dev/null +++ b/venice-data/velocity/sidebox_config.vm @@ -0,0 +1,109 @@ +#* + The contents of this file are subject to the Mozilla Public License Version 1.1 + (the "License"); you may not use this file except in compliance with the License. + You may obtain a copy of the License at . + + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + WARRANTY OF ANY KIND, either express or implied. See the License for the specific + language governing rights and limitations under the License. + + The Original Code is the Venice Web Communities System. + + The Initial Developer of the Original Code is Eric J. Bowersox , + for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + + Contributor(s): +*# +#* + Parameters: + list = List of sidebox descriptors on our front page + notlist = List of sidebox descriptors not on our Front Page +*# +#header2( "Your Sidebox Configuration:" "Front Page" ) + + +#if( $list.size() > 0 ) + #comment( "List of sideboxes" ) +

+ #set( $max_i = $list.size() - 1 ) + #set( $i = 0 ) + #foreach( $d in $list ) + + + + + + + #set( $i = $i + 1 ) + #end +
+ #if( $i < $max_i ) + #set( $ix = $i + 1 ) + [Down] + #else +   + #end + + #if( $i > 0 ) + #set( $ix = $i - 1 ) + [Up] + #else +   + #end + + [Remove] + #encodeHTML( ${d.getDescription()} )

+ + #comment( "Explanation of the sidebox icons" ) +

+ + + + + + + + + +
+ [Down] + + Click this symbol to move the specified sidebox down on your Front Page. + +
+ [Up] + + Click this symbol to move the specified sidebox up on your Front Page. + +
+ [Remove] + + Click this symbol to remove the specified sidebox from your Front Page. + +

+#else +

No sideboxes currently defined.

+#end + +#if( $notlist.size() > 0 ) +
+ Add new sidebox:   +    + #button( "INPUT" "add" ) +
+#end diff --git a/venice-web/images/icn_down.gif b/venice-web/images/icn_down.gif new file mode 100644 index 0000000000000000000000000000000000000000..f430a9c1d0ee369af150061c051945d7219bce32 GIT binary patch literal 90 zcmZ?wbh9u|6krfw_{hL8bLRiFv@`$zGyMO5Mu!0iK;jHc#y$O+2j1?xC&2Gw{yO(( t?lnh8Q8Vw3pydvXcbD|(S)YH)x_N_U^Bet149!ly>mLPb@Ut>l0{|5mBL4sY literal 0 HcmV?d00001 diff --git a/venice-web/images/icn_up.gif b/venice-web/images/icn_up.gif new file mode 100644 index 0000000000000000000000000000000000000000..4eaed3f57018ae77a7363e40c5e1720028f5935f GIT binary patch literal 92 zcmZ?wbh9u|6krfw_{hL8bLRiFv@`$zGyMO5Mu!0iK;jHcrak?c2j1?xC%}KijJ5S( u>R!X^>M6b{ehrzWYj$Pj_O!kV4Yyz}4y}LX;dD?wP-V>vku%PW4AuZ&NhC1< literal 0 HcmV?d00001 diff --git a/venice-web/images/icn_x.gif b/venice-web/images/icn_x.gif new file mode 100644 index 0000000000000000000000000000000000000000..ed59ba98d95c585585059517ef8b458e66a5910d GIT binary patch literal 96 zcmZ?wbh9u|6krfw_{hL8bLRiFv@`!182%d@>o5QTNSuMmvZp`uz}tPtDtwzXSY&^) zP0I{@ZmM{=bLq^b7oN9hZMJy1XVIq^X1#(%2kR7s*x27BXdIRKytG4#i@_QIc$XyV literal 0 HcmV?d00001