diff options
author | afinkbein | 2008-06-20 00:15:31 +0000 |
---|---|---|
committer | afinkbein | 2008-06-20 00:15:31 +0000 |
commit | 307ce728c633a4c191d877cef52d7ba8ebe53389 (patch) | |
tree | 51309fe0229f3c335acdaea0cb67aa411282196c | |
parent | 7d73d6acfe4a81421e41a0168fa7ea1cb0381c6d (diff) | |
download | org.eclipse.osee-307ce728c633a4c191d877cef52d7ba8ebe53389.tar.gz org.eclipse.osee-307ce728c633a4c191d877cef52d7ba8ebe53389.tar.xz org.eclipse.osee-307ce728c633a4c191d877cef52d7ba8ebe53389.zip |
8 files changed, 317 insertions, 0 deletions
diff --git a/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/.classpath b/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/.classpath new file mode 100644 index 00000000000..02159672985 --- /dev/null +++ b/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/.project b/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/.project new file mode 100644 index 00000000000..6245017568c --- /dev/null +++ b/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.osee.framework.branch.management.servlet</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/.settings/org.eclipse.pde.core.prefs b/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 00000000000..54e7f34adec --- /dev/null +++ b/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,4 @@ +#Thu May 08 12:25:01 MST 2008
+eclipse.preferences.version=1
+pluginProject.extensions=false
+resolve.requirebundle=false
diff --git a/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/META-INF/MANIFEST.MF b/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..0e6975eaa67 --- /dev/null +++ b/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Servlet Plug-in +Bundle-SymbolicName: org.eclipse.osee.framework.branch.management.servlet +Bundle-Version: 0.2.0.qualifier +Bundle-Activator: org.eclipse.osee.framework.branch.management.servlet.Activator +Import-Package: javax.servlet;version="2.4.0", + javax.servlet.http;version="2.4.0", + org.eclipse.osee.framework.branch.management, + org.eclipse.osee.framework.jdk.core.util, + org.eclipse.osee.framework.logging, + org.osgi.framework;version="1.3.0", + org.osgi.service.http;version="1.2.0", + org.osgi.service.log;version="1.3.0", + org.osgi.util.tracker;version="1.3.3" +Eclipse-LazyStart: true diff --git a/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/build.properties b/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/build.properties new file mode 100644 index 00000000000..41eb6ade2b4 --- /dev/null +++ b/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/build.properties @@ -0,0 +1,4 @@ +source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/src/org/eclipse/osee/framework/branch/management/servlet/Activator.java b/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/src/org/eclipse/osee/framework/branch/management/servlet/Activator.java new file mode 100644 index 00000000000..20b482c7f03 --- /dev/null +++ b/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/src/org/eclipse/osee/framework/branch/management/servlet/Activator.java @@ -0,0 +1,70 @@ +package org.eclipse.osee.framework.branch.management.servlet;
+
+import org.eclipse.osee.framework.branch.management.IBranchCreation;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.HttpService;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class Activator implements BundleActivator {
+
+ private HttpServiceTracker httpTracker;
+ private ServiceTracker branchCreationTracker;
+ private static Activator instance;
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ instance = this;
+
+ httpTracker = new HttpServiceTracker(context);
+ httpTracker.open();
+
+ branchCreationTracker = new ServiceTracker(context, IBranchCreation.class.getName(), null);
+ branchCreationTracker.open();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ httpTracker.close();
+ branchCreationTracker.close();
+ instance = null;
+ }
+
+ public static Activator getInstance() {
+ return instance;
+ }
+
+ public IBranchCreation getBranchCreation() {
+ return (IBranchCreation) branchCreationTracker.getService();
+ }
+
+ private class HttpServiceTracker extends ServiceTracker {
+ public HttpServiceTracker(BundleContext context) {
+ super(context, HttpService.class.getName(), null);
+ }
+
+ public Object addingService(ServiceReference reference) {
+ HttpService httpService = (HttpService) context.getService(reference);
+ try {
+ httpService.registerServlet("/branch", new BranchManagerServlet(), null, null);
+ System.out.println("Registered servlet '/branch'");
+ } catch (Exception ex) {
+ }
+ return httpService;
+ }
+
+ public void removedService(ServiceReference reference, Object service) {
+ HttpService httpService = (HttpService) service;
+ httpService.unregister("/branch");
+ System.out.println("De-registering servlet '/branch'");
+ super.removedService(reference, service);
+ }
+ }
+}
diff --git a/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/src/org/eclipse/osee/framework/branch/management/servlet/BranchManagerServlet.java b/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/src/org/eclipse/osee/framework/branch/management/servlet/BranchManagerServlet.java new file mode 100644 index 00000000000..cfa62c17297 --- /dev/null +++ b/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/src/org/eclipse/osee/framework/branch/management/servlet/BranchManagerServlet.java @@ -0,0 +1,65 @@ +/*
+ * Created on May 13, 2008
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.framework.branch.management.servlet;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+/**
+ * @author Andrew M Finkbeiner
+ */
+public class BranchManagerServlet extends HttpServlet {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 226986283540461526L;
+
+ /* (non-Javadoc)
+ * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ try {
+ resp.setStatus(HttpServletResponse.SC_ACCEPTED);
+ resp.setContentType("text/plain");
+ HttpBranchCreationInfo info = new HttpBranchCreationInfo(req);
+ int branchId = -1;
+ switch (info.getFunction()) {
+ case createChildBranch:
+ branchId =
+ Activator.getInstance().getBranchCreation().createChildBranch(info.getParentBranchId(),
+ info.getBranchShortName(), info.getBranchName(), info.getCreationComment(),
+ info.getAssociatedArtifactId(), info.getAuthorId());
+ break;
+ case createRootBranch:
+ branchId =
+ Activator.getInstance().getBranchCreation().createRootBranch(info.getParentBranchId(),
+ info.getBranchShortName(), info.getBranchName(), info.getCreationComment(),
+ info.getAssociatedArtifactId(), info.getAuthorId(), info.getStaticBranchName());
+ break;
+ }
+ if (branchId != -1) {
+ resp.getWriter().write(Integer.toString(branchId));
+ } else {
+ resp.getWriter().write("Unknown Error during branch creation.");
+ }
+ } catch (Exception ex) {
+ OseeLog.log(Activator.class.getName(), Level.SEVERE, String.format(
+ "Failed to respond to a branch servlet request [%s]", req.toString()), ex);
+ resp.getWriter().write(Lib.exceptionToString(ex));
+ }
+ resp.getWriter().flush();
+ resp.getWriter().close();
+ }
+
+}
diff --git a/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/src/org/eclipse/osee/framework/branch/management/servlet/HttpBranchCreationInfo.java b/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/src/org/eclipse/osee/framework/branch/management/servlet/HttpBranchCreationInfo.java new file mode 100644 index 00000000000..f537cab7ed4 --- /dev/null +++ b/MS_0.2.0_20080619/org.eclipse.osee.framework.branch.management.servlet/src/org/eclipse/osee/framework/branch/management/servlet/HttpBranchCreationInfo.java @@ -0,0 +1,123 @@ +package org.eclipse.osee.framework.branch.management.servlet;
+
+import javax.servlet.http.HttpServletRequest;
+import org.eclipse.osee.framework.jdk.core.util.StringFormat;
+
+class HttpBranchCreationInfo {
+
+ enum BranchCreationFunction {
+ createRootBranch, createChildBranch
+ };
+
+ private BranchCreationFunction function;
+ private int parentBranchId;
+ private String branchShortName;
+ private String branchName;
+ private String creationComment;
+ private int associatedArtifactId;
+ private int authorId;
+ private String staticBranchName;
+
+ public HttpBranchCreationInfo(HttpServletRequest req) throws Exception {
+ isFunctionValid(req.getParameter("function"));
+
+ String parentBranchIdStr = req.getParameter("parentBranchId");
+ if (parentBranchIdStr != null) {
+ parentBranchId = Integer.parseInt(parentBranchIdStr);
+ } else {
+ parentBranchId = -1;
+ }
+ branchName = req.getParameter("branchName");//required
+ if (branchName == null || branchName.length() == 0) {
+ throw new IllegalArgumentException("A 'branchName' parameter must be specified");
+ }
+ branchShortName = req.getParameter("branchShortName");
+ if (branchShortName == null) {
+ branchShortName = branchName;
+ }
+ branchShortName = StringFormat.truncate(branchShortName, 25);
+ creationComment = req.getParameter("creationComment");//required
+ if (creationComment == null || creationComment.length() == 0) {
+ throw new IllegalArgumentException("A 'creationComment' parameter must be specified");
+ }
+ String associatedArtifactIdStr = req.getParameter("associatedArtifactId");
+ if (associatedArtifactIdStr == null) {
+ throw new IllegalArgumentException("A 'associatedArtifactId' parameter must be specified");
+ }
+ associatedArtifactId = Integer.parseInt(associatedArtifactIdStr);
+ String authorIdStr = req.getParameter("authorId");
+ if (authorIdStr == null) {
+ throw new IllegalArgumentException("A 'authorIdStr' parameter must be specified");
+ }
+ authorId = Integer.parseInt(authorIdStr);
+ staticBranchName = req.getParameter("staticBranchName");
+ }
+
+ private void isFunctionValid(String function) throws Exception {
+ if (function == null) {
+ throw new Exception("A 'function' parameter must be defined.");
+ }
+ try {
+ this.function = BranchCreationFunction.valueOf(function);
+ } catch (IllegalArgumentException ex) {
+ throw new Exception(String.format("[%s] is not a valid function.", function), ex);
+ }
+ }
+
+ /**
+ * @return the parentBranchId
+ */
+ public int getParentBranchId() {
+ return parentBranchId;
+ }
+
+ /**
+ * @return the branchShortName
+ */
+ public String getBranchShortName() {
+ return branchShortName;
+ }
+
+ /**
+ * @return the branchName
+ */
+ public String getBranchName() {
+ return branchName;
+ }
+
+ /**
+ * @return the creationComment
+ */
+ public String getCreationComment() {
+ return creationComment;
+ }
+
+ /**
+ * @return the associatedArtifactId
+ */
+ public int getAssociatedArtifactId() {
+ return associatedArtifactId;
+ }
+
+ /**
+ * @return the authorId
+ */
+ public int getAuthorId() {
+ return authorId;
+ }
+
+ /**
+ * @return the staticBranchName
+ */
+ public String getStaticBranchName() {
+ return staticBranchName;
+ }
+
+ /**
+ * @return the function
+ */
+ public BranchCreationFunction getFunction() {
+ return function;
+ }
+
+}
|