Skip to content

Commit

Permalink
fixed LOAD RESULT regression
Browse files Browse the repository at this point in the history
  • Loading branch information
chaddy314 committed Feb 7, 2022
1 parent 1ad1e4f commit a934489
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
24 changes: 18 additions & 6 deletions src/main/java/de/uniwue/web/controller/FileController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
Expand All @@ -20,6 +21,9 @@
import javax.xml.transform.stream.StreamResult;

import de.uniwue.web.config.Constants;
import de.uniwue.web.model.Book;
import de.uniwue.web.model.Page;
import org.apache.commons.io.FileUtils;
import org.opencv.core.Mat;
import org.opencv.core.MatOfByte;
import org.opencv.core.Size;
Expand All @@ -39,6 +43,8 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.w3c.dom.Document;

import de.uniwue.algorithm.data.MemoryCleaner;
Expand Down Expand Up @@ -194,12 +200,18 @@ public ResponseEntity<byte[]> getImage(@PathVariable("imageEnc") final String im
* Upload a segmentation to load back into the gui.
*
*/
@RequestMapping(value = "file/upload/annotations", method = RequestMethod.POST)
public @ResponseBody PageAnnotations uploadSegmentation(@RequestParam("file") File file) {
if (!file.isFile()) {
return PageXMLReader.getPageAnnotations(file);
}
return null;
@RequestMapping(value = "file/upload/annotations", method = RequestMethod.POST, headers = "Accept=*/*")
public @ResponseBody PageAnnotations uploadSegmentation(@RequestParam("file") CommonsMultipartFile multipart,
@RequestParam("pageNr") int pageNr,
@RequestParam("bookID") int bookID,
@RequestParam("xmlName") String xmlName) throws IOException {
multipart.getFileItem().getName();
File file = new File(xmlName);
FileUtils.writeByteArrayToFile(file, multipart.getBytes());
FileUtils.writeByteArrayToFile(file, multipart.getBytes());
PageAnnotations annotations = PageXMLReader.getPageAnnotations(file);
file.delete();
return annotations;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/main/webapp/resources/js/viewer/communicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,14 @@ class Communicator {
return this.request("file/upload/segmentsettings", formData, DataType.BYTE);
}

uploadPageXML(file, pageNr, bookID) {
uploadPageXML(file, pageNr, bookID, xmlName) {
const formData = new FormData();
formData.append("file", file);
formData.append("pageNr", pageNr);
formData.append("bookID", bookID);
formData.append("xmlName", xmlName);

return this.request("file/upload/annotations", formData, DataType.SIMPLE);
return this.request("file/upload/annotations", formData, DataType.BYTE);
}

loadImage(image_path, id) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/webapp/resources/js/viewer/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,11 +667,13 @@ function Controller(bookID, accessible_modes, canvasID, regionColors, colors, gl
this.uploadSegmentation = function (file) {
this.showPreloader(true);

_communicator.uploadPageXML(file, _currentPage, _book.id).done((page) => {
_communicator.uploadPageXML(file, _currentPage, _book.id, _segmentation[_currentPage].xmlName).done((page) => {
if(!page){
_gui.displayWarning("Couldn't retrieve annotations from file.", 4000, "red");
this.displayPage(_currentPage, this._imageVersion, true);
}else{
this.setChanged(_currentPage);
this.rotateAnnotations(page);
this._setPage(_currentPage,page);
this.displayPage(_currentPage);
}
Expand Down

0 comments on commit a934489

Please sign in to comment.