use of org.phoebus.logbook.LogEntryImpl.LogEntryBuilder in project phoebus by ControlSystemStudio.
the class InMemoryLogClient method set.
@Override
public LogEntry set(LogEntry log) {
long id = logIdCounter.incrementAndGet();
LogEntryBuilder logBuilder = LogEntryImpl.LogEntryBuilder.log(log);
logBuilder.id(id);
logBuilder.createdDate(Instant.now());
Set<Attachment> attachmentsBuilder = log.getAttachments().stream().map(attachment -> {
try {
File file = attachment.getFile();
int i = file.getName().lastIndexOf(".");
String ext = null;
if (i >= 0) {
ext = file.getName().substring(i);
}
File tempFile = File.createTempFile(prefix, ext);
Files.copy(file, tempFile);
tempFile.deleteOnExit();
String mimeType = URLConnection.guessContentTypeFromName(tempFile.getName());
return AttachmentImpl.of(tempFile, mimeType != null ? mimeType : ext, false);
} catch (IOException e) {
logger.log(Level.WARNING, "failed to get in memory attachment", e);
return null;
}
}).collect(Collectors.toSet());
logBuilder.setAttach(attachmentsBuilder);
LogEntry logEntry = logBuilder.build();
logEntries.put(id, logEntry);
return logEntry;
}
use of org.phoebus.logbook.LogEntryImpl.LogEntryBuilder 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.LogEntryImpl.LogEntryBuilder 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.LogEntryImpl.LogEntryBuilder 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);
}
use of org.phoebus.logbook.LogEntryImpl.LogEntryBuilder in project phoebus by ControlSystemStudio.
the class SendLogbookAction method submitLogEntry.
private void submitLogEntry(final Node parent, final String title, final String body, final File image_file) {
LogEntryBuilder logEntryBuilder = new LogEntryBuilder();
if (title != null)
logEntryBuilder.title(title);
if (body != null)
logEntryBuilder.appendDescription(body);
if (image_file != null) {
try {
final Attachment attachment = AttachmentImpl.of(image_file, "image", false);
logEntryBuilder.attach(attachment);
} catch (FileNotFoundException ex) {
logger.log(Level.WARNING, "Cannot attach " + image_file, ex);
}
}
final LogEntryModel model = new LogEntryModel(logEntryBuilder.createdDate(Instant.now()).build());
new LogEntryEditorStage(parent, model, null).show();
}
Aggregations