Skip to content

Commit 633dc0f

Browse files
committed
Enhance Java aspect tooling documentation with extended validator usage and programmatic access details
1 parent c204060 commit 633dc0f

File tree

3 files changed

+61
-48
lines changed

3 files changed

+61
-48
lines changed

documentation/developer-guide/modules/tooling-guide/examples/ValidateAspectModel.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import java.util.List;
1919

2020
import org.eclipse.esmf.aspectmodel.loader.AspectModelLoader;
21+
import org.eclipse.esmf.aspectmodel.shacl.fix.Fix;
22+
import org.eclipse.esmf.aspectmodel.shacl.violation.EvaluationContext;
2123
import org.eclipse.esmf.aspectmodel.shacl.violation.Violation;
2224
import org.eclipse.esmf.aspectmodel.validation.services.AspectModelValidator;
2325
import org.eclipse.esmf.aspectmodel.validation.services.DetailedViolationFormatter;
@@ -38,11 +40,20 @@ public void validate() {
3840
new File( "aspect-models/org.eclipse.esmf.examples.movement/1.0.0/Movement.ttl" ) );
3941
// tag::validate[]
4042

43+
// tag::violations[]
4144
final List<Violation> violations = new AspectModelValidator().validateModel( aspectModel );
4245
if ( violations.isEmpty() ) {
4346
// Aspect Model is valid!
4447
return;
48+
} else {
49+
for (Violation violation : violations) {
50+
String errorCode = violation.errorCode();
51+
String message = violation.message();
52+
EvaluationContext context = violation.context();
53+
List<Fix> fixes = violation.fixes();
54+
}
4555
}
56+
// end::violations[]
4657

4758
final String validationReport = new ViolationFormatter().apply( violations ); // <1>
4859
final String detailedReport = new DetailedViolationFormatter().apply( violations );

documentation/developer-guide/modules/tooling-guide/pages/error-codes.adoc

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -232,50 +232,28 @@ Each error includes contextual information to help locate and resolve the issue:
232232
| **Shape** | The SHACL shape that detected the violation
233233
|===
234234

235-
[[accessing-error-information]]
236-
== Accessing Error Information
237-
238-
=== Programmatic Access
239-
240-
When using the Java API, errors are available through the `Violation` interface:
241-
242-
[source,java]
243-
----
244-
List<Violation> violations = validator.validateModel(aspectModel);
245-
for (Violation violation : violations) {
246-
String errorCode = violation.errorCode();
247-
String message = violation.message();
248-
EvaluationContext context = violation.context();
249-
List<Fix> fixes = violation.fixes();
250-
}
251-
----
252-
253-
[[error-resolution]]
254-
== Error Resolution Guide
255-
256-
257-
258235
[[troubleshooting]]
259236
== Troubleshooting
260237

261238
=== Common Issues
262239

263-
**Error Not Listed**: If you encounter an error code not documented here, check:
264-
- ESMF SDK version compatibility
265-
- Update to the latest documentation
266-
- Report missing documentation via GitHub issues
240+
* **Error Not Listed**: If you encounter an error code not documented here, check:
241+
** ESMF SDK version compatibility;
242+
** Update to the latest documentation;
243+
** Report missing documentation via GitHub issues.
267244

268-
**Inconsistent Error Messages**: Ensure you're using compatible versions of:
269-
- ESMF SDK
270-
- SAMM specification
271-
- Validation tools
245+
* **Inconsistent Error Messages**: Ensure you're using compatible versions of:
246+
** ESMF SDK;
247+
** SAMM specification;
248+
** Validation tools.
272249

273-
**Performance Issues**: For large models with many errors:
274-
- Process errors in batches
275-
- Use streaming validation where available
276-
- Consider model restructuring
250+
* **Performance Issues**: For large models with many errors:
251+
** Process errors in batches;
252+
** Use streaming validation where available;
253+
** Consider model restructuring.
277254

278255
=== Getting Help
279256

280257
For additional support:
281-
- ESMF SDK GitHub Issues: https://github.com/eclipse-esmf/esmf-sdk/issues
258+
259+
* **ESMF SDK GitHub Issues**: https://github.com/eclipse-esmf/esmf-sdk/issues

documentation/developer-guide/modules/tooling-guide/pages/java-aspect-tooling.adoc

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,20 @@ different structure can implement the `Violation.Visitor` Interface with a suita
346346
type `(String` used as an example here) and use the visitor to handle the different types of
347347
Violations in a type-safe way.
348348

349+
The `AspectModelValidator` also provides the `loadModel(Supplier<AspectModel>)` method that can be used in
350+
conjunction with `() -> new AspectModeLoader().load(...)` to have exceptions that might be created during the
351+
Aspect Model loading process, for example due to model resolution failures or syntax errors in the input
352+
files, be turned into a `List<Violation>` that can be passed to the aforementioned violation formatters. This
353+
allows for custom structured handling of problems that occur during model loading.
354+
355+
To include the model validator, use the following dependencies:
356+
357+
include::esmf-developer-guide:ROOT:partial$esmf-aspect-model-validator-artifact.adoc[]
358+
349359
=== Custom Error Formatting
350360

351-
In order to access validation violations in a type-safe way, implement the interface
352-
`org.eclipse.esmf.aspectmodel.shacl.violation.Violation.Visitor`. This allows you to handle each
361+
In order to access validation violations in a type-safe way, implement the interface
362+
`org.eclipse.esmf.aspectmodel.shacl.violation.Violation.Visitor`. This allows you to handle each
353363
violation type specifically and format error messages according to your application's requirements.
354364

355365
++++
@@ -369,25 +379,39 @@ include::example$CustomViolationFormatter.java[tags=imports]
369379
include::example$CustomViolationFormatter.java[tags=custom-formatter]
370380
----
371381

382+
=== Programmatic Access
383+
384+
When using the Java API, errors are available through the `Violation` interface:
385+
386+
[source,java]
387+
++++
388+
<details>
389+
<summary>Show used imports</summary>
390+
++++
391+
[source,java,indent=0,subs="+macros,+quotes"]
392+
----
393+
include::example$ValidateAspectModel.java[tags=imports]
394+
----
395+
++++
396+
</details>
397+
++++
398+
399+
[source,java,indent=0,subs="+macros,+quotes"]
400+
----
401+
include::example$ValidateAspectModel.java[tags=violations]
402+
----
403+
404+
372405
=== Error Aggregation
373406

374-
For applications that need to process multiple violations efficiently, you can group errors by type
407+
For applications that need to process multiple violations efficiently, you can group errors by type
375408
for batch processing:
376409

377410
[source,java,indent=0,subs="+macros,+quotes"]
378411
----
379412
include::example$CustomViolationFormatter.java[tags=error-aggregation]
380413
----
381414

382-
The `AspectModelValidator` also provides the `loadModel(Supplier<AspectModel>)` method that can be used in
383-
conjunction with `() -> new AspectModeLoader().load(...)` to have exceptions that might be created during the
384-
Aspect Model loading process, for example due to model resolution failures or syntax errors in the input
385-
files, be turned into a `List<Violation>` that can be passed to the aforementioned violation formatters. This
386-
allows for custom structured handling of problems that occur during model loading.
387-
388-
To include the model validator, use the following dependencies:
389-
390-
include::esmf-developer-guide:ROOT:partial$esmf-aspect-model-validator-artifact.adoc[]
391415

392416
[[generating-documentation]]
393417
== Generating Documentation for Aspect Models

0 commit comments

Comments
 (0)