Using the Scenario API

The Scenario API exposes a service that can be injected in any Angular component. For more details, please refer to the Scenario API documentation.

It allows interacting with scenarios.

The Sample Widget implements some examples of Scenario API usage to address basic use cases:

  • Fetch the list of all scenarios I have access to;

  • Set a custom property value on the selected scenario..

    /**
     * This method returns an Observable of SampleWidgetModel which is built
     * using both Scenario API and Data API.
     *
     * @param context
     */
    public loadWidgetModel(context: GeneContext): Observable<SampleWidgetModel> {
        return forkJoin([
                this.scenarioApi.getAllPathNodes(['scenario']),
                this.countIssues(context)
            ]
        ).pipe(
            map(([scenarios, issuesCount]) => this.buildWidgetModel(context, scenarios, issuesCount))
        );
    }

    /**
     * Update the Scenario object having the given scenarioUuid by setting its property SCENARIO_STATUS to the
     * given value.
     *
     * @param scenarioUuid
     * @param status
     */
    public updateScenarioStatus(context: GeneContext, status: SampleScenarioStatus): Observable<VoidResult> {
        if (context.scenarioIds.length > 0) {
            const scenarioUuid = context.scenarioIds[0];
            return this.scenarioApi.savePathProperties(scenarioUuid, {[SampleWidgetService.SCENARIO_STATUS] : status});
        } else {
            throw Error('No scenario Selected');
        }
    }

The Scenario API provides services and model classes to interact with the Scenario Service. Note that every exposed method is subject to access right checks. For example, you can list scenarios for which you have at least "READ" permission, but you won't be able to modify them if you do not have "WRITE" permission.

The Scenario API manipulates "nodes" that can represent different types of elements, such as scenarios, folders, workspaces, views and dashboards.

This allows to:

  • List all nodes of type (e.g. list all nodes of type "SCENARIOS").

  • Retrieve properties of a give node.

  • Save properties for a given node.

  • Change node permissions.

  • Create nodes

  • Retrieve events attached to a node

The Platform allows the applications to store "events" attached to Nodes (Scenario or any other Node objects). Events have a message, an author and a timestamp. For example, each time a Scenario is locked by the system, an event is automatically created. When the user add comments through the Scenario Timeline, an event is also attached to the Scenario.

The Scenario API provides methods to:

  • Retrieve the Events associated to a Node

  • Create Comment Events on a Node.