0001: /**********************************************************************************
0002: * $URL: https://source.sakaiproject.org/svn/msgcntr/trunk/messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/PermissionManagerImpl.java $
0003: * $Id: PermissionManagerImpl.java 9227 2006-05-15 15:02:42Z cwen@iupui.edu $
0004: ***********************************************************************************
0005: *
0006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
0007: *
0008: * Licensed under the Educational Community License, Version 1.0 (the "License");
0009: * you may not use this file except in compliance with the License.
0010: * You may obtain a copy of the License at
0011: *
0012: * http://www.opensource.org/licenses/ecl1.php
0013: *
0014: * Unless required by applicable law or agreed to in writing, software
0015: * distributed under the License is distributed on an "AS IS" BASIS,
0016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0017: * See the License for the specific language governing permissions and
0018: * limitations under the License.
0019: *
0020: **********************************************************************************/package org.sakaiproject.component.app.messageforums;
0021:
0022: import java.sql.SQLException;
0023:
0024: import org.apache.commons.logging.Log;
0025: import org.apache.commons.logging.LogFactory;
0026: import org.hibernate.Hibernate;
0027: import org.hibernate.HibernateException;
0028: import org.hibernate.Query;
0029: import org.hibernate.Session;
0030: import org.sakaiproject.api.app.messageforums.Area;
0031: import org.sakaiproject.api.app.messageforums.AreaControlPermission;
0032: import org.sakaiproject.api.app.messageforums.AreaManager;
0033: import org.sakaiproject.api.app.messageforums.BaseForum;
0034: import org.sakaiproject.api.app.messageforums.ControlPermissions;
0035: import org.sakaiproject.api.app.messageforums.DefaultPermissionsManager;
0036: import org.sakaiproject.api.app.messageforums.DiscussionForumService;
0037: import org.sakaiproject.api.app.messageforums.ForumControlPermission;
0038: import org.sakaiproject.api.app.messageforums.MessageForumsTypeManager;
0039: import org.sakaiproject.api.app.messageforums.MessagePermissions;
0040: import org.sakaiproject.api.app.messageforums.PermissionManager;
0041: import org.sakaiproject.api.app.messageforums.Topic;
0042: import org.sakaiproject.api.app.messageforums.TopicControlPermission;
0043: import org.sakaiproject.component.app.messageforums.dao.hibernate.AreaControlPermissionImpl;
0044: import org.sakaiproject.component.app.messageforums.dao.hibernate.ControlPermissionsImpl;
0045: import org.sakaiproject.component.app.messageforums.dao.hibernate.ForumControlPermissionImpl;
0046: import org.sakaiproject.component.app.messageforums.dao.hibernate.MessagePermissionsImpl;
0047: import org.sakaiproject.component.app.messageforums.dao.hibernate.TopicControlPermissionImpl;
0048: import org.sakaiproject.event.api.EventTrackingService;
0049: import org.sakaiproject.id.api.IdManager;
0050: import org.sakaiproject.tool.api.Placement;
0051: import org.sakaiproject.tool.api.SessionManager;
0052: import org.sakaiproject.tool.cover.ToolManager;
0053: import org.springframework.orm.hibernate3.HibernateCallback;
0054: import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
0055:
0056: public class PermissionManagerImpl extends HibernateDaoSupport
0057: implements PermissionManager {
0058:
0059: private static final Log LOG = LogFactory
0060: .getLog(PermissionManagerImpl.class);
0061:
0062: private static final String QUERY_CP_BY_ROLE = "findAreaControlPermissionByRole";
0063: private static final String QUERY_CP_BY_FORUM = "findForumControlPermissionByRole";
0064: private static final String QUERY_CP_BY_TOPIC = "findTopicControlPermissionByRole";
0065: private static final String QUERY_MP_BY_ROLE = "findAreaMessagePermissionByRole";
0066: private static final String QUERY_MP_BY_FORUM = "findForumMessagePermissionByRole";
0067: private static final String QUERY_MP_BY_TOPIC = "findTopicMessagePermissionByRole";
0068:
0069: private IdManager idManager;
0070:
0071: private SessionManager sessionManager;
0072:
0073: private MessageForumsTypeManager typeManager;
0074:
0075: private AreaManager areaManager;
0076:
0077: private EventTrackingService eventTrackingService;
0078:
0079: private DefaultPermissionsManager defaultPermissionsManager;
0080:
0081: public void init() {
0082: LOG.info("init()");
0083: ;
0084: }
0085:
0086: public EventTrackingService getEventTrackingService() {
0087: return eventTrackingService;
0088: }
0089:
0090: public void setEventTrackingService(
0091: EventTrackingService eventTrackingService) {
0092: this .eventTrackingService = eventTrackingService;
0093: }
0094:
0095: public AreaManager getAreaManager() {
0096: return areaManager;
0097: }
0098:
0099: public void setAreaManager(AreaManager areaManager) {
0100: this .areaManager = areaManager;
0101: }
0102:
0103: public MessageForumsTypeManager getTypeManager() {
0104: return typeManager;
0105: }
0106:
0107: public void setTypeManager(MessageForumsTypeManager typeManager) {
0108: this .typeManager = typeManager;
0109: }
0110:
0111: public void setSessionManager(SessionManager sessionManager) {
0112: this .sessionManager = sessionManager;
0113: }
0114:
0115: public IdManager getIdManager() {
0116: return idManager;
0117: }
0118:
0119: public SessionManager getSessionManager() {
0120: return sessionManager;
0121: }
0122:
0123: public void setIdManager(IdManager idManager) {
0124: this .idManager = idManager;
0125: }
0126:
0127: /**
0128: * @param defaultPermissionsManager The defaultPermissionsManager to set.
0129: */
0130: public void setDefaultPermissionsManager(
0131: DefaultPermissionsManager defaultPermissionManager) {
0132: this .defaultPermissionsManager = defaultPermissionManager;
0133: }
0134:
0135: public AreaControlPermission getAreaControlPermissionForRole(
0136: String role, String typeId) {
0137: ControlPermissions permissions = getAreaControlPermissionByRoleAndType(
0138: role, typeId, false);
0139: AreaControlPermission cp = new AreaControlPermissionImpl();
0140:
0141: if (permissions == null) {
0142: // cp.setChangeSettings(Boolean.FALSE);
0143: // cp.setMovePostings(Boolean.FALSE);
0144: // cp.setNewForum(Boolean.FALSE);
0145: // cp.setNewResponse(Boolean.FALSE);
0146: // cp.setNewTopic(Boolean.FALSE);
0147: // cp.setResponseToResponse(Boolean.FALSE);
0148: // cp.setPostToGradebook(Boolean.FALSE);
0149: return getDefaultAreaControlPermissionForRole(role, typeId);
0150: } else {
0151: cp.setPostToGradebook(permissions.getPostToGradebook());
0152: cp.setChangeSettings(permissions.getChangeSettings());
0153: cp.setMovePostings(permissions.getMovePostings());
0154: cp.setNewForum(permissions.getNewForum());
0155: cp.setNewResponse(permissions.getNewResponse());
0156: cp.setNewTopic(permissions.getNewTopic());
0157: cp.setResponseToResponse(permissions
0158: .getResponseToResponse());
0159: }
0160: cp.setRole(role);
0161: return cp;
0162: }
0163:
0164: public AreaControlPermission getDefaultAreaControlPermissionForRole(
0165: String role, String typeId) {
0166: // ControlPermissions permissions = getAreaControlPermissionByRoleAndType(role, typeId, true);
0167: AreaControlPermission cp = new AreaControlPermissionImpl();
0168: // if (permissions == null) {
0169: // cp.setChangeSettings(Boolean.FALSE);
0170: // cp.setMovePostings(Boolean.FALSE);
0171: // cp.setNewForum(Boolean.FALSE);
0172: // cp.setNewResponse(Boolean.FALSE);
0173: // cp.setNewTopic(Boolean.FALSE);
0174: // cp.setResponseToResponse(Boolean.FALSE);
0175: // cp.setPostToGradebook(Boolean.FALSE);
0176: // } else {
0177: // cp.setChangeSettings(permissions.getChangeSettings());
0178: // cp.setMovePostings(permissions.getMovePostings());
0179: // cp.setNewForum(permissions.getNewForum());
0180: // cp.setNewResponse(permissions.getNewResponse());
0181: // cp.setNewTopic(permissions.getNewTopic());
0182: // cp.setResponseToResponse(permissions.getResponseToResponse());
0183: // cp.setPostToGradebook(permissions.getPostToGradebook());
0184: // }
0185: cp.setChangeSettings(new Boolean(defaultPermissionsManager
0186: .isChangeSettings(role)));
0187: cp.setMovePostings(new Boolean(defaultPermissionsManager
0188: .isMovePostings(role)));
0189: cp.setNewForum(new Boolean(defaultPermissionsManager
0190: .isNewForum(role)));
0191: cp.setNewResponse(new Boolean(defaultPermissionsManager
0192: .isNewResponse(role)));
0193: cp.setNewTopic(new Boolean(defaultPermissionsManager
0194: .isNewTopic(role)));
0195: cp.setResponseToResponse(new Boolean(defaultPermissionsManager
0196: .isResponseToResponse(role)));
0197: cp.setPostToGradebook(new Boolean(defaultPermissionsManager
0198: .isPostToGradebook(role)));
0199: cp.setRole(role);
0200: return cp;
0201: }
0202:
0203: public AreaControlPermission createAreaControlPermissionForRole(
0204: String role, String typeId) {
0205: AreaControlPermission permission = new AreaControlPermissionImpl();
0206: AreaControlPermission acp = getDefaultAreaControlPermissionForRole(
0207: role, typeId);
0208: permission.setChangeSettings(acp.getChangeSettings());
0209: permission.setMovePostings(acp.getMovePostings());
0210: permission.setNewForum(acp.getNewForum());
0211: permission.setNewResponse(acp.getNewResponse());
0212: permission.setNewTopic(acp.getNewTopic());
0213: permission.setResponseToResponse(acp.getResponseToResponse());
0214: permission.setPostToGradebook(acp.getPostToGradebook());
0215: permission.setRole(role);
0216: return permission;
0217: }
0218:
0219: public void saveAreaControlPermissionForRole(Area area,
0220: AreaControlPermission permission, String typeId) {
0221: ControlPermissions permissions = getAreaControlPermissionByRoleAndType(
0222: permission.getRole(), typeId, false);
0223: if (permissions == null) {
0224: permissions = new ControlPermissionsImpl();
0225: }
0226: boolean isNew = permissions.getId() == null;
0227:
0228: permissions.setArea(area);
0229: permissions.setDefaultValue(Boolean.FALSE);
0230: permissions.setChangeSettings(permission.getChangeSettings());
0231: permissions.setMovePostings(permission.getMovePostings());
0232: permissions.setNewForum(permission.getNewForum());
0233: permissions.setNewResponse(permission.getNewResponse());
0234: permissions.setNewTopic(permission.getNewTopic());
0235: permissions.setResponseToResponse(permission
0236: .getResponseToResponse());
0237: permissions.setPostToGradebook(permission.getPostToGradebook());
0238: permissions.setRole(permission.getRole());
0239: getHibernateTemplate().saveOrUpdate(permissions);
0240:
0241: if (isNew) {
0242: eventTrackingService.post(eventTrackingService.newEvent(
0243: DiscussionForumService.EVENT_RESOURCE_ADD,
0244: getEventMessage(area, permissions), false));
0245: } else {
0246: eventTrackingService.post(eventTrackingService.newEvent(
0247: DiscussionForumService.EVENT_RESOURCE_WRITE,
0248: getEventMessage(area, permissions), false));
0249: }
0250: }
0251:
0252: public void saveDefaultAreaControlPermissionForRole(Area area,
0253: AreaControlPermission permission, String typeId) {
0254: ControlPermissions permissions = getAreaControlPermissionByRoleAndType(
0255: permission.getRole(), typeId, true);
0256: if (permissions == null) {
0257: permissions = new ControlPermissionsImpl();
0258: }
0259: boolean isNew = permissions.getId() == null;
0260:
0261: permissions.setArea(area);
0262: permissions.setDefaultValue(Boolean.TRUE);
0263: permissions.setChangeSettings(permission.getChangeSettings());
0264: permissions.setMovePostings(permission.getMovePostings());
0265: permissions.setNewForum(permission.getNewForum());
0266: permissions.setNewResponse(permission.getNewResponse());
0267: permissions.setNewTopic(permission.getNewTopic());
0268: permissions.setResponseToResponse(permission
0269: .getResponseToResponse());
0270: permissions.setPostToGradebook(permission.getPostToGradebook());
0271: permissions.setRole(permission.getRole());
0272: getHibernateTemplate().saveOrUpdate(permissions);
0273:
0274: if (isNew) {
0275: eventTrackingService.post(eventTrackingService.newEvent(
0276: DiscussionForumService.EVENT_RESOURCE_ADD,
0277: getEventMessage(area, permissions), false));
0278: } else {
0279: eventTrackingService.post(eventTrackingService.newEvent(
0280: DiscussionForumService.EVENT_RESOURCE_WRITE,
0281: getEventMessage(area, permissions), false));
0282: }
0283: }
0284:
0285: public ForumControlPermission getForumControlPermissionForRole(
0286: BaseForum forum, String role, String typeId) {
0287: ControlPermissions permissions = forum == null
0288: || forum.getId() == null ? null
0289: : getControlPermissionByKeyValue(role, "forumId", forum
0290: .getId().toString(), false);
0291: ForumControlPermission cp = new ForumControlPermissionImpl();
0292:
0293: if (permissions == null) {
0294: return null;
0295: } else {
0296: cp.setChangeSettings(permissions.getChangeSettings());
0297: cp.setMovePostings(permissions.getMovePostings());
0298: cp.setNewResponse(permissions.getNewResponse());
0299: cp.setNewTopic(permissions.getNewTopic());
0300: cp.setPostToGradebook(permissions.getPostToGradebook());
0301: cp.setResponseToResponse(permissions
0302: .getResponseToResponse());
0303: }
0304: cp.setRole(role);
0305: return cp;
0306: }
0307:
0308: public ForumControlPermission getDefaultForumControlPermissionForRole(
0309: BaseForum forum, String role, String typeId) {
0310: ControlPermissions permissions = forum == null
0311: || forum.getId() == null ? null
0312: : getControlPermissionByKeyValue(role, "forumId", forum
0313: .getId().toString(), true);
0314: ForumControlPermission cp = new ForumControlPermissionImpl();
0315:
0316: if (permissions == null) {
0317: return null;
0318: } else {
0319: cp.setPostToGradebook(permissions.getPostToGradebook());
0320: cp.setChangeSettings(permissions.getChangeSettings());
0321: cp.setMovePostings(permissions.getMovePostings());
0322: cp.setNewResponse(permissions.getNewResponse());
0323: cp.setNewTopic(permissions.getNewTopic());
0324: cp.setResponseToResponse(permissions
0325: .getResponseToResponse());
0326: }
0327: cp.setRole(role);
0328: return cp;
0329: }
0330:
0331: public ForumControlPermission createForumControlPermissionForRole(
0332: String role, String typeId) {
0333: ForumControlPermission permission = new ForumControlPermissionImpl();
0334: AreaControlPermission acp = getAreaControlPermissionForRole(
0335: role, typeId);
0336: permission.setChangeSettings(acp.getChangeSettings());
0337: permission.setMovePostings(acp.getMovePostings());
0338: permission.setNewResponse(acp.getNewResponse());
0339: permission.setNewTopic(acp.getNewTopic());
0340: permission.setResponseToResponse(acp.getResponseToResponse());
0341: permission.setPostToGradebook(acp.getPostToGradebook());
0342: permission.setRole(role);
0343: return permission;
0344: }
0345:
0346: public void saveForumControlPermissionForRole(BaseForum forum,
0347: ForumControlPermission permission) {
0348: ControlPermissions permissions = forum == null
0349: || forum.getId() == null ? null
0350: : getControlPermissionByKeyValue(permission.getRole(),
0351: "forumId", forum.getId().toString(), false);
0352: if (permissions == null) {
0353: permissions = new ControlPermissionsImpl();
0354: }
0355: boolean isNew = permissions.getId() == null;
0356:
0357: permissions.setForum(forum);
0358: permissions.setDefaultValue(Boolean.FALSE);
0359: permissions.setChangeSettings(permission.getChangeSettings());
0360: permissions.setMovePostings(permission.getMovePostings());
0361: permissions.setNewForum(Boolean.FALSE);
0362: permissions.setNewResponse(permission.getNewResponse());
0363: permissions.setPostToGradebook(permission.getPostToGradebook());
0364: permissions.setNewTopic(permission.getNewTopic());
0365: permissions.setResponseToResponse(permission
0366: .getResponseToResponse());
0367: permissions.setRole(permission.getRole());
0368: getHibernateTemplate().saveOrUpdate(permissions);
0369:
0370: if (isNew) {
0371: eventTrackingService.post(eventTrackingService.newEvent(
0372: DiscussionForumService.EVENT_RESOURCE_ADD,
0373: getEventMessage(forum, permissions), false));
0374: } else {
0375: eventTrackingService.post(eventTrackingService.newEvent(
0376: DiscussionForumService.EVENT_RESOURCE_WRITE,
0377: getEventMessage(forum, permissions), false));
0378: }
0379: }
0380:
0381: public void saveDefaultForumControlPermissionForRole(
0382: BaseForum forum, ForumControlPermission permission) {
0383: ControlPermissions permissions = forum == null
0384: || forum.getId() == null ? null
0385: : getControlPermissionByKeyValue(permission.getRole(),
0386: "forumId", forum.getId().toString(), false);
0387: if (permissions == null) {
0388: permissions = new ControlPermissionsImpl();
0389: }
0390: boolean isNew = permissions.getId() == null;
0391:
0392: permissions.setForum(forum);
0393: permissions.setDefaultValue(Boolean.TRUE);
0394: permissions.setChangeSettings(permission.getChangeSettings());
0395: permissions.setMovePostings(permission.getMovePostings());
0396: permissions.setNewForum(Boolean.FALSE);
0397: permissions.setNewResponse(permission.getNewResponse());
0398: permissions.setPostToGradebook(permission.getPostToGradebook());
0399: permissions.setNewTopic(permission.getNewTopic());
0400: permissions.setResponseToResponse(permission
0401: .getResponseToResponse());
0402: permissions.setRole(permission.getRole());
0403: getHibernateTemplate().saveOrUpdate(permissions);
0404:
0405: if (isNew) {
0406: eventTrackingService.post(eventTrackingService.newEvent(
0407: DiscussionForumService.EVENT_RESOURCE_ADD,
0408: getEventMessage(forum, permissions), false));
0409: } else {
0410: eventTrackingService.post(eventTrackingService.newEvent(
0411: DiscussionForumService.EVENT_RESOURCE_WRITE,
0412: getEventMessage(forum, permissions), false));
0413: }
0414: }
0415:
0416: public TopicControlPermission getTopicControlPermissionForRole(
0417: Topic topic, String role, String typeId) {
0418: ControlPermissions permissions = topic == null
0419: || topic.getId() == null ? null
0420: : getControlPermissionByKeyValue(role, "topicId", topic
0421: .getId().toString(), false);
0422: TopicControlPermission cp = new TopicControlPermissionImpl();
0423:
0424: if (permissions == null) {
0425: return null;
0426: } else {
0427: cp.setChangeSettings(permissions.getChangeSettings());
0428: cp.setMovePostings(permissions.getMovePostings());
0429: cp.setNewResponse(permissions.getNewResponse());
0430: cp.setResponseToResponse(permissions
0431: .getResponseToResponse());
0432: cp.setPostToGradebook(permissions.getPostToGradebook());
0433: }
0434: cp.setRole(role);
0435: return cp;
0436: }
0437:
0438: public TopicControlPermission getDefaultTopicControlPermissionForRole(
0439: Topic topic, String role, String typeId) {
0440: ControlPermissions permissions = topic == null
0441: || topic.getId() == null ? null
0442: : getControlPermissionByKeyValue(role, "topicId", topic
0443: .getId().toString(), true);
0444: TopicControlPermission cp = new TopicControlPermissionImpl();
0445:
0446: if (permissions == null) {
0447: return null;
0448: } else {
0449: cp.setPostToGradebook(permissions.getPostToGradebook());
0450: cp.setChangeSettings(permissions.getChangeSettings());
0451: cp.setMovePostings(permissions.getMovePostings());
0452: cp.setNewResponse(permissions.getNewResponse());
0453: cp.setResponseToResponse(permissions
0454: .getResponseToResponse());
0455: }
0456: cp.setRole(role);
0457: return cp;
0458: }
0459:
0460: public TopicControlPermission createTopicControlPermissionForRole(
0461: BaseForum forum, String role, String typeId) {
0462: TopicControlPermission permission = new TopicControlPermissionImpl();
0463: ForumControlPermission fcp = getForumControlPermissionForRole(
0464: forum, role, typeId);
0465: permission.setChangeSettings(fcp.getChangeSettings());
0466: permission.setMovePostings(fcp.getMovePostings());
0467: permission.setNewResponse(fcp.getNewResponse());
0468: permission.setResponseToResponse(fcp.getResponseToResponse());
0469: permission.setPostToGradebook(fcp.getPostToGradebook());
0470: permission.setRole(role);
0471: return permission;
0472: }
0473:
0474: public void saveTopicControlPermissionForRole(Topic topic,
0475: TopicControlPermission permission) {
0476: ControlPermissions permissions = topic == null
0477: || topic.getId() == null ? null
0478: : getControlPermissionByKeyValue(permission.getRole(),
0479: "topicId", topic.getId().toString(), false);
0480: if (permissions == null) {
0481: permissions = new ControlPermissionsImpl();
0482: }
0483: boolean isNew = permissions.getId() == null;
0484:
0485: permissions.setTopic(topic);
0486: permissions.setDefaultValue(Boolean.FALSE);
0487: permissions.setChangeSettings(permission.getChangeSettings());
0488: permissions.setMovePostings(permission.getMovePostings());
0489: permissions.setNewForum(Boolean.FALSE);
0490: permissions.setNewResponse(permission.getNewResponse());
0491: permissions.setNewTopic(Boolean.FALSE);
0492: permissions.setPostToGradebook(permission.getPostToGradebook());
0493: permissions.setResponseToResponse(permission
0494: .getResponseToResponse());
0495: permissions.setRole(permission.getRole());
0496: getHibernateTemplate().saveOrUpdate(permissions);
0497:
0498: if (isNew) {
0499: eventTrackingService.post(eventTrackingService.newEvent(
0500: DiscussionForumService.EVENT_RESOURCE_ADD,
0501: getEventMessage(topic, permissions), false));
0502: } else {
0503: eventTrackingService.post(eventTrackingService.newEvent(
0504: DiscussionForumService.EVENT_RESOURCE_WRITE,
0505: getEventMessage(topic, permissions), false));
0506: }
0507: }
0508:
0509: public void saveDefaultTopicControlPermissionForRole(Topic topic,
0510: TopicControlPermission permission) {
0511: ControlPermissions permissions = topic == null
0512: || topic.getId() == null ? null
0513: : getControlPermissionByKeyValue(permission.getRole(),
0514: "topicId", topic.getId().toString(), false);
0515: if (permissions == null) {
0516: permissions = new ControlPermissionsImpl();
0517: }
0518: boolean isNew = permissions.getId() == null;
0519:
0520: permissions.setTopic(topic);
0521: permissions.setDefaultValue(Boolean.TRUE);
0522: permissions.setChangeSettings(permission.getChangeSettings());
0523: permissions.setMovePostings(permission.getMovePostings());
0524: permissions.setNewForum(Boolean.FALSE);
0525: permissions.setNewResponse(permission.getNewResponse());
0526: permissions.setNewTopic(Boolean.FALSE);
0527: permissions.setResponseToResponse(permission
0528: .getResponseToResponse());
0529: permissions.setPostToGradebook(permission.getPostToGradebook());
0530: permissions.setRole(permission.getRole());
0531: getHibernateTemplate().saveOrUpdate(permissions);
0532:
0533: if (isNew) {
0534: eventTrackingService.post(eventTrackingService.newEvent(
0535: DiscussionForumService.EVENT_RESOURCE_ADD,
0536: getEventMessage(topic, permissions), false));
0537: } else {
0538: eventTrackingService.post(eventTrackingService.newEvent(
0539: DiscussionForumService.EVENT_RESOURCE_WRITE,
0540: getEventMessage(topic, permissions), false));
0541: }
0542: }
0543:
0544: public ControlPermissions getAreaControlPermissionByRoleAndType(
0545: final String roleId, final String typeId,
0546: final boolean defaultValue) {
0547: LOG
0548: .debug("getAreaControlPermissionByRole executing for current user: "
0549: + getCurrentUser());
0550: final Area area = areaManager
0551: .getAreaByContextIdAndTypeId(typeId);
0552: if (area == null) {
0553: return null;
0554: }
0555: HibernateCallback hcb = new HibernateCallback() {
0556: public Object doInHibernate(Session session)
0557: throws HibernateException, SQLException {
0558: Query q = session.getNamedQuery(QUERY_CP_BY_ROLE);
0559: q.setParameter("roleId", roleId, Hibernate.STRING);
0560: q.setParameter("areaId", area.getId().toString(),
0561: Hibernate.STRING);
0562: q.setParameter("defaultValue",
0563: new Boolean(defaultValue), Hibernate.BOOLEAN);
0564: return q.uniqueResult();
0565: }
0566: };
0567: return (ControlPermissions) getHibernateTemplate().execute(hcb);
0568: }
0569:
0570: private ControlPermissions getControlPermissionByKeyValue(
0571: final String roleId, final String key, final String value,
0572: final boolean defaultValue) {
0573: LOG
0574: .debug("getAreaControlPermissionByRole executing for current user: "
0575: + getCurrentUser());
0576: HibernateCallback hcb = new HibernateCallback() {
0577: public Object doInHibernate(Session session)
0578: throws HibernateException, SQLException {
0579: String queryString = "forumId".equals(key) ? QUERY_CP_BY_FORUM
0580: : QUERY_CP_BY_TOPIC;
0581: Query q = session.getNamedQuery(queryString);
0582: q.setParameter("roleId", roleId, Hibernate.STRING);
0583: q.setParameter(key, value, Hibernate.STRING);
0584: q.setParameter("defaultValue",
0585: new Boolean(defaultValue), Hibernate.BOOLEAN);
0586: return q.uniqueResult();
0587: }
0588: };
0589: return (ControlPermissions) getHibernateTemplate().execute(hcb);
0590: }
0591:
0592: private MessagePermissions getMessagePermissionByKeyValue(
0593: final String roleId, final String key, final String value,
0594: final boolean defaultValue) {
0595: LOG
0596: .debug("getAreaMessagePermissionByRole executing for current user: "
0597: + getCurrentUser());
0598: HibernateCallback hcb = new HibernateCallback() {
0599: public Object doInHibernate(Session session)
0600: throws HibernateException, SQLException {
0601: String queryString = "forumId".equals(key) ? QUERY_MP_BY_FORUM
0602: : QUERY_MP_BY_TOPIC;
0603: Query q = session.getNamedQuery(queryString);
0604: q.setParameter("roleId", roleId, Hibernate.STRING);
0605: q.setParameter(key, value, Hibernate.STRING);
0606: q.setParameter("defaultValue",
0607: new Boolean(defaultValue), Hibernate.BOOLEAN);
0608: return q.uniqueResult();
0609: }
0610: };
0611: return (MessagePermissions) getHibernateTemplate().execute(hcb);
0612: }
0613:
0614: /**
0615: * Get the area message permission for a given role. This provides the permissions
0616: * that the role currently has.
0617: */
0618: public MessagePermissions getAreaMessagePermissionForRole(
0619: String role, String typeId) {
0620: MessagePermissions permissions = getAreaMessagePermissionByRoleAndType(
0621: role, typeId, false);
0622: MessagePermissions mp = new MessagePermissionsImpl();
0623:
0624: if (permissions == null) {
0625: // mp.setDeleteAny(Boolean.FALSE);
0626: // mp.setDeleteOwn(Boolean.FALSE);
0627: // mp.setRead(Boolean.FALSE);
0628: // mp.setReadDrafts(Boolean.FALSE);
0629: // mp.setReviseAny(Boolean.FALSE);
0630: // mp.setReviseOwn(Boolean.FALSE);
0631: // mp.setMarkAsRead(Boolean.FALSE);
0632: return getDefaultAreaMessagePermissionForRole(role, typeId);
0633: } else {
0634: mp.setDeleteAny(permissions.getDeleteAny());
0635: mp.setDeleteOwn(permissions.getDeleteOwn());
0636: mp.setRead(permissions.getRead());
0637: mp.setReadDrafts(permissions.getReadDrafts());
0638: mp.setReviseAny(permissions.getReviseAny());
0639: mp.setReviseOwn(permissions.getReviseOwn());
0640: mp.setMarkAsRead(permissions.getMarkAsRead());
0641: }
0642: mp.setRole(role);
0643:
0644: return mp;
0645: }
0646:
0647: /**
0648: * Get the default area message permission for a given role. This provides the
0649: * permissions that the role currently has.
0650: */
0651: public MessagePermissions getDefaultAreaMessagePermissionForRole(
0652: String role, String typeId) {
0653: // MessagePermissions permissions = getAreaMessagePermissionByRoleAndType(role, typeId, true);
0654: MessagePermissions mp = new MessagePermissionsImpl();
0655:
0656: // if (permissions == null) {
0657: // mp.setDeleteAny(Boolean.FALSE);
0658: // mp.setDeleteOwn(Boolean.FALSE);
0659: // mp.setRead(Boolean.FALSE);
0660: // mp.setReadDrafts(Boolean.FALSE);
0661: // mp.setReviseAny(Boolean.FALSE);
0662: // mp.setReviseOwn(Boolean.FALSE);
0663: // mp.setMarkAsRead(Boolean.FALSE);
0664: // } else {
0665: // mp.setDeleteAny(permissions.getDeleteAny());
0666: // mp.setDeleteOwn(permissions.getDeleteOwn());
0667: // mp.setRead(permissions.getRead());
0668: // mp.setReadDrafts(permissions.getReadDrafts());
0669: // mp.setReviseAny(permissions.getReviseAny());
0670: // mp.setReviseOwn(permissions.getReviseOwn());
0671: // mp.setMarkAsRead(permissions.getMarkAsRead());
0672: // }
0673: mp.setRole(role);
0674: mp.setDeleteAny(new Boolean(defaultPermissionsManager
0675: .isDeleteAny(role)));
0676: mp.setDeleteOwn(new Boolean(defaultPermissionsManager
0677: .isDeleteOwn(role)));
0678: mp.setRead(new Boolean(defaultPermissionsManager.isRead(role)));
0679: mp.setReadDrafts(new Boolean(false));
0680: mp.setReviseAny(new Boolean(defaultPermissionsManager
0681: .isReviseAny(role)));
0682: mp.setReviseOwn(new Boolean(defaultPermissionsManager
0683: .isReviseOwn(role)));
0684: mp.setMarkAsRead(new Boolean(defaultPermissionsManager
0685: .isMarkAsRead(role)));
0686: return mp;
0687: }
0688:
0689: /**
0690: * Create an empty area message permission with system properties
0691: * populated (ie: uuid).
0692: */
0693: public MessagePermissions createAreaMessagePermissionForRole(
0694: String role, String typeId) {
0695: MessagePermissions permissions = new MessagePermissionsImpl();
0696: MessagePermissions mp = getDefaultAreaMessagePermissionForRole(
0697: role, typeId);
0698: if (mp != null) {
0699: permissions.setDefaultValue(mp.getDefaultValue());
0700: permissions.setDeleteAny(mp.getDeleteAny());
0701: permissions.setDeleteOwn(mp.getDeleteOwn());
0702: permissions.setRead(mp.getRead());
0703: permissions.setReadDrafts(mp.getReadDrafts());
0704: permissions.setReviseAny(mp.getReviseAny());
0705: permissions.setReviseOwn(mp.getReviseOwn());
0706: permissions.setMarkAsRead(mp.getMarkAsRead());
0707: permissions.setRole(role);
0708: }
0709: return permissions;
0710: }
0711:
0712: /**
0713: * Save an area message permission. This is backed in the database by a single
0714: * message permission (used for areas, forums, and topics).
0715: */
0716: public void saveAreaMessagePermissionForRole(Area area,
0717: MessagePermissions permission, String typeId) {
0718: MessagePermissions permissions = getAreaMessagePermissionByRoleAndType(
0719: permission.getRole(), typeId, false);
0720: if (permissions == null) {
0721: permissions = new MessagePermissionsImpl();
0722: }
0723: boolean isNew = permissions.getId() == null;
0724:
0725: permissions.setArea(area);
0726: permissions.setDefaultValue(Boolean.FALSE);
0727: permissions.setDeleteAny(permission.getDeleteAny());
0728: permissions.setDeleteOwn(permission.getDeleteOwn());
0729: permissions.setRead(permission.getRead());
0730: permissions.setReadDrafts(permission.getReadDrafts());
0731: permissions.setReviseAny(permission.getReviseAny());
0732: permissions.setReviseOwn(permission.getReviseOwn());
0733: permissions.setRole(permission.getRole());
0734: permissions.setMarkAsRead(permission.getMarkAsRead());
0735: getHibernateTemplate().saveOrUpdate(permissions);
0736:
0737: if (isNew) {
0738: eventTrackingService.post(eventTrackingService.newEvent(
0739: DiscussionForumService.EVENT_RESOURCE_ADD,
0740: getEventMessage(area, permissions), false));
0741: } else {
0742: eventTrackingService.post(eventTrackingService.newEvent(
0743: DiscussionForumService.EVENT_RESOURCE_WRITE,
0744: getEventMessage(area, permissions), false));
0745: }
0746: }
0747:
0748: /**
0749: * Save a default area message permission. This is backed in the database by a
0750: * single message permission (used for areas, forums, and topics).
0751: */
0752: public void saveDefaultAreaMessagePermissionForRole(Area area,
0753: MessagePermissions permission, String typeId) {
0754: MessagePermissions permissions = getAreaMessagePermissionByRoleAndType(
0755: permission.getRole(), typeId, true);
0756: if (permissions == null) {
0757: permissions = new MessagePermissionsImpl();
0758: }
0759: boolean isNew = permissions.getId() == null;
0760:
0761: permissions.setArea(area);
0762: permissions.setDefaultValue(Boolean.TRUE);
0763: permissions.setDeleteAny(permission.getDeleteAny());
0764: permissions.setDeleteOwn(permission.getDeleteOwn());
0765: permissions.setRead(permission.getRead());
0766: permissions.setReadDrafts(permission.getReadDrafts());
0767: permissions.setReviseAny(permission.getReviseAny());
0768: permissions.setReviseOwn(permission.getReviseOwn());
0769: permissions.setMarkAsRead(permission.getMarkAsRead());
0770: permissions.setRole(permission.getRole());
0771: getHibernateTemplate().saveOrUpdate(permissions);
0772:
0773: if (isNew) {
0774: eventTrackingService.post(eventTrackingService.newEvent(
0775: DiscussionForumService.EVENT_RESOURCE_ADD,
0776: getEventMessage(area, permissions), false));
0777: } else {
0778: eventTrackingService.post(eventTrackingService.newEvent(
0779: DiscussionForumService.EVENT_RESOURCE_WRITE,
0780: getEventMessage(area, permissions), false));
0781: }
0782: }
0783:
0784: /**
0785: * Get the forum message permission for a given role. This provides the permissions
0786: * that the role currently has.
0787: */
0788: public MessagePermissions getForumMessagePermissionForRole(
0789: BaseForum forum, String role, String typeId) {
0790: MessagePermissions permissions = forum == null
0791: || forum.getId() == null ? null
0792: : getMessagePermissionByKeyValue(role, "forumId", forum
0793: .getId().toString(), false);
0794: MessagePermissions mp = new MessagePermissionsImpl();
0795:
0796: if (permissions == null) {
0797: return null;
0798: } else {
0799: mp.setDeleteAny(permissions.getDeleteAny());
0800: mp.setDeleteOwn(permissions.getDeleteOwn());
0801: mp.setRead(permissions.getRead());
0802: mp.setReadDrafts(permissions.getReadDrafts());
0803: mp.setReviseAny(permissions.getReviseAny());
0804: mp.setReviseOwn(permissions.getReviseOwn());
0805: mp.setMarkAsRead(permissions.getMarkAsRead());
0806: }
0807: mp.setRole(role);
0808:
0809: return mp;
0810: }
0811:
0812: /**
0813: * Get the default forum message permission for a given role. This provides the
0814: * permissions that the role currently has.
0815: */
0816: public MessagePermissions getDefaultForumMessagePermissionForRole(
0817: BaseForum forum, String role, String typeId) {
0818: MessagePermissions permissions = forum == null
0819: || forum.getId() == null ? null
0820: : getMessagePermissionByKeyValue(role, "forumId", forum
0821: .getId().toString(), true);
0822: MessagePermissions mp = new MessagePermissionsImpl();
0823:
0824: if (permissions == null) {
0825: return null;
0826: } else {
0827: mp.setDeleteAny(permissions.getDeleteAny());
0828: mp.setDeleteOwn(permissions.getDeleteOwn());
0829: mp.setRead(permissions.getRead());
0830: mp.setReadDrafts(permissions.getReadDrafts());
0831: mp.setReviseAny(permissions.getReviseAny());
0832: mp.setReviseOwn(permissions.getReviseOwn());
0833: mp.setMarkAsRead(permissions.getMarkAsRead());
0834: }
0835: mp.setRole(role);
0836:
0837: return mp;
0838: }
0839:
0840: /**
0841: * Create an empty forum message permission with system properties
0842: * populated (ie: uuid).
0843: */
0844: public MessagePermissions createForumMessagePermissionForRole(
0845: String role, String typeId) {
0846: MessagePermissions permissions = new MessagePermissionsImpl();
0847: MessagePermissions mp = getAreaMessagePermissionForRole(role,
0848: typeId);
0849: if (mp != null) {
0850: permissions.setDefaultValue(mp.getDefaultValue());
0851: permissions.setDeleteAny(mp.getDeleteAny());
0852: permissions.setDeleteOwn(mp.getDeleteOwn());
0853: permissions.setRead(mp.getRead());
0854: permissions.setReadDrafts(mp.getReadDrafts());
0855: permissions.setReviseAny(mp.getReviseAny());
0856: permissions.setReviseOwn(mp.getReviseOwn());
0857: permissions.setMarkAsRead(mp.getMarkAsRead());
0858: permissions.setRole(role);
0859: }
0860: return permissions;
0861: }
0862:
0863: /**
0864: * Save an forum message permission. This is backed in the database by a single
0865: * message permission (used for topics, forums, and topics).
0866: */
0867: public void saveForumMessagePermissionForRole(BaseForum forum,
0868: MessagePermissions permission) {
0869: MessagePermissions permissions = forum == null
0870: || forum.getId() == null ? null
0871: : getMessagePermissionByKeyValue(permission.getRole(),
0872: "forumId", forum.getId().toString(), false);
0873: if (permissions == null) {
0874: permissions = new MessagePermissionsImpl();
0875: }
0876: boolean isNew = permissions.getId() == null;
0877:
0878: permissions.setForum(forum);
0879: permissions.setDefaultValue(Boolean.FALSE);
0880: permissions.setDeleteAny(permission.getDeleteAny());
0881: permissions.setDeleteOwn(permission.getDeleteOwn());
0882: permissions.setRead(permission.getRead());
0883: permissions.setReadDrafts(permission.getReadDrafts());
0884: permissions.setReviseAny(permission.getReviseAny());
0885: permissions.setReviseOwn(permission.getReviseOwn());
0886: permissions.setMarkAsRead(permission.getMarkAsRead());
0887: permissions.setRole(permission.getRole());
0888: getHibernateTemplate().saveOrUpdate(permissions);
0889:
0890: if (isNew) {
0891: eventTrackingService.post(eventTrackingService.newEvent(
0892: DiscussionForumService.EVENT_RESOURCE_ADD,
0893: getEventMessage(forum, permissions), false));
0894: } else {
0895: eventTrackingService.post(eventTrackingService.newEvent(
0896: DiscussionForumService.EVENT_RESOURCE_WRITE,
0897: getEventMessage(forum, permissions), false));
0898: }
0899: }
0900:
0901: /**
0902: * Save a default forum message permission. This is backed in the database by a
0903: * single message permission (used for topics, forums, and topics).
0904: */
0905: public void saveDefaultForumMessagePermissionForRole(
0906: BaseForum forum, MessagePermissions permission) {
0907: MessagePermissions permissions = forum == null
0908: || forum.getId() == null ? null
0909: : getMessagePermissionByKeyValue(permission.getRole(),
0910: "forumId", forum.getId().toString(), true);
0911: if (permissions == null) {
0912: permissions = new MessagePermissionsImpl();
0913: }
0914: boolean isNew = permissions.getId() == null;
0915:
0916: permissions.setForum(forum);
0917: permissions.setDefaultValue(Boolean.TRUE);
0918: permissions.setDeleteAny(permission.getDeleteAny());
0919: permissions.setDeleteOwn(permission.getDeleteOwn());
0920: permissions.setRead(permission.getRead());
0921: permissions.setReadDrafts(permission.getReadDrafts());
0922: permissions.setReviseAny(permission.getReviseAny());
0923: permissions.setReviseOwn(permission.getReviseOwn());
0924: permissions.setMarkAsRead(permission.getMarkAsRead());
0925: permissions.setRole(permission.getRole());
0926: getHibernateTemplate().saveOrUpdate(permissions);
0927:
0928: if (isNew) {
0929: eventTrackingService.post(eventTrackingService.newEvent(
0930: DiscussionForumService.EVENT_RESOURCE_ADD,
0931: getEventMessage(forum, permissions), false));
0932: } else {
0933: eventTrackingService.post(eventTrackingService.newEvent(
0934: DiscussionForumService.EVENT_RESOURCE_WRITE,
0935: getEventMessage(forum, permissions), false));
0936: }
0937: }
0938:
0939: /**
0940: * Get the topic message permission for a given role. This provides the permissions
0941: * that the role currently has.
0942: */
0943: public MessagePermissions getTopicMessagePermissionForRole(
0944: Topic topic, String role, String typeId) {
0945: MessagePermissions permissions = topic == null
0946: || topic.getId() == null ? null
0947: : getMessagePermissionByKeyValue(role, "topicId", topic
0948: .getId().toString(), false);
0949: MessagePermissions mp = new MessagePermissionsImpl();
0950:
0951: if (permissions == null) {
0952: return null;
0953: } else {
0954: mp.setDeleteAny(permissions.getDeleteAny());
0955: mp.setDeleteOwn(permissions.getDeleteOwn());
0956: mp.setRead(permissions.getRead());
0957: mp.setReadDrafts(permissions.getReadDrafts());
0958: mp.setReviseAny(permissions.getReviseAny());
0959: mp.setReviseOwn(permissions.getReviseOwn());
0960: mp.setMarkAsRead(permissions.getMarkAsRead());
0961: }
0962: mp.setRole(role);
0963:
0964: return mp;
0965: }
0966:
0967: /**
0968: * Get the default topic message permission for a given role. This provides the
0969: * permissions that the role currently has.
0970: */
0971: public MessagePermissions getDefaultTopicMessagePermissionForRole(
0972: Topic topic, String role, String typeId) {
0973: MessagePermissions permissions = topic == null
0974: || topic.getId() == null ? null
0975: : getMessagePermissionByKeyValue(role, "topicId", topic
0976: .getId().toString(), true);
0977: MessagePermissions mp = new MessagePermissionsImpl();
0978:
0979: if (permissions == null) {
0980: return null;
0981: } else {
0982: mp.setDeleteAny(permissions.getDeleteAny());
0983: mp.setDeleteOwn(permissions.getDeleteOwn());
0984: mp.setRead(permissions.getRead());
0985: mp.setReadDrafts(permissions.getReadDrafts());
0986: mp.setReviseAny(permissions.getReviseAny());
0987: mp.setReviseOwn(permissions.getReviseOwn());
0988: mp.setMarkAsRead(permissions.getMarkAsRead());
0989: }
0990: mp.setRole(role);
0991:
0992: return mp;
0993: }
0994:
0995: /**
0996: * Create an empty topic message permission with system properties
0997: * populated (ie: uuid).
0998: */
0999: public MessagePermissions createTopicMessagePermissionForRole(
1000: BaseForum forum, String role, String typeId) {
1001: MessagePermissions permissions = new MessagePermissionsImpl();
1002: MessagePermissions mp = getForumMessagePermissionForRole(forum,
1003: role, typeId);
1004: if (mp != null) {
1005: permissions.setDefaultValue(mp.getDefaultValue());
1006: permissions.setDeleteAny(mp.getDeleteAny());
1007: permissions.setDeleteOwn(mp.getDeleteOwn());
1008: permissions.setRead(mp.getRead());
1009: permissions.setReadDrafts(mp.getReadDrafts());
1010: permissions.setReviseAny(mp.getReviseAny());
1011: permissions.setReviseOwn(mp.getReviseOwn());
1012: permissions.setMarkAsRead(mp.getMarkAsRead());
1013: permissions.setRole(role);
1014: }
1015: return permissions;
1016: }
1017:
1018: /**
1019: * Save an topic message permission. This is backed in the database by a single
1020: * message permission (used for areas, forums, and topics).
1021: */
1022: public void saveTopicMessagePermissionForRole(Topic topic,
1023: MessagePermissions permission) {
1024: MessagePermissions permissions = topic == null
1025: || topic.getId() == null ? null
1026: : getMessagePermissionByKeyValue(permission.getRole(),
1027: "topicId", topic.getId().toString(), false);
1028: if (permissions == null) {
1029: permissions = new MessagePermissionsImpl();
1030: }
1031: boolean isNew = permissions.getId() == null;
1032:
1033: permissions.setTopic(topic);
1034: permissions.setDefaultValue(Boolean.FALSE);
1035: permissions.setDeleteAny(permission.getDeleteAny());
1036: permissions.setDeleteOwn(permission.getDeleteOwn());
1037: permissions.setRead(permission.getRead());
1038: permissions.setReadDrafts(permission.getReadDrafts());
1039: permissions.setReviseAny(permission.getReviseAny());
1040: permissions.setReviseOwn(permission.getReviseOwn());
1041: permissions.setMarkAsRead(permission.getMarkAsRead());
1042: permissions.setRole(permission.getRole());
1043: getHibernateTemplate().saveOrUpdate(permissions);
1044:
1045: if (isNew) {
1046: eventTrackingService.post(eventTrackingService.newEvent(
1047: DiscussionForumService.EVENT_RESOURCE_ADD,
1048: getEventMessage(topic, permissions), false));
1049: } else {
1050: eventTrackingService.post(eventTrackingService.newEvent(
1051: DiscussionForumService.EVENT_RESOURCE_WRITE,
1052: getEventMessage(topic, permissions), false));
1053: }
1054: }
1055:
1056: /**
1057: * Save a default topic message permission. This is backed in the database by a
1058: * single message permission (used for areas, forums, and topics).
1059: */
1060: public void saveDefaultTopicMessagePermissionForRole(Topic topic,
1061: MessagePermissions permission) {
1062: MessagePermissions permissions = topic == null
1063: || topic.getId() == null ? null
1064: : getMessagePermissionByKeyValue(permission.getRole(),
1065: "topicId", topic.getId().toString(), true);
1066: if (permissions == null) {
1067: permissions = new MessagePermissionsImpl();
1068: }
1069: boolean isNew = permissions.getId() == null;
1070:
1071: permissions.setTopic(topic);
1072: permissions.setDefaultValue(Boolean.TRUE);
1073: permissions.setDeleteAny(permission.getDeleteAny());
1074: permissions.setDeleteOwn(permission.getDeleteOwn());
1075: permissions.setRead(permissions.getRead());
1076: permissions.setReadDrafts(permission.getReadDrafts());
1077: permissions.setReviseAny(permission.getReviseAny());
1078: permissions.setReviseOwn(permission.getReviseOwn());
1079: permissions.setMarkAsRead(permission.getMarkAsRead());
1080: permissions.setRole(permission.getRole());
1081: getHibernateTemplate().saveOrUpdate(permissions);
1082:
1083: if (isNew) {
1084: eventTrackingService.post(eventTrackingService.newEvent(
1085: DiscussionForumService.EVENT_RESOURCE_ADD,
1086: getEventMessage(topic, permissions), false));
1087: } else {
1088: eventTrackingService.post(eventTrackingService.newEvent(
1089: DiscussionForumService.EVENT_RESOURCE_WRITE,
1090: getEventMessage(topic, permissions), false));
1091: }
1092: }
1093:
1094: public MessagePermissions getAreaMessagePermissionByRoleAndType(
1095: final String roleId, final String typeId,
1096: final boolean defaultValue) {
1097: LOG
1098: .debug("getAreaMessagePermissionByRole executing for current user: "
1099: + getCurrentUser());
1100: final Area area = areaManager
1101: .getAreaByContextIdAndTypeId(typeId);
1102: if (area == null) {
1103: return null;
1104: }
1105: HibernateCallback hcb = new HibernateCallback() {
1106: public Object doInHibernate(Session session)
1107: throws HibernateException, SQLException {
1108: Query q = session.getNamedQuery(QUERY_MP_BY_ROLE);
1109: q.setParameter("roleId", roleId, Hibernate.STRING);
1110: q.setParameter("areaId", area.getId().toString(),
1111: Hibernate.STRING);
1112: q.setParameter("defaultValue",
1113: new Boolean(defaultValue), Hibernate.BOOLEAN);
1114: return q.uniqueResult();
1115: }
1116: };
1117: return (MessagePermissions) getHibernateTemplate().execute(hcb);
1118: }
1119:
1120: // helpers
1121:
1122: private String getCurrentUser() {
1123: if (TestUtil.isRunningTests()) {
1124: return "test-user";
1125: }
1126: return sessionManager.getCurrentSessionUserId();
1127: }
1128:
1129: private String getEventMessage(Object parent, Object child) {
1130: return "/MessageCenter/site/" + getContextId() + "/"
1131: + parent.toString() + "/" + child.toString() + "/"
1132: + getCurrentUser();
1133: //return "MessageCenter::" + getCurrentUser() + "::" + parent.toString() + "::" + child.toString();
1134: }
1135:
1136: private String getContextId() {
1137: if (TestUtil.isRunningTests()) {
1138: return "test-context";
1139: }
1140: Placement placement = ToolManager.getCurrentPlacement();
1141: String presentSiteId = placement.getContext();
1142: return presentSiteId;
1143: }
1144:
1145: }
|