Skip to main content

Binding

Connect your model to semi-structured files

External Format

External Format allows you to define a formal schema (eg : XSD, Json Schema) of your data using and bind this formal schema to your Studio model. External Format should be used for anything related to a format.

A) Starting with a data schema

Step 1: Create Schemaset

  1. Create a New SchemaSetExtFormat1
  2. Provide a name for the SchemaSet and select Flatdata as the type from the drop-down list ExtFormat2
  3. Add the schema definition with the + icon and add add your schema definition in the box ExtFormat3
  4. (Optional for flatdata) Provide id and location for your schema

Step 2: Generate corresponding models and binding

  1. Navigate to the Model Generation tab ExtFormat4

  2. Provide targetPackage (the package under which the classes would be generated) and binding path (path for the generated binding) ExtFormat5

  3. Click the Generate button. You should be able to preview the classes that will be generated.

  4. If the preview looks good, click Import and the classes will be added to your project

  5. If your flatdata schema has multiple sections and you want to generate a wrapper class linking all record classes, you can do so by providing a 'schemaClassName'

Step 3: Create a new service

  1. When working with external formats you need to use internalize instead of all queries. Internalize can be chained with checked(), graphFetch(), graphFetchChecked() depending on the requirements. See reference documentation for details.

  2. When defining a service with internalize, you don't need a mapping or runtime. You will only need to define a query (currently supported via Text Mode only).

  3. Define your service with query using internalize. You can find examples in the External Format showcase project, under the 'flatdata' package.

    • Example data: String[1]| Person ->internalize(PersonBinding, $data)->serialize(#Person{firstName,lastName}}#);
      • This query accepts input as a parameter named data. Query uses internalize function to deserialize this data into Person instances which are then serialized using the serialize function.
  4. Define tests for your service. You do not need to provide a connection test data as there are no connections. Your test data goes as a parameter in the test setup tab, because your query accepts data as a parameter.

  5. Run your test and validate the output.

  6. Save your test

Step 4: (Optional) Add M2M transform.

  1. Create your target model

  2. Create an M2M mapping between your target model and source model (auto-generated model from schema)

  3. Create a service chaining deserialization and M2M transform:

    • Query data: String[1]|TargetPerson.all()->graphFetch(#{TargetPerson{fullName}}#)->from(M2MMapping, Person->getRuntimeWithModelQueryConnection(PersonBinding, $data))->serialize(#{TargetPerson{fullName}}#);
      • This query accepts input as parameter named data. This input is deserialized into Person instances and wrapped into a runtime by this part of the query Person->getRuntimeWithModelQueryConnection(PersonBinding, $data). Once deserialization is achieved and generated instances are wrapped into runtime, the query executes from expression to perform a M2M transform.
  4. Define tests for your service. You do not need to provide connection test data because connection is generated implicitly using input. Your test data goes as a parameter in the test setup tab, because your query accepts data as a parameter.

  5. Run your test and validate the output.

  6. Save your test

B) Starting from a model definition

Tutorial coming soon.

More