|
72 | 72 | import org.labkey.api.data.Table; |
73 | 73 | import org.labkey.api.data.TableInfo; |
74 | 74 | import org.labkey.api.data.TableSelector; |
| 75 | +import org.labkey.api.discvrcore.annotation.UtilityAction; |
75 | 76 | import org.labkey.api.exceptions.OptimisticConflictException; |
76 | 77 | import org.labkey.api.exp.ExperimentException; |
77 | 78 | import org.labkey.api.exp.api.DataType; |
@@ -428,6 +429,81 @@ public void addNavTrail(NavTree tree) |
428 | 429 | } |
429 | 430 | } |
430 | 431 |
|
| 432 | + @RequiresPermission(ReadPermission.class) |
| 433 | + @IgnoresTermsOfUse |
| 434 | + public static class DownloadTempImageAction extends ExportAction<TempImageAction> |
| 435 | + { |
| 436 | + @Override |
| 437 | + public void export(TempImageAction form, HttpServletResponse response, BindException errors) throws Exception |
| 438 | + { |
| 439 | + File parentDir = form.getDirectory() == null ? FileUtil.getTempDirectory() : new File(FileUtil.getTempDirectory(), form.getDirectory()); |
| 440 | + File targetFile = new File(parentDir, form.getFileName()); |
| 441 | + targetFile = FileUtil.getAbsoluteCaseSensitiveFile(targetFile); |
| 442 | + |
| 443 | + if (!NetworkDrive.exists(targetFile)) |
| 444 | + { |
| 445 | + throw new FileNotFoundException("Could not find file: " + targetFile.getPath()); |
| 446 | + } |
| 447 | + |
| 448 | + if (parentDir.listFiles() == null) |
| 449 | + { |
| 450 | + throw new FileNotFoundException("Unable to list the contents of folder: " + parentDir.getPath()); |
| 451 | + } |
| 452 | + |
| 453 | + PageFlowUtil.streamFile(response, targetFile, false); |
| 454 | + |
| 455 | + //the file will be recreated, so delete upon running |
| 456 | + FileUtils.deleteQuietly(targetFile); |
| 457 | + |
| 458 | + //if the folder if empty, remove it too. other simultaneous requests might have deleted this folder before we get to it |
| 459 | + if (parentDir != null && parentDir.exists()) |
| 460 | + { |
| 461 | + File[] children = parentDir.listFiles(); |
| 462 | + if (children != null && children.length == 0 && !parentDir.equals(FileUtil.getTempDirectory())) |
| 463 | + { |
| 464 | + FileUtils.deleteQuietly(parentDir); //the Images folder |
| 465 | + File parent = parentDir.getParentFile(); |
| 466 | + FileUtils.deleteQuietly(parent); //the file's folder |
| 467 | + |
| 468 | + if (parent != null && parent.getParentFile() != null) |
| 469 | + { |
| 470 | + File[] children2 = parent.getParentFile().listFiles(); |
| 471 | + if (children2 != null && children2.length == 0) |
| 472 | + FileUtils.deleteQuietly(parent.getParentFile()); //the file's folder |
| 473 | + } |
| 474 | + } |
| 475 | + } |
| 476 | + } |
| 477 | + } |
| 478 | + |
| 479 | + @RequiresPermission(ReadPermission.class) |
| 480 | + @IgnoresTermsOfUse |
| 481 | + public static class ConvertTextToFileAction extends ExportAction<ConvertTextToFileForm> |
| 482 | + { |
| 483 | + @Override |
| 484 | + public void export(ConvertTextToFileForm form, HttpServletResponse response, BindException errors) throws Exception |
| 485 | + { |
| 486 | + String text = form.getText(); |
| 487 | + |
| 488 | + if (text == null) |
| 489 | + { |
| 490 | + errors.reject(ERROR_MSG, "Need to provide text"); |
| 491 | + return; |
| 492 | + } |
| 493 | + if (form.getFileName() == null) |
| 494 | + { |
| 495 | + errors.reject(ERROR_MSG, "Need to provide a filename"); |
| 496 | + return; |
| 497 | + } |
| 498 | + |
| 499 | + Map<String, String> headers = new HashMap<>(); |
| 500 | + |
| 501 | + PageFlowUtil.prepareResponseForFile(response, headers, form.getFileName(), true); |
| 502 | + response.getOutputStream().print(text); |
| 503 | + } |
| 504 | + } |
| 505 | + |
| 506 | + @UtilityAction(label = "Find Orphan Files", description = "This will start a pipeline job that will inspect all files in this folder to identify potential orphan or otherwise unnecessary files") |
431 | 507 | @RequiresPermission(ReadPermission.class) |
432 | 508 | public static class FindOrphanFilesAction extends ConfirmAction<Object> |
433 | 509 | { |
@@ -4955,6 +5031,7 @@ public void setOutputFileIds(Integer[] outputFileIds) |
4955 | 5031 | } |
4956 | 5032 | } |
4957 | 5033 |
|
| 5034 | + @UtilityAction(label = "Update ExpData Path", description = "This will update the DataFileUrl on the selected ExpData to the path provided") |
4958 | 5035 | @RequiresSiteAdmin |
4959 | 5036 | public static class UpdateExpDataPathAction extends ConfirmAction<UpdateExpDataPathForm> |
4960 | 5037 | { |
|
0 commit comments