Author: chathura
Date: Tue Jan 22 22:02:11 2008
New Revision: 12738
Log:
Implemented comment delete functionality in the comment url hander. Now
registry.delete(<comment-url>) works.
Added a test case to test this.
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/urlhandlers/CommentCollectionURLHandler.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/jdbc/urlhandlers/RatingURLHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingsCollectionURLHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/TagURLHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandlerManager.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/CommentTest.java
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
Tue Jan 22 22:02:11 2008
@@ -68,6 +68,16 @@
s.executeUpdate();
}
+ public void deleteComment(long commentId, Connection conn)
+ throws SQLException {
+
+ String sql = "DELETE FROM COMMENTS WHERE CM_ID=?";
+
+ PreparedStatement s = conn.prepareStatement(sql);
+ s.setLong(1, commentId);
+ s.executeUpdate();
+ }
+
public Comment[] getComments(String path, Connection conn) throws
SQLException {
String sql =
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentCollectionURLHandler.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentCollectionURLHandler.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentCollectionURLHandler.java
Tue Jan 22 22:02:11 2008
@@ -38,7 +38,7 @@
super(dataSource, realm);
}
- public Resource handleURL(String url) throws RegistryException {
+ public Resource get(String url) throws RegistryException {
String[] parts = url.split(";");
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
Tue Jan 22 22:02:11 2008
@@ -45,7 +45,7 @@
* @param url
* @return
*/
- public Resource handleURL(String url) throws RegistryException {
+ public Resource get(String url) throws RegistryException {
String[] parts = url.split(";");
@@ -120,4 +120,53 @@
return resource;
}
+
+ public boolean delete(String path) throws RegistryException {
+
+ String[] parts = path.split(";");
+
+ if (parts.length != 2) {
+ return false;
+ }
+
+ if (parts[0].length() == 0) {
+ return false;
+ }
+
+ if (!parts[1].startsWith("comments:")) {
+ return false;
+ }
+
+ String commentID = parts[1].substring("comments:".length());
+ if (!(commentID.length() > 0)) {
+ return false;
+ }
+
+ long cID ;
+ try {
+ cID = Long.parseLong(commentID);
+
+ } catch (NumberFormatException e) {
+ // note that this might not be an exceptional scenario. there
could be a different URL
+ // form, which contains strings after "comment".
+ // it is just that it is not the URL we expect here
+ return false;
+ }
+
+ Connection conn;
+ try {
+ conn = dataSource.getConnection();
+ } catch (SQLException e) {
+ throw new RegistryException(e.getMessage());
+ }
+
+ try {
+ commentsDAO.deleteComment(cID, conn);
+ } catch (SQLException e) {
+ String msg = "Could not delete the comment with the path: " + path;
+ throw new RegistryException(msg, e);
+ }
+
+ return true;
+ }
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingURLHandler.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingURLHandler.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingURLHandler.java
Tue Jan 22 22:02:11 2008
@@ -37,7 +37,7 @@
super(dataSource, realm);
}
- public Resource handleURL(String url) throws RegistryException {
+ public Resource get(String url) throws RegistryException {
String[] parts = url.split(";");
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingsCollectionURLHandler.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingsCollectionURLHandler.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingsCollectionURLHandler.java
Tue Jan 22 22:02:11 2008
@@ -37,7 +37,7 @@
super(dataSource, realm);
}
- public Resource handleURL(String url) throws RegistryException {
+ public Resource get(String url) throws RegistryException {
String[] parts = url.split(";");
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/TagURLHandler.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/TagURLHandler.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/TagURLHandler.java
Tue Jan 22 22:02:11 2008
@@ -40,7 +40,7 @@
* @return
* @throws RegistryException
*/
- public Resource handleURL(String url) throws RegistryException {
+ public Resource get(String url) throws RegistryException {
String[] parts = url.split(";");
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandler.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandler.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandler.java
Tue Jan 22 22:02:11 2008
@@ -45,10 +45,11 @@
}
/**
- * Determine if the given url can be handled. If yes, process the request
and return the
- * resulting resource. Further processing of the resource is terminated if
a resource is
- * returned. If the given url cannot be handled return null, which causes
other url
- * handlers to process the request, or the request to be reached the media
type handlers.
+ * Determine if get(...) on the given url can be handled. If yes, process
the request and
+ * return the resulting resource. Further processing of the resource is
terminated
+ * if a resource is returned. If the given url cannot be handled return
null,
+ * which causes other url handlers to process the request, or the request
to be reached
+ * the media type handlers.
*
* @param url URL to process
*
@@ -57,5 +58,38 @@
*
* @throws RegistryException
*/
- public abstract Resource handleURL(String url) throws RegistryException;
+ public Resource get(String url) throws RegistryException {
+ return null;
+ }
+
+ /**
+ * Determine if put(...) on the given url can be handled. If yes, process
the request and
+ * persisting the resulting resource. Further processing of the resource
is terminated
+ * if string (actual path) is returned. If the given url cannot be handled
return null,
+ * which causes other url handlers to process the request, or the request
to be reached
+ * the media type handlers.
+ *
+ * @param suggestPath
+ * @param resource
+ * @return
+ * @throws RegistryException
+ */
+ public String put(String suggestPath, Resource resource) throws
RegistryException {
+ return null;
+ }
+
+ /**
+ * Determine if delete(...) on the given url can be handled. If yes,
process the request and
+ * delete the resulting resource. Further processing of the resource is
terminated
+ * if true is returned. If the given url cannot be handled return false,
+ * which causes other url handlers to process the request, or the request
to be reached
+ * the media type handlers.
+ *
+ * @param path
+ * @return
+ * @throws RegistryException
+ */
+ public boolean delete(String path) throws RegistryException {
+ return false;
+ }
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandlerManager.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandlerManager.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandlerManager.java
Tue Jan 22 22:02:11 2008
@@ -80,7 +80,7 @@
while (i.hasNext()) {
URLHandler urlHandler = (URLHandler)i.next();
- if ((resource = urlHandler.handleURL(url)) != null) {
+ if ((resource = urlHandler.get(url)) != null) {
return resource;
}
}
Modified:
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/CommentTest.java
==============================================================================
---
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/CommentTest.java
(original)
+++
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/CommentTest.java
Tue Jan 22 22:02:11 2008
@@ -422,6 +422,54 @@
*/
}
+ public void testCommentDelete() {
+
+ try {
+ String r1Path = "/c1d1/c1";
+ Resource r1 = new Resource();
+ r1.setDirectory(true);
+ registry.put(r1Path, r1);
+
+ String c1Path = registry.addComment(r1Path, new Comment("test
comment1"));
+ String c2Path = registry.addComment(r1Path, new Comment("test
comment2"));
+
+ Comment[] comments1 = registry.getComments(r1Path);
+
+ assertEquals("There should be two comments.", comments1.length, 2);
+
+ String[] cTexts1 = {comments1[0].getText(),
comments1[1].getText()};
+
+ assertTrue("comment is missing", containsString(cTexts1, "test
comment1"));
+ assertTrue("comment is missing", containsString(cTexts1, "test
comment2"));
+
+ registry.delete(c1Path);
+
+ assertEquals("There should be one comment.", comments1.length, 1);
+
+ String[] cTexts2 = {comments1[0].getText()};
+
+ assertTrue("comment is missing", containsString(cTexts1, "test
comment2"));
+ assertTrue("deleted comment still exists",
!containsString(cTexts1, "test comment1"));
+
+ } catch (RegistryException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ private boolean containsString(String[] array, String value) {
+
+ boolean found = false;
+ for (String anArray : array) {
+ if (anArray.startsWith(value)) {
+ found = true;
+ break;
+ }
+ }
+
+ return found;
+ }
+
}
_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev