From b56832663141e952a02267c207cdb0cfa938fd45 Mon Sep 17 00:00:00 2001
From: Andrew M Finkbeiner
Date: Mon, 18 Mar 2013 16:42:34 -0700
Subject: feature[ats_5Z6FP]: Add OTE rest server
Change-Id: I231e42246e5134a0bfb191dfbedd1823b38a4692
---
plugins/org.eclipse.osee.ote.rest/.classpath | 7 ++
plugins/org.eclipse.osee.ote.rest/.project | 33 +++++++
.../org.eclipse.osee.ote.rest/META-INF/MANIFEST.MF | 22 +++++
.../OSGI-INF/ote.configuration.store.xml | 9 ++
.../OSGI-INF/ote.job.store.xml | 7 ++
.../OSGI-INF/ote.rest.application.xml | 9 ++
plugins/org.eclipse.osee.ote.rest/build.properties | 13 +++
plugins/org.eclipse.osee.ote.rest/pom.xml | 34 +++++++
.../ote/rest/internal/ConfigurationJobStatus.java | 101 ++++++++++++++++++++
.../rest/internal/OteConfigurationResource.java | 60 ++++++++++++
.../ote/rest/internal/OteConfigurationStore.java | 19 ++++
.../rest/internal/OteConfigurationStoreImpl.java | 102 +++++++++++++++++++++
.../org/eclipse/osee/ote/rest/internal/OteJob.java | 13 +++
.../osee/ote/rest/internal/OteJobResource.java | 53 +++++++++++
.../osee/ote/rest/internal/OteJobStore.java | 16 ++++
.../osee/ote/rest/internal/OteJobStoreImpl.java | 36 ++++++++
.../osee/ote/rest/internal/OteJobsResource.java | 56 +++++++++++
.../osee/ote/rest/internal/OteRestApplication.java | 46 ++++++++++
.../internal/mappers/OseeCoreExceptionMapper.java | 36 ++++++++
19 files changed, 672 insertions(+)
create mode 100644 plugins/org.eclipse.osee.ote.rest/.classpath
create mode 100644 plugins/org.eclipse.osee.ote.rest/.project
create mode 100644 plugins/org.eclipse.osee.ote.rest/META-INF/MANIFEST.MF
create mode 100644 plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.configuration.store.xml
create mode 100644 plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.job.store.xml
create mode 100644 plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.rest.application.xml
create mode 100644 plugins/org.eclipse.osee.ote.rest/build.properties
create mode 100644 plugins/org.eclipse.osee.ote.rest/pom.xml
create mode 100644 plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/ConfigurationJobStatus.java
create mode 100644 plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationResource.java
create mode 100644 plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationStore.java
create mode 100644 plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationStoreImpl.java
create mode 100644 plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJob.java
create mode 100644 plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobResource.java
create mode 100644 plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobStore.java
create mode 100644 plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobStoreImpl.java
create mode 100644 plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobsResource.java
create mode 100644 plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteRestApplication.java
create mode 100644 plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/mappers/OseeCoreExceptionMapper.java
(limited to 'plugins/org.eclipse.osee.ote.rest')
diff --git a/plugins/org.eclipse.osee.ote.rest/.classpath b/plugins/org.eclipse.osee.ote.rest/.classpath
new file mode 100644
index 00000000000..ad32c83a788
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.rest/.classpath
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/plugins/org.eclipse.osee.ote.rest/.project b/plugins/org.eclipse.osee.ote.rest/.project
new file mode 100644
index 00000000000..e388ba0b504
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.rest/.project
@@ -0,0 +1,33 @@
+
+
+ org.eclipse.osee.ote.rest
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.pde.ManifestBuilder
+
+
+
+
+ org.eclipse.pde.SchemaBuilder
+
+
+
+
+ org.eclipse.pde.ds.core.builder
+
+
+
+
+
+ org.eclipse.pde.PluginNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/plugins/org.eclipse.osee.ote.rest/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.rest/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..5b693498bd3
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.rest/META-INF/MANIFEST.MF
@@ -0,0 +1,22 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Osee OTE Rest
+Bundle-SymbolicName: org.eclipse.osee.ote.rest
+Bundle-Version: 0.11.0.qualifier
+Bundle-Vendor: Eclipse Open System Engineering Environment
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Service-Component: OSGI-INF/*.xml
+Import-Package: javax.ws.rs,
+ javax.ws.rs.core,
+ javax.ws.rs.ext,
+ org.eclipse.core.resources,
+ org.eclipse.osee.framework.core.data,
+ org.eclipse.osee.framework.core.enums,
+ org.eclipse.osee.framework.core.exception,
+ org.eclipse.osee.framework.core.model,
+ org.eclipse.osee.framework.core.model.cache,
+ org.eclipse.osee.framework.core.util,
+ org.eclipse.osee.ote,
+ org.eclipse.osee.ote.rest.model
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.osee.framework.jdk.core;bundle-version="0.11.0"
diff --git a/plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.configuration.store.xml b/plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.configuration.store.xml
new file mode 100644
index 00000000000..b3dcec39f4e
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.configuration.store.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.job.store.xml b/plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.job.store.xml
new file mode 100644
index 00000000000..eee590006ac
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.job.store.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.rest.application.xml b/plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.rest.application.xml
new file mode 100644
index 00000000000..710ac2e2238
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.rest.application.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/plugins/org.eclipse.osee.ote.rest/build.properties b/plugins/org.eclipse.osee.ote.rest/build.properties
new file mode 100644
index 00000000000..9b4616ae0ea
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.rest/build.properties
@@ -0,0 +1,13 @@
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ OSGI-INF/,\
+ OSGI-INF/ote.configuration.store.xml,\
+ OSGI-INF/ote.job.store.xml
+source.. = src/
+additional.bundles = org.eclipse.osee.orcs,\
+ javax.ws.rs,\
+ org.eclipse.osee.framework.core.model,\
+ org.eclipse.osee.framework.core,\
+ org.eclipse.osee.framework.jdk.core,\
+ org.eclipse.osee.orcs.rest.model
diff --git a/plugins/org.eclipse.osee.ote.rest/pom.xml b/plugins/org.eclipse.osee.ote.rest/pom.xml
new file mode 100644
index 00000000000..3cb108093e0
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.rest/pom.xml
@@ -0,0 +1,34 @@
+
+
+ 4.0.0
+
+
+ org.eclipse.osee
+ org.eclipse.osee.x.server.parent
+ 0.11.0-SNAPSHOT
+ ../../plugins/org.eclipse.osee.x.server.parent
+
+
+ org.eclipse.osee.ote.rest
+ eclipse-plugin
+ OSEE OTE Rest - (Incubation)
+
+
+
+
+
+ src
+
+ **/*.java
+
+
+
+
+
+ org.eclipse.tycho
+ tycho-source-plugin
+
+
+
+
\ No newline at end of file
diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/ConfigurationJobStatus.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/ConfigurationJobStatus.java
new file mode 100644
index 00000000000..d2a55d3d2b9
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/ConfigurationJobStatus.java
@@ -0,0 +1,101 @@
+package org.eclipse.osee.ote.rest.internal;
+
+import java.net.URL;
+import java.util.concurrent.ExecutionException;
+
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.ote.OTEConfigurationStatus;
+import org.eclipse.osee.ote.OTEFuture;
+import org.eclipse.osee.ote.OTEStatusCallback;
+import org.eclipse.osee.ote.rest.model.OteJobStatus;
+
+public class ConfigurationJobStatus implements OTEStatusCallback, OteJob {
+
+ private int totalUnitsOfWork;
+ private int count;
+ private StringBuilder errorLog;
+ private StringBuilder statusLog;
+ private OTEFuture future;
+ private String uuid;
+ private URL url;
+
+ public ConfigurationJobStatus(){
+ totalUnitsOfWork = 0;
+ errorLog = new StringBuilder();
+ statusLog = new StringBuilder();
+ }
+
+ @Override
+ public void complete(OTEConfigurationStatus done) {
+ }
+
+ @Override
+ public void setTotalUnitsOfWork(int totalUnitsOfWork) {
+ this.totalUnitsOfWork = totalUnitsOfWork;
+ }
+
+ @Override
+ public void incrememtUnitsWorked(int count) {
+ this.count+=count;
+ }
+
+ @Override
+ public void log(String string) {
+ statusLog.append(string);
+ statusLog.append("\n");
+ }
+
+ @Override
+ public void error(String message, Throwable th) {
+ errorLog.append(message);
+ errorLog.append("\n");
+ errorLog.append(Lib.exceptionToString(th));
+ errorLog.append("\n");
+ }
+
+ @Override
+ public void error(String message) {
+ errorLog.append(message);
+ errorLog.append("\n");
+ }
+
+ public void setFuture(OTEFuture future) {
+ this.future = future;
+ }
+
+ @Override
+ public OteJobStatus getStatus() throws InterruptedException, ExecutionException {
+ OteJobStatus jobStatus = new OteJobStatus();
+ if(future.isDone()){
+ jobStatus.setJobComplete(true);
+ jobStatus.setSuccess(future.get().isSuccess());
+ if(!future.get().isSuccess()){
+ error(future.get().getMessage());
+ }
+ } else {
+ jobStatus.setJobComplete(false);
+ jobStatus.setSuccess(false);
+ }
+ jobStatus.setJobId(uuid);
+ jobStatus.setErrorLog(errorLog.toString());
+ jobStatus.setTotalUnitsOfWork(totalUnitsOfWork);
+ jobStatus.setUnitsWorked(count);
+ jobStatus.setUpdatedJobStatus(url);
+ return jobStatus;
+ }
+
+ @Override
+ public String getId() {
+ return uuid;
+ }
+
+ @Override
+ public void setId(String uuid) {
+ this.uuid = uuid;
+ }
+
+ public void setUrl(URL url) {
+ this.url = url;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationResource.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationResource.java
new file mode 100644
index 00000000000..f0d46907cc3
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationResource.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.ote.rest.internal;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.concurrent.ExecutionException;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.UriBuilderException;
+import javax.ws.rs.core.UriInfo;
+
+import org.eclipse.osee.ote.rest.model.OteConfiguration;
+import org.eclipse.osee.ote.rest.model.OteJobStatus;
+
+/**
+ * @author Andrew M. Finkbeiner
+ */
+@Path("config")
+public class OteConfigurationResource {
+
+ // Allows to insert contextual objects into the class,
+ // e.g. ServletContext, Request, Response, UriInfo
+ @Context
+ UriInfo uriInfo;
+ @Context
+ Request request;
+
+ @GET
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public OteConfiguration getConfiguration() throws MalformedURLException, IllegalArgumentException, UriBuilderException, InterruptedException, ExecutionException {
+ return getDataStore().getConfiguration(uriInfo);
+ }
+
+ @POST
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public OteJobStatus createConfig(OteConfiguration config) throws IOException, InterruptedException, ExecutionException {
+ return getDataStore().setup(config, uriInfo);
+ }
+
+ private OteConfigurationStore getDataStore(){
+ return OteRestApplication.get();
+ }
+}
diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationStore.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationStore.java
new file mode 100644
index 00000000000..a6c3751e25e
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationStore.java
@@ -0,0 +1,19 @@
+package org.eclipse.osee.ote.rest.internal;
+
+import java.net.MalformedURLException;
+import java.util.Collection;
+import java.util.concurrent.ExecutionException;
+
+import javax.ws.rs.core.UriBuilderException;
+import javax.ws.rs.core.UriInfo;
+
+import org.eclipse.osee.ote.rest.model.OteConfiguration;
+import org.eclipse.osee.ote.rest.model.OteJobStatus;
+
+public interface OteConfigurationStore {
+ OteJobStatus setup(OteConfiguration config, UriInfo uriInfo) throws InterruptedException, ExecutionException, MalformedURLException, IllegalArgumentException, UriBuilderException;
+ OteJobStatus reset(UriInfo uriInfo) throws InterruptedException, ExecutionException, MalformedURLException, IllegalArgumentException, UriBuilderException;
+ OteConfiguration getConfiguration(UriInfo uriInfo) throws MalformedURLException, IllegalArgumentException, UriBuilderException, InterruptedException, ExecutionException;
+ OteJobStatus getJob(String uuid) throws InterruptedException, ExecutionException;
+ Collection getAllJobIds();
+}
diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationStoreImpl.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationStoreImpl.java
new file mode 100644
index 00000000000..9ccf4ebae8e
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationStoreImpl.java
@@ -0,0 +1,102 @@
+package org.eclipse.osee.ote.rest.internal;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+
+import javax.ws.rs.core.UriBuilderException;
+import javax.ws.rs.core.UriInfo;
+
+import org.eclipse.osee.ote.OTEApi;
+import org.eclipse.osee.ote.OTEConfiguration;
+import org.eclipse.osee.ote.OTEConfigurationStatus;
+import org.eclipse.osee.ote.OTEFuture;
+import org.eclipse.osee.ote.rest.model.OteConfiguration;
+import org.eclipse.osee.ote.rest.model.OteJobStatus;
+
+public class OteConfigurationStoreImpl implements OteConfigurationStore {
+
+ private OTEApi ote;
+ private OteJobStore oteJobs;
+
+ public OteConfigurationStoreImpl(){
+ }
+
+ public void bindOTEApi(OTEApi ote){
+ this.ote = ote;
+ }
+
+ public void unbindOTEApi(OTEApi ote){
+ this.ote = null;
+ }
+
+ public void bindOteJobStore(OteJobStore oteJobs){
+ this.oteJobs = oteJobs;
+ }
+
+ public void unbindOteJobStore(OteJobStore oteJobs){
+ this.oteJobs = null;
+ }
+
+ @Override
+ public OteJobStatus setup(OteConfiguration config, UriInfo uriInfo) throws InterruptedException, ExecutionException, MalformedURLException, IllegalArgumentException, UriBuilderException {
+ OTEConfiguration realConfig = config.translateToOtherConfig();
+ ConfigurationJobStatus status = createConfigurationJobStatus(config, uriInfo);
+ OTEFuture future = ote.loadConfiguration(realConfig, status);
+ status.setFuture(future);
+ return status.getStatus();
+ }
+
+ private ConfigurationJobStatus createConfigurationJobStatus(OteConfiguration config, UriInfo uriInfo) throws MalformedURLException, IllegalArgumentException, UriBuilderException {
+ ConfigurationJobStatus status = new ConfigurationJobStatus();
+ status.setId(UUID.randomUUID().toString());
+ status.setUrl(generateJobUrl(status, uriInfo));
+ oteJobs.add(status);
+ return status;
+ }
+
+ private URL generateJobUrl(OteJob job, UriInfo uriInfo) throws MalformedURLException, IllegalArgumentException, UriBuilderException{
+ return uriInfo.getBaseUriBuilder().path("job").path(job.getId()).build().toURL();
+ }
+
+ @Override
+ public OteJobStatus reset(UriInfo uriInfo) throws InterruptedException, ExecutionException, MalformedURLException, IllegalArgumentException, UriBuilderException {
+ ConfigurationJobStatus status = createConfigurationJobStatus(uriInfo);
+ OTEFuture future = ote.resetConfiguration(status);
+ status.setFuture(future);
+ return status.getStatus();
+ }
+
+ @Override
+ public OteConfiguration getConfiguration(UriInfo uriInfo) throws MalformedURLException, IllegalArgumentException, UriBuilderException, InterruptedException, ExecutionException {
+ ConfigurationJobStatus status = createConfigurationJobStatus(uriInfo);
+ OTEFuture future = ote.getConfiguration();
+ status.setFuture(future);
+ if(future.isDone()){
+ return new OteConfiguration(future.get().getConfiguration());
+ } else {
+ return new OteConfiguration();
+ }
+ }
+
+ private ConfigurationJobStatus createConfigurationJobStatus(UriInfo uriInfo) throws MalformedURLException, IllegalArgumentException, UriBuilderException {
+ ConfigurationJobStatus status = new ConfigurationJobStatus();
+ status.setId(UUID.randomUUID().toString());
+ status.setUrl(generateJobUrl(status, uriInfo));
+ oteJobs.add(status);
+ return status;
+ }
+
+ @Override
+ public OteJobStatus getJob(String uuid) throws InterruptedException, ExecutionException {
+ return oteJobs.get(uuid);
+ }
+
+ @Override
+ public Collection getAllJobIds() {
+ return oteJobs.getAll();
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJob.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJob.java
new file mode 100644
index 00000000000..d9614fdbe6d
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJob.java
@@ -0,0 +1,13 @@
+package org.eclipse.osee.ote.rest.internal;
+
+import java.util.concurrent.ExecutionException;
+
+import org.eclipse.osee.ote.rest.model.OteJobStatus;
+
+public interface OteJob {
+
+ String getId();
+ void setId(String uuid);
+ OteJobStatus getStatus() throws InterruptedException, ExecutionException;
+
+}
diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobResource.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobResource.java
new file mode 100644
index 00000000000..c3a8246089d
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobResource.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+9 * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.ote.rest.internal;
+
+import java.util.concurrent.ExecutionException;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.UriInfo;
+
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.ote.rest.model.OteJobStatus;
+
+/**
+ * @author Andrew M. Finkbeiner
+ */
+public class OteJobResource {
+
+ @Context
+ private final UriInfo uriInfo;
+ @Context
+ private final Request request;
+
+ private final String uuid;
+
+ private final OteConfigurationStore store;
+
+
+ public OteJobResource(UriInfo uriInfo, Request request, OteConfigurationStore store, String id) {
+ this.uriInfo = uriInfo;
+ this.request = request;
+ this.uuid = id;
+ this.store = store;
+ }
+
+ @GET
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public OteJobStatus getConfig() throws OseeCoreException, InterruptedException, ExecutionException {
+ return store.getJob(uuid);
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobStore.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobStore.java
new file mode 100644
index 00000000000..bba69370c65
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobStore.java
@@ -0,0 +1,16 @@
+package org.eclipse.osee.ote.rest.internal;
+
+import java.util.Collection;
+import java.util.concurrent.ExecutionException;
+
+import org.eclipse.osee.ote.rest.model.OteJobStatus;
+
+public interface OteJobStore {
+
+ OteJobStatus get(String uuid) throws InterruptedException, ExecutionException;
+
+ Collection getAll();
+
+ void add(OteJob job);
+
+}
diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobStoreImpl.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobStoreImpl.java
new file mode 100644
index 00000000000..f3a30f587b6
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobStoreImpl.java
@@ -0,0 +1,36 @@
+package org.eclipse.osee.ote.rest.internal;
+
+import java.util.Collection;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+
+import org.eclipse.osee.ote.rest.model.OteJobStatus;
+
+public class OteJobStoreImpl implements OteJobStore {
+
+ ConcurrentHashMap jobs;
+
+ public OteJobStoreImpl(){
+ jobs = new ConcurrentHashMap();
+ }
+
+ @Override
+ public OteJobStatus get(String uuid) throws InterruptedException, ExecutionException {
+ OteJob job = jobs.get(uuid);
+ if(job != null){
+ return job.getStatus();
+ }
+ return null;
+ }
+
+ @Override
+ public Collection getAll() {
+ return jobs.keySet();
+ }
+
+ @Override
+ public void add(OteJob job) {
+ jobs.put(job.getId(), job);
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobsResource.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobsResource.java
new file mode 100644
index 00000000000..ec416862f11
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobsResource.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.ote.rest.internal;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.UriInfo;
+
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+
+/**
+ * @author Andrew M. Finkbeiner
+ */
+@Path("job")
+public class OteJobsResource {
+
+ // Allows to insert contextual objects into the class,
+ // e.g. ServletContext, Request, Response, UriInfo
+ @Context
+ UriInfo uriInfo;
+ @Context
+ Request request;
+
+ @Path("{uuid}")
+ public OteJobResource getConfiguration(@PathParam("uuid") String id) {
+ return new OteJobResource(uriInfo, request, getDataStore(), id);
+ }
+
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String getConfiguration() throws OseeCoreException {
+ StringBuilder sb = new StringBuilder();
+ for(String id:getDataStore().getAllJobIds()){
+ sb.append(id);
+ sb.append("\n");
+ }
+ return sb.toString();
+ }
+
+ private OteConfigurationStore getDataStore(){
+ return OteRestApplication.get();
+ }
+}
diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteRestApplication.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteRestApplication.java
new file mode 100644
index 00000000000..dfb988ca60d
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteRestApplication.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.ote.rest.internal;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+import org.eclipse.osee.ote.rest.internal.mappers.OseeCoreExceptionMapper;
+
+/**
+ * Get application.wadl at this context to get rest documentation
+ *
+ * @author Roberto E. Escobar
+ */
+public class OteRestApplication extends Application {
+
+ private static OteConfigurationStore store;
+
+ public void setOteConfigurationStore(OteConfigurationStore store){
+ OteRestApplication.store = store;
+ }
+
+ public static OteConfigurationStore get(){
+ return store;
+ }
+
+ @Override
+ public Set> getClasses() {
+ Set> classes = new HashSet>();
+ classes.add(OseeCoreExceptionMapper.class);
+ classes.add(OteConfigurationResource.class);
+ classes.add(OteJobsResource.class);
+ return classes;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/mappers/OseeCoreExceptionMapper.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/mappers/OseeCoreExceptionMapper.java
new file mode 100644
index 00000000000..4bc0f0ba1a0
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/mappers/OseeCoreExceptionMapper.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.ote.rest.internal.mappers;
+
+import javax.ws.rs.core.GenericEntity;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.ote.rest.model.ExceptionEntity;
+
+/**
+ * @author John Misinco
+ */
+@Provider
+public class OseeCoreExceptionMapper implements ExceptionMapper {
+
+ @Override
+ public Response toResponse(OseeCoreException exception) {
+ ExceptionEntity entity = new ExceptionEntity(Lib.exceptionToString(exception));
+ GenericEntity ge = new GenericEntity(entity, ExceptionEntity.class);
+ return Response.status(Status.INTERNAL_SERVER_ERROR).type(MediaType.APPLICATION_JSON_TYPE).entity(ge).build();
+ }
+
+}
--
cgit v1.2.3