From 98da8887cff72a852240bec2c8ce2e36dd1e965f Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Tue, 7 Mar 2023 10:23:40 +0000 Subject: [PATCH 01/18] Remove invalid TODO for adding since --- samples/delete-activity-profile/pom.xml | 22 +++++ .../DeleteActivityProfileApplication.java | 74 +++++++++++++++ .../DeleteAgentProfileApplication.java | 1 + .../deletestate/DeleteStateApplication.java | 5 +- samples/delete-states/pom.xml | 22 +++++ .../deletestates/DeleteStatesApplication.java | 80 +++++++++++++++++ .../samples/getabout/GetAboutApplication.java | 1 + samples/get-activity-profile/pom.xml | 22 +++++ .../GetActivityProfileApplication.java | 79 ++++++++++++++++ samples/get-activity-profiles/pom.xml | 22 +++++ .../GetActivityProfilesApplication.java | 77 ++++++++++++++++ .../getactivity/GetActivityApplication.java | 1 + .../GetAgentProfileApplication.java | 1 + samples/get-more-statements/pom.xml | 22 +++++ .../GetMoreStatementsApplication.java | 68 ++++++++++++++ .../samples/getstate/GetStateApplication.java | 1 + .../getstatement/GetStatementApplication.java | 1 + .../GetStatementsApplication.java | 12 +++ samples/get-states/pom.xml | 22 +++++ .../getstates/GetStatesApplication.java | 87 ++++++++++++++++++ samples/get-voided-statement/pom.xml | 22 +++++ .../GetVoidedStatementApplication.java | 89 +++++++++++++++++++ samples/pom.xml | 37 +++++--- samples/post-activity-profile/pom.xml | 22 +++++ .../PostActivityProfileApplication.java | 62 +++++++++++++ samples/post-statements/pom.xml | 22 +++++ .../PostStatementsApplication.java | 58 ++++++++++++ samples/put-activity-profile/pom.xml | 22 +++++ .../PutActivityProfile.java | 62 +++++++++++++ .../PutAgentProfileApplication.java | 2 +- .../xapi/client/GetAgentsRequest.java | 3 - .../xapi/client/GetMoreStatementsRequest.java | 4 +- .../dev/learning/xapi/model/Statement.java | 19 ++++ 33 files changed, 1026 insertions(+), 18 deletions(-) create mode 100644 samples/delete-activity-profile/pom.xml create mode 100644 samples/delete-activity-profile/src/main/java/dev/learning/xapi/samples/deleteactivityprofile/DeleteActivityProfileApplication.java create mode 100644 samples/delete-states/pom.xml create mode 100644 samples/delete-states/src/main/java/dev/learning/xapi/samples/deletestates/DeleteStatesApplication.java create mode 100644 samples/get-activity-profile/pom.xml create mode 100644 samples/get-activity-profile/src/main/java/dev/learning/xapi/samples/getactivityprofile/GetActivityProfileApplication.java create mode 100644 samples/get-activity-profiles/pom.xml create mode 100644 samples/get-activity-profiles/src/main/java/dev/learning/xapi/samples/getactivityprofiles/GetActivityProfilesApplication.java create mode 100644 samples/get-more-statements/pom.xml create mode 100644 samples/get-more-statements/src/main/java/dev/learning/xapi/samples/getmorestatements/GetMoreStatementsApplication.java create mode 100644 samples/get-states/pom.xml create mode 100644 samples/get-states/src/main/java/dev/learning/xapi/samples/getstates/GetStatesApplication.java create mode 100644 samples/get-voided-statement/pom.xml create mode 100644 samples/get-voided-statement/src/main/java/dev/learning/xapi/samples/getvoidedstatement/GetVoidedStatementApplication.java create mode 100644 samples/post-activity-profile/pom.xml create mode 100644 samples/post-activity-profile/src/main/java/dev/learning/xapi/samples/postactivityprofile/PostActivityProfileApplication.java create mode 100644 samples/post-statements/pom.xml create mode 100644 samples/post-statements/src/main/java/dev/learning/xapi/samples/poststatements/PostStatementsApplication.java create mode 100644 samples/put-activity-profile/pom.xml create mode 100644 samples/put-activity-profile/src/main/java/dev/learning/xapi/samples/putactivityprofile/PutActivityProfile.java diff --git a/samples/delete-activity-profile/pom.xml b/samples/delete-activity-profile/pom.xml new file mode 100644 index 00000000..5f901d74 --- /dev/null +++ b/samples/delete-activity-profile/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + dev.learning.xapi.samples + xapi-samples-build + 1.0.7-SNAPSHOT + + delete-activity-profile + Delete xAPI Activity Profile Sample + Delete xAPI Activity Profile + + + dev.learning.xapi + xapi-client + + + dev.learning.xapi.samples + core + + + diff --git a/samples/delete-activity-profile/src/main/java/dev/learning/xapi/samples/deleteactivityprofile/DeleteActivityProfileApplication.java b/samples/delete-activity-profile/src/main/java/dev/learning/xapi/samples/deleteactivityprofile/DeleteActivityProfileApplication.java new file mode 100644 index 00000000..2ed768ed --- /dev/null +++ b/samples/delete-activity-profile/src/main/java/dev/learning/xapi/samples/deleteactivityprofile/DeleteActivityProfileApplication.java @@ -0,0 +1,74 @@ +/* + * Copyright 2016-2023 Berry Cloud Ltd. All rights reserved. + */ + +package dev.learning.xapi.samples.deleteactivityprofile; + +import dev.learning.xapi.client.XapiClient; +import dev.learning.xapi.samples.core.ExampleState; +import java.time.Instant; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.reactive.function.client.WebClient; + +/** + * Sample using xAPI client to delete an activity profile. + * + * @author Thomas Turrell-Croft + */ +@SpringBootApplication +public class DeleteActivityProfileApplication implements CommandLineRunner { + + private final XapiClient client; + + /** + * Constructor for application. In this sample the WebClient.Builder instance is injected by the + * Spring Framework. + */ + public DeleteActivityProfileApplication(WebClient.Builder webClientBuilder) { + + webClientBuilder + // Change for the URL of your LRS + .baseUrl("https://example.com/xapi/") + // Set the Authorization value + .defaultHeader("Authorization", "") + + .build(); + + client = new XapiClient(webClientBuilder); + } + + public static void main(String[] args) { + SpringApplication.run(DeleteActivityProfileApplication.class, args).close(); + } + + @Override + public void run(String... args) throws Exception { + + // Post activity profile for later deletion + postActivityProfile(); + + // Delete activity profile + client.deleteActivityProfile(r -> r.activityId("https://example.com/activity/1") + + .profileId("bookmark")) + + .block(); + + } + + private void postActivityProfile() { + + // Post activity profile + client.postActivityProfile(r -> r.activityId("https://example.com/activity/1") + + .profileId("bookmark") + + .activityProfile(new ExampleState("Hello World!", Instant.now()))) + + .block(); + + } + +} diff --git a/samples/delete-agent-profile/src/main/java/dev/learning/xapi/samples/deleteagentprofile/DeleteAgentProfileApplication.java b/samples/delete-agent-profile/src/main/java/dev/learning/xapi/samples/deleteagentprofile/DeleteAgentProfileApplication.java index 52a2251b..f3dfe8ec 100644 --- a/samples/delete-agent-profile/src/main/java/dev/learning/xapi/samples/deleteagentprofile/DeleteAgentProfileApplication.java +++ b/samples/delete-agent-profile/src/main/java/dev/learning/xapi/samples/deleteagentprofile/DeleteAgentProfileApplication.java @@ -30,6 +30,7 @@ public DeleteAgentProfileApplication(WebClient.Builder webClientBuilder) { // Set the Authorization value .defaultHeader("Authorization", "") + .build(); client = new XapiClient(webClientBuilder); diff --git a/samples/delete-state/src/main/java/dev/learning/xapi/samples/deletestate/DeleteStateApplication.java b/samples/delete-state/src/main/java/dev/learning/xapi/samples/deletestate/DeleteStateApplication.java index 22695e47..1037a24f 100644 --- a/samples/delete-state/src/main/java/dev/learning/xapi/samples/deletestate/DeleteStateApplication.java +++ b/samples/delete-state/src/main/java/dev/learning/xapi/samples/deletestate/DeleteStateApplication.java @@ -25,11 +25,12 @@ public class DeleteStateApplication implements CommandLineRunner { public DeleteStateApplication(WebClient.Builder webClientBuilder) { webClientBuilder - + // Change for the URL of your LRS .baseUrl("https://example.com/xapi/") - + // Set the Authorization value .defaultHeader("Authorization", "") + .build(); client = new XapiClient(webClientBuilder); diff --git a/samples/delete-states/pom.xml b/samples/delete-states/pom.xml new file mode 100644 index 00000000..5e29f172 --- /dev/null +++ b/samples/delete-states/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + dev.learning.xapi.samples + xapi-samples-build + 1.0.7-SNAPSHOT + + delete-states + Delete xAPI States Sample + Delete xAPI States + + + dev.learning.xapi + xapi-client + + + dev.learning.xapi.samples + core + + + diff --git a/samples/delete-states/src/main/java/dev/learning/xapi/samples/deletestates/DeleteStatesApplication.java b/samples/delete-states/src/main/java/dev/learning/xapi/samples/deletestates/DeleteStatesApplication.java new file mode 100644 index 00000000..865f63bb --- /dev/null +++ b/samples/delete-states/src/main/java/dev/learning/xapi/samples/deletestates/DeleteStatesApplication.java @@ -0,0 +1,80 @@ +/* + * Copyright 2016-2023 Berry Cloud Ltd. All rights reserved. + */ + +package dev.learning.xapi.samples.deletestates; + +import dev.learning.xapi.client.XapiClient; +import dev.learning.xapi.samples.core.ExampleState; +import java.time.Instant; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.reactive.function.client.WebClient; + +/** + * Sample using xAPI client to delete multiple states. + * + * @author Thomas Turrell-Croft + */ +@SpringBootApplication +public class DeleteStatesApplication implements CommandLineRunner { + + private final XapiClient client; + + /** + * Constructor for application. In this sample the WebClient.Builder instance is injected by the + * Spring Framework. + */ + public DeleteStatesApplication(WebClient.Builder webClientBuilder) { + + webClientBuilder + // Change for the URL of your LRS + .baseUrl("https://example.com/xapi/") + // Set the Authorization value + .defaultHeader("Authorization", "") + + .build(); + + client = new XapiClient(webClientBuilder); + } + + public static void main(String[] args) { + SpringApplication.run(DeleteStatesApplication.class, args).close(); + } + + @Override + public void run(String... args) throws Exception { + + // Post state for later deletion + postState(); + + // Delete states + client.deleteStates(r -> r.activityId("https://example.com/activity/1") + + .agent(a -> a.name("A N Other").mbox("mailto:another@example.com")) + + .registration("67828e3a-d116-4e18-8af3-2d2c59e27be6")) + + .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:another@example.com")) + + .registration("67828e3a-d116-4e18-8af3-2d2c59e27be6") + + .stateId("bookmark") + + .state(new ExampleState("Hello World!", Instant.now()))) + + .block(); + + } + +} diff --git a/samples/get-about/src/main/java/dev/learning/xapi/samples/getabout/GetAboutApplication.java b/samples/get-about/src/main/java/dev/learning/xapi/samples/getabout/GetAboutApplication.java index e0141a29..12bb64e2 100644 --- a/samples/get-about/src/main/java/dev/learning/xapi/samples/getabout/GetAboutApplication.java +++ b/samples/get-about/src/main/java/dev/learning/xapi/samples/getabout/GetAboutApplication.java @@ -30,6 +30,7 @@ public GetAboutApplication(WebClient.Builder webClientBuilder) { // Set the Authorization value .defaultHeader("Authorization", "") + .build(); client = new XapiClient(webClientBuilder); diff --git a/samples/get-activity-profile/pom.xml b/samples/get-activity-profile/pom.xml new file mode 100644 index 00000000..4dad4bf4 --- /dev/null +++ b/samples/get-activity-profile/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + dev.learning.xapi.samples + xapi-samples-build + 1.0.7-SNAPSHOT + + get-activity-profile + Get xAPI Activity Profile Sample + Get xAPI Activity Profile + + + dev.learning.xapi + xapi-client + + + dev.learning.xapi.samples + core + + + diff --git a/samples/get-activity-profile/src/main/java/dev/learning/xapi/samples/getactivityprofile/GetActivityProfileApplication.java b/samples/get-activity-profile/src/main/java/dev/learning/xapi/samples/getactivityprofile/GetActivityProfileApplication.java new file mode 100644 index 00000000..ffeb0a91 --- /dev/null +++ b/samples/get-activity-profile/src/main/java/dev/learning/xapi/samples/getactivityprofile/GetActivityProfileApplication.java @@ -0,0 +1,79 @@ +/* + * Copyright 2016-2023 Berry Cloud Ltd. All rights reserved. + */ + +package dev.learning.xapi.samples.getactivityprofile; + +import dev.learning.xapi.client.XapiClient; +import dev.learning.xapi.samples.core.ExampleState; +import java.time.Instant; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.http.ResponseEntity; +import org.springframework.web.reactive.function.client.WebClient; + +/** + * Sample using xAPI client to get an activity profile. + * + * @author Thomas Turrell-Croft + */ +@SpringBootApplication +public class GetActivityProfileApplication implements CommandLineRunner { + + private final XapiClient client; + + /** + * Constructor for application. In this sample the WebClient.Builder instance is injected by the + * Spring Framework. + */ + public GetActivityProfileApplication(WebClient.Builder webClientBuilder) { + + webClientBuilder + // Change for the URL of your LRS + .baseUrl("https://example.com/xapi/") + // Set the Authorization value + .defaultHeader("Authorization", "") + + .build(); + + client = new XapiClient(webClientBuilder); + } + + public static void main(String[] args) { + SpringApplication.run(GetActivityProfileApplication.class, args).close(); + } + + @Override + public void run(String... args) throws Exception { + + // Post activity profile for later retrieval + postActivityProfile(); + + // Get activity profile + ResponseEntity response = client + .getActivityProfile(r -> r.activityId("https://example.com/activity/1") + + .profileId("bookmark"), ExampleState.class) + + .block(); + + // Print the returned activity profile to the console + System.out.println(response.getBody()); + + } + + private void postActivityProfile() { + + // Post Profile + client.postActivityProfile(r -> r.activityId("https://example.com/activity/1") + + .profileId("bookmark") + + .activityProfile(new ExampleState("Hello World!", Instant.now()))) + + .block(); + + } + +} diff --git a/samples/get-activity-profiles/pom.xml b/samples/get-activity-profiles/pom.xml new file mode 100644 index 00000000..531972ee --- /dev/null +++ b/samples/get-activity-profiles/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + dev.learning.xapi.samples + xapi-samples-build + 1.0.7-SNAPSHOT + + get-activity-profiles + Get xAPI Activity Profiles Sample + Get xAPI Activity Profiles + + + dev.learning.xapi + xapi-client + + + dev.learning.xapi.samples + core + + + diff --git a/samples/get-activity-profiles/src/main/java/dev/learning/xapi/samples/getactivityprofiles/GetActivityProfilesApplication.java b/samples/get-activity-profiles/src/main/java/dev/learning/xapi/samples/getactivityprofiles/GetActivityProfilesApplication.java new file mode 100644 index 00000000..b9963b4e --- /dev/null +++ b/samples/get-activity-profiles/src/main/java/dev/learning/xapi/samples/getactivityprofiles/GetActivityProfilesApplication.java @@ -0,0 +1,77 @@ +/* + * Copyright 2016-2023 Berry Cloud Ltd. All rights reserved. + */ + +package dev.learning.xapi.samples.getactivityprofiles; + +import dev.learning.xapi.client.XapiClient; +import dev.learning.xapi.samples.core.ExampleState; +import java.time.Instant; +import java.util.Arrays; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.http.ResponseEntity; +import org.springframework.web.reactive.function.client.WebClient; + +/** + * Sample using xAPI client to get activity profiles. + * + * @author Thomas Turrell-Croft + */ +@SpringBootApplication +public class GetActivityProfilesApplication implements CommandLineRunner { + + private final XapiClient client; + + /** + * Constructor for application. In this sample the WebClient.Builder instance is injected by the + * Spring Framework. + */ + public GetActivityProfilesApplication(WebClient.Builder webClientBuilder) { + + webClientBuilder + // Change for the URL of your LRS + .baseUrl("https://example.com/xapi/") + // Set the Authorization value + .defaultHeader("Authorization", "") + + .build(); + + client = new XapiClient(webClientBuilder); + } + + public static void main(String[] args) { + SpringApplication.run(GetActivityProfilesApplication.class, args).close(); + } + + @Override + public void run(String... args) throws Exception { + + // Post Example Activity profile for later retrieval + postActivityProfile(); + + // Get Activity Profiles + ResponseEntity response = + client.getActivityProfiles(r -> r.activityId("https://example.com/activity/1")) + + .block(); + + // Print the each returned activity profile id to the console + Arrays.asList(response.getBody()).forEach(id -> System.out.println(id)); + } + + private void postActivityProfile() { + + // Post Profile + client.postActivityProfile(r -> r.activityId("https://example.com/activity/1") + + .profileId("bookmark") + + .activityProfile(new ExampleState("Hello World!", Instant.now()))) + + .block(); + + } + +} diff --git a/samples/get-activity/src/main/java/dev/learning/xapi/samples/getactivity/GetActivityApplication.java b/samples/get-activity/src/main/java/dev/learning/xapi/samples/getactivity/GetActivityApplication.java index 82372e67..98e1231b 100644 --- a/samples/get-activity/src/main/java/dev/learning/xapi/samples/getactivity/GetActivityApplication.java +++ b/samples/get-activity/src/main/java/dev/learning/xapi/samples/getactivity/GetActivityApplication.java @@ -34,6 +34,7 @@ public GetActivityApplication(WebClient.Builder webClientBuilder) { // Set the Authorization value .defaultHeader("Authorization", "") + .build(); diff --git a/samples/get-agent-profile/src/main/java/dev/learning/xapi/samples/getagentprofile/GetAgentProfileApplication.java b/samples/get-agent-profile/src/main/java/dev/learning/xapi/samples/getagentprofile/GetAgentProfileApplication.java index e2a3cc05..0e07b740 100644 --- a/samples/get-agent-profile/src/main/java/dev/learning/xapi/samples/getagentprofile/GetAgentProfileApplication.java +++ b/samples/get-agent-profile/src/main/java/dev/learning/xapi/samples/getagentprofile/GetAgentProfileApplication.java @@ -31,6 +31,7 @@ public GetAgentProfileApplication(WebClient.Builder webClientBuilder) { // Set the Authorization value .defaultHeader("Authorization", "") + .build(); client = new XapiClient(webClientBuilder); diff --git a/samples/get-more-statements/pom.xml b/samples/get-more-statements/pom.xml new file mode 100644 index 00000000..8e4f661d --- /dev/null +++ b/samples/get-more-statements/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + dev.learning.xapi.samples + xapi-samples-build + 1.0.7-SNAPSHOT + + get-more-statements + Get xAPI More Statements Sample + Get xAPI More Statements + + + dev.learning.xapi + xapi-client + + + dev.learning.xapi.samples + core + + + diff --git a/samples/get-more-statements/src/main/java/dev/learning/xapi/samples/getmorestatements/GetMoreStatementsApplication.java b/samples/get-more-statements/src/main/java/dev/learning/xapi/samples/getmorestatements/GetMoreStatementsApplication.java new file mode 100644 index 00000000..372c7bc7 --- /dev/null +++ b/samples/get-more-statements/src/main/java/dev/learning/xapi/samples/getmorestatements/GetMoreStatementsApplication.java @@ -0,0 +1,68 @@ +package dev.learning.xapi.samples.getmorestatements; + +import dev.learning.xapi.client.XapiClient; +import dev.learning.xapi.model.StatementResult; +import java.net.URI; +import java.util.Arrays; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.http.ResponseEntity; +import org.springframework.web.reactive.function.client.WebClient; + +/** + * Sample using xAPI client to get more multiple statements. + * + * @author Thomas Turrell-Croft + */ +@SpringBootApplication +public class GetMoreStatementsApplication implements CommandLineRunner { + + private final XapiClient client; + + /** + * Constructor for application. In this sample the WebClient.Builder instance is injected by the + * Spring Framework. + */ + public GetMoreStatementsApplication(WebClient.Builder webClientBuilder) { + + webClientBuilder + // Change for the URL of your LRS + .baseUrl("https://example.com/xapi/") + // Set the Authorization value + .defaultHeader("Authorization", "") + + .build(); + + + client = new XapiClient(webClientBuilder); + } + + public static void main(String[] args) { + SpringApplication.run(GetMoreStatementsApplication.class, args).close(); + } + + @Override + public void run(String... args) throws Exception { + + // Get Statements + ResponseEntity response = client.getStatements(r -> r.limit(1)).block(); + + // Print the returned statements to the console + Arrays.asList(response.getBody().getStatements()).forEach(s -> System.out.println(s)); + + + URI moreUrl = response.getBody().getMore(); + + System.out.println("me " + moreUrl); + + if (moreUrl.getPath() != "") { + // Get More Statements + ResponseEntity more = client.getMoreStatements(r -> r.more(moreUrl)).block(); + + // Print the returned statements to the console + Arrays.asList(more.getBody().getStatements()).forEach(s -> System.out.println(s)); + } + } + +} diff --git a/samples/get-state/src/main/java/dev/learning/xapi/samples/getstate/GetStateApplication.java b/samples/get-state/src/main/java/dev/learning/xapi/samples/getstate/GetStateApplication.java index 7b89ae61..22952db0 100644 --- a/samples/get-state/src/main/java/dev/learning/xapi/samples/getstate/GetStateApplication.java +++ b/samples/get-state/src/main/java/dev/learning/xapi/samples/getstate/GetStateApplication.java @@ -31,6 +31,7 @@ public GetStateApplication(WebClient.Builder webClientBuilder) { // Set the Authorization value .defaultHeader("Authorization", "") + .build(); diff --git a/samples/get-statement/src/main/java/dev/learning/xapi/samples/getstatement/GetStatementApplication.java b/samples/get-statement/src/main/java/dev/learning/xapi/samples/getstatement/GetStatementApplication.java index 9acd4a58..4f151cb6 100644 --- a/samples/get-statement/src/main/java/dev/learning/xapi/samples/getstatement/GetStatementApplication.java +++ b/samples/get-statement/src/main/java/dev/learning/xapi/samples/getstatement/GetStatementApplication.java @@ -33,6 +33,7 @@ public GetStatementApplication(WebClient.Builder webClientBuilder) { // Set the Authorization value .defaultHeader("Authorization", "") + .build(); diff --git a/samples/get-statements/src/main/java/dev/learning/xapi/samples/getstatements/GetStatementsApplication.java b/samples/get-statements/src/main/java/dev/learning/xapi/samples/getstatements/GetStatementsApplication.java index 4a0022f0..1abecce4 100644 --- a/samples/get-statements/src/main/java/dev/learning/xapi/samples/getstatements/GetStatementsApplication.java +++ b/samples/get-statements/src/main/java/dev/learning/xapi/samples/getstatements/GetStatementsApplication.java @@ -2,6 +2,7 @@ import dev.learning.xapi.client.XapiClient; import dev.learning.xapi.model.StatementResult; +import dev.learning.xapi.model.Verb; import java.util.Arrays; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; @@ -31,6 +32,7 @@ public GetStatementsApplication(WebClient.Builder webClientBuilder) { // Set the Authorization value .defaultHeader("Authorization", "") + .build(); @@ -49,6 +51,16 @@ public void run(String... args) throws Exception { // Print the returned statements to the console Arrays.asList(response.getBody().getStatements()).forEach(s -> System.out.println(s)); + + + + // Get Statements with Verb filter + ResponseEntity filteredResponse = + client.getStatements(r -> r.verb(Verb.ATTEMPTED.getId())).block(); + + // Print the returned statements to the console + Arrays.asList(filteredResponse.getBody().getStatements()).forEach(s -> System.out.println(s)); + } } diff --git a/samples/get-states/pom.xml b/samples/get-states/pom.xml new file mode 100644 index 00000000..b167fbae --- /dev/null +++ b/samples/get-states/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + dev.learning.xapi.samples + xapi-samples-build + 1.0.7-SNAPSHOT + + get-states + Get xAPI States Sample + Get xAPI States + + + dev.learning.xapi + xapi-client + + + dev.learning.xapi.samples + core + + + diff --git a/samples/get-states/src/main/java/dev/learning/xapi/samples/getstates/GetStatesApplication.java b/samples/get-states/src/main/java/dev/learning/xapi/samples/getstates/GetStatesApplication.java new file mode 100644 index 00000000..b5dc8c54 --- /dev/null +++ b/samples/get-states/src/main/java/dev/learning/xapi/samples/getstates/GetStatesApplication.java @@ -0,0 +1,87 @@ +/* + * Copyright 2016-2023 Berry Cloud Ltd. All rights reserved. + */ + +package dev.learning.xapi.samples.getstates; + +import dev.learning.xapi.client.XapiClient; +import dev.learning.xapi.samples.core.ExampleState; +import java.time.Instant; +import java.util.Arrays; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.http.ResponseEntity; +import org.springframework.web.reactive.function.client.WebClient; + +/** + * Sample using xAPI client to get states. + * + * @author Thomas Turrell-Croft + */ +@SpringBootApplication +public class GetStatesApplication implements CommandLineRunner { + + private final XapiClient client; + + /** + * Constructor for application. In this sample the WebClient.Builder instance is injected by the + * Spring Framework. + */ + public GetStatesApplication(WebClient.Builder webClientBuilder) { + + webClientBuilder + // Change for the URL of your LRS + .baseUrl("https://example.com/xapi/") + // Set the Authorization value + .defaultHeader("Authorization", "") + + .build(); + + + client = new XapiClient(webClientBuilder); + } + + public static void main(String[] args) { + SpringApplication.run(GetStatesApplication.class, args).close(); + } + + @Override + public void run(String... args) throws Exception { + + // Post Example state for later retrieval + postState(); + + // Get States + ResponseEntity response = client + .getStates(r -> r.activityId("https://example.com/activity/1") + + .agent(a -> a.name("A N Other").mbox("mailto:another@example.com")) + + .registration("67828e3a-d116-4e18-8af3-2d2c59e27be6")) + + .block(); + + // Print the each returned state id to the console + Arrays.asList(response.getBody()).forEach(id -> System.out.println(id)); + + } + + private void postState() { + + // Post State + client.postState(r -> r.activityId("https://example.com/activity/1") + + .agent(a -> a.name("A N Other").mbox("mailto:another@example.com")) + + .registration("67828e3a-d116-4e18-8af3-2d2c59e27be6") + + .stateId("bookmark") + + .state(new ExampleState("Hello World!", Instant.now()))) + + .block(); + + } + +} diff --git a/samples/get-voided-statement/pom.xml b/samples/get-voided-statement/pom.xml new file mode 100644 index 00000000..8712854b --- /dev/null +++ b/samples/get-voided-statement/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + dev.learning.xapi.samples + xapi-samples-build + 1.0.7-SNAPSHOT + + get-voided-statement + Get xAPI Voided Statement Sample + Get xAPI Voided Statement + + + dev.learning.xapi + xapi-client + + + dev.learning.xapi.samples + core + + + diff --git a/samples/get-voided-statement/src/main/java/dev/learning/xapi/samples/getvoidedstatement/GetVoidedStatementApplication.java b/samples/get-voided-statement/src/main/java/dev/learning/xapi/samples/getvoidedstatement/GetVoidedStatementApplication.java new file mode 100644 index 00000000..00b19f0a --- /dev/null +++ b/samples/get-voided-statement/src/main/java/dev/learning/xapi/samples/getvoidedstatement/GetVoidedStatementApplication.java @@ -0,0 +1,89 @@ +/* + * Copyright 2016-2023 Berry Cloud Ltd. All rights reserved. + */ + +package dev.learning.xapi.samples.getvoidedstatement; + +import dev.learning.xapi.client.XapiClient; +import dev.learning.xapi.model.Statement; +import dev.learning.xapi.model.Verb; +import java.util.Locale; +import java.util.UUID; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.http.ResponseEntity; +import org.springframework.web.reactive.function.client.WebClient; + +/** + * Sample using xAPI client to get a voided statement. + * + * @author Thomas Turrell-Croft + */ +@SpringBootApplication +public class GetVoidedStatementApplication implements CommandLineRunner { + + private final XapiClient client; + + /** + * Constructor for application. In this sample the WebClient.Builder instance is injected by the + * Spring Framework. + */ + public GetVoidedStatementApplication(WebClient.Builder webClientBuilder) { + + webClientBuilder + // Change for the URL of your LRS + .baseUrl("https://example.com/xapi/") + // Set the Authorization value + .defaultHeader("Authorization", "") + + .build(); + + + client = new XapiClient(webClientBuilder); + } + + public static void main(String[] args) { + SpringApplication.run(GetVoidedStatementApplication.class, args).close(); + } + + @Override + public void run(String... args) throws Exception { + + // Get Voided Statement + ResponseEntity response = + client.getVoidedStatement(r -> r.id(postAndVoidStatement())).block(); + + // Print the returned statement to the console + System.out.println(response.getBody()); + } + + private UUID postAndVoidStatement() { + + // Post a statement + ResponseEntity response = client + .postStatement(r -> r + .statement(s -> s.actor(a -> a.name("A N Other").mbox("mailto:another@example.com")) + + .verb(Verb.ATTEMPTED) + + .activityObject(o -> o.id("https://example.com/activity/simplestatement") + .definition(d -> d.addName(Locale.ENGLISH, "Simple Statement"))))) + + .block(); + + // Void the statement + client + .postStatement(r -> r + .statement(s -> s.actor(a -> a.name("A N Other").mbox("mailto:another@example.com")) + + .verb(Verb.VOIDED) + + .statementReferenceObject(sr -> sr.id(response.getBody())))) + + .block(); + + return response.getBody(); + } + +} diff --git a/samples/pom.xml b/samples/pom.xml index 4abe4d63..fc666ac4 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -33,21 +33,38 @@ core - delete-agent-profile + + get-statement + post-statement + get-statements + get-more-statements + get-voided-statement + post-statements + + get-state + post-state + put-state delete-state - get-about + get-states + delete-states + + get-agents + get-activity + get-agent-profile - get-agent-profiles - get-agents - get-state - get-statement - get-statements post-agent-profile - post-state - post-statement put-agent-profile - put-state + delete-agent-profile + get-agent-profiles + + get-activity-profile + post-activity-profile + put-activity-profile + delete-activity-profile + get-activity-profiles + + get-about diff --git a/samples/post-activity-profile/pom.xml b/samples/post-activity-profile/pom.xml new file mode 100644 index 00000000..0e4dfe0f --- /dev/null +++ b/samples/post-activity-profile/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + dev.learning.xapi.samples + xapi-samples-build + 1.0.7-SNAPSHOT + + post-activity-profile + Post xAPI Activity Profile Sample + Post xAPI Activity Profile + + + dev.learning.xapi + xapi-client + + + dev.learning.xapi.samples + core + + + diff --git a/samples/post-activity-profile/src/main/java/dev/learning/xapi/samples/postactivityprofile/PostActivityProfileApplication.java b/samples/post-activity-profile/src/main/java/dev/learning/xapi/samples/postactivityprofile/PostActivityProfileApplication.java new file mode 100644 index 00000000..c5f01176 --- /dev/null +++ b/samples/post-activity-profile/src/main/java/dev/learning/xapi/samples/postactivityprofile/PostActivityProfileApplication.java @@ -0,0 +1,62 @@ +/* + * Copyright 2016-2023 Berry Cloud Ltd. All rights reserved. + */ + +package dev.learning.xapi.samples.postactivityprofile; + +import dev.learning.xapi.client.XapiClient; +import dev.learning.xapi.samples.core.ExampleState; +import java.time.Instant; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.reactive.function.client.WebClient; + +/** + * Sample using xAPI client to post an activity profile. + * + * @author Thomas Turrell-Croft + */ +@SpringBootApplication +public class PostActivityProfileApplication implements CommandLineRunner { + + private final XapiClient client; + + /** + * Constructor for application. In this sample the WebClient.Builder instance is injected by the + * Spring Framework. + */ + public PostActivityProfileApplication(WebClient.Builder webClientBuilder) { + + webClientBuilder + // Change for the URL of your LRS + .baseUrl("https://example.com/xapi/") + // Set the Authorization value + .defaultHeader("Authorization", "") + + .build(); + + client = new XapiClient(webClientBuilder); + } + + public static void main(String[] args) { + SpringApplication.run(PostActivityProfileApplication.class, args).close(); + } + + @Override + public void run(String... args) throws Exception { + + // Post activity profile + client.postActivityProfile(r -> r + + .activityId("https://example.com/activity/1") + + .profileId("bookmark") + + .activityProfile(new ExampleState("Hello World!", Instant.now()))) + + .block(); + + } + +} diff --git a/samples/post-statements/pom.xml b/samples/post-statements/pom.xml new file mode 100644 index 00000000..c0a9b7c0 --- /dev/null +++ b/samples/post-statements/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + dev.learning.xapi.samples + xapi-samples-build + 1.0.7-SNAPSHOT + + post-statements + Post xAPI Statements Sample + Post xAPI Statements + + + dev.learning.xapi + xapi-client + + + dev.learning.xapi.samples + core + + + diff --git a/samples/post-statements/src/main/java/dev/learning/xapi/samples/poststatements/PostStatementsApplication.java b/samples/post-statements/src/main/java/dev/learning/xapi/samples/poststatements/PostStatementsApplication.java new file mode 100644 index 00000000..2b9a6db6 --- /dev/null +++ b/samples/post-statements/src/main/java/dev/learning/xapi/samples/poststatements/PostStatementsApplication.java @@ -0,0 +1,58 @@ +package dev.learning.xapi.samples.poststatements; + +import dev.learning.xapi.client.XapiClient; +import dev.learning.xapi.model.Statement; +import dev.learning.xapi.model.Verb; +import java.util.Locale; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.reactive.function.client.WebClient; + +/** + * Sample using xAPI client to post multiple statements. + * + * @author Thomas Turrell-Croft + */ +@SpringBootApplication +public class PostStatementsApplication implements CommandLineRunner { + + private final XapiClient client; + + /** + * Constructor for application. In this sample the WebClient.Builder instance is injected by the + * Spring Framework. + */ + public PostStatementsApplication(WebClient.Builder webClientBuilder) { + + webClientBuilder + // Change for the URL of your LRS + .baseUrl("https://example.com/xapi/") + // Set the Authorization value + .defaultHeader("Authorization", "") + + .build(); + + client = new XapiClient(webClientBuilder); + } + + public static void main(String[] args) { + SpringApplication.run(PostStatementsApplication.class, args).close(); + } + + @Override + public void run(String... args) throws Exception { + + Statement attemptedStatement = Statement.builder() + .actor(a -> a.name("A N Other").mbox("mailto:another@example.com")).verb(Verb.ATTEMPTED) + .activityObject(o -> o.id("https://example.com/activity/simplestatement") + .definition(d -> d.addName(Locale.ENGLISH, "Simple Statement"))) + .build(); + + Statement passedStatement = attemptedStatement.toBuilder().verb(Verb.PASSED).build(); + + // Post multiple statements + client.postStatements(r -> r.statements(attemptedStatement, passedStatement)).block(); + } + +} diff --git a/samples/put-activity-profile/pom.xml b/samples/put-activity-profile/pom.xml new file mode 100644 index 00000000..ef8c9a9b --- /dev/null +++ b/samples/put-activity-profile/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + dev.learning.xapi.samples + xapi-samples-build + 1.0.7-SNAPSHOT + + put-activity-profile + Put xAPI Activity Profile Sample + Put xAPI Activity Profile + + + dev.learning.xapi + xapi-client + + + dev.learning.xapi.samples + core + + + diff --git a/samples/put-activity-profile/src/main/java/dev/learning/xapi/samples/putactivityprofile/PutActivityProfile.java b/samples/put-activity-profile/src/main/java/dev/learning/xapi/samples/putactivityprofile/PutActivityProfile.java new file mode 100644 index 00000000..d0254889 --- /dev/null +++ b/samples/put-activity-profile/src/main/java/dev/learning/xapi/samples/putactivityprofile/PutActivityProfile.java @@ -0,0 +1,62 @@ +/* + * Copyright 2016-2023 Berry Cloud Ltd. All rights reserved. + */ + +package dev.learning.xapi.samples.putactivityprofile; + +import dev.learning.xapi.client.XapiClient; +import dev.learning.xapi.samples.core.ExampleState; +import java.time.Instant; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.reactive.function.client.WebClient; + +/** + * Sample using xAPI client to put an activity profile. + * + * @author Thomas Turrell-Croft + */ +@SpringBootApplication +public class PutActivityProfile implements CommandLineRunner { + + private final XapiClient client; + + /** + * Constructor for application. In this sample the WebClient.Builder instance is injected by the + * Spring Framework. + */ + public PutActivityProfile(WebClient.Builder webClientBuilder) { + + webClientBuilder + // Change for the URL of your LRS + .baseUrl("https://example.com/xapi/") + // Set the Authorization value + .defaultHeader("Authorization", "") + + .build(); + + client = new XapiClient(webClientBuilder); + } + + public static void main(String[] args) { + SpringApplication.run(PutActivityProfile.class, args).close(); + } + + @Override + public void run(String... args) throws Exception { + + // Put activity profile + client.putActivityProfile(r -> r + + .activityId("https://example.com/activity/1") + + .profileId("bookmark") + + .activityProfile(new ExampleState("Hello World!", Instant.now()))) + + .block(); + + } + +} diff --git a/samples/put-agent-profile/src/main/java/dev/learning/xapi/samples/putagentprofile/PutAgentProfileApplication.java b/samples/put-agent-profile/src/main/java/dev/learning/xapi/samples/putagentprofile/PutAgentProfileApplication.java index d8882424..cd0bf383 100644 --- a/samples/put-agent-profile/src/main/java/dev/learning/xapi/samples/putagentprofile/PutAgentProfileApplication.java +++ b/samples/put-agent-profile/src/main/java/dev/learning/xapi/samples/putagentprofile/PutAgentProfileApplication.java @@ -46,7 +46,7 @@ public void run(String... args) throws Exception { // Put Profile client.putAgentProfile(r -> r.agent(a -> a.name("A N Other").mbox("mailto:another@example.com")) - .profileId("bookmark") + .profileId("bookmark864") .profile(new ExampleState("Hello World!", Instant.now()))) diff --git a/xapi-client/src/main/java/dev/learning/xapi/client/GetAgentsRequest.java b/xapi-client/src/main/java/dev/learning/xapi/client/GetAgentsRequest.java index 2fd51686..c64242a7 100644 --- a/xapi-client/src/main/java/dev/learning/xapi/client/GetAgentsRequest.java +++ b/xapi-client/src/main/java/dev/learning/xapi/client/GetAgentsRequest.java @@ -30,9 +30,6 @@ public class GetAgentsRequest implements Request { private static final ObjectMapper objectMapper = new ObjectMapper(); - - // TODO add since - /** * The Agent representation to use in fetching expanded Agent information. */ diff --git a/xapi-client/src/main/java/dev/learning/xapi/client/GetMoreStatementsRequest.java b/xapi-client/src/main/java/dev/learning/xapi/client/GetMoreStatementsRequest.java index 5e205605..6fac8002 100644 --- a/xapi-client/src/main/java/dev/learning/xapi/client/GetMoreStatementsRequest.java +++ b/xapi-client/src/main/java/dev/learning/xapi/client/GetMoreStatementsRequest.java @@ -11,7 +11,6 @@ import lombok.NonNull; import org.springframework.http.HttpMethod; import org.springframework.web.util.UriBuilder; -import org.springframework.web.util.UriComponentsBuilder; /** * Request for getting multiple Statements. @@ -37,7 +36,8 @@ public HttpMethod getMethod() { @Override public UriBuilder url(UriBuilder uriBuilder, Map queryParams) { - return UriComponentsBuilder.fromUri(more); + // TODO this seems unclear in the spec + return uriBuilder.replacePath(more.getPath()).replaceQuery(more.getQuery()); } diff --git a/xapi-model/src/main/java/dev/learning/xapi/model/Statement.java b/xapi-model/src/main/java/dev/learning/xapi/model/Statement.java index f72ba191..9bda92ce 100644 --- a/xapi-model/src/main/java/dev/learning/xapi/model/Statement.java +++ b/xapi-model/src/main/java/dev/learning/xapi/model/Statement.java @@ -244,6 +244,25 @@ public Builder activityObject(Consumer activity) { return object(builder.build()); } + /** + * Consumer Builder for statement reference object. + * + * @param statementReference The Consumer Builder for statement reference object + * + * @return This builder + * + * @see Statement#object + */ + public Builder statementReferenceObject( + Consumer statementReference) { + + final StatementReference.Builder builder = StatementReference.builder(); + + statementReference.accept(builder); + + return object(builder.build()); + } + /** * Consumer Builder for context. * From 115b181795ab0fe2a8a0b5acf62a5bd51e019d35 Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Tue, 7 Mar 2023 23:11:55 +0000 Subject: [PATCH 02/18] tip --- .../src/test/java/dev/learning/xapi/client/XapiClientTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xapi-client/src/test/java/dev/learning/xapi/client/XapiClientTests.java b/xapi-client/src/test/java/dev/learning/xapi/client/XapiClientTests.java index 2945f5a9..78113b26 100644 --- a/xapi-client/src/test/java/dev/learning/xapi/client/XapiClientTests.java +++ b/xapi-client/src/test/java/dev/learning/xapi/client/XapiClientTests.java @@ -555,7 +555,7 @@ void whenGettingMoreStatementsThenRequestURLExpected() throws InterruptedExcepti // When Getting Statements With Activity Parameter client.getMoreStatements(r -> r - .more(mockWebServer.url("/xapi/statements/869cc589-76fa-4283-8e96-eea86f9124e1").uri()) + .more((URI.create("/xapi/statements/869cc589-76fa-4283-8e96-eea86f9124e1"))) ).block(); From 3bc983b3b7e9352580b6e2b5820e28e22b582223 Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Tue, 7 Mar 2023 23:14:08 +0000 Subject: [PATCH 03/18] tip --- .../src/test/java/dev/learning/xapi/client/XapiClientTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xapi-client/src/test/java/dev/learning/xapi/client/XapiClientTests.java b/xapi-client/src/test/java/dev/learning/xapi/client/XapiClientTests.java index 78113b26..2cf8c5e4 100644 --- a/xapi-client/src/test/java/dev/learning/xapi/client/XapiClientTests.java +++ b/xapi-client/src/test/java/dev/learning/xapi/client/XapiClientTests.java @@ -555,7 +555,7 @@ void whenGettingMoreStatementsThenRequestURLExpected() throws InterruptedExcepti // When Getting Statements With Activity Parameter client.getMoreStatements(r -> r - .more((URI.create("/xapi/statements/869cc589-76fa-4283-8e96-eea86f9124e1"))) + .more(URI.create("/xapi/statements/869cc589-76fa-4283-8e96-eea86f9124e1")) ).block(); From 891d275e97db43ad9ecbe58c700d9dde33c1ac53 Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Tue, 7 Mar 2023 23:30:13 +0000 Subject: [PATCH 04/18] tip --- .../deleteagentprofile/DeleteAgentProfileApplication.java | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/delete-agent-profile/src/main/java/dev/learning/xapi/samples/deleteagentprofile/DeleteAgentProfileApplication.java b/samples/delete-agent-profile/src/main/java/dev/learning/xapi/samples/deleteagentprofile/DeleteAgentProfileApplication.java index f3dfe8ec..52a2251b 100644 --- a/samples/delete-agent-profile/src/main/java/dev/learning/xapi/samples/deleteagentprofile/DeleteAgentProfileApplication.java +++ b/samples/delete-agent-profile/src/main/java/dev/learning/xapi/samples/deleteagentprofile/DeleteAgentProfileApplication.java @@ -30,7 +30,6 @@ public DeleteAgentProfileApplication(WebClient.Builder webClientBuilder) { // Set the Authorization value .defaultHeader("Authorization", "") - .build(); client = new XapiClient(webClientBuilder); From 6ea0ffbeb5e0239802f8054a1ed5758ba9f15ef4 Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Tue, 7 Mar 2023 23:30:51 +0000 Subject: [PATCH 05/18] tip --- .../xapi/samples/deletestate/DeleteStateApplication.java | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/delete-state/src/main/java/dev/learning/xapi/samples/deletestate/DeleteStateApplication.java b/samples/delete-state/src/main/java/dev/learning/xapi/samples/deletestate/DeleteStateApplication.java index 1037a24f..b4593028 100644 --- a/samples/delete-state/src/main/java/dev/learning/xapi/samples/deletestate/DeleteStateApplication.java +++ b/samples/delete-state/src/main/java/dev/learning/xapi/samples/deletestate/DeleteStateApplication.java @@ -30,7 +30,6 @@ public DeleteStateApplication(WebClient.Builder webClientBuilder) { // Set the Authorization value .defaultHeader("Authorization", "") - .build(); client = new XapiClient(webClientBuilder); From fa263b8bb7028cc40511fcb967890deac0ed798d Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Tue, 7 Mar 2023 23:31:30 +0000 Subject: [PATCH 06/18] tip --- .../dev/learning/xapi/samples/getabout/GetAboutApplication.java | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/get-about/src/main/java/dev/learning/xapi/samples/getabout/GetAboutApplication.java b/samples/get-about/src/main/java/dev/learning/xapi/samples/getabout/GetAboutApplication.java index 12bb64e2..e0141a29 100644 --- a/samples/get-about/src/main/java/dev/learning/xapi/samples/getabout/GetAboutApplication.java +++ b/samples/get-about/src/main/java/dev/learning/xapi/samples/getabout/GetAboutApplication.java @@ -30,7 +30,6 @@ public GetAboutApplication(WebClient.Builder webClientBuilder) { // Set the Authorization value .defaultHeader("Authorization", "") - .build(); client = new XapiClient(webClientBuilder); From eeee2783abafb135cd0cc9faab5c7605ab8c883c Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Tue, 7 Mar 2023 23:32:06 +0000 Subject: [PATCH 07/18] tip --- .../xapi/samples/getactivity/GetActivityApplication.java | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/get-activity/src/main/java/dev/learning/xapi/samples/getactivity/GetActivityApplication.java b/samples/get-activity/src/main/java/dev/learning/xapi/samples/getactivity/GetActivityApplication.java index 98e1231b..82372e67 100644 --- a/samples/get-activity/src/main/java/dev/learning/xapi/samples/getactivity/GetActivityApplication.java +++ b/samples/get-activity/src/main/java/dev/learning/xapi/samples/getactivity/GetActivityApplication.java @@ -34,7 +34,6 @@ public GetActivityApplication(WebClient.Builder webClientBuilder) { // Set the Authorization value .defaultHeader("Authorization", "") - .build(); From 99daa489e43cbf4e27f89286d9b2c8844705b321 Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Tue, 7 Mar 2023 23:32:33 +0000 Subject: [PATCH 08/18] tip --- .../xapi/samples/getagentprofile/GetAgentProfileApplication.java | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/get-agent-profile/src/main/java/dev/learning/xapi/samples/getagentprofile/GetAgentProfileApplication.java b/samples/get-agent-profile/src/main/java/dev/learning/xapi/samples/getagentprofile/GetAgentProfileApplication.java index 0e07b740..e2a3cc05 100644 --- a/samples/get-agent-profile/src/main/java/dev/learning/xapi/samples/getagentprofile/GetAgentProfileApplication.java +++ b/samples/get-agent-profile/src/main/java/dev/learning/xapi/samples/getagentprofile/GetAgentProfileApplication.java @@ -31,7 +31,6 @@ public GetAgentProfileApplication(WebClient.Builder webClientBuilder) { // Set the Authorization value .defaultHeader("Authorization", "") - .build(); client = new XapiClient(webClientBuilder); From 409c5eb01a197018a8f8e04b746f613efbef4446 Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Tue, 7 Mar 2023 23:32:57 +0000 Subject: [PATCH 09/18] tip --- .../dev/learning/xapi/samples/getstate/GetStateApplication.java | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/get-state/src/main/java/dev/learning/xapi/samples/getstate/GetStateApplication.java b/samples/get-state/src/main/java/dev/learning/xapi/samples/getstate/GetStateApplication.java index 22952db0..7b89ae61 100644 --- a/samples/get-state/src/main/java/dev/learning/xapi/samples/getstate/GetStateApplication.java +++ b/samples/get-state/src/main/java/dev/learning/xapi/samples/getstate/GetStateApplication.java @@ -31,7 +31,6 @@ public GetStateApplication(WebClient.Builder webClientBuilder) { // Set the Authorization value .defaultHeader("Authorization", "") - .build(); From 6612c4aea3802ffa2b3a69ad73c9f433e1099d2d Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Tue, 7 Mar 2023 23:33:14 +0000 Subject: [PATCH 10/18] tip --- .../xapi/samples/getstatement/GetStatementApplication.java | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/get-statement/src/main/java/dev/learning/xapi/samples/getstatement/GetStatementApplication.java b/samples/get-statement/src/main/java/dev/learning/xapi/samples/getstatement/GetStatementApplication.java index 4f151cb6..9acd4a58 100644 --- a/samples/get-statement/src/main/java/dev/learning/xapi/samples/getstatement/GetStatementApplication.java +++ b/samples/get-statement/src/main/java/dev/learning/xapi/samples/getstatement/GetStatementApplication.java @@ -33,7 +33,6 @@ public GetStatementApplication(WebClient.Builder webClientBuilder) { // Set the Authorization value .defaultHeader("Authorization", "") - .build(); From 0ddead5a994e719015e37643b670a63068013019 Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Tue, 7 Mar 2023 23:33:46 +0000 Subject: [PATCH 11/18] tip --- .../xapi/samples/getstatements/GetStatementsApplication.java | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/get-statements/src/main/java/dev/learning/xapi/samples/getstatements/GetStatementsApplication.java b/samples/get-statements/src/main/java/dev/learning/xapi/samples/getstatements/GetStatementsApplication.java index 1abecce4..7108f327 100644 --- a/samples/get-statements/src/main/java/dev/learning/xapi/samples/getstatements/GetStatementsApplication.java +++ b/samples/get-statements/src/main/java/dev/learning/xapi/samples/getstatements/GetStatementsApplication.java @@ -32,7 +32,6 @@ public GetStatementsApplication(WebClient.Builder webClientBuilder) { // Set the Authorization value .defaultHeader("Authorization", "") - .build(); From 842a55b44ccf689ff559270a783907d23065edca Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Tue, 7 Mar 2023 23:35:05 +0000 Subject: [PATCH 12/18] tip --- .../samples/putagentprofile/PutAgentProfileApplication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/put-agent-profile/src/main/java/dev/learning/xapi/samples/putagentprofile/PutAgentProfileApplication.java b/samples/put-agent-profile/src/main/java/dev/learning/xapi/samples/putagentprofile/PutAgentProfileApplication.java index cd0bf383..d8882424 100644 --- a/samples/put-agent-profile/src/main/java/dev/learning/xapi/samples/putagentprofile/PutAgentProfileApplication.java +++ b/samples/put-agent-profile/src/main/java/dev/learning/xapi/samples/putagentprofile/PutAgentProfileApplication.java @@ -46,7 +46,7 @@ public void run(String... args) throws Exception { // Put Profile client.putAgentProfile(r -> r.agent(a -> a.name("A N Other").mbox("mailto:another@example.com")) - .profileId("bookmark864") + .profileId("bookmark") .profile(new ExampleState("Hello World!", Instant.now()))) From 90625bf3321a0d556853dc03a8d0e5188ea6fca9 Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Tue, 7 Mar 2023 23:38:52 +0000 Subject: [PATCH 13/18] tip --- ...ivityProfile.java => PutActivityProfileApplication.java} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename samples/put-activity-profile/src/main/java/dev/learning/xapi/samples/putactivityprofile/{PutActivityProfile.java => PutActivityProfileApplication.java} (86%) diff --git a/samples/put-activity-profile/src/main/java/dev/learning/xapi/samples/putactivityprofile/PutActivityProfile.java b/samples/put-activity-profile/src/main/java/dev/learning/xapi/samples/putactivityprofile/PutActivityProfileApplication.java similarity index 86% rename from samples/put-activity-profile/src/main/java/dev/learning/xapi/samples/putactivityprofile/PutActivityProfile.java rename to samples/put-activity-profile/src/main/java/dev/learning/xapi/samples/putactivityprofile/PutActivityProfileApplication.java index d0254889..8c3850b6 100644 --- a/samples/put-activity-profile/src/main/java/dev/learning/xapi/samples/putactivityprofile/PutActivityProfile.java +++ b/samples/put-activity-profile/src/main/java/dev/learning/xapi/samples/putactivityprofile/PutActivityProfileApplication.java @@ -18,7 +18,7 @@ * @author Thomas Turrell-Croft */ @SpringBootApplication -public class PutActivityProfile implements CommandLineRunner { +public class PutActivityProfileApplication implements CommandLineRunner { private final XapiClient client; @@ -26,7 +26,7 @@ public class PutActivityProfile implements CommandLineRunner { * Constructor for application. In this sample the WebClient.Builder instance is injected by the * Spring Framework. */ - public PutActivityProfile(WebClient.Builder webClientBuilder) { + public PutActivityProfileApplication(WebClient.Builder webClientBuilder) { webClientBuilder // Change for the URL of your LRS @@ -40,7 +40,7 @@ public PutActivityProfile(WebClient.Builder webClientBuilder) { } public static void main(String[] args) { - SpringApplication.run(PutActivityProfile.class, args).close(); + SpringApplication.run(PutActivityProfileApplication.class, args).close(); } @Override From 7bd6e1229d019fbab6a244aeb0f363a792f84952 Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Tue, 7 Mar 2023 23:40:48 +0000 Subject: [PATCH 14/18] tip --- .../samples/getmorestatements/GetMoreStatementsApplication.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/samples/get-more-statements/src/main/java/dev/learning/xapi/samples/getmorestatements/GetMoreStatementsApplication.java b/samples/get-more-statements/src/main/java/dev/learning/xapi/samples/getmorestatements/GetMoreStatementsApplication.java index 372c7bc7..82112995 100644 --- a/samples/get-more-statements/src/main/java/dev/learning/xapi/samples/getmorestatements/GetMoreStatementsApplication.java +++ b/samples/get-more-statements/src/main/java/dev/learning/xapi/samples/getmorestatements/GetMoreStatementsApplication.java @@ -54,8 +54,6 @@ public void run(String... args) throws Exception { URI moreUrl = response.getBody().getMore(); - System.out.println("me " + moreUrl); - if (moreUrl.getPath() != "") { // Get More Statements ResponseEntity more = client.getMoreStatements(r -> r.more(moreUrl)).block(); From 5a7a4405b393d6cdf92cd3114db77d0e942f6bc3 Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Tue, 7 Mar 2023 23:41:02 +0000 Subject: [PATCH 15/18] tip --- .../samples/getmorestatements/GetMoreStatementsApplication.java | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/get-more-statements/src/main/java/dev/learning/xapi/samples/getmorestatements/GetMoreStatementsApplication.java b/samples/get-more-statements/src/main/java/dev/learning/xapi/samples/getmorestatements/GetMoreStatementsApplication.java index 82112995..39c424db 100644 --- a/samples/get-more-statements/src/main/java/dev/learning/xapi/samples/getmorestatements/GetMoreStatementsApplication.java +++ b/samples/get-more-statements/src/main/java/dev/learning/xapi/samples/getmorestatements/GetMoreStatementsApplication.java @@ -51,7 +51,6 @@ public void run(String... args) throws Exception { // Print the returned statements to the console Arrays.asList(response.getBody().getStatements()).forEach(s -> System.out.println(s)); - URI moreUrl = response.getBody().getMore(); if (moreUrl.getPath() != "") { From 53d5a10c8a48b9a97976f82a917d155a7b8308ba Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Wed, 8 Mar 2023 10:24:04 +0000 Subject: [PATCH 16/18] tip --- .../GetMoreStatementsApplication.java | 12 ++--- .../learning/xapi/model/StatementResult.java | 14 ++++++ .../xapi/model/StatementResultTest.java | 45 +++++++++++++++++++ .../learning/xapi/model/StatementTests.java | 20 +++++++++ 4 files changed, 85 insertions(+), 6 deletions(-) diff --git a/samples/get-more-statements/src/main/java/dev/learning/xapi/samples/getmorestatements/GetMoreStatementsApplication.java b/samples/get-more-statements/src/main/java/dev/learning/xapi/samples/getmorestatements/GetMoreStatementsApplication.java index 39c424db..b3616d9b 100644 --- a/samples/get-more-statements/src/main/java/dev/learning/xapi/samples/getmorestatements/GetMoreStatementsApplication.java +++ b/samples/get-more-statements/src/main/java/dev/learning/xapi/samples/getmorestatements/GetMoreStatementsApplication.java @@ -2,7 +2,6 @@ import dev.learning.xapi.client.XapiClient; import dev.learning.xapi.model.StatementResult; -import java.net.URI; import java.util.Arrays; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; @@ -48,14 +47,15 @@ public void run(String... args) throws Exception { // Get Statements ResponseEntity response = client.getStatements(r -> r.limit(1)).block(); - // Print the returned statements to the console - Arrays.asList(response.getBody().getStatements()).forEach(s -> System.out.println(s)); + StatementResult result = response.getBody(); - URI moreUrl = response.getBody().getMore(); + // Print the returned statements to the console + Arrays.asList(result.getStatements()).forEach(s -> System.out.println(s)); - if (moreUrl.getPath() != "") { + if (result.hasMore()) { // Get More Statements - ResponseEntity more = client.getMoreStatements(r -> r.more(moreUrl)).block(); + ResponseEntity more = + client.getMoreStatements(r -> r.more(result.getMore())).block(); // Print the returned statements to the console Arrays.asList(more.getBody().getStatements()).forEach(s -> System.out.println(s)); diff --git a/xapi-model/src/main/java/dev/learning/xapi/model/StatementResult.java b/xapi-model/src/main/java/dev/learning/xapi/model/StatementResult.java index 6cce9ad3..37b36ec7 100644 --- a/xapi-model/src/main/java/dev/learning/xapi/model/StatementResult.java +++ b/xapi-model/src/main/java/dev/learning/xapi/model/StatementResult.java @@ -28,6 +28,8 @@ @JsonInclude(Include.NON_NULL) // Statements array could be empty public class StatementResult { + private final static URI NO_MORE = URI.create(""); + /** * List of Statements. Where no matching Statements are found, this property will contain an empty * array. @@ -41,6 +43,18 @@ public class StatementResult { // **Warning** do not add fields that are not required by the xAPI specification. + /** + * True if more is not empty or null. + * + * @return true if there are more statements + */ + public boolean hasMore() { + + // It is prudent check for null, even though the xAPI specification does not require it. + + return !(NO_MORE.equals(more) || more == null); + } + /** * Builder for Statement. */ diff --git a/xapi-model/src/test/java/dev/learning/xapi/model/StatementResultTest.java b/xapi-model/src/test/java/dev/learning/xapi/model/StatementResultTest.java index 54661441..30e7d985 100644 --- a/xapi-model/src/test/java/dev/learning/xapi/model/StatementResultTest.java +++ b/xapi-model/src/test/java/dev/learning/xapi/model/StatementResultTest.java @@ -132,5 +132,50 @@ void whenBuildingStatementResultWithTwoStatementsThenStatmentsIsArrayWithSizeTwo } + @Test + void whenBuildingStatementResultWithEmptyMoreThenHasMoreIsFalse() { + + // When Building StatementResult With Empty More + final StatementResult statementResult = StatementResult.builder() + + .more(URI.create("")) + + .build(); + + // Then HasMore Is False + assertThat(statementResult.hasMore(), is(false)); + + } + + @Test + void whenBuildingStatementResultWithNullMoreThenHasMoreIsFalse() { + + // When Building StatementResult With Null More + final StatementResult statementResult = StatementResult.builder() + + .more(null) + + .build(); + + // Then HasMore Is False + assertThat(statementResult.hasMore(), is(false)); + + } + + @Test + void whenBuildingStatementResultWithMoreThenHasMoreIsTrue() { + + // When Building StatementResult With More + final StatementResult statementResult = StatementResult.builder() + + .more(URI.create("123")) + + .build(); + + // Then HasMore Is True + assertThat(statementResult.hasMore(), is(true)); + + } + } diff --git a/xapi-model/src/test/java/dev/learning/xapi/model/StatementTests.java b/xapi-model/src/test/java/dev/learning/xapi/model/StatementTests.java index 7495f6c1..d3c4d3b0 100644 --- a/xapi-model/src/test/java/dev/learning/xapi/model/StatementTests.java +++ b/xapi-model/src/test/java/dev/learning/xapi/model/StatementTests.java @@ -349,6 +349,26 @@ void givenStatementWithPassedVerbWhenCallingToBuilderAndSettingVerbToCompletedTh } + @Test + void WhenCallingToBuilderAndSettingVerbToCompletedThenResultVerbIsCompleted() { + + // When Building Statement With Statement Reference Object + final Statement statement = Statement.builder() + + .actor(a -> a.name("A N Other")) + + .verb(Verb.VOIDED) + + .statementReferenceObject( + sr -> sr.id(UUID.fromString("c972020f-0718-4033-95d0-4b502a115aa9"))) + + .build(); + + // Then Statement Object Is Instances Of StatementReference + assertThat(statement.getObject(), instanceOf(StatementReference.class)); + + } + @Test void whenValidatingStatementWithAllRequiredPropertiesThenConstraintViolationsSizeIsZero() { From e4c452d5a11deeeaf53631fc855fb07962f6c5bd Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Wed, 8 Mar 2023 10:32:03 +0000 Subject: [PATCH 17/18] tip --- .../main/java/dev/learning/xapi/model/StatementResult.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xapi-model/src/main/java/dev/learning/xapi/model/StatementResult.java b/xapi-model/src/main/java/dev/learning/xapi/model/StatementResult.java index 37b36ec7..481cca81 100644 --- a/xapi-model/src/main/java/dev/learning/xapi/model/StatementResult.java +++ b/xapi-model/src/main/java/dev/learning/xapi/model/StatementResult.java @@ -28,7 +28,7 @@ @JsonInclude(Include.NON_NULL) // Statements array could be empty public class StatementResult { - private final static URI NO_MORE = URI.create(""); + private static final URI NO_MORE = URI.create(""); /** * List of Statements. Where no matching Statements are found, this property will contain an empty @@ -45,7 +45,7 @@ public class StatementResult { /** * True if more is not empty or null. - * + * * @return true if there are more statements */ public boolean hasMore() { From 88a249c4546da4d204aa6a610c2ba6ee82a98f46 Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Wed, 8 Mar 2023 11:25:48 +0000 Subject: [PATCH 18/18] tip --- .../xapi/samples/getagents/GetAgentsApplication.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/get-agents/src/main/java/dev/learning/xapi/samples/getagents/GetAgentsApplication.java b/samples/get-agents/src/main/java/dev/learning/xapi/samples/getagents/GetAgentsApplication.java index f6347c56..4c80df4d 100644 --- a/samples/get-agents/src/main/java/dev/learning/xapi/samples/getagents/GetAgentsApplication.java +++ b/samples/get-agents/src/main/java/dev/learning/xapi/samples/getagents/GetAgentsApplication.java @@ -46,15 +46,15 @@ public static void main(String[] args) { @Override public void run(String... args) throws Exception { - // Post statement for later retrieval of activity + // Post statement for later retrieval of Agent postStatement(); - // Get Activity + // Get Agents ResponseEntity response = client.getAgents(r -> r.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"))) .block(); - // Print the returned activity to the console + // Print the returned Person to the console System.out.println(response.getBody()); }