Skip to content

Commit

Permalink
Merge pull request #2173 from ControlSystemStudio/olog-resource-property
Browse files Browse the repository at this point in the history
Update the olog adapter to add opi resource as a resource property
  • Loading branch information
shroffk authored Mar 17, 2022
2 parents 62fbfab + 17fa2b9 commit 73a9739
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
import org.csstudio.display.builder.runtime.app.SelectionInfo;
import org.phoebus.applications.email.EmailEntry;
import org.phoebus.framework.adapter.AdapterFactory;
import org.phoebus.logbook.AttachmentImpl;
import org.phoebus.logbook.LogEntry;
import org.phoebus.logbook.*;
import org.phoebus.logbook.LogEntryImpl.LogEntryBuilder;
import org.phoebus.logbook.LogbookPreferences;
import org.phoebus.ui.javafx.Screenshot;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

import static org.phoebus.logbook.LogEntryImpl.LogEntryBuilder.log;
Expand Down Expand Up @@ -59,16 +56,22 @@ public <T> Optional<T> adapt(Object adaptableObject, Class<T> adapterType)
}
else if (adapterType.isAssignableFrom(LogEntry.class))
{
LogEntryBuilder log = log().title(LogbookPreferences.auto_title ?
"Display Screenshot for : " + selectionInfo.getName() : "")
.appendDescription(getBody(selectionInfo));
try
{
final File image_file = selectionInfo.getImage() == null ? null : new Screenshot(selectionInfo.getImage()).writeToTempfile("image");
log.attach(AttachmentImpl.of(image_file));
} catch (Exception e)
{
e.printStackTrace();
LogEntryBuilder log = log()
.title(LogbookPreferences.auto_title ? "Display Screenshot for : " + selectionInfo.getName() : "")
.appendDescription(getBody(selectionInfo));
if(LogbookPreferences.auto_property) {
Map<String, String> attributes = new HashMap<>();
attributes.put("name",selectionInfo.getName());
attributes.put("file",selectionInfo.toURI().toString());
log.appendProperty(PropertyImpl.of("resource", attributes));
try
{
final File image_file = selectionInfo.getImage() == null ? null : new Screenshot(selectionInfo.getImage()).writeToTempfile("image");
log.attach(AttachmentImpl.of(image_file));
} catch (Exception e)
{
logger.log(Level.WARNING, "Failed to build a log entry from this Display Builder selection ", e);
}
}
return Optional.of(adapterType.cast(log.build()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class LogbookPreferences {

@Preference
public static boolean auto_title;
@Preference
public static boolean auto_property;

/** Is there support for a logbook?
* Is the 'logbook_factory' configured and available?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ logbook_factory=inmemory

# Determines if a log entry created from context menu (e.g. display or data browser)
# should auto generate a title (e.g. "Display Screenshot...").
auto_title=true
auto_title=true

# Determines if a log entry created from context menu (e.g. display or data browser)
# should auto generate properties (e.g. "resources.file").
auto_property=false

0 comments on commit 73a9739

Please sign in to comment.