Search in sources :

Example 1 with OlogAttachment

use of org.phoebus.olog.es.api.model.OlogAttachment in project phoebus by ControlSystemStudio.

the class LogEntryDisplayDemo method start.

@Override
public void start(Stage primaryStage) throws Exception {
    primaryStage.setTitle("LogEntry Display demo");
    BorderPane root;
    ResourceBundle resourceBundle = NLS.getMessages(Messages.class);
    FXMLLoader loader = new FXMLLoader();
    loader.setResources(resourceBundle);
    loader.setLocation(this.getClass().getResource("LogEntryDisplay.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());
            } else if (clazz.isAssignableFrom(LogPropertiesController.class)) {
                return clazz.getConstructor().newInstance();
            } else if (clazz.isAssignableFrom(AttachmentsPreviewController.class)) {
                return clazz.getConstructor().newInstance();
            } else if (clazz.isAssignableFrom(LogEntryCellController.class)) {
                return clazz.getConstructor().newInstance();
            } else if (clazz.isAssignableFrom(LogEntryDisplayController.class)) {
                return clazz.getConstructor(LogClient.class).newInstance(getLogClient());
            } else if (clazz.isAssignableFrom(MergedLogEntryDisplayController.class)) {
                return clazz.getConstructor(LogClient.class).newInstance(getLogClient());
            } else if (clazz.isAssignableFrom(SingleLogEntryDisplayController.class)) {
                return clazz.getConstructor(LogClient.class).newInstance(getLogClient());
            } else {
                throw new RuntimeException("No controller for class " + clazz.getName());
            }
        } catch (Exception e) {
            Logger.getLogger(LogEntryEditorStage.class.getName()).log(Level.SEVERE, "Failed to construct controller for log calendar view", e);
        }
        return null;
    });
    loader.load();
    LogEntryDisplayController 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(() -> {
        OlogLog ologLog = new OlogLog(1L);
        ologLog.setDescription("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.");
        ologLog.setCreatedDate(Instant.now());
        runLater(() -> {
            controller.setLogEntry(ologLog);
        });
    }, 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"));
        LogEntry logEntry = controller.getLogEntry();
        runLater(() -> {
            OlogLog anotherLog = new OlogLog(2L);
            anotherLog.setDescription(controller.getLogEntry().getDescription());
            anotherLog.setCreatedDate(controller.getLogEntry().getCreatedDate());
            anotherLog.setTags(tags);
            anotherLog.setLogbooks(logbooks);
            controller.setLogEntry(anotherLog);
        });
    }, 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"));
        Map<String, String> tracAttributes = new HashMap<>();
        tracAttributes.put("id", "1234");
        tracAttributes.put("URL", "https://trac.epics.org/tickets/1234");
        Property track = PropertyImpl.of("Track", tracAttributes);
        Map<String, String> experimentAttributes = new HashMap<>();
        experimentAttributes.put("id", "1234");
        experimentAttributes.put("type", "XPD xray diffraction");
        experimentAttributes.put("scan-id", "6789");
        Property experimentProperty = PropertyImpl.of("Experiment", experimentAttributes);
        runLater(() -> {
            OlogLog ologLog = new OlogLog(3L);
            ologLog.setCreatedDate(Instant.now());
            ologLog.setTitle("A report on the orbit studies");
            ologLog.setDescription("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.");
            ologLog.setTags(new HashSet(Arrays.asList(TagImpl.of("Orbit", "active"), TagImpl.of("Studies", "active"))));
            ologLog.setLogbooks(new HashSet(Arrays.asList(LogbookImpl.of("Operations", "active"))));
            ologLog.setProperties(Arrays.asList(track, experimentProperty));
            List<Attachment> attachments = new ArrayList<>();
            OlogAttachment attachment1 = new OlogAttachment("image_1.png");
            attachment1.setFileName("image_1.png");
            attachment1.setContentType("image");
            OlogAttachment attachment2 = new OlogAttachment("file_phoebus.txt");
            attachment2.setFileName("file_phoebus.txt");
            attachment2.setContentType("text");
            attachments.add(attachment1);
            attachments.add(attachment2);
            ologLog.setAttachments(attachments);
            controller.setLogEntry(ologLog);
        });
    }, 2, TimeUnit.SECONDS);
}
Also used : BorderPane(javafx.scene.layout.BorderPane) LogClient(org.phoebus.logbook.LogClient) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OlogAttachment(org.phoebus.olog.es.api.model.OlogAttachment) Attachment(org.phoebus.logbook.Attachment) OlogLog(org.phoebus.olog.es.api.model.OlogLog) FXMLLoader(javafx.fxml.FXMLLoader) Logbook(org.phoebus.logbook.Logbook) OlogAttachment(org.phoebus.olog.es.api.model.OlogAttachment) Property(org.phoebus.logbook.Property) LogEntry(org.phoebus.logbook.LogEntry) HashSet(java.util.HashSet) LogEntryEditorStage(org.phoebus.logbook.olog.ui.write.LogEntryEditorStage) Scene(javafx.scene.Scene) LogbookException(org.phoebus.logbook.LogbookException) ResourceBundle(java.util.ResourceBundle) Tag(org.phoebus.logbook.Tag)

