Running the demo

Contents

On this page, you’ll run the finished application from this tutorial without going through the chapters. It takes a few minutes and gives you a local Enonic XP instance populated with the completed schemas, sample content and media, ready to inspect in Content Studio and query through Guillotine.

Want to learn how each part works? Start with the first chapter of the tutorial instead.

To run the demo you will need the Enonic CLI and Git, in addition to the prerequisites of the tutorial.

Task: Start Enonic

The demo runs in its own sandbox, a local instance of Enonic XP.

  1. Create the demo sandbox - Run this command in your terminal. It works from any folder:

    enonic sandbox create demo_modeling -t essentials -f

    The essentials template installs Content Studio and the Guillotine GraphQL API. The -f flag accepts the defaults for the remaining prompts, including the latest version of Enonic XP, and starts the sandbox.

    The demo uses its own sandbox (demo_modeling), separate from the tutorial_modeling sandbox used in the chapters. All sandboxes share port 8080 by default, so stop any other running sandbox before starting this one.
  2. Verify that the sandbox is running - Wait for the terminal to report that Enonic XP has started, then open http://localhost:8080. The Enonic SDK welcome page appears.

Leave the sandbox running in this terminal window. To stop it, press ctrl-c. To start it again later, run enonic sandbox start demo_modeling from any folder.

Task: Deploy the completed app

  1. Get the code - Open a new terminal window in the folder where you keep your tutorial projects, and clone the repository:

    git clone https://github.com/enonic/tutorial-content-modeling.git

    This creates a tutorial-content-modeling/ folder containing the finished com.example.tutorial.modeling application and its sample content.

  2. Link and deploy the app - Enter the folder, link it to the demo sandbox, and deploy:

    cd tutorial-content-modeling
    enonic project sandbox demo_modeling -f
    enonic project deploy -f

    The CLI builds the app and deploys it to demo_modeling. On first startup, the app creates the My First Project (my-first-project) content project, imports the sample artists, animals and images, and publishes them.

Task: Explore the content and GraphQL API

  1. Inspect the content in Content Studio - On the welcome page at http://localhost:8080, click Log In as Guest, then open XP menu → Content Studio.

    Select My First Project in the top bar if it is not already open. You’ll see the Animals, Artists and Images folders with 11 published content items — open Cardi B, Lion or Lynx to inspect their fields, references, rich text and Editorial mixin tab.

  2. Query the model in Query Playground - Click the GraphQL icon in Content Studio’s left menu bar, keep My First Project selected, and run this query:

    {
      guillotine {
        queryDsl(
          query: {
            term: {
              field: "type"
              value: { string: "com.example.tutorial.modeling:artist" }
            }
          }
          sort: [{ field: "displayName", direction: ASC }]
        ) {
          displayName
          ... on com_example_tutorial_modeling_Artist {
            data {
              legalName
              birthday
              filmography {
                title
                year
              }
              favoriteAnimal {
                displayName
                ... on com_example_tutorial_modeling_Animal {
                  data {
                    otherNames
                    feedingBehavior {
                      _selected
                    }
                    images {
                      ... on media_Image {
                        imageUrl(scale: "block(400,600)") {
                          path
                          queryString
                        }
                      }
                    }
                  }
                }
              }
            }
          }
          x {
            com_example_tutorial_modeling {
              editorial {
                notes
              }
            }
          }
        }
      }
    }

    The response returns Cardi B, Missy Elliott and P!nk along with their filmography item sets, linked favorite animals, feeding behavior option sets, cropped image URL components and editorial mixin notes.

  3. Test the public HTTP endpoint - Because the startup task published the content to master in a public project, you can also query http://localhost:8080/api/com.enonic.app.guillotine:graphql directly from a terminal without authentication:

    curl 'http://localhost:8080/api/com.enonic.app.guillotine:graphql' \
      -H 'Content-Type: application/json' \
      --data-binary '{"query":"{ guillotine(project: \"my-first-project\", branch: \"master\") { get(key: \"/animals/lynx\") { displayName ... on com_example_tutorial_modeling_Animal { data { description { processedHtml } } } } } }"}'

How it works

The repository packages both the tutorial’s YAML schemas and a startup task that initializes sample data on first run. Everything lives under src/main/resources/:

cms/

The YAML schemas built across the tutorial: the artist and animal content types, the distributionData form fragment, the editorial mixin, cms.yaml and style.yaml

import/

Exported content items and image binaries for the Artists, Animals and Images folders

main.js and tasks/initialize/

Schedules a one-time initialization task on startup that creates my-first-project, assigns com.example.tutorial.modeling, imports the bundled content, and publishes it to master (if my-first-project already exists, your edits are left untouched)

If you want to experiment with changing the schemas in tutorial-content-modeling/ and see updates redeployed automatically, run enonic dev from that folder.

Each schema and query pattern is explained step by step in the tutorial, starting with setting up your environment.


Contents

Contents