Skip to content

Commit

Permalink
Merge branch 'backport-4161' into release-2.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Coduz committed Dec 20, 2024
2 parents 27c63cc + a550329 commit f2a9944
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
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 javax.batch.runtime.BatchStatus;
import javax.batch.runtime.Metric;
import javax.batch.runtime.context.StepContext;
import javax.xml.bind.DatatypeConverter;
import javax.xml.bind.JAXBException;
import java.io.Serializable;
import java.util.Properties;

Expand Down Expand Up @@ -92,10 +90,15 @@ public <T, E extends Enum<E>> T getStepProperty(String stepPropertyName, Class<T
throw new KapuaIllegalArgumentException(stepPropertyName, stepPropertyString);
}
} else {
// Try both formats: XML - JSON
try {
stepProperty = XmlUtil.unmarshal(stepPropertyString, type);
} catch (JAXBException | SAXException e) {
throw new KapuaIllegalArgumentException(stepPropertyName, stepPropertyString);
} catch (Exception eXml) {
try {
stepProperty = XmlUtil.unmarshalJson(stepPropertyString, type);
} catch (Exception eJson) {
throw new KapuaIllegalArgumentException(stepPropertyName, stepPropertyString);
}
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public DeviceConfigurationPutJobStepDefinition() {
Lists.newArrayList(
new JobStepPropertyRecord(
DeviceConfigurationPutPropertyKeys.CONFIGURATION,
"XML string that defines the configuration update sent",
"XML or JSON string that defines the configuration update sent to the target devices",
DeviceConfiguration.class.getName(),
null,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<configurations xmlns:ns0=\"http://www.osgi.org/xmlns/metatype/v1.2.0\">\n <configuration>\n <id>org.eclipse.kura.demo.heater.Heater</id>\n <properties>\n <property name=\"temperature.increment\" array=\"false\" encrypted=\"false\" type=\"Float\">\n <value>0.25</value>\n </property>\n <property name=\"publish.rate\" array=\"false\" encrypted=\"false\" type=\"Integer\">\n <value>60</value>\n </property>\n <property name=\"program.stopTime\" array=\"false\" encrypted=\"false\" type=\"String\">\n <value>22:00</value>\n </property>\n <property name=\"publish.retain\" array=\"false\" encrypted=\"false\" type=\"Boolean\">\n <value>false</value>\n </property>\n <property name=\"service.pid\" array=\"false\" encrypted=\"false\" type=\"String\">\n <value>org.eclipse.kura.demo.heater.Heater</value>\n </property>\n <property name=\"kura.service.pid\" array=\"false\" encrypted=\"false\" type=\"String\">\n <value>org.eclipse.kura.demo.heater.Heater</value>\n </property>\n <property name=\"program.startTime\" array=\"false\" encrypted=\"false\" type=\"String\">\n <value>06:00</value>\n </property>\n <property name=\"mode\" array=\"false\" encrypted=\"false\" type=\"String\">\n <value>Program</value>\n </property>\n <property name=\"publish.semanticTopic\" array=\"false\" encrypted=\"false\" type=\"String\">\n <value>data/210</value>\n </property>\n <property name=\"manual.setPoint\" array=\"false\" encrypted=\"false\" type=\"Float\">\n <value>30.0</value>\n </property>\n <property name=\"publish.qos\" array=\"false\" encrypted=\"false\" type=\"Integer\">\n <value>2</value>\n </property>\n <property name=\"temperature.initial\" array=\"false\" encrypted=\"false\" type=\"Float\">\n <value>13.0</value>\n </property>\n <property name=\"program.setPoint\" array=\"false\" encrypted=\"false\" type=\"Float\">\n <value>30.0</value>\n </property>\n </properties>\n </configuration>\n</configurations>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,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,
Expand Down Expand Up @@ -414,8 +415,17 @@ private void validateJobStepProperties(List<JobStepProperty> 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);
}
Expand Down Expand Up @@ -447,7 +457,12 @@ private <C extends Comparable<C>, E extends Enum<E>> void validateJobStepPropert
Class<E> jobStepDefinitionPropertyClassEnum = (Class<E>) 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) {
Expand Down

0 comments on commit f2a9944

Please sign in to comment.