Skip to content

Commit 031c578

Browse files
committed
Refactoring in the name of simplification
1 parent b5c248d commit 031c578

File tree

8 files changed

+40
-50
lines changed

8 files changed

+40
-50
lines changed

app/logbook/inmemory/src/main/java/org/phoebus/applications/logbook/InMemoryLogClient.java

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
package org.phoebus.applications.logbook;
22

3+
import org.phoebus.logbook.Attachment;
4+
import org.phoebus.logbook.AttachmentImpl;
5+
import org.phoebus.logbook.LogClient;
6+
import org.phoebus.logbook.LogEntry;
7+
import org.phoebus.logbook.LogEntryImpl;
8+
import org.phoebus.logbook.LogEntryImpl.LogEntryBuilder;
9+
import org.phoebus.logbook.LogEntryLevel;
10+
import org.phoebus.logbook.Logbook;
11+
import org.phoebus.logbook.LogbookException;
12+
import org.phoebus.logbook.LogbookImpl;
13+
import org.phoebus.logbook.Property;
14+
import org.phoebus.logbook.PropertyImpl;
15+
import org.phoebus.logbook.SearchResult;
16+
import org.phoebus.logbook.Tag;
17+
import org.phoebus.logbook.TagImpl;
18+
319
import java.io.File;
420
import java.io.FileInputStream;
521
import java.io.FileNotFoundException;
622
import java.io.IOException;
723
import java.io.InputStream;
824
import java.net.URLConnection;
9-
import java.nio.file.CopyOption;
1025
import java.nio.file.Files;
11-
import java.nio.file.StandardCopyOption;
1226
import java.time.Instant;
1327
import java.util.Arrays;
1428
import java.util.Collection;
@@ -23,21 +37,6 @@
2337
import java.util.stream.Collectors;
2438
import java.util.stream.Stream;
2539

26-
import org.phoebus.logbook.Attachment;
27-
import org.phoebus.logbook.AttachmentImpl;
28-
import org.phoebus.logbook.LogClient;
29-
import org.phoebus.logbook.LogEntry;
30-
import org.phoebus.logbook.LogEntryImpl;
31-
import org.phoebus.logbook.LogEntryImpl.LogEntryBuilder;
32-
import org.phoebus.logbook.Logbook;
33-
import org.phoebus.logbook.LogbookException;
34-
import org.phoebus.logbook.LogbookImpl;
35-
import org.phoebus.logbook.Property;
36-
import org.phoebus.logbook.PropertyImpl;
37-
import org.phoebus.logbook.SearchResult;
38-
import org.phoebus.logbook.Tag;
39-
import org.phoebus.logbook.TagImpl;
40-
4140
/**
4241
* A logbook which maintains logentries in memory. It is mainly for testing and debugging purpose.
4342
*/
@@ -47,16 +46,16 @@ public class InMemoryLogClient implements LogClient {
4746
private final Map<Long, LogEntry> logEntries;
4847

4948
private final Collection<Logbook> logbooks = Arrays.asList(LogbookImpl.of("Controls"),
50-
LogbookImpl.of("Commissioning"),
51-
LogbookImpl.of("Scratch Pad"));
49+
LogbookImpl.of("Commissioning"),
50+
LogbookImpl.of("Scratch Pad"));
5251
private final Collection<Tag> tags = Arrays.asList(TagImpl.of("Operations"),
53-
TagImpl.of("Alarm"),
54-
TagImpl.of("Example"));
52+
TagImpl.of("Alarm"),
53+
TagImpl.of("Example"));
5554
private final List<String> levels = Arrays.asList("Urgent", "Suggestion", "Info", "Request", "Problem");
5655

