From 7bf7db6d936ca855a6ebac9a9b80795d9c4d17e8 Mon Sep 17 00:00:00 2001 From: Alberto Codutti Date: Thu, 19 Dec 2024 16:53:15 +0100 Subject: [PATCH] :sparkles: [Job] Support for JSON-formatted in JobStepProperties.value for complex properties Signed-off-by: Alberto Codutti --- .../commons/wrappers/StepContextWrapper.java | 11 ++++++---- ...viceConfigurationPutJobStepDefinition.java | 2 +- .../job/step/internal/JobStepServiceImpl.java | 22 +++++++++++++++---- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/job-engine/commons/src/main/java/org/eclipse/kapua/job/engine/commons/wrappers/StepContextWrapper.java b/job-engine/commons/src/main/java/org/eclipse/kapua/job/engine/commons/wrappers/StepContextWrapper.java index fe70fbd9207..bd82796ca4e 100644 --- a/job-engine/commons/src/main/java/org/eclipse/kapua/job/engine/commons/wrappers/StepContextWrapper.java +++ b/job-engine/commons/src/main/java/org/eclipse/kapua/job/engine/commons/wrappers/StepContextWrapper.java @@ -19,14 +19,12 @@ import javax.batch.runtime.Metric; import javax.batch.runtime.context.StepContext; import javax.xml.bind.DatatypeConverter; -import javax.xml.bind.JAXBException; import org.eclipse.kapua.KapuaIllegalArgumentException; import org.eclipse.kapua.KapuaRuntimeException; import org.eclipse.kapua.commons.util.xml.XmlUtil; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.model.id.KapuaIdFactory; -import org.xml.sax.SAXException; import com.google.common.base.Strings; @@ -96,10 +94,15 @@ public > T getStepProperty(String stepPropertyName, Class\n\n \n org.eclipse.kura.demo.heater.Heater\n \n \n 0.25\n \n \n 60\n \n \n 22:00\n \n \n false\n \n \n org.eclipse.kura.demo.heater.Heater\n \n \n org.eclipse.kura.demo.heater.Heater\n \n \n 06:00\n \n \n Program\n \n \n data/210\n \n \n 30.0\n \n \n 2\n \n \n 13.0\n \n \n 30.0\n \n \n \n", diff --git a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepServiceImpl.java b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepServiceImpl.java index f50bed40469..ead07713317 100644 --- a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepServiceImpl.java +++ b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepServiceImpl.java @@ -129,6 +129,7 @@ public JobStep create(JobStepCreator jobStepCreator) throws KapuaException { return txManager.execute(tx -> { // Check job step definition validateJobStepProperties(tx, jobStepCreator); + // Check duplicate name if (jobStepRepository.countEntitiesWithNameInScope( tx, @@ -420,9 +421,17 @@ private void validateJobStepProperties(List jobStepProperties, } if (jobStepProperty.getPropertyValue() != null) { - ArgumentValidator.areEqual(jobStepProperty.getPropertyType(), jobStepDefinitionProperty.getPropertyType(), "stepProperties[]." + jobStepProperty.getName()); - ArgumentValidator.lengthRange(jobStepProperty.getPropertyValue(), jobStepDefinitionProperty.getMinLength(), jobStepDefinitionProperty.getMaxLength(), - "stepProperties[]." + jobStepProperty.getName()); + ArgumentValidator.areEqual( + jobStepProperty.getPropertyType(), + jobStepDefinitionProperty.getPropertyType(), + "stepProperties[]." + jobStepProperty.getName() + ); + ArgumentValidator.lengthRange( + jobStepProperty.getPropertyValue(), + jobStepDefinitionProperty.getMinLength(), + jobStepDefinitionProperty.getMaxLength(), + "stepProperties[]." + jobStepProperty.getName() + ); validateJobStepPropertyValue(jobStepProperty, jobStepDefinitionProperty); } @@ -455,7 +464,12 @@ private , E extends Enum> void validateJobStepPropert Class jobStepDefinitionPropertyClassEnum = (Class) jobStepDefinitionPropertyClass; Enum.valueOf(jobStepDefinitionPropertyClassEnum, jobStepProperty.getPropertyValue()); } else { - xmlUtil.unmarshal(jobStepProperty.getPropertyValue(), jobStepDefinitionPropertyClass); + // Try both formats: XML - JSON + try { + xmlUtil.unmarshal(jobStepProperty.getPropertyValue(), jobStepDefinitionPropertyClass); + } catch (Exception e) { + xmlUtil.unmarshalJson(jobStepProperty.getPropertyValue(), jobStepDefinitionPropertyClass); + } } } catch (KapuaIllegalArgumentException kiae) {