1. Micha Kops
  2. confluence-activeobject-tutorial

Commits

Micha Kops  committed b7e4690

initial import

  • Participants
  • Branches default

Comments (0)

Files changed (5)

File pom.xml

View file
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<parent>
+		<groupId>com.atlassian.confluence.plugin.base</groupId>
+		<artifactId>confluence-plugin-base</artifactId>
+		<version>25</version>
+	</parent>
+
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>com.hascode.confluence.plugin</groupId>
+	<artifactId>confluence-activeobjects-tutorial</artifactId>
+	<version>0.0.1</version>
+	<name>Confluence ActiveObjects Tutorial</name>
+	<description>hasCode.com Tutorial on ActiveObjects Integration in Confluence</description>
+	<packaging>atlassian-plugin</packaging>
+	<url>http://www.hascode.com</url>
+
+	<organization>
+		<name>hasCode.com</name>
+		<url>http://www.hascode.com</url>
+	</organization>
+
+	<developers>
+		<developer>
+			<name>Micha Kops</name>
+		</developer>
+	</developers>
+
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+		<atlassian.plugin.key>com.hascode.confluence.plugin.activeobjects</atlassian.plugin.key>
+		<atlassian.product.version>3.3</atlassian.product.version>
+		<atlassian.product.test-lib.version>1.4.1</atlassian.product.test-lib.version>
+		<atlassian.product.data.version>3.0</atlassian.product.data.version>
+	</properties>
+
+	<repositories>
+		<repository>
+			<id>atlassian-public</id>
+			<url>https://maven.atlassian.com/repository/public</url>
+			<snapshots>
+				<enabled>true</enabled>
+			</snapshots>
+			<releases>
+				<enabled>true</enabled>
+			</releases>
+		</repository>
+		<repository>
+			<id>atlassian-m1-repository</id>
+			<url>https://maven.atlassian.com/maven1</url>
+			<layout>legacy</layout>
+		</repository>
+		<repository>
+			<id>atlassian-unknown</id>
+			<name>atlassian-unknown</name>
+			<url>http://repository.atlassian.com/</url>
+		</repository>
+		<repository>
+			<id>maven2-repository.dev.java.net</id>
+			<name>Java.net Repository for Maven</name>
+			<url>http://download.java.net/maven/2/</url>
+			<layout>default</layout>
+		</repository>
+	</repositories>
+	<pluginRepositories>
+		<pluginRepository>
+			<id>atlassian-public</id>
+			<url>https://maven.atlassian.com/repository/public</url>
+			<snapshots>
+				<enabled>true</enabled>
+			</snapshots>
+			<releases>
+				<enabled>true</enabled>
+			</releases>
+		</pluginRepository>
+	</pluginRepositories>
+	<dependencies>
+		<dependency>
+			<groupId>com.atlassian.confluence</groupId>
+			<artifactId>confluence</artifactId>
+			<version>${atlassian.product.version}</version>
+			<scope>provided</scope>
+			<exclusions>
+				<exclusion>
+					<groupId>opensymphony</groupId>
+					<artifactId>pell-multipart</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>seraph</groupId>
+					<artifactId>seraph</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>tangosol-coherence</groupId>
+					<artifactId>coherence</artifactId>
+				</exclusion>
+				<exclusion>
+					<artifactId>tangosol</artifactId>
+					<groupId>tangosol-coherence</groupId>
+				</exclusion>
+			</exclusions>
+		</dependency>
+		<dependency>
+			<groupId>com.atlassian.activeobjects</groupId>
+			<artifactId>activeobjects-plugin</artifactId>
+			<version>0.9.6</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.atlassian.sal</groupId>
+			<artifactId>sal-api</artifactId>
+			<version>2.4.1</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.google.collections</groupId>
+			<artifactId>google-collections</artifactId>
+			<version>1.0</version>
+			<scope>provided</scope>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.6</source>
+					<target>1.6</target>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>com.atlassian.maven.plugins</groupId>
+				<artifactId>maven-refapp-plugin</artifactId>
+				<version>3.1</version>
+				<extensions>true</extensions>
+				<configuration>
+					<pluginArtifacts>
+						<pluginArtifact>
+							<groupId>com.atlassian.activeobjects</groupId>
+							<artifactId>activeobjects-plugin</artifactId>
+							<version>0.9.6</version>
+						</pluginArtifact>
+						<pluginArtifact>
+							<groupId>com.atlassian.activeobjects</groupId>
+							<artifactId>activeobjects-refapp-spi</artifactId>
+							<version>0.9.6</version>
+						</pluginArtifact>
+					</pluginArtifacts>
+					<productVersion>3.1</productVersion>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+</project>

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

View file
+package com.hascode.confluence.plugin.activeobject;
+
+import java.util.Date;
+
+import net.java.ao.Entity;
+import net.java.ao.Preload;
+
+@Preload
+public interface Note extends Entity {
+	public abstract String getNote();
+
+	public abstract void setNote(final String note);
+
+	public abstract Date getCreated();
+
+	public abstract void setCreated(final Date date);
+}

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

View file
+package com.hascode.confluence.plugin.activeobject;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.io.IOException;
+import java.util.Date;
+
+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 NoteAddServlet extends HttpServlet {
+	private static final long	serialVersionUID	= 1L;
+	private final ActiveObjects	ao;
+
+	public NoteAddServlet(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(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+		final String noteText = req.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;
+			}
+		});
+		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/NoteMacro.java

View file
+package com.hascode.confluence.plugin.activeobject;
+
+import java.util.Map;
+
+import com.atlassian.activeobjects.external.ActiveObjects;
+import com.atlassian.renderer.RenderContext;
+import com.atlassian.renderer.v2.RenderMode;
+import com.atlassian.renderer.v2.macro.BaseMacro;
+import com.atlassian.renderer.v2.macro.Macro;
+import com.atlassian.renderer.v2.macro.MacroException;
+import com.atlassian.sal.api.transaction.TransactionCallback;
+
+public class NoteMacro extends BaseMacro implements Macro {
+
+	private final ActiveObjects	ao;
+
+	public NoteMacro(final ActiveObjects ao) {
+		this.ao = ao;
+	}
+
+	@Override
+	public String execute(final Map params, final String body, final RenderContext ctx) throws MacroException {
+		final StringBuffer output = new StringBuffer("<b>Notes</b><br/><ul>");
+		ao.executeInTransaction(new TransactionCallback<Void>() {
+			@Override
+			public Void doInTransaction() {
+				for (final Note note : ao.find(Note.class)) {
+					output.append("<li>");
+					output.append(note.getCreated());
+					output.append(": ");
+					output.append(note.getNote());
+					output.append("</li>");
+				}
+				return null;
+			}
+		});
+		output.append("</ul>");
+		return output.toString();
+	}
+
+	@Override
+	public RenderMode getBodyRenderMode() {
+		return RenderMode.ALL;
+	}
+
+	@Override
+	public boolean hasBody() {
+		return false;
+	}
+
+}

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

View file
+<atlassian-plugin key="${atlassian.plugin.key}" name="${project.name}"
+	pluginsVersion="2">
+	<plugin-info>
+		<description>${project.description}</description>
+		<version>${project.version}</version>
+		<vendor name="${project.organization.name}" url="${project.organization.url}" />
+	</plugin-info>
+
+	<ao key="ao-module">
+		<description>The module configuring the Active Objects Note service
+		</description>
+		<entity>com.hascode.confluence.plugin.activeobject.Note</entity>
+	</ao>
+
+	<component-import key="ao" name="Active Objects service"
+		interface="com.atlassian.activeobjects.external.ActiveObjects">
+		<description>Component to access Active Objects functionality from the
+			plugin</description>
+	</component-import>
+
+	<macro name="NoteMacro"
+		class="com.hascode.confluence.plugin.activeobject.NoteMacro" key="com.hascode.confluence.plugin.notemacro">
+		<parameters />
+	</macro>
+
+	<servlet name="Note Add Servlet"
+		class="com.hascode.confluence.plugin.activeobject.NoteAddServlet" key="note-add-servlet">
+		<description>A servlet to add a new note</description>
+		<url-pattern>/note/add</url-pattern>
+	</servlet>
+
+</atlassian-plugin>