Skip to content

Commit 1409ed5

Browse files
authored
Merge pull request #3202 from ControlSystemStudio/CSSTUDIO-1257
Support for Olog templates
2 parents 9c0f55d + 1cf069e commit 1409ed5

File tree

28 files changed

+535
-1248
lines changed

28 files changed

+535
-1248
lines changed

app/logbook/olog/client-es/src/main/java/org/phoebus/olog/es/api/OlogClient.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.phoebus.logbook.LogClient;
2121
import org.phoebus.logbook.LogEntry;
2222
import org.phoebus.logbook.LogEntryChangeHandler;
23+
import org.phoebus.logbook.LogTemplate;
2324
import org.phoebus.logbook.Logbook;
2425
import org.phoebus.logbook.LogbookException;
2526
import org.phoebus.logbook.Messages;
@@ -43,6 +44,7 @@
4344
import java.io.IOException;
4445
import java.io.InputStream;
4546
import java.net.URI;
47+
import java.net.http.HttpHeaders;
4648
import java.util.ArrayList;
4749
import java.util.Arrays;
4850
import java.util.Collection;
@@ -562,4 +564,36 @@ public SearchResult getArchivedEntries(long id){
562564
throw new RuntimeException(e);
563565
}
564566
}
567+
568+
@Override
569+
public Collection<LogTemplate> getTemplates(){
570+
try {
571+
return OlogObjectMappers.logEntryDeserializer.readValue(
572+
service.path("templates").accept(MediaType.APPLICATION_JSON).get(String.class),
573+
new TypeReference<List<LogTemplate>>() {
574+
});
575+
} catch (UniformInterfaceException | ClientHandlerException | IOException e) {
576+
logger.log(Level.WARNING, "Unable to get templates from service", e);
577+
return Collections.emptySet();
578+
}
579+
}
580+
581+
@Override
582+
public LogTemplate saveTemplate(LogTemplate template) throws LogbookException{
583+
ClientResponse clientResponse = service.path("templates").accept(MediaType.APPLICATION_JSON_TYPE)
584+
.header("Content-Type", MediaType.APPLICATION_JSON_TYPE)
585+
.put(ClientResponse.class, template);
586+
if (clientResponse.getStatus() > 300) {
587+
logger.log(Level.SEVERE, "Failed to create template: " + clientResponse);
588+
throw new LogbookException(clientResponse.toString());
589+
}
590+
591+
try {
592+
return OlogObjectMappers.logEntryDeserializer.readValue(clientResponse.getEntityInputStream(), LogTemplate.class);
593+
} catch (IOException e) {
594+
logger.log(Level.SEVERE, "Failed to submit template, got client exception", e);
595+
throw new LogbookException(e);
596+
}
597+
598+
}
565599
}

