Search in sources :

Example 16 with LogEntry

use of org.phoebus.logbook.LogEntry in project phoebus by ControlSystemStudio.

the class LogEntryCalenderDemo method start.

@Override
public void start(Stage primaryStage) throws Exception {
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(this.getClass().getResource("LogEntryCalenderView.fxml"));
    loader.setControllerFactory(clazz -> {
        try {
            if (clazz.isAssignableFrom(LogEntryCalenderViewController.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();
    LogEntryCalenderViewController 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().minusSeconds(i * 60 * 60)).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 17 with LogEntry

use of org.phoebus.logbook.LogEntry in project phoebus by ControlSystemStudio.

the class LogEntryGroupTest method testGetLogEntryGroupProperty1.

@Test
public void testGetLogEntryGroupProperty1() {
    Map<String, String> attributes = new HashMap<>();
    String uuid = UUID.randomUUID().toString();
    attributes.put(LogGroupProperty.ATTRIBUTE_ID, uuid);
    Property logGroupProperty = new OlogProperty(LogGroupProperty.NAME, attributes);
    LogEntry logEntry1 = LogEntryBuilder.log().property(logGroupProperty).description("").build();
    assertTrue(LogGroupProperty.getLogGroupProperty(logEntry1).isPresent());
    logEntry1 = LogEntryBuilder.log().description("").build();
    assertFalse(LogGroupProperty.getLogGroupProperty(logEntry1).isPresent());
    logGroupProperty = new OlogProperty("Some other name", attributes);
    logEntry1 = LogEntryBuilder.log().property(logGroupProperty).description("").build();
    assertFalse(LogGroupProperty.getLogGroupProperty(logEntry1).isPresent());
}
Also used : HashMap(java.util.HashMap) OlogProperty(org.phoebus.olog.es.api.model.OlogProperty) Property(org.phoebus.logbook.Property) OlogProperty(org.phoebus.olog.es.api.model.OlogProperty) LogGroupProperty(org.phoebus.olog.es.api.model.LogGroupProperty) LogEntry(org.phoebus.logbook.LogEntry) Test(org.junit.Test)

Example 18 with LogEntry

use of org.phoebus.logbook.LogEntry in project phoebus by ControlSystemStudio.

the class LogEntryCalenderViewController method refresh.

private void refresh() {
    map = new HashMap<Appointment, LogEntry>();
    map = this.logEntries.stream().collect(Collectors.toMap(new Function<LogEntry, Appointment>() {

        @Override
        public Appointment apply(LogEntry logentry) {
            AppointmentImplLocal appointment = new Agenda.AppointmentImplLocal();
            appointment.withSummary(logentry.getDescription());
            appointment.withDescription(logentry.getDescription());
            appointment.withStartLocalDateTime(LocalDateTime.ofInstant(logentry.getCreatedDate(), ZoneId.systemDefault()));
            appointment.withEndLocalDateTime(LocalDateTime.ofInstant(logentry.getCreatedDate().plusSeconds(2400), ZoneId.systemDefault()));
            List<String> logbookNames = getLogbookNames();
            if (logbookNames != null && !logbookNames.isEmpty()) {
                int index = logbookNames.indexOf(logentry.getLogbooks().iterator().next().getName());
                if (index >= 0 && index <= 22) {
                    appointment.setAppointmentGroup(appointmentGroupMap.get(String.format("group%02d", (index + 1))));
                } else {
                    appointment.setAppointmentGroup(appointmentGroupMap.get(String.format("group%02d", 23)));
                }
            }
            return appointment;
        }
    }, new Function<LogEntry, LogEntry>() {

        @Override
        public LogEntry apply(LogEntry logentry) {
            return logentry;
        }
    }));
    agenda.appointments().clear();
    agenda.appointments().setAll(map.keySet());
}
Also used : Appointment(jfxtras.scene.control.agenda.Agenda.Appointment) AppointmentImplLocal(jfxtras.scene.control.agenda.Agenda.AppointmentImplLocal) AppointmentImplLocal(jfxtras.scene.control.agenda.Agenda.AppointmentImplLocal) Agenda(jfxtras.scene.control.agenda.Agenda) List(java.util.List) LogEntry(org.phoebus.logbook.LogEntry)

Example 19 with LogEntry

use of org.phoebus.logbook.LogEntry in project phoebus by ControlSystemStudio.

the class LogPropertiesEditorDemo method getDummyLogClient.

private LogClient getDummyLogClient() {
    return new LogClient() {

        @Override
        public LogEntry set(LogEntry log) throws LogbookException {
            return null;
        }

        @Override
        public LogEntry getLog(Long logId) {
            return null;
        }

        @Override
        public Collection<Attachment> listAttachments(Long logId) {
            return null;
        }

        @Override
        public List<LogEntry> findLogs(Map<String, String> map) {
            return null;
        }

        @Override
        public Collection<LogEntry> listLogs() {
            return null;
        }

        @Override
        public Collection<Property> listProperties() {
            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);
            return Arrays.asList(experimentProperty);
        }
    };
}
Also used : LogClient(org.phoebus.logbook.LogClient) Attachment(org.phoebus.logbook.Attachment) Property(org.phoebus.logbook.Property) LogEntry(org.phoebus.logbook.LogEntry)

Example 20 with LogEntry

use of org.phoebus.logbook.LogEntry in project phoebus by ControlSystemStudio.

the class LogEntryCalenderViewController method refresh.

private void refresh() {
    map = new HashMap<Appointment, LogEntry>();
    map = this.logEntries.stream().collect(Collectors.toMap(new Function<LogEntry, Appointment>() {

        @Override
        public Appointment apply(LogEntry logentry) {
            AppointmentImplLocal appointment = new Agenda.AppointmentImplLocal();
            appointment.withSummary(logentry.getDescription());
            appointment.withDescription(logentry.getDescription());
            appointment.withStartLocalDateTime(LocalDateTime.ofInstant(logentry.getCreatedDate(), ZoneId.systemDefault()));
            appointment.withEndLocalDateTime(LocalDateTime.ofInstant(logentry.getCreatedDate().plusSeconds(2400), ZoneId.systemDefault()));
            List<String> logbookNames = getLogbookNames();
            if (logbookNames != null && !logbookNames.isEmpty()) {
                int index = logbookNames.indexOf(logentry.getLogbooks().iterator().next().getName());
                if (index >= 0 && index <= 22) {
                    appointment.setAppointmentGroup(appointmentGroupMap.get(String.format("group%02d", (index + 1))));
                } else {
                    appointment.setAppointmentGroup(appointmentGroupMap.get(String.format("group%02d", 23)));
                }
            }
            return appointment;
        }
    }, new Function<LogEntry, LogEntry>() {

        @Override
        public LogEntry apply(LogEntry logentry) {
            return logentry;
        }
    }));
    Platform.runLater(() -> {
        agenda.appointments().clear();
        agenda.appointments().setAll(map.keySet());
    });
}
Also used : Appointment(jfxtras.scene.control.agenda.Agenda.Appointment) AppointmentImplLocal(jfxtras.scene.control.agenda.Agenda.AppointmentImplLocal) AppointmentImplLocal(jfxtras.scene.control.agenda.Agenda.AppointmentImplLocal) Agenda(jfxtras.scene.control.agenda.Agenda) List(java.util.List) ObservableList(javafx.collections.ObservableList) LogEntry(org.phoebus.logbook.LogEntry)

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