Skip to content

Commit

Permalink
supply runtime paramters at cmdline (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
claeis committed Dec 6, 2023
1 parent ed15a6a commit b523f56
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ilivalidator 1.14.0 (SNAPSHOT)
--------------------------------
- supply runtime paramters at cmdline (#383)
- ili2c-5.4.0
- iox-ili-1.22.0

Expand Down
29 changes: 28 additions & 1 deletion src/org/interlis2/validator/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

Expand All @@ -20,6 +21,7 @@
import ch.interlis.ili2c.Ili2cException;
import ch.interlis.ili2c.Ili2cFailure;
import ch.interlis.ili2c.gui.UserSettings;
import ch.interlis.ili2c.metamodel.GraphicParameterDef;
import ch.interlis.ili2c.metamodel.Model;
import ch.interlis.ili2c.metamodel.TransferDescription;
import ch.interlis.ilirepository.Dataset;
Expand Down Expand Up @@ -337,7 +339,16 @@ public boolean validate(
}
td.setActualRuntimeParameter(ch.interlis.ili2c.metamodel.RuntimeParameters.MINIMAL_RUNTIME_SYSTEM01_RUNTIME_SYSTEM_NAME, Main.APP_NAME);
td.setActualRuntimeParameter(ch.interlis.ili2c.metamodel.RuntimeParameters.MINIMAL_RUNTIME_SYSTEM01_RUNTIME_SYSTEM_VERSION, Main.getVersion());

java.util.Properties sysprops=System.getProperties();
for(ch.interlis.ili2c.metamodel.GraphicParameterDef param:getRuntimeParameters(td)) {
String paramName=param.getScopedName();
if(sysprops.containsKey(paramName)) {
String value=sysprops.getProperty(paramName);
if(value!=null) {
td.setActualRuntimeParameter(paramName, value);
}
}
}
// process data files
EhiLogger.logState("validate data...");
ch.interlis.iox_j.validator.Validator validator=null;
Expand Down Expand Up @@ -464,6 +475,22 @@ public boolean validate(
}
return ret;
}
private List<GraphicParameterDef> getRuntimeParameters(TransferDescription td) {
List<GraphicParameterDef> ret=new ArrayList<GraphicParameterDef>();
for(Iterator modelIt=td.iterator();modelIt.hasNext();) {
Object modelo=modelIt.next();
if(modelo instanceof Model) {
for(Iterator paramIt=((Model)modelo).iterator();paramIt.hasNext();) {
Object paramo=paramIt.next();
if(paramo instanceof GraphicParameterDef) {
ret.add((GraphicParameterDef)paramo);
}
}
}
}
return ret;
}

private Settings readMetaConfig(File metaConfigFile,OutParam<String> baseConfig) throws IOException {
Settings settings=new Settings();
ValidationConfig config = IniFileReader.readFile(metaConfigFile);
Expand Down
11 changes: 11 additions & 0 deletions test/data/runtimeParameter/RuntimeSystem23.ili
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ MODEL RuntimeSystem23

IMPORTS MinimalRuntimeSystem01;

PARAMETER
JobId : TEXT*150;

TOPIC TopicA =
CLASS ClassA =
attrA : TEXT;
Expand All @@ -20,5 +23,13 @@ MODEL RuntimeSystem23
END ClassB;
END TopicB;

TOPIC TopicC =
CLASS ClassC =
attrA : TEXT;
MANDATORY CONSTRAINT attrA==PARAMETER JobId;
END ClassC;
END TopicC;


END RuntimeSystem23.

5 changes: 5 additions & 0 deletions test/data/runtimeParameter/SimpleA.xtf
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@
<attrA>test/data/runtimeParameter/SimpleA.xtf</attrA>
</RuntimeSystem23.TopicB.ClassB>
</RuntimeSystem23.TopicB>
<RuntimeSystem23.TopicC BID="b3">
<RuntimeSystem23.TopicC.ClassC TID="o3">
<attrA>test1</attrA>
</RuntimeSystem23.TopicC.ClassC>
</RuntimeSystem23.TopicC>
</DATASECTION>
</TRANSFER>
6 changes: 1 addition & 5 deletions test/src/org/interlis2/validator/ValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

import static org.junit.Assert.*;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import ch.ehi.basics.logging.EhiLogger;
import ch.ehi.basics.settings.Settings;
import ch.interlis.iom.IomObject;
import ch.interlis.iom_j.xtf.XtfReader;
import ch.interlis.iom_j.xtf.XtfStartTransferEvent;
import ch.interlis.iox.EndBasketEvent;
import ch.interlis.iox.EndTransferEvent;
import ch.interlis.iox.IoxEvent;
Expand Down Expand Up @@ -101,15 +98,13 @@ public void xtfOkWithSettings() {
public void xtfInvalidPlaceholderSettingFail() {
Settings settings=new Settings();
settings.setValue(Validator.SETTING_ILIDIRS, "%ILI_DIR;http://models.interlis.ch/;%JAR_DIR/ilimodels");
EhiLogger.getInstance().setTraceFilter(false);
boolean ret=Validator.runValidation("test/data/Beispiel2a.xtf", settings);
assertFalse(ret);
}
@Test
public void xtfValidPlaceholderSettingOk() {
Settings settings=new Settings();
settings.setValue(Validator.SETTING_ILIDIRS, "%ITF_DIR;http://models.interlis.ch/;%JAR_DIR/ilimodels");
EhiLogger.getInstance().setTraceFilter(false);
boolean ret=Validator.runValidation("test/data/Beispiel2a.xtf", settings);
assertTrue(ret);
}
Expand Down Expand Up @@ -260,6 +255,7 @@ public void ili2cFail() {
}
@Test
public void xtfRuntimeParameterOk() {
System.setProperty("RuntimeSystem23.JobId", "test2");
boolean ret=Validator.runValidation("test/data/runtimeParameter/SimpleA.xtf", null);
assertTrue(ret);
}
Expand Down

0 comments on commit b523f56

Please sign in to comment.