-
Notifications
You must be signed in to change notification settings - Fork 4
Replace websocket with RestAPI #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
01Parzival10
wants to merge
8
commits into
main
Choose a base branch
from
rest
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4c23ff0
fix hide method call
Kr0nox 786b0e9
use css for delay
Kr0nox 03d1840
Feat: Switch from WebSocket to RestAPI
01Parzival10 31fd6e5
Fix: set correct api adress
01Parzival10 f1615a2
Feat: Get ready for production build
01Parzival10 016eb03
Ensure file writer closure
01Parzival10 930615c
Fix: Issues pointed out by copilot
01Parzival10 37f59a4
Merge branch 'rest' of https://github.com/DataFlowAnalysis/OnlineEdit…
01Parzival10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 2 additions & 19 deletions
21
...dles/org.dataflowanalysis.standalone/src/org/dataflowanalysis/standalone/Application.java
This file contains hidden or 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
8 changes: 3 additions & 5 deletions
8
...ver/bundles/org.dataflowanalysis.standalone/src/org/dataflowanalysis/standalone/Main.java
This file contains hidden or 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
148 changes: 0 additions & 148 deletions
148
...g.dataflowanalysis.standalone/src/org/dataflowanalysis/standalone/analysis/Converter.java
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
...g.dataflowanalysis.standalone/src/org/dataflowanalysis/standalone/api/AnalyzeServlet.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package org.dataflowanalysis.standalone.api; | ||
|
|
||
| import org.dataflowanalysis.standalone.services.AnalyzeService; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
|
|
||
| public class AnalyzeServlet extends Servlet { | ||
| private static final long serialVersionUID = 1L; | ||
| private final AnalyzeService analysisService = new AnalyzeService(); | ||
|
|
||
| protected String doSpecific(String message, String name){ | ||
| try { | ||
| return analysisService.analyzeAnnotate(message); | ||
| } catch (JsonProcessingException e) { | ||
| throw new IllegalArgumentException("Json unparsable"); | ||
| } | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
...rg.dataflowanalysis.standalone/src/org/dataflowanalysis/standalone/api/LoadDDServlet.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package org.dataflowanalysis.standalone.api; | ||
|
|
||
| import org.dataflowanalysis.standalone.services.LoadDDService; | ||
|
|
||
| public class LoadDDServlet extends Servlet { | ||
|
|
||
| private static final long serialVersionUID = 1L; | ||
| private final LoadDDService loadDDService = new LoadDDService(); | ||
|
|
||
| protected String doSpecific(String message, String name){ | ||
| return loadDDService.safeLoadAndConvertDFDString(message, name); | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
...g.dataflowanalysis.standalone/src/org/dataflowanalysis/standalone/api/LoadPCMServlet.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package org.dataflowanalysis.standalone.api; | ||
|
|
||
| import org.dataflowanalysis.standalone.services.LoadPCMService; | ||
|
|
||
| public class LoadPCMServlet extends Servlet { | ||
|
|
||
| private static final long serialVersionUID = 1L; | ||
| private final LoadPCMService loadPCMService = new LoadPCMService(); | ||
|
|
||
| protected String doSpecific(String message, String name){ | ||
| return loadPCMService.safeLoadAndConvertPCMString(message); | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
...rg.dataflowanalysis.standalone/src/org/dataflowanalysis/standalone/api/SaveDDServlet.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package org.dataflowanalysis.standalone.api; | ||
|
|
||
| import org.dataflowanalysis.standalone.services.SaveDDService; | ||
|
|
||
|
|
||
| public class SaveDDServlet extends Servlet { | ||
|
|
||
| private static final long serialVersionUID = 1L; | ||
| private final SaveDDService saveDDService = new SaveDDService(); | ||
|
|
||
| protected String doSpecific(String message, String name){ | ||
| return saveDDService.convertToDFDandStringify(message, name); | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
...dles/org.dataflowanalysis.standalone/src/org/dataflowanalysis/standalone/api/Servlet.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package org.dataflowanalysis.standalone.api; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import jakarta.servlet.http.HttpServlet; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
|
|
||
| public abstract class Servlet extends HttpServlet{ | ||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| @Override | ||
| protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
| String message = request.getReader() | ||
| .lines() | ||
| .collect(Collectors.joining(System.lineSeparator())); | ||
|
|
||
| String name = message.split(":")[0]; | ||
| message = message.replaceFirst(name + ":", ""); | ||
|
|
||
| try { | ||
| var result = doSpecific(message, name); | ||
| writeText(response, HttpServletResponse.SC_OK, name + ":" + result); | ||
| } catch (IllegalArgumentException e) { | ||
| writeText(response, HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); | ||
|
|
||
| } catch (Exception e) { | ||
| writeText(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal server error"); | ||
| } | ||
| } | ||
|
|
||
| private void writeText(HttpServletResponse response, int status, String message) throws IOException { | ||
| response.setStatus(status); | ||
| response.setContentType("text/plain;charset=UTF-8"); | ||
| response.getWriter().write(message); | ||
| } | ||
|
|
||
| /** | ||
| * Servlet specific activities | ||
| * @param message Incoming message content | ||
| * @param name Name of the diagram | ||
| * @return result | ||
| */ | ||
| protected abstract String doSpecific(String message, String name); | ||
| } | ||
28 changes: 28 additions & 0 deletions
28
...org.dataflowanalysis.standalone/src/org/dataflowanalysis/standalone/server/ApiServer.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package org.dataflowanalysis.standalone.server; | ||
|
|
||
| import java.net.InetSocketAddress; | ||
|
|
||
| import org.dataflowanalysis.standalone.api.AnalyzeServlet; | ||
| import org.dataflowanalysis.standalone.api.LoadDDServlet; | ||
| import org.dataflowanalysis.standalone.api.LoadPCMServlet; | ||
| import org.dataflowanalysis.standalone.api.SaveDDServlet; | ||
| import org.eclipse.jetty.server.Server; | ||
| import org.eclipse.jetty.servlet.ServletContextHandler; | ||
|
|
||
| public class ApiServer { | ||
| public static void start() throws Exception { | ||
| Server server = new Server(new InetSocketAddress("localhost", 3000)); | ||
|
01Parzival10 marked this conversation as resolved.
|
||
|
|
||
| ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); | ||
| context.setContextPath("/"); | ||
|
|
||
| context.addServlet(AnalyzeServlet.class, "/api/analyze"); | ||
| context.addServlet(LoadDDServlet.class, "/api/loadDD"); | ||
| context.addServlet(LoadPCMServlet.class, "/api/loadPCM"); | ||
| context.addServlet(SaveDDServlet.class, "/api/saveDD"); | ||
|
|
||
| server.setHandler(context); | ||
| server.start(); | ||
| server.join(); | ||
| } | ||
| } | ||
39 changes: 39 additions & 0 deletions
39
...aflowanalysis.standalone/src/org/dataflowanalysis/standalone/services/AnalyzeService.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package org.dataflowanalysis.standalone.services; | ||
|
|
||
| import org.dataflowanalysis.converter.dfd2web.DFD2WebConverter; | ||
| import org.dataflowanalysis.converter.web2dfd.Web2DFDConverter; | ||
| import org.dataflowanalysis.converter.web2dfd.WebEditorConverterModel; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
|
|
||
| public class AnalyzeService { | ||
| /** | ||
| * Analyzes a Model in WebEditor Json Representation and returns the analyzed Model | ||
| * @param webEditorDfd Model to be analyzed | ||
| * @return Analyzed Model | ||
| * @throws JsonProcessingException | ||
| */ | ||
| public String analyzeAnnotate(String diagramMessage) throws JsonProcessingException { | ||
| var webEditorDfd = Util.deserializeJson(diagramMessage); | ||
|
|
||
| var webEditorConverter = new Web2DFDConverter(); | ||
| var dd = webEditorConverter.convert(new WebEditorConverterModel(webEditorDfd)); | ||
| var dfdConverter = new DFD2WebConverter(); | ||
| if (webEditorDfd.constraints() != null && !webEditorDfd.constraints().isEmpty()) { | ||
| var constraints = Util.parseConstraints(webEditorDfd); | ||
| dfdConverter.setConstraints(constraints); | ||
| } | ||
| var newJson = dfdConverter.convert(dd).getModel(); | ||
|
|
||
| for (var child : newJson.model().children()) { | ||
| if (child.type().startsWith("node") && child.annotations() != null) { | ||
| var oldNode = webEditorDfd.model().children().stream().filter(node -> node.id().equals(child.id())).findAny().orElseThrow(); | ||
| //Necessary if ugly if we want to preserve custom annotations | ||
| var annotationsToRemove = oldNode.annotations().stream().filter(a -> a.message().startsWith("Propagated") || a.message().startsWith("Incoming") || a.message().startsWith("Constraint")).toList(); | ||
| oldNode.annotations().removeAll(annotationsToRemove); | ||
| oldNode.annotations().addAll(child.annotations()); | ||
| } | ||
| } | ||
| return Util.serializeJson(webEditorDfd); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.