Author: deepal
Date: Wed Jan 9 04:21:15 2008
New Revision: 12076
Log:
API changes
- put
- addComments
- editComments
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/Comment.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/comments/CommentManager.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/CommentsDAO.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentURLHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/inmemory/InMemoryRegistryTest.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
trunk/registry/modules/webapps/src/main/webapp/admin/comments.jsp
trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/Comment.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/Comment.java
(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/Comment.java
Wed Jan 9 04:21:15 2008
@@ -23,38 +23,47 @@
public class Comment {
- private String commentText;
- private String commentedUser;
- private Date commentedTime;
+ private String text;
+ private String user;
+ private Date time;
+ private String path;
public Comment() {
}
public Comment(String commentText) {
- this.commentText = commentText;
+ this.text = commentText;
}
- public String getCommentText() {
- return commentText;
+ public String getText() {
+ return text;
}
- public void setCommentText(String commentText) {
- this.commentText = commentText;
+ public void setText(String text) {
+ this.text = text;
}
- public String getCommentedUser() {
- return commentedUser;
+ public String getUser() {
+ return user;
}
- public void setCommentedUser(String commentedUser) {
- this.commentedUser = commentedUser;
+ public void setUser(String user) {
+ this.user = user;
}
- public Date getCommentedTime() {
- return commentedTime;
+ public Date getTime() {
+ return time;
}
- public void setCommentedTime(Date commentedTime) {
- this.commentedTime = commentedTime;
+ public void setTime(Date time) {
+ this.time = time;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
}
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
Wed Jan 9 04:21:15 2008
@@ -47,12 +47,10 @@
* resource is added. If a resource already exist in the given path, it
will be replaced with
* the new resource.
*
- * @param path Path of the new resource
- * @param resource Resource instance for the new resource
- * @throws org.wso2.registry.RegistryException
- * is thrown if the storage exception is encountered.
+ * @param suggestedPath
+ * @param resource Resource instance for the new resource @throws
org.wso2.registry.RegistryException
*/
- void put(String path, Resource resource) throws RegistryException;
+ String put(String suggestedPath, Resource resource) throws
RegistryException;
/**
* Deletes the resource in the given path. If the path refers to a
directory, all child
@@ -137,7 +135,9 @@
* @param comment Comment instance for the new comment.
* @throws RegistryException is thrown if a resource does not exist in the
given path.
*/
- void addComment(String resourcePath, Comment comment) throws
RegistryException;
+ String addComment(String resourcePath, Comment comment) throws
RegistryException;
+
+ void editComment(String commentPath, String text) throws RegistryException;
/**
* Retruns all comments for the given resource.
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
Wed Jan 9 04:21:15 2008
@@ -95,12 +95,17 @@
getSecureRegistry(request).applyTag(resourcePath,
entryContent);
} else if
(RegistryConstants.PARAMETER_COMMENTS.equals(operation)) {
Comment comment = new Comment();
- comment.setCommentText(entryContent);
-
comment.setCommentedUser(entry.getAuthor().getName());
- comment.setCommentedTime(entry.getUpdated());
-
getSecureRegistry(request).addComment(resourcePath, comment);
+ comment.setText(entryContent);
+ comment.setUser(entry.getAuthor().getName());
+ comment.setTime(entry.getUpdated());
+ String commentPath =
getSecureRegistry(request).addComment(resourcePath,
+ comment);
+ EmptyResponseContext responseContext = new
EmptyResponseContext(200);
+ responseContext.setLocation(commentPath);
+ return responseContext;
} else if
(RegistryConstants.PARAMETER_RATINGS.equals(operation)) {
-
getSecureRegistry(request).rateResource(resourcePath,
Integer.parseInt(entryContent));
+
getSecureRegistry(request).rateResource(resourcePath,
+ Integer.parseInt(entryContent));
} else {
//TODO : We need to implement the other operation
as well
return new EmptyResponseContext(500);
@@ -216,13 +221,8 @@
getSecureRegistry(request).rateResource(path,
Integer.parseInt(rate));
} else if
(RegistryConstants.PARAMETER_COMMENTS.equals(operation)) {
String path = values[0];
- String author = entry.getAuthor().getName();
String commentString = entry.getContent();
- Comment comment = new Comment();
- comment.setCommentedTime(entry.getUpdated());
- comment.setCommentedUser(author);
- comment.setCommentText(commentString);
- getSecureRegistry(request).addComment(path, comment);
+ getSecureRegistry(request).editComment(path,
commentString);
}
}
return new EmptyResponseContext(200);
@@ -713,9 +713,9 @@
for (Comment comment : comments) {
Entry entry = abdera.getFactory().newEntry();
entry.setId("http://wso2.org/jdbcregistry/atom/comment");
- entry.addAuthor(comment.getCommentedUser());
- entry.setUpdated(comment.getCommentedTime());
- entry.setContent(comment.getCommentText());
+ entry.addAuthor(comment.getUser());
+ entry.setUpdated(comment.getTime());
+ entry.setContent(comment.getText());
feed.addEntry(entry);
}
return feed;
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
Wed Jan 9 04:21:15 2008
@@ -163,7 +163,7 @@
return (response.getType() == Response.ResponseType.SUCCESS);
}
- public void put(String path, Resource resource) throws RegistryException {
+ public String put(String suggestedPath, Resource resource) throws
RegistryException {
// Figure out where we're POSTing to...
Abdera abdera = new Abdera();
@@ -196,13 +196,14 @@
entry.setContent((String) content);
}
}
- ClientResponse resp = abderaClient.post(baseURI + path, entry,
getAuthorization());
+ ClientResponse resp = abderaClient.post(baseURI + suggestedPath,
entry, getAuthorization());
if (resp.getType() == Response.ResponseType.SUCCESS) {
- log.info(Messages.getMessage("resource.add", path));
+ log.info(Messages.getMessage("resource.add", suggestedPath));
} else {
- log.error(Messages.getMessage("add.resource.fail", path));
- throw new
RegistryException(Messages.getMessage("add.resource.fail", path));
+ log.error(Messages.getMessage("add.resource.fail", suggestedPath));
+ throw new
RegistryException(Messages.getMessage("add.resource.fail", suggestedPath));
}
+ return suggestedPath;
}
public void delete(String path) throws RegistryException {
@@ -335,24 +336,42 @@
}
}
- public void addComment(String resourcePath, Comment comment) throws
RegistryException {
+ public String addComment(String resourcePath, Comment comment) throws
RegistryException {
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
Entry entry = abdera.getFactory().newEntry();
- entry.setUpdated(comment.getCommentedTime());
- entry.addAuthor(comment.getCommentedUser());
- entry.setContent(comment.getCommentText());
- ClientResponse resp = abderaClient.put(baseURI + resourcePath +
+ entry.setUpdated(comment.getTime());
+ entry.addAuthor(comment.getUser());
+ entry.setContent(comment.getText());
+ ClientResponse resp = abderaClient.post(baseURI + resourcePath +
URL_SEPARATOR +
PARAMETER_COMMENTS, entry , getAuthorization());
if (resp.getType() == Response.ResponseType.SUCCESS) {
log.info(Messages.getMessage("resource.commented", resourcePath));
+ return resp.getLocation().toString();
} else {
log.error(Messages.getMessage("resouce.comment.fails",
resourcePath));
throw new
RegistryException(Messages.getMessage("resouce.comment.fails", resourcePath));
}
}
+
+ public void editComment(String commentPath, String text) throws
RegistryException {
+ Abdera abdera = new Abdera();
+ AbderaClient abderaClient = new AbderaClient(abdera);
+ Entry entry = abdera.getFactory().newEntry();
+ entry.setContent(text);
+ ClientResponse resp = abderaClient.put(baseURI + commentPath +
+ URL_SEPARATOR +
+ PARAMETER_COMMENTS, entry, getAuthorization());
+ if (resp.getType() == Response.ResponseType.SUCCESS) {
+ log.info(Messages.getMessage("resource.commented", commentPath));
+ } else {
+ log.error(Messages.getMessage("resouce.comment.fails",
commentPath));
+ throw new
RegistryException(Messages.getMessage("resouce.comment.fails", commentPath));
+ }
+ }
+
public Comment[] getComments(String resourcePath) throws RegistryException
{
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
@@ -370,9 +389,9 @@
for (int i = 0; i < entries.size(); i++) {
Entry entry = (Entry) entries.get(i);
Comment comment = new Comment();
- comment.setCommentedTime(entry.getUpdated());
- comment.setCommentText(entry.getContent());
- comment.setCommentedUser(entry.getAuthor().getName());
+ comment.setTime(entry.getUpdated());
+ comment.setText(entry.getContent());
+ comment.setUser(entry.getAuthor().getName());
comments[i] = comment;
}
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistry.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistry.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistry.java
Wed Jan 9 04:21:15 2008
@@ -69,19 +69,15 @@
/**
* Creates and updates resources (directories, repositories, content
resourcess)
*
- * @param path Path of the resource. e.g. foo/bar/myresource. In this
case Directories foo
- * and foo/bar should exists in the resourceMap. If they
do not exists they will
- * be created.
+ * @param suggestedPath
* @param resource Resource to be placed in the given path. It can be a
normal resource
- * (resource containing content), a general directory or a
special directory
- * (e.g. synapse repository)
*/
- public synchronized void put(String path, Resource resource) throws
RegistryException {
+ public synchronized String put(String suggestedPath, Resource resource)
throws RegistryException {
- resource.setPath(path);
+ resource.setPath(suggestedPath);
resource.setLastModified(new Date());
- String[] parts = path.split(RegistryConstants.PATH_SEPARATOR);
+ String[] parts = suggestedPath.split(RegistryConstants.PATH_SEPARATOR);
// check if the new resource is a top level resource
if (parts.length > 1) {
@@ -117,7 +113,7 @@
currentDirectory = r;
} else {
String message =
- Messages.getMessage("resource.delete.error",
currentPath, path);
+ Messages.getMessage("resource.delete.error",
currentPath, suggestedPath);
log.error(message);
throw new RegistryException(message);
}
@@ -126,14 +122,15 @@
updateArtifact(currentDirectory, resource.getPath());
// now we have the parent directory for the new resource. add the
new resource to
// the resourceMap and make it a child of the parent directory
- resourceMap.put(path, resource);
+ resourceMap.put(suggestedPath, resource);
} else {
Resource root =
(Resource)resourceMap.get(RegistryConstants.ROOT_PATH);
- updateArtifact(root, path);
+ updateArtifact(root, suggestedPath);
// new resource is a top level resource. just add it to the
resourceMap
- resourceMap.put(path, resource);
+ resourceMap.put(suggestedPath, resource);
}
+ return suggestedPath;
}
private void updateArtifact(Resource currentDirectory, String currentPath)
{
@@ -214,9 +211,15 @@
"Removing
tags"));
}
- public synchronized void addComment(String resourcePath, Comment comment)
+ public synchronized String addComment(String resourcePath, Comment comment)
throws RegistryException {
- commentManager.addComment(resourcePath, comment);
+ return resourcePath + ";comments:" +
commentManager.addComment(resourcePath, comment);
+ }
+
+
+ public void editComment(String commentPath, String text) throws
RegistryException {
+ throw new
UnsupportedOperationException(Messages.getMessage("unsupported.exception",
+ "edit
comments"));
}
public Comment[] getComments(String resourcePath) throws RegistryException
{
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/comments/CommentManager.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/comments/CommentManager.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/comments/CommentManager.java
Wed Jan 9 04:21:15 2008
@@ -36,13 +36,13 @@
this.inMemoryRegistryProvider = inMemoryRegistryProvider;
}
- public void addComment(String resourcePath, Comment comment) throws
RegistryException {
+ public int addComment(String resourcePath, Comment comment) throws
RegistryException {
if (!inMemoryRegistryProvider.isResourceAvailable(resourcePath)) {
throw new
RegistryException(Messages.getMessage("cannotadd.comment", resourcePath));
}
- comment.setCommentedTime(new Date());
+ comment.setTime(new Date());
List resourceComments = (List)comments.get(resourcePath);
@@ -52,6 +52,7 @@
}
resourceComments.add(comment);
+ return resourceComments.size() - 1;
}
public Comment[] getComments(String resourcePath) {
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
Wed Jan 9 04:21:15 2008
@@ -235,21 +235,19 @@
* the new resource. Implementations may use a concurrency control method
to prevent concurrency
* issues.
*
- * @param path Path of the new resource
- * @param resource Resource instance for the new resource
- * @throws org.wso2.registry.RegistryException
- * : if the user is not authorized
+ * @param suggestedPath
+ * @param resource Resource instance for the new resource @throws
org.wso2.registry.RegistryException
*/
- public synchronized void put(String path, Resource resource) throws
RegistryException {
- path = preparePath(path);
- mediaTypeManager.put(path, resource);
+ public synchronized String put(String suggestedPath, Resource resource)
throws RegistryException {
+ suggestedPath = preparePath(suggestedPath);
+ mediaTypeManager.put(suggestedPath, resource);
Connection conn = getConnection();
try {
conn.setAutoCommit(false);
- long resourceID = resourceDAO.getResourceID(path, conn);
+ long resourceID = resourceDAO.getResourceID(suggestedPath, conn);
logsDAO.addLog(resourceID, User.getCurrentUser(), LogEntry.UPDATE,
null, conn);
conn.commit();
@@ -272,6 +270,7 @@
log.info("Exception while closing the DB connection in put
method of JDBCRegistry");
}
}
+ return suggestedPath;
}
/**
@@ -633,7 +632,7 @@
* @throws RegistryException ResourceNotFound exception is thrown if a
resource does not exist
* in the given path.
*/
- public synchronized void addComment(String resourcePath, Comment comment)
+ public synchronized String addComment(String resourcePath, Comment comment)
throws RegistryException {
resourcePath = preparePath(resourcePath);
@@ -641,15 +640,16 @@
Connection conn = getConnection();
String userID = User.getCurrentUser();
-
+ String commentPath;
try {
conn.setAutoCommit(false);
Resource resource = resourceDAO.getLatestVersion(resourcePath,
conn);
if (resource != null) {
- commentsDAO.addComment(resource.getId(), userID, comment,
conn);
+ commentPath = commentsDAO.addComment(resource.getId(), userID,
comment, conn);
+ commentPath = resourcePath + ";comments:" + commentPath;
logsDAO.addLog(
- resource.getId(), userID, LogEntry.COMMENT,
comment.getCommentText(), conn);
+ resource.getId(), userID, LogEntry.COMMENT,
comment.getText(), conn);
} else {
String msg = Messages.getMessage("comment.on.null.artfact",
resourcePath);
@@ -668,7 +668,7 @@
}
String msg = Messages.
- getMessage("resource.comment.fail", resourcePath,
comment.getCommentText());
+ getMessage("resource.comment.fail", resourcePath,
comment.getText());
log.error(msg, e);
throw new RegistryException(msg);
@@ -680,7 +680,21 @@
e.printStackTrace();
}
}
+ return commentPath;
+ }
+
+ public void editComment(String commentPath, String text) throws
RegistryException {
+ String [] parts = commentPath.split(";");
+ String commentPart = parts[1];
+ if (parts.length == 2 && commentPart.startsWith("comments:")) {
+ String commentId = parts[1].substring(9);
+ try {
+ commentsDAO.updateComment(Long.parseLong(commentId), text,
getConnection());
+ } catch (SQLException e) {
+ //TODO : i18n
+ }
+ }
}
/**
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/CommentsDAO.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/CommentsDAO.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/CommentsDAO.java
Wed Jan 9 04:21:15 2008
@@ -28,7 +28,7 @@
public class CommentsDAO {
- public void addComment(long artifactID, String userID, Comment comment,
Connection conn)
+ public String addComment(long artifactID, String userID, Comment comment,
Connection conn)
throws SQLException {
String sql = "INSERT INTO COMMENTS (AID, USER_ID, COMMENT_TEXT,
COMMENTED_TIME) " +
@@ -39,9 +39,32 @@
PreparedStatement s = conn.prepareStatement(sql);
s.setLong(1, artifactID);
s.setString(2, userID);
- s.setString(3, comment.getCommentText());
+ s.setString(3, comment.getText());
s.setDate(4, new Date(now));
+ s.executeUpdate();
+
+ sql = "SELECT CM_ID FROM COMMENTS WHERE AID=? AND USER_ID=? AND
COMMENTED_TIME=?";
+ s = conn.prepareStatement(sql);
+ s.setLong(1, artifactID);
+ s.setString(2, userID);
+ s.setDate(3, new Date(now));
+ ResultSet result = s.executeQuery();
+
+ if (result.next()) {
+ return result.getString(1);
+ }
+ return null;
+ }
+ public void updateComment(long commentId, String text, Connection conn)
+ throws SQLException {
+
+ String sql = "UPDATE COMMENTS SET COMMENT_TEXT=?,COMMENTED_TIME=?
WHERE CM_ID=?";
+ long now = System.currentTimeMillis();
+ PreparedStatement s = conn.prepareStatement(sql);
+ s.setString(1, text);
+ s.setDate(2, new Date(now));
+ s.setLong(3, commentId);
s.executeUpdate();
}
@@ -57,9 +80,9 @@
ResultSet results = s.executeQuery();
while (results.next()) {
Comment comment = new Comment();
-
comment.setCommentText(results.getString(DatabaseConstants.COMMENT_TEXT_FIELD));
-
comment.setCommentedUser(results.getString(DatabaseConstants.COMMENTED_USER_ID_FIELD));
-
comment.setCommentedTime(results.getTimestamp(DatabaseConstants.COMMENTED_TIME_FIELD));
+
comment.setText(results.getString(DatabaseConstants.COMMENT_TEXT_FIELD));
+
comment.setUser(results.getString(DatabaseConstants.COMMENTED_USER_ID_FIELD));
+
comment.setTime(results.getTimestamp(DatabaseConstants.COMMENTED_TIME_FIELD));
commentList.add(comment);
}
@@ -87,9 +110,9 @@
if (result.next()) {
Comment comment = new Comment();
-
comment.setCommentText(result.getString(DatabaseConstants.COMMENT_TEXT_FIELD));
-
comment.setCommentedUser(result.getString(DatabaseConstants.COMMENTED_USER_ID_FIELD));
-
comment.setCommentedTime(result.getDate(DatabaseConstants.COMMENTED_TIME_FIELD));
+
comment.setText(result.getString(DatabaseConstants.COMMENT_TEXT_FIELD));
+
comment.setUser(result.getString(DatabaseConstants.COMMENTED_USER_ID_FIELD));
+
comment.setTime(result.getDate(DatabaseConstants.COMMENTED_TIME_FIELD));
return comment;
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentURLHandler.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentURLHandler.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentURLHandler.java
Wed Jan 9 04:21:15 2008
@@ -112,9 +112,9 @@
resource.setPath(url);
resource.setMediaType(RegistryConstants.COMMENT_MEDIA_TYPE);
- resource.setContent(comment.getCommentText());
- resource.setAuthorUserName(comment.getCommentedUser());
- resource.setCreatedTime(comment.getCommentedTime());
+ resource.setContent(comment.getText());
+ resource.setAuthorUserName(comment.getUser());
+ resource.setCreatedTime(comment.getTime());
resource.setProperty("resourcePath", resourcePath);
return true;
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
Wed Jan 9 04:21:15 2008
@@ -203,14 +203,13 @@
* Then sets the default permissions for newly created paths. i.e. in the
above sample, default
* permissions are set for "/d1/d2/d3" and "/d1/d2/d3/r1".
*
- * @param path Path to put the new resource
- * @param resource New resource
- * @throws RegistryException
+ * @param suggestedPath
+ * @param resource New resource @throws RegistryException
*/
- public void put(String path, Resource resource) throws RegistryException {
+ public String put(String suggestedPath, Resource resource) throws
RegistryException {
// find the existing ascendent path of the given path
- String pathToSplit = path;
+ String pathToSplit = suggestedPath;
if (pathToSplit.startsWith(RegistryConstants.PATH_SEPARATOR)) {
pathToSplit =
pathToSplit.substring(RegistryConstants.PATH_SEPARATOR.length());
}
@@ -255,7 +254,7 @@
// updatedOnly = true;
// }
- registry.put(path, resource);
+ registry.put(suggestedPath, resource);
// we should set default permissions for all newly created paths
//if (!updatedOnly) {
@@ -266,6 +265,7 @@
// setDefaultAuthorizations(newPath, userID);
// }
//}
+ return suggestedPath;
}
public void delete(String path) throws RegistryException {
@@ -432,7 +432,7 @@
registry.removeTag(resourcePath, tag);
}
- public void addComment(String resourcePath, Comment comment) throws
RegistryException {
+ public String addComment(String resourcePath, Comment comment) throws
RegistryException {
// if the user has permission to the current version, he will get
permission to all
// previous versions of the same resource
@@ -457,7 +457,33 @@
}
User.setCurrentUser(userID);
- registry.addComment(resourcePath, comment);
+ return registry.addComment(resourcePath, comment);
+ }
+
+
+ public void editComment(String commentPath, String text) throws
RegistryException {
+ // if the user has permission to the current version, he will get
permission to all
+ // previous versions of the same resource
+ String authorizationPath = commentPath;
+ if (commentPath.indexOf(";") > 0) {
+ authorizationPath = commentPath.split(";")[0];
+ }
+
+ try {
+ if (!authorizer.isUserAuthorized(userID, authorizationPath,
ActionConstants.GET)) {
+ String msg = "User: " + userID + " is not authorized to
comment on the resource: " +
+ authorizationPath;
+ log.info(msg);
+ throw new AuthorizationFailedException(msg);
+ }
+ } catch (UserManagerException e) {
+ String msg = "Could not check authorization. \nCaused by " +
e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg);
+ }
+
+ User.setCurrentUser(userID);
+ registry.editComment(commentPath, text);
}
public Comment[] getComments(String resourcePath) throws RegistryException
{
Modified:
trunk/registry/modules/core/src/test/java/org/wso2/registry/inmemory/InMemoryRegistryTest.java
==============================================================================
---
trunk/registry/modules/core/src/test/java/org/wso2/registry/inmemory/InMemoryRegistryTest.java
(original)
+++
trunk/registry/modules/core/src/test/java/org/wso2/registry/inmemory/InMemoryRegistryTest.java
Wed Jan 9 04:21:15 2008
@@ -253,7 +253,7 @@
boolean commentFound = false;
for (int i = 0; i < comments.length; i++) {
- if (comments[i].getCommentText().equals(comment1)) {
+ if (comments[i].getText().equals(comment1)) {
commentFound = true;
break;
}
Modified:
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
==============================================================================
---
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
(original)
+++
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
Wed Jan 9 04:21:15 2008
@@ -21,16 +21,11 @@
import junit.framework.TestCase;
import org.wso2.registry.*;
-import org.wso2.registry.secure.HSQLDBInitializer;
-import org.wso2.registry.jdbc.utils.RegistryDataSource;
-import org.wso2.registry.jdbc.hsql.DBUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
-import java.sql.SQLException;
-import java.sql.Connection;
public class JDBCRegistryTest extends TestCase {
@@ -412,7 +407,7 @@
boolean commentFound = false;
for (Comment comment : comments) {
- if (comment.getCommentText().equals(comment1)) {
+ if (comment.getText().equals(comment1)) {
commentFound = true;
break;
}
Modified: trunk/registry/modules/webapps/src/main/webapp/admin/comments.jsp
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/comments.jsp
(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/comments.jsp Wed Jan
9 04:21:15 2008
@@ -32,13 +32,13 @@
<div class="heading">Comments</div>
<div class="detail-section">
-<% Comment[] comments = registry.getComments(path);
- for (int i = 0; i < comments.length; i++) {
- String comment = comments[i].getCommentText();
- String commentedTime = comments[i].getCommentedTime().toString();
- String commentedUser = comments[i].getCommentedUser();
-
- %>
+<% Comment[] comments = registry.getComments(path);
+ for (int i = 0; i < comments.length; i++) {
+ String comment = comments[i].getText();
+ String commentedTime = comments[i].getTime().toString();
+ String commentedUser = comments[i].getUser();
+
+%>
<ul>
<li><%=comment%> <br/><span style=" padding:20px; color:#666666">posted on
<%=commentedTime%> by <%=commentedUser%></span></li>
</ul>
Modified:
trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp
(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp
Wed Jan 9 04:21:15 2008
@@ -526,9 +526,9 @@
Comment comment = (Comment) iComments.next();
%>
<div class="comments-header">
- <strong>Commented on
</strong><%=comment.getCommentedTime().toString()%><strong> by</strong> <a
href="#"><%=comment.getCommentedUser()%></a>
+ <strong>Commented on
</strong><%=comment.getTime().toString()%><strong> by</strong> <a
href="#"><%=comment.getUser()%></a>
<div class="comments-bottom">
- <%=comment.getCommentText()%>
+ <%=comment.getText()%>
</div>
</div>
_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev