mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
Restore model validation not to fail on diagnostic errors for rules and scripts (#5351)
* Restore model validation not to fail on diagnostic errors Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This commit is contained in:
+3
-1
@@ -331,10 +331,12 @@ public class ModelRepositoryImpl implements ModelRepository {
|
||||
|
||||
// Check for validation errors, but log them only
|
||||
try {
|
||||
String modelType = resource.getURI().fileExtension();
|
||||
final org.eclipse.emf.common.util.Diagnostic diagnostic = safeEmf
|
||||
.call(() -> Diagnostician.INSTANCE.validate(resource.getContents().getFirst()));
|
||||
for (org.eclipse.emf.common.util.Diagnostic d : diagnostic.getChildren()) {
|
||||
if (d.getSeverity() == org.eclipse.emf.common.util.Diagnostic.ERROR) {
|
||||
if (d.getSeverity() == org.eclipse.emf.common.util.Diagnostic.ERROR
|
||||
&& !"rules".equalsIgnoreCase(modelType) && !"script".equalsIgnoreCase(modelType)) {
|
||||
errors.add(d.getMessage());
|
||||
} else {
|
||||
warnings.add(d.getMessage());
|
||||
|
||||
+22
@@ -268,4 +268,26 @@ public class DSLRuleProviderTest extends JavaOSGiTest {
|
||||
Object x = context.getValue(QualifiedName.create("x"));
|
||||
assertThat(x, is(15));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRuleWithUntypedLambdaArgsDoesNotFailToLoad() {
|
||||
Collection<Rule> rules = dslRuleProvider.getAll();
|
||||
assertThat(rules.size(), is(0));
|
||||
|
||||
String model = """
|
||||
var lambdaWithUntypedArgs = [ foo | foo ]
|
||||
rule "RuleWithUntypedLambdaArgs"
|
||||
when
|
||||
System started
|
||||
then
|
||||
logInfo('Test', 'Test')
|
||||
end
|
||||
""";
|
||||
|
||||
modelRepository.addOrRefreshModel(TESTMODEL_NAME,
|
||||
new ByteArrayInputStream(model.getBytes(StandardCharsets.UTF_8)));
|
||||
Collection<Rule> actualRules = dslRuleProvider.getAll();
|
||||
|
||||
assertThat(actualRules.size(), is(1));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user