Skip to content

Commit

Permalink
feat: Implement endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
jamilraichouni committed Oct 23, 2024
1 parent 2ec6840 commit 79c1c29
Show file tree
Hide file tree
Showing 43 changed files with 3,035 additions and 59 deletions.
19 changes: 0 additions & 19 deletions CONTRIBUTING.md

This file was deleted.

2 changes: 2 additions & 0 deletions rest-api/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: CC0-1.0
README.md
pom.xml
src/com/db/capella/Main.java
Expand Down
2 changes: 2 additions & 0 deletions rest-api/bin/jaxrs-jersey.json.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Copyright DB InfraGO AG and contributors
SPDX-License-Identifier: Apache-2.0
4 changes: 3 additions & 1 deletion rest-api/bin/jaxrs-jersey.zsh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env zsh
# Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: CC0-1.0
SCRIPT_PATH=$(realpath -s $0)
SCRIPT_DIR=$(dirname $SCRIPT_PATH)
openapi-generator-cli generate \
openapi-generator generate \
-i openapi/custom.yaml \
-c $SCRIPT_DIR/jaxrs-jersey.json \
-g jaxrs-jersey \
Expand Down
42 changes: 41 additions & 1 deletion rest-api/openapi/custom.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0

openapi: 3.0.3
info:
title: Capella API
description: API to access live data and modify Capella projects
version: 0.0.1
servers:
- url: http://localhost:5007/api/v1
description: Embeded Capella REST API server
description: Embedded Capella REST API server
tags:
- name: Diagrams
description: >
Expand Down Expand Up @@ -181,6 +184,30 @@ paths:
description: Project saved successfully
'404':
description: Project not found
/projects/{project_name}/diagram-editors:
get:
tags:
- Diagrams
summary: Get a list of all open diagram editors for a project by name
operationId: getDiagramEditorsByProjectName
parameters:
- name: project_name
in: path
required: true
description: Unique name of the project
schema:
type: string
responses:
'200':
description: A list of open diagram editors
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/DiagramEditor'
'404':
description: Project not found
/projects/{project_name}/diagrams:
get:
tags:
Expand Down Expand Up @@ -236,6 +263,19 @@ components:
documentation:
type: string
description: Documentation of the diagram
DiagramEditor:
type: object
description: A diagram editor in Capella
properties:
id:
type: string
description: Unique identifier of the diagram
name:
type: string
description: Name of the diagram
uri:
type: string
description: URI of the diagram
EObject:
type: object
description: An abstract model object
Expand Down
3 changes: 1 addition & 2 deletions rest-api/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<plugin>
<extension point="org.eclipse.ui.startup">
<startup
class="Main">
class="com.db.capella.Main">
</startup>
</extension>
</plugin>

2 changes: 1 addition & 1 deletion rest-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<version>0.0.1</version>
<properties>
<tycho-version>2.7.5</tycho-version>
<java.version>11</java.version>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<swagger-core-version>2.2.15</swagger-core-version>
Expand Down
35 changes: 0 additions & 35 deletions rest-api/src/Main.java

This file was deleted.

18 changes: 18 additions & 0 deletions rest-api/src/com/db/capella/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright DB InfraGO AG and contributors
// SPDX-License-Identifier: Apache-2.0

package com.db.capella;

import org.glassfish.jersey.server.ResourceConfig;

import com.db.capella.api.JacksonJsonProvider;
import com.db.capella.api.ProjectsApi;
import com.db.capella.api.WorkspaceApi;

public class Application extends ResourceConfig {
public Application() {
register(ProjectsApi.class);
register(WorkspaceApi.class);
register(JacksonJsonProvider.class);
}
}
45 changes: 45 additions & 0 deletions rest-api/src/com/db/capella/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright DB InfraGO AG and contributors
// SPDX-License-Identifier: Apache-2.0

package com.db.capella;

import java.net.URI;

import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.IStartup;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;

public class Main implements IStartup {
public static final String BASE_URI = "http://0.0.0.0:5007/api/v1";

public static void log(int severity, String message, Throwable exception) {
Bundle bundle = FrameworkUtil.getBundle(Main.class);
ILog log = Platform.getLog(bundle);
IStatus status = new Status(severity, bundle.getSymbolicName(),
message, exception);
log.log(status);
}

@Override
public void earlyStartup() {
final ResourceConfig resourceConfig = new Application();
try {
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(
URI.create(BASE_URI),
resourceConfig, true);
log(IStatus.INFO, "Capella REST API server listens on " + BASE_URI + " ...", null);
} catch (Exception e) {
String msg = "There was an error while starting Capella REST API server.";
log(IStatus.ERROR, msg, null);
System.err.println(msg);
e.printStackTrace();
}
}
}
40 changes: 40 additions & 0 deletions rest-api/src/com/db/capella/api/ApiException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright DB InfraGO AG and contributors
// SPDX-License-Identifier: Apache-2.0

package com.db.capella.api;

/**
* The exception that can be used to store the HTTP status code returned by an API response.
*/
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJerseyServerCodegen", comments = "Generator version: 7.9.0")
public class ApiException extends Exception {
/** The HTTP status code. */
private int code;

/**
* Constructor.
*
* @param code The HTTP status code.
* @param msg The error message.
*/
public ApiException(int code, String msg) {
super(msg);
this.code = code;
}

/**
* Get the HTTP status code.
*
* @return The HTTP status code.
*/
public int getCode() {
return code;
}

@Override
public String toString() {
return "ApiException{" +
"code=" + code +
'}';
}
}
25 changes: 25 additions & 0 deletions rest-api/src/com/db/capella/api/ApiOriginFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright DB InfraGO AG and contributors
// SPDX-License-Identifier: Apache-2.0

package com.db.capella.api;

import java.io.IOException;

import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletResponse;

@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJerseyServerCodegen", comments = "Generator version: 7.9.0")
public class ApiOriginFilter implements jakarta.servlet.Filter {
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletResponse res = (HttpServletResponse) response;
res.addHeader("Access-Control-Allow-Origin", "*");
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
chain.doFilter(request, response);
}

public void destroy() {}

public void init(FilterConfig filterConfig) throws ServletException {}
}
69 changes: 69 additions & 0 deletions rest-api/src/com/db/capella/api/ApiResponseMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright DB InfraGO AG and contributors
// SPDX-License-Identifier: Apache-2.0

package com.db.capella.api;


@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJerseyServerCodegen", comments = "Generator version: 7.9.0")
public class ApiResponseMessage {
public static final int ERROR = 1;
public static final int WARNING = 2;
public static final int INFO = 3;
public static final int OK = 4;
public static final int TOO_BUSY = 5;

int code;
String type;
String message;

public ApiResponseMessage(){}

public ApiResponseMessage(int code, String message){
this.code = code;
switch(code){
case ERROR:
setType("error");
break;
case WARNING:
setType("warning");
break;
case INFO:
setType("info");
break;
case OK:
setType("ok");
break;
case TOO_BUSY:
setType("too busy");
break;
default:
setType("unknown");
break;
}
this.message = message;
}

public int getCode() {
return code;
}

public void setCode(int code) {
this.code = code;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}
}
Loading

0 comments on commit 79c1c29

Please sign in to comment.