Example 2 with OlogAttachment

use of org.phoebus.olog.es.api.model.OlogAttachment in project phoebus by ControlSystemStudio.

the class AttachmentsViewController method addFiles.

private void addFiles(List<File> files) {
    MimetypesFileTypeMap fileTypeMap = new MimetypesFileTypeMap();
    for (File file : files) {
        OlogAttachment ologAttachment = new OlogAttachment();
        ologAttachment.setFile(file);
        ologAttachment.setFileName(file.getName());
        String mimeType = fileTypeMap.getContentType(file.getName());
        if (mimeType.startsWith("image")) {
            ologAttachment.setContentType("image");
        } else {
            ologAttachment.setContentType("file");
        }
        attachments.add(ologAttachment);
    }
}
Also used : MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) OlogAttachment(org.phoebus.olog.es.api.model.OlogAttachment) File(java.io.File)

Example 3 with OlogAttachment

use of org.phoebus.olog.es.api.model.OlogAttachment 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)));
    });
}
Also used : Button(javafx.scene.control.Button) LogEntry(org.phoebus.logbook.LogEntry) OlogAttachment(org.phoebus.olog.es.api.model.OlogAttachment) WebEngine(javafx.scene.web.WebEngine) JobManager(org.phoebus.framework.jobs.JobManager) Arrays(java.util.Arrays) FXCollections(javafx.collections.FXCollections) VBox(javafx.scene.layout.VBox) StandardCopyOption(java.nio.file.StandardCopyOption) Level(java.util.logging.Level) Property(org.phoebus.logbook.Property) Attachment(org.phoebus.logbook.Attachment) Path(java.nio.file.Path) LogbookException(org.phoebus.logbook.LogbookException) SECONDS_FORMAT(org.phoebus.util.time.TimestampFormats.SECONDS_FORMAT) WebView(javafx.scene.web.WebView) Logbook(org.phoebus.logbook.Logbook) ImageCache(org.phoebus.ui.javafx.ImageCache) Label(javafx.scene.control.Label) TitledPane(javafx.scene.control.TitledPane) Files(java.nio.file.Files) Collection(java.util.Collection) Tag(org.phoebus.logbook.Tag) IOException(java.io.IOException) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) List(java.util.List) Clipboard(javafx.scene.input.Clipboard) ImageView(javafx.scene.image.ImageView) ObservableList(javafx.collections.ObservableList) ClipboardContent(javafx.scene.input.ClipboardContent) OlogLog(org.phoebus.olog.es.api.model.OlogLog) Image(javafx.scene.image.Image) LogClient(org.phoebus.logbook.LogClient) Path(java.nio.file.Path) OlogAttachment(org.phoebus.olog.es.api.model.OlogAttachment) OlogAttachment(org.phoebus.olog.es.api.model.OlogAttachment) Attachment(org.phoebus.logbook.Attachment)

Example 4 with OlogAttachment

use of org.phoebus.olog.es.api.model.OlogAttachment in project phoebus by ControlSystemStudio.

the class AttachmentsViewController method addImage.

private void addImage(Image image, String id) {
    try {
        File imageFile = new File(System.getProperty("java.io.tmpdir"), id + ".png");
        imageFile.deleteOnExit();
        ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", imageFile);
        OlogAttachment ologAttachment = new OlogAttachment(id);
        ologAttachment.setContentType("image");
        ologAttachment.setFile(imageFile);
        ologAttachment.setFileName(imageFile.getName());
        attachments.add(ologAttachment);
        attachmentsToDelete.add(ologAttachment);
    } catch (IOException e) {
        Logger.getLogger(AttachmentsViewController.class.getName()).log(Level.INFO, "Unable to create temp file from clipboard image or embedded image", e);
    }
}
Also used : OlogAttachment(org.phoebus.olog.es.api.model.OlogAttachment) IOException(java.io.IOException) File(java.io.File)

Aggregations

OlogAttachment (org.phoebus.olog.es.api.model.OlogAttachment)4 File (java.io.File)2 IOException (java.io.IOException)2 Attachment (org.phoebus.logbook.Attachment)2 LogClient (org.phoebus.logbook.LogClient)2 LogEntry (org.phoebus.logbook.LogEntry)2 Logbook (org.phoebus.logbook.Logbook)2 LogbookException (org.phoebus.logbook.LogbookException)2 Property (org.phoebus.logbook.Property)2 Tag (org.phoebus.logbook.Tag)2 OlogLog (org.phoebus.olog.es.api.model.OlogLog)2 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 StandardCopyOption (java.nio.file.StandardCopyOption)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1