diff --git a/app/logbook/olog/client-es/src/main/java/org/phoebus/olog/es/api/model/OlogObjectMappers.java b/app/logbook/olog/client-es/src/main/java/org/phoebus/olog/es/api/model/OlogObjectMappers.java index 0e07d9f6fe..618ae71dae 100644 --- a/app/logbook/olog/client-es/src/main/java/org/phoebus/olog/es/api/model/OlogObjectMappers.java +++ b/app/logbook/olog/client-es/src/main/java/org/phoebus/olog/es/api/model/OlogObjectMappers.java @@ -112,6 +112,7 @@ public OlogAttachment deserialize(JsonParser jp, DeserializationContext ctxt) String fileMetadataDescription = node.get("fileMetadataDescription").asText(); OlogAttachment a = new OlogAttachment(); a.setFileName(filename); + a.setId(id); a.setContentType(fileMetadataDescription); return a; } diff --git a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/SingleLogEntryDisplayController.java b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/SingleLogEntryDisplayController.java index ba6960d68f..9ab9552142 100644 --- a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/SingleLogEntryDisplayController.java +++ b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/SingleLogEntryDisplayController.java @@ -199,11 +199,21 @@ protected void finalize() { fileAttachment.setContentType(attachment.getContentType()); fileAttachment.setThumbnail(false); fileAttachment.setFileName(attachment.getName()); + // A bit of a hack here. The idea is to create a temporary file with a known name, + // i.e. without the random file name part. + // Files.createdTempFile does not support it, so a bit of workaround is needed. try { - Path temp = Files.createTempFile("phoebus", attachment.getName()); - Files.copy(logClient.getAttachment(logEntry.getId(), attachment.getName()), temp, StandardCopyOption.REPLACE_EXISTING); - fileAttachment.setFile(temp.toFile()); - temp.toFile().deleteOnExit(); + // This creates a temp file with a random part + Path random = Files.createTempFile(attachment.getId(), attachment.getName()); + // This does NOT create a file + Path nonRandom = random.resolveSibling(attachment.getId()); + if(!Files.exists(nonRandom.toAbsolutePath())){ + // Moves the temp file with random part to file with non-random part. + nonRandom = Files.move(random, nonRandom); + Files.copy(logClient.getAttachment(logEntry.getId(), attachment.getName()), nonRandom, StandardCopyOption.REPLACE_EXISTING); + fileAttachment.setFile(nonRandom.toFile()); + nonRandom.toFile().deleteOnExit(); + } } catch (LogbookException | IOException e) { Logger.getLogger(SingleLogEntryDisplayController.class.getName()) .log(Level.WARNING, "Failed to retrieve attachment " + fileAttachment.getFileName(), e);