Java tutorial
/** * Copyright (c) 2001-2012 "Redbasin Networks, INC" [http://redbasin.org] * * This file is part of Redbasin OpenDocShare community project. * * Redbasin OpenDocShare is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package dao; import java.io.File; import java.sql.Connection; import java.util.*; import javax.sql.DataSource; import model.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jboss.cache.Fqn; import san.FileSystemImpl; import util.DbConstants; import util.SanConstants; import util.RegexStrUtil; import util.WebUtil; // certified to be heap efficient 3/31/2005 /** * <B>CollabrumDaoDb</B> * <BR> * This object implements CollabrumDao interface. * * This interface defines how to access data from a data source. * This Dao uses multiple tables: * - collabrum, colladmin, collmembers, dircoll are not partitioned. * - other tables are partitioned based on collabrumid * * One implementation for each data source is required. For instance * we can have one implementation for JDBC and one for search index. * * * @author Smitha Gudur (smitha@redbasin.com) * @version $Revision: 1.1 $ */ public class CollabrumDaoDb extends DirectoryAbstractDao implements CollabrumDao { protected final Log logger = LogFactory.getLog(getClass()); // these obejcts are set by spring // private volatile DiaryAdmin diaryAdmin; //private volatile ExpiringObjectPool eop; private volatile CollabrumAddQuery addQuery; private volatile CollabrumDeleteQuery deleteQuery; private volatile CollabrumUpdateQuery updateQuery; private volatile CollHitsQuery collHitsUpdateQuery; //private volatile CollabrumQuery getQuery; private volatile BasicQuery getQuery; private volatile CollabrumAddAdminQuery addAdminQuery; private volatile CollabrumDeleteAdminQuery deleteAdminQuery; private volatile CollModeratorsListQuery listModeratorQuery; //private volatile CollabrumAdminExistsQuery adminExistsQuery; // members private volatile CollMembersDeleteQuery deleteMemberQuery; private volatile CollMembersAddQuery addMemberQuery; private volatile CollMemberAddBlockQuery addBlockMemberQuery; private volatile CollAllMembersDeleteQuery deleteAllMembersQuery; //private volatile CollMembersQuery membersQuery; //private volatile CollMembersNumQuery membersNumQuery; //private volatile CollMemberExistsQuery isMemberQuery; private volatile BasicQuery membersQuery; private volatile BasicQuery membersNumQuery; private volatile BasicQuery isMemberQuery; private volatile DirCollAddQuery addDircollQuery; private volatile DirCollDeleteQuery deleteDircollQuery; // private volatile DirAdminExistsQuery diradminexistsQuery; //private volatile ColTopicExistsQuery topicExistsQuery; //private volatile DirectoryScopeQuery scopeQuery; //private volatile CollabrumViewQuery collabrumViewQuery; private volatile BasicQuery topicExistsQuery; private volatile BasicQuery scopeQuery; private volatile BasicQuery collabrumViewQuery; private volatile DeleteColBlobTagsQuery deleteColBlobTagsQuery; private volatile ColStreamBlobDeleteQuery deleteStreamblobQuery; private volatile ColStreamBlobAddQuery addStreamblobQuery; private volatile ColStreamBlobUpdateQuery updateStreamblobQuery; private volatile CollabrumDefaultDeleteQuery deleteDefQuery; private volatile CollabrumDefaultAddQuery addDefQuery; //private volatile ColOneStreamBlobQuery oneStreamblobQuery; //private volatile ColStreamBlobQuery streamblobQuery; //private volatile ColStreamsDataQuery getAllStreamDataQuery; //private volatile ColBlobQuery blobQuery; //private volatile CollabrumDefaultQuery defaultQuery; //private volatile CollabrumDefaultPhotoQuery defaultblobQuery; //private volatile ColStreamsByCategoryQuery blobCategoryQuery; //private volatile ColStreamPhotoExistsQuery photoExistsQuery; private volatile BasicQuery oneStreamblobQuery; private volatile BasicQuery streamblobQuery; private volatile BasicQuery getAllStreamDataQuery; private volatile BasicQuery blobQuery; private volatile BasicQuery defaultQuery; private volatile BasicQuery defaultblobQuery; private volatile BasicQuery blobCategoryQuery; private volatile BasicQuery photoExistsQuery; // private volatile ColStreamFileEntriesQuery filesQuery; private volatile CollMemberBlockQuery listBlockedCollabrumsQuery; //private volatile CollabrumCobrandQuery cobrandQuery; //private volatile CollabrumOrganizersQuery getOrganizersQuery; //private volatile CollabrumTopQuery collabrumTopQuery; /* * not required anymore * private volatile CollTrafficQuery collTrafficQuery; * private volatile BasicQuery collTrafficQuery; * private volatile DeleteColTrafficPerCollabrumQuery deleteColTrafficQuery; */ private volatile BasicQuery cobrandQuery; private volatile BasicQuery getOrganizersQuery; private volatile BasicQuery collabrumTopQuery; /** * delete queries */ private volatile DeleteColTopicsPerCollabrumQuery deleteColTopicsQuery; private volatile DeleteColTopicAttrPerCollabrumQuery deleteColTopicsAttrQuery; private volatile DeleteColCobrandPerCollabrumQuery deleteColCobrandQuery; private volatile ColStreamBlobDeleteAllQuery deleteAllCollBlobs; /** * delete all collabrum messages and message attributes */ private volatile DeleteColMessagePerTidQuery deleteColMessagesQuery; private volatile DeleteColMessageAttrPerTidQuery deleteColMsgAttrQuery; //private volatile ColTopicsIdQuery getTidsQuery; //private volatile ColRidsQuery getRidsQuery; //private volatile ColStreamBlobEntriesQuery getBlobEntryListQuery; //private volatile CollMembersPerCollabrumQuery getCollabrumMembersQuery; private volatile BasicQuery getTidsQuery; private volatile BasicQuery getRidsQuery; private volatile BasicQuery getBlobEntryListQuery; private volatile BasicQuery getCollabrumMembersQuery; private volatile DeleteColBlogTagsQuery deleteColBlogTagsQuery; private volatile DeleteCollabrumIndexQuery deleteCollabrumIndexQuery; private volatile DeleteColBlobIndexQuery deleteColBlobIndexQuery; private volatile DeleteColMessagesIndexQuery deleteColMessagesIndexQuery; private volatile DeleteColTopicsIndexQuery deleteColTopicsIndexQuery; private volatile DeleteColBlockedMembersQuery deleteBlockedMembersQuery; private volatile CollBlobTagsAddQuery addTagQuery; private volatile CollBlobTagsUpdateQuery updateTagsQuery; private volatile BasicQuery tagsQuery; private volatile BasicQuery allTagsQuery; private volatile CollBlobEntryIdQuery getEntryIdQuery; private volatile CollBlobTagsDeleteQuery deleteTagsQuery; //CollBlobTagsQuery - tagsQuery //CollBlobTagsAllQuery - allTagsQuery /** * Create a new collabrum. The path, createdate, moddate is automatically set by the create que * @param parentId this is the parent node, if root, parent is -1 * @param name the name of the collabrum, need not be unique * @param userId this is the userId name on this server that is already authenticated, if required * @param desc this is the description of this collabrum * @param keywords this is the keywords of this collabrum * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void createCollabrum(String parentId, String name, String userId, String desc, String keywords, String userLogin, String style) throws BaseDaoException { if (RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(parentId) || RegexStrUtil.isNull(name) || RegexStrUtil.isNull(style)) { throw new BaseDaoException("params are null"); } boolean isAddable = false; if (diaryAdmin.isDiaryAdmin(userLogin)) { isAddable = true; } /** * check global flag * operations: 1 (Designate Specific Members As Authors), * 2 (Automatically Allow All Members To Be Authors) * status: 1 (Hidden), 2 (Ready) should we check for the status for operations (2) * if set to 1, check if this user is the designated author */ if (!isAddable) { DirScope dirscope = getDirectoryScope(parentId); if (dirscope.getValue(DbConstants.OPERATIONS).equals((Object) "2")) { isAddable = true; } else { if (isAuthor(parentId, userId)) { isAddable = true; } } } if (!isAddable) { StringBuffer sb = new StringBuffer("Donot have the permission to add to this directory, "); sb.append(parentId); sb.append(" userId = "); sb.append(userId); throw new BaseDaoException(sb.toString()); } /** * Get scalability datasource for collmember, dircoll, collabrum - not partitioned */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, createCollabrum() " + sourceName); } Connection conn = null; try { conn = ds.getConnection(); conn.setAutoCommit(false); //addQuery = new CollabrumAddQuery(); addQuery.run(conn, name, userId, desc, keywords, style); /** add member query **/ addMemberQuery.run(conn, "LAST_INSERT_ID()", userId); //addDircollQuery = new DirCollAddQuery(); addDircollQuery.run(conn, "LAST_INSERT_ID()", parentId); /** * The table insertion order is important as LAST_INSERT_ID * will change when we use entryId column here. For the tables below. * */ addAdminQuery.run(conn, "LAST_INSERT_ID()", userId); } catch (Exception e) { try { conn.rollback(); } catch (Exception e1) { try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e2) { StringBuffer sb = new StringBuffer( "conn.close exception for rollback(), for createCollabrum() "); sb.append("parentId = "); sb.append(parentId); sb.append(" name = "); sb.append(name); sb.append(" keywords = "); sb.append(keywords); sb.append(" userId = "); sb.append(userId); sb.append(" desc = "); sb.append(desc); throw new BaseDaoException(sb.toString(), e2); } StringBuffer sb = new StringBuffer(" rollback() exception, for createCollabrum() "); sb.append("parentId = "); sb.append(parentId); sb.append(" name = "); sb.append(name); sb.append(" keywords = "); sb.append(keywords); sb.append(" userId = "); sb.append(userId); sb.append(" desc = "); sb.append(desc); throw new BaseDaoException(sb.toString(), e1); } throw new BaseDaoException("conn error ", e); } // connection commit try { conn.commit(); } catch (Exception e3) { StringBuffer sb = new StringBuffer(" commit() exception, for createCollabrum(), parentId = "); sb.append(parentId); sb.append(" name = "); sb.append(name); sb.append(" keywords = "); sb.append(keywords); sb.append(" userId = "); sb.append(userId); sb.append(" desc = "); sb.append(desc); throw new BaseDaoException(sb.toString(), e3); } try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e4) { StringBuffer sb = new StringBuffer( " conn.close() exception, for commit(), createCollabrum() parentId = "); sb.append(parentId); sb.append(" name = "); sb.append(name); sb.append(" keywords = "); sb.append(keywords); sb.append(" userId = "); sb.append(userId); sb.append(" desc = "); sb.append(desc); throw new BaseDaoException(sb.toString(), e4); } /** * remove this directory from cache */ Fqn fqn = cacheUtil.fqn(DbConstants.DIRECTORY); if (treeCache.exists(fqn, parentId)) { treeCache.remove(fqn, parentId); } fqn = cacheUtil.fqn(DbConstants.COLLABRUM_LIST); if (treeCache.exists(fqn, parentId)) { treeCache.remove(fqn, parentId); } fqn = cacheUtil.fqn(DbConstants.USER_PAGE); if (treeCache.exists(fqn, userLogin)) { treeCache.remove(fqn, userLogin); } } /** * This deletes all topics belonging to a collabrum * @throws BaseDaoException If we have a problem interpreting the data */ private void deleteCollTopics(String collabrumId, List tidList) { /** * tidList */ for (int i = 0; i < tidList.size(); i++) { String tid = (String) ((ColTopic) tidList.get(i)).getValue(DbConstants.TID); if (RegexStrUtil.isNull(tid)) { continue; } String sourceName = scalabilityManager.getWriteScalability(tid); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, deleteCollTopics() " + sourceName + " tid = " + tid); } Connection conn = null; try { conn = ds.getConnection(); conn.setAutoCommit(false); deleteColTopicsAttrQuery.run(conn, tid); } catch (Exception e) { /** * conn.rollback() */ try { conn.rollback(); } catch (Exception e1) { try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e2) { throw new BaseDaoException( "conn.close(), deleteColtopicsAttrQuery() collabrumId = " + collabrumId, e2); } throw new BaseDaoException( " rollback() exception, deleteColTopicsAttrQuery(), collabrumId= " + collabrumId, e1); } throw new BaseDaoException("conn.close()", e); } /** * AutoCommit(true) */ try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e4) { throw new BaseDaoException( "conn.close() exception, for commit(), deleteColTopicsAttrQuery() collabrumId = ", e4); } } /** * Get scalability datasource for colltopic partitioned on collabrumid */ String sourceName = scalabilityManager.getWriteScalability(collabrumId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException( "ds null, deleteColTopicsAttrQuery() " + sourceName + " collabrumId = " + collabrumId); } /** * Partitioned on collabrumId * colltopics (deleteColTopicsQuery) * colltopicattr (deleteColTopicsAttrQuery) * colltraffic (deleteColTrafficQuery) * collcobrand (deleteCollCobrandQuery) * collblob (deleteCollBlobsQuery) */ Connection conn = null; try { conn = ds.getConnection(); if (conn == null) { throw new BaseDaoException("conn is null" + collabrumId); } conn.setAutoCommit(false); deleteColTopicsQuery.run(conn, collabrumId); deleteColCobrandQuery.run(conn, collabrumId); deleteAllCollBlobs.run(conn, collabrumId); /* not required any more * deleteColTrafficQuery.run(conn,collabrumId); */ } catch (Exception e) { try { conn.rollback(); } catch (Exception e1) { try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e2) { throw new BaseDaoException( "conn.close() exception for rollback(), for deleteCollTopics() collabrumId = " + collabrumId, e2); } throw new BaseDaoException(" rollback() exception, deleteCollTopics(), collabrumId= " + collabrumId, e1); } throw new BaseDaoException("delete exception deleteCollTopics(), collabrumId= " + collabrumId, e); } // connection commit try { conn.commit(); } catch (Exception e3) { throw new BaseDaoException("commit() exception, for deleteCollTopics() collabrumId = " + collabrumId, e3); } try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e4) { throw new BaseDaoException("conn.close() exception, for commit(), deleteCollTopics() collabrumId = ", e4); } } /** * This lists all members belonging to a collabrum * @return List - the list of members in a collabrum * @throws BaseDaoException If we have a problem interpreting the data */ private List getCollabrumMembers(String collabrumId) throws BaseDaoException { /** * Get scalability ds, collmembers not partitioned */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException( "ds null, getCollabrumMembers() " + sourceName + " collabrumId = " + collabrumId); } try { Object[] params = { (Object) collabrumId }; List membersList = getCollabrumMembersQuery.execute(params); if (membersList == null) { throw new BaseDaoException("getCollabrumMembers() is null, collabrumId = " + collabrumId); } return membersList; } catch (Exception e) { throw new BaseDaoException("error occured getCollabrumMembers()", e); } } /** * This deletes all blocked members belonging to a collabrum * @throws BaseDaoException If we have a problem interpreting the data */ private void deleteBlockedMembers(String collabrumId) throws BaseDaoException { List memberList = getCollabrumMembers(collabrumId); /** * Get scalability ds, collblock partitioned on loginId */ for (int i = 0; i < memberList.size(); i++) { String loginId = (String) ((Hdlogin) memberList.get(i)).getValue(DbConstants.LOGIN_ID); String sourceName = scalabilityManager.getWriteScalability(loginId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException( "ds null, deleteBlockedMembers() " + sourceName + " loginId = " + loginId); } Connection conn = null; try { conn = ds.getConnection(); deleteBlockedMembersQuery.run(conn, loginId); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException("deleteBlockedMembersQuery(), conn.close() error ", e2); } throw new BaseDaoException("exception, deleteBlockedMembersQuery.run() loginId = " + loginId, e); } } } /** * This lists all blobEntryList belonging to a collabrum blob * @return List - the list of entryid * @throws BaseDaoException If we have a problem interpreting the data */ private List getBlobEntryList(String collabrumId) throws BaseDaoException { /** * Get scalability ds, collblob partitioned on collabrumId * collblob */ String sourceName = scalabilityManager.getWriteScalability(collabrumId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException( "ds null, getBlobEntryList() " + sourceName + " collabrumId = " + collabrumId); } try { Object[] params = { (Object) collabrumId }; List entryList = getBlobEntryListQuery.execute(params); if (entryList == null) { throw new BaseDaoException("getBlobEntryList() is null, collabrumId = " + collabrumId); } return entryList; } catch (Exception e) { throw new BaseDaoException("error occured getBlobEntryList()", e); } } /** * This lists all rids belonging to a tid * @return List the list of rids * @throws BaseDaoException If we have a problem interpreting the data */ private List getRidList(String tid) throws BaseDaoException { /** * Get scalability ds, collmessages partitioned on tid * collmessages */ String sourceName = scalabilityManager.getWriteScalability(tid); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getRidList() " + sourceName + " tid = " + tid); } try { Object[] params = { (Object) tid }; List ridList = getRidsQuery.execute(params); if (ridList == null) { throw new BaseDaoException("ridList() is null, tid = " + tid); } return ridList; } catch (Exception e) { throw new BaseDaoException("error occured getRidList()", e); } } /** * This lists all tids belonging to a collabrum * @return List - the list of entryid * @throws BaseDaoException If we have a problem interpreting the data */ private List getTidList(String collabrumId) throws BaseDaoException { /** * Get scalability ds, topics partitioned on collabrumid * colltopics */ String sourceName = scalabilityManager.getReadScalability(collabrumId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getTidList(), " + sourceName + " collabrumId = " + collabrumId); } try { Object[] params = { (Object) collabrumId }; List tidList = getTidsQuery.execute(params); if (tidList == null) { throw new BaseDaoException("collabrum tids null getTidList(), collabrumId " + collabrumId); } return tidList; } catch (Exception e) { throw new BaseDaoException("error occured getTidList()", e); } } /** * This deletes all messages belonging to a collabrum * @throws BaseDaoException If we have a problem interpreting the data */ private void deleteCollMessages(String collabrumId, List tidList) throws BaseDaoException { /** * Get scalability datasource, for messages partitioned on tid * - collmessages * - collmsgattr */ for (int i = 0; i < tidList.size(); i++) { String tid = (String) ((ColTopic) tidList.get(i)).getValue(DbConstants.TID); String sourceName = scalabilityManager.getWriteScalability(tid); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, deleteCollMessages() " + sourceName + " tid = " + tid); } Connection conn = null; try { conn = ds.getConnection(); conn.setAutoCommit(false); deleteColMessagesQuery.run(conn, tid); deleteColMsgAttrQuery.run(conn, tid); } catch (Exception e) { try { conn.rollback(); } catch (Exception e1) { try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e2) { throw new BaseDaoException( "conn.close exception for rollback(), for deleteCollMessages() tid = " + tid + " collabrumId = " + collabrumId, e2); } throw new BaseDaoException(" rollback() exception deleteCollMessages(), tid=" + tid + "collabrumId = " + collabrumId, e1); } throw new BaseDaoException( "delete exception deleteCollMessages(), tid=" + tid + " collabrumId = " + collabrumId, e); } // connection commit try { conn.commit(); } catch (Exception e3) { throw new BaseDaoException( "commit() exception, for deleteCollMessages() collabrumId = " + collabrumId, e3); } try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e4) { throw new BaseDaoException( "conn.close() exception, for commit(), deleteCollMessages() collabrumId = ", e4); } } } /** * Get a collabrum for updating this collabrum. check user permissions for this purpose * @param collabrumId the controller will need the collabrumId to get this bean * @param userId userId to check permission for getting * @return Collabrum the collabrum bean returned is for editing collabrum * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public Collabrum getCollabrum(String collabrumId, String userId, String userLogin) throws BaseDaoException { if (RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(collabrumId)) { throw new BaseDaoException("params are null"); } /** * check user permissions (isDiaryAdmin or isOrganizer both are checked */ if (!isOrganizer(collabrumId, userLogin, userId)) { StringBuffer sb = new StringBuffer("User does not have permission to edit collabrum, getCollabrum(), "); sb.append(collabrumId); sb.append(" userId = "); sb.append(userId); throw new BaseDaoException(sb.toString()); } /** Jboss methods * fqn - full qualified name * check if the userpage already set in the cache * If it exists, return the userpage from the cache. */ Fqn fqn = cacheUtil.fqn(DbConstants.COLLABRUM_EDIT); Object obj = treeCache.get(fqn, collabrumId); if (obj != null) { return (Collabrum) obj; } return getCollabrum(collabrumId); } /** * GetCollabrum, retrieves the collabrum from database based on collabrumId. * @param collabrumId - the collabrum id * @return Collabrum - the <code>Collabrum</code> * @throws BaseDaoException - when error occurs */ private Collabrum getCollabrum(String collabrumId) { if (RegexStrUtil.isNull(collabrumId)) { throw new BaseDaoException("params are null"); } /** Jboss methods * fqn - full qualified name * check if the userpage already set in the cache * If it exists, return the userpage from the cache. */ Fqn fqn = cacheUtil.fqn(DbConstants.COLLABRUM_EDIT); Object obj = treeCache.get(fqn, collabrumId); if (obj != null) { return (Collabrum) obj; } /** * Get scalability datasource for collabrum, not partitioned */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds null, getCollabrum() "); sb.append(sourceName); sb.append(" collabrumId = "); sb.append(collabrumId); throw new BaseDaoException(sb.toString()); } List result = null; Collabrum collabrum = null; try { result = getQuery.execute(collabrumId); } catch (Exception e1) { throw new BaseDaoException("exception while getting collabrum, for collabrumId = " + collabrumId, e1); } if (result != null && result.size() > 0) { collabrum = (Collabrum) result.get(0); } else { throw new BaseDaoException("cannot retrieve collabrum as it does not exist " + collabrumId); } if (collabrum == null) { throw new BaseDaoException("Collabrum is null " + collabrumId); } String ownerId = collabrum.getValue(DbConstants.OWNER_ID); Hdlogin hdlogin = getLogin(ownerId); collabrum.setObject(DbConstants.OWNER_INFO, hdlogin); /** * #members */ collabrum.setValue(DbConstants.NUM_MEMBERS, "0"); String num = null; Object[] params = { (Object) collabrumId }; try { result = membersNumQuery.execute(params); if (result != null) { if (result.size() > 0) { num = ((Collabrum) result.get(0)).getValue("count(*)"); collabrum.setValue(DbConstants.NUM_MEMBERS, num); } } } catch (Exception e) { throw new BaseDaoException("exception in membersNumQuery, " + membersNumQuery.getSql()); } /** * Get scalability datasource based on collabrumid for table * colltraffic partitioned on collabrumid **/ sourceName = scalabilityManager.getReadScalability(collabrumId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null, getCollabrum, collabrumDaoDb "); sb.append(sourceName); sb.append(" collabrumId = "); sb.append(collabrumId); throw new BaseDaoException(sb.toString()); } /** * #hits */ /* collabrum.setValue(DbConstants.HITS, "0"); try { result = collTrafficQuery.execute(params); if (result != null) { if (result.size() > 0) { num = ((Collabrum)result.get(0)).getValue("count(*)"); collabrum.setValue(DbConstants.HITS, num); // work on this later collabrum.setValue(DbConstants.POPULARITY, num); } } } catch(Exception e) { throw new BaseDaoException("exception in traffic, hitsquery, " + collTrafficQuery.getSql()); } */ /* Hits = 250 Total Collabrums = 30000 Num Collabrums with Hits > 250 = 10 Popularity = (100 - ((10/30000)*100)) */ if (collabrum != null) { treeCache.put(fqn, collabrumId, collabrum); } return collabrum; } /** * Updates collabrum description and keywords * @param userId the id of the user * @param collabrumId the collabrum id * @param desc this is the description of this collabrum * @param keywords the keywords for this collabrum * @param userLogin the userLogin * @param directoryId the directory id * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void updateCollabrum(String userId, String collabrumId, String desc, String keywords, String userLogin, String directoryId) throws BaseDaoException { if (RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(collabrumId) || RegexStrUtil.isNull(directoryId)) { throw new BaseDaoException("params are null"); } /** * check user permissions- diaryAdmin & isOrganizer are checked */ if (!isOrganizer(collabrumId, userLogin, userId)) { StringBuffer sb = new StringBuffer("User does not have permission to update collabrum, "); sb.append(collabrumId); sb.append(" userId = "); sb.append(userId); throw new BaseDaoException(sb.toString()); } /** * Get scalability datasource, collabrum table - not partitioned. */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null for updateCollabrum() "); sb.append(sourceName); sb.append(" collabrumId = "); sb.append(collabrumId); throw new BaseDaoException(sb.toString()); } Connection conn = null; try { conn = ds.getConnection(); updateQuery.run(conn, collabrumId, desc, keywords); } catch (Exception e1) { try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException("updatecollabrum conn.close() error ", e2); } StringBuffer sb = new StringBuffer("exception while updating, for user id + "); sb.append(userId); sb.append(" collabrumId = "); sb.append(collabrumId); sb.append(" desc = "); sb.append(desc); throw new BaseDaoException(sb.toString()); } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("updatecollabrum conn.close() error ", e); } /** * Jboss methods * fqn - full qualified name * check if the collabrum already exists in the cache * If it exists, remove the collabrum from the cache. * This will enable to get the updated collabrum when the user does getCollabrum(); */ Fqn fqn = cacheUtil.fqn(DbConstants.COLLABRUM); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.COLLABRUM_EDIT); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.COLLABRUM_LIST); if (treeCache.exists(fqn, directoryId)) { treeCache.remove(fqn, directoryId); } } /** * Deletes a list of collabrums that exist in a directory * This deletes all the resources associated with a collabrum: * - blogging * - images/streamblobs * - members * - tags associated with blogging/stream blobs * - indexes * @param directoryId the directory id * @param collabrumIdList the list of collabrum id belonging to a directory * @param userId the userId to be verified for deletion permission * @param userLogin the userId to be verified for deletion permission * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void deleteDirCollabrums(String directoryId, ArrayList collabrumIdList, String userId, String userLogin) throws BaseDaoException { if (RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(directoryId) || RegexStrUtil.isNull(userLogin) || collabrumIdList == null) { throw new BaseDaoException("params are null"); } for (int i = 0; i < collabrumIdList.size(); i++) { deleteRBCollabrum(directoryId, (String) collabrumIdList.get(i), userId, userLogin); } } /** * Delete a collabrum * This deletes all the resources associated with a collabrum: * - blogging * - images/streamblobs * - members * - tags associated with blogging/stream blobs * - indexes * @param directoryId - the directory id * @param collabrumId the collabrum id * @param userId the userId to be verified for deletion permission * @param userLogin the userId to be verified for deletion permission * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void deleteCollabrum(String directoryId, String collabrumId, String userId, String userLogin) throws BaseDaoException { if (RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(collabrumId) || RegexStrUtil.isNull(directoryId) || RegexStrUtil.isNull(userLogin)) { throw new BaseDaoException("params are null"); } /** * check if this collabrum has messages. * Throw error if there are messages. */ /* if (doesTopicExist(collabrumId)) { throw new BaseDaoException("cannot delete collabrum, as topics exist. " + collabrumId); } */ /** * check user permissions - diaryAdmin & isOrganizer are checked */ if (!isOrganizer(collabrumId, userLogin, userId)) { StringBuffer sb = new StringBuffer("User does not have permission to delete collabrum, "); sb.append(collabrumId); sb.append(" userId = "); sb.append(userId); throw new BaseDaoException(sb.toString()); } deleteRBCollabrum(directoryId, collabrumId, userId, userLogin); } private void deleteRBCollabrum(String directoryId, String collabrumId, String userId, String userLogin) throws BaseDaoException { if (RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(collabrumId) || RegexStrUtil.isNull(directoryId) || RegexStrUtil.isNull(userLogin)) { throw new BaseDaoException("params are null"); } List tidList = getTidList(collabrumId); List blobEntryList = getBlobEntryList(collabrumId); Vector ridVector = new Vector(); for (int i = 0; i < tidList.size(); i++) { /* get list of rids from collmessages */ List ridList = getRidList((String) ((ColTopic) tidList.get(i)).getValue(DbConstants.TID)); ridVector.add(ridList); } /** * get the members list from collmembers, then access each record in this table * collblock (deleteAllColBlockQuery) partitioned on loginid * deleteColBlockQuery.run(conn, collabrumId); */ deleteBlockedMembers(collabrumId); /** * Get scalability datasource with no partitions for colladmin, collmembers, dircoll, collabrum */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null, deleteCollabrum() "); sb.append(sourceName); sb.append(" collabrumId = "); sb.append(collabrumId); throw new BaseDaoException(sb.toString()); } HashSet result = null; Connection conn = null; /** * non partitioned tables */ try { conn = ds.getConnection(); conn.setAutoCommit(false); result = listModeratorQuery.run(conn, collabrumId); /** * Not partitioned * collabrum, (deleteQuery) * colladmin (deleteAdminQuery) * dircoll (deleteDirColQuery) * collmembers (deleteColMembersQuery), * * collblobtags (deleteColBlobTagsQuery) * collblogtags (deleteColBlogTagsQuery) * collabrum_ind, (deleteCollabrumIndexQuery) * collblob_ind, (deleteColBlobIndexQuery) * collmessages_ind, (deleteColMessagesIndexQuery) * colltopics_ind, (deleteColTopicsIndexQuery) */ deleteQuery.run(conn, collabrumId); deleteAdminQuery.run(conn, collabrumId); deleteDircollQuery.run(conn, collabrumId); deleteAllMembersQuery.run(conn, collabrumId); /* new ones */ deleteColBlobTagsQuery.run(conn, collabrumId); deleteColBlogTagsQuery.run(conn, collabrumId); deleteCollabrumIndexQuery.run(conn, collabrumId); for (int i = 0; i < blobEntryList.size(); i++) { deleteColBlobIndexQuery.run(conn, (String) ((Photo) blobEntryList.get(i)).getValue(DbConstants.ENTRYID)); } for (int i = 0; i < tidList.size(); i++) { deleteColTopicsIndexQuery.run(conn, (String) ((ColTopic) tidList.get(i)).getValue(DbConstants.TID)); } for (int i = 0; i < ridVector.size(); i++) { List ridList = (List) ridVector.elementAt(i); for (int j = 0; i < ridList.size(); j++) { deleteColMessagesIndexQuery.run(conn, (String) ((ColMessage) ridList.get(j)).getValue(DbConstants.RID)); } } } catch (Exception e) { try { conn.rollback(); } catch (Exception e1) { try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e2) { StringBuffer sb = new StringBuffer( "conn.close exception for rollback(), for deleteCollabrum() "); sb.append("collabrumId = "); sb.append(collabrumId); sb.append(" userId = "); sb.append(userId); throw new BaseDaoException(sb.toString(), e2); } StringBuffer sb = new StringBuffer(" rollback() exception, for deleteCollabrum() "); sb.append("collabrumId = "); sb.append(collabrumId); sb.append(" userId = "); sb.append(userId); throw new BaseDaoException(sb.toString(), e1); } } // connection commit try { conn.commit(); } catch (Exception e3) { StringBuffer sb = new StringBuffer(" commit() exception, for deleteCollabrum() collabrumId = "); sb.append(collabrumId); sb.append(" userId = "); sb.append(userId); throw new BaseDaoException(sb.toString(), e3); } try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e4) { StringBuffer sb = new StringBuffer( " conn.close() exception, for commit(), deleteCollabrum() collabrumId = "); sb.append(collabrumId); sb.append(" userId = "); sb.append(userId); throw new BaseDaoException(sb.toString(), e4); } deleteCollMessages(collabrumId, tidList); deleteCollTopics(collabrumId, tidList); /** * Jboss methods * fqn - full qualified name * check if the collabrum already exists in the cache * If it exists, remove the collabrum from the cache */ Fqn fqn = cacheUtil.fqn(DbConstants.COLLABRUM); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.ORGANIZERS); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.COLLABRUM_EDIT); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.DIRECTORY); if (treeCache.exists(fqn, directoryId)) { treeCache.remove(fqn, directoryId); } fqn = cacheUtil.fqn(DbConstants.COLTOPICS); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.COLTRAFFIC); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } /** * delete collabrum messages */ for (int i = 0; i < tidList.size(); i++) { StringBuffer sb = new StringBuffer(collabrumId); sb.append("-"); sb.append(tidList.get(i)); String key = sb.toString(); fqn = cacheUtil.fqn(DbConstants.COLMSGS); if (treeCache.exists(fqn, key)) { treeCache.remove(fqn, key); } fqn = cacheUtil.fqn(DbConstants.COLTOPIC); if (treeCache.exists(fqn, key)) { treeCache.remove(fqn, key); } } fqn = cacheUtil.fqn(DbConstants.COLLABRUM_STREAM_BLOBS); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } // deleting user pages for each admin as we want them to be updated if ((result != null) && (result.size() > 0)) { Iterator it = result.iterator(); StringBuffer sb = new StringBuffer(); while (it.hasNext()) { Collabrum collabrum = (Collabrum) it.next(); String adminUser = collabrum.getValue(DbConstants.LOGIN); if (!RegexStrUtil.isNull(adminUser)) { fqn = cacheUtil.fqn(DbConstants.USER_PAGE); if (treeCache.exists(fqn, adminUser)) { treeCache.remove(fqn, adminUser); } fqn = cacheUtil.fqn(DbConstants.MEM_AS_ORGANIZER_LIST); if (treeCache.exists(fqn, adminUser)) { treeCache.remove(fqn, adminUser); } fqn = cacheUtil.fqn(DbConstants.MEM_AS_MODERATOR_LIST); if (treeCache.exists(fqn, adminUser)) { treeCache.remove(fqn, adminUser); } String adminId = collabrum.getValue(DbConstants.LOGIN_ID); fqn = cacheUtil.fqn(DbConstants.BLOCKED_COLLABRUM_LIST); if (treeCache.exists(fqn, adminId)) { treeCache.remove(fqn, adminId); } // delete organizer key = collabrumid-memberid sb.delete(0, sb.length()); sb.append(collabrumId); sb.append("-"); sb.append(adminId); fqn = cacheUtil.fqn(DbConstants.ORGANIZER); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } } } } fqn = cacheUtil.fqn(DbConstants.COLLABRUM_LIST); if (treeCache.exists(fqn, directoryId)) { treeCache.remove(fqn, directoryId); } /** * Jboss methods - * fqn - full qualified name * check if the streamblob already set in the cache * If it exists, remove the bean from the cache. */ for (int i = 0; i < blobEntryList.size(); i++) { String entryId = (String) ((Photo) blobEntryList.get(i)).getValue(DbConstants.ENTRYID); fqn = cacheUtil.fqn(DbConstants.PHOTO); if (treeCache.exists(fqn, entryId)) { treeCache.remove(fqn, entryId); } StringBuffer buf = new StringBuffer(collabrumId); buf.append("-"); buf.append(entryId); String key = buf.toString(); fqn = cacheUtil.fqn(DbConstants.COL_STREAM_BLOB); if (treeCache.exists(fqn, key)) { treeCache.remove(fqn, key); } fqn = cacheUtil.fqn(DbConstants.DEFAULT_PHOTO); if (treeCache.exists(fqn, key)) { treeCache.remove(fqn, key); } } fqn = cacheUtil.fqn(DbConstants.COLL_CAT); StringBuffer sb = new StringBuffer(collabrumId); sb.append("-"); sb.append(DbConstants.PHOTO_CATEGORY); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } sb.delete(0, sb.length()); sb.append(collabrumId); sb.append("-"); sb.append(DbConstants.FILE_CATEGORY); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } } /** * @param collabrumId the id of the collabrum for viewing purposes without the session * @param loginid the id of the user * @param login the login of the user * @param accessFlag the access flag to retrieve the collabrum from either slave or master * @param blobAccess the blob access to retrieve the blobs from either slave or master * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect * @return Collabrum */ public Collabrum viewCollabrum(String collabrumId, String loginid, String login, int accessFlag, int blobAccess) throws BaseDaoException { return getDiaryCollabrum(collabrumId, loginid, login, accessFlag, blobAccess); } /** * @param collabrumId the id of the collabrum for viewing purposes without the session * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public Collabrum viewCollabrum(String collabrumId) throws BaseDaoException { return getDiaryCollabrum(collabrumId, null, null, DbConstants.READ_FROM_SLAVE, DbConstants.BLOB_READ_FROM_SLAVE); } /** * view the collabrum page when the user is in session, from slave. * @param collabrumId * @param loginId * @param login * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or i * @return Collabrum ncorrect */ public Collabrum viewCollabrum(String collabrumId, String loginId, String login) throws BaseDaoException { return getDiaryCollabrum(collabrumId, loginId, login, DbConstants.READ_FROM_SLAVE, DbConstants.BLOB_READ_FROM_SLAVE); } /** * @param collabrumId the id of the collabrum for viewing purposes without the session * @param loginid the login id of the user * @param login the login of the user * @param accessFlag retreive collabrum from slave(0) READ_FROM_SLAVE, master (1) READ_FROM_MASTER * @param blobAccess retreive blobs slave(0) BLOB_READ_FROM_SLAVE, master (1) BLOB_READ_FROM_MASTER * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ private Collabrum getDiaryCollabrum(String collabrumId, String userId, String userLogin, int accessFlag, int blobAccess) { /* if (RegexStrUtil.isNull(collabrumId)) { throw new BaseDaoException("params are null"); } */ /** * Unavailable in cache, get it from DB * Get scalability datasource, read from master or slave to get access to updated information */ String sourceName = ""; if (accessFlag == DbConstants.READ_FROM_MASTER) { // read from master sourceName = scalabilityManager.getWriteZeroScalability(); } else { sourceName = scalabilityManager.getReadZeroScalability(); } ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null, getDiaryCollabrum() "); sb.append(sourceName); throw new BaseDaoException(sb.toString()); } List result = null; /** * if collabrumId is not specified, get the first collabrumId * that exists in a directory */ if (RegexStrUtil.isNull(collabrumId)) { try { result = collabrumTopQuery.execute(); if ((result != null) && (result.size() > 0)) { collabrumId = (String) ((Collabrum) result.get(0)).getValue(DbConstants.COLLABRUM_ID); } else { throw new BaseDaoException(" collabrumTopQuery result is null, collabrum does not exist"); } } catch (Exception e) { throw new BaseDaoException("exception error, getting collabrum " + collabrumTopQuery.getSql(), e); } } if (RegexStrUtil.isNull(collabrumId)) { throw new BaseDaoException("collabrum does not exist"); } /** * check if the user is blocked for this collabrum, if the user is blocked, return null; */ if (!RegexStrUtil.isNull(userId)) { if (isThisMemberBlockedFromCollabrum(collabrumId, userId)) { return null; } } /** * Jboss methods * fqn - full qualified name * check if the collabrum already set in the cache * If it exists, return the collabrum from the cache. */ Fqn fqn = cacheUtil.fqn(DbConstants.COLLABRUM); Object obj = treeCache.get(fqn, collabrumId); if (obj != null) { Collabrum coll = (Collabrum) obj; /** * is organizer - not put in the cache as different users are checked for this */ if (RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(userLogin)) { coll.setValue(DbConstants.IS_ORGANIZER, "0"); } else { List organizers = (List) coll.getObject(DbConstants.ORGANIZERS); if (diaryAdmin.isDiaryAdmin(userLogin) || isUserCollOrganizer(organizers, userId)) { coll.setValue(DbConstants.IS_ORGANIZER, "1"); } else { coll.setValue(DbConstants.IS_ORGANIZER, "0"); } } /** * is member - not put in the cache */ if (RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(userLogin)) { coll.setValue(DbConstants.IS_MEMBER, "0"); } else { result = (List) coll.getObject(DbConstants.MEMBERS); if (isUserCollMember(result, userLogin)) { coll.setValue(DbConstants.IS_MEMBER, "1"); } else { coll.setValue(DbConstants.IS_MEMBER, "0"); } } return coll; } Object[] params = { (Object) collabrumId }; Collabrum coll = null; try { result = collabrumViewQuery.execute(params); if ((result != null) && (result.size() > 0)) { coll = (Collabrum) result.get(0); } else { return null; } } catch (Exception e) { throw new BaseDaoException("exception error, getting collabrum " + collabrumViewQuery.getSql(), e); } /** * set members for this collabrum, uses the same datasource as zeroscalability */ try { result = membersQuery.execute(params); if (result != null) { if (result.size() > 0) { coll.setObject(DbConstants.MEMBERS, result); } } } catch (Exception e) { throw new BaseDaoException("exception in membersQuery, " + membersQuery.getSql()); } /** * get blocked collabrums for login */ coll.setValue(DbConstants.BLOCK_MEMBER, "0"); Hdlogin hdlogin = getLogin(coll.getValue(DbConstants.OWNER_ID)); if (hdlogin != null) { coll.setObject(DbConstants.OWNER_INFO, hdlogin); } /** * set topics flag for this collabrum */ result = topicExists(collabrumId); if ((result != null) && (result.size() > 0)) { coll.setObject(DbConstants.COLTOPICS, result); coll.setValue(DbConstants.MSG_EXISTS, "1"); } else { coll.setValue(DbConstants.MSG_EXISTS, "0"); } /** * set stream blobs (photos and files), partitioned based on collabrumid * Get scalable datasource based on whether this list has to be retrieved from master or slave */ if (blobAccess == DbConstants.READ_FROM_MASTER) { sourceName = scalabilityManager.getWriteBlobScalability(collabrumId); } else { sourceName = scalabilityManager.getReadBlobScalability(collabrumId); } ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null, getReadBlobScalability(), in getCollabrum() "); sb.append(sourceName); sb.append(" collabrumId = "); sb.append(collabrumId); throw new BaseDaoException(sb.toString()); } boolean photoExists = false; try { List dResult = defaultblobQuery.execute(params); if (dResult != null && dResult.size() > 0) { coll.setObject(DbConstants.DEFAULT_PHOTO, ((Photo) dResult.get(0))); coll.setValue(DbConstants.PHOTO_CATEGORY, DbConstants.PHOTO_CATEGORY); photoExists = true; } coll.setObject(DbConstants.FILES, getBlobsByCategory(collabrumId, DbConstants.FILE_CATEGORY, blobAccess)); /* Object[] blobParams = {(Object)collabrumId, DbConstants.FILE_CATEGORY}; dResult = filesQuery.execute(blobParams); if (dResult != null && dResult.size() > 0) { coll.setObject(DbConstants.FILES, dResult); } */ if (!photoExists) { Object[] blobParams = { (Object) collabrumId, DbConstants.PHOTO_CATEGORY }; dResult = photoExistsQuery.execute(blobParams); if (dResult != null && dResult.size() > 0) { coll.setValue(DbConstants.PHOTO_CATEGORY, DbConstants.PHOTO_CATEGORY); } } // set objects here } catch (BaseDaoException e) { StringBuffer sb = new StringBuffer( "viewCollabrum exception in either files or defblob or photoExistsQuery "); sb.append(defaultblobQuery.getSql()); if (!photoExists) { sb.append(photoExistsQuery.getSql()); } sb.append("collabrumid = "); sb.append(collabrumId); throw new BaseDaoException(sb.toString(), e); } /** * set cobrand for collabrum */ getCobrand(collabrumId, coll); /** * set organizers */ try { result = getOrganizersQuery.execute(params); if ((result != null) && (result.size() > 0)) { coll.setObject(DbConstants.ORGANIZERS, result); } } catch (Exception e) { throw new BaseDaoException( "getOrganizerQuery() error, collabrumid = " + collabrumId + getOrganizersQuery.getSql()); } if (coll != null) { treeCache.put(fqn, collabrumId, (Collabrum) coll); } if (RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(userLogin)) { coll.setValue(DbConstants.IS_ORGANIZER, "0"); } else { if (diaryAdmin.isDiaryAdmin(userLogin) || isUserCollOrganizer(result, userId)) { coll.setValue(DbConstants.IS_ORGANIZER, "1"); } else { coll.setValue(DbConstants.IS_ORGANIZER, "0"); } } /** * set member for this collabrum, use the same datasource as zeroscalability */ result = (List) coll.getObject(DbConstants.MEMBERS); if (isUserCollMember(result, userLogin)) { coll.setValue(DbConstants.IS_MEMBER, "1"); } else { coll.setValue(DbConstants.IS_MEMBER, "0"); } return coll; } /** * isUserCollOrganize method checks if this user is an organizer from a given list * @param List organizers * @param String userId * @return boolean - true if this user is an organizer, false otherwise */ private boolean isUserCollOrganizer(List organizers, String userId) { if ((organizers != null) && (organizers.size() > 0)) { for (int i = 0; i < organizers.size(); i++) { if (((Member) organizers.get(i)).getValue(DbConstants.LOGIN_ID).equals(userId)) { return true; } } } return false; } /** * isUserCollMember method checks if this user is member from a given list of members * @param List members * @param String userLogin * @return boolean - true if this user is a member, false otherwise */ private boolean isUserCollMember(List members, String userLogin) { if ((members != null) && (members.size() > 0)) { for (int i = 0; i < members.size(); i++) { if (((Hdlogin) members.get(i)).getValue(DbConstants.LOGIN).equals(userLogin)) { return true; } } } return false; } /** * topicExists - this method checks if this collabrum contains a topic * @param String collabrumId * @return List - result set that checks for the existence of a topic */ private List topicExists(String collabrumId) throws BaseDaoException { if (RegexStrUtil.isNull(collabrumId)) { throw new BaseDaoException("params are null"); } /** * Get scalability datasource based on collabrumid for colltopics - colltopics table */ String sourceName = scalabilityManager.getReadScalability(collabrumId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null, topicExists()"); sb.append(sourceName); sb.append(" collabrumid = "); sb.append(collabrumId); throw new BaseDaoException(sb.toString()); } try { Object[] params = { (Object) collabrumId }; List result = topicExistsQuery.execute(params); return result; } catch (Exception e) { throw new BaseDaoException("error, checking if coltopics exists for collabrum = " + collabrumId + topicExistsQuery.getSql(), e); } } /** * Not used anymore * Get a collabrum and add the traffic update to this collabrum * @param collabrumId the controller will need the collabrumId to get this bean * @param visitorid visitorid who has visited this collabrum (for members, uses memberid) * @param referer rerferer * @param ipaddress ipaddress * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void incrementHits(String collabrumId, String visitorid, String referer, String ipaddress) throws BaseDaoException { /** * Get scalability datasource based on collabrumid for colltraffic - colltraffic table */ String sourceName = scalabilityManager.getWriteScalability(collabrumId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null, incrementHits() for "); sb.append(sourceName); sb.append(" collabrumid = "); sb.append(collabrumId); throw new BaseDaoException(sb.toString()); } /** * increment hits for this collabrum */ Connection conn = null; try { conn = ds.getConnection(); collHitsUpdateQuery.run(conn, collabrumId, visitorid, referer, ipaddress); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("conn.close() error, adding hits, collabrumId = " + collabrumId, e1); } throw new BaseDaoException("error occured while adding hits, collabrumId = " + collabrumId, e); } try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("conn.close() error, adding hits, collabrumId = " + collabrumId, e1); } Fqn fqn = cacheUtil.fqn(DbConstants.COLLABRUM_EDIT); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } } /** * This method checks if the user is already a member of this collabrum, if not, add this member * @param collabrumId the id of the collabrum * @param userId the userId to be added * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void addMember(String collabrumId, String userId) throws BaseDaoException { if (RegexStrUtil.isNull(collabrumId) || RegexStrUtil.isNull(userId)) { throw new BaseDaoException("params are null"); } /** * Get scalability datasource, collmembers is not partitioned */ String sourceName = scalabilityManager.getReadZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null for addMember() in collabrumDaoDb "); sb.append(sourceName); sb.append("collabrumId = "); sb.append(collabrumId); sb.append(" userId "); sb.append(userId); throw new BaseDaoException(sb.toString()); } /** * check if this user is already a member for this collabrum */ Connection conn = null; try { boolean memberExists = false; Object[] params = { (Object) userId, (Object) collabrumId }; List result = isMemberQuery.execute(params); if (result != null) { if (result.size() > 0) { memberExists = true; /* if ( ((Hdlogin)result.get(0)).getValue("1").equals((Object)"1") ){ memberExists = true; } */ } } /** * Get scalability datasource, collmembers is not partitioned */ sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null for addMember() in collabrumDaoDb "); sb.append(sourceName); sb.append("collabrumId = "); sb.append(collabrumId); sb.append(" userId "); sb.append(userId); throw new BaseDaoException(sb.toString()); } /** * add Member to DB */ if (!memberExists) { conn = ds.getConnection(); addMemberQuery.run(conn, collabrumId, userId); } } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("conn.close() error, addMember, collabrumId = " + collabrumId + userId, e1); } throw new BaseDaoException("error occured while addMember, collabrumId = " + collabrumId + userId, e); } try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("conn.close() error, addMember, collabrumId = " + collabrumId + userId, e1); } /** * Jboss methods * fqn - full qualified name * check if the collabrum already exists in the cache * If it exists, remove the collabrum from the cache. * This will enable to get the updated collabrum when the user does getCollabrum(); */ Fqn fqn = cacheUtil.fqn(DbConstants.COLLABRUM); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.COLLABRUM_EDIT); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } } /** * @param idList the list of the collabrum ids * @param memberId the memberId to be deleted * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void deleteMemberFromCollabrums(ArrayList idList, String memberId) throws BaseDaoException { if ((idList == null) || RegexStrUtil.isNull(memberId)) { throw new BaseDaoException("params are null, deleteMemberFromCollabrums"); } /** * Get scalability datasource, collmembers is not partitioned **/ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null for deleteMemberFromCollabrums() in collabrumDaoDb "); sb.append(sourceName); sb.append(" memberId "); sb.append(memberId); throw new BaseDaoException(sb.toString()); } Connection conn = null; try { conn = ds.getConnection(); conn.setAutoCommit(false); for (int i = 0; i < idList.size(); i++) { deleteMemberQuery.run(conn, (String) idList.get(i), memberId); } } catch (Exception e) { try { conn.rollback(); } catch (Exception e1) { try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e2) { throw new BaseDaoException( "conn.close() error, deleteMemberFromCollabrums, memberId" + memberId, e2); } throw new BaseDaoException( " rollback() exception, for deleteMemberFromCollabrums(), memberId = " + memberId, e1); } } // connection commit try { conn.commit(); } catch (Exception e3) { throw new BaseDaoException( " commit() exception, for deleteMemberFromCollabrums() memberId = " + memberId, e3); } try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e4) { throw new BaseDaoException( " conn.close() exception, for commit(), addBlockMemberQuery() memberId = " + memberId, e4); } /** * Jboss methods * fqn - full qualified name * check if the collabrum already exists in the cache * If it exists, remove the collabrum from the cache. * This will enable to get the updated collabrum when the user does getCollabrum(); */ Fqn fqn = cacheUtil.fqn(DbConstants.BLOCKED_COLLABRUM_LIST); if (treeCache.exists(fqn, memberId)) { treeCache.remove(fqn, memberId); } for (int i = 0; i < idList.size(); i++) { fqn = cacheUtil.fqn(DbConstants.COLLABRUM); String collabrumId = (String) idList.get(i); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.COLLABRUM_EDIT); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } } Hdlogin hdlogin = getLogin(memberId); if (hdlogin != null) { String userLogin = hdlogin.getValue(DbConstants.LOGIN); fqn = cacheUtil.fqn(DbConstants.MEM_AS_MODERATOR_LIST); if (treeCache.exists(fqn, userLogin)) { treeCache.remove(fqn, userLogin); } fqn = cacheUtil.fqn(DbConstants.MEM_AS_ORGANIZER_LIST); if (treeCache.exists(fqn, userLogin)) { treeCache.remove(fqn, userLogin); } } } /** * @param collabrumId the id of the collabrum * @param userId the userId to be deleted * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void deleteMember(String collabrumId, String userId) throws BaseDaoException { /** * Get scalability datasource, collmembers is not partitioned **/ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null for deleteMember() in collabrumDaoDb "); sb.append(sourceName); sb.append("collabrumId = "); sb.append(collabrumId); sb.append(" userId "); sb.append(userId); throw new BaseDaoException(sb.toString()); } Fqn fqn = cacheUtil.fqn(DbConstants.COLLABRUM); Object obj = treeCache.get(fqn, collabrumId); if (obj != null) { int num = new Integer(((Collabrum) obj).getValue("count(*)")).intValue(); if (num <= 1) return; } /** * Cannot delete the member if this member is the only one for this collabrum */ try { Object[] params = { (Object) collabrumId }; List result = membersNumQuery.execute(params); if ((result != null) && (result.size() > 0)) { int num = new Integer(((Collabrum) result.get(0)).getValue("count(*)")).intValue(); if (num <= 1) { return; } } } catch (Exception e) { throw new BaseDaoException("error in collabrumId = " + collabrumId + membersNumQuery.getSql(), e); } Connection conn = null; try { conn = ds.getConnection(); deleteMemberQuery.run(conn, collabrumId, userId); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException( "conn.close() error, deleteMember, collabrumId = " + collabrumId + userId, e1); } throw new BaseDaoException("error occured while deleteMember, collabrumId = " + collabrumId + userId, e); } try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("conn.close() error, deleteMember, collabrumId = " + collabrumId + userId, e1); } /** * Jboss methods * fqn - full qualified name * check if the collabrum already exists in the cache * If it exists, remove the collabrum from the cache. * This will enable to get the updated collabrum when the user does getCollabrum(); */ fqn = cacheUtil.fqn(DbConstants.COLLABRUM); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.COLLABRUM_EDIT); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } Hdlogin hdlogin = getLogin(userId); if (hdlogin != null) { String userLogin = hdlogin.getValue(DbConstants.LOGIN); fqn = cacheUtil.fqn(DbConstants.MEM_AS_MODERATOR_LIST); if (treeCache.exists(fqn, userLogin)) { treeCache.remove(fqn, userLogin); } fqn = cacheUtil.fqn(DbConstants.MEM_AS_ORGANIZER_LIST); if (treeCache.exists(fqn, userLogin)) { treeCache.remove(fqn, userLogin); } } fqn = cacheUtil.fqn(DbConstants.BLOCKED_COLLABRUM_LIST); if (treeCache.exists(fqn, userId)) { treeCache.remove(fqn, userId); } } /** * blocks member from collabrums - used by the organizer or diaryadmin * @param idList the list of the collabrum ids * @param memberId memberId who is to be blocked. * @param userId administrator of collabrum * @param userLogin administrator's login of collabrum * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void blockMemberFromCollabrums(ArrayList idList, String memberId, String userId, String userLogin) throws BaseDaoException { if ((idList == null) || RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(memberId) || RegexStrUtil.isNull(userLogin)) { throw new BaseDaoException("params are null"); } boolean isAdmin = true; /** * check user permissions */ if (!diaryAdmin.isDiaryAdmin(userLogin)) { isAdmin = false; } /** * check oraganizer permissions, only if the user is not a diary admin, make queries for organizer */ if (!isAdmin) { for (int i = 0; i < idList.size(); i++) { if (!isOrganizer((String) idList.get(i), userLogin, userId)) { StringBuffer sb = new StringBuffer( "User does not have permission to delete member from collabrum , "); sb.append(idList.get(i)); sb.append(" userId = "); sb.append(userId); sb.append(" memberId = "); sb.append(memberId); throw new BaseDaoException(sb.toString()); } } } /** * delete this member from multiple collabrums */ deleteMemberFromCollabrums(idList, memberId); /** * block this member from multiple collabrums */ for (int i = 0; i < idList.size(); i++) { blockMember((String) idList.get(i), memberId); } } /** * This method is used by blockMemberFromCollabrums() * @param collabrumId the id of the collabrum * @param memberId memberId who is to be blocked. * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ private void blockMember(String collabrumId, String memberId) throws BaseDaoException { if (RegexStrUtil.isNull(collabrumId) || RegexStrUtil.isNull(memberId)) { throw new BaseDaoException("params are null, blockMember() in collabrumDaoDb"); } /** * Get scalability datasource, collblock is partitioned on collabrumId **/ String sourceName = scalabilityManager.getWriteScalability(collabrumId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null for blockMember() in collabrumDaoDb "); sb.append(sourceName); sb.append("collabrumId = "); sb.append(collabrumId); sb.append(" memberId "); sb.append(memberId); throw new BaseDaoException(sb.toString()); } /** * block this member, add the member in collblock **/ Connection conn = null; try { conn = ds.getConnection(); addBlockMemberQuery.run(conn, collabrumId, memberId); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException( "conn.close() error, addBlockMember, collabrumId = " + collabrumId + memberId, e1); } throw new BaseDaoException( "error occured while addBlockMember, collabrumId = " + collabrumId + memberId, e); } try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException( "conn.close() error, addBlockMember, collabrumId = " + collabrumId + memberId, e1); } /** * Jboss methods * fqn - full qualified name * check if the collabrum already exists in the cache * If it exists, remove the collabrum from the cache. * This will enable to get the updated collabrum when the user does getCollabrum(); */ Fqn fqn = cacheUtil.fqn(DbConstants.COLLABRUM); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.COLLABRUM_EDIT); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.BLOCKED_COLLABRUM_LIST); if (treeCache.exists(fqn, memberId)) { treeCache.remove(fqn, memberId); } StringBuffer sb = new StringBuffer(); sb.append(collabrumId); sb.append("-"); sb.append(memberId); fqn = cacheUtil.fqn(DbConstants.ORGANIZER); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } Hdlogin hdlogin = getLogin(memberId); if (hdlogin != null) { String organizer = hdlogin.getValue(DbConstants.LOGIN); fqn = cacheUtil.fqn(DbConstants.MEM_AS_ORGANIZER_LIST); if (treeCache.exists(fqn, organizer)) { treeCache.remove(fqn, organizer); } fqn = cacheUtil.fqn(DbConstants.MEM_AS_MODERATOR_LIST); if (treeCache.exists(fqn, organizer)) { treeCache.remove(fqn, organizer); } } } private boolean doesTopicExist(String collabrumId) { /** * Get scalability datasource, colltopics is partitioned based on collabrumId **/ String sourceName = scalabilityManager.getReadScalability(collabrumId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null for doesTopicExist() in collabrumDaoDb "); sb.append(sourceName); sb.append("collabrumId = "); sb.append(collabrumId); throw new BaseDaoException(sb.toString()); } /** * check if this topic exists in this collabrum **/ List result = null; try { result = topicExistsQuery.execute(collabrumId); } catch (Exception e) { StringBuffer sb = new StringBuffer(); sb.append("exception error in ColTopicExistsQuery , "); sb.append(topicExistsQuery.getSql()); sb.append(" collabrumId = "); sb.append(collabrumId); throw new BaseDaoException(sb.toString(), e); } if ((result != null) && (result.size() > 0)) { return true; } return false; } /** * Checks if the scope for this directory allows collabrums to be added to this directory * @param directoryid * @param userId * @return DirectoryScope * @throws BaseDaoException **/ private DirScope getDirectoryScope(String directoryid) throws BaseDaoException { /** * Get scalability datasource, dirscope is partitioned on directoryid */ String sourceName = scalabilityManager.getReadScalability(directoryid); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null for getDirectoryScope() in collabrumDaoDb "); sb.append(sourceName); sb.append(" directoryid = "); sb.append(directoryid); throw new BaseDaoException(sb.toString()); } Object[] params = { (Object) directoryid }; List result = scopeQuery.execute(params); if (result == null) { StringBuffer sb = new StringBuffer("DirectoryScopeCategory db result is null, "); sb.append(scopeQuery.getSql()); sb.append(" params (1) directoryid = "); sb.append(directoryid); throw new BaseDaoException(sb.toString()); } else { if (result.size() > 0 && result.get(0) != null) { return (DirScope) result.get(0); } else { StringBuffer sb = new StringBuffer("DirectoryScopeCategory result is null, "); sb.append(scopeQuery.getSql()); sb.append(" params (1) directoryid = "); sb.append(directoryid); throw new BaseDaoException(sb.toString()); } } } /** * isAuthor() method * checks if this user is the author of this directory and returns the value of either true or false * @param myparams * @param adminResult * @return boolean * @throws BaseDaoException */ /* private boolean isAuthor(String directoryid, String userId) { */ /** * Get scalability datasource, diradmin is not partitioned */ /* String sourceName = scalabilityManager.getReadZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null for isAuthor() in collabrumDaoDb "); sb.append(sourceName); sb.append("directoryid = "); sb.append(directoryid); throw new BaseDaoException(sb.toString()); } Object[] myparams = {(Object)directoryid, (Object)userId }; List adminResult = null; try { adminResult = diradminexistsQuery.execute(myparams); if (adminResult != null) { if (adminResult.size() > 0) { return true; } } } catch (BaseDaoException e) { throw new BaseDaoException("exception for isauthor, " + diradminexistsQuery.getSql(), e); } return false; } */ /** * gets the stream blob data for all blobs * This method is called when stream blob is to zipped * @param collabrumId * @param blobtype * @return List * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public List getAllStreamData(String collabrumId, String blobType) throws BaseDaoException { if (RegexStrUtil.isNull(blobType) || RegexStrUtil.isNull(collabrumId)) { throw new BaseDaoException("params are null"); } /** * Get scalability datasource, collblob is partitioned on collabrumId */ String sourceName = scalabilityManager.getReadBlobScalability(collabrumId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null for getAllStreamData() in collabrumDaoDb "); sb.append(sourceName); sb.append(" collabrumId = "); sb.append(collabrumId); throw new BaseDaoException(sb.toString()); } Object[] params = { (Object) collabrumId, (Object) blobType }; try { List blobs = (List) getAllStreamDataQuery.execute(params); if (WebUtil.isSanEnabled()) { return getSanBlobsCollabrum(collabrumId, blobs); } else { return blobs; } //return (List)getAllStreamDataQuery.execute(params); } catch (Exception e) { throw new BaseDaoException("getAllStreamData() collabrumDao error, collabrumId= " + collabrumId + getAllStreamDataQuery.getSql(), e); } } /** * gets the blob without the blob data but with default value * This method is called when blob information is to displayed * @param entryId * @param collabrumId * @return StreamBlob * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public Photo getPhoto(String entryId, String collabrumId) throws BaseDaoException { if (RegexStrUtil.isNull(entryId) || RegexStrUtil.isNull(collabrumId)) { throw new BaseDaoException("params are null"); } /** * Jboss methods - * fqn - full qualified name * check if the streamblob already set in the cache * If it exists, return the userpage from the cache. */ StringBuffer buf = new StringBuffer(collabrumId); buf.append("-"); buf.append(entryId); String key = buf.toString(); Fqn fqn = cacheUtil.fqn(DbConstants.DEFAULT_PHOTO); Object obj = treeCache.get(fqn, key); if (obj != null) { return (Photo) obj; } /** * Get scalability datasource, collblob is partitioned on collabrumId */ String sourceName = scalabilityManager.getReadBlobScalability(collabrumId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null for getPhoto() in collabrumDaoDb "); sb.append(sourceName); sb.append(" collabrumId = "); sb.append(collabrumId); throw new BaseDaoException(sb.toString()); } Object[] params = { (Object) entryId }; try { List photos = blobQuery.execute(params); if ((photos != null) && (photos.size() > 0)) { treeCache.put(fqn, key, (Photo) photos.get(0)); return (Photo) photos.get(0); } else { return null; } } catch (Exception e) { throw new BaseDaoException("getPhoto() collabrumDao error, entryId= " + entryId + blobQuery.getSql(), e); } } /** * gets the stream blob * This method is called when stream blob is to displayed * @param entryId * @param collabrumId * @return StreamBlob * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public Photo getStreamBlob(String entryId, String collabrumId) throws BaseDaoException { if (RegexStrUtil.isNull(entryId) || RegexStrUtil.isNull(collabrumId)) { throw new BaseDaoException("params are null"); } /** * Jboss methods - * fqn - full qualified name * check if the streamblob already set in the cache * If it exists, return the userpage from the cache. */ StringBuffer buf = new StringBuffer(collabrumId); buf.append("-"); buf.append(entryId); String key = buf.toString(); Fqn fqn = cacheUtil.fqn(DbConstants.COL_STREAM_BLOB); Object obj = treeCache.get(fqn, key); if (obj != null) { return (Photo) obj; } /** * Get scalability datasource, collblob is partitioned on collabrumId */ String sourceName = scalabilityManager.getReadBlobScalability(collabrumId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null for getStreamBlob() in collabrumDaoDb "); sb.append(sourceName); sb.append(" collabrumId = "); sb.append(collabrumId); throw new BaseDaoException(sb.toString()); } Object[] params = { (Object) entryId }; try { List photos = oneStreamblobQuery.execute(params); if ((photos != null) && (photos.size() > 0)) { if ((Photo) photos.get(0) != null) { Photo photo = ((Photo) photos.get(0)); if (WebUtil.isSanEnabled()) { photo.setBlob(getSanBlobCollabrum(collabrumId, photo.getValue(DbConstants.BTITLE))); } treeCache.put(fqn, key, (Photo) photos.get(0)); } return (Photo) photos.get(0); } else { return null; } } catch (Exception e) { throw new BaseDaoException( "getStreamBlob() collabrumDao error, entryId= " + entryId + oneStreamblobQuery.getSql(), e); } } /** * provides the list of stream blobs in a collabrum * @param collabrumId - the collabrum id * @param loginId - the login id * @param login - the login * @return List is the list of streamblobs * @throws BaseDaoException - when error occurs */ /* public List getStreamBlobs(String collabrumId, String loginId, String login) throws BaseDaoException { if (RegexStrUtil.isNull(collabrumId) ) { throw new BaseDaoException("params are null"); } Fqn fqn = cacheUtil.fqn(DbConstants.COLLABRUM_STREAM_BLOBS); Object obj = treeCache.get(fqn, collabrumId); if (obj != null) { return (List)obj; } String sourceName = scalabilityManager.getReadBlobScalability(collabrumId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null for getStreamBlobs() in collabrumDaoDb "); sb.append(sourceName); sb.append(" collabrumId = "); sb.append(collabrumId); throw new BaseDaoException(sb.toString()); } List dResult = null; try { Object[] params = {(Object)collabrumId}; dResult = streamblobQuery.execute(params); } catch(BaseDaoException e) { throw new BaseDaoException("streamblobQuery exception for collabrumId = " + streamblobQuery.getSql() + collabrumId, e); } if ( (dResult != null) && (dResult.size() > 0)) { treeCache.put(fqn, collabrumId, dResult); } return dResult; } */ /** * delete a stream blob * This method is called when stream blob is to be deleted * @param entryId - the entryid * @param collabrumId - the collabrum id * @param userId - the user Id * @param userLogin - the user login * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void deleteStreamBlob(String entryId, String collabrumId, String userId, String userLogin) throws BaseDaoException { if (RegexStrUtil.isNull(entryId) || RegexStrUtil.isNull(collabrumId) || RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(userLogin)) { throw new BaseDaoException("params are null in deleteStreamBlob"); } /** * check authority to delete - diaryAdmin & isOrganizer are checked */ if (!isOrganizer(collabrumId, userLogin, userId)) { StringBuffer sb = new StringBuffer("No permission to delete streamblobs in collabrum "); sb.append(collabrumId); sb.append(" userId "); sb.append(userId); throw new BaseDaoException(sb.toString()); } /** * Get scalability datasource, collblob is partitioned on collabrumId */ String sourceName = scalabilityManager.getWriteBlobScalability(collabrumId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds is null for deleteStreamBlob() in collabrumDaoDb "); sb.append(sourceName); sb.append(" collabrumId = "); sb.append(collabrumId); throw new BaseDaoException(sb.toString()); } boolean exists = false; String defId = null; try { Object[] params = { (Object) collabrumId }; List result = defaultQuery.execute(params); if (result != null && result.size() > 0) { defId = ((Photo) result.get(0)).getValue(DbConstants.ENTRYID); if (!RegexStrUtil.isNull(defId) && defId.equals(entryId)) { exists = true; } } } catch (Exception e) { throw new BaseDaoException("error while" + defaultQuery.getSql()); } Connection conn = null; try { conn = ds.getConnection(); deleteStreamblobQuery.run(conn, entryId); if (exists) { deleteDefQuery.run(conn, collabrumId); } } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException("deleteStreamBlob/deleteDefQuery error ", e2); } } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("deleteStreamBlob/deleteDefQuery error ", e); } /** * Jboss methods - * fqn - full qualified name * check if the streamblob already set in the cache * If it exists, remove the bean from the cache. */ Fqn fqn = cacheUtil.fqn(DbConstants.PHOTO); if (treeCache.exists(fqn, entryId)) { treeCache.remove(fqn, entryId); } StringBuffer buf = new StringBuffer(collabrumId); buf.append("-"); buf.append(entryId); String key = buf.toString(); fqn = cacheUtil.fqn(DbConstants.COL_STREAM_BLOB); if (treeCache.exists(fqn, key)) { treeCache.remove(fqn, key); } fqn = cacheUtil.fqn(DbConstants.DEFAULT_PHOTO); if (treeCache.exists(fqn, key)) { treeCache.remove(fqn, key); } /* default photo */ fqn = cacheUtil.fqn(DbConstants.DEFAULT_PHOTO); if (!RegexStrUtil.isNull(defId)) { buf.delete(0, buf.length()); buf.append(collabrumId); buf.append("-"); buf.append(defId); key = buf.toString(); if (treeCache.exists(fqn, key)) { treeCache.remove(fqn, key); } } fqn = cacheUtil.fqn(DbConstants.COLLABRUM); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.COLLABRUM_STREAM_BLOBS); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.COLL_CAT); StringBuffer sb = new StringBuffer(collabrumId); sb.append("-"); sb.append(DbConstants.PHOTO_CATEGORY); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } sb.delete(0, sb.length()); sb.append(collabrumId); sb.append("-"); sb.append(DbConstants.FILE_CATEGORY); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } } /** * add the stream blob * This method is called to add a stream blob to collabrum * @param bsize - the blob size * @param blobtype - the blob type * @param mtype - the mime type * @param btitle - the blob title * @param blob - the blob itself * @param zoom - zoom * @param userId - the user id * @param collabrumId - collabrum Id * @param userLogin - the user Login * @param usertags - the user tags * @param caption - caption * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void addStreamBlob(long bsize, int blobtype, String mtype, String btitle, byte[] blob, int zoom, String userId, String collabrumId, String userLogin, String usertags, String caption) throws BaseDaoException { if ((bsize <= 0) || RegexStrUtil.isNull(mtype) || RegexStrUtil.isNull(btitle) || (blob == null)) { throw new BaseDaoException("params are null"); } /** * check authority to add - diaryAdmin & isOrganizer are checked */ if (!isOrganizer(collabrumId, userLogin, userId)) { StringBuffer sb = new StringBuffer("user does not have permission to add streamblobs in collabrum "); sb.append(collabrumId); sb.append(" userId "); sb.append(userId); throw new BaseDaoException(sb.toString()); } /** * Get scalability datasource, collblob is partitioned on collabrumId */ String sourceName = scalabilityManager.getWriteBlobScalability(collabrumId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds null, addStreamBlob() in collabrumDaoDb "); sb.append(sourceName); sb.append("collabrumId = "); sb.append(collabrumId); throw new BaseDaoException(sb.toString()); } if (RegexStrUtil.isNull(caption)) { caption = btitle; } Connection conn = null; String entryId = null; try { conn = ds.getConnection(); addStreamblobQuery.run(conn, blob, blobtype, mtype, btitle, bsize, zoom, collabrumId, userId, caption); List entryIdResult = getEntryIdQuery.run(conn, collabrumId); if (entryIdResult != null && entryIdResult.size() > 0) { if ((Photo) entryIdResult.get(0) != null) { entryId = ((Photo) entryIdResult.get(0)).getValue(DbConstants.ENTRYID); } } } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException("addBlob error ", e2); } } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("addBlob error ", e); } if (entryId != null) { addTags(entryId, collabrumId, usertags); } /** * remove the collabrum, get the latest photos */ Fqn fqn = cacheUtil.fqn(DbConstants.COLLABRUM); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.COLLABRUM_EDIT); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.COLLABRUM_STREAM_BLOBS); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.COLL_CAT); StringBuffer sb = new StringBuffer(collabrumId); sb.append("-"); sb.append(DbConstants.PHOTO_CATEGORY); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } sb.delete(0, sb.length()); sb.append(collabrumId); sb.append("-"); sb.append(DbConstants.FILE_CATEGORY); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } } /** * updates the stream blob (title, zoom) * @param entryId - entry id * @param collabrumId - collabrum id * @param userId - user Id * @param userLogin - user login * @param zoom - the zoom * @param btitle - the blob title * @param def - the default blob * @param caption - caption */ public void updateStreamBlob(String entryId, String collabrumId, String userId, String userLogin, String zoom, String btitle, boolean def, String caption) throws BaseDaoException { if (RegexStrUtil.isNull(entryId) || RegexStrUtil.isNull(collabrumId) || RegexStrUtil.isNull(userId)) { throw new BaseDaoException("params are null"); } if (RegexStrUtil.isNull(userLogin) || RegexStrUtil.isNull(btitle)) { throw new BaseDaoException("params are null"); } /** * check authority to update - diaryAdmin & isOrganizer are checked */ if (!isOrganizer(collabrumId, userLogin, userId)) { StringBuffer sb = new StringBuffer("user does not have permission to update streamblobs in collabrum "); sb.append(collabrumId); sb.append(" userId "); sb.append(userId); throw new BaseDaoException(sb.toString()); } /** * Get scalability datasource, collblob is partitioned on collabrumId */ String sourceName = scalabilityManager.getWriteBlobScalability(collabrumId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { StringBuffer sb = new StringBuffer("ds null, in updateStreamBlob() in collabrumDaoDb "); sb.append(sourceName); sb.append(" collabrumId = "); sb.append(collabrumId); sb.append(" entryid = "); sb.append(entryId); throw new BaseDaoException(sb.toString()); } boolean exists = false; try { Object[] params = { (Object) entryId }; List result = defaultQuery.execute(params); if (result != null && result.size() > 0) { exists = true; } } catch (Exception e) { throw new BaseDaoException("error while" + defaultQuery.getSql()); } if (RegexStrUtil.isNull(caption)) { caption = btitle; } Connection conn = null; try { conn = ds.getConnection(); conn.setAutoCommit(false); updateStreamblobQuery.run(conn, entryId, collabrumId, zoom, btitle, caption); /** if this is the default photo and this photo does not exist, add this entry */ if (def) { if (!exists) { deleteDefQuery.run(conn, collabrumId); addDefQuery.run(conn, entryId, collabrumId); } } else { /** no more a default photo, delete this entry */ if (exists) { deleteDefQuery.run(conn, collabrumId); } } } catch (Exception e) { try { conn.rollback(); } catch (Exception e1) { try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e2) { throw new BaseDaoException("connection close exception in add/delete default collabrum blob", e2); } throw new BaseDaoException( "error occured while rollingback entries from default collabrum stream blob", e1); } } try { conn.commit(); } catch (Exception e3) { throw new BaseDaoException("commit exception", e3); } try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e4) { throw new BaseDaoException("connection close exception", e4); } /* try { if (conn != null) { conn.close(); } } catch(Exception e2) { StringBuffer sb = new StringBuffer("updateBlob error, collabrumId "); sb.append(collabrumId); sb.append(" entryId = "); sb.append(entryId); sb.append(" btitle = "); sb.append(btitle); sb.append(" userId = "); sb.append(userId); throw new BaseDaoException(sb.toString(), e2); } StringBuffer sb = new StringBuffer("updateBlob error, collabrumId "); sb.append(collabrumId); sb.append(" entryId = "); sb.append(entryId); sb.append(" btitle = "); sb.append(btitle); sb.append(" userId = "); sb.append(userId); throw new BaseDaoException(sb.toString(), e); } try { if (conn != null) { conn.close(); } } catch(Exception e) { StringBuffer sb = new StringBuffer("updateBlob error collabrumId "); sb.append(collabrumId); sb.append(" entryId = "); sb.append(entryId); sb.append( " btitle = "); sb.append(btitle); sb.append(" userId = "); sb.append(userId); throw new BaseDaoException(sb.toString(), e); } */ /** * Jboss methods * fqn - full qualified name (key=collabrumId + entryId); * check if the entryId already set in the cache * If it exists, return the entryId from the cache. */ Fqn fqn = cacheUtil.fqn(DbConstants.COL_STREAM_BLOB); StringBuffer sb = new StringBuffer(collabrumId); sb.append("-"); sb.append(entryId); String key = sb.toString(); if (treeCache.exists(fqn, key)) { treeCache.remove(fqn, key); } fqn = cacheUtil.fqn(DbConstants.DEFAULT_PHOTO); if (treeCache.exists(fqn, key)) { treeCache.remove(fqn, key); } fqn = cacheUtil.fqn(DbConstants.COLLABRUM_STREAM_BLOBS); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.COLLABRUM); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.COLL_CAT); sb.delete(0, sb.length()); sb.append(collabrumId); sb.append("-"); sb.append(DbConstants.PHOTO_CATEGORY); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } } /** * getCobrand method - gets the cobranding information for this user and sets it in the collabrum * @throws BaseDaoException - when error occurs */ private void getCobrand(String collabrumId, Collabrum collabrum) throws BaseDaoException { Fqn fqn = cacheUtil.fqn(DbConstants.COLL_COBRAND); Object obj = treeCache.get(fqn, collabrumId); if (obj != null) { collabrum.setValue(DbConstants.COBRAND, "1"); collabrum.setValue(DbConstants.HEADER, ((Collabrum) obj).getValue(DbConstants.HEADER)); collabrum.setValue(DbConstants.FOOTER, ((Collabrum) obj).getValue(DbConstants.FOOTER)); return; } /** * Get scalability datasource for partitioned on userid */ String sourceName = scalabilityManager.getReadScalability(collabrumId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, Collabrum getCobrand() " + sourceName); } try { Object[] params = { (Object) collabrumId }; List result = cobrandQuery.execute(params); if ((result != null) && (result.size() > 0)) { collabrum.setValue(DbConstants.COBRAND, "1"); collabrum.setValue(DbConstants.HEADER, ((Collabrum) result.get(0)).getValue(DbConstants.HEADER)); collabrum.setValue(DbConstants.FOOTER, ((Collabrum) result.get(0)).getValue(DbConstants.FOOTER)); treeCache.put(fqn, collabrumId, result.get(0)); } } catch (Exception e) { throw new BaseDaoException("CollabrumDao, get cobrandQuery() " + cobrandQuery.getSql(), e); } } /** * get a list of collabrums that are blocked for a login * @param collabrumId - the collabrum id * @returns List - the list of members */ private List getBlockedCollabrumsForLogin(String loginId) { if (RegexStrUtil.isNull(loginId)) { throw new BaseDaoException("params are null"); } /** * get COLL_BLOCKED_MEMBERS value for this userId */ Fqn fqn = cacheUtil.fqn(DbConstants.BLOCKED_COLLABRUM_LIST); Object obj = treeCache.get(fqn, loginId); if (obj != null) { return (List) obj; } /** * Get scalability datasource for collblock - partitioned on loginId */ String sourceName = scalabilityManager.getReadBlobScalability(loginId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null" + sourceName); } try { Object[] params = { (Object) loginId }; List result = listBlockedCollabrumsQuery.execute(params); if (result != null && (result.size() > 0)) { treeCache.put(fqn, loginId, result); } return result; } catch (Exception e) { throw new BaseDaoException("listBlockedCollabrumsQuery for collabrum ", e); } } private boolean isThisMemberBlockedFromCollabrum(String collabrumId, String userId) { if (RegexStrUtil.isNull(collabrumId) || (userId == null)) { throw new BaseDaoException("params are null"); } List blockedSet = getBlockedCollabrumsForLogin(userId); if ((blockedSet != null) && (blockedSet.size() > 0)) { for (int i = 0; i < blockedSet.size(); i++) { if (collabrumId.equals(((Collabrum) blockedSet.get(i)).getValue(DbConstants.COLLABRUM_ID))) { return true; } } } return false; } /** * gets the stream blob information (without the blob data) * This method is called when stream blob information is displayed * @param collabrumId - the collabrum id * @param blobType - the blobType * @param blobAccessFlag - the blobAccessFlag * @return List of streamblobs belonging to this collabrum * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public List getBlobsByCategory(String collabrumId, String blobType, int blobAccessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(collabrumId) || RegexStrUtil.isNull(blobType)) { throw new BaseDaoException("params are null in getBlobsByCategory"); } /** * get stream blobs for a collabrum from cache, if it exists */ Fqn fqn = cacheUtil.fqn(DbConstants.COLL_CAT); StringBuffer sb = new StringBuffer(collabrumId); sb.append("-"); sb.append(blobType); Object obj = treeCache.get(fqn, sb.toString()); if (obj != null) { return (List) obj; } /** * Get scalability datasource for dirblob, partitioned on collabrumId */ String sourceName = null; if (blobAccessFlag == DbConstants.BLOB_READ_FROM_MASTER) { sourceName = scalabilityManager.getReadBlobScalability(collabrumId); } else { sourceName = scalabilityManager.getReadBlobScalability(collabrumId); } ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getBlobsByCategory() " + sourceName); } try { Object[] params = { (Object) collabrumId, (Object) blobType }; List result = blobCategoryQuery.execute(params); if ((result != null) && (result.size() > 0)) { treeCache.put(fqn, sb.toString(), (List) result); } return result; } catch (BaseDaoException e) { throw new BaseDaoException( "blobCategoryQuery exception, collabrumId = " + blobCategoryQuery.getSql() + collabrumId, e); } } /** * checks if this user is the collabrum organizer * @param collabrumId the id of the collabrum * @param loginId the loginId * @param login the login * @return boolean * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public boolean isOrganizerCollabrum(String collabrumId, String userLogin, String userId) throws BaseDaoException { if (RegexStrUtil.isNull(collabrumId) || RegexStrUtil.isNull(userId)) { throw new BaseDaoException("params are null isModerator()"); } return isOrganizer(collabrumId, userLogin, userId); } /** * adds tags for the blob * @param entryid the entryid * @param collabrumId the id of the collabrum * @param usertags the usertags * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void addTags(String entryId, String collabrumId, String usertags) { if (RegexStrUtil.isNull(entryId) || RegexStrUtil.isNull(collabrumId)) { throw new BaseDaoException("params are null"); } String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, addTags " + sourceName); } Connection conn = null; try { conn = ds.getConnection(); addTagQuery.run(conn, collabrumId, usertags, entryId); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("addTags () ", e1); } throw new BaseDaoException("addTags () ", e); } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("conn.close() error", e); } } /** * Delete collabrum blob usertags * @param collabrumId * @param entryid * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void deleteTags(String collabrumid, String entryid) throws BaseDaoException { if (RegexStrUtil.isNull(entryid) || RegexStrUtil.isNull(collabrumid)) { throw new BaseDaoException("params are null"); } /** * Get scalability usertab - not partitioned * not being used right now. */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, deleteTags " + sourceName); } try { deleteTagsQuery.run(collabrumid, entryid); } catch (Exception e) { throw new BaseDaoException("deleteTags is null" + deleteTagsQuery.getSql()); } } /** * get usertags * @param entryid * @param collabrumid * @return usertags * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public String getTags(String entryid, String collabrumid, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(entryid) || RegexStrUtil.isNull(collabrumid)) { throw new BaseDaoException("params are null"); } /** * Get scalability usertab - not partitioned * not being used right now. */ String queryName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { queryName = scalabilityManager.getWriteZeroScalability("collblobtagsQuery"); } else { queryName = scalabilityManager.getReadZeroScalability("collblobtagsQuery"); } tagsQuery = getQueryMapper().getQuery(queryName); /** loginid missing, add to usertab, hdprofile * fname, lname, email */ List uResult = null; try { Object[] params = { (Object) collabrumid, entryid }; uResult = tagsQuery.execute(params); } catch (Exception e) { throw new BaseDaoException("error executing Query" + tagsQuery.getSql(), e); } if (uResult == null) { throw new BaseDaoException("collTagsQuery result is null" + tagsQuery.getSql()); } else { if (uResult.size() > 0) { if ((Photo) uResult.get(0) != null) { return ((Photo) uResult.get(0)).getValue(DbConstants.USER_TAGS); } } } return null; } /** * get all collabrum blob usertags * @param collabrumid * @return List * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public List getAllTags(String collabrumid, int accessFlag) throws BaseDaoException { /** * Get scalability usertab - not partitioned * not being used right now. */ String queryName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { queryName = scalabilityManager.getWriteZeroScalability("collbloballtagsQuery"); } else { queryName = scalabilityManager.getReadZeroScalability("collbloballtagsQuery"); } allTagsQuery = getQueryMapper().getQuery(queryName); /** loginid missing, add to usertab, hdprofile * fname, lname, email */ List uResult = null; try { Object[] params = { (Object) collabrumid }; uResult = allTagsQuery.execute(params); } catch (Exception e) { throw new BaseDaoException("error executing Query" + allTagsQuery.getSql(), e); } return uResult; } /** * Update usertags * @param entryid * @param collabrumid * @param usertags * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void updateTags(String entryid, String collabrumid, String usertags) throws BaseDaoException { if (RegexStrUtil.isNull(entryid) || RegexStrUtil.isNull(collabrumid)) { throw new BaseDaoException("params are null"); } String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, updateTags " + sourceName); } Connection conn = null; try { conn = ds.getConnection(); updateTagsQuery.run(conn, entryid, collabrumid, usertags); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("updateTags () ", e1); } throw new BaseDaoException("updateTags () ", e); } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("conn.close() error", e); } } /** * getSanBlobsCollabrums - get the list of collabrum blobs for a category * (photos/files & videos & audio * @param collabrumid - collabrumid * @param collBlobs - list of collabrum blobs * @return collBlobs - return the list with the blobs * @throws BaseDaoException for errors */ public List getSanBlobsCollabrum(String collabrumid, List collBlobs) { if (RegexStrUtil.isNull(collabrumid) || (collBlobs == null)) { throw new BaseDaoException("params are null"); } if (WebUtil.isSanEnabled()) { Collabrum collabrum = viewCollabrum(collabrumid); if (collabrum == null) { throw new BaseDaoException("getSanBlobsCollabrum(), collabrum null, collabrumid =" + collabrumid); } /* read it from collabrum directory, created under the dirname */ /** * append directoryname to collabrumname */ StringBuffer sb = new StringBuffer(collabrum.getValue(DbConstants.DIRNAME)); if (sb == null) { throw new BaseDaoException("getSanBlobsCollabrum, sb null, collabrumid =" + collabrumid); } if (RegexStrUtil.isNull(collabrum.getValue(DbConstants.NAME))) { throw new BaseDaoException("collabrum name is null" + collabrumid); } else { sb.append(File.separator); sb.append(collabrum.getValue(DbConstants.NAME)); } String filePath = RegexStrUtil.sanFilePath(collabrum.getValue(DbConstants.DIRPATH), sb.toString()); if (RegexStrUtil.isNull(filePath)) { throw new BaseDaoException("filePath is null for collabrumid" + collabrumid); } FileSystemImpl fApi = new FileSystemImpl(); if (fApi != null) { for (int i = 0; i < collBlobs.size(); i++) { if ((Photo) collBlobs.get(i) != null) { String btitle = ((Photo) collBlobs.get(i)).getValue(DbConstants.BTITLE); if (!RegexStrUtil.isNull(btitle)) { byte[] blob = fApi.readFile(filePath, SanConstants.sanPath, btitle); if (blob != null && blob.length > 0) { ((Photo) collBlobs.get(i)).setBlob(blob); } } //btitle } // if } //for } else { throw new BaseDaoException("fApi is null, getSanBlobsCollabrum(), collabrumid" + collabrumid); } } // WebUtil return collBlobs; } /** * getSanBlobCollabrums - get collabrum blob * @param collabrumid - collabrumid * @param btitle - file name * @return byte[] - blob array * @throws BaseDaoException for errors */ public byte[] getSanBlobCollabrum(String collabrumid, String btitle) { if (WebUtil.isSanEnabled()) { if (RegexStrUtil.isNull(collabrumid) || RegexStrUtil.isNull(btitle)) { throw new BaseDaoException("params are null"); } Collabrum collabrum = viewCollabrum(collabrumid); if (collabrum == null) { throw new BaseDaoException("getSanBlobCollabrum, collabrum is null" + collabrumid); } /* read it from collabrum directory, created under the dirname */ StringBuffer sb = new StringBuffer(collabrum.getValue(DbConstants.DIRNAME)); if (sb == null) { throw new BaseDaoException("getSanBlobCollabrum, sb null, collabrumid =" + collabrumid); } if (RegexStrUtil.isNull(collabrum.getValue(DbConstants.NAME))) { throw new BaseDaoException("collabrum name is null" + collabrumid); } else { sb.append(collabrum.getValue(DbConstants.NAME)); } String filePath = RegexStrUtil.sanFilePath(collabrum.getValue(DbConstants.DIRPATH), sb.toString()); logger.info("filePath = " + filePath); FileSystemImpl fApi = new FileSystemImpl(); if (fApi != null) { return fApi.readFile(filePath, SanConstants.sanPath, btitle); } } return null; } /** * This property is setby spring automatically at web.xml startup. * @param ds - this is JDBC datasource bean that is connection from the pool */ public void setJdbcSource(DataSource ds) { this.ds = ds; } /** * @param daq */ public void setcollabrumaddQuery(CollabrumAddQuery daq) { this.addQuery = daq; } public void setcollabrumdeleteQuery(CollabrumDeleteQuery daq) { this.deleteQuery = daq; } public void setcollabrumupdateQuery(CollabrumUpdateQuery daq) { this.updateQuery = daq; } public void setcollabrumQuery(BasicQuery daq) { this.getQuery = daq; } /* public void setcollabrumadminexistsQuery(CollabrumAdminExistsQuery daq) { this.adminExistsQuery = daq; } */ public void setcollabrumaddadminQuery(CollabrumAddAdminQuery daq) { this.addAdminQuery = daq; } public void setcollabrumdeleteadminQuery(CollabrumDeleteAdminQuery daq) { this.deleteAdminQuery = daq; } public void setadddircollQuery(DirCollAddQuery daq) { this.addDircollQuery = daq; } public void setdeletedircollQuery(DirCollDeleteQuery daq) { this.deleteDircollQuery = daq; } public void setcolltopicexistsQuery(BasicQuery daq) { this.topicExistsQuery = daq; } public void setdirectoryscopeQuery(BasicQuery daq) { this.scopeQuery = daq; } public void setcollonestreamblobQuery(BasicQuery daq) { this.oneStreamblobQuery = daq; } public void setcollstreamblobQuery(BasicQuery daq) { this.streamblobQuery = daq; } public void setcollstreamdeleteQuery(ColStreamBlobDeleteQuery daq) { this.deleteStreamblobQuery = daq; } public void setcollstreamaddQuery(ColStreamBlobAddQuery daq) { this.addStreamblobQuery = daq; } /* public void setdiradminexistsQuery(DirAdminExistsQuery daq) { this.diradminexistsQuery = daq; } */ public void setcollhitsQuery(CollHitsQuery daq) { this.collHitsUpdateQuery = daq; } public void setcollabrumviewQuery(BasicQuery daq) { this.collabrumViewQuery = daq; } // members query /** * This property is setby spring automatically at web.xml startup. * @param daq */ public void setcollmembersQuery(BasicQuery daq) { this.membersQuery = daq; } /** * This property is setby spring automatically at web.xml startup. * @param daq */ public void setcollmembersnumQuery(BasicQuery daq) { this.membersNumQuery = daq; } /** * This property is setby spring automatically at web.xml startup. * @param daq */ public void setcollmembersdeleteQuery(CollMembersDeleteQuery daq) { this.deleteMemberQuery = daq; } /** * This property is setby spring automatically at web.xml startup. * @param daq */ public void setcollmemberaddblockQuery(CollMemberAddBlockQuery daq) { this.addBlockMemberQuery = daq; } /** * This property is setby spring automatically at web.xml startup. * @param daq */ public void setcollmembersaddQuery(CollMembersAddQuery daq) { this.addMemberQuery = daq; } public void setismemberQuery(BasicQuery daq) { this.isMemberQuery = daq; } public void setcollstreamupdateQuery(ColStreamBlobUpdateQuery daq) { this.updateStreamblobQuery = daq; } public void setcollallmembersdeleteQuery(CollAllMembersDeleteQuery daq) { this.deleteAllMembersQuery = daq; } public void setcollcobrandQuery(BasicQuery daq) { this.cobrandQuery = daq; } public void setlistmoderatorQuery(CollModeratorsListQuery daq) { this.listModeratorQuery = daq; } public void setcolstreamblobdeleteallQuery(ColStreamBlobDeleteAllQuery daq) { this.deleteAllCollBlobs = daq; } /* public void setEop(ExpiringObjectPool eop) { this.eop = eop; } */ public void setcollabrumorganizersQuery(BasicQuery daq) { this.getOrganizersQuery = daq; } public void setcollmemberblockQuery(CollMemberBlockQuery daq) { this.listBlockedCollabrumsQuery = daq; } /** delete */ public void setdeletecolmessagepertidQuery(DeleteColMessagePerTidQuery daq) { this.deleteColMessagesQuery = daq; } public void setdeletecolmsgattrpertidQuery(DeleteColMessageAttrPerTidQuery daq) { this.deleteColMsgAttrQuery = daq; } public void setcoltopicsidQuery(BasicQuery daq) { this.getTidsQuery = daq; } public void setcolridsQuery(BasicQuery daq) { this.getRidsQuery = daq; } public void setcolstreamblobentriesQuery(BasicQuery daq) { this.getBlobEntryListQuery = daq; } public void setcollmemberspercollabrumQuery(BasicQuery daq) { this.getCollabrumMembersQuery = daq; } public void setdeletecolblobtagsQuery(DeleteColBlobTagsQuery daq) { this.deleteColBlobTagsQuery = daq; } public void setdeletecollabrumindexQuery(DeleteCollabrumIndexQuery daq) { this.deleteCollabrumIndexQuery = daq; } public void setdeleteindexcolblobQuery(DeleteColBlobIndexQuery daq) { this.deleteColBlobIndexQuery = daq; } public void setdeleteindexcolmessagesQuery(DeleteColMessagesIndexQuery daq) { this.deleteColMessagesIndexQuery = daq; } public void setdeletecoltopicsindexQuery(DeleteColTopicsIndexQuery daq) { this.deleteColTopicsIndexQuery = daq; } public void setdeletecolblockedmembersQuery(DeleteColBlockedMembersQuery daq) { this.deleteBlockedMembersQuery = daq; } public void setcollabrumtopQuery(BasicQuery daq) { this.collabrumTopQuery = daq; } public void setdatacolstreamQuery(BasicQuery daq) { this.getAllStreamDataQuery = daq; } public void setblobcollabrumQuery(BasicQuery daq) { this.blobQuery = daq; } public void setcollabrumdefaultQuery(BasicQuery daq) { this.defaultQuery = daq; } public void setcolldefaultdeleteQuery(CollabrumDefaultDeleteQuery daq) { this.deleteDefQuery = daq; } public void setcolldefaultaddQuery(CollabrumDefaultAddQuery daq) { this.addDefQuery = daq; } public void setcollphotodefaultQuery(BasicQuery daq) { this.defaultblobQuery = daq; } /** * This property is setby spring automatically at web.xml startup. * @param daq */ /* public void setcollfileQuery(ColStreamFileEntriesQuery daq) { this.filesQuery = daq; } */ public void setcollexistsphotoQuery(BasicQuery daq) { this.photoExistsQuery = daq; } public void setcollstreamsbycategoryQuery(BasicQuery daq) { this.blobCategoryQuery = daq; } public void setcdeletecolblogtagsQuery(DeleteColBlogTagsQuery daq) { this.deleteColBlogTagsQuery = daq; } public void setdeletecoltopicsQuery(DeleteColTopicsPerCollabrumQuery daq) { this.deleteColTopicsQuery = daq; } public void setdelcoltopicattrpercollabrumQuery(DeleteColTopicAttrPerCollabrumQuery daq) { this.deleteColTopicsAttrQuery = daq; } /* not required any more public void setdelcoltrafficpercollabrumQuery(DeleteColTrafficPerCollabrumQuery daq) { this.deleteColTrafficQuery = daq; } */ public void setdelcolcobrandpercollabrumQuery(DeleteColCobrandPerCollabrumQuery daq) { this.deleteColCobrandQuery = daq; } public void setcollblobtagsaddQuery(CollBlobTagsAddQuery daq) { this.addTagQuery = daq; } public void setcollblobentryidQuery(CollBlobEntryIdQuery daq) { this.getEntryIdQuery = daq; } public void setcollblobupdatetagsQuery(CollBlobTagsUpdateQuery daq) { this.updateTagsQuery = daq; } public void setcollblobdeletetagsQuery(CollBlobTagsDeleteQuery daq) { this.deleteTagsQuery = daq; } }