Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.phoebus.logbook.LogClient;
import org.phoebus.logbook.LogEntry;
import org.phoebus.logbook.LogEntryChangeHandler;
import org.phoebus.logbook.LogTemplate;
import org.phoebus.logbook.Logbook;
import org.phoebus.logbook.LogbookException;
import org.phoebus.logbook.Messages;
Expand All @@ -43,6 +44,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.http.HttpHeaders;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -562,4 +564,36 @@ public SearchResult getArchivedEntries(long id){
throw new RuntimeException(e);
}
}

@Override
public Collection<LogTemplate> getTemplates(){
try {
return OlogObjectMappers.logEntryDeserializer.readValue(
service.path("templates").accept(MediaType.APPLICATION_JSON).get(String.class),
new TypeReference<List<LogTemplate>>() {
});
} catch (UniformInterfaceException | ClientHandlerException | IOException e) {
logger.log(Level.WARNING, "Unable to get templates from service", e);
return Collections.emptySet();
}
}

@Override
public LogTemplate saveTemplate(LogTemplate template) throws LogbookException{
ClientResponse clientResponse = service.path("templates").accept(MediaType.APPLICATION_JSON_TYPE)
.header("Content-Type", MediaType.APPLICATION_JSON_TYPE)
.put(ClientResponse.class, template);
if (clientResponse.getStatus() > 300) {
logger.log(Level.SEVERE, "Failed to create template: " + clientResponse);
throw new LogbookException(clientResponse.toString());
}

try {
return OlogObjectMappers.logEntryDeserializer.readValue(clientResponse.getEntityInputStream(), LogTemplate.class);
} catch (IOException e) {
logger.log(Level.SEVERE, "Failed to submit template, got client exception", e);
throw new LogbookException(e);
}

}
}
5 changes: 5 additions & 0 deletions app/logbook/olog/ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<artifactId>core-security</artifactId>
<version>4.7.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.phoebus</groupId>
<artifactId>core-ui</artifactId>
<version>4.7.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jfxtras</groupId>
<artifactId>jfxtras-agenda</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import org.phoebus.logbook.LogEntry;
import org.phoebus.logbook.olog.ui.write.EditMode;
import org.phoebus.logbook.olog.ui.write.LogEntryEditorStage;
import org.phoebus.olog.es.api.model.LogGroupProperty;
import org.phoebus.olog.es.api.model.OlogLog;
Expand Down Expand Up @@ -180,13 +181,13 @@ public void jumpToLogEntry() {
public void reply() {
// Show a new editor dialog. When user selects to save the reply entry, update the original log entry
// to ensure that it contains the log group property.
new LogEntryEditorStage(new OlogLog(), logEntryProperty.get(), null).show();
new LogEntryEditorStage(new OlogLog(), logEntryProperty.get(), EditMode.NEW_LOG_ENTRY).show();
}

@FXML
public void newLogEntry(){
// Show a new editor dialog.
new LogEntryEditorStage(new OlogLog(), null, null).show();
new LogEntryEditorStage(new OlogLog(), null, EditMode.NEW_LOG_ENTRY).show();
}

@FXML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
import org.phoebus.logbook.SearchResult;
import org.phoebus.logbook.olog.ui.query.OlogQuery;
import org.phoebus.logbook.olog.ui.query.OlogQueryManager;
import org.phoebus.logbook.olog.ui.write.EditMode;
import org.phoebus.logbook.olog.ui.spi.Decoration;
import org.phoebus.logbook.olog.ui.write.LogEntryEditorStage;
import org.phoebus.logbook.olog.ui.write.LogEntryUpdateStage;
import org.phoebus.olog.es.api.model.LogGroupProperty;
import org.phoebus.olog.es.api.model.OlogLog;
import org.phoebus.security.store.SecureStore;
Expand Down Expand Up @@ -186,12 +186,12 @@ public void initialize() {

MenuItem menuItemNewLogEntry = new MenuItem(Messages.NewLogEntry);
menuItemNewLogEntry.acceleratorProperty().setValue(new KeyCodeCombination(KeyCode.N, KeyCombination.CONTROL_DOWN));
menuItemNewLogEntry.setOnAction(ae -> new LogEntryEditorStage(new OlogLog(), null, null).show());
menuItemNewLogEntry.setOnAction(ae -> new LogEntryEditorStage(new OlogLog(), null, EditMode.NEW_LOG_ENTRY).showAndWait());

MenuItem menuItemUpdateLogEntry = new MenuItem(Messages.UpdateLogEntry);
menuItemUpdateLogEntry.visibleProperty().bind(Bindings.createBooleanBinding(() -> selectedLogEntries.size() == 1, selectedLogEntries));
menuItemUpdateLogEntry.acceleratorProperty().setValue(new KeyCodeCombination(KeyCode.U, KeyCombination.CONTROL_DOWN));
menuItemUpdateLogEntry.setOnAction(ae -> new LogEntryUpdateStage(selectedLogEntries.get(0), null).show());
menuItemUpdateLogEntry.setOnAction(ae -> new LogEntryEditorStage(selectedLogEntries.get(0), null, EditMode.UPDATE_LOG_ENTRY).show());

contextMenu.getItems().addAll(groupSelectedEntries, menuItemShowHideAll, menuItemNewLogEntry);
if (LogbookUIPreferences.log_entry_update_support) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Messages
AttachmentsDirectoryNotWritable,
AttachmentsFileNotDirectory,
AttachmentsNoStorage,
AvailableTemplates,
Back,
CloseRequestHeader,
CloseRequestButtonContinue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.ListChangeListener;
import javafx.embed.swing.SwingFXUtils;
import javafx.fxml.FXML;
Expand Down Expand Up @@ -117,26 +119,31 @@ public class AttachmentsEditorController {
private final SimpleStringProperty sizeLimitsText = new SimpleStringProperty();

/**
* @param logEntry The log entry template potentially holding a set of attachments. Note
* @param logEntry The log entry potentially holding a set of attachments. Note
* that files associated with these attachments are considered temporary and
* are subject to removal when the log entry has been committed.
*/
public AttachmentsEditorController(LogEntry logEntry) {
this.logEntry = logEntry;
// If the log entry has an attachment - e.g. log entry created from display or data browser -
// then add the file size to the total attachments size
Collection<Attachment> attachments = logEntry.getAttachments();
if (attachments != null && !attachments.isEmpty()) {
attachments.forEach(a -> attachedFilesSize += getFileSize(a.getFile()));
}
}

@FXML
public void initialize() {

attachmentsViewController.setAttachments(logEntry.getAttachments());
// If the log entry has an attachment - e.g. log entry created from display or data browser -
// then add the file size to the total attachments size.
Collection<Attachment> attachments = logEntry.getAttachments();
if (attachments != null && !attachments.isEmpty()) {
attachments.forEach(a -> {
if(a.getFile() != null){
attachedFilesSize += getFileSize(a.getFile());
}
});
}

attachmentsViewController.setAttachments(attachments);

filesToDeleteAfterSubmit.addAll(logEntry.getAttachments().stream().map(Attachment::getFile).toList());
filesToDeleteAfterSubmit.addAll(attachments.stream().map(Attachment::getFile).toList());

removeButton.setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/delete.png"));
removeButton.disableProperty().bind(Bindings.isEmpty(attachmentsViewController.getSelectedAttachments()));
Expand Down Expand Up @@ -335,10 +342,19 @@ private void addImage(Image image, String id) {
}
}

public List<Attachment> getAttachments() {
/**
*
* @return The {@link ObservableList} of {@link Attachment}s managed in the {@link AttachmentsViewController}.
*/
public ObservableList<Attachment> getAttachments() {
return attachmentsViewController.getAttachments();
}

/**
* Sets the file upload constraints information in the editor.
* @param maxFileSize Maximum size for a single file.
* @param maxRequestSize Maximum total size of all attachments.
*/
public void setSizeLimits(String maxFileSize, String maxRequestSize) {
this.maxFileSize = Double.parseDouble(maxFileSize);
this.maxRequestSize = Double.parseDouble(maxRequestSize);
Expand Down Expand Up @@ -380,4 +396,11 @@ private void showFileSizeExceedsLimit(File file) {
private void showTotalSizeExceedsLimit() {
Platform.runLater(() -> sizesErrorMessage.set(Messages.RequestTooLarge));
}

/**
* Clears list of {@link Attachment}s.
*/
public void clearAttachments(){
getAttachments().clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void call(Node parent, Selection selection) {
adaptedSelections.add(adapted);
});
});
new LogEntryEditorStage(adaptedSelections.get(0), null, null).show();
new LogEntryEditorStage(adaptedSelections.get(0), null, EditMode.NEW_LOG_ENTRY).show();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (C) 2024 European Spallation Source ERIC.
*/

package org.phoebus.logbook.olog.ui.write;

public enum EditMode {

NEW_LOG_ENTRY,
UPDATE_LOG_ENTRY
}

This file was deleted.

Loading
Loading