some of the underpinnings of community services

This commit is contained in:
Eric J. Bowersox
2003-06-15 19:02:26 +00:00
parent ce27befa54
commit 80d4ba4212
21 changed files with 657 additions and 11 deletions

View File

@@ -94,6 +94,7 @@ class CommunityImpl implements VeniceCommunity
*--------------------------------------------------------------------------------
*/
private CommunityManager m_base; // base object
private CommunityOps m_ops; // community operations object
private NamespaceCache m_nscache; // namespace cache object
private SecurityReferenceMonitor m_srm; // security reference monitor
@@ -114,6 +115,7 @@ class CommunityImpl implements VeniceCommunity
private java.util.Date m_lastaccessed; // date last accessed
private java.util.Date m_lastupdate; // date last updated
private ReferenceMap m_properties; // properties cache
private List m_service_list = null; // cached service list
/*--------------------------------------------------------------------------------
* Constructors
@@ -141,9 +143,11 @@ class CommunityImpl implements VeniceCommunity
* corresponding to static fields of the
* {@link com.silverwrist.venice.community.CommunityManagerOps CommunityManagerOps} object.
*/
CommunityImpl(CommunityOps ops, NamespaceCache nscache, SecurityReferenceMonitor srm, UserManagement users,
AuthenticatorLookup alook, PostDynamicUpdate post, CategoryService cats, Map data)
CommunityImpl(CommunityManager base, CommunityOps ops, NamespaceCache nscache, SecurityReferenceMonitor srm,
UserManagement users, AuthenticatorLookup alook, PostDynamicUpdate post, CategoryService cats,
Map data)
{
m_base = base;
m_ops = ops;
m_nscache = nscache;
m_srm = srm;
@@ -1065,4 +1069,43 @@ class CommunityImpl implements VeniceCommunity
} // end isAdministrator
public List getServices() throws DatabaseException
{
if (m_service_list==null)
{ // need to fake up the service list
int[] svcids = m_ops.getServiceIDs(m_id);
if (svcids.length>0)
{ // convert this to a list of ServiceDescriptors
ArrayList rc = new ArrayList(svcids.length);
for (int i=0; i<svcids.length; i++)
rc.add(m_base.getServiceForID(svcids[i]));
Collections.sort(rc,new Comparator()
{
public int compare(Object o1, Object o2)
{
String s1 = ((CommunityServiceDescriptor)o1).getDescription();
String s2 = ((CommunityServiceDescriptor)o2).getDescription();
return s1.compareTo(s2);
} // end compare
public boolean equals(Object obj)
{
return false;
} // end equals
}); // end Comparator object
m_service_list = Collections.unmodifiableList(rc);
} // end if
else // just use the empty list as a return value
m_service_list = Collections.EMPTY_LIST;
} // end if
return m_service_list;
} // end getServices
} // end class CommunityImpl

View File

@@ -27,11 +27,13 @@ import com.silverwrist.dynamo.db.NamespaceCache;
import com.silverwrist.dynamo.db.UserManagement;
import com.silverwrist.dynamo.except.*;
import com.silverwrist.dynamo.iface.*;
import com.silverwrist.dynamo.module.ModuleOperations;
import com.silverwrist.dynamo.security.SecurityReferenceMonitor;
import com.silverwrist.dynamo.util.*;
import com.silverwrist.venice.CommunitySearchField;
import com.silverwrist.venice.SearchMode;
import com.silverwrist.venice.VeniceNamespaces;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.iface.*;
public class CommunityManager
@@ -140,6 +142,129 @@ public class CommunityManager
} // end class CommunitySerializer
/*--------------------------------------------------------------------------------
* Internal class that initializes the services
*--------------------------------------------------------------------------------
*/
private class ServiceInit implements FinalStageInitHook
{
/*====================================================================
* Constructor
*====================================================================
*/
ServiceInit()
{ // do nothing
} // end constructor
/*====================================================================
* Implementations from interface FinalStageInitHook
*====================================================================
*/
public void initialize(Application application, ServiceProvider services) throws DynamoException
{
logger.info("Initializing community service list");
List svclist = m_ops.getMasterServiceList();
ModuleOperations module_ops = (ModuleOperations)(services.queryService(ModuleOperations.class));
Iterator it = svclist.iterator();
while (it.hasNext())
{ // get the Map full of data
Map item = (Map)(it.next());
// make sure we have the module
PropertyKey pk = (PropertyKey)(item.get(CommunityManagerOps.KEY_MODNAME));
Module module = module_ops.findModule(m_ns_cache.namespaceIdToName(pk.getNamespaceID()),pk.getName());
if (module==null)
{ // the module is not loaded - we have to load it
String filename = (String)(item.get(CommunityManagerOps.KEY_MODFILENAME));
module = module_ops.loadModule(filename,true);
QualifiedNameKey modid = module.getModuleID();
PropertyKey pk2 = new PropertyKey(m_ns_cache.namespaceNameToId(modid.getNamespace()),modid.getName());
if (!(pk.equals(pk2)))
{ // module name does not match what we expect - throw exception
CommunityServiceException cse = new CommunityServiceException(CommunityManager.class,"CommunityMessages",
"svc.modname.mismatch");
cse.setParameter(0,filename);
throw cse;
} // end if
} // end if
// now get the CommunityServiceController from the module
pk = (PropertyKey)(item.get(CommunityManagerOps.KEY_OBJNAME));
DynamicObject dobj = module.getProvidedObject(m_ns_cache.namespaceIdToName(pk.getNamespaceID()),pk.getName());
if (!(dobj instanceof CommunityServiceController))
{ // invalid controller object - throw exception
CommunityServiceException cse = new CommunityServiceException(CommunityManager.class,"CommunityMessages",
"svc.object.badType");
cse.setParameter(0,m_ns_cache.namespaceIdToName(pk.getNamespaceID()));
cse.setParameter(1,pk.getName());
throw cse;
} // end if
CommunityServiceController csc = (CommunityServiceController)dobj;
// preserve the descriptors
pk = (PropertyKey)(item.get(CommunityManagerOps.KEY_SVCNAME));
CommunityServiceDescriptor csdesc =
new CommunityServiceDescriptor((Integer)(item.get(CommunityManagerOps.KEY_SVCID)),
new QualifiedNameKey(m_ns_cache.namespaceIdToName(pk.getNamespaceID()),
pk.getName()),
(String)(item.get(CommunityManagerOps.KEY_SHORTVAR)),csc);
m_qname_to_service.put(csdesc.getName(),csdesc);
m_index_to_service.put(item.get(CommunityManagerOps.KEY_SVCID),csdesc);
} // end while
// Now register our ServiceShutdown class as a pre-stage shutdown hook.
FinalStageRegistration fsreg = (FinalStageRegistration)(services.queryService(FinalStageRegistration.class));
fsreg.registerPreStageShutdown(new ServiceShutdown());
} // end initialize
} // end class ServiceInit
/*--------------------------------------------------------------------------------
* Internal class that shuts down the services
*--------------------------------------------------------------------------------
*/
private class ServiceShutdown implements ComponentShutdown
{
/*====================================================================
* Constructor
*====================================================================
*/
ServiceShutdown()
{ // do nothing
} // end constructor
/*====================================================================
* Implementations from interface ComponentShutdown
*====================================================================
*/
public void shutdown()
{
LinkedList shut_list = new LinkedList(m_qname_to_service.values());
m_qname_to_service.clear();
m_index_to_service.clear();
while (shut_list.size()>0)
{ // shut down this community service
CommunityServiceController csc = ((CommunityServiceDescriptor)(shut_list.removeFirst())).getController();
csc.shutdown();
} // end while
} // end shutdown
} // end class ServiceShutdown
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
@@ -162,6 +287,8 @@ public class CommunityManager
private CategoryService m_cats; // category service object
private ReferenceMap m_id_to_comm; // ReferenceMap of community IDs to communities
private ReferenceMap m_alias_to_comm; // ReferenceMap of community aliases to communities
private Hashtable m_qname_to_service; // maps service QualifiedNameKeys to descriptord
private Hashtable m_index_to_service; // maps service index numbers to descriptors
private ComponentShutdown m_pszreg; // property serializer registration
/*--------------------------------------------------------------------------------
@@ -173,6 +300,8 @@ public class CommunityManager
{
m_id_to_comm = new ReferenceMap(ReferenceMap.HARD,ReferenceMap.SOFT);
m_alias_to_comm = new ReferenceMap(ReferenceMap.HARD,ReferenceMap.SOFT);
m_qname_to_service = new Hashtable();
m_index_to_service = new Hashtable();
} // end constructor
@@ -307,6 +436,10 @@ public class CommunityManager
(PropertySerializerRegistration)(services.queryService(PropertySerializerRegistration.class));
m_pszreg = psreg.registerPropertySerializer(new CommunitySerializer());
// Register our ServiceInit class as a pre-stage init hook.
FinalStageRegistration fsreg = (FinalStageRegistration)(services.queryService(FinalStageRegistration.class));
fsreg.registerFinalStageInitHook(new ServiceInit());
} // end initialize
/*--------------------------------------------------------------------------------
@@ -379,7 +512,7 @@ public class CommunityManager
rc = (CommunityImpl)(m_alias_to_comm.get(data.get(CommunityManagerOps.KEY_ALIAS)));
if (rc==null)
{ // create the CommunityImpl object
rc = new CommunityImpl(m_ops.getCommunityOps(),m_ns_cache,m_srm,m_users,m_alook,m_post,m_cats,data);
rc = new CommunityImpl(this,m_ops.getCommunityOps(),m_ns_cache,m_srm,m_users,m_alook,m_post,m_cats,data);
// poke the maps with the new object
m_id_to_comm.put(key,rc);
@@ -416,7 +549,7 @@ public class CommunityManager
rc = (CommunityImpl)(m_id_to_comm.get(key));
if (rc==null)
{ // create the CommunityImpl object
rc = new CommunityImpl(m_ops.getCommunityOps(),m_ns_cache,m_srm,m_users,m_alook,m_post,m_cats,data);
rc = new CommunityImpl(this,m_ops.getCommunityOps(),m_ns_cache,m_srm,m_users,m_alook,m_post,m_cats,data);
// poke the maps with the new object
m_id_to_comm.put(key,rc);
@@ -495,6 +628,38 @@ public class CommunityManager
} // end getNumCommunitiesInCategory
public List getAvailableServices()
{
if (m_qname_to_service.isEmpty())
return Collections.EMPTY_LIST;
ArrayList rc = new ArrayList(m_qname_to_service.values());
Collections.sort(rc,new Comparator()
{
public int compare(Object o1, Object o2)
{
String s1 = ((CommunityServiceDescriptor)o1).getDescription();
String s2 = ((CommunityServiceDescriptor)o2).getDescription();
return s1.compareTo(s2);
} // end compare
public boolean equals(Object obj)
{
return false;
} // end equals
}); // end Comparator object
return Collections.unmodifiableList(rc);
} // end getAvailableServices
public CommunityServiceDescriptor getServiceForID(int id)
{
return (CommunityServiceDescriptor)(m_index_to_service.get(new Integer(id)));
} // end getServiceForID
/*--------------------------------------------------------------------------------
* Implementations from interface CommunityProxyService
*--------------------------------------------------------------------------------

View File

@@ -43,6 +43,13 @@ abstract class CommunityManagerOps extends OpsBase
static final String KEY_ACCESS = "access";
static final String KEY_UPDATE = "update";
static final String KEY_SVCID = "svcid";
static final String KEY_SVCNAME = "svcname";
static final String KEY_MODNAME = "modname";
static final String KEY_MODFILENAME = "modfilename";
static final String KEY_OBJNAME = "objname";
static final String KEY_SHORTVAR = "shortvar";
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
@@ -83,6 +90,8 @@ abstract class CommunityManagerOps extends OpsBase
abstract int searchNameCount(SearchMode mode, String term, boolean show_all) throws DatabaseException;
abstract List getMasterServiceList() throws DatabaseException;
/*--------------------------------------------------------------------------------
* External static operations
*--------------------------------------------------------------------------------

View File

@@ -22,6 +22,7 @@ import java.util.*;
import com.silverwrist.util.*;
import com.silverwrist.dynamo.except.*;
import com.silverwrist.dynamo.iface.*;
import com.silverwrist.dynamo.util.*;
import com.silverwrist.venice.CommunityVisibility;
import com.silverwrist.venice.SearchMode;
@@ -543,4 +544,52 @@ public class CommunityManagerOps_mysql extends CommunityManagerOps
} // end searchNameCount
List getMasterServiceList() 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 svcid, svc_nsid, svc_name, mod_nsid, mod_name, mod_filename, obj_nsid, "
+ "obj_name, shortvar FROM commsvc_master;");
rs = stmt.executeQuery();
// prepare the return value
ArrayList rc = new ArrayList();
while (rs.next())
{ // load values into a Map
HashMap tmp = new HashMap();
tmp.put(KEY_SVCID,new Integer(rs.getInt(1)));
tmp.put(KEY_SVCNAME,new PropertyKey(rs.getInt(2),rs.getString(3)));
tmp.put(KEY_MODNAME,new PropertyKey(rs.getInt(4),rs.getString(5)));
tmp.put(KEY_MODFILENAME,rs.getString(6));
tmp.put(KEY_OBJNAME,new PropertyKey(rs.getInt(7),rs.getString(8)));
tmp.put(KEY_SHORTVAR,rs.getString(9));
rc.add(tmp);
} // end while
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 getMasterServiceList
} // end class CommunityManagerOps_mysql

View File

@@ -31,3 +31,5 @@ auth.grantAccess=You are not authorized to grant access to community "{0}."
auth.revokeAccess=You are not authorized to revoke access grants in community "{0}."
join.disallowed=You are not permitted to join community "{0}."
join.authFail=Unable to authenticate to community "{0}"; cannot join.
svc.modname.mismatch=The name of the service module "{0}" did not match the name stored in the database.
svc.object.badType=The service controller object {0}::{1} was of the wrong type.

View File

@@ -80,4 +80,6 @@ abstract class CommunityOps extends OpsBase
abstract void deleteSingleUseAuthData(int cid, int ugid, boolean is_group) throws DatabaseException;
abstract int[] getServiceIDs(int cid) throws DatabaseException;
} // end class CommunityOps

View File

@@ -1011,4 +1011,45 @@ class CommunityOps_mysql extends CommunityOps
} // end deleteSingleUseAuthData
int[] getServiceIDs(int cid) 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 svcid FROM commsvc WHERE cid = ?;");
stmt.setInt(1,cid);
rs = stmt.executeQuery();
// extract the initial results
ArrayList tmp = new ArrayList();
while (rs.next())
tmp.add(new Integer(rs.getInt(1)));
// create the actual return value
int[] rc = new int[tmp.size()];
for (int i=0; i<tmp.size(); i++)
rc[i] = ((Integer)(tmp.get(i))).intValue();
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 getServiceIDs
} // end class CommunityOps_mysql

View File

@@ -609,6 +609,12 @@ abstract class CommunityProxy implements VeniceCommunity, DynamicWrapper
} // end isAdministrator
public List getServices() throws DatabaseException
{
return getRealCommunity().getServices();
} // end getServices
/*--------------------------------------------------------------------------------
* Implementations from interface DynamicWrapper
*--------------------------------------------------------------------------------

View File

@@ -50,4 +50,8 @@ public interface CommunityService
public int getNumCommunitiesInCategory(DynamoUser caller, VeniceCategory cat) throws DatabaseException;
public List getAvailableServices();
public CommunityServiceDescriptor getServiceForID(int id);
} // end interface CommunityService

View File

@@ -0,0 +1,83 @@
/*
* 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 <http://www.mozilla.org/MPL/>.
*
* 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 <erbo@silcom.com>,
* 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.community;
import com.silverwrist.dynamo.util.*;
import com.silverwrist.venice.iface.*;
public final class CommunityServiceDescriptor
{
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private int m_index;
private QualifiedNameKey m_qname;
private String m_shortvar;
private CommunityServiceController m_csc;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
CommunityServiceDescriptor(Integer index, QualifiedNameKey qname, String shortvar, CommunityServiceController csc)
{
m_index = index.intValue();
m_qname = qname;
m_shortvar = shortvar;
m_csc = csc;
} // end constructor
/*--------------------------------------------------------------------------------
* Package-internal operations
*--------------------------------------------------------------------------------
*/
CommunityServiceController getController()
{
return m_csc;
} // end getController
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
public int getIndex()
{
return m_index;
} // end getindex
public QualifiedNameKey getName()
{
return m_qname;
} // end getName
public String getDescription()
{
return m_csc.getDescription();
} // end getDescription
} // end class CommunityServiceDescriptor

