All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.learning.xapi.samples.deletestate.DeleteStateApplication Maven / Gradle / Ivy

There is a newer version: 1.1.15
Show newest version
/*
 * Copyright 2016-2023 Berry Cloud Ltd. All rights reserved.
 */

package dev.learning.xapi.samples.deletestate;

import dev.learning.xapi.client.XapiClient;
import dev.learning.xapi.samples.core.ExampleState;
import java.time.Instant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Sample using xAPI client to delete a state.
 *
 * @author Thomas Turrell-Croft
 */
@SpringBootApplication
public class DeleteStateApplication implements CommandLineRunner {

  /**
   * Default xAPI client. Properties are picked automatically from application.properties.
   */
  @Autowired
  private XapiClient client;

  public static void main(String[] args) {
    SpringApplication.run(DeleteStateApplication.class, args).close();
  }

  @Override
  public void run(String... args) throws Exception {

    // Post Example state for later deletion
    postState();

    // Delete State
    client.deleteState(r -> r.activityId("https://example.com/activity/1")

        .agent(a -> a.name("A N Other").mbox("mailto:[email protected]"))

        .registration("67828e3a-d116-4e18-8af3-2d2c59e27be6")

        .stateId("bookmark"))

        .block();

  }

  private void postState() {

    // Post State
    client.postState(r -> r.activityId("https://example.com/activity/1")

        .agent(a -> a.name("A N Other").mbox("mailto:[email protected]"))

        .registration("67828e3a-d116-4e18-8af3-2d2c59e27be6")

        .stateId("bookmark")

        .state(new ExampleState("Hello World!", Instant.now())))

        .block();

  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy