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
@@ -1,14 +1,28 @@
package org.phoebus.applications.logbook;

import org.phoebus.logbook.Attachment;
import org.phoebus.logbook.AttachmentImpl;
import org.phoebus.logbook.LogClient;
import org.phoebus.logbook.LogEntry;
import org.phoebus.logbook.LogEntryImpl;
import org.phoebus.logbook.LogEntryImpl.LogEntryBuilder;
import org.phoebus.logbook.LogEntryLevel;
import org.phoebus.logbook.Logbook;
import org.phoebus.logbook.LogbookException;
import org.phoebus.logbook.LogbookImpl;
import org.phoebus.logbook.Property;
import org.phoebus.logbook.PropertyImpl;
import org.phoebus.logbook.SearchResult;
import org.phoebus.logbook.Tag;
import org.phoebus.logbook.TagImpl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLConnection;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -23,21 +37,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.phoebus.logbook.Attachment;
import org.phoebus.logbook.AttachmentImpl;
import org.phoebus.logbook.LogClient;
import org.phoebus.logbook.LogEntry;
import org.phoebus.logbook.LogEntryImpl;
import org.phoebus.logbook.LogEntryImpl.LogEntryBuilder;
import org.phoebus.logbook.Logbook;
import org.phoebus.logbook.LogbookException;
import org.phoebus.logbook.LogbookImpl;
import org.phoebus.logbook.Property;
import org.phoebus.logbook.PropertyImpl;
import org.phoebus.logbook.SearchResult;
import org.phoebus.logbook.Tag;
import org.phoebus.logbook.TagImpl;

/**
* A logbook which maintains logentries in memory. It is mainly for testing and debugging purpose.
*/
Expand All @@ -47,16 +46,16 @@ public class InMemoryLogClient implements LogClient {
private final Map<Long, LogEntry> logEntries;

private final Collection<Logbook> logbooks = Arrays.asList(LogbookImpl.of("Controls"),
LogbookImpl.of("Commissioning"),
LogbookImpl.of("Scratch Pad"));
LogbookImpl.of("Commissioning"),
LogbookImpl.of("Scratch Pad"));
private final Collection<Tag> tags = Arrays.asList(TagImpl.of("Operations"),
TagImpl.of("Alarm"),
TagImpl.of("Example"));
TagImpl.of("Alarm"),
TagImpl.of("Example"));
private final List<String> levels = Arrays.asList("Urgent", "Suggestion", "Info", "Request", "Problem");

private static List<Property> inMemoryProperties() {
Map<String, String> tracAttributes = new HashMap<>();
Property track = PropertyImpl.of("Track",tracAttributes);
Property track = PropertyImpl.of("Track", tracAttributes);
Map<String, String> experimentAttributes = new HashMap<>();
Property experimentProperty = PropertyImpl.of("Experiment", experimentAttributes);
Map<String, String> resourceAttributes = new HashMap<>();
Expand All @@ -80,8 +79,8 @@ public InMemoryLogClient() {
}

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

@Override
Expand Down Expand Up @@ -110,6 +109,7 @@ public LogEntry getLog(Long logId) {
}

String prefix = "phoebus_tmp_file";

@Override
public LogEntry set(LogEntry log) {
long id = logIdCounter.incrementAndGet();
Expand Down Expand Up @@ -155,12 +155,12 @@ public SearchResult search(Map<String, String> map) {
@Override
public List<LogEntry> findLogs(Map<String, String> map) {
Stream<LogEntry> searchStream = logEntries.values().stream();
if(map.containsKey("start")) {
if (map.containsKey("start")) {
searchStream = searchStream.filter(log -> {
return log.getCreatedDate().isAfter(Instant.ofEpochSecond(Long.valueOf(map.get("start"))));
});
}
if(map.containsKey("end")) {
if (map.containsKey("end")) {
searchStream = searchStream.filter(log -> {
return log.getCreatedDate().isBefore(Instant.ofEpochSecond(Long.valueOf(map.get("end"))));
});
Expand All @@ -169,7 +169,7 @@ public List<LogEntry> findLogs(Map<String, String> map) {
final String searchString = map.get("search").replaceAll("\\*", "");
if (!searchString.isEmpty()) {
searchStream = searchStream.filter(log -> {
return log.getDescription().contains(searchString)||log.getTitle().contains(searchString);
return log.getDescription().contains(searchString) || log.getTitle().contains(searchString);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.phoebus.logbook.LogClient;
import org.phoebus.logbook.LogEntry;
import org.phoebus.logbook.LogEntryChangeHandler;
import org.phoebus.logbook.LogEntryLevel;
import org.phoebus.logbook.LogTemplate;
import org.phoebus.logbook.Logbook;
import org.phoebus.logbook.LogbookException;
Expand Down Expand Up @@ -49,6 +50,7 @@
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -548,4 +550,22 @@ public LogTemplate saveTemplate(LogTemplate template) throws LogbookException {
throw new LogbookException(e);
}
}

@Override
public Collection<LogEntryLevel> listLevels(){
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(Preferences.olog_url + "/levels"))
.GET()
.build();

try {
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
return OlogObjectMappers.logEntryDeserializer.readValue(
response.body(), new TypeReference<Set<LogEntryLevel>>() {
});
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Unable to get templates from service", e);
return Collections.emptySet();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.phoebus.logbook.Attachment;
import org.phoebus.logbook.LogClient;
import org.phoebus.logbook.LogEntry;
import org.phoebus.logbook.LogEntryLevel;
import org.phoebus.logbook.Logbook;
import org.phoebus.logbook.LogbookException;
import org.phoebus.logbook.Messages;
Expand Down Expand Up @@ -197,13 +198,12 @@ private OlogClient(HttpClient httpClient, String userName, String password) {

}


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

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

@Override
Expand Down
Loading