View File

@@ -0,0 +1,60 @@
/*
* 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 <http://www.mozilla.org/MPL/>.
*
* 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 <erbo@silcom.com>,
* 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.except;
import com.silverwrist.dynamo.except.ExternalException;
public class CommunityServiceException extends ExternalException
{
/*--------------------------------------------------------------------------------
* Constructors
*--------------------------------------------------------------------------------
*/
/**
* Constructs a new <CODE>CommunityServiceException</CODE> instance.
*
* @param caller The classname of the class that's creating the exception. Its class loader
* and package name will be used, together with <CODE>bundle</CODE>, to find the
* resource bundle.
* @param bundle The name of the resource bundle to be loaded.
* @param message_id The identifier of the message to be loaded from the bundle.
*/
public CommunityServiceException(Class caller, String bundle, String message_id)
{
super(caller,bundle,message_id);
} // end constructor
/**
* Constructs a new <CODE>CommunityServiceException</CODE> instance.
*
* @param caller The classname of the class that's creating the exception. Its class loader
* and package name will be used, together with <CODE>bundle</CODE>, to find the
* resource bundle.
* @param bundle The name of the resource bundle to be loaded.
* @param message_id The identifier of the message to be loaded from the bundle.
* @param inner The exception to be nested inside this one.
*/
public CommunityServiceException(Class caller, String bundle, String message_id, Throwable inner)
{
super(caller,bundle,message_id,inner);
} // end constructor
} // end class CommunityServiceException

View File

@@ -0,0 +1,27 @@
/*
* 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 <http://www.mozilla.org/MPL/>.
*
* 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 <erbo@silcom.com>,
* 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.iface;
import com.silverwrist.dynamo.iface.ComponentShutdown;
import com.silverwrist.dynamo.iface.DynamicObject;
public interface CommunityServiceController extends DynamicObject, ComponentShutdown
{
public String getDescription();
} // end interface CommunityServiceController

View File

@@ -20,6 +20,7 @@ package com.silverwrist.venice.iface;
import java.security.Principal;
import java.security.acl.AclNotFoundException;
import java.util.Date;
import java.util.List;
import com.silverwrist.dynamo.except.AuthenticationException;
import com.silverwrist.dynamo.except.DatabaseException;
import com.silverwrist.dynamo.except.DynamoSecurityException;
@@ -313,4 +314,6 @@ public interface VeniceCommunity extends NamedObject, SecureObjectStore
public boolean isAdministrator(DynamoUser user);
public List getServices() throws DatabaseException;
} // end interface VeniceCommunity