-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
570e7bd
commit f8be3ad
Showing
5 changed files
with
58 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 6 additions & 41 deletions
47
...a/org/eclipse/epsilon/labs/playground/fn/emfatic2plantuml/Emfatic2PlantUMLController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,31 @@ | ||
package org.eclipse.epsilon.labs.playground.fn.emfatic2plantuml; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.nio.charset.Charset; | ||
|
||
import org.eclipse.epsilon.egl.EglModule; | ||
import org.eclipse.epsilon.labs.playground.execution.ScriptTimeoutTerminator; | ||
import org.eclipse.epsilon.labs.playground.fn.ModelLoader; | ||
|
||
import io.micronaut.http.annotation.Body; | ||
import io.micronaut.http.annotation.Controller; | ||
import io.micronaut.http.annotation.Post; | ||
import io.micronaut.scheduling.TaskExecutors; | ||
import io.micronaut.scheduling.annotation.ExecuteOn; | ||
import jakarta.inject.Inject; | ||
import net.sourceforge.plantuml.FileFormat; | ||
import net.sourceforge.plantuml.FileFormatOption; | ||
import net.sourceforge.plantuml.SourceStringReader; | ||
import org.eclipse.epsilon.labs.playground.fn.ModelDiagramRenderer; | ||
|
||
@Controller(Emfatic2PlantUMLController.PATH) | ||
public class Emfatic2PlantUMLController { | ||
public static final String PATH = "/emfatic2plantuml"; | ||
|
||
@Inject | ||
ScriptTimeoutTerminator timeoutTerminator; | ||
|
||
@Inject | ||
ModelLoader loader; | ||
ModelDiagramRenderer renderer; | ||
|
||
@ExecuteOn(TaskExecutors.IO) | ||
@Post("/") | ||
@Post | ||
public MetamodelDiagramResponse render(@Body Emfatic2PlantUMLRequest request) { | ||
var response = new MetamodelDiagramResponse(); | ||
|
||
try { | ||
String plantuml = run(request.getEmfatic()); | ||
response.setMetamodelDiagram(plantuml); | ||
return renderer.generateMetamodelDiagram(request.getEmfatic()); | ||
} catch (Throwable e) { | ||
var response = new MetamodelDiagramResponse(); | ||
response.setError(e.getMessage()); | ||
response.setOutput(e.getMessage()); | ||
return response; | ||
} | ||
|
||
return response; | ||
} | ||
|
||
protected String run(String emfatic) throws Exception { | ||
EglModule module = new EglModule(); | ||
module.parse(getClass().getResource("/emfatic2plantuml.egl").toURI()); | ||
module.getContext().getModelRepository().addModel(loader.getInMemoryEmfaticModel(emfatic)); | ||
timeoutTerminator.scheduleScriptTimeout(module); | ||
|
||
try { | ||
String plantUml = module.execute() + ""; | ||
|
||
SourceStringReader reader = new SourceStringReader(plantUml); | ||
ByteArrayOutputStream os = new ByteArrayOutputStream(); | ||
reader.outputImage(os, new FileFormatOption(FileFormat.SVG)); | ||
os.close(); | ||
|
||
return new String(os.toByteArray(), Charset.forName("UTF-8")); | ||
} finally { | ||
module.getContext().getModelRepository().dispose(); | ||
module.getContext().dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters