Search in sources :

Example 1 with LogEntry

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);
}
Also used : LogClient(org.phoebus.logbook.LogClient) Parent(javafx.scene.Parent) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) LogEntryEditorStage(org.phoebus.logbook.ui.write.LogEntryEditorStage) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) LogbookException(org.phoebus.logbook.LogbookException) FileNotFoundException(java.io.FileNotFoundException) Logbook(org.phoebus.logbook.Logbook) LogEntryBuilder(org.phoebus.logbook.LogEntryImpl.LogEntryBuilder) Tag(org.phoebus.logbook.Tag) File(java.io.File) LogEntry(org.phoebus.logbook.LogEntry) HashSet(java.util.HashSet)

Example 2 with LogEntry

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);
    });
}
Also used : LogClient(org.phoebus.logbook.LogClient) ScopedAuthenticationToken(org.phoebus.security.tokens.ScopedAuthenticationToken) LogbookException(org.phoebus.logbook.LogbookException) OlogLog(org.phoebus.olog.es.api.model.OlogLog) SecureStore(org.phoebus.security.store.SecureStore) LogEntry(org.phoebus.logbook.LogEntry) LogbookException(org.phoebus.logbook.LogbookException) ExecutionException(java.util.concurrent.ExecutionException) SimpleAuthenticationToken(org.phoebus.security.tokens.SimpleAuthenticationToken) FXML(javafx.fxml.FXML)

Example 3 with LogEntry

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);
    }
}
Also used : ExecutionException(java.util.concurrent.ExecutionException) LogEntry(org.phoebus.logbook.LogEntry) FXML(javafx.fxml.FXML)

Example 4 with LogEntry

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;
}
Also used : ArrayList(java.util.ArrayList) LogEntryBuilder(org.phoebus.logbook.LogEntryImpl.LogEntryBuilder) Image(javafx.scene.image.Image) File(java.io.File) SecureStore(org.phoebus.security.store.SecureStore) LogEntry(org.phoebus.logbook.LogEntry) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SimpleAuthenticationToken(org.phoebus.security.tokens.SimpleAuthenticationToken)

Example 5 with LogEntry

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);
}
Also used : LogClient(org.phoebus.logbook.LogClient) Parent(javafx.scene.Parent) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) LogEntryEditorStage(org.phoebus.logbook.ui.write.LogEntryEditorStage) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) LogbookException(org.phoebus.logbook.LogbookException) FileNotFoundException(java.io.FileNotFoundException) Logbook(org.phoebus.logbook.Logbook) LogEntryBuilder(org.phoebus.logbook.LogEntryImpl.LogEntryBuilder) Tag(org.phoebus.logbook.Tag) File(java.io.File) LogEntry(org.phoebus.logbook.LogEntry) HashSet(java.util.HashSet)

Aggregations

LogEntry (org.phoebus.logbook.LogEntry)23 LogClient (org.phoebus.logbook.LogClient)12 Logbook (org.phoebus.logbook.Logbook)12 Tag (org.phoebus.logbook.Tag)12 FXMLLoader (javafx.fxml.FXMLLoader)11 LogEntryBuilder (org.phoebus.logbook.LogEntryImpl.LogEntryBuilder)10 File (java.io.File)9 FileNotFoundException (java.io.FileNotFoundException)9 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9 Scene (javafx.scene.Scene)9 LogbookException (org.phoebus.logbook.LogbookException)9 FXML (javafx.fxml.FXML)7 Parent (javafx.scene.Parent)6 Property (org.phoebus.logbook.Property)6 IOException (java.io.IOException)5 List (java.util.List)5 HashMap (java.util.HashMap)4 Level (java.util.logging.Level)4 ObservableList (javafx.collections.ObservableList)4