[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/action ...
Christian Bauer
christian at hibernate.org
Fri Nov 9 10:08:26 EST 2007
User: cbauer
Date: 07/11/09 10:08:26
Modified: examples/wiki/src/main/org/jboss/seam/wiki/core/action
NodeHome.java Menu.java DocumentHome.java
Authenticator.java WikiIdentity.java Help.java
CommentHome.java DirectoryHome.java
Removed: examples/wiki/src/main/org/jboss/seam/wiki/core/action
NodePermissions.java
Log:
Various updates to core classes and views, required for forum plugin
Revision Changes Path
1.27 +68 -5 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/action/NodeHome.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: NodeHome.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/action/NodeHome.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- NodeHome.java 12 Oct 2007 16:31:25 -0000 1.26
+++ NodeHome.java 9 Nov 2007 15:08:26 -0000 1.27
@@ -11,9 +11,11 @@
import org.jboss.seam.framework.EntityHome;
import org.jboss.seam.wiki.core.dao.NodeDAO;
import org.jboss.seam.wiki.core.dao.UserDAO;
+import org.jboss.seam.wiki.core.dao.UserRoleAccessFactory;
import org.jboss.seam.wiki.core.model.User;
import org.jboss.seam.wiki.core.model.Directory;
import org.jboss.seam.wiki.core.model.Node;
+import org.jboss.seam.wiki.core.model.Role;
import org.jboss.seam.wiki.util.WikiUtil;
import org.jboss.seam.wiki.preferences.PreferenceProvider;
import org.jboss.seam.annotations.In;
@@ -25,6 +27,7 @@
import org.jboss.seam.security.Identity;
import java.util.Date;
+import java.util.List;
/**
* Superclass for all creating and editing documents, directories, files, etc.
@@ -41,9 +44,13 @@
private UserDAO userDAO;
@In
private User currentUser;
+ @In
+ List<Role.AccessLevel> accessLevelsList;
+
protected NodeDAO getNodeDAO() { return nodeDAO; }
protected UserDAO getUserDAO() { return userDAO; }
protected User getCurrentUser() { return currentUser; }
+ public List<Role.AccessLevel> getAccessLevelsList() { return accessLevelsList; }
/* -------------------------- Request Wiring ------------------------------ */
@@ -82,7 +89,7 @@
if (!isIdDefined()) {
getLog().debug("no instance identifier, getting parent directory with id: " + parentDirectoryId);
- parentDirectory = nodeDAO.findDirectory(parentDirectoryId);
+ parentDirectory = loadParentDirectory(parentDirectoryId);
} else {
getLog().debug("using parent of instance: " + getInstance());
parentDirectory = getInstance().getParent();
@@ -92,10 +99,8 @@
getLog().debug("initalized with parent directory: " + parentDirectory);
- // Outject current node (required for polymorphic UI, e.g. access level dropdown boxes)
- Contexts.getPageContext().set("currentNode", getInstance());
-
// Outjects current node or parent directory, e.g. for breadcrumb rendering
+ // TODO: This clashes if several subclasses of NodeHome run on the same page, e.g. DocumentHome + ForumHome
Contexts.getPageContext().set("currentLocation", !isManaged() ? getParentDirectory() : getInstance());
return null;
@@ -114,7 +119,20 @@
public N find() {
//noinspection unchecked
N result = (N)nodeDAO.findNode((Long)getId());
- if (result==null) handleNotFound();
+ if (result==null) {
+ handleNotFound();
+ } else {
+ writeAccessLevel = getAccessLevelsList().get(
+ accessLevelsList.indexOf(
+ new Role.AccessLevel(result.getWriteAccessLevel())
+ )
+ );
+ readAccessLevel = getAccessLevelsList().get(
+ accessLevelsList.indexOf(
+ new Role.AccessLevel(result.getReadAccessLevel())
+ )
+ );
+ }
return result;
}
@@ -127,6 +145,16 @@
// Set default permissions for new nodes - default to same access as parent directory
node.setWriteAccessLevel(parentDirectory.getWriteAccessLevel());
node.setReadAccessLevel(parentDirectory.getReadAccessLevel());
+ writeAccessLevel = getAccessLevelsList().get(
+ accessLevelsList.indexOf(
+ new Role.AccessLevel(parentDirectory.getWriteAccessLevel())
+ )
+ );
+ readAccessLevel = getAccessLevelsList().get(
+ accessLevelsList.indexOf(
+ new Role.AccessLevel(parentDirectory.getReadAccessLevel())
+ )
+ );
return node;
}
@@ -260,6 +288,10 @@
throw new AuthorizationException("You don't have permission for this operation");
}
+ protected Directory loadParentDirectory(Long parentDirectoryId) {
+ return nodeDAO.findDirectory(parentDirectoryId);
+ }
+
/* -------------------------- Subclass Callbacks ------------------------------ */
/**
@@ -338,4 +370,35 @@
getInstance().setCreatedBy(newCreator);
}
+ private Role.AccessLevel writeAccessLevel;
+ private Role.AccessLevel readAccessLevel;
+
+ public Role.AccessLevel getWriteAccessLevel() {
+ return writeAccessLevel;
+ }
+
+ public void setWriteAccessLevel(Role.AccessLevel writeAccessLevel) {
+ if (!Identity.instance().hasPermission("Node", "changeAccessLevel", getInstance()) ) {
+ throw new AuthorizationException("You don't have permission for this operation");
+ }
+ this.writeAccessLevel = writeAccessLevel;
+ getInstance().setWriteAccessLevel(
+ writeAccessLevel != null ? writeAccessLevel.getAccessLevel() : UserRoleAccessFactory.ADMINROLE_ACCESSLEVEL
+ );
+ }
+
+ public Role.AccessLevel getReadAccessLevel() {
+ return readAccessLevel;
+ }
+
+ public void setReadAccessLevel(Role.AccessLevel readAccessLevel) {
+ if (!Identity.instance().hasPermission("Node", "changeAccessLevel", getInstance()) ) {
+ throw new AuthorizationException("You don't have permission for this operation");
+ }
+ this.readAccessLevel = readAccessLevel;
+ getInstance().setReadAccessLevel(
+ readAccessLevel != null ? readAccessLevel.getAccessLevel() : UserRoleAccessFactory.ADMINROLE_ACCESSLEVEL
+ );
+ }
+
}
1.12 +6 -4 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/action/Menu.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Menu.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/action/Menu.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- Menu.java 15 Sep 2007 17:06:19 -0000 1.11
+++ Menu.java 9 Nov 2007 15:08:26 -0000 1.12
@@ -7,10 +7,8 @@
package org.jboss.seam.wiki.core.action;
import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Observer;
-import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.log.Log;
+import org.jboss.seam.annotations.*;
import org.jboss.seam.wiki.core.action.prefs.WikiPreferences;
import org.jboss.seam.wiki.core.dao.NodeDAO;
import org.jboss.seam.wiki.core.model.Directory;
@@ -28,6 +26,9 @@
@Scope(ScopeType.PAGE)
public class Menu implements Serializable {
+ @Logger
+ Log log;
+
@In
Directory wikiRoot;
@@ -47,6 +48,7 @@
@Observer(value = "Nodes.menuStructureModified", create = false)
public void refreshRoot() {
+ log.debug("Loading menu items tree");
root = nodeDAO.findMenuItems(
wikiRoot,
wikiPreferences.getMainMenuDepth(),
1.35 +34 -21 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/action/DocumentHome.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: DocumentHome.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/action/DocumentHome.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -b -r1.34 -r1.35
--- DocumentHome.java 22 Oct 2007 13:14:14 -0000 1.34
+++ DocumentHome.java 9 Nov 2007 15:08:26 -0000 1.35
@@ -20,6 +20,7 @@
import org.jboss.seam.wiki.core.dao.TagDAO;
import org.jboss.seam.wiki.core.action.prefs.DocumentEditorPreferences;
import org.jboss.seam.wiki.core.action.prefs.CommentsPreferences;
+import org.jboss.seam.wiki.core.action.prefs.WikiPreferences;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.log.Log;
@@ -27,6 +28,8 @@
import java.util.List;
import java.util.Date;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
import antlr.RecognitionException;
import antlr.ANTLRException;
@@ -56,10 +59,6 @@
String result = super.init();
if (result != null) return result;
- // Preferences
- minorRevision = (Boolean)((DocumentEditorPreferences)Component
- .getInstance("docEditorPreferences")).getProperties().get("minorRevisionEnabled");
-
// Rollback to historical revision?
if (selectedHistoricalNode != null) {
getLog().debug("rolling back to revision: " + selectedHistoricalNode.getRevision());
@@ -68,7 +67,7 @@
// Make a copy
if (historicalCopy == null) {
- historicalCopy = new Document(getInstance());
+ historicalCopy = new Document(getInstance(), true);
}
// Wiki text parser and plugins need this
@@ -83,12 +82,13 @@
/* -------------------------- Internal State ------------------------------ */
private Document historicalCopy;
- private boolean minorRevision;
+ private Boolean minorRevision;
private String formContent;
private boolean enabledPreview = false;
private boolean pushOnFeeds = false;
private boolean pushOnSiteFeed = false;
private List<Node> historicalNodes;
+ private Long numOfHistoricalNodes;
/* -------------------------- Basic Overrides ------------------------------ */
@@ -109,7 +109,7 @@
getInstance().setCreatedOn(new Date());
// Make a copy
- historicalCopy = new Document(getInstance());
+ historicalCopy = new Document(getInstance(), true);
return true;
}
@@ -118,7 +118,7 @@
String outcome = super.persist();
// Create feed entries (needs identifiers assigned, so we run after persist())
- if (outcome != null && getInstance().getReadAccessLevel() == UserRoleAccessFactory.GUESTROLE_ACCESSLEVEL && isPushOnFeeds()) {
+ if (outcome != null && isPushOnFeeds()) {
feedDAO.createFeedEntry(getInstance(), isPushOnSiteFeed());
getEntityManager().flush();
pushOnFeeds = false;
@@ -139,9 +139,13 @@
pushOnFeeds = false;
pushOnSiteFeed = false;
}
+
// Feeds should not be removed by a maintenance thread: If there
// is no activity on the site, feeds shouldn't be empty but show the last updates.
- feedDAO.purgeOldFeedEntries();
+ WikiPreferences wikiPrefs = (WikiPreferences) Component.getInstance("wikiPreferences");
+ Calendar oldestDate = GregorianCalendar.getInstance();
+ oldestDate.roll(Calendar.DAY_OF_YEAR, -wikiPrefs.getPurgeFeedEntriesAfterDays().intValue());
+ feedDAO.purgeOldFeedEntries(oldestDate.getTime());
// Write history log and prepare a new copy for further modification
if (!isMinorRevision()) {
@@ -150,7 +154,7 @@
getNodeDAO().persistHistoricalNode(historicalCopy);
getInstance().incrementRevision();
// New historical copy in conversation
- historicalCopy = new Document(getInstance());
+ historicalCopy = new Document(getInstance(), true);
// Reset form
setMinorRevision(
@@ -165,7 +169,7 @@
protected boolean prepareRemove() {
// Remove feed entry before removing document
- feedDAO.removeFeedEntry(getInstance());
+ feedDAO.removeFeedEntries(getInstance());
return super.prepareRemove();
}
@@ -214,7 +218,7 @@
getInstance().setContent(
wikiLinkResolver.convertToWikiProtocol(dir.getAreaNumber(), formContent)
);
- getInstance().setPluginsUsed( findPluginsUsed() );
+ getInstance().setMacros( findMacros() );
}
private void syncInstanceToForm(Directory dir) {
@@ -222,9 +226,9 @@
formContent = wikiLinkResolver.convertFromWikiProtocol(dir.getAreaNumber(), getInstance().getContent());
}
- private String findPluginsUsed() {
+ private String findMacros() {
if (formContent == null) return null;
- final StringBuilder usedPlugins = new StringBuilder();
+ final StringBuilder usedMacros = new StringBuilder();
WikiTextParser parser = new WikiTextParser(formContent, false, false);
parser.setCurrentDocument(getInstance());
parser.setCurrentDirectory(getParentDirectory());
@@ -241,7 +245,7 @@
public void setAttachmentLinks(List<WikiLink> attachmentLinks) {}
public void setExternalLinks(List<WikiLink> externalLinks) {}
public String renderMacro(String macroName) {
- usedPlugins.append(macroName).append(" ");
+ usedMacros.append(macroName).append(" ");
return null;
}
}
@@ -249,13 +253,13 @@
} catch (RecognitionException rex) {
// Swallow and log and low debug level
- getLog().debug( "Ignored parse error finding plugins in text: " + FormattedTextValidator.getErrorMessage(formContent, rex) );
+ getLog().debug( "Ignored parse error finding marcos in text: " + FormattedTextValidator.getErrorMessage(formContent, rex) );
} catch (ANTLRException ex) {
// All other errors are fatal;
throw new RuntimeException(ex);
}
- return usedPlugins.toString();
+ return usedMacros.toString();
}
/* -------------------------- Public Features ------------------------------ */
@@ -271,7 +275,13 @@
if (formContent != null) syncFormToInstance(getParentDirectory());
}
- public boolean isMinorRevision() { return minorRevision; }
+ public boolean isMinorRevision() {
+ // Lazily initalize preferences
+ if (minorRevision == null)
+ minorRevision = (Boolean)((DocumentEditorPreferences)Component
+ .getInstance("docEditorPreferences")).getProperties().get("minorRevisionEnabled");
+ return minorRevision;
+ }
public void setMinorRevision(boolean minorRevision) { this.minorRevision = minorRevision; }
public boolean isEnabledPreview() {
@@ -284,7 +294,7 @@
}
public boolean isSiteFeedEntryPresent() {
- return feedDAO.findSiteFeedEntry(getInstance()) != null;
+ return feedDAO.isOnSiteFeed(getInstance());
}
public boolean isPushOnFeeds() {
@@ -314,8 +324,11 @@
}
public boolean isHistoricalNodesPresent() {
- Long numOfNodes = getNodeDAO().findNumberOfHistoricalNodes(getInstance());
- return numOfNodes != null && numOfNodes > 0;
+ if (numOfHistoricalNodes == null) {
+ getLog().debug("Finding number of historical nodes for: " + getInstance());
+ numOfHistoricalNodes = getNodeDAO().findNumberOfHistoricalNodes(getInstance());
+ }
+ return numOfHistoricalNodes != null && numOfHistoricalNodes > 0;
}
public List<Node> getHistoricalNodes() {
1.9 +57 -8 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/action/Authenticator.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Authenticator.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/action/Authenticator.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- Authenticator.java 24 Sep 2007 08:23:21 -0000 1.8
+++ Authenticator.java 9 Nov 2007 15:08:26 -0000 1.9
@@ -7,7 +7,6 @@
package org.jboss.seam.wiki.core.action;
import org.jboss.seam.annotations.*;
-import org.jboss.seam.annotations.web.RequestParameter;
import org.jboss.seam.wiki.core.dao.UserDAO;
import org.jboss.seam.wiki.core.dao.NodeDAO;
import org.jboss.seam.wiki.core.dao.UserRoleAccessFactory;
@@ -18,12 +17,22 @@
import org.jboss.seam.wiki.util.Hash;
import org.jboss.seam.ScopeType;
import org.jboss.seam.Component;
+import org.jboss.seam.persistence.PersistenceProvider;
+import org.jboss.seam.log.Log;
+import org.jboss.seam.util.Base64;
+import org.jboss.seam.core.Events;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.security.Identity;
+import javax.servlet.http.HttpServletRequest;
+import java.util.Date;
+
@Name("authenticator")
public class Authenticator {
+ @Logger
+ Log log;
+
@In
private UserDAO userDAO;
@@ -37,15 +46,56 @@
public String getActivationCode() { return activationCode; }
public void setActivationCode(String activationCode) { this.activationCode = activationCode; }
+ public boolean authenticateBasicHttp(HttpServletRequest request) {
+ String auth = request.getHeader("Authorization");
+ if (auth == null || !!auth.toUpperCase().startsWith("Basic ")) {
+ log.debug("Basic HTTP authorization header not found");
+ return false;
+ }
+ String userpassEncoded = auth.substring(6);
+ String userpassDecoded = new String(Base64.decode(userpassEncoded));
+ if (!userpassDecoded.contains(":")) {
+ log.debug("Basic HTTP authorization password not supplied");
+ return false;
+ }
+ String username = userpassDecoded.substring(0, userpassDecoded.indexOf(":"));
+ String password = userpassDecoded.substring(userpassDecoded.indexOf(":")+1);
+
+ log.debug("Basic HTTP authentication for user: " + username);
+ User user = getUserForCredentials(username, password);
+ if (user == null) return false;
+ setRolesAndAccessLevels(user);
+ Events.instance().raiseEvent("User.loggedInBasicHttp", user);
+ return true;
+ }
+
public boolean authenticate() {
- if (org.jboss.seam.wiki.core.dao.UserRoleAccessFactory.GUEST_USERNAME.equals(identity.getUsername())) return false;
+ User user = getUserForCredentials(identity.getUsername(), identity.getPassword());
+ if (user == null) return false;
- User user = userDAO.findUser(identity.getUsername(), true, true);
- if (user == null ||
- identity.getPassword() == null ||
- !user.getPasswordHash().equalsIgnoreCase(hashUtil.hash(identity.getPassword())))
- return false;
+ setRolesAndAccessLevels(user);
+
+ // Set last login (storing the previous last login too, so we can create deltas between the two logins)
+ user.setPreviousLastLoginOn(user.getLastLoginOn());
+ user.setLastLoginOn(new Date());
+
+ Events.instance().raiseEvent("User.loggedIn", user);
+ return true;
+ }
+
+ private User getUserForCredentials(String username, String password) {
+ if (org.jboss.seam.wiki.core.dao.UserRoleAccessFactory.GUEST_USERNAME.equals(username)) return null;
+ User user = userDAO.findUser(username, true, true);
+ if (user == null || password == null || !user.getPasswordHash().equalsIgnoreCase(hashUtil.hash(password))) {
+ log.info("Invalid authentication credentials for user: " + username);
+ return null;
+ }
+ log.debug("Successfully authenticated user: " + user.getUsername());
+ return user;
+ }
+
+ private void setRolesAndAccessLevels(User user) {
// We don't use Seams Role class, wiki currently only uses numeric access levels
Role bestRole = (Role)Component.getInstance("guestRole");
@@ -57,7 +107,6 @@
Contexts.getSessionContext().set("currentUser", user);
Contexts.getSessionContext().set("currentAccessLevel", bestRole.getAccessLevel());
- return true;
}
public String activate() {
1.11 +4 -0 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/action/WikiIdentity.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: WikiIdentity.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/action/WikiIdentity.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- WikiIdentity.java 25 Aug 2007 17:59:24 -0000 1.10
+++ WikiIdentity.java 9 Nov 2007 15:08:26 -0000 1.11
@@ -20,6 +20,10 @@
import org.jboss.seam.Component;
import org.jboss.seam.core.Events;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
+import javax.faces.context.FacesContext;
+
/**
* Need this until Drools fixes bugs and becomes usable/debuggable.
*
1.3 +6 -1 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/action/Help.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Help.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/action/Help.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- Help.java 26 Sep 2007 09:35:00 -0000 1.2
+++ Help.java 9 Nov 2007 15:08:26 -0000 1.3
@@ -3,8 +3,9 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Logger;
import org.jboss.seam.ScopeType;
-import org.jboss.seam.Component;
+import org.jboss.seam.log.Log;
import org.jboss.seam.framework.EntityNotFoundException;
import org.jboss.seam.wiki.core.model.Document;
import org.jboss.seam.wiki.core.model.Directory;
@@ -20,6 +21,9 @@
@Scope(ScopeType.PAGE)
public class Help implements Serializable {
+ @Logger
+ Log log;
+
@In
NodeDAO nodeDAO;
@@ -33,6 +37,7 @@
if (root == null || !root.getWrappedNode().getName().equals(wikiPreferences.getHelpArea()) ) {
Directory helpAreaRoot = nodeDAO.findArea(WikiUtil.convertToWikiName(wikiPreferences.getHelpArea()));
if (helpAreaRoot != null) {
+ log.debug("Loading help documents tree");
root = nodeDAO.findMenuItems(helpAreaRoot, 99l, 1l, false);
} else {
throw new EntityNotFoundException("Help Area: '" + wikiPreferences.getHelpArea() + "'", Directory.class);
1.12 +57 -23 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/action/CommentHome.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CommentHome.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/action/CommentHome.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- CommentHome.java 12 Oct 2007 16:31:25 -0000 1.11
+++ CommentHome.java 9 Nov 2007 15:08:26 -0000 1.12
@@ -8,9 +8,11 @@
import org.jboss.seam.annotations.*;
import org.jboss.seam.ScopeType;
+import org.jboss.seam.international.Messages;
import org.jboss.seam.security.Identity;
import org.jboss.seam.security.AuthorizationException;
import org.jboss.seam.wiki.core.model.*;
+import org.jboss.seam.wiki.core.dao.FeedDAO;
import org.jboss.seam.wiki.util.WikiUtil;
import javax.persistence.EntityManager;
@@ -23,22 +25,25 @@
public class CommentHome implements Serializable {
@In
- EntityManager entityManager;
+ FeedDAO feedDAO;
@In
- DocumentHome documentHome;
+ protected EntityManager restrictedEntityManager;
@In
- User currentUser;
+ protected Document currentDocument;
@In
- User guestUser;
+ protected User currentUser;
+
+ @In
+ protected User guestUser;
@In("#{commentsPreferences.properties['listAscending']}")
- boolean listCommentsAscending;
+ protected boolean listCommentsAscending;
- private Comment comment;
- private List<Comment> comments;
+ protected Comment comment;
+ protected List<Comment> comments;
@Create
public void initialize() {
@@ -51,32 +56,43 @@
comments = new ArrayList<Comment>();
//noinspection unchecked
- comments = entityManager
- .createQuery("select c from Comment c where c.document is :doc" +
+ comments = restrictedEntityManager
+ .createQuery("select c from Comment c left join fetch c.fromUser u left join fetch u.profile fetch all properties where c.document is :doc" +
" order by c.createdOn " + (listCommentsAscending ? "asc" : "desc") )
- .setParameter("doc", documentHome.getInstance())
+ .setParameter("doc", currentDocument)
.setHint("org.hibernate.cacheable", true)
.getResultList();
+ createComment(); // Stay inside the same persistence context
+ }
+
+ public void createComment() {
+
+ User user = restrictedEntityManager.find(User.class, currentUser.getId());
+
comment = new Comment();
- if (!currentUser.getId().equals(guestUser.getId())) {
- comment.setFromUserName(currentUser.getFullname());
- comment.setFromUserEmail(currentUser.getEmail());
+ if (!user.getId().equals(guestUser.getId())) {
+ comment.setFromUserName(user.getFullname());
+ comment.setFromUserEmail(user.getEmail());
+ // Profile website overrides member home website
comment.setFromUserHomepage(
- currentUser.getMemberHome() != null
- ? WikiUtil.renderHomeURL(currentUser)
- : null);
+ user.getProfile() != null && user.getProfile().getWebsite() != null
+ ? user.getProfile().getWebsite()
+ : user.getMemberHome() != null ? WikiUtil.renderHomeURL(user) : null);
}
// Default to title of document as subject
- comment.setSubject(documentHome.getInstance().getName());
+ comment.setSubject(currentDocument.getName());
+
+ // Default to help text
+ comment.setText(Messages.instance().get("lacewiki.msg.commentForm.EditThisTextPreviewUpdatesAutomatically"));
}
public void persist() {
- Document currentDocument = entityManager.merge(documentHome.getInstance());
- comment.setDocument(currentDocument);
- currentDocument.getComments().add(comment);
+ Document doc = restrictedEntityManager.find(Document.class, currentDocument.getId());
+ comment.setDocument(doc);
+ doc.getComments().add(comment);
// Null out the property so that the @Email validator doesn't fall over it...
// I hate JSF and its "let's set an empty string" behavior
@@ -86,23 +102,41 @@
: null
);
- entityManager.persist(comment);
+ restrictedEntityManager.persist(comment);
+
+ pushOnFeeds(doc, null);
refreshComments();
+ createComment();
}
public void remove(Long commentId) {
- Comment foundCommment = entityManager.find(Comment.class, commentId);
+ Comment foundCommment = restrictedEntityManager.find(Comment.class, commentId);
if (foundCommment != null) {
if (!Identity.instance().hasPermission("Comment", "delete", foundCommment.getDocument()) ) {
throw new AuthorizationException("You don't have permission for this operation");
}
- entityManager.remove(foundCommment);
+ restrictedEntityManager.remove(foundCommment);
+
+ Document doc = restrictedEntityManager.find(Document.class, currentDocument.getId());
+ feedDAO.removeFeedEntry(doc, foundCommment);
}
refreshComments();
+ createComment();
+ }
+
+ protected void pushOnFeeds(Document document, String title) {
+
+ String feedEntryTitle =
+ title == null
+ ? Messages.instance().get("lacewiki.label.comment.FeedEntryTitlePrefix") + " " + comment.getSubject()
+ : title;
+ if (currentDocument.getEnableComments() && document.getEnableCommentsOnFeeds()) {
+ feedDAO.createFeedEntry(document, comment, false, feedEntryTitle);
+ }
}
public Comment getComment() {
1.21 +11 -15 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/action/DirectoryHome.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: DirectoryHome.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/action/DirectoryHome.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- DirectoryHome.java 12 Oct 2007 16:31:25 -0000 1.20
+++ DirectoryHome.java 9 Nov 2007 15:08:26 -0000 1.21
@@ -14,6 +14,7 @@
import org.jboss.seam.ScopeType;
import org.jboss.seam.wiki.core.model.*;
import org.jboss.seam.wiki.core.dao.WikiTreeNodeAdapter;
+import org.jboss.seam.wiki.core.dao.FeedDAO;
import org.jboss.seam.wiki.util.WikiUtil;
import org.richfaces.model.TreeNode;
@@ -26,6 +27,8 @@
/* -------------------------- Context Wiring ------------------------------ */
+ @In
+ FeedDAO feedDAO;
/* -------------------------- Request Wiring ------------------------------ */
@@ -135,35 +138,28 @@
}
}
- private void createOrRemoveFeed() {
+ public void createOrRemoveFeed() {
if (hasFeed && getInstance().getFeed() == null) {
// Does not have a feed but user wants one, create it
- Feed feed = new Feed();
- feed.setDirectory(getInstance());
- feed.setAuthor(getInstance().getCreatedBy().getFullname());
- feed.setTitle(getInstance().getName());
- feed.setDescription(getInstance().getDescription());
- getInstance().setFeed(feed);
+ feedDAO.createFeed(getInstance());
getFacesMessages().addFromResourceBundleOrDefault(
FacesMessage.SEVERITY_INFO,
- "feedCreated",
+ "lacewiki.msg.Feed.Create",
"Created syndication feed for this directory");
} else if (!hasFeed && getInstance().getFeed() != null) {
// Does have feed but user doesn't want it anymore... delete it
- getEntityManager().remove(getInstance().getFeed());
- getInstance().setFeed(null);
+ feedDAO.removeFeed(getInstance());
getFacesMessages().addFromResourceBundleOrDefault(
FacesMessage.SEVERITY_INFO,
- "feedRemoved",
+ "lacewiki.msg.Feed.Remove",
"Removed syndication feed of this directory");
+
} else if (getInstance().getFeed() != null) {
// Does have a feed and user still wants it, update the feed
- getInstance().getFeed().setTitle(getInstance().getName());
- getInstance().getFeed().setAuthor(getInstance().getCreatedBy().getFullname());
- getInstance().getFeed().setDescription(getInstance().getDescription());
+ feedDAO.updateFeed(getInstance());
}
}
@@ -212,7 +208,7 @@
getInstance().getFeed().setPublishedDate(new Date());
getFacesMessages().addFromResourceBundleOrDefault(
FacesMessage.SEVERITY_INFO,
- "feedReset",
+ "lacewiki.msg.Feed.Reset",
"Queued removal of all feed entries from the syndication feed of this directory, please update to finalize");
}
}
More information about the jboss-cvs-commits
mailing list