Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename IsInsideExternalXtf functions #48

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

public final class IsInsideExternalDatasetIoxPlugin extends BaseIsInsideFunction {
public final class IsInsideExternalXtfIoxPlugin extends BaseIsInsideFunction {
private static File dataDirectory;
private static Map<String, Set<URL>> modelFilesFromDataDirectory;
private static Map<String, Set<URL>> modelFilesFromJars;
private static final Map<ValidAreaKey, Geometry> VALID_AREA_CACHE = new HashMap<>();
private static final String QUALIFIED_ILI_NAME = "GeoW_FunctionsExt.IsInsideExternalDataset";
private static final String QUALIFIED_ILI_NAME = "GeoW_FunctionsExt.IsInsideExternalXtf";

@Override
public String getQualifiedIliName() {
Expand Down Expand Up @@ -113,7 +113,7 @@ private Collection<URL> getUrlsForModel(String model) {
* @return A {@link File} representing the directory or {@code null}.
*/
private File getDataDirectory() {
Class<IsInsideExternalDatasetIoxPlugin> pluginClass = IsInsideExternalDatasetIoxPlugin.class;
Class<IsInsideExternalXtfIoxPlugin> pluginClass = IsInsideExternalXtfIoxPlugin.class;
URL resource = pluginClass.getResource(pluginClass.getSimpleName() + ".class");
if (resource == null) {
logger.addEvent(logger.logErrorMsg(MessageFormat.format("{0}: Could not resolve data directory, resource is null.", this.getQualifiedIliName())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import java.util.List;
import java.util.Map;

public final class IsInsideExternalDatasetResourceIoxPlugin extends BaseIsInsideFunction {
public final class IsInsideExternalXtfResourceIoxPlugin extends BaseIsInsideFunction {
private static final Map<ValidAreaKey, Geometry> VALID_AREA_CACHE = new HashMap<>();
private static final String QUALIFIED_ILI_NAME = "GeoW_FunctionsExt.IsInsideExternalDatasetResource";
private static final String QUALIFIED_ILI_NAME = "GeoW_FunctionsExt.IsInsideExternalXtfResource";

@Override
public String getQualifiedIliName() {
Expand Down
4 changes: 2 additions & 2 deletions src/model/GeoW_FunctionsExt.ili
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ MODEL GeoW_FunctionsExt
!!@ fn.param = "DatasetName: Qualifizierter Name des Attributes aus dem Transfermodell, in welchem die Objekte zur Prüfung bereitliegen. Objects: Objekt(e), über die TID identifiziert, welche zur Prüfung beigezogen werden. TestObject: Objekt, welches zu prüfen ist. TestObjectgeometry: Geometriefeld, bezogen auf das unter Testobject übergebene Objekt";
!!@ fn.return = "Boolean";
!!@ fn.since = "2022-12-05";
FUNCTION IsInsideExternalDataset (DatasetName: TEXT; Objects: TEXT; TestObject: OBJECT OF ANYCLASS; TestObjectgeometry: TEXT): BOOLEAN;
FUNCTION IsInsideExternalXtf (DatasetName: TEXT; Objects: TEXT; TestObject: OBJECT OF ANYCLASS; TestObjectgeometry: TEXT): BOOLEAN;

!!@ fn.description = "Prüft, ob ein Objekt innerhalb einer gegebenen Testgeometrie liegt, welche aus einem externen Datensatz innerhalb der Ressourcen stammt. Der externe Datensatz muss sich in einer INTERLIS 2.3 Transferdatei befinden, die über den angegebenen Pfad als Ressource erreichbar ist.";
!!@ fn.param = "TransferFile: Qualifizierter Name der Transferdatei-Ressource. DatasetName: Qualifizierter Name des Attributes aus dem Transfermodell, in welchem die Objekte zur Prüfung bereitliegen. Objects: Objekt(e), über die TID identifiziert, welche zur Prüfung beigezogen werden. TestObject: Objekt, welches zu prüfen ist. TestObjectgeometry: Geometriefeld, bezogen auf das unter Testobject übergebene Objekt";
!!@ fn.return = "Boolean";
!!@ fn.since = "2023-12-20";
FUNCTION IsInsideExternalDatasetResource (TransferFile: TEXT; DatasetName: TEXT; Objects: TEXT; TestObject: OBJECT OF ANYCLASS; TestObjectgeometry: TEXT): BOOLEAN;
FUNCTION IsInsideExternalXtfResource (TransferFile: TEXT; DatasetName: TEXT; Objects: TEXT; TestObject: OBJECT OF ANYCLASS; TestObjectgeometry: TEXT): BOOLEAN;

!!@ fn.description = "Prüft, ob ein Objekt innerhalb der Geometrie eines anderen Objektes liegt.";
!!@ fn.param = "ReferenceObject: Referenzobjekt oder -geometrie, innerhalb welcher das TestObject liegen muss. ReferenceGeometryAttr: Pfad zum Geometrieattribut vom Referenzobjekt oder UNDEFINED. TestObject: Objekt, welches zu prüfen ist. TestObjectgeometry: Geometriefeld, bezogen auf das unter Testobject übergebene Objekt";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,54 +24,54 @@ MODEL TestSuite

CLASS Area EXTENDS ConstraintTestClass =
testAttributeArea : AREA WITH (STRAIGHTS) VERTEX CHKoord3d WITHOUT OVERLAPS > 0.001;
MANDATORY CONSTRAINT Area: GeoW_FunctionsExt.IsInsideExternalDataset("swissBOUNDARIES3D_ili2_LV95_V1_3.TLM_GRENZEN.TLM_KANTONSGEBIET.Shape", "9230, 9245, 9247, 9257", THIS, "testAttributeArea") == expected;
MANDATORY CONSTRAINT Area: GeoW_FunctionsExt.IsInsideExternalXtf("swissBOUNDARIES3D_ili2_LV95_V1_3.TLM_GRENZEN.TLM_KANTONSGEBIET.Shape", "9230, 9245, 9247, 9257", THIS, "testAttributeArea") == expected;
END Area;

CLASS Surface EXTENDS ConstraintTestClass =
testAttributeSurface : SURFACE WITH (STRAIGHTS) VERTEX CHKoord WITHOUT OVERLAPS > 0.001;
MANDATORY CONSTRAINT Surface: GeoW_FunctionsExt.IsInsideExternalDataset("swissBOUNDARIES3D_ili2_LV95_V1_3.TLM_GRENZEN.TLM_KANTONSGEBIET.Shape", "9230,9245,9247,9257", THIS, "testAttributeSurface") == expected;
MANDATORY CONSTRAINT Surface: GeoW_FunctionsExt.IsInsideExternalXtf("swissBOUNDARIES3D_ili2_LV95_V1_3.TLM_GRENZEN.TLM_KANTONSGEBIET.Shape", "9230,9245,9247,9257", THIS, "testAttributeSurface") == expected;
END Surface;

CLASS MultiSurface EXTENDS ConstraintTestClass =
testAttributeMultiSurface : MULTISURFACE WITH (STRAIGHTS) VERTEX CHKoord3d WITHOUT OVERLAPS > 0.001;
MANDATORY CONSTRAINT MultiSurface: GeoW_FunctionsExt.IsInsideExternalDataset("swissBOUNDARIES3D_ili2_LV95_V1_3.TLM_GRENZEN.TLM_KANTONSGEBIET.Shape", "9230,9245,9247,9257", THIS, "testAttributeMultiSurface") == expected;
MANDATORY CONSTRAINT MultiSurface: GeoW_FunctionsExt.IsInsideExternalXtf("swissBOUNDARIES3D_ili2_LV95_V1_3.TLM_GRENZEN.TLM_KANTONSGEBIET.Shape", "9230,9245,9247,9257", THIS, "testAttributeMultiSurface") == expected;
END MultiSurface;

CLASS Polyline3d EXTENDS ConstraintTestClass =
testAttributePolyline3d : POLYLINE WITH (STRAIGHTS) VERTEX CHKoord3d;
MANDATORY CONSTRAINT Polyline3d: GeoW_FunctionsExt.IsInsideExternalDataset("swissBOUNDARIES3D_ili2_LV95_V1_3.TLM_GRENZEN.TLM_KANTONSGEBIET.Shape", "9230,9245,9247,9257", THIS, "testAttributePolyline3d") == expected;
MANDATORY CONSTRAINT Polyline3d: GeoW_FunctionsExt.IsInsideExternalXtf("swissBOUNDARIES3D_ili2_LV95_V1_3.TLM_GRENZEN.TLM_KANTONSGEBIET.Shape", "9230,9245,9247,9257", THIS, "testAttributePolyline3d") == expected;
END Polyline3d;

CLASS MultiPolyline EXTENDS ConstraintTestClass =
testAttributeMultiPolyline : MULTIPOLYLINE WITH (STRAIGHTS) VERTEX CHKoord;
MANDATORY CONSTRAINT MultiPolyline: GeoW_FunctionsExt.IsInsideExternalDataset("swissBOUNDARIES3D_ili2_LV95_V1_3.TLM_GRENZEN.TLM_KANTONSGEBIET.Shape", "9230,9245,9247,9257", THIS, "testAttributeMultiPolyline") == expected;
MANDATORY CONSTRAINT MultiPolyline: GeoW_FunctionsExt.IsInsideExternalXtf("swissBOUNDARIES3D_ili2_LV95_V1_3.TLM_GRENZEN.TLM_KANTONSGEBIET.Shape", "9230,9245,9247,9257", THIS, "testAttributeMultiPolyline") == expected;
END MultiPolyline;

CLASS Point2d EXTENDS ConstraintTestClass =
testAttributePoint2d : CHKoord;
MANDATORY CONSTRAINT Point2D: GeoW_FunctionsExt.IsInsideExternalDataset("swissBOUNDARIES3D_ili2_LV95_V1_3.TLM_GRENZEN.TLM_KANTONSGEBIET.Shape", "9230,9245,9247,9257", THIS, "testAttributePoint2d") == expected;
MANDATORY CONSTRAINT Point2D: GeoW_FunctionsExt.IsInsideExternalXtf("swissBOUNDARIES3D_ili2_LV95_V1_3.TLM_GRENZEN.TLM_KANTONSGEBIET.Shape", "9230,9245,9247,9257", THIS, "testAttributePoint2d") == expected;
END Point2d;

CLASS Point3d EXTENDS ConstraintTestClass =
testAttributePoint3d : CHKoord3d;
MANDATORY CONSTRAINT Point3d: GeoW_FunctionsExt.IsInsideExternalDataset("swissBOUNDARIES3D_ili2_LV95_V1_3.TLM_GRENZEN.TLM_KANTONSGEBIET.Shape", "9230,9245,9247,9257", THIS, "testAttributePoint3d") == expected;
MANDATORY CONSTRAINT Point3d: GeoW_FunctionsExt.IsInsideExternalXtf("swissBOUNDARIES3D_ili2_LV95_V1_3.TLM_GRENZEN.TLM_KANTONSGEBIET.Shape", "9230,9245,9247,9257", THIS, "testAttributePoint3d") == expected;
END Point3d;

CLASS MultiCoord EXTENDS ConstraintTestClass =
testAttributeMultiCoord : CHMultiKoord;
MANDATORY CONSTRAINT MultiCoord: GeoW_FunctionsExt.IsInsideExternalDataset("swissBOUNDARIES3D_ili2_LV95_V1_3.TLM_GRENZEN.TLM_KANTONSGEBIET.Shape", "9230,9245,9247,9257", THIS, "testAttributeMultiCoord") == expected;
MANDATORY CONSTRAINT MultiCoord: GeoW_FunctionsExt.IsInsideExternalXtf("swissBOUNDARIES3D_ili2_LV95_V1_3.TLM_GRENZEN.TLM_KANTONSGEBIET.Shape", "9230,9245,9247,9257", THIS, "testAttributeMultiCoord") == expected;
END MultiCoord;

CLASS IsInsideCHBaseGeometrie EXTENDS ConstraintTestClass =
testAttributeIsInsideCHBaseGeometrie : CHKoord;
MANDATORY CONSTRAINT IsInsideCHBaseGeometrie: GeoW_FunctionsExt.IsInsideExternalDataset("SO_Hoheitsgrenzen_Publikation_20170626.Hoheitsgrenzen.Kantonsgrenze.Geometrie", "fubar", THIS, "testAttributeIsInsideCHBaseGeometrie") == expected;
MANDATORY CONSTRAINT IsInsideCHBaseGeometrie: GeoW_FunctionsExt.IsInsideExternalXtf("SO_Hoheitsgrenzen_Publikation_20170626.Hoheitsgrenzen.Kantonsgrenze.Geometrie", "fubar", THIS, "testAttributeIsInsideCHBaseGeometrie") == expected;
END IsInsideCHBaseGeometrie;

CLASS InvalidConstraints =
geometryAttribute : CHKoord;
MANDATORY CONSTRAINT MalformedDatasetName: GeoW_FunctionsExt.IsInsideExternalDataset("DatasetNameWithoutQualifiedAttribute", "906645", THIS, "geometryAttribute");
MANDATORY CONSTRAINT NonExistentDatasetName: GeoW_FunctionsExt.IsInsideExternalDataset("DoesNotExist.AwesomeTopic.AwesomeClass.NondescriptAttribute", "788070", THIS, "geometryAttribute");
MANDATORY CONSTRAINT NonExistentTransferIds: GeoW_FunctionsExt.IsInsideExternalDataset("swissBOUNDARIES3D_ili2_LV95_V1_3.TLM_GRENZEN.TLM_KANTONSGEBIET.Shape", "9999,100000000", THIS, "geometryAttribute");
MANDATORY CONSTRAINT MalformedDatasetName: GeoW_FunctionsExt.IsInsideExternalXtf("DatasetNameWithoutQualifiedAttribute", "906645", THIS, "geometryAttribute");
MANDATORY CONSTRAINT NonExistentDatasetName: GeoW_FunctionsExt.IsInsideExternalXtf("DoesNotExist.AwesomeTopic.AwesomeClass.NondescriptAttribute", "788070", THIS, "geometryAttribute");
MANDATORY CONSTRAINT NonExistentTransferIds: GeoW_FunctionsExt.IsInsideExternalXtf("swissBOUNDARIES3D_ili2_LV95_V1_3.TLM_GRENZEN.TLM_KANTONSGEBIET.Shape", "9999,100000000", THIS, "geometryAttribute");
END InvalidConstraints;

END FunctionTestTopic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ MODEL TestSuite

CLASS IsInsideSOKantonsgrenze EXTENDS ConstraintTestClass =
testAttributeIsInsideSOKantonsgrenze : CHKoord;
MANDATORY CONSTRAINT IsInsideSOKantonsgrenze: GeoW_FunctionsExt.IsInsideExternalDatasetResource("IsInsideExternalDatasetResource/ch.so.agi.av.hoheitsgrenzen_excerpt.xtf", "SO_Hoheitsgrenzen_Publikation_20170626.Hoheitsgrenzen.Kantonsgrenze.Geometrie", "fubar", THIS, "testAttributeIsInsideCHBaseGeometrie") == expected;
MANDATORY CONSTRAINT IsInsideSOKantonsgrenze: GeoW_FunctionsExt.IsInsideExternalXtfResource("IsInsideExternalXtfResource/ch.so.agi.av.hoheitsgrenzen_excerpt.xtf", "SO_Hoheitsgrenzen_Publikation_20170626.Hoheitsgrenzen.Kantonsgrenze.Geometrie", "fubar", THIS, "testAttributeIsInsideSOKantonsgrenze") == expected;
END IsInsideSOKantonsgrenze;

CLASS InvalidConstraints =
geometryAttribute : CHKoord;
MANDATORY CONSTRAINT MalformedDatasetName: GeoW_FunctionsExt.IsInsideExternalDatasetResource("IsInsideExternalDatasetResource/ch.so.agi.av.hoheitsgrenzen_excerpt.xtf", "DatasetNameWithoutQualifiedAttribute", "fubar", THIS, "geometryAttribute");
MANDATORY CONSTRAINT NonExistentTransferFile: GeoW_FunctionsExt.IsInsideExternalDatasetResource("NotExistingFile.xtf", "SO_Hoheitsgrenzen_Publikation_20170626.Hoheitsgrenzen.Kantonsgrenze.Geometrie", "fubar", THIS, "geometryAttribute");
MANDATORY CONSTRAINT NonExistentTransferIds: GeoW_FunctionsExt.IsInsideExternalDatasetResource("IsInsideExternalDatasetResource/ch.so.agi.av.hoheitsgrenzen_excerpt.xtf", "SO_Hoheitsgrenzen_Publikation_20170626.Hoheitsgrenzen.Kantonsgrenze.Geometrie", "9999,100000000", THIS, "geometryAttribute");
MANDATORY CONSTRAINT MalformedDatasetName: GeoW_FunctionsExt.IsInsideExternalXtfResource("IsInsideExternalXtfResource/ch.so.agi.av.hoheitsgrenzen_excerpt.xtf", "DatasetNameWithoutQualifiedAttribute", "fubar", THIS, "geometryAttribute");
MANDATORY CONSTRAINT NonExistentTransferFile: GeoW_FunctionsExt.IsInsideExternalXtfResource("NotExistingFile.xtf", "SO_Hoheitsgrenzen_Publikation_20170626.Hoheitsgrenzen.Kantonsgrenze.Geometrie", "fubar", THIS, "geometryAttribute");
MANDATORY CONSTRAINT NonExistentTransferIds: GeoW_FunctionsExt.IsInsideExternalXtfResource("IsInsideExternalXtfResource/ch.so.agi.av.hoheitsgrenzen_excerpt.xtf", "SO_Hoheitsgrenzen_Publikation_20170626.Hoheitsgrenzen.Kantonsgrenze.Geometrie", "9999,100000000", THIS, "geometryAttribute");
END InvalidConstraints;

END FunctionTestTopic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,36 @@
import java.io.File;
import java.lang.reflect.Field;

class IsInsideExternalDatasetIoxPluginTest {
private static final String TEST_DATA = "IsInsideExternalDataset/TestData.xtf";
class IsInsideExternalXtfIoxPluginTest {
private static final String TEST_DATA = "IsInsideExternalXtf/TestData.xtf";
ValidationTestHelper vh;

@BeforeEach
void setUp() throws NoSuchFieldException, IllegalAccessException {
IsInsideExternalDatasetIoxPlugin interlisFunction = new IsInsideExternalDatasetIoxPlugin();
IsInsideExternalXtfIoxPlugin interlisFunction = new IsInsideExternalXtfIoxPlugin();

Field dataDirectory = IsInsideExternalDatasetIoxPlugin.class.getDeclaredField("dataDirectory");
Field dataDirectory = IsInsideExternalXtfIoxPlugin.class.getDeclaredField("dataDirectory");
dataDirectory.setAccessible(true);
dataDirectory.set(null, new File("src/test/data/IsInsideExternalDataset").getAbsoluteFile());
dataDirectory.set(null, new File("src/test/data/IsInsideExternalXtf").getAbsoluteFile());

vh = new ValidationTestHelper();
vh.addFunction(interlisFunction);
}

@Test
void isInsideExternalDataset() throws Ili2cFailure, IoxException {
vh.runValidation(new String[]{TEST_DATA}, new String[]{"IsInsideExternalDataset/MandatoryConstraintThis.ili"});
void isInsideExternalXtf() throws Ili2cFailure, IoxException {
vh.runValidation(new String[]{TEST_DATA}, new String[]{"IsInsideExternalXtf/MandatoryConstraintThis.ili"});

Assert.equals(6, vh.getErrs().size());
AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "TestSuite.FunctionTestTopic.InvalidConstraints.MalformedDatasetName: Unable to evaluate GeoW_FunctionsExt.IsInsideExternalDataset. Expected qualified attribute name but got <DatasetNameWithoutQualifiedAttribute>.");
AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "TestSuite.FunctionTestTopic.InvalidConstraints.NonExistentDatasetName: Unable to evaluate GeoW_FunctionsExt.IsInsideExternalDataset. Could not find Transferfile containing model <DoesNotExist>.");
AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "TestSuite.FunctionTestTopic.InvalidConstraints.NonExistentTransferIds: Unable to evaluate GeoW_FunctionsExt.IsInsideExternalDataset. Could not find objects with TID <100000000, 9999> in transfer file");
AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "TestSuite.FunctionTestTopic.InvalidConstraints.MalformedDatasetName: Unable to evaluate GeoW_FunctionsExt.IsInsideExternalXtf. Expected qualified attribute name but got <DatasetNameWithoutQualifiedAttribute>.");
AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "TestSuite.FunctionTestTopic.InvalidConstraints.NonExistentDatasetName: Unable to evaluate GeoW_FunctionsExt.IsInsideExternalXtf. Could not find Transferfile containing model <DoesNotExist>.");
AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "TestSuite.FunctionTestTopic.InvalidConstraints.NonExistentTransferIds: Unable to evaluate GeoW_FunctionsExt.IsInsideExternalXtf. Could not find objects with TID <100000000, 9999> in transfer file");
AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "Mandatory Constraint TestSuite.FunctionTestTopic.InvalidConstraints.MalformedDatasetName is not true.");
AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "Mandatory Constraint TestSuite.FunctionTestTopic.InvalidConstraints.NonExistentDatasetName is not true.");
AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "Mandatory Constraint TestSuite.FunctionTestTopic.InvalidConstraints.NonExistentTransferIds is not true.");

Assert.equals(1, vh.getWarn().size());
// Interlis 2.4 XTF files do not work.
AssertionHelper.assertLogEventsContainMessage(vh.getWarn(), "GeoW_FunctionsExt.IsInsideExternalDataset: Error while reading xtf file \\S*TestData.xtf. Expected TRANSFER, but transfer found.");
AssertionHelper.assertLogEventsContainMessage(vh.getWarn(), "GeoW_FunctionsExt.IsInsideExternalXtf: Error while reading xtf file \\S*TestData.xtf. Expected TRANSFER, but transfer found.");
}
}
Loading
Loading