### Complete Language Derivation and Serialization Example Source: https://lionweb.io/Guides-JVM/Guides-Kotlin/node-classes A full example demonstrating language derivation, node instantiation, and JSON serialization/deserialization using the LionWeb Kotlin API. ```kotlin import io.lionweb.model.impl.DynamicNode import io.lionweb.serialization.SerializationProvider import io.lionweb.kotlin.MetamodelRegistry import io.lionweb.kotlin.lwLanguage import kotlin.test.assertTrue fun main(args: Array) { val organizationLanguage = lwLanguage("Organization", Tenant::class, User::class, File::class, Directory::class, TextFile::class) val tenantConcept = organizationLanguage.getConceptByName("Tenant")!! val userConcept = organizationLanguage.getConceptByName("User")!! val fileConcept = organizationLanguage.getConceptByName("File")!! val directoryConcept = organizationLanguage.getConceptByName("Directory")!! val textFileConcept = organizationLanguage.getConceptByName("TextFile")!! val tenant1 = Tenant().apply { name = "My Tenant" users.add(User().apply { name = "Gino" password = "FerraraBiciclette87" }) directories.add(Directory().apply { name = "root" files.add(TextFile().apply { name = "foo.json" contents = "{}" }) }) } val jsonSerialization = SerializationProvider.getStandardJsonSerialization() val tenant1Serialized = jsonSerialization.serializeTreeToJsonString(tenant1) jsonSerialization.enableDynamicNodes() var deserializedTenant1 = jsonSerialization.deserializeToNodes(tenant1Serialized).first() assertTrue(deserializedTenant1 is DynamicNode) MetamodelRegistry.prepareJsonSerialization(jsonSerialization) deserializedTenant1 = jsonSerialization.deserializeToNodes(tenant1Serialized).first() assertTrue(deserializedTenant1 is Tenant) } ``` -------------------------------- ### Start the LionWeb Server Source: https://lionweb.io/Guides-JVM/server Commands to launch the server with various configurations. ```bash java -jar server--all.jar ``` ```bash java -jar server--all.jar --web-ui ``` ```bash java -jar server--all.jar \ --http-port 8080 \ --ws-port 8081 \ --web-ui \ --web-port 8082 \ --repository myproject ``` -------------------------------- ### Example of a Class Reference Source: https://lionweb.io/Introduction/nodes A conceptual example showing how a class inheritance reference is represented. ```text class A extends B { } ``` -------------------------------- ### Complete Serialization and Deserialization Example Source: https://lionweb.io/Guides-JVM/Guides-Java/serialization Demonstrates defining a language, creating model nodes, and handling serialization with dynamic nodes. ```java package com.example; import io.lionweb.lioncore.java.language.*; import io.lionweb.lioncore.java.model.ClassifierInstance; import io.lionweb.lioncore.java.model.Node; import io.lionweb.lioncore.java.model.impl.DynamicNode; import io.lionweb.lioncore.java.serialization.Instantiator; import io.lionweb.lioncore.java.serialization.JsonSerialization; import io.lionweb.lioncore.java.serialization.SerializationProvider; import io.lionweb.lioncore.java.serialization.data.SerializedClassifierInstance; import io.lionweb.lioncore.java.utils.NodeTreeValidator; import io.lionweb.lioncore.java.utils.ValidationResult; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; public class SerializationAPIExample { private static Concept taskListConcept; private static Concept taskConcept; private static Property nameProperty; private static Containment tasksContainment; private static Language taskLanguage; { defineLanguage(); } private static class TaskList extends DynamicNode { TaskList(String id) { super(id, taskListConcept); } TaskList() { this(UUID.randomUUID().toString()); } void addTask(Task task) { addChild(tasksContainment, task); } List getTasks() { return getChildren(tasksContainment).stream().map(n -> (Task) n).collect(Collectors.toList()); } } private static class Task extends DynamicNode { Task(String name) { this(UUID.randomUUID().toString(), name); } Task(String id, String name) { super(id, taskConcept); setName(name); } void setName(String name) { setPropertyValue(nameProperty, name); } String getName() { return (String) getPropertyValue(nameProperty); } } public static void defineLanguage() { // Define the 'TaskList' concept taskListConcept = new Concept("TaskList"); taskListConcept.setID("TaskList-id"); taskListConcept.setName("TaskList"); taskListConcept.setKey("TaskList"); taskListConcept.setAbstract(false); taskListConcept.setPartition(true); // Define the 'Task' concept taskConcept = new Concept("Task"); taskConcept.setID("Task-id"); taskConcept.setName("Task"); taskConcept.setKey("Task"); taskConcept.setAbstract(false); // Add a 'tasks' containment tasksContainment = new Containment() .setID("TasksList-tasks-id") .setName("tasks") .setKey("TasksList-tasks") .setMultiple(true) .setOptional(false) .setType(taskConcept); taskListConcept.addFeature(tasksContainment); // Add a 'name' property nameProperty = new Property(); nameProperty.setID("task-name-id"); nameProperty.setName("name"); nameProperty.setKey("task-name"); nameProperty.setType(LionCoreBuiltins.getString()); taskConcept.addFeature(nameProperty); // Define the language container taskLanguage = new Language(); taskLanguage.setID("task-id"); taskLanguage.setKey("task"); taskLanguage.setName("Task Language"); taskLanguage.setVersion("1.0"); taskLanguage.addElement(taskListConcept); taskLanguage.addElement(taskConcept); } public TaskList createTaskList() { // Create the model TaskList errands = new TaskList(); Task task1 = new Task("My Task #1"); errands.addTask(task1); Task task2 = new Task("My Task #2"); errands.addTask(task2); ValidationResult res = new NodeTreeValidator().validate(errands); if (!res.isSuccessful()) { throw new IllegalStateException("The tree is invalid: " + res); } return errands; } public static void main(String[] args) { SerializationAPIExample example = new SerializationAPIExample(); TaskList taskList = example.createTaskList(); JsonSerialization serialization = SerializationProvider.getStandardJsonSerialization(); String serialized = serialization.serializeTreesToJsonString(taskList); System.out.println("== Tasks list =="); System.out.println(serialized); System.out.println(); try { serialization.deserializeToNodes(serialized); throw new RuntimeException("We expect an exception"); } catch (IllegalArgumentException e) { // We expect this System.out.println("Expected error: " + e.getMessage()); } serialization.enableDynamicNodes();; ``` -------------------------------- ### Example of Property Values Source: https://lionweb.io/Introduction/nodes Examples of primitive property values defined by a Concept. ```text name: "MyClass" visibility: public isAbstract: false ``` -------------------------------- ### Install LionWeb Kotlin with Gradle Source: https://lionweb.io/Guides-JVM/Guides-Kotlin Add these dependencies to your build.gradle or build.gradle.kts file to include the core and client modules. ```kotlin dependencies { implementation("io.lionweb:lionweb-kotlin-2024.1-kotlin-core:${latest_version}") implementation("io.lionweb:lionweb-kotlin-2024.1-kotlin-client:${latest_version}") } ``` -------------------------------- ### Install LionWeb Kotlin with Maven Source: https://lionweb.io/Guides-JVM/Guides-Kotlin Add these dependency blocks to your pom.xml file to include the core and client modules. ```xml io.lionweb lionweb-2024.1-kotlin-core ${latest_version} io.lionweb lionweb-2024.1-kotlin-client ${latest_version} ``` -------------------------------- ### Reference structure with resolveInfo Source: https://lionweb.io/specification/serialization/serialization.html Example of a reference entry containing resolveInfo and a target reference ID. ```json "j": [ { "resolveInfo": "k", "reference": "l" } ] ``` -------------------------------- ### Install LionWeb Core via Gradle Kotlin DSL Source: https://lionweb.io/Guides-JVM/Guides-Java/getting-started Add the LionWeb core dependency using the Gradle Kotlin DSL. ```kotlin implementation("io.lionweb:lionweb-2024.1-core:${lionwebVersion}") ``` -------------------------------- ### LionCore M3 Serialization Example Source: https://lionweb.io/specification/metametamodel/lioncore.json A JSON representation of the LionCore M3 metametamodel, defining the Language, Concept, and Reference structures. ```json { "serializationFormatVersion": "2026.1", "languages": [ { "key": "LionCore-M3", "version": "2026.1" }, { "key": "LionCore-builtins", "version": "2026.1" } ], "nodes": [ { "id": "-id-LionCore-M3-2026-1", "classifier": { "language": "LionCore-M3", "version": "2026.1", "key": "Language" }, "properties": [ { "property": { "language": "LionCore-builtins", "version": "2026.1", "key": "LionCore-builtins-INamed-name" }, "value": "LionCore_M3" }, { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Language-version" }, "value": "2026.1" }, { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "IKeyed-key" }, "value": "LionCore-M3" } ], "containments": [ { "containment": { "language": "LionCore-M3", "version": "2026.1", "key": "Language-entities" }, "children": [ "-id-Annotation-2026-1", "-id-Concept-2026-1", "-id-Interface-2026-1", "-id-Containment-2026-1", "-id-DataType-2026-1", "-id-Enumeration-2026-1", "-id-EnumerationLiteral-2026-1", "-id-Feature-2026-1", "-id-Field-2026-1", "-id-Classifier-2026-1", "-id-Link-2026-1", "-id-Language-2026-1", "-id-LanguageEntity-2026-1", "-id-IKeyed-2026-1", "-id-PrimitiveType-2026-1", "-id-Property-2026-1", "-id-Reference-2026-1", "-id-StructuredDataType-2026-1" ] } ], "references": [ { "reference": { "language": "LionCore-M3", "version": "2026.1", "key": "Language-dependsOn" }, "targets": [] } ], "annotations": [], "parent": null }, { "id": "-id-Annotation-2026-1", "classifier": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept" }, "properties": [ { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-abstract" }, "value": "false" }, { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-partition" }, "value": "false" }, { "property": { "language": "LionCore-builtins", "version": "2026.1", "key": "LionCore-builtins-INamed-name" }, "value": "Annotation" }, { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "IKeyed-key" }, "value": "Annotation" } ], "containments": [ { "containment": { "language": "LionCore-M3", "version": "2026.1", "key": "Classifier-features" }, "children": [ "-id-Annotation-annotates-2026-1", "-id-Annotation-extends-2026-1", "-id-Annotation-implements-2026-1" ] } ], "references": [ { "reference": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-extends" }, "targets": [ { "resolveInfo": "LionWeb.LionCore_M3.Classifier", "reference": null } ] }, { "reference": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-implements" }, "targets": [] } ], "annotations": [], "parent": "-id-LionCore-M3-2026-1" }, { "id": "-id-Annotation-annotates-2026-1", "classifier": { "language": "LionCore-M3", "version": "2026.1", "key": "Reference" }, "properties": [ { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Link-multiple" }, "value": "false" }, { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Feature-optional" }, "value": "true" }, { "property": { "language": "LionCore-builtins", "version": "2026.1", "key": "LionCore-builtins-INamed-name" }, "value": "annotates" ``` -------------------------------- ### Install LionWeb Core via Gradle Source: https://lionweb.io/Guides-JVM/Guides-Java/getting-started Add the LionWeb core dependency to your Gradle build configuration. ```gradle dependencies { implementation("io.lionweb:lionweb-2024.1-core:$lionwebVersion") } ``` -------------------------------- ### LionCore M3 Serialization Example Source: https://lionweb.io/specification/metametamodel/metametamodel.html A partial JSON representation of the LionCore M3 model, showing the definition of the Language and Annotation entities. ```json { "serializationFormatVersion": "2026.1", "languages": [ { "key": "LionCore-M3", "version": "2026.1" }, { "key": "LionCore-builtins", "version": "2026.1" } ], "nodes": [ { "id": "-id-LionCore-M3-2026-1", "classifier": { "language": "LionCore-M3", "version": "2026.1", "key": "Language" }, "properties": [ { "property": { "language": "LionCore-builtins", "version": "2026.1", "key": "LionCore-builtins-INamed-name" }, "value": "LionCore_M3" }, { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Language-version" }, "value": "2026.1" }, { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "IKeyed-key" }, "value": "LionCore-M3" } ], "containments": [ { "containment": { "language": "LionCore-M3", "version": "2026.1", "key": "Language-entities" }, "children": [ "-id-Annotation-2026-1", "-id-Concept-2026-1", "-id-Interface-2026-1", "-id-Containment-2026-1", "-id-DataType-2026-1", "-id-Enumeration-2026-1", "-id-EnumerationLiteral-2026-1", "-id-Feature-2026-1", "-id-Field-2026-1", "-id-Classifier-2026-1", "-id-Link-2026-1", "-id-Language-2026-1", "-id-LanguageEntity-2026-1", "-id-IKeyed-2026-1", "-id-PrimitiveType-2026-1", "-id-Property-2026-1", "-id-Reference-2026-1", "-id-StructuredDataType-2026-1" ] } ], "references": [ { "reference": { "language": "LionCore-M3", "version": "2026.1", "key": "Language-dependsOn" }, "targets": [] } ], "annotations": [], "parent": null }, { "id": "-id-Annotation-2026-1", "classifier": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept" }, "properties": [ { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-abstract" }, "value": "false" }, { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-partition" }, "value": "false" }, { "property": { "language": "LionCore-builtins", "version": "2026.1", "key": "LionCore-builtins-INamed-name" }, "value": "Annotation" }, { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "IKeyed-key" }, "value": "Annotation" } ], "containments": [ { "containment": { "language": "LionCore-M3", "version": "2026.1", "key": "Classifier-features" }, "children": [ "-id-Annotation-annotates-2026-1", "-id-Annotation-extends-2026-1", "-id-Annotation-implements-2026-1" ] } ], "references": [ { "reference": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-extends" }, "targets": [ { "resolveInfo": "LionWeb.LionCore_M3.Classifier", "reference": null } ] }, { "reference": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-implements" }, "targets": [] } ], "annotations": [], "parent": "-id-LionCore-M3-2026-1" }, { "id": "-id-Annotation-annotates-2026-1", "classifier": { "language": "LionCore-M3", "version": "2026.1", "key": "Reference" }, "properties": [ { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Link-multiple" }, "value": "false" }, { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Feature-optional" }, "value": "true" }, { "property": { ``` -------------------------------- ### LionCore JSON Serialization Structure Source: https://lionweb.io/specification/metametamodel/metametamodel.html Example of serialized LionCore nodes representing concepts and containments. ```JSON { "language": "LionCore-M3", "version": "2026.1", "key": "IKeyed-key" }, "value": "Reference" } ], "containments": [ { "containment": { "language": "LionCore-M3", "version": "2026.1", "key": "Classifier-features" }, "children": [] } ], "references": [ { "reference": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-extends" }, "targets": [ { "resolveInfo": "LionWeb.LionCore_M3.Link", "reference": null } ] }, { "reference": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-implements" }, "targets": [] } ], "annotations": [], "parent": "-id-LionCore-M3-2026-1" }, { "id": "-id-StructuredDataType-2026-1", "classifier": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept" }, "properties": [ { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-abstract" }, "value": "false" }, { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-partition" }, "value": "false" }, { "property": { "language": "LionCore-builtins", "version": "2026.1", "key": "LionCore-builtins-INamed-name" }, "value": "StructuredDataType" }, { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "IKeyed-key" }, "value": "StructuredDataType" } ], "containments": [ { "containment": { "language": "LionCore-M3", "version": "2026.1", "key": "Classifier-features" }, "children": [ "-id-StructuredDataType-fields-2026-1" ] } ], "references": [ { "reference": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-extends" }, "targets": [ { "resolveInfo": "LionWeb.LionCore_M3.DataType", "reference": null } ] }, { "reference": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-implements" }, "targets": [] } ], "annotations": [], "parent": "-id-LionCore-M3-2026-1" }, { "id": "-id-StructuredDataType-fields-2026-1", "classifier": { "language": "LionCore-M3", "version": "2026.1", "key": "Containment" }, "properties": [ { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Link-multiple" }, "value": "true" }, { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Feature-optional" }, "value": "false" }, { "property": { "language": "LionCore-builtins", "version": "2026.1", "key": "LionCore-builtins-INamed-name" }, "value": "fields" }, { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "IKeyed-key" }, "value": "StructuredDataType-fields" } ], "containments": [], "references": [ { "reference": { "language": "LionCore-M3", "version": "2026.1", "key": "Link-type" }, "targets": [ { "resolveInfo": "LionWeb.LionCore_M3.Field", "reference": null } ] } ], "annotations": [], "parent": "-id-StructuredDataType-2026-1" } ``` -------------------------------- ### Install LionWeb Core via Maven Source: https://lionweb.io/Guides-JVM/Guides-Java/getting-started Add the LionWeb core dependency to your Maven project's pom.xml. ```xml io.lionweb lionweb-2024.1-core ${lionwebVersion} ``` -------------------------------- ### Define LionCore M3 Concepts and Features Source: https://lionweb.io/specification/metametamodel/metametamodel.html Examples of JSON structures representing M3 concepts like Property and Reference, including their properties, containments, and references. ```JSON "language": "LionCore-M3", "version": "2026.1", "key": "Classifier-features" }, "children": [] } ], "references": [ { "reference": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-extends" }, "targets": [ { "resolveInfo": "LionWeb.LionCore_M3.DataType", "reference": null } ] }, { "reference": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-implements" }, "targets": [] } ], "annotations": [], "parent": "-id-LionCore-M3-2026-1" }, { "id": "-id-Property-2026-1", "classifier": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept" }, "properties": [ { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-abstract" }, "value": "false" }, { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-partition" }, "value": "false" }, { "property": { "language": "LionCore-builtins", "version": "2026.1", "key": "LionCore-builtins-INamed-name" }, "value": "Property" }, { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "IKeyed-key" }, "value": "Property" } ], "containments": [ { "containment": { "language": "LionCore-M3", "version": "2026.1", "key": "Classifier-features" }, "children": [ "-id-Property-type-2026-1" ] } ], "references": [ { "reference": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-extends" }, "targets": [ { "resolveInfo": "LionWeb.LionCore_M3.Feature", "reference": null } ] }, { "reference": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-implements" }, "targets": [] } ], "annotations": [], "parent": "-id-LionCore-M3-2026-1" }, { "id": "-id-Property-type-2026-1", "classifier": { "language": "LionCore-M3", "version": "2026.1", "key": "Reference" }, "properties": [ { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Link-multiple" }, "value": "false" }, { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Feature-optional" }, "value": "false" }, { "property": { "language": "LionCore-builtins", "version": "2026.1", "key": "LionCore-builtins-INamed-name" }, "value": "type" }, { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "IKeyed-key" }, "value": "Property-type" } ], "containments": [], "references": [ { "reference": { "language": "LionCore-M3", "version": "2026.1", "key": "Link-type" }, "targets": [ { "resolveInfo": "LionWeb.LionCore_M3.DataType", "reference": null } ] } ], "annotations": [], "parent": "-id-Property-2026-1" }, { "id": "-id-Reference-2026-1", "classifier": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept" }, "properties": [ { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-abstract" }, "value": "false" }, { "property": { "language": "LionCore-M3", "version": "2026.1", "key": "Concept-partition" }, "value": "false" }, { "property": { "language": "LionCore-builtins", "version": "2026.1", "key": "LionCore-builtins-INamed-name" }, "value": "Reference" }, { "property": { ``` -------------------------------- ### Set up development environment Source: https://lionweb.io/Guides-JVM/development Initializes the project environment after cloning the repository. ```bash ./gradlew setup ``` -------------------------------- ### Invalid Structured Data Type Examples Source: https://lionweb.io/specification/serialization/serialization.html Examples demonstrating common serialization errors such as incorrect types, missing fields, or invalid keys. ```json { "amount-val": 42, "amount-cur": "cur-eur", "digital": false } ``` ```json {"decimal-int": "42"} ``` ```json {"decimal-int": "42", "decimal-frac": null} ``` ```json "decimal-int": "42", "decimal-frac": "0" ``` ```json {"int": "42", "frac": "0"} ``` ```json {"decimal-int": "42", "decimal-frac": "nothing"} ``` ```json {"decimal-int": "42", "decimal-frac": "0", "decimal-comment": "life question?"} ``` ```json { "complex-real": "{ \"decimal-int\": \"23\", \"decimal-frac\": \"17\"}", "complex-imaginary": { "decimal-int": "42", "decimal-frac": "0"} } ``` -------------------------------- ### Connect and Manage Nodes in LionWeb Repository Source: https://lionweb.io/Guides-JVM/Guides-Java/working-with-repository Demonstrates initializing a LionWebBulkClient, registering a language, creating partitions, adding children, and performing store/retrieve operations. ```java import io.lionweb.LionWebVersion; import io.lionweb.client.LionWebBulkClient; import io.lionweb.model.impl.DynamicNode; import io.lionweb.model.ClassifierInstanceUtils; import io.lionweb.model.Node; LionWebBulkClient client = new LionWebBulkClient.Builder() .withVersion(LionWebVersion.v2024_1) .withHostname("localhost") .withPort(3005) .withRepository("myRepo") .build(); client.getJsonSerialization().registerLanguage(PropertiesLanguage.propertiesLanguage); DynamicNode p1 = new DynamicNode("p1", PropertiesLanguage.propertiesPartition); client.createPartitions(client.getJsonSerialization().serializeNodesToJsonString(p1)); DynamicNode f1 = new DynamicNode("f1", PropertiesLanguage.propertiesFile); ClassifierInstanceUtils.setPropertyValueByName(f1, "path", "my-path-1.txt"); DynamicNode f2 = new DynamicNode("f2", PropertiesLanguage.propertiesFile); ClassifierInstanceUtils.setPropertyValueByName(f2, "path", "my-path-2.txt"); ClassifierInstanceUtils.addChild(p1, "files", f1); ClassifierInstanceUtils.addChild(p1, "files", f2); client.store(Collections.singletonList(p1)); List retrievedNodes = client.retrieve(Collections.singletonList("p1"), 10); assertEquals(1, retrievedNodes.size()); assertEquals(p1, retrievedNodes.get(0)); ``` -------------------------------- ### GET /inspection/nodesByLanguage Source: https://lionweb.io/Guides-JVM/server Groups nodes by their associated language. ```APIDOC ## GET /inspection/nodesByLanguage ### Description Returns the node inventory grouped by language. ### Method GET ### Endpoint /inspection/nodesByLanguage ### Query Parameters - **repository** (string) - Optional - The name of the repository to address. ``` -------------------------------- ### GET /inspection/nodesByClassifier Source: https://lionweb.io/Guides-JVM/server Classifies and lists node inventory by classifier. ```APIDOC ## GET /inspection/nodesByClassifier ### Description Returns the node inventory grouped by classifier. ### Method GET ### Endpoint /inspection/nodesByClassifier ### Query Parameters - **repository** (string) - Optional - The name of the repository to address. ``` -------------------------------- ### Build the LionWeb Server Source: https://lionweb.io/Guides-JVM/server Use Gradle to generate the self-contained shadow JAR for deployment. ```bash ./gradlew :server:shadowJar # Output: server/build/libs/server--all.jar ``` -------------------------------- ### Concept Definition Source: https://lionweb.io/specification/serialization/serialization.html Example of a concept definition utilizing properties and enumerations. ```text concept OpeningTime [id 44, key time_to_open] property day: DaysOfWeek [id 42, key day] property startHour: Integer [id 22, key starthour] property endHour: Integer [id 89, key endhour] ``` -------------------------------- ### Create Partitions and Add Children Source: https://lionweb.io/Guides-JVM/Guides-Java/working-with-repository Partitions must be created empty before adding children and storing them in the repository. ```java // Step 1: create the empty partition client.createPartitions(client.getJsonSerialization().serializeNodesToJsonString(partition)); // Step 2: add children and store partition.addChild(myContainment, childNode); client.store(Collections.singletonList(partition)); ``` -------------------------------- ### Enumeration Definition Source: https://lionweb.io/specification/serialization/serialization.html Example of an enumeration definition used for property typing. ```text enumeration DaysOfWeek [id 23, key days-of-week] literal Monday [id 34, key monday] literal Tuesday [id 2, key tttt] literal Wednesday [id 55, key 12398712] ``` -------------------------------- ### Initialize InMemoryServer for Testing Source: https://lionweb.io/Guides-JVM/Guides-Java/working-with-repository Use InMemoryServer to simulate a LionWeb server environment for unit and integration tests without requiring Docker. ```java import io.lionweb.LionWebVersion; import io.lionweb.client.LionWebBulkClient; import io.lionweb.client.inmemory.InMemoryServer; InMemoryServer server = new InMemoryServer(LionWebVersion.v2024_1); LionWebBulkClient client = server.connectClient(); client.getJsonSerialization().registerLanguage(myLanguage); // Create, store, and retrieve nodes exactly as you would with a real server DynamicNode partition = new DynamicNode("part-1", myPartitionConcept); client.createPartitions(client.getJsonSerialization().serializeNodesToJsonString(partition)); client.store(Collections.singletonList(partition)); List result = client.retrieve(Collections.singletonList("part-1"), Integer.MAX_VALUE); assertEquals(partition, result.get(0)); ``` -------------------------------- ### Apply code style Source: https://lionweb.io/Guides-JVM/development Formats the codebase according to project guidelines before committing changes. ```bash ./gradlew spotlessApply ``` -------------------------------- ### Implementing Heterogeneous Nodes in Java Source: https://lionweb.io/Guides-JVM/Guides-Java/working-with-nodes Demonstrates defining custom node classes by extending DynamicNode and configuring the corresponding language concepts. ```java package com.example; import io.lionweb.lioncore.java.language.*; import io.lionweb.lioncore.java.model.impl.DynamicNode; import io.lionweb.lioncore.java.utils.NodeTreeValidator; import io.lionweb.lioncore.java.utils.ValidationResult; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; public class HeterogeneousAPIExample { private static Concept taskListConcept; private static Concept taskConcept; private static Property nameProperty; private static Containment tasksContainment; private static Language taskLanguage; { defineLanguage(); } private class TaskList extends DynamicNode { TaskList() { super(UUID.randomUUID().toString(), taskListConcept); } void addTask(Task task) { addChild(tasksContainment, task); } List getTasks() { return getChildren(tasksContainment).stream().map(n -> (Task)n).collect(Collectors.toList()); } } private class Task extends DynamicNode { Task(String name) { super(UUID.randomUUID().toString(), taskConcept); setName(name); } void setName(String name) { setPropertyValue(nameProperty, name); } String getName() { return (String) getPropertyValue(nameProperty); } } public static void defineLanguage() { // Define the 'TaskList' concept taskListConcept = new Concept("TaskList"); taskListConcept.setID("TaskList-id"); taskListConcept.setName("TaskList"); taskListConcept.setKey("TaskList"); taskListConcept.setAbstract(false); taskListConcept.setPartition(true); // Define the 'Task' concept taskConcept = new Concept("Task"); taskConcept.setID("Task-id"); taskConcept.setName("Task"); taskConcept.setKey("Task"); taskConcept.setAbstract(false); // Add a 'tasks' containment tasksContainment = new Containment() .setID("TasksList-tasks-id") .setName("tasks") .setKey("TasksList-tasks") .setMultiple(true) .setOptional(false) .setType(taskConcept); taskListConcept.addFeature(tasksContainment); // Add a 'name' property nameProperty = new Property(); nameProperty.setID("task-name-id"); nameProperty.setName("name"); nameProperty.setKey("task-name"); nameProperty.setType(LionCoreBuiltins.getString()); taskConcept.addFeature(nameProperty); // Define the language container taskLanguage = new Language(); taskLanguage.setID("task-id"); taskLanguage.setKey("task"); taskLanguage.setName("Task Language"); taskLanguage.setVersion("1.0"); taskLanguage.addElement(taskListConcept); taskLanguage.addElement(taskConcept); } public void useSpecificClasses() { // Create the model TaskList errands = new TaskList(); Task task1 = new Task("My Task #1"); errands.addTask(task1); Task task2 = new Task("My Task #2"); errands.addTask(task2); ValidationResult res = new NodeTreeValidator().validate(errands); if (!res.isSuccessful()) { throw new IllegalStateException("The tree is invalid: " + res); } // Access the model List tasks = errands.getTasks(); System.out.println("Tasks found: " + tasks.size()); for (Task task : tasks) { System.out.println(" - " + task.getName()); } } public static void main(String[] args) { new HeterogeneousAPIExample().useSpecificClasses(); } } ``` -------------------------------- ### Connect a Java Client Source: https://lionweb.io/Guides-JVM/server Initialize a LionWebBulkClient to interact with the server's HTTP API. ```java import io.lionweb.LionWebVersion; import io.lionweb.client.LionWebBulkClient; LionWebBulkClient client = new LionWebBulkClient.Builder() .withVersion(LionWebVersion.v2024_1) .withHostname("localhost") .withPort(9239) .withRepository("repo") .build(); ``` -------------------------------- ### Valid Structured Data Type Examples Source: https://lionweb.io/specification/serialization/serialization.html Correctly formatted JSON representations for Amount, Decimal, and ComplexNumber types. ```json { "amount-val": "42", "amount-cur": "cur-eur", "digital": "false" } ``` ```json {"decimal-int": "42", "decimal-frac": "0"} ``` ```json { "complex-real": { "decimal-int": "23", "decimal-frac": "17"}, "complex-imaginary": { "decimal-int": "42", "decimal-frac": "0"} } ``` -------------------------------- ### Configure LionWeb dependencies Source: https://lionweb.io/Guides-JVM/Guides-Java/lionweb-archive Add the core and extensions libraries to your Gradle project. ```gradle // build.gradle.kts dependencies { implementation("io.lionweb:lionweb-2024-1-core:") implementation("io.lionweb:lionweb-2024.1-extensions:") } ``` -------------------------------- ### POST /createRepository Source: https://lionweb.io/Guides-JVM/server Creates a new named repository. ```APIDOC ## POST /createRepository ### Description Initializes a new repository with the specified name. ### Method POST ### Endpoint /createRepository ``` -------------------------------- ### Run tests and coverage Source: https://lionweb.io/Guides-JVM/development Executes the test suite and generates coverage reports. ```bash ./gradlew check && ./gradlew functionalTest ``` ```bash ./gradlew jacocoTestReport ``` -------------------------------- ### Manage repositories with LionWebClient Source: https://lionweb.io/Guides-JVM/Guides-Kotlin/client Methods for creating, deleting, and listing repositories within the LionWeb environment. ```kotlin client.createRepository("myRepo", LionWebVersion.v2024_1) ``` ```kotlin client.deleteRepository("myRepo") ``` ```kotlin val repos = client.listRepositories() ``` -------------------------------- ### POST /listRepositories Source: https://lionweb.io/Guides-JVM/server Lists all repositories currently managed by the server. ```APIDOC ## POST /listRepositories ### Description Returns a list of all available repositories. ### Method POST ### Endpoint /listRepositories ``` -------------------------------- ### Apply LionWeb Gradle Plugin Source: https://lionweb.io/Guides-JVM/Guides-Java/code-generation Apply the plugin in your build configuration using either Kotlin or Groovy DSL. ```kotlin plugins { id("io.lionweb") version "VERSION" } ``` ```groovy plugins { id "io.lionweb" version "VERSION" } ```