Skip to content

Commit

Permalink
fix(Export): Request uri too large error (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffreykwan authored Dec 20, 2022
1 parent bcfd4c3 commit 716622e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,11 @@
<artifactId>clamav-client</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>com.github.wajda</groupId>
<artifactId>lzstring4java</artifactId>
<version>0.1</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
40 changes: 31 additions & 9 deletions src/main/java/org/wise/vle/web/wise5/TeacherGetDataController.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.wise.vle.web.wise5;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.AccessDeniedException;
Expand All @@ -16,6 +19,8 @@
import org.wise.portal.presentation.web.controllers.ControllerUtil;
import org.wise.portal.service.vle.wise5.VLEService;

import rufus.lzstring4java.LZString;

@Secured("ROLE_TEACHER")
@RestController
public class TeacherGetDataController {
Expand All @@ -24,8 +29,7 @@ public class TeacherGetDataController {
private VLEService vleService;

@GetMapping("/api/teacher/data")
protected HashMap<String, Object> getData(
@RequestParam("runId") RunImpl run,
protected HashMap<String, Object> getData(@RequestParam("runId") RunImpl run,
@RequestParam(value = "getStudentWork", defaultValue = "false") boolean getStudentWork,
@RequestParam(value = "getEvents", defaultValue = "false") boolean getEvents,
@RequestParam(value = "getAnnotations", defaultValue = "false") boolean getAnnotations,
Expand All @@ -46,30 +50,48 @@ protected HashMap<String, Object> getData(
@RequestParam(value = "localNotebookItemId", required = false) String localNotebookItemId,
@RequestParam(value = "notebookItemId", required = false) Integer notebookItemId,
@RequestParam(value = "annotationType", required = false) String annotationType,
@RequestParam(value = "components", required = false) List<JSONObject> components,
@RequestParam(value = "components", required = false) String components,
@RequestParam(value = "onlyGetLatest", required = false) Boolean onlyGetLatest) {
if (canGetData(run)) {
HashMap<String, Object> data = new HashMap<String, Object>();
int runId = run.getId().intValue();
if (getStudentWork) {
data.put("studentWorkList", vleService.getStudentWorkList(id, runId, periodId, workgroupId,
isAutoSave, isSubmit, nodeId, componentId, componentType, components, onlyGetLatest));
data.put("studentWorkList",
vleService.getStudentWorkList(id, runId, periodId, workgroupId, isAutoSave, isSubmit,
nodeId, componentId, componentType, getComponentsList(components), onlyGetLatest));
}
if (getEvents) {
data.put("events", vleService.getEvents(id, runId, periodId, workgroupId, nodeId,
componentId, componentType, context, category, event, components));
componentId, componentType, context, category, event, getComponentsList(components)));
}
if (getAnnotations) {
data.put("annotations", vleService.getAnnotations(id, runId, periodId, fromWorkgroupId,
toWorkgroupId, nodeId, componentId, studentWorkId, localNotebookItemId, notebookItemId,
annotationType));
data.put("annotations",
vleService.getAnnotations(id, runId, periodId, fromWorkgroupId, toWorkgroupId, nodeId,
componentId, studentWorkId, localNotebookItemId, notebookItemId, annotationType));
}
return data;
} else {
throw new AccessDeniedException("Not permitted");
}
}

private List<JSONObject> getComponentsList(String components) {
if (components == null) {
return null;
}
String decompressedComponents = LZString.decompressFromEncodedURIComponent(components);
List<JSONObject> componentsList = new ArrayList<>();
try {
JSONArray componentsJSONArray = new JSONArray(decompressedComponents);
for (int c = 0; c < componentsJSONArray.length(); c++) {
componentsList.add(componentsJSONArray.getJSONObject(c));
}
} catch (JSONException e) {
e.printStackTrace();
}
return componentsList;
}

private boolean canGetData(Run run) {
User signedInUser = ControllerUtil.getSignedInUser();
return run.getOwner().equals(signedInUser) || run.getSharedowners().contains(signedInUser)
Expand Down

0 comments on commit 716622e

Please sign in to comment.