I look for a possibility to load A12 models (JSON) into a Java-Application and perform basic A12 checks on this - if existing, I would expect there are some.
The background is, there is a modifying (merging) of models in my project. Before deployment in a A12 server I would check, if the operation was basically successful.
Also, is there any example code?
Hi there!
I’m not sure how to validate Models but we did run the computations for documents in PI application ([here]<INTERNAL_LINK>), maybe you can start from here!
It may be helpful alto to look in the [Data Services Diagram!]<INTERNAL_LINK>
I currently try an approach with dataservices-core:
Extend project configuration:
testImplementation “com.mgmtp.a12.dataservices:dataservices-core:33.0.9”
Testcode:
public static void main(String[] args) throws Exception { DocumentModelSerializerImpl dmsi = new DocumentModelSerializerImpl(); FileReader fr = new FileReader("src/test/resources/moduleSources/denkmalantrag/Adresse_D.json"); IDocumentModel idm = dmsi.deserialize(fr); System.out.println(idm.getHeader().getId()); }
Thanks, that could be of help, too!
The kernel (de)serialization method offers indeed a basic check. For a more complete check, you can use com.mgmtp.a12.kernel.md.model.api.services.IDocumentModelService#checkConsistency.
Hint: Instead of using DocumentModelSerializerImpl (kernel internal implementation), you should go through our entry point DocumentModelServiceFactory.
There is a generic model consistency validation API available for A12 models.
The API is defined in the A12 Base product. You have to use the following maven artifact: com.mgmtp.a12.base:base-model-consistency
It only works when provided with model-specific consistency validation rules. As far as I know, those rules currently only exist for the form-model (as provided by the com.mgmtp.a12.formengine:formengine-form-model dependency) and maybe for the document model. I’m not sure about this one. Please ask the Kernel team.
The central class for model validation is: com.mgmtp.a12.model.consistency.ConsistencyValidator
There are methods to validate a single model or multiple models at once.
The constructor of the validator class requires you to implement and pass a ModelResolver interface that allows the validator to resolve references between models e.g. from a form model to a document models.
A pure form model validation can also be done with a command-line tool that is provided with the com.mgmtp.a12.formengine:formengine-model-consistency-check-cli artifact.
Edit: The ConsistencyValidator class also allows you to implement and add your own validation rules via the com.mgmtp.a12.model.consistency.ConsistencyValidator.CustomConsistencyRule interface.