app/logbook/olog/ui/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
<artifactId>core-security</artifactId>
4141
<version>4.7.4-SNAPSHOT</version>
4242
</dependency>
43+
<dependency>
44+
<groupId>org.phoebus</groupId>
45+
<artifactId>core-ui</artifactId>
46+
<version>4.7.4-SNAPSHOT</version>
47+
</dependency>
4348
<dependency>
4449
<groupId>org.jfxtras</groupId>
4550
<artifactId>jfxtras-agenda</artifactId>

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryDisplayController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import javafx.scene.layout.Priority;
3737
import javafx.scene.layout.Region;
3838
import org.phoebus.logbook.LogEntry;
39+
import org.phoebus.logbook.olog.ui.write.EditMode;
3940
import org.phoebus.logbook.olog.ui.write.LogEntryEditorStage;
4041
import org.phoebus.olog.es.api.model.LogGroupProperty;
4142
import org.phoebus.olog.es.api.model.OlogLog;
@@ -180,13 +181,13 @@ public void jumpToLogEntry() {
180181
public void reply() {
181182
// Show a new editor dialog. When user selects to save the reply entry, update the original log entry
182183
// to ensure that it contains the log group property.
183-
new LogEntryEditorStage(new OlogLog(), logEntryProperty.get(), null).show();
184+
new LogEntryEditorStage(new OlogLog(), logEntryProperty.get(), EditMode.NEW_LOG_ENTRY).show();
184185
}
185186

186187
@FXML
187188
public void newLogEntry(){
188189
// Show a new editor dialog.
189-
new LogEntryEditorStage(new OlogLog(), null, null).show();
190+
new LogEntryEditorStage(new OlogLog(), null, EditMode.NEW_LOG_ENTRY).show();
190191
}
191192

192193
@FXML

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryTableViewController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
import org.phoebus.logbook.SearchResult;
4949
import org.phoebus.logbook.olog.ui.query.OlogQuery;
5050
import org.phoebus.logbook.olog.ui.query.OlogQueryManager;
51+
import org.phoebus.logbook.olog.ui.write.EditMode;
5152
import org.phoebus.logbook.olog.ui.spi.Decoration;
5253
import org.phoebus.logbook.olog.ui.write.LogEntryEditorStage;
53-
import org.phoebus.logbook.olog.ui.write.LogEntryUpdateStage;
5454
import org.phoebus.olog.es.api.model.LogGroupProperty;
5555
import org.phoebus.olog.es.api.model.OlogLog;
5656
import org.phoebus.security.store.SecureStore;
@@ -186,12 +186,12 @@ public void initialize() {
186186

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

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

196196
contextMenu.getItems().addAll(groupSelectedEntries, menuItemShowHideAll, menuItemNewLogEntry);
197197
if (LogbookUIPreferences.log_entry_update_support) {

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class Messages
2323
AttachmentsDirectoryNotWritable,
2424
AttachmentsFileNotDirectory,
2525
AttachmentsNoStorage,
26+
AvailableTemplates,
2627
Back,
2728
CloseRequestHeader,
2829
CloseRequestButtonContinue,

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/AttachmentsEditorController.java

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import javafx.beans.binding.Bindings;
2424
import javafx.beans.property.SimpleBooleanProperty;
2525
import javafx.beans.property.SimpleStringProperty;
26+
import javafx.collections.FXCollections;
27+
import javafx.collections.ObservableList;
2628
import javafx.collections.ListChangeListener;
2729
import javafx.embed.swing.SwingFXUtils;
2830
import javafx.fxml.FXML;
@@ -117,26 +119,31 @@ public class AttachmentsEditorController {
117119
private final SimpleStringProperty sizeLimitsText = new SimpleStringProperty();
118120

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

134130
@FXML
135131
public void initialize() {
136132

137-
attachmentsViewController.setAttachments(logEntry.getAttachments());
133+
// If the log entry has an attachment - e.g. log entry created from display or data browser -
134+
// then add the file size to the total attachments size.
135+
Collection<Attachment> attachments = logEntry.getAttachments();
136+
if (attachments != null && !attachments.isEmpty()) {
137+
attachments.forEach(a -> {
138+
if(a.getFile() != null){
139+
attachedFilesSize += getFileSize(a.getFile());
140+
}
141+
});
142+
}
143+
144+
attachmentsViewController.setAttachments(attachments);
138145

139-
filesToDeleteAfterSubmit.addAll(logEntry.getAttachments().stream().map(Attachment::getFile).toList());
146+
filesToDeleteAfterSubmit.addAll(attachments.stream().map(Attachment::getFile).toList());
140147

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

338-
public List<Attachment> getAttachments() {
345+
/**
346+
*
347+
* @return The {@link ObservableList} of {@link Attachment}s managed in the {@link AttachmentsViewController}.
348+
*/
349+
public ObservableList<Attachment> getAttachments() {
339350
return attachmentsViewController.getAttachments();
340351
}
341352

353+
/**
354+
* Sets the file upload constraints information in the editor.
355+
* @param maxFileSize Maximum size for a single file.
356+
* @param maxRequestSize Maximum total size of all attachments.
357+
*/
342358
public void setSizeLimits(String maxFileSize, String maxRequestSize) {
343359
this.maxFileSize = Double.parseDouble(maxFileSize);
344360
this.maxRequestSize = Double.parseDouble(maxRequestSize);
@@ -380,4 +396,11 @@ private void showFileSizeExceedsLimit(File file) {
380396
private void showTotalSizeExceedsLimit() {
381397
Platform.runLater(() -> sizesErrorMessage.set(Messages.RequestTooLarge));
382398
}
399+
400+
/**
401+
* Clears list of {@link Attachment}s.
402+
*/
403+
public void clearAttachments(){
404+
getAttachments().clear();
405+
}
383406
}

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/ContextMenuLogging.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void call(Node parent, Selection selection) {
4444
adaptedSelections.add(adapted);
4545
});
4646
});
47-
new LogEntryEditorStage(adaptedSelections.get(0), null, null).show();
47+
new LogEntryEditorStage(adaptedSelections.get(0), null, EditMode.NEW_LOG_ENTRY).show();
4848
}
4949

5050
@Override
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (C) 2024 European Spallation Source ERIC.
3+
*/
4+
5+
package org.phoebus.logbook.olog.ui.write;
6+
7+
public enum EditMode {
8+
9+
NEW_LOG_ENTRY,
10+
UPDATE_LOG_ENTRY
11+
}

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryCompletionHandler.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)