Skip to content

Commit

Permalink
update comparetext
Browse files Browse the repository at this point in the history
  • Loading branch information
Yinnii committed Oct 17, 2024
1 parent c786d8f commit 8764c52
Showing 1 changed file with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@
import javax.ws.rs.core.MediaType;

import org.glassfish.jersey.media.multipart.FormDataParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestPart;


import lombok.Locked;


Expand Down Expand Up @@ -98,7 +100,6 @@ public ResponseEntity<String> getWritingTasks(@RequestParam(value = "courseId")
jsonObject.put("text", tasks.get(i).getText());
jsonObject.put("title", tasks.get(i).getTitle());
jsonArray.add(jsonObject);
System.out.println(jsonObject.toString());
jsonObject.put("intent", "nummer " + tasks.get(i).getNr());
jsonObject.put("label", "Schreibaufgabe "+ tasks.get(i).getNr());
jsonObject.put("isFile", false);
Expand Down Expand Up @@ -479,19 +480,10 @@ public ResponseEntity<String> getAnalyzedText(@PathVariable("label1") String lab
@ApiResponse(responseCode = "200" , description = "",content = {@Content(mediaType = "application/json")} ),
@ApiResponse(responseCode = "500", description = "Response failed.")
})
@PostMapping(value = "/compareText", produces = MediaType.APPLICATION_JSON)
public ResponseEntity<String> compareText(@RequestPart MultiValueMap<String,String> fileMp, @RequestPart("file") MultipartFile file) throws ParseException, IOException {
System.out.println(fileMp);
String label1 = fileMp.getFirst("label1");
String label2 = fileMp.getFirst("label2");
String type = fileMp.getFirst("type");
String template = fileMp.getFirst("template");
String wordSpec = fileMp.getFirst("wordSpec");
String email = fileMp.getFirst("email");
Integer courseId = Integer.parseInt(fileMp.getFirst("courseId"));
String sbfmURL = fileMp.getFirst("sbfmURL");


@PostMapping(value = "/compareText", consumes = {MediaType.MULTIPART_FORM_DATA, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM}, produces = MediaType.APPLICATION_JSON)
public ResponseEntity<String> compareText(@RequestPart("file") MultipartFile file, @RequestPart String label1, @RequestPart String label2, @RequestPart String type, @RequestPart String wordspec, @RequestPart String template, @RequestPart String courseId, @RequestPart String email, @RequestPart String sbfmURL
) throws ParseException, IOException {
System.out.println("Comparing text...");
if (service.isActive.getOrDefault(label1, false)) {
JSONObject err = new JSONObject();
err.put("errorMessage", "User: " + label1 + " currently busy.");
Expand All @@ -508,8 +500,7 @@ public ResponseEntity<String> compareText(@RequestPart MultiValueMap<String,Stri
}

service.isActive.put(label1, true);

String topic = service.getTaskNameByIds(courseId, Integer.parseInt(label2));
String topic = service.getTaskNameByIds(Integer.parseInt(courseId), Integer.parseInt(label2));
InputStream textInputStream = file.getInputStream();

String encodedByteString = service.convertInputStreamToBase64(textInputStream);
Expand Down Expand Up @@ -550,9 +541,9 @@ public ResponseEntity<String> compareText(@RequestPart MultiValueMap<String,Stri
String uuid = service.getUuidByEmail(email);
if (uuid!=null){
// user has accepted
LrsCredentials lrsCredentials = service.getLrsCredentialsByCourse(courseId);
LrsCredentials lrsCredentials = service.getLrsCredentialsByCourse(Integer.parseInt(courseId));
if(lrsCredentials!=null){
JSONObject xapi = service.prepareXapiStatement(uuid, "uploaded_task", topic, courseId, Integer.parseInt(label2), uploaded.toString(),null,null);
JSONObject xapi = service.prepareXapiStatement(uuid, "uploaded_task", topic, Integer.parseInt(courseId), Integer.parseInt(label2), uploaded.toString(),null,null);
String toEncode = lrsCredentials.getClientKey()+":"+lrsCredentials.getClientSecret();
String encodedString = Base64.getEncoder().encodeToString(toEncode.getBytes());
service.sendXAPIStatement(xapi, encodedString);
Expand Down

0 comments on commit 8764c52

Please sign in to comment.