use of org.phoebus.logbook.LogClient in project phoebus by ControlSystemStudio.
the class FieldsViewController method setupLogbooksAndTags.
/**
* Retrieves logbooks and tags from service and populates all the data structures that depend
* on the result. The call to the remote service is asynchronous.
*/
private void setupLogbooksAndTags() {
JobManager.schedule("Fetch Logbooks and Tags", monitor -> {
LogClient logClient = LogService.getInstance().getLogFactories().get(LogbookPreferences.logbook_factory).getLogClient();
availableLogbooks = logClient.listLogbooks();
availableLogbooksAsStringList = FXCollections.observableArrayList(availableLogbooks.stream().map(logbook -> logbook.getName()).collect(Collectors.toList()));
Collections.sort(availableLogbooksAsStringList);
List<String> preSelectedLogbooks = logEntry.getLogbooks().stream().map(l -> l.getName()).collect(Collectors.toList());
List<String> defaultLogbooks = Arrays.asList(LogbookUIPreferences.default_logbooks);
availableLogbooksAsStringList.forEach(logbook -> {
CheckBox checkBox = new CheckBox(logbook);
CustomMenuItem newLogbook = new CustomMenuItem(checkBox);
newLogbook.setHideOnClick(false);
checkBox.setOnAction(e -> {
CheckBox source = (CheckBox) e.getSource();
String text = source.getText();
if (source.isSelected()) {
selectedLogbooks.add(text);
} else {
selectedLogbooks.remove(text);
}
});
if (!preSelectedLogbooks.isEmpty() && preSelectedLogbooks.contains(logbook)) {
checkBox.setSelected(preSelectedLogbooks.contains(logbook));
selectedLogbooks.add(logbook);
} else if (defaultLogbooks.contains(logbook)) {
checkBox.setSelected(defaultLogbooks.contains(logbook));
selectedLogbooks.add(logbook);
}
logbookDropDown.getItems().add(newLogbook);
});
availableTags = logClient.listTags();
availableTagsAsStringList = FXCollections.observableArrayList(availableTags.stream().map(tag -> tag.getName()).collect(Collectors.toList()));
Collections.sort(availableLogbooksAsStringList);
List<String> preSelectedTags = logEntry.getTags().stream().map(t -> t.getName()).collect(Collectors.toList());
availableTagsAsStringList.forEach(tag -> {
CheckBox checkBox = new CheckBox(tag);
CustomMenuItem newTag = new CustomMenuItem(checkBox);
newTag.setHideOnClick(false);
checkBox.setOnAction(e -> {
CheckBox source = (CheckBox) e.getSource();
String text = source.getText();
if (source.isSelected()) {
selectedTags.add(text);
} else {
selectedTags.remove(text);
}
});
checkBox.setSelected(preSelectedTags.contains(tag));
if (preSelectedTags.contains(tag)) {
selectedTags.add(tag);
}
tagDropDown.getItems().add(newTag);
});
});
}
use of org.phoebus.logbook.LogClient in project phoebus by ControlSystemStudio.
the class LogEntryEditorController method submit.
@FXML
public void submit() {
submissionInProgress.set(true);
JobManager.schedule("Submit Log Entry", monitor -> {
OlogLog ologLog = new OlogLog();
ologLog.setTitle(fieldsViewController.getTitle());
ologLog.setDescription(fieldsViewController.getDescription());
ologLog.setLevel(fieldsViewController.getSelectedLevel());
ologLog.setLogbooks(fieldsViewController.getSelectedLogbooks());
ologLog.setTags(fieldsViewController.getSelectedTags());
ologLog.setAttachments(attachmentsViewController.getAttachments());
ologLog.setProperties(logPropertiesEditorController.getProperties());
LogClient logClient = logFactory.getLogClient(new SimpleAuthenticationToken(fieldsViewController.getUsernameProperty(), fieldsViewController.getPasswordProperty()));
LogEntry result;
try {
if (replyTo == null) {
result = logClient.set(ologLog);
} else {
result = logClient.reply(ologLog, replyTo);
}
if (result != null) {
if (completionHandler != null) {
completionHandler.handleResult(result);
}
// Set username and password in secure store if submission of log entry completes successfully
if (LogbookUIPreferences.save_credentials) {
// Get the SecureStore. Store username and password.
try {
SecureStore store = new SecureStore();
ScopedAuthenticationToken scopedAuthenticationToken = new ScopedAuthenticationToken(LogService.AUTHENTICATION_SCOPE, fieldsViewController.getUsernameProperty(), fieldsViewController.getPasswordProperty());
store.setScopedAuthentication(scopedAuthenticationToken);
} catch (Exception ex) {
logger.log(Level.WARNING, "Secure Store file not found.", ex);
}
}
attachmentsViewController.deleteTemporaryFiles();
// This will close the editor
Platform.runLater(() -> cancel());
}
} catch (LogbookException e) {
logger.log(Level.WARNING, "Unable to submit log entry", e);
Platform.runLater(() -> {
if (e.getCause() != null && e.getCause().getMessage() != null) {
completionMessageLabel.textProperty().setValue(e.getCause().getMessage());
} else if (e.getMessage() != null) {
completionMessageLabel.textProperty().setValue(e.getMessage());
} else {
completionMessageLabel.textProperty().setValue(org.phoebus.logbook.Messages.SubmissionFailed);
}
});
}
submissionInProgress.set(false);
});
}
use of org.phoebus.logbook.LogClient in project phoebus by ControlSystemStudio.
the class LogPropertiesEditorController method setupProperties.
/**
* Refreshes the list of available properties. Properties provided by {@link LogPropertyProvider} implementations
* are considered first, and then properties available from service. However, adding items to the list of properties
* always consider equality, i.e. properties with same name are added only once. SPI implementations should therefore
* not support properties with same name, and should not implement properties available from service.
* <p>
* Further, if the user is editing a copy (reply) based on another log entry, a set of properties may
* already be present in the new log entry. The list of available properties will not contain such properties
* as this would be confusing.
* <p>
* When user chooses to remove a property from the list of properties, the list of available properties must
* also be refreshed, so this method should handle such a use case.
* <p>
* Also, properties to be excluded as listed in the preferences (properties_excluded_from_view) are not
* added to the properties tree.
*/
private void setupProperties() {
JobManager.schedule("Fetch Properties from service", monitor -> {
// First add properties from SPI implementations
List<LogPropertyProvider> factories = new ArrayList<>();
ServiceLoader<LogPropertyProvider> loader = ServiceLoader.load(LogPropertyProvider.class);
loader.stream().forEach(p -> {
if (p.get().getProperty() != null) {
factories.add(p.get());
}
});
// List of property names added if user is replying to a log entry.
List<String> selectedPropertyNames = selectedProperties.stream().map(Property::getName).collect(Collectors.toList());
factories.stream().map(LogPropertyProvider::getProperty).forEach(property -> {
// Do not add a property that is already selected
if (!selectedPropertyNames.contains(property.getName())) {
selectedProperties.add(property);
selectedPropertyNames.add(property.getName());
}
});
LogClient logClient = LogService.getInstance().getLogFactories().get(LogbookPreferences.logbook_factory).getLogClient();
List<Property> propertyList = logClient.listProperties().stream().collect(Collectors.toList());
List<Property> list = new ArrayList<>();
Platform.runLater(() -> {
propertyList.forEach(property -> {
// Do not add a property that is already selected or already added from provider
if (!selectedPropertyNames.contains(property.getName())) {
list.add(property);
}
});
list.sort(Comparator.comparing(Property::getName));
availableProperties.setAll(list);
});
});
}
use of org.phoebus.logbook.LogClient in project phoebus by ControlSystemStudio.
the class LogPropertiesEditorDemo method getDummyLogClient.
private LogClient getDummyLogClient() {
return new LogClient() {
@Override
public LogEntry set(LogEntry log) throws LogbookException {
return null;
}
@Override
public LogEntry getLog(Long logId) {
return null;
}
@Override
public Collection<Attachment> listAttachments(Long logId) {
return null;
}
@Override
public List<LogEntry> findLogs(Map<String, String> map) {
return null;
}
@Override
public Collection<LogEntry> listLogs() {
return null;
}
@Override
public Collection<Property> listProperties() {
Map<String, String> experimentAttributes = new HashMap<>();
experimentAttributes.put("id", "1234");
experimentAttributes.put("type", "XPD xray diffraction");
experimentAttributes.put("scan-id", "6789");
Property experimentProperty = PropertyImpl.of("Experiment", experimentAttributes);
return Arrays.asList(experimentProperty);
}
};
}
Aggregations