diff --git a/pom.xml b/pom.xml index 3b60db0..d3ddeac 100644 --- a/pom.xml +++ b/pom.xml @@ -1,45 +1,48 @@ - - - 4.0.0 - - edu.uoc.elc.lti - lti-1.3-core - 0.0.2 - jar - - lti-1.3-core - Shared interfaces and beans for using in LTI libraries - - - UTF-8 - UTF-8 - 1.8 - - - - - org.projectlombok - lombok - 1.16.10 - provided - - - com.fasterxml.jackson.core - jackson-databind - 2.9.10.1 - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - - - - + + + 4.0.0 + + edu.uoc.elc.lti + lti-1.3-core + 0.0.2 + jar + + lti-1.3-core + Shared interfaces and beans for using in LTI libraries + + + UTF-8 + UTF-8 + 1.8 + + + + + org.projectlombok + lombok + 1.18.12 + provided + + + com.fasterxml.jackson.core + jackson-databind + 2.9.10.1 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + + diff --git a/src/main/java/edu/uoc/lti/accesstoken/AccessTokenRequest.java b/src/main/java/edu/uoc/lti/accesstoken/AccessTokenRequest.java index 12676af..7b71bdc 100644 --- a/src/main/java/edu/uoc/lti/accesstoken/AccessTokenRequest.java +++ b/src/main/java/edu/uoc/lti/accesstoken/AccessTokenRequest.java @@ -1,16 +1,16 @@ -package edu.uoc.lti.accesstoken; - -import lombok.Builder; -import lombok.Getter; - -/** - * @author Created by xaracil@uoc.edu - */ -@Getter -@Builder -public class AccessTokenRequest { - private String grant_type; - private String client_assertion_type; - private String scope; - private String client_assertion; -} +package edu.uoc.lti.accesstoken; + +import lombok.Builder; +import lombok.Value; + +/** + * @author Created by xaracil@uoc.edu + */ +@Value +@Builder +public class AccessTokenRequest { + private String grant_type; + private String client_assertion_type; + private String scope; + private String client_assertion; +} diff --git a/src/main/java/edu/uoc/lti/accesstoken/UrlEncodedFormAccessTokenRequestBuilderImpl.java b/src/main/java/edu/uoc/lti/accesstoken/UrlEncodedFormAccessTokenRequestBuilderImpl.java index 9e6c119..8952193 100644 --- a/src/main/java/edu/uoc/lti/accesstoken/UrlEncodedFormAccessTokenRequestBuilderImpl.java +++ b/src/main/java/edu/uoc/lti/accesstoken/UrlEncodedFormAccessTokenRequestBuilderImpl.java @@ -1,50 +1,51 @@ -package edu.uoc.lti.accesstoken; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.stream.Collectors; - -public class UrlEncodedFormAccessTokenRequestBuilderImpl implements AccessTokenRequestBuilder { - - @Override - public String build(final AccessTokenRequest request) throws IOException { - final Method[] methods = request.getClass().getDeclaredMethods(); - - return Arrays.stream(methods) - .map(method -> { - try { - if (!method.getName().startsWith("get")) { - return null; - } - final Object value = method.invoke(request, null); - String valueAsString = null; - if (method.getReturnType().getSimpleName().equals("String")) { - valueAsString = (String) value; - } - else if (method.getReturnType().isPrimitive()) { - valueAsString = String.valueOf(value); - } - return valueAsString != null && valueAsString.length() > 0 - ? method.getName().substring(3, 4).toLowerCase() + method.getName().substring(4) + "=" + URLEncoder.encode(valueAsString, StandardCharsets.UTF_8.toString()) - : null; - } catch (IllegalArgumentException | InvocationTargetException | UnsupportedEncodingException - | IllegalAccessException e) { - e.printStackTrace(); - } - return null; - }) - .filter(value -> value != null) - .collect(Collectors.joining("&")); - } - - @Override - public String getContentType() { - return "application/x-www-form-urlencoded"; - } - +package edu.uoc.lti.accesstoken; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.stream.Collectors; + +import lombok.extern.java.Log; + +@Log +public class UrlEncodedFormAccessTokenRequestBuilderImpl implements AccessTokenRequestBuilder { + + @Override + public String build(final AccessTokenRequest request) throws IOException { + final Method[] methods = request.getClass().getDeclaredMethods(); + + return Arrays.stream(methods).map(method -> { + try { + if (!method.getName().startsWith("get")) { + return null; + } + final Object value = method.invoke(request, (Object[]) null); + String valueAsString = null; + if (method.getReturnType().getSimpleName().equals("String")) { + valueAsString = (String) value; + } else if (method.getReturnType().isPrimitive()) { + valueAsString = String.valueOf(value); + } + return valueAsString != null && valueAsString.length() > 0 + ? method.getName().substring(3, 4).toLowerCase() + method.getName().substring(4) + "=" + + URLEncoder.encode(valueAsString, StandardCharsets.UTF_8.toString()) + : null; + } catch (IllegalArgumentException | InvocationTargetException | UnsupportedEncodingException + | IllegalAccessException e) { + log.warning("Cannot build UrlEncodedFormAccessTokenRequest. " + e.getClass().getName() + " - " + + e.getMessage()); + } + return null; + }).filter(value -> value != null).collect(Collectors.joining("&")); + } + + @Override + public String getContentType() { + return "application/x-www-form-urlencoded"; + } + } \ No newline at end of file diff --git a/src/main/java/edu/uoc/lti/ags/LineItem.java b/src/main/java/edu/uoc/lti/ags/LineItem.java index afc2c39..6190b10 100644 --- a/src/main/java/edu/uoc/lti/ags/LineItem.java +++ b/src/main/java/edu/uoc/lti/ags/LineItem.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; + import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; diff --git a/src/main/java/edu/uoc/lti/ags/Result.java b/src/main/java/edu/uoc/lti/ags/Result.java index cecec2f..0f6972b 100644 --- a/src/main/java/edu/uoc/lti/ags/Result.java +++ b/src/main/java/edu/uoc/lti/ags/Result.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; + import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/edu/uoc/lti/ags/Score.java b/src/main/java/edu/uoc/lti/ags/Score.java index a499f8f..3fefaa9 100644 --- a/src/main/java/edu/uoc/lti/ags/Score.java +++ b/src/main/java/edu/uoc/lti/ags/Score.java @@ -1,13 +1,14 @@ package edu.uoc.lti.ags; +import java.time.Instant; + import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; + import lombok.Builder; import lombok.Getter; import lombok.Setter; -import java.time.Instant; - /** * @author Created by xaracil@uoc.edu */ diff --git a/src/main/java/edu/uoc/lti/ags/Submission.java b/src/main/java/edu/uoc/lti/ags/Submission.java index 69cde1e..5bf9443 100644 --- a/src/main/java/edu/uoc/lti/ags/Submission.java +++ b/src/main/java/edu/uoc/lti/ags/Submission.java @@ -1,10 +1,11 @@ package edu.uoc.lti.ags; +import java.time.Instant; + import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.Setter; -import java.time.Instant; +import lombok.Setter; /** * @author Created by xaracil@uoc.edu diff --git a/src/main/java/edu/uoc/lti/deeplink/DeepLinkingResponse.java b/src/main/java/edu/uoc/lti/deeplink/DeepLinkingResponse.java index 0639f82..4ac7d66 100644 --- a/src/main/java/edu/uoc/lti/deeplink/DeepLinkingResponse.java +++ b/src/main/java/edu/uoc/lti/deeplink/DeepLinkingResponse.java @@ -1,12 +1,11 @@ package edu.uoc.lti.deeplink; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; - import java.util.List; import edu.uoc.lti.deeplink.content.Item; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; /** * @author Created by xaracil@uoc.edu diff --git a/src/main/java/edu/uoc/lti/deeplink/content/DataItem.java b/src/main/java/edu/uoc/lti/deeplink/content/DataItem.java index af1110e..e0924a4 100644 --- a/src/main/java/edu/uoc/lti/deeplink/content/DataItem.java +++ b/src/main/java/edu/uoc/lti/deeplink/content/DataItem.java @@ -1,6 +1,7 @@ package edu.uoc.lti.deeplink.content; import com.fasterxml.jackson.annotation.JsonInclude; + import lombok.Builder; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/edu/uoc/lti/deeplink/content/Duration.java b/src/main/java/edu/uoc/lti/deeplink/content/Duration.java index 57e4a73..1ca3620 100644 --- a/src/main/java/edu/uoc/lti/deeplink/content/Duration.java +++ b/src/main/java/edu/uoc/lti/deeplink/content/Duration.java @@ -1,12 +1,13 @@ package edu.uoc.lti.deeplink.content; +import java.time.Instant; + import com.fasterxml.jackson.annotation.JsonInclude; + import lombok.Builder; import lombok.Setter; import lombok.ToString; -import java.time.Instant; - /** * @author Created by xaracil@uoc.edu */ diff --git a/src/main/java/edu/uoc/lti/deeplink/content/FileItem.java b/src/main/java/edu/uoc/lti/deeplink/content/FileItem.java index 1090a91..906c489 100644 --- a/src/main/java/edu/uoc/lti/deeplink/content/FileItem.java +++ b/src/main/java/edu/uoc/lti/deeplink/content/FileItem.java @@ -1,12 +1,12 @@ package edu.uoc.lti.deeplink.content; +import java.time.Instant; + import lombok.Builder; import lombok.Getter; import lombok.Setter; import lombok.ToString; -import java.time.Instant; - /** * @author Created by xaracil@uoc.edu */ diff --git a/src/main/java/edu/uoc/lti/deeplink/content/HtmlItem.java b/src/main/java/edu/uoc/lti/deeplink/content/HtmlItem.java index 424ea39..16cdd65 100644 --- a/src/main/java/edu/uoc/lti/deeplink/content/HtmlItem.java +++ b/src/main/java/edu/uoc/lti/deeplink/content/HtmlItem.java @@ -1,6 +1,7 @@ package edu.uoc.lti.deeplink.content; import com.fasterxml.jackson.annotation.JsonInclude; + import lombok.Builder; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/edu/uoc/lti/deeplink/content/IFrame.java b/src/main/java/edu/uoc/lti/deeplink/content/IFrame.java index 2b8812e..4a295b6 100644 --- a/src/main/java/edu/uoc/lti/deeplink/content/IFrame.java +++ b/src/main/java/edu/uoc/lti/deeplink/content/IFrame.java @@ -1,6 +1,7 @@ package edu.uoc.lti.deeplink.content; import com.fasterxml.jackson.annotation.JsonInclude; + import lombok.Builder; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/edu/uoc/lti/deeplink/content/Image.java b/src/main/java/edu/uoc/lti/deeplink/content/Image.java index 5cdef4d..a8b1a1b 100644 --- a/src/main/java/edu/uoc/lti/deeplink/content/Image.java +++ b/src/main/java/edu/uoc/lti/deeplink/content/Image.java @@ -1,6 +1,7 @@ package edu.uoc.lti.deeplink.content; import com.fasterxml.jackson.annotation.JsonInclude; + import lombok.Builder; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/edu/uoc/lti/deeplink/content/ImageItem.java b/src/main/java/edu/uoc/lti/deeplink/content/ImageItem.java index b7a01e2..ef880c5 100644 --- a/src/main/java/edu/uoc/lti/deeplink/content/ImageItem.java +++ b/src/main/java/edu/uoc/lti/deeplink/content/ImageItem.java @@ -1,6 +1,7 @@ package edu.uoc.lti.deeplink.content; import com.fasterxml.jackson.annotation.JsonInclude; + import lombok.Builder; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/edu/uoc/lti/deeplink/content/Item.java b/src/main/java/edu/uoc/lti/deeplink/content/Item.java index 1a320ba..734318d 100644 --- a/src/main/java/edu/uoc/lti/deeplink/content/Item.java +++ b/src/main/java/edu/uoc/lti/deeplink/content/Item.java @@ -1,15 +1,16 @@ package edu.uoc.lti.deeplink.content; +import java.util.HashMap; +import java.util.Map; + import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonInclude; + import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.ToString; -import java.util.HashMap; -import java.util.Map; - /** * @author Created by xaracil@uoc.edu */ diff --git a/src/main/java/edu/uoc/lti/deeplink/content/LineItem.java b/src/main/java/edu/uoc/lti/deeplink/content/LineItem.java index d2de4af..c783538 100644 --- a/src/main/java/edu/uoc/lti/deeplink/content/LineItem.java +++ b/src/main/java/edu/uoc/lti/deeplink/content/LineItem.java @@ -1,6 +1,7 @@ package edu.uoc.lti.deeplink.content; import com.fasterxml.jackson.annotation.JsonInclude; + import lombok.Builder; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/edu/uoc/lti/deeplink/content/LinkItem.java b/src/main/java/edu/uoc/lti/deeplink/content/LinkItem.java index b9a63af..af7d45c 100644 --- a/src/main/java/edu/uoc/lti/deeplink/content/LinkItem.java +++ b/src/main/java/edu/uoc/lti/deeplink/content/LinkItem.java @@ -1,7 +1,11 @@ package edu.uoc.lti.deeplink.content; import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.*; + +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; /** * @author Created by xaracil@uoc.edu diff --git a/src/main/java/edu/uoc/lti/deeplink/content/LtiResourceItem.java b/src/main/java/edu/uoc/lti/deeplink/content/LtiResourceItem.java index ed80843..77826db 100644 --- a/src/main/java/edu/uoc/lti/deeplink/content/LtiResourceItem.java +++ b/src/main/java/edu/uoc/lti/deeplink/content/LtiResourceItem.java @@ -1,5 +1,8 @@ package edu.uoc.lti.deeplink.content; +import java.util.HashMap; +import java.util.Map; + import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Builder; @@ -7,9 +10,6 @@ import lombok.Setter; import lombok.ToString; -import java.util.HashMap; -import java.util.Map; - /** * @author Created by xaracil@uoc.edu */ diff --git a/src/main/java/edu/uoc/lti/deeplink/content/Presentation.java b/src/main/java/edu/uoc/lti/deeplink/content/Presentation.java index d1cdb8d..1d1e50d 100644 --- a/src/main/java/edu/uoc/lti/deeplink/content/Presentation.java +++ b/src/main/java/edu/uoc/lti/deeplink/content/Presentation.java @@ -1,30 +1,37 @@ -package edu.uoc.lti.deeplink.content; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -/** - * @author Created by xaracil@uoc.edu - */ -@Getter -@Setter -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonInclude(JsonInclude.Include.NON_EMPTY) -@ToString -public class Presentation { - @JsonProperty("document_target") - private String documentTarget; - private int width; - private int height; - @JsonProperty("return_url") - private String returnUrl; -} +package edu.uoc.lti.deeplink.content; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +/** + * @author Created by xaracil@uoc.edu + */ +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_EMPTY) +/* + * To fix an issue with Moodle 3.8 + * Moodle adds "locale". The @JsonIgnoreProperties annotation ignores unknown property + * @author heutelbeck + */ +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Presentation { + @JsonProperty("document_target") + private String documentTarget; + private int width; + private int height; + @JsonProperty("return_url") + private String returnUrl; +}