use of org.phoebus.logbook.LogEntry in project phoebus by ControlSystemStudio.
the class SingleLogEntryDisplayController method fetchAttachments.
/**
* Retrieves the actual attachments from the remote service and copies them to temporary files. The idea is that attachments
* should be retrieved when user requests to see the details, not in connection to a log entry search.
* @return A {@link Collection} of {@link Attachment}s holding the attachment content.
*/
private void fetchAttachments() {
JobManager.schedule("Fetch attachment data", monitor -> {
Collection<Attachment> attachments = logEntry.getAttachments().stream().filter((attachment) -> {
return attachment.getName() != null && !attachment.getName().isEmpty();
}).map((attachment) -> {
OlogAttachment fileAttachment = new OlogAttachment();
fileAttachment.setContentType(attachment.getContentType());
fileAttachment.setThumbnail(false);
fileAttachment.setFileName(attachment.getName());
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();
} catch (LogbookException | IOException e) {
Logger.getLogger(SingleLogEntryDisplayController.class.getName()).log(Level.WARNING, "Failed to retrieve attachment " + fileAttachment.getFileName(), e);
}
return fileAttachment;
}).collect(Collectors.toList());
// // TODO: to allow the UI to be used by non Olog log services commenting out the cast to OlogLog,
// // the model will not be updated.
// // Update the log entry attachments object
// ((OlogLog)logEntry).setAttachments(attachments);
// // Update UI
// Platform.runLater(() -> attachmentsPreviewController
// .setAttachments(FXCollections.observableArrayList(logEntry.getAttachments())));
// Update UI
Platform.runLater(() -> attachmentsPreviewController.setAttachments(FXCollections.observableArrayList(attachments)));
});
}
use of org.phoebus.logbook.LogEntry in project phoebus by ControlSystemStudio.
the class SingleLogEntryDisplayController method setLogEntry.
public void setLogEntry(LogEntry logEntry) {
this.logEntry = logEntry;
// Always expand properties pane.
attachmentsPane.setExpanded(true);
// Get the attachments from service
fetchAttachments();
// attachmentsPreviewController
// .setAttachments(FXCollections.observableArrayList(logEntry.getAttachments()));
List<String> hiddenPropertiesNames = Arrays.asList(LogbookUIPreferences.hidden_properties);
// Remove the hidden properties
List<Property> propertiesToShow = logEntry.getProperties().stream().filter(property -> !hiddenPropertiesNames.contains(property.getName())).collect(Collectors.toList());
propertiesController.setProperties(propertiesToShow);
logTime.setText(SECONDS_FORMAT.format(logEntry.getCreatedDate()));
logOwner.setText(logEntry.getOwner());
logTitle.setWrapText(true);
logTitle.setText(logEntry.getTitle());
// Content is defined by the source (default) or description field. If both are null
// or empty, do no load any content to the WebView.
WebEngine webEngine = logDescription.getEngine();
webEngine.setUserStyleSheetLocation(getClass().getResource("/detail_log_webview.css").toExternalForm());
if (logEntry.getSource() != null) {
webEngine.loadContent(getFullHtml(logEntry.getSource()));
} else if (logEntry.getDescription() != null) {
webEngine.loadContent(getFullHtml(logEntry.getDescription()));
}
ObservableList<String> logbookList = FXCollections.observableArrayList();
logbookList.addAll(logEntry.getLogbooks().stream().map(Logbook::getName).collect(Collectors.toList()));
ObservableList<String> tagList = FXCollections.observableArrayList();
tagList.addAll(logEntry.getTags().stream().map(Tag::getName).collect(Collectors.toList()));
if (!logEntry.getLogbooks().isEmpty()) {
logbooks.setWrapText(false);
logbooks.setText(logEntry.getLogbooks().stream().map(Logbook::getName).collect(Collectors.joining(",")));
}
if (!logEntry.getTags().isEmpty()) {
tags.setText(logEntry.getTags().stream().map(Tag::getName).collect(Collectors.joining(",")));
} else {
tags.setText(null);
}
logEntryId.setText(Long.toString(logEntry.getId()));
level.setText(logEntry.getLevel());
}
use of org.phoebus.logbook.LogEntry in project phoebus by ControlSystemStudio.
the class DataBrowserAdapterFactoryTest method testAdaptLogEntry.
@Test
public void testAdaptLogEntry() {
DatabrowserAdapterFactory factory = new DatabrowserAdapterFactory();
DatabrowserSelection databrowserSelection = Mockito.mock(DatabrowserSelection.class);
when(databrowserSelection.getPlotTitle()).thenReturn(Optional.of("Plot Title"));
when(databrowserSelection.getPlotPVs()).thenReturn(Arrays.asList("PV1", "PV2"));
when(databrowserSelection.getPlotTime()).thenReturn(TimeRelativeInterval.of(Instant.EPOCH, Duration.ofDays(10)));
Optional<LogEntry> logEntry = factory.adapt(databrowserSelection, LogEntry.class);
assertEquals(1, logEntry.get().getAttachments().size());
}
use of org.phoebus.logbook.LogEntry in project phoebus by ControlSystemStudio.
the class LogEntryDisplayDemo method start.
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("LogEntry Display demo");
VBox root = new VBox();
FXMLLoader loader = new FXMLLoader();
loader.setLocation(this.getClass().getResource("LogEntryDisplay.fxml"));
loader.setRoot(root);
loader.setController(new LogEntryController());
loader.load();
LogEntryController controller = loader.getController();
root = loader.getRoot();
primaryStage.setScene(new Scene(root, 400, 400));
primaryStage.show();
// Every few seconds add a new log entry
ex.schedule(() -> {
LogEntry log = LogEntryBuilder.log().description("Fast correctors for the vertical orbit have glitched to near saturation. Archiver shows there have been several episodes the past 24 hrs. Appears that FOFB in vertical plane might have momentary bad BPM reading.").createdDate(Instant.now()).build();
runLater(() -> {
controller.setLogEntry(log);
});
}, 2, TimeUnit.SECONDS);
ex.schedule(() -> {
Set<Tag> tags = new HashSet<Tag>();
tags.add(TagImpl.of("tag1", "active"));
tags.add(TagImpl.of("tag2", "active"));
Set<Logbook> logbooks = new HashSet<Logbook>();
logbooks.add(LogbookImpl.of("logbook1", "active"));
logbooks.add(LogbookImpl.of("logbook2", "active"));
runLater(() -> {
controller.setLogEntry(LogEntryBuilder.log(controller.getLogEntry()).inLogbooks(logbooks).withTags(tags).build());
});
}, 2, TimeUnit.SECONDS);
ex.schedule(() -> {
Set<Tag> tags = new HashSet<Tag>();
tags.add(TagImpl.of("tag1", "active"));
tags.add(TagImpl.of("tag2", "active"));
Set<Logbook> logbooks = new HashSet<Logbook>();
logbooks.add(LogbookImpl.of("logbook1", "active"));
logbooks.add(LogbookImpl.of("logbook2", "active"));
String path = "C:\\Users\\Kunal Shroff\\Pictures\\screenshot-git\\log-att";
File folder = new File(path);
List<File> listOfFiles = Arrays.asList(folder.listFiles());
runLater(() -> {
LogEntryBuilder lb = LogEntryBuilder.log().createdDate(Instant.now()).description("Fast correctors for the vertical orbit have glitched to near saturation. Archiver shows there have been several episodes the past 24 hrs. Appears that FOFB in vertical plane might have momentary bad BPM reading.").withTags(new HashSet<Tag>(Arrays.asList(TagImpl.of("Orbit", "active"), TagImpl.of("Studies", "active")))).inLogbooks(new HashSet<Logbook>(Arrays.asList(LogbookImpl.of("Operations", "active"))));
listOfFiles.forEach(file -> {
try {
lb.attach(AttachmentImpl.of(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
});
controller.setLogEntry(lb.build());
});
}, 2, TimeUnit.SECONDS);
}
use of org.phoebus.logbook.LogEntry in project phoebus by ControlSystemStudio.
the class PACEInstance method doSaveChanges.
private void doSaveChanges(final JobMonitor monitor) {
final String text = createElogText();
final LogEntryBuilder builder = new LogEntryBuilder();
builder.title(MessageFormat.format(Messages.ELogTitleFmt, model.getTitle()));
builder.appendDescription(text);
final LogEntry entry = builder.createdDate(Instant.now()).build();
LogEntryModel logEntryModel = new LogEntryModel(entry);
new LogEntryEditorStage(gui, logEntryModel, logEntry -> {
if (logEntry != null) {
final String user = logEntryModel.getUsername();
try {
// Change PVs
model.saveUserValues(user);
// On success, clear user values
model.clearUserValues();
} catch (Exception ex) {
logger.log(Level.WARNING, "Save failed", ex);
// At least some saves failed, to revert
try {
model.revertOriginalValues();
} catch (Exception ex2) {
// Since saving didn't work, restoral will also fail.
// Hopefully those initial PVs that did get updated will
// also be restored...
logger.log(Level.WARNING, "Restore failed", ex2);
}
ExceptionDetailsErrorDialog.openError(gui, Messages.SaveError, Messages.PVWriteError, ex);
}
}
}).show();
}
Aggregations