Skip to content

Commit

Permalink
Add an MDENet Education Platform tools endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
agarciadom committed Nov 3, 2023
1 parent b3016e4 commit a749bf7
Show file tree
Hide file tree
Showing 18 changed files with 430 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ The project is divided into three modules:

These endpoints accept the `OPTIONS` method as well.

### Additional endpoints for the HTTP server

* `GET /tools`: returns a JSON document according to the [MDENet Education Platform tool specification](https://github.com/mdenet/educationplatform/wiki/Adding-a-Tool).

### Additional endpoints for the Google Cloud Function

* `POST /shorturl`: allows for storing work in Google Cloud Storage and retrieving it later.
Expand Down
8 changes: 8 additions & 0 deletions http-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ dependencies {

// To try out the functions locally via a Netty HTTP server
developmentOnly("io.micronaut:micronaut-http-server-netty")

// For rendering the MDENet Education Platform tools JSON file
implementation("org.eclipse.epsilon:org.eclipse.epsilon.egl.engine:${epsilonVersion}")

// For testing the additional logic for exposing the services as an MDENet EP tool
testImplementation("io.micronaut:micronaut-http-client")
testImplementation("io.micronaut.reactor:micronaut-reactor")

}

application {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
package org.eclipse.epsilon.labs.playground;

import io.micronaut.context.ApplicationContextBuilder;
import io.micronaut.context.ApplicationContextConfigurer;
import io.micronaut.context.annotation.ContextConfigurer;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.runtime.Micronaut;

public class Application {

@ContextConfigurer
public static class DefaultEnvironmentConfigurer implements ApplicationContextConfigurer {
@Override
public void configure(@NonNull ApplicationContextBuilder builder) {
builder.defaultEnvironments("", "http");
}
}
public static void main(String[] args) {
Micronaut.run(Application.class, args);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.eclipse.epsilon.labs.playground.fn.tooldesc;

import java.util.HashMap;

import org.eclipse.epsilon.egl.EglTemplateFactoryModuleAdapter;
import org.eclipse.epsilon.eol.execute.context.Variable;
import org.eclipse.epsilon.labs.playground.fn.emfatic2plantuml.Emfatic2PlantUMLController;
import org.eclipse.epsilon.labs.playground.fn.flexmi2plantuml.Flexmi2PlantUMLController;
import org.eclipse.epsilon.labs.playground.fn.run.RunEpsilonController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.server.util.HttpHostResolver;
import jakarta.inject.Inject;

@Controller("/tools")
public class ToolDescriptorController {

@Inject
private HttpHostResolver hostResolver;

private static final Logger LOGGER = LoggerFactory.getLogger(ToolDescriptorController.class);

@Get("/")
public HttpResponse<String> render(HttpRequest<?> request) {
try {
EglTemplateFactoryModuleAdapter module = new EglTemplateFactoryModuleAdapter();
module.parse(getClass().getResource("/mdenet_tool.egl").toURI());

var urls = new HashMap<String, String>();
urls.put("epsilon", resolve(request, RunEpsilonController.PATH));
urls.put("flexmi2plantuml", resolve(request, Flexmi2PlantUMLController.PATH));
urls.put("emfatic2plantuml", resolve(request, Emfatic2PlantUMLController.PATH));

module.getContext().getFrameStack().put(
Variable.createReadOnlyVariable("urls", urls)
);

return HttpResponse.ok("" + module.execute()).contentType(MediaType.APPLICATION_JSON);
} catch (Exception e) {
LOGGER.error(e.getMessage());
return HttpResponse.serverError("Failed to render the tools configuration: error has been logged");
}
}

private String resolve(HttpRequest<?> request, String path) {
return hostResolver.resolve(request) + path;
}

}
4 changes: 4 additions & 0 deletions http-server/src/main/resources/application-http.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Serve the icon files as well
micronaut.router.static-resources.default.enabled=true
micronaut.router.static-resources.default.mapping=/**/*
micronaut.router.static-resources.default.paths=classpath:public
245 changes: 245 additions & 0 deletions http-server/src/main/resources/mdenet_tool.egl
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
{
"tool":
{
"id": "epsilon",
"name": "playground-micronaut",
"version": "0.1.0",
"author": "Epsilon Labs",
"homepage": "https://eclipse.dev/epsilon/",

"functions": [
{
"id": "function-eol",
"name": "eol",
"parameters": [ {"name":"language", "type":"text"},
{"name":"outputType", "type":"text"},
{"name":"outputLanguage", "type":"text"},
{"name":"program", "type":"eol"},
{"name":"secondProgram", "type":"eol"},
{"name":"emfatic", "type":"emfatic"},
{"name":"flexmi", "type":"flexmi", "instanceOf": "emfatic"},
{"name":"secondEmfatic", "type":"emfatic"},
{"name":"secondFlexmi", "type":"flexmi", "instanceOf": "secondEmfatic"},
{"name":"thirdEmfatic", "type":"emfatic"},
{"name":"thirdFlexmi", "type":"flexmi", "instanceOf": "thirdEmfatic"}
],
"returnType": "text",
"path": "[%= urls.get("epsilon") %]"
},

{
"id": "function-etl",
"name": "etl",
"parameters": [ {"name":"language", "type":"text"},
{"name":"outputType", "type":"text"},
{"name":"outputLanguage", "type":"text"},
{"name":"program", "type":"etl"},
{"name":"secondProgram", "type":"etl"},
{"name":"emfatic", "type":"emfatic"},
{"name":"flexmi", "type":"flexmi", "instanceOf": "emfatic"},
{"name":"secondEmfatic", "type":"emfatic"},
{"name":"secondFlexmi", "type":"flexmi", "instanceOf": "secondEmfatic"},
{"name":"thirdEmfatic", "type":"emfatic"},
{"name":"thirdFlexmi", "type":"flexmi", "instanceOf": "thirdEmfatic"}
],
"returnType": "text",
"path": "[%= urls.get("epsilon") %]"
},

{
"id": "function-egl",
"name": "egl",
"parameters": [ {"name":"language", "type":"text"},
{"name":"outputType", "type":"text"},
{"name":"outputLanguage", "type":"text"},
{"name":"program", "type":"egl"},
{"name":"secondProgram", "type":"egl"},
{"name":"emfatic", "type":"emfatic"},
{"name":"flexmi", "type":"flexmi", "instanceOf": "emfatic"},
{"name":"secondEmfatic", "type":"emfatic"},
{"name":"secondFlexmi", "type":"flexmi", "instanceOf": "secondEmfatic"},
{"name":"thirdEmfatic", "type":"emfatic"},
{"name":"thirdFlexmi", "type":"flexmi", "instanceOf": "thirdEmfatic"}
],
"returnType": "text",
"path": "[%= urls.get("epsilon") %]"
},

{
"id": "function-evl",
"name": "evl",
"parameters": [ {"name":"language", "type":"text"},
{"name":"outputType", "type":"text"},
{"name":"outputLanguage", "type":"text"},
{"name":"program", "type":"evl"},
{"name":"secondProgram", "type":"evl"},
{"name":"emfatic", "type":"emfatic"},
{"name":"flexmi", "type":"flexmi", "instanceOf": "emfatic"},
{"name":"secondEmfatic", "type":"emfatic"},
{"name":"secondFlexmi", "type":"flexmi", "instanceOf": "secondEmfatic"},
{"name":"thirdEmfatic", "type":"emfatic"},
{"name":"thirdFlexmi", "type":"flexmi", "instanceOf": "thirdEmfatic"}
],

"returnType": "text",
"path": "[%= urls.get("epsilon") %]"
},

{
"id": "function-flexmi2plantuml",
"name": "FlexmiToPlantUML",
"parameters": [ {"name":"flexmi", "type":"flexmi"},
{"name":"emfatic", "type":"emfatic"}
],
"returnType": "diagram",
"path": "[%= urls.get("flexmi2plantuml") %]"
},

{
"id": "function-flexmi2plantuml",
"name": "EmfaticToPlantUML",
"parameters": [ {"name":"emfatic", "type":"emfatic"} ],
"returnType": "diagram",
"path": "[%= urls.get("emfatic2plantuml") %]"
}
],

"panelDefs": [

{
"id": "eol",
"name": "eol",
"panelclass": "ProgramPanel",
"icon": "eol",
"language": "eol",
"buttons" : [
{
"id": "action-button",
"icon": "run",
"actionfunction": "function-eol",
"hint": "Run the program (Ctrl/Cmd+S)"
},
{
"id": "help-button",
"icon": "info",
"url": "https://www.eclipse.org/epsilon/doc/eol/",
"hint": "EOL Language Reference"
}
]
},

{
"id": "etl",
"name": "etl",
"panelclass": "ProgramPanel",
"icon": "etl",
"language": "etl",
"buttons" : [
{
"id": "action-button",
"icon": "run",
"actionfunction": "function-etl",
"hint": "Run the program (Ctrl/Cmd+S)"
},
{
"id": "help-button",
"icon": "info",
"url": "https://www.eclipse.org/epsilon/doc/etl/",
"hint": "ETL Language Reference"
}
]
},

{
"id": "egl",
"name": "egl",
"panelclass": "ProgramPanel",
"icon": "egl",
"help": "https://www.eclipse.org/epsilon/doc/egl/",
"language": "egl",
"buttons" : [
{
"id": "action-button",
"icon": "run",
"actionfunction": "function-egl",
"hint": "Run the program (Ctrl/Cmd+S)"
},
{
"id": "help-button",
"icon": "info",
"url": "https://www.eclipse.org/epsilon/doc/egl/",
"hint": "EGL Language Reference"
}
]
},

{
"id": "evl",
"name": "evl",
"panelclass": "ProgramPanel",
"icon": "evl",
"language": "evl",
"buttons" : [
{
"id": "action-button",
"icon": "run",
"actionfunction": "function-evl",
"hint": "Run the program (Ctrl/Cmd+S)"
},
{
"id": "help-button",
"icon": "info",
"url": "https://www.eclipse.org/epsilon/doc/evl/",
"hint": "EVL Language Reference"
}
]
},

{
"id": "flexmi",
"name": "flexmi",
"panelclass": "ProgramPanel",
"icon": "flexmi",
"language": "flexmi",
"buttons" : [
{
"id": "refresh-button",
"icon": "refresh",
"renderfunction": "function-flexmi2plantuml",
"hint": "Render the model object diagram"
},
{
"id": "help-button",
"icon": "info",
"url": "https://www.eclipse.org/epsilon/doc/flexmi/",
"hint": "Flexmi Reference"
}
]
},

{
"id": "emfatic",
"name": "emfatic",
"panelclass": "ProgramPanel",
"icon": "emfatic",
"language": "emfatic",
"buttons" : [
{
"id": "refresh-button",
"icon": "refresh",
"renderfunction": "function-emfatic2plantuml",
"hint": "Render the model object diagram"
},
{
"id": "help-button",
"icon": "info",
"url": "https://eclipse.org/emfatic",
"hint": "Emfatic Website"
}
]
}
]
}


}
35 changes: 35 additions & 0 deletions http-server/src/main/resources/public/icons.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.mif-eol::before {
content: url("./icons/eol.gif");
}

.mif-flock::before {
content: url("./icons/flock.png");
}

.mif-egl::before {
content: url("./icons/egl.png");
}

.mif-egx::before {
content: url("./icons/egx.png");
}

.mif-etl::before {
content: url("./icons/etl.gif");
}

.mif-epl::before {
content: url("./icons/epl.gif");
}

.mif-evl::before {
content: url("./icons/evl.gif");
}

.mif-flexmi::before {
content: url("./icons/flexmi.png");
}

.mif-emfatic::before {
content: url("./icons/emfatic.png");
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added http-server/src/main/resources/public/icons/eol.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added http-server/src/main/resources/public/icons/epl.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added http-server/src/main/resources/public/icons/etl.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added http-server/src/main/resources/public/icons/evl.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a749bf7

Please sign in to comment.