use of org.phoebus.logbook.LogEntry in project phoebus by ControlSystemStudio.
the class LogEntryTableDemo method start.
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(this.getClass().getResource("LogEntryTableView.fxml"));
loader.setControllerFactory(clazz -> {
try {
if (clazz.isAssignableFrom(LogEntryTableViewController.class)) {
return clazz.getConstructor(LogClient.class).newInstance(getLogClient());
} else if (clazz.isAssignableFrom(AdvancedSearchViewController.class)) {
return clazz.getConstructor(LogClient.class).newInstance(getLogClient());
}
} catch (Exception e) {
Logger.getLogger(LogEntryEditorStage.class.getName()).log(Level.SEVERE, "Failed to construct controller for log calendar view", e);
}
return null;
});
loader.load();
LogEntryTableViewController controller = loader.getController();
Parent root = loader.getRoot();
primaryStage.setScene(new Scene(root, 400, 400));
primaryStage.show();
List<LogEntry> logs = new ArrayList<LogEntry>();
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"));
File imageFile = new File(this.getClass().getClassLoader().getResource("image_1.png").toURI());
File textFile = new File(this.getClass().getClassLoader().getResource("file_phoebus.txt").toURI());
List<File> listOfFiles = Arrays.asList(imageFile, textFile);
for (int i = 0; i < 10; i++) {
LogEntryBuilder lb = LogEntryBuilder.log().owner("Owner").title("log " + i).description("First line for log " + i).createdDate(Instant.now()).inLogbooks(logbooks).withTags(tags);
StringBuilder sb = new StringBuilder();
for (int j = 0; j < i; j++) {
sb.append("Some additional log text");
}
lb.appendDescription(sb.toString());
listOfFiles.forEach(file -> {
try {
lb.attach(AttachmentImpl.of(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
});
logs.add(lb.build());
}
controller.setLogs(logs);
}
use of org.phoebus.logbook.LogEntry in project phoebus by ControlSystemStudio.
the class LogEntryEditorController method submit.
@FXML
public void submit() {
submissionInProgress.set(true);
JobManager.schedule("Submit Log Entry", monitor -> {
OlogLog ologLog = new OlogLog();
ologLog.setTitle(fieldsViewController.getTitle());
ologLog.setDescription(fieldsViewController.getDescription());
ologLog.setLevel(fieldsViewController.getSelectedLevel());
ologLog.setLogbooks(fieldsViewController.getSelectedLogbooks());
ologLog.setTags(fieldsViewController.getSelectedTags());
ologLog.setAttachments(attachmentsViewController.getAttachments());
ologLog.setProperties(logPropertiesEditorController.getProperties());
LogClient logClient = logFactory.getLogClient(new SimpleAuthenticationToken(fieldsViewController.getUsernameProperty(), fieldsViewController.getPasswordProperty()));
LogEntry result;
try {
if (replyTo == null) {
result = logClient.set(ologLog);
} else {
result = logClient.reply(ologLog, replyTo);
}
if (result != null) {
if (completionHandler != null) {
completionHandler.handleResult(result);
}
// Set username and password in secure store if submission of log entry completes successfully
if (LogbookUIPreferences.save_credentials) {
// Get the SecureStore. Store username and password.
try {
SecureStore store = new SecureStore();
ScopedAuthenticationToken scopedAuthenticationToken = new ScopedAuthenticationToken(LogService.AUTHENTICATION_SCOPE, fieldsViewController.getUsernameProperty(), fieldsViewController.getPasswordProperty());
store.setScopedAuthentication(scopedAuthenticationToken);
} catch (Exception ex) {
logger.log(Level.WARNING, "Secure Store file not found.", ex);
}
}
attachmentsViewController.deleteTemporaryFiles();
// This will close the editor
Platform.runLater(() -> cancel());
}
} catch (LogbookException e) {
logger.log(Level.WARNING, "Unable to submit log entry", e);
Platform.runLater(() -> {
if (e.getCause() != null && e.getCause().getMessage() != null) {
completionMessageLabel.textProperty().setValue(e.getCause().getMessage());
} else if (e.getMessage() != null) {
completionMessageLabel.textProperty().setValue(e.getMessage());
} else {
completionMessageLabel.textProperty().setValue(org.phoebus.logbook.Messages.SubmissionFailed);
}
});
}
submissionInProgress.set(false);
});
}
use of org.phoebus.logbook.LogEntry in project phoebus by ControlSystemStudio.
the class LogEntryEditorController method submit.
/**
* Handler for the Submit button
*/
@FXML
public void submit() {
progressIndicatorVisibility.setValue(true);
completionMessageLabel.textProperty().setValue("");
model.setImages(attachmentsViewController.getImages());
model.setFiles(attachmentsViewController.getFiles());
try {
Future<LogEntry> future = executorService.submit(() -> model.submitEntry());
LogEntry result = future.get();
if (result != null) {
if (completionHandler != null) {
completionHandler.handleResult(result);
}
cancel();
}
} catch (InterruptedException e) {
logger.log(Level.WARNING, "Unable to submit log entry", e);
completionMessageLabel.textProperty().setValue(org.phoebus.logbook.Messages.SubmissionFailed);
} catch (ExecutionException e) {
logger.log(Level.WARNING, "Unable to submit log entry", e);
if (e.getCause() != null && e.getCause().getMessage() != null) {
completionMessageLabel.textProperty().setValue(e.getCause().getMessage());
} else if (e.getMessage() != null) {
completionMessageLabel.textProperty().setValue(e.getMessage());
} else {
completionMessageLabel.textProperty().setValue(org.phoebus.logbook.Messages.SubmissionFailed);
}
} finally {
progressIndicatorVisibility.setValue(false);
}
}
use of org.phoebus.logbook.LogEntry in project phoebus by ControlSystemStudio.
the class LogEntryModel method submitEntry.
/**
* Create and return a log entry with the current data in the log entry form.
* NOTE: this method calls the remote service in a synchronous manner. Calling code should handle potential
* threading issues, e.g. invoking this method on the UI thread. Using a synchronous approach facilitates
* handling of connection or authentication issues.
*
* @throws IOException
*/
public LogEntry submitEntry() throws Exception {
// Create a log entry with the form data.
LogEntryBuilder logEntryBuilder = new LogEntryBuilder();
logEntryBuilder.title(title).description(text).level(level);
for (String selectedLogbook : selectedLogbooks) logEntryBuilder.appendToLogbook(LogbookImpl.of(selectedLogbook));
for (String selectedTag : selectedTags) logEntryBuilder.appendTag(TagImpl.of(selectedTag));
// List of temporary image files to delete.
List<File> toDelete = new ArrayList<>();
// Add Images
for (Image image : images) {
File imageFile = File.createTempFile("log_entry_image_", ".png");
imageFile.deleteOnExit();
toDelete.add(imageFile);
ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", imageFile);
logEntryBuilder.attach(AttachmentImpl.of(imageFile, "image", false));
}
// Add Files
for (File file : files) {
logEntryBuilder.attach(AttachmentImpl.of(file, "file", false));
}
LogEntry logEntry = logEntryBuilder.build();
if (LogbookUiPreferences.save_credentials) {
// Get the SecureStore. Store username and password.
try {
SecureStore store = new SecureStore();
store.set(SecureStore.USERNAME_TAG, username);
store.set(SecureStore.PASSWORD_TAG, password);
} catch (Exception ex) {
logger.log(Level.WARNING, "Secure Store file not found.", ex);
}
}
LogEntry result = null;
if (null != logFactory)
result = logFactory.getLogClient(new SimpleAuthenticationToken(username, password)).set(logEntry);
// Delete the temporary files.
for (File file : toDelete) file.delete();
// Run the onSubmitAction runnable
if (null != onSubmitAction)
onSubmitAction.run();
return result;
}
use of org.phoebus.logbook.LogEntry in project phoebus by ControlSystemStudio.
the class LogEntrySearchDemo method start.
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(this.getClass().getResource("LogEntryTableView.fxml"));
loader.setControllerFactory(clazz -> {
try {
if (clazz.isAssignableFrom(LogEntryTableViewController.class)) {
return clazz.getConstructor(LogClient.class).newInstance(getLogClient());
} else if (clazz.isAssignableFrom(AdvancedSearchViewController.class)) {
return clazz.getConstructor(LogClient.class).newInstance(getLogClient());
}
} catch (Exception e) {
Logger.getLogger(LogEntryEditorStage.class.getName()).log(Level.SEVERE, "Failed to construct controller for log calendar view", e);
}
return null;
});
loader.load();
LogEntryTableViewController controller = loader.getController();
Parent root = loader.getRoot();
primaryStage.setScene(new Scene(root, 400, 400));
primaryStage.show();
List<LogEntry> logs = new ArrayList<LogEntry>();
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());
for (int i = 0; i < 10; i++) {
LogEntryBuilder lb = LogEntryBuilder.log().owner("Owner").title("log " + i).description("First line for log " + i).createdDate(Instant.now()).inLogbooks(logbooks).withTags(tags);
StringBuilder sb = new StringBuilder();
for (int j = 0; j < i; j++) {
sb.append("Some additional log text");
}
lb.appendDescription(sb.toString());
listOfFiles.forEach(file -> {
try {
lb.attach(AttachmentImpl.of(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
});
logs.add(lb.build());
}
controller.setLogs(logs);
}
Aggregations