gchq / MagmaCore

Magma Core is a collection of Java Classes and utilities to enable HQDM objects and patterns to be created and consumed as RDF Linked Data.
Apache License 2.0
25 stars 4 forks source link

Not properly fetching ClassOfClassOfSpatioTemporalExtent #221

Closed Fabalab closed 2 months ago

Fabalab commented 3 months ago

Describe the bug ClassOfClassOfSpatioTemporalExtent is being fetched as a ClassOfSpatioTemporalExtent so that when it is cast, a ClassCastException is being thrown.

To Reproduce Run the following code:

public class Program {
    public static void main(String[] args) {
        final MagmaCoreService mcService = MagmaCoreServiceFactory.createWithJenaDatabase();

        final IriBase testIriBase = new IriBase("test", "https://example.com/test#");
        final IRI testIri = new IRI(testIriBase, "TestClassOfClassOfSpatioTemporalExtent");

        final ClassOfClassOfSpatioTemporalExtent testClassOfClassOfSpatioTemporalExtent = new ClassOfClassOfSpatioTemporalExtentBuilder(testIri).build();

        mcService.create(testClassOfClassOfSpatioTemporalExtent);

        final ClassOfClassOfSpatioTemporalExtent retrievedClassOfClassOfSpatioTemporalExtent = (ClassOfClassOfSpatioTemporalExtent) mcService.get(testIri);
    }
}

Which spits out the following error:

Exception in thread "main" java.lang.ClassCastException: class uk.gov.gchq.magmacore.hqdm.model.impl.ClassOfSpatioTemporalExtentImpl cannot be cast to class uk.gov.gchq.magmacore.hqdm.model.ClassOfClassOfSpatioTemporalExtent (uk.gov.gchq.magmacore.hqdm.model.impl.ClassOfSpatioTemporalExtentImpl and uk.gov.gchq.magmacore.hqdm.model.ClassOfClassOfSpatioTemporalExtent are in unnamed module of loader 'app')
    at uk.co.amrc.adg23537.Program.main(Program.java:38)

Expected behavior This should run with no errors or output.

Additional context Run on the current Main branch of MagmaCore

ClimbingAl commented 3 months ago

Just recreated error as described above. It is cause by an error in the HqdmObjectFactory.mapToThing(final String typeName, final IRI iri) switch-case statement for the offending type handled in the case "class_of_class_of_spatio_temporal_extent". It should return ClassServices.createClassOfClassOfSpatioTemporalExtent(iri); but instead returns ClassServices.createClassOfSpatioTemporalExtent(iri);. I have just corrected it locally and it works. I will submit a PR later for this fix. There is already an outstanding PR for HqdmObjectFactory but it also contains the error you found (see here).