From 2bbc80fd396e260ebd8d4c89e3b3d5eafeeacf8a Mon Sep 17 00:00:00 2001 From: Lars Johansson Date: Thu, 21 Mar 2024 09:09:51 +0100 Subject: [PATCH] Log entry group property not editable --- .../java/org/phoebus/olog/LogResource.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/java/org/phoebus/olog/LogResource.java b/src/main/java/org/phoebus/olog/LogResource.java index e92b95d..da23d9e 100644 --- a/src/main/java/org/phoebus/olog/LogResource.java +++ b/src/main/java/org/phoebus/olog/LogResource.java @@ -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; @@ -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()); @@ -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 null if property not found + */ + private Property extractProperty(Set 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 logEntryIds) {