Fixes bug on DMP pdf and doc export not deleting the documents created in memory.
This commit is contained in:
parent
9d91c8419d
commit
2276a875ec
|
@ -42,6 +42,7 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
@ -168,7 +169,8 @@ public class DMPs extends BaseController {
|
|||
ResponseEntity<byte[]> getPDFDocument(@PathVariable String id, @RequestHeader("Content-Type") String contentType) throws IllegalAccessException, IOException, InstantiationException, InterruptedException {
|
||||
System.out.println(contentType);
|
||||
File file = this.dataManagementPlanManager.getWordDocument(id);
|
||||
File pdffile = datasetManager.convertToPDF(file, environment, file.getName());
|
||||
String name = file.getName().substring(0, file.getName().length() - 5);
|
||||
File pdffile = datasetManager.convertToPDF(file, environment, name);
|
||||
InputStream resource = new FileInputStream(pdffile);
|
||||
System.out.println("Mime Type of " + file.getName() + " is " +
|
||||
new MimetypesFileTypeMap().getContentType(file));
|
||||
|
@ -180,6 +182,9 @@ public class DMPs extends BaseController {
|
|||
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
|
||||
|
||||
byte[] content = org.apache.poi.util.IOUtils.toByteArray(resource);
|
||||
resource.close();
|
||||
Files.deleteIfExists(file.toPath());
|
||||
Files.deleteIfExists(pdffile.toPath());
|
||||
return new ResponseEntity<>(content,
|
||||
responseHeaders,
|
||||
HttpStatus.OK);
|
||||
|
|
|
@ -33,6 +33,7 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -88,8 +89,10 @@ public class DatasetWizardController extends BaseController {
|
|||
responseHeaders.set("Content-Disposition", "attachment;filename=" + file.getName());
|
||||
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
|
||||
byte[] content = IOUtils.toByteArray(resource);
|
||||
|
||||
byte[] content = IOUtils.toByteArray(resource);
|
||||
resource.close();
|
||||
Files.deleteIfExists(file.toPath());
|
||||
return new ResponseEntity<>(content,
|
||||
responseHeaders,
|
||||
HttpStatus.OK);
|
||||
|
|
|
@ -284,6 +284,7 @@ public class DatasetManager {
|
|||
File resultPdf = new File(environment.getProperty("configuration.exportUrl") + label + ".pdf");
|
||||
FileOutputStream output = new FileOutputStream(resultPdf);
|
||||
IOUtils.write(queueResult, output);
|
||||
output.close();
|
||||
|
||||
return resultPdf;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue