opengisch / QgisModelBaker

Create QGIS projects from database schemas or Interlis models
https://opengisch.github.io/QgisModelBaker/
GNU Lesser General Public License v3.0
55 stars 17 forks source link

Data can only be exported with Tree Catalogue Data #629

Closed signedav closed 2 years ago

signedav commented 2 years ago

It's not possible to export data with validation from a model using codelists with CatalogueObjectTrees_V1 without exporting the catalogue data as well.

Error:

Info: validate mandatory constraint CatalogueObjectTrees_V1.Catalogues.CatalogueReference.Constraint1...
Error: line 0: Faults_V1.Faults.Fault: tid 93c252b1-4eac-4b85-b32e-b6d6ed59611b: Mandatory Constraint CatalogueObjectTrees_V1.Catalogues.CatalogueReference.Constraint1 is not true.

Having a model:

INTERLIS 2.3;
MODEL Faults_V1 (en)
AT "mailto:U80863546@localhost"
VERSION "2021-12-15"  =

  IMPORTS FaultsCatalogues_V1;

  TOPIC Faults =
    OID AS INTERLIS.UUIDOID;
  DEPENDS ON FaultsCatalogues_V1.Catalogues; 
    CLASS Fault = 
      Fault_Name : TEXT;
      Hierarchy : MANDATORY FaultsCatalogues_V1.Catalogues.FaultHierRef;
    END Fault;
  END Faults;

END Faults_V1. 

Using the catalogue:

INTERLIS 2.3;

MODEL FaultsCatalogues_V1 (en) 
AT "mailto:U80863546@localhost" 
VERSION "2021-12-15" =
IMPORTS CatalogueObjectTrees_V1,LocalisationCH_V1;

  TOPIC Catalogues =
    OID AS INTERLIS.UUIDOID;

    CLASS FaultHierItem
    EXTENDS CatalogueObjectTrees_V1.Catalogues.Item =
      IdName : MANDATORY TEXT;
      Name : MANDATORY LocalisationCH_V1.MultilingualText;
      Description : LocalisationCH_V1.MultilingualMText;
    END FaultHierItem;

    STRUCTURE FaultHierRef
    EXTENDS CatalogueObjectTrees_V1.Catalogues.CatalogueReference =
      Reference (EXTENDED) : REFERENCE TO (EXTERNAL) FaultHierItem;
    END FaultHierRef;
  END Catalogues;
END FaultsCatalogues_V1.

With like data:

