Revize f19bcf07
Přidáno uživatelem Tomáš Šimandl před více než 6 roky(ů)
sources/src/main/java/cz/zcu/kiv/offscreen/servlets/UploadFiles.java | ||
---|---|---|
43 | 43 |
|
44 | 44 |
@Override |
45 | 45 |
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
46 |
String jsonGraph = new FileLoader().loadFile(request);
|
|
46 |
Map<String, String> jsonData = new FileLoader().loadFile(request);
|
|
47 | 47 |
|
48 |
if (Strings.isNullOrEmpty(jsonGraph)) { |
|
48 |
if(!jsonData.containsKey("file") || !jsonData.containsKey("jsonFileFormat")) { |
|
49 |
request.setAttribute("errorMessage", "<strong>Invalid request!</strong><br/>"); |
|
50 |
doGet(request, response); |
|
51 |
|
|
52 |
} else if (Strings.isNullOrEmpty(jsonData.get("file"))) { |
|
49 | 53 |
request.setAttribute("errorMessage", "<strong>Unsupported file</strong><br/>"); |
50 | 54 |
doGet(request, response); |
51 | 55 |
} else { |
52 |
request.getSession().setAttribute("json_graph", jsonGraph); |
|
56 |
request.getSession().setAttribute("json_graph", jsonData.get("file")); |
|
57 |
request.getSession().setAttribute("json_graph_type", jsonData.get("jsonFileFormat")); |
|
53 | 58 |
response.sendRedirect(getServletContext().getInitParameter("HOME_URL") + "graph"); |
54 | 59 |
} |
55 | 60 |
} |
sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/LoadGraphData.java | ||
---|---|---|
50 | 50 |
*/ |
51 | 51 |
private void getDiagramFromSession(HttpServletRequest request, HttpServletResponse response) throws IOException { |
52 | 52 |
String jsonToDisplay = (String) request.getSession().getAttribute("json_graph"); |
53 |
String jsonType = (String) request.getSession().getAttribute("json_graph_type"); |
|
53 | 54 |
|
54 |
if (!Strings.isNullOrEmpty(jsonToDisplay)) { |
|
55 |
GraphManager graphManager = new GraphJSONDataLoader(jsonToDisplay).LoadData(); |
|
55 |
if (!Strings.isNullOrEmpty(jsonToDisplay) && jsonType != null) { |
|
56 | 56 |
|
57 |
String configLocation = ConfigurationLoader.getConfigLocation(request.getServletContext()); |
|
58 |
JSONConfigLoader configLoader = new JSONConfigLoader(graphManager, configLocation); |
|
57 |
String rawJson; |
|
59 | 58 |
|
60 |
Graph graph = graphManager.createGraph(configLoader); |
|
61 |
JSONObject json = JSONObject.fromObject(graph); |
|
59 |
switch (jsonType) { |
|
60 |
case "spade": |
|
61 |
String configLocation = ConfigurationLoader.getConfigLocation(request.getServletContext()); |
|
62 |
rawJson = convertSpadeToRawJson(jsonToDisplay, configLocation); |
|
63 |
break; |
|
64 |
default: |
|
65 |
rawJson = jsonToDisplay; |
|
66 |
} |
|
62 | 67 |
|
63 | 68 |
response.setStatus(HttpServletResponse.SC_OK); |
64 |
response.getWriter().write(json.toString());
|
|
69 |
response.getWriter().write(rawJson);
|
|
65 | 70 |
response.getWriter().flush(); |
66 | 71 |
return; |
67 | 72 |
} |
... | ... | |
69 | 74 |
response.setStatus(HttpServletResponse.SC_BAD_REQUEST); |
70 | 75 |
} |
71 | 76 |
|
77 |
/** |
|
78 |
* Convert input spade JSON to frontend backend JSON and return it. |
|
79 |
*/ |
|
80 |
private String convertSpadeToRawJson(String spadeJson, String configLocation){ |
|
81 |
GraphManager graphManager = new GraphJSONDataLoader(spadeJson).LoadData(); |
|
82 |
|
|
83 |
JSONConfigLoader configLoader = new JSONConfigLoader(graphManager, configLocation); |
|
84 |
|
|
85 |
Graph graph = graphManager.createGraph(configLoader); |
|
86 |
JSONObject json = JSONObject.fromObject(graph); |
|
87 |
|
|
88 |
return json.toString(); |
|
89 |
} |
|
90 |
|
|
72 | 91 |
/** |
73 | 92 |
* Add json of diagram which is taken from database to response or set http status code to UNAUTHORIZED. |
74 | 93 |
* Permissions of user to this diagram is checked. |
sources/src/main/webapp/uploadFiles.jsp | ||
---|---|---|
41 | 41 |
<input type="file" name="file" id="file"> |
42 | 42 |
</div> |
43 | 43 |
|
44 |
<div class="form-field"> |
|
45 |
<label for="jsonFileFormat">Select type of JSON:</label><br> |
|
46 |
<select name="jsonFileFormat" id="jsonFileFormat"> |
|
47 |
<option value="spade">Spade JSON</option> |
|
48 |
<option value="raw">Raw JSON</option> |
|
49 |
</select> |
|
50 |
</div> |
|
51 |
|
|
44 | 52 |
<button type="submit">Start visualization</button> |
45 | 53 |
</form> |
46 | 54 |
</div> |
Také k dispozici: Unified diff
Added possibility to upload raw JSON (front-end -- back-end JSON)