Commits

Micha Kops  committed f7cd35a

deletion sample added

  • Participants
  • Parent commits b7e4690

Comments (0)

Files changed (4)

File src/main/java/com/hascode/confluence/plugin/activeobject/NoteAddServlet.java

 		this.ao = checkNotNull(ao);
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest
-	 * , javax.servlet.http.HttpServletResponse)
-	 */
 	@Override
-	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+	protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
 		final String noteText = req.getParameter("note");
 		ao.executeInTransaction(new TransactionCallback<Note>() {
 			@Override
 		});
 		resp.getWriter().append("New note saved").close();
 	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest
-	 * , javax.servlet.http.HttpServletResponse)
-	 */
-	// @Override
-	// protected void doGet(HttpServletRequest req, HttpServletResponse res)
-	// throws ServletException, IOException {
-	// final String noteText =
-	// ServletActionContext.getRequest().getParameter("note");
-	// // ao.executeInTransaction(new TransactionCallback<Note>() {
-	// // @Override
-	// // public Note doInTransaction() {
-	// // final Note note = ao.create(Note.class);
-	// // note.setNote(noteText);
-	// // note.setCreated(new Date());
-	// // note.save();
-	// // return note;
-	// // }
-	// // });
-	// res.getWriter().append("New note saved").close();
-	// }
-
 }

File src/main/java/com/hascode/confluence/plugin/activeobject/NoteDeleteServlet.java

+package com.hascode.confluence.plugin.activeobject;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.atlassian.activeobjects.external.ActiveObjects;
+import com.atlassian.sal.api.transaction.TransactionCallback;
+
+public class NoteDeleteServlet extends HttpServlet {
+	private static final long	serialVersionUID	= 1L;
+	private final ActiveObjects	ao;
+
+	public NoteDeleteServlet(final ActiveObjects ao) {
+		this.ao = checkNotNull(ao);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest
+	 * , javax.servlet.http.HttpServletResponse)
+	 */
+	@Override
+	protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
+		final int noteId = Integer.parseInt(req.getParameter("noteId"));
+		ao.executeInTransaction(new TransactionCallback<Void>() {
+			@Override
+			public Void doInTransaction() {
+				final Note note = ao.get(Note.class, noteId);
+				ao.delete(note);
+				return null;
+			}
+		});
+		resp.getWriter().append("New note saved").close();
+	}
+}

File src/main/java/com/hascode/confluence/plugin/activeobject/NoteMacro.java

 			@Override
 			public Void doInTransaction() {
 				for (final Note note : ao.find(Note.class)) {
-					output.append("<li>");
+					output.append("<li>ID: ");
+					output.append(note.getID());
+					output.append(", created: ");
 					output.append(note.getCreated());
 					output.append(": ");
 					output.append(note.getNote());
 				return null;
 			}
 		});
-		output.append("</ul>");
+		output.append("</ul><hr/><form action=\"/plugins/servlet/note/add\"><input type=\"text\" name=\"note\"/><input type=\"submit\" value=\"add\"/></form><hr/><form action=\"/plugins/servlet/note/delete\"><input type=\"text\" name=\"noteId\"/><input type=\"submit\" value=\"delete\"/></form>");
 		return output.toString();
 	}
 

File src/main/resources/atlassian-plugin.xml

 		<description>A servlet to add a new note</description>
 		<url-pattern>/note/add</url-pattern>
 	</servlet>
+	
+	<servlet name="Note Delete Servlet"
+		class="com.hascode.confluence.plugin.activeobject.NoteDeleteServlet" key="note-delete-servlet">
+		<description>A servlet to delete a note</description>
+		<url-pattern>/note/delete</url-pattern>
+	</servlet>
 
 </atlassian-plugin>