Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log entry group property not editable #190

Closed
wants to merge 1 commit into from
Closed
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
30 changes: 30 additions & 0 deletions src/main/java/org/phoebus/olog/LogResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package org.phoebus.olog;

import org.apache.commons.codec.binary.StringUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.phoebus.olog.entity.*;
import org.phoebus.olog.entity.preprocess.LogPropertyProvider;
Expand Down Expand Up @@ -377,6 +378,16 @@ public Log updateLog(@PathVariable String logId,
Log persistedLog = foundLog.get();
logRepository.archive(persistedLog);

// log entry group property should not be editable but remain if it exists
Property logEntryGroupProperty = extractProperty(log.getProperties(), LogEntryGroupHelper.LOG_ENTRY_GROUP);
if (logEntryGroupProperty != null) {
log.getProperties().remove(logEntryGroupProperty);
}
logEntryGroupProperty = extractProperty(persistedLog.getProperties(), LogEntryGroupHelper.LOG_ENTRY_GROUP);
if (logEntryGroupProperty != null) {
log.getProperties().add(logEntryGroupProperty);
}

persistedLog.setOwner(principal.getName());
persistedLog.setLevel(log.getLevel());
persistedLog.setProperties(log.getProperties());
Expand All @@ -394,6 +405,25 @@ public Log updateLog(@PathVariable String logId,
}
}

/**
* Extract property with given name from set of properties.
*
* @param properties set of properties
* @param name property name
* @return extracted property or <tt>null</tt> if property not found
*/
private Property extractProperty(Set<Property> properties, String name) {
if (properties == null || name == null) {
return null;
}
for (Property property : properties) {
if (StringUtils.equals(name, property.getName())) {
return property;
}
}
return null;
}

@SuppressWarnings("unused")
@PostMapping(value = "/group")
public void groupLogEntries(@RequestBody List<Long> logEntryIds) {
Expand Down
Loading