5756
private static List<Property> inMemoryProperties() {
5857
Map<String, String> tracAttributes = new HashMap<>();
59-
Property track = PropertyImpl.of("Track",tracAttributes);
58+
Property track = PropertyImpl.of("Track", tracAttributes);
6059
Map<String, String> experimentAttributes = new HashMap<>();
6160
Property experimentProperty = PropertyImpl.of("Experiment", experimentAttributes);
6261
Map<String, String> resourceAttributes = new HashMap<>();
@@ -80,8 +79,8 @@ public InMemoryLogClient() {
8079
}
8180

8281
@Override
83-
public Collection<String> listLevels() {
84-
return levels;
82+
public Collection<LogEntryLevel> listLevels() {
83+
return levels.stream().map(l -> new LogEntryLevel(l, false)).toList();
8584
}
8685

8786
@Override
@@ -110,6 +109,7 @@ public LogEntry getLog(Long logId) {
110109
}
111110

112111
String prefix = "phoebus_tmp_file";
112+
113113
@Override
114114
public LogEntry set(LogEntry log) {
115115
long id = logIdCounter.incrementAndGet();
@@ -155,12 +155,12 @@ public SearchResult search(Map<String, String> map) {
155155
@Override
156156
public List<LogEntry> findLogs(Map<String, String> map) {
157157
Stream<LogEntry> searchStream = logEntries.values().stream();
158-
if(map.containsKey("start")) {
158+
if (map.containsKey("start")) {
159159
searchStream = searchStream.filter(log -> {
160160
return log.getCreatedDate().isAfter(Instant.ofEpochSecond(Long.valueOf(map.get("start"))));
161161
});
162162
}
163-
if(map.containsKey("end")) {
163+
if (map.containsKey("end")) {
164164
searchStream = searchStream.filter(log -> {
165165
return log.getCreatedDate().isBefore(Instant.ofEpochSecond(Long.valueOf(map.get("end"))));
166166
});
@@ -169,7 +169,7 @@ public List<LogEntry> findLogs(Map<String, String> map) {
169169
final String searchString = map.get("search").replaceAll("\\*", "");
170170
if (!searchString.isEmpty()) {
171171
searchStream = searchStream.filter(log -> {
172-
return log.getDescription().contains(searchString)||log.getTitle().contains(searchString);
172+
return log.getDescription().contains(searchString) || log.getTitle().contains(searchString);
173173
});
174174
}
175175
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ public LogTemplate saveTemplate(LogTemplate template) throws LogbookException {
552552
}
553553

554554
@Override
555-
public Collection<LogEntryLevel> getLogEntryLevels(){
555+
public Collection<LogEntryLevel> listLevels(){
556556
HttpRequest request = HttpRequest.newBuilder()
557557
.uri(URI.create(Preferences.olog_url + "/levels"))
558558
.GET()

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.phoebus.logbook.Attachment;
77
import org.phoebus.logbook.LogClient;
88
import org.phoebus.logbook.LogEntry;
9+
import org.phoebus.logbook.LogEntryLevel;
910
import org.phoebus.logbook.Logbook;
1011
import org.phoebus.logbook.LogbookException;
1112
import org.phoebus.logbook.Messages;
@@ -197,13 +198,12 @@ private OlogClient(HttpClient httpClient, String userName, String password) {
197198

198199
}
199200

200-
201201
// A predefined set of levels supported by olog
202202
private final List<String> levels = Arrays.asList("Urgent", "Suggestion", "Info", "Request", "Problem");
203203

204204
@Override
205-
public Collection<String> listLevels() {
206-
return levels;
205+
public Collection<LogEntryLevel> listLevels() {
206+
return levels.stream().map(l -> new LogEntryLevel(l, false)).toList();
207207
}
208208

209209
@Override

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ public void initialize() {
180180
startTime.setOnKeyReleased(this::searchOnEnter);
181181
endTime.textProperty().bindBidirectional(this.searchParameters.endTimeProperty());
182182
endTime.setOnKeyReleased(this::searchOnEnter);
183-
searchParameters.addListener((observable, oldValue, newValue) -> {
184-
updateControls(newValue);
185-
});
183+
searchParameters.addListener((observable, oldValue, newValue) -> updateControls(newValue));
186184
sortAscending.addListener(searchOnSortChange);
187185

188186
attachmentTypes.textProperty().bindBidirectional(this.searchParameters.attachmentsProperty());
@@ -318,7 +316,7 @@ public void initialize() {
318316
}
319317
});
320318

321-
levelsList.addAll(logClient.getLogEntryLevels().stream().map(LogEntryLevel::name).sorted().toList());
319+
levelsList.addAll(logClient.listLevels().stream().map(LogEntryLevel::name).sorted().toList());
322320
levelsList.forEach(level -> {
323321
LevelSelection levelSelection = new LevelSelection(level, false);
324322
levelSelections.add(levelSelection);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ private void getServerSideStaticData() {
825825

826826
templatesProperty.setAll(logClient.getTemplates().stream().toList());
827827

828-
Collection<LogEntryLevel> levels = logClient.getLogEntryLevels();
828+
Collection<LogEntryLevel> levels = logClient.listLevels();
829829
availableLevels.setAll(levels.stream().map(LogEntryLevel::name).sorted().toList());
830830
Optional<LogEntryLevel> optionalLevel = levels.stream().filter(LogEntryLevel::defaultLevel).findFirst();
831831
String defaultLevel = null;

app/logbook/ui/src/main/java/org/phoebus/logbook/ui/AdvancedSearchViewController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import javafx.scene.layout.HBox;
3636
import javafx.scene.layout.VBox;
3737
import org.phoebus.logbook.LogClient;
38+
import org.phoebus.logbook.LogEntryLevel;
3839
import org.phoebus.logbook.Logbook;
3940
import org.phoebus.logbook.Tag;
4041
import org.phoebus.logbook.ui.LogbookQueryUtil.Keys;
@@ -261,7 +262,7 @@ public void initialize() {
261262
searchParameters.put(Keys.TITLE, newValue);
262263
});
263264

264-
List<String> levelList = logClient.listLevels().stream().collect(Collectors.toList());
265+
List<String> levelList = logClient.listLevels().stream().map(LogEntryLevel::name).toList();
265266
levelSelector.getItems().add("");
266267
levelSelector.getItems().addAll(levelList);
267268

app/logbook/ui/src/main/java/org/phoebus/logbook/ui/write/LogEntryModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.phoebus.logbook.LogClient;
2222
import org.phoebus.logbook.LogEntry;
2323
import org.phoebus.logbook.LogEntryImpl.LogEntryBuilder;
24+
import org.phoebus.logbook.LogEntryLevel;
2425
import org.phoebus.logbook.LogFactory;
2526
import org.phoebus.logbook.LogService;
2627
import org.phoebus.logbook.Logbook;
@@ -46,7 +47,6 @@
4647
import java.util.List;
4748
import java.util.logging.Level;
4849
import java.util.logging.Logger;
49-
import java.util.stream.Collectors;
5050

5151
import static org.phoebus.ui.application.PhoebusApplication.logger;
5252

@@ -579,7 +579,7 @@ public void fetchLevels() {
579579
{
580580
LogClient logClient = logFactory.getLogClient();
581581

582-
List<String> levelList = logClient.listLevels().stream().collect(Collectors.toList());
582+
List<String> levelList = logClient.listLevels().stream().map(LogEntryLevel::name).toList();
583583

584584
// Certain views have listeners to these observable lists. So, when they change, the call backs need to execute on the FX Application thread.
585585
Platform.runLater(() ->

core/logbook/src/main/java/org/phoebus/logbook/LogClient.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,9 @@ default Collection<Property> listProperties() {
9292
}
9393

9494
/**
95-
* List the supported log levels
96-
*
97-
* @return a list of supported levels
95+
* @return List of {@link LogEntryLevel}s maintained in the service
9896
*/
99-
default Collection<String> listLevels() {
97+
default Collection<LogEntryLevel> listLevels() {
10098
return Collections.emptyList();
10199
}
102100

@@ -529,11 +527,4 @@ default Collection<LogTemplate> getTemplates(){
529527
default LogTemplate saveTemplate(LogTemplate logTemplate) throws LogbookException{
530528
return null;
531529
}
532-
533-
/**
534-
* @return List of {@link LogEntryLevel}s maintained in the service
535-
*/
536-
default Collection<LogEntryLevel> getLogEntryLevels(){
537-
return Collections.emptySet();
538-
}
539530
}

0 commit comments

Comments
 (0)