From ffd5faaa5088d06eb16c3bfd6b16fd562f77e413 Mon Sep 17 00:00:00 2001 From: Matteo Saloni Date: Fri, 6 Dec 2024 10:52:30 +0100 Subject: [PATCH] fix: avoid external state modification for non-local runs --- .../core/services/RunServiceImpl.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/services/RunServiceImpl.java b/application/src/main/java/it/smartcommunitylabdhub/core/services/RunServiceImpl.java index 610c8414..ec29d41b 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/services/RunServiceImpl.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/services/RunServiceImpl.java @@ -15,12 +15,14 @@ import it.smartcommunitylabdhub.commons.models.relationships.RelationshipDetail; import it.smartcommunitylabdhub.commons.models.run.Run; import it.smartcommunitylabdhub.commons.models.run.RunBaseSpec; +import it.smartcommunitylabdhub.commons.models.run.RunBaseStatus; import it.smartcommunitylabdhub.commons.models.specs.Spec; import it.smartcommunitylabdhub.commons.models.task.Task; import it.smartcommunitylabdhub.commons.services.LogService; import it.smartcommunitylabdhub.commons.services.RelationshipsAwareEntityService; import it.smartcommunitylabdhub.commons.services.SpecRegistry; import it.smartcommunitylabdhub.commons.utils.KeyUtils; +import it.smartcommunitylabdhub.commons.utils.MapUtils; import it.smartcommunitylabdhub.core.components.infrastructure.specs.SpecValidator; import it.smartcommunitylabdhub.core.models.builders.run.RunEntityBuilder; import it.smartcommunitylabdhub.core.models.entities.AbstractEntity_; @@ -310,6 +312,14 @@ public Run updateRun(@NotNull String id, @NotNull Run dto) dto.setSpec(current.getSpec()); } + //state is modifiable *only* for local runs + RunSpecAccessor specAccessor = RunSpecAccessor.with(current.getSpec()); + if (!specAccessor.isLocalExecution()) { + //keep base status from current + RunBaseStatus bs = RunBaseStatus.with(current.getSpec()); + dto.setStatus(MapUtils.mergeMultipleMaps(dto.getStatus(), bs.toMap())); + } + //TODO: implement logic to update status only in some states //update, run is modifiable