Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew M Finkbeiner2013-03-18 19:42:34 -0400
committerdonald.g.dunne2013-03-27 15:21:25 -0400
commitb56832663141e952a02267c207cdb0cfa938fd45 (patch)
tree521966bc2389b44429e32ae48e7980b353d501b1 /plugins/org.eclipse.osee.ote.rest
parent36ce89dfbdb3148fb91239e151b07543ea599099 (diff)
downloadorg.eclipse.osee-b56832663141e952a02267c207cdb0cfa938fd45.tar.gz
org.eclipse.osee-b56832663141e952a02267c207cdb0cfa938fd45.tar.xz
org.eclipse.osee-b56832663141e952a02267c207cdb0cfa938fd45.zip
feature[ats_5Z6FP]: Add OTE rest server
Diffstat (limited to 'plugins/org.eclipse.osee.ote.rest')
-rw-r--r--plugins/org.eclipse.osee.ote.rest/.classpath7
-rw-r--r--plugins/org.eclipse.osee.ote.rest/.project33
-rw-r--r--plugins/org.eclipse.osee.ote.rest/META-INF/MANIFEST.MF22
-rw-r--r--plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.configuration.store.xml9
-rw-r--r--plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.job.store.xml7
-rw-r--r--plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.rest.application.xml9
-rw-r--r--plugins/org.eclipse.osee.ote.rest/build.properties13
-rw-r--r--plugins/org.eclipse.osee.ote.rest/pom.xml34
-rw-r--r--plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/ConfigurationJobStatus.java101
-rw-r--r--plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationResource.java60
-rw-r--r--plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationStore.java19
-rw-r--r--plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationStoreImpl.java102
-rw-r--r--plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJob.java13
-rw-r--r--plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobResource.java53
-rw-r--r--plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobStore.java16
-rw-r--r--plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobStoreImpl.java36
-rw-r--r--plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobsResource.java56
-rw-r--r--plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteRestApplication.java46
-rw-r--r--plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/mappers/OseeCoreExceptionMapper.java36
19 files changed, 672 insertions, 0 deletions
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.osee.ote.rest</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>
+ <buildCommand>
+ <name>org.eclipse.pde.ds.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.osee.ote.rest.configuration">
+ <implementation class="org.eclipse.osee.ote.rest.internal.OteConfigurationStoreImpl"/>
+ <service>
+ <provide interface="org.eclipse.osee.ote.rest.internal.OteConfigurationStore"/>
+ </service>
+ <reference bind="bindOTEApi" cardinality="1..1" interface="org.eclipse.osee.ote.OTEApi" name="OTEApi" policy="static" unbind="unbindOTEApi"/>
+ <reference bind="bindOteJobStore" cardinality="1..1" interface="org.eclipse.osee.ote.rest.internal.OteJobStore" name="OteJobStore" policy="static" unbind="unbindOteJobStore"/>
+</scr:component>
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.osee.ote.rest">
+ <implementation class="org.eclipse.osee.ote.rest.internal.OteJobStoreImpl"/>
+ <service>
+ <provide interface="org.eclipse.osee.ote.rest.internal.OteJobStore"/>
+ </service>
+</scr:component>
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.osee.ote.rest.internal.OteRestApplication">
+ <implementation class="org.eclipse.osee.ote.rest.internal.OteRestApplication"/>
+ <service>
+ <provide interface="javax.ws.rs.core.Application"/>
+ </service>
+ <property name="context.name" type="String" value="ote"/>
+ <reference bind="setOteConfigurationStore" cardinality="1..1" interface="org.eclipse.osee.ote.rest.internal.OteConfigurationStore" name="OteConfigurationStore" policy="static"/>
+</scr:component>
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 @@
+<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/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.eclipse.osee</groupId>
+ <artifactId>org.eclipse.osee.x.server.parent</artifactId>
+ <version>0.11.0-SNAPSHOT</version>
+ <relativePath>../../plugins/org.eclipse.osee.x.server.parent</relativePath>
+ </parent>
+
+ <artifactId>org.eclipse.osee.ote.rest</artifactId>
+ <packaging>eclipse-plugin</packaging>
+ <name>OSEE OTE Rest - (Incubation)</name>
+
+ <build>
+ <!-- workaround for https://issues.sonatype.org/browse/TYCHO-168 -->
+ <resources>
+ <resource>
+ <directory>src</directory>
+ <excludes>
+ <exclude>**/*.java</exclude>
+ </excludes>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-source-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project> \ 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<OTEConfigurationStatus>, OteJob {
+
+ private int totalUnitsOfWork;
+ private int count;
+ private StringBuilder errorLog;
+ private StringBuilder statusLog;
+ private OTEFuture<OTEConfigurationStatus> 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<OTEConfigurationStatus> 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<String> 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<OTEConfigurationStatus> 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<OTEConfigurationStatus> 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<OTEConfigurationStatus> 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<String> 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<String> 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<String, OteJob> jobs;
+
+ public OteJobStoreImpl(){
+ jobs = new ConcurrentHashMap<String, OteJob>();
+ }
+
+ @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<String> 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<Class<?>> getClasses() {
+ Set<Class<?>> classes = new HashSet<Class<?>>();
+ 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<OseeCoreException> {
+
+ @Override
+ public Response toResponse(OseeCoreException exception) {
+ ExceptionEntity entity = new ExceptionEntity(Lib.exceptionToString(exception));
+ GenericEntity<ExceptionEntity> ge = new GenericEntity<ExceptionEntity>(entity, ExceptionEntity.class);
+ return Response.status(Status.INTERNAL_SERVER_ERROR).type(MediaType.APPLICATION_JSON_TYPE).entity(ge).build();
+ }
+
+}

Back to the top