Skip to content

Commit f027add

Browse files
authored
Merge pull request #2299 from ControlSystemStudio/CSSTUIDO-1703
Better error message on Olog search failure
2 parents ed63eb7 + 448f17a commit f027add

File tree

6 files changed

+63
-80
lines changed

6 files changed

+63
-80
lines changed

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

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import java.util.Map;
4747
import java.util.logging.Level;
4848
import java.util.logging.Logger;
49-
import java.util.stream.Collectors;
5049

5150
/**
5251
* A client to the Olog-es webservice
@@ -68,20 +67,20 @@ public class OlogClient implements LogClient {
6867
*/
6968
public static class OlogClientBuilder {
7069
// required
71-
private URI ologURI = null;
70+
private final URI ologURI;
7271

7372
// optional
7473
private boolean withHTTPAuthentication = true;
7574

7675
private ClientConfig clientConfig = null;
7776
@SuppressWarnings("unused")
7877
private SSLContext sslContext = null;
79-
private String protocol = null;
78+
private final String protocol;
8079
private String username = null;
8180
private String password = null;
8281
private String connectTimeoutAsString = null;
8382

84-
private OlogProperties properties = new OlogProperties();
83+
private final OlogProperties properties = new OlogProperties();
8584

8685
private OlogClientBuilder() {
8786
this.ologURI = URI.create(this.properties.getPreferenceValue("olog_url"));
@@ -92,7 +91,7 @@ private OlogClientBuilder() {
9291
* Creates a {@link OlogClientBuilder} for a CF client to Default URL in the
9392
* channelfinder.properties.
9493
*
95-
* @return
94+
* @return The builder
9695
*/
9796
public static OlogClientBuilder serviceURL() {
9897
return new OlogClientBuilder();
@@ -101,7 +100,7 @@ public static OlogClientBuilder serviceURL() {
101100
/**
102101
* Enable of Disable the HTTP authentication on the client connection.
103102
*
104-
* @param withHTTPAuthentication
103+
* @param withHTTPAuthentication Whether to use authentication or not
105104
* @return {@link OlogClientBuilder}
106105
*/
107106
public OlogClientBuilder withHTTPAuthentication(boolean withHTTPAuthentication) {
@@ -112,7 +111,7 @@ public OlogClientBuilder withHTTPAuthentication(boolean withHTTPAuthentication)
112111
/**
113112
* Set the username to be used for HTTP Authentication.
114113
*
115-
* @param username
114+
* @param username User's identity
116115
* @return {@link OlogClientBuilder}
117116
*/
118117
public OlogClientBuilder username(String username) {
@@ -123,7 +122,7 @@ public OlogClientBuilder username(String username) {
123122
/**
124123
* Set the password to be used for the HTTP Authentication.
125124
*
126-
* @param password
125+
* @param password User's password
127126
* @return {@link OlogClientBuilder}
128127
*/
129128
public OlogClientBuilder password(String password) {
@@ -149,7 +148,7 @@ public OlogClient create() {
149148
this.username = ifNullReturnPreferenceValue(this.username, "username");
150149
this.password = ifNullReturnPreferenceValue(this.password, "password");
151150
this.connectTimeoutAsString = ifNullReturnPreferenceValue(this.connectTimeoutAsString, "connectTimeout");
152-
Integer connectTimeout = 0;
151+
int connectTimeout = 0;
153152
try {
154153
connectTimeout = Integer.parseInt(connectTimeoutAsString);
155154
} catch (NumberFormatException e) {
@@ -216,7 +215,7 @@ private LogEntry save(LogEntry log, LogEntry inReplyTo) throws LogbookException
216215

217216
if (clientResponse.getStatus() < 300) {
218217
OlogLog createdLog = OlogObjectMappers.logEntryDeserializer.readValue(clientResponse.getEntityInputStream(), OlogLog.class);
219-
log.getAttachments().stream().forEach(attachment -> {
218+
log.getAttachments().forEach(attachment -> {
220219
FormDataMultiPart form = new FormDataMultiPart();
221220
// Add id only if it is set, otherwise Jersey will complain and cause the submission to fail.
222221
if (attachment.getId() != null && !attachment.getId().isEmpty()) {
@@ -277,12 +276,11 @@ public LogEntry getLog(Long logId) {
277276
@Override
278277
public LogEntry findLogById(Long logId) {
279278
try {
280-
OlogLog ologLog = OlogObjectMappers.logEntryDeserializer.readValue(
279+
return OlogObjectMappers.logEntryDeserializer.readValue(
281280
service
282281
.path("logs")
283282
.path(logId.toString())
284283
.accept(MediaType.APPLICATION_JSON).get(String.class), OlogLog.class);
285-
return ologLog;
286284
} catch (JsonProcessingException e) {
287285
return null;
288286
}
@@ -300,7 +298,7 @@ public List<LogEntry> findLogs(Map<String, String> map) throws RuntimeException
300298
*
301299
* @param searchParams Map of search parameters/expressions
302300
* @return A list of matching {@link LogEntry}s
303-
* @throws RuntimeException
301+
* @throws RuntimeException If search fails, e.g. due to invalid search parameters
304302
*/
305303
private SearchResult findLogs(MultivaluedMap<String, String> searchParams) throws RuntimeException {
306304
try {
@@ -311,10 +309,15 @@ private SearchResult findLogs(MultivaluedMap<String, String> searchParams) throw
311309
.accept(MediaType.APPLICATION_JSON)
312310
.get(String.class),
313311
OlogSearchResult.class);
314-
return SearchResult.of(ologSearchResult.getLogs().stream().collect(Collectors.toList()),
312+
return SearchResult.of(new ArrayList<>(ologSearchResult.getLogs()),
315313
ologSearchResult.getHitCount());
316314
} catch (UniformInterfaceException | ClientHandlerException | IOException e) {
317315
logger.log(Level.WARNING, "failed to retrieve log entries", e);
316+
if(e instanceof UniformInterfaceException){
317+
if(((UniformInterfaceException) e).getResponse().getStatus() == Status.BAD_REQUEST.getStatusCode()){
318+
throw new RuntimeException(Messages.BadRequestFailure);
319+
}
320+
}
318321
throw new RuntimeException(e);
319322
}
320323
}
@@ -373,8 +376,7 @@ public Collection<String> listAttributes(String propertyName) {
373376

374377
@Override
375378
public List<LogEntry> listLogs() {
376-
List<LogEntry> logEntries = new ArrayList<>();
377-
return logEntries;
379+
return new ArrayList<>();
378380
}
379381

380382
/**
@@ -400,11 +402,10 @@ public Collection<String> listLevels() {
400402
@Override
401403
public Collection<Logbook> listLogbooks() {
402404
try {
403-
List<Logbook> logbooks = OlogObjectMappers.logEntryDeserializer.readValue(
405+
return OlogObjectMappers.logEntryDeserializer.readValue(
404406
service.path("logbooks").accept(MediaType.APPLICATION_JSON).get(String.class),
405407
new TypeReference<List<Logbook>>() {
406408
});
407-
return logbooks;
408409
} catch (UniformInterfaceException | ClientHandlerException | IOException e) {
409410
logger.log(Level.WARNING, "Unable to get logbooks from service", e);
410411
return Collections.emptySet();
@@ -414,11 +415,10 @@ public Collection<Logbook> listLogbooks() {
414415
@Override
415416
public Collection<Property> listProperties() {
416417
try {
417-
List<Property> properties = OlogObjectMappers.logEntryDeserializer.readValue(
418+
return OlogObjectMappers.logEntryDeserializer.readValue(
418419
service.path("properties").accept(MediaType.APPLICATION_JSON).get(String.class),
419420
new TypeReference<List<Property>>() {
420421
});
421-
return properties;
422422
} catch (UniformInterfaceException | ClientHandlerException | IOException e) {
423423
logger.log(Level.WARNING, "failed to list olog properties", e);
424424
return Collections.emptySet();
@@ -428,11 +428,10 @@ public Collection<Property> listProperties() {
428428
@Override
429429
public Collection<Tag> listTags() {
430430
try {
431-
List<Tag> tags = OlogObjectMappers.logEntryDeserializer.readValue(
431+
return OlogObjectMappers.logEntryDeserializer.readValue(
432432
service.path("tags").accept(MediaType.APPLICATION_JSON).get(String.class),
433433
new TypeReference<List<Tag>>() {
434434
});
435-
return tags;
436435
} catch (UniformInterfaceException | ClientHandlerException | IOException e) {
437436
logger.log(Level.WARNING, "failed to retrieve olog tags", e);
438437
return Collections.emptySet();
@@ -449,7 +448,7 @@ public String getServiceUrl() {
449448
}
450449

451450
@Override
452-
public LogEntry updateLogEntry(LogEntry logEntry) throws LogbookException {
451+
public LogEntry updateLogEntry(LogEntry logEntry) {
453452
ClientResponse clientResponse;
454453

455454
try {
@@ -469,9 +468,7 @@ public LogEntry updateLogEntry(LogEntry logEntry) throws LogbookException {
469468
@Override
470469
public SearchResult search(Map<String, String> map) {
471470
MultivaluedMap<String, String> mMap = new MultivaluedMapImpl();
472-
map.forEach((k, v) -> {
473-
mMap.putSingle(k, v);
474-
});
471+
map.forEach(mMap::putSingle);
475472
return findLogs(mMap);
476473
}
477474

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

Lines changed: 36 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import javafx.beans.property.SimpleBooleanProperty;
99
import javafx.beans.property.SimpleIntegerProperty;
1010
import javafx.beans.property.SimpleObjectProperty;
11-
import javafx.beans.value.ChangeListener;
1211
import javafx.collections.FXCollections;
1312
import javafx.collections.ObservableList;
1413
import javafx.css.PseudoClass;
@@ -31,7 +30,6 @@
3130
import javafx.scene.control.TableColumn;
3231
import javafx.scene.control.TableView;
3332
import javafx.scene.control.TextField;
34-
import javafx.scene.image.ImageView;
3533
import javafx.scene.input.KeyCode;
3634
import javafx.scene.input.KeyCodeCombination;
3735
import javafx.scene.input.KeyCombination;
@@ -51,7 +49,6 @@
5149
import org.phoebus.olog.es.api.model.LogGroupProperty;
5250
import org.phoebus.ui.dialog.DialogHelper;
5351
import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog;
54-
import org.phoebus.ui.javafx.ImageCache;
5552

5653
import java.io.IOException;
5754
import java.util.List;
@@ -107,7 +104,7 @@ public class LogEntryTableViewController extends LogbookSearchController {
107104
private final ObservableList<LogEntry> selectedLogEntries = FXCollections.observableArrayList();
108105
private final Logger logger = Logger.getLogger(LogEntryTableViewController.class.getName());
109106

110-
private SimpleBooleanProperty showDetails = new SimpleBooleanProperty();
107+
private final SimpleBooleanProperty showDetails = new SimpleBooleanProperty();
111108

112109
/**
113110
* Constructor.
@@ -129,13 +126,7 @@ public LogEntryTableViewController(LogClient logClient, OlogQueryManager ologQue
129126
private final OlogQueryManager ologQueryManager;
130127
private final ObservableList<OlogQuery> ologQueries = FXCollections.observableArrayList();
131128

132-
/**
133-
* The listener called when user selects an item in the {@link ComboBox}
134-
* drop-down, or when a value is set implicitly from code when updating the list of items in the drop-down.
135-
*/
136-
private ChangeListener<OlogQuery> onActionListener;
137-
138-
private SearchParameters searchParameters;
129+
private final SearchParameters searchParameters;
139130

140131
private LogEntry selectedLogEntry;
141132

@@ -144,16 +135,12 @@ public void initialize() {
144135
configureComboBox();
145136
ologQueries.setAll(ologQueryManager.getQueries());
146137

147-
searchParameters.addListener((observable, oldValue, newValue) -> {
148-
query.getEditor().setText(newValue);
149-
});
138+
searchParameters.addListener((observable, oldValue, newValue) -> query.getEditor().setText(newValue));
150139

151140
tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
152141

153142
MenuItem groupSelectedEntries = new MenuItem(Messages.GroupSelectedEntries);
154-
groupSelectedEntries.setOnAction(e -> {
155-
createLogEntryGroup();
156-
});
143+
groupSelectedEntries.setOnAction(e -> createLogEntryGroup());
157144

158145
groupSelectedEntries.disableProperty()
159146
.bind(Bindings.createBooleanBinding(() ->
@@ -190,37 +177,35 @@ public void initialize() {
190177
descriptionCol = new TableColumn<>();
191178
descriptionCol.setMaxWidth(1f * Integer.MAX_VALUE * 100);
192179
descriptionCol.setCellValueFactory(col -> new SimpleObjectProperty(col.getValue()));
193-
descriptionCol.setCellFactory(col -> {
194-
return new TableCell<>() {
195-
private final Node graphic;
196-
private final PseudoClass childlessTopLevel =
197-
PseudoClass.getPseudoClass("grouped");
198-
private final LogEntryCellController controller;
199-
200-
{
201-
try {
202-
FXMLLoader loader = new FXMLLoader(getClass().getResource("LogEntryCell.fxml"));
203-
graphic = loader.load();
204-
controller = loader.getController();
205-
} catch (IOException exc) {
206-
throw new RuntimeException(exc);
207-
}
180+
descriptionCol.setCellFactory(col -> new TableCell<>() {
181+
private final Node graphic;
182+
private final PseudoClass childlessTopLevel =
183+
PseudoClass.getPseudoClass("grouped");
184+
private final LogEntryCellController controller;
185+
186+
{
187+
try {
188+
FXMLLoader loader = new FXMLLoader(getClass().getResource("LogEntryCell.fxml"));
189+
graphic = loader.load();
190+
controller = loader.getController();
191+
} catch (IOException exc) {
192+
throw new RuntimeException(exc);
208193
}
194+
}
209195

210-
@Override
211-
public void updateItem(TableViewListItem logEntry, boolean empty) {
212-
super.updateItem(logEntry, empty);
213-
if (empty) {
214-
setGraphic(null);
215-
pseudoClassStateChanged(childlessTopLevel, false);
216-
} else {
217-
controller.setLogEntry(logEntry);
218-
setGraphic(graphic);
219-
boolean b = LogGroupProperty.getLogGroupProperty(logEntry.getLogEntry()).isPresent();
220-
pseudoClassStateChanged(childlessTopLevel, b);
221-
}
196+
@Override
197+
public void updateItem(TableViewListItem logEntry, boolean empty) {
198+
super.updateItem(logEntry, empty);
199+
if (empty) {
200+
setGraphic(null);
201+
pseudoClassStateChanged(childlessTopLevel, false);
202+
} else {
203+
controller.setLogEntry(logEntry);
204+
setGraphic(graphic);
205+
boolean b = LogGroupProperty.getLogGroupProperty(logEntry.getLogEntry()).isPresent();
206+
pseudoClassStateChanged(childlessTopLevel, b);
222207
}
223-
};
208+
}
224209
});
225210

226211
tableView.getColumns().add(descriptionCol);
@@ -230,9 +215,7 @@ public void updateItem(TableViewListItem logEntry, boolean empty) {
230215

231216
searchResultView.disableProperty().bind(searchInProgress);
232217

233-
pagination.currentPageIndexProperty().addListener((a, b, c) -> {
234-
search();
235-
});
218+
pagination.currentPageIndexProperty().addListener((a, b, c) -> search());
236219

237220
pageSizeTextField.setText(Integer.toString(pageSizeProperty.get()));
238221

@@ -339,7 +322,7 @@ public void search() {
339322
searchInProgress.set(false);
340323
setSearchResult(searchResult1);
341324
logger.log(Level.INFO, "Starting periodic search: " + queryString);
342-
periodicSearch(params, searchResult -> setSearchResult(searchResult));
325+
periodicSearch(params, this::setSearchResult);
343326
List<OlogQuery> queries = ologQueryManager.getQueries();
344327
Platform.runLater(() -> {
345328
ologQueries.setAll(queries);
@@ -348,7 +331,7 @@ public void search() {
348331
},
349332
(msg, ex) -> {
350333
searchInProgress.set(false);
351-
ExceptionDetailsErrorDialog.openError("Logbook Search Error", ex.getMessage(), ex);
334+
ExceptionDetailsErrorDialog.openError(Messages.LogbooksSearchFailTitle, ex.getMessage(), null);
352335
});
353336
}
354337

@@ -433,7 +416,7 @@ private void configureComboBox() {
433416
new Callback<>() {
434417
@Override
435418
public ListCell<OlogQuery> call(ListView<OlogQuery> param) {
436-
final ListCell<OlogQuery> cell = new ListCell<>() {
419+
return new ListCell<>() {
437420
@Override
438421
public void updateItem(OlogQuery item,
439422
boolean empty) {
@@ -450,7 +433,6 @@ public void updateItem(OlogQuery item,
450433
}
451434
}
452435
};
453-
return cell;
454436
}
455437
});
456438

@@ -479,8 +461,8 @@ public OlogQuery fromString(String s) {
479461
* log entry meta data should be rendered in the list view.
480462
*/
481463
public static class TableViewListItem {
482-
private SimpleBooleanProperty showDetails = new SimpleBooleanProperty(true);
483-
private LogEntry logEntry;
464+
private final SimpleBooleanProperty showDetails = new SimpleBooleanProperty(true);
465+
private final LogEntry logEntry;
484466

485467
public TableViewListItem(LogEntry logEntry, boolean showDetails) {
486468
this.logEntry = logEntry;

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
@@ -27,6 +27,7 @@ public class Messages
2727
GroupSelectedEntries,
2828
Level,
2929
Logbooks,
30+
LogbooksSearchFailTitle,
3031
LogbookServiceUnavailableTitle,
3132
LogbookServiceHasNoLogbooks,
3233
LogbooksTitle,

app/logbook/olog/ui/src/main/resources/org/phoebus/logbook/olog/ui/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Level=Level
4242
Logbooks=Logbooks:
4343
LogbookServiceUnavailableTitle=Cannot create logbook entry
4444
LogbookServiceHasNoLogbooks=Logbook service "{0}" has no logbooks or is not available.
45+
LogbooksSearchFailTitle=Logbook Search Error
4546
LogbooksTitle=Select Logbooks
4647
LogbooksTooltip=Add logbook to the log entry.
4748
NoClipboardContent=Clipboard does not contain any content that may be added as attachment.

0 commit comments

Comments
 (0)