<?xml version="1.0" encoding="UTF-8"?><TRANSFER xmlns="http://www.interlis.ch/INTERLIS2.3">
<HEADERSECTION SENDER="ili2gpkg-4.6.1-63db90def1260a503f0f2d4cb846686cd4851184" VERSION="2.3"><MODELS><MODEL NAME="FaultsCatalogues_V1" VERSION="2021-12-15" URI="mailto:U80863546@localhost"></MODEL></MODELS></HEADERSECTION>
<DATASECTION>
<FaultsCatalogues_V1.Catalogues BID="b1e196b7-7d1a-4512-a5c2-5f36f52ba2cc">
<FaultsCatalogues_V1.Catalogues.FaultHierItem TID="a29e59ff-ab78-43cd-8a0d-9ab64037c4dd"><IsSuperItem>true</IsSuperItem><IsUseable>false</IsUseable><IdName>fault</IdName><Name><LocalisationCH_V1.MultilingualText><LocalisedText><LocalisationCH_V1.LocalisedText><Text>Störung</Text></LocalisationCH_V1.LocalisedText><LocalisationCH_V1.LocalisedText><Language>de</Language><Text>Störung</Text></LocalisationCH_V1.LocalisedText><LocalisationCH_V1.LocalisedText><Language>fr</Language><Text>faille</Text></LocalisationCH_V1.LocalisedText><LocalisationCH_V1.LocalisedText><Language>en</Language><Text>fault</Text></LocalisationCH_V1.LocalisedText></LocalisedText></LocalisationCH_V1.MultilingualText></Name></FaultsCatalogues_V1.Catalogues.FaultHierItem>
<FaultsCatalogues_V1.Catalogues.FaultHierItem TID="db473781-7aec-4100-80eb-9b366b05ffe5"><IsSuperItem>false</IsSuperItem><IsUseable>true</IsUseable><Parent REF="a29e59ff-ab78-43cd-8a0d-9ab64037c4dd"></Parent><IdName>subfault system</IdName><Name><LocalisationCH_V1.MultilingualText><LocalisedText><LocalisationCH_V1.LocalisedText><Text>Teilstörungssystem</Text></LocalisationCH_V1.LocalisedText><LocalisationCH_V1.LocalisedText><Language>de</Language><Text>Teilstörungssystem</Text></LocalisationCH_V1.LocalisedText><LocalisationCH_V1.LocalisedText><Language>fr</Language><Text>système de faille partiel</Text></LocalisationCH_V1.LocalisedText><LocalisationCH_V1.LocalisedText><Language>en</Language><Text>subfault system</Text></LocalisationCH_V1.LocalisedText></LocalisedText></LocalisationCH_V1.MultilingualText></Name></FaultsCatalogues_V1.Catalogues.FaultHierItem>
<FaultsCatalogues_V1.Catalogues.FaultHierItem TID="e17b72cb-e6fc-4e5e-ad2e-25b1d132b050"><IsSuperItem>false</IsSuperItem><IsUseable>true</IsUseable><Parent REF="a29e59ff-ab78-43cd-8a0d-9ab64037c4dd"></Parent><IdName>large-scale fault system</IdName><Name><LocalisationCH_V1.MultilingualText><LocalisedText><LocalisationCH_V1.LocalisedText><Text>Grossstörungssystem</Text></LocalisationCH_V1.LocalisedText><LocalisationCH_V1.LocalisedText><Language>de</Language><Text>Grossstörungssystem</Text></LocalisationCH_V1.LocalisedText><LocalisationCH_V1.LocalisedText><Language>fr</Language><Text>système de faille majeur</Text></LocalisationCH_V1.LocalisedText><LocalisationCH_V1.LocalisedText><Language>en</Language><Text>large-scale fault system</Text></LocalisationCH_V1.LocalisedText></LocalisedText></LocalisationCH_V1.MultilingualText></Name></FaultsCatalogues_V1.Catalogues.FaultHierItem>
</FaultsCatalogues_V1.Catalogues>
</DATASECTION>
</TRANSFER>

This might be because the constraint Reference->IsUseable of the model CatalogeObjectTrees_V1 from here http://models.geo.admin.ch/CH/CHBase_Part3_CATALOGUEOBJECTS_V1.ili seems to be checked even when this model is not passed to ili2db.

Kind of makes sense. The CatalogueReference is part of the data - not of the catalogues. But still the constraint concernes the catalogue data.

Btw. In the V2 of the CatalogueObject Model this constraint is not there anymore but it's 2.4 anyway.

zigertiger commented 2 years ago

I don't see any error in your model nor in your catalogue data... You are right, the integrity of the catalogue data is always checked. Because catalogue data are actually data that are involved in your particular transfer... So, in case of catalogue trees, the catalogue data must always be transferred, because of the Reference->IsUseable constraint.

One can consider this an inadequacy because catalogue data shall be an extended part of the model definition, but this is a conceptual question, not a technical one.

Your model and your data are correct, and also how the tool checks this data including the catalogue is correct.

Grz P.

zigertiger commented 2 years ago

So this I'd consider a very useful usabILIty hub extension!

signedav commented 2 years ago

Thanks a lot @zigertiger for your explanation. So it is how it is. One way is to make the validation with the "Model Baker Data Validator" and then export it without validation (but then you will have an "invalid" transfer file) or just import/export all your catalogues as well.

In what way you consider it as usabILIty hub extension here? What could be the needed use case?

signedav commented 2 years ago

Maybe this is related to #665

Edit; Not really related

signedav commented 2 years ago

Other thing is that when having BAG ... OF like here #637 (but using CatalogueTREE) the catalog should never be imported first. Because the Ref-Objects needs to contain a link to the parent (in the model). When importing the main model with import Catalog, everything works fine. When first importing catalogue model and then the main model, it will not work...

signedav commented 2 years ago

If this cannot be solved, it needs some documentation at least.