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