Skip to content

Commit

Permalink
Log entry group property not editable
Browse files Browse the repository at this point in the history
  • Loading branch information
thelarsjohansson committed Mar 21, 2024
1 parent 97b1086 commit 2bbc80f
Showing 1 changed file with 30 additions and 0 deletions.
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

0 comments on commit 2bbc80f

Please sign in to comment.