Десериализация jsonb в структуру
This commit is contained in:
parent
20c67a04fc
commit
ec3f3318ac
|
|
@ -3,6 +3,7 @@ package ru.oa2.lti;
|
||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ru.oa2.lti.model.LtiLogin;
|
import ru.oa2.lti.model.LtiLogin;
|
||||||
|
import ru.oa2.lti.model.TaskData;
|
||||||
import ru.oa2.lti.repository.LMSContentRepository;
|
import ru.oa2.lti.repository.LMSContentRepository;
|
||||||
import ru.oa2.lti.repository.entities.LMSContent;
|
import ru.oa2.lti.repository.entities.LMSContent;
|
||||||
import ru.oa2.lti.repository.entities.Task;
|
import ru.oa2.lti.repository.entities.Task;
|
||||||
|
|
@ -38,8 +39,10 @@ public class ApplicationService {
|
||||||
Collection<Task> tasks = lmsContent.getTasks();
|
Collection<Task> tasks = lmsContent.getTasks();
|
||||||
|
|
||||||
//TODO добавить версию в Task и выбирать самую старшую и опубликованную
|
//TODO добавить версию в Task и выбирать самую старшую и опубликованную
|
||||||
Object data = tasks.stream().findFirst().get().getData();
|
TaskData data = tasks.stream().findFirst().get().getData();
|
||||||
return (String)data;
|
|
||||||
|
//TODO запуск initScript
|
||||||
|
return data.getDescription();
|
||||||
} else {
|
} else {
|
||||||
return "Not Page";
|
return "Not Page";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ public class AppConfig {
|
||||||
@Bean
|
@Bean
|
||||||
public JwtDecoder jwtDecoder() {
|
public JwtDecoder jwtDecoder() {
|
||||||
return NimbusJwtDecoder
|
return NimbusJwtDecoder
|
||||||
.withJwkSetUri(appProperties.lmsUri() + "/lti/keys")
|
.withJwkSetUri(appProperties.lmsUrl() + "/lti/keys")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,7 +40,7 @@ public class AppConfig {
|
||||||
@Bean
|
@Bean
|
||||||
public RestClient getRestClient(RestClient.Builder restClientBuilder) {
|
public RestClient getRestClient(RestClient.Builder restClientBuilder) {
|
||||||
return restClientBuilder
|
return restClientBuilder
|
||||||
.baseUrl(appProperties.lmsUri())
|
.baseUrl(appProperties.lmsUrl())
|
||||||
.defaultHeader(HttpHeaders.USER_AGENT, "LtiProvider")
|
.defaultHeader(HttpHeaders.USER_AGENT, "LtiProvider")
|
||||||
.defaultStatusHandler(HttpStatusCode::isError, (req, res) -> {
|
.defaultStatusHandler(HttpStatusCode::isError, (req, res) -> {
|
||||||
throw new RuntimeException("API error: " + res.getStatusCode() + " body: " +
|
throw new RuntimeException("API error: " + res.getStatusCode() + " body: " +
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
@ConfigurationProperties(prefix = "lti")
|
@ConfigurationProperties(prefix = "lti")
|
||||||
public record AppProperties(
|
public record AppProperties(
|
||||||
String lmsUri
|
String lmsUrl
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package ru.oa2.lti.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TaskData {
|
||||||
|
String initScript;
|
||||||
|
String description;
|
||||||
|
String verificationScript;
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,9 @@ package ru.oa2.lti.repository.entities;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.hibernate.annotations.JdbcTypeCode;
|
||||||
|
import org.hibernate.type.SqlTypes;
|
||||||
|
import ru.oa2.lti.model.TaskData;
|
||||||
import ru.oa2.lti.model.TaskType;
|
import ru.oa2.lti.model.TaskType;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
|
@ -17,6 +20,7 @@ public class Task {
|
||||||
@Enumerated(EnumType.STRING)
|
@Enumerated(EnumType.STRING)
|
||||||
TaskType taskType;
|
TaskType taskType;
|
||||||
|
|
||||||
|
@JdbcTypeCode(SqlTypes.JSON)
|
||||||
@Column(name = "data", columnDefinition = "jsonb")
|
@Column(name = "data", columnDefinition = "jsonb")
|
||||||
Object data;
|
TaskData data;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ public class TokenService {
|
||||||
public String exchangeForAccessToken(
|
public String exchangeForAccessToken(
|
||||||
String clientId) {
|
String clientId) {
|
||||||
|
|
||||||
var endpointUrl = appProperties.lmsUri() + "/lti/token";
|
var endpointUrl = appProperties.lmsUrl() + "/lti/token";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Генерируем client_assertion
|
// Генерируем client_assertion
|
||||||
|
|
@ -74,7 +74,7 @@ public class TokenService {
|
||||||
"&code=code1" +
|
"&code=code1" +
|
||||||
"&iss=" + iss +
|
"&iss=" + iss +
|
||||||
"&login_hint=" + loginHint +
|
"&login_hint=" + loginHint +
|
||||||
"&redirect_uri=" + appProperties.lmsUri() + "/tool/lti/redirect" +
|
"&redirect_uri=" + appProperties.lmsUrl() + "/tool/lti/redirect" +
|
||||||
"<i_message_hint=" + ltiLoginHint)
|
"<i_message_hint=" + ltiLoginHint)
|
||||||
.retrieve();
|
.retrieve();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue