исправление отправки оценки
This commit is contained in:
parent
a85f511e9d
commit
7ad47f42f4
5
pom.xml
5
pom.xml
|
|
@ -64,6 +64,11 @@
|
|||
<version>42.7.8</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package ru.oa2.lti.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class MapperConfig {
|
||||
|
||||
@Bean
|
||||
public ObjectMapper getMapper() {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
mapper.disable(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
|
||||
return mapper;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,8 +5,12 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestClient;
|
||||
import ru.oa2.lti.service.jwt.IdTokenPayload;
|
||||
import ru.oa2.lti.service.results.dto.GradingType;
|
||||
import ru.oa2.lti.service.results.dto.Lineitems;
|
||||
import ru.oa2.lti.service.results.dto.ProgressType;
|
||||
import ru.oa2.lti.service.results.dto.ResultRequest;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
|
|
@ -15,9 +19,9 @@ public class ResultServiceImpl implements ResultService {
|
|||
private final RestClient restClient;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public ResultServiceImpl(RestClient client) {
|
||||
public ResultServiceImpl(RestClient client, ObjectMapper mapper) {
|
||||
this.restClient = client;
|
||||
this.mapper = new ObjectMapper();
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -40,6 +44,18 @@ public class ResultServiceImpl implements ResultService {
|
|||
String resourceId = "112999233990970"; //TODO
|
||||
String userId = "efc0b988-cfe0-4d00-9466-cf86fcf8f885"; //TODO
|
||||
|
||||
|
||||
var body = mapper.writeValueAsString(
|
||||
ResultRequest.builder()
|
||||
.scoreGiven(1L)
|
||||
.scoreMaximum(1L)
|
||||
.activityProgress(ProgressType.Completed)
|
||||
.gradingProgress(GradingType.FullyGraded)
|
||||
.timestamp(LocalDateTime.now())
|
||||
.userId(userId)
|
||||
.build()
|
||||
);
|
||||
|
||||
var result = restClient
|
||||
.post()
|
||||
.uri(String.format("/lti/ags/%s/context/%s/lineitems/laba/lineitem/scores/x",
|
||||
|
|
@ -47,13 +63,9 @@ public class ResultServiceImpl implements ResultService {
|
|||
.header("Authorization", "Bearer " + accessToken)
|
||||
.header("Content-Type", "application/vnd.ims.lis.v1.score+json")
|
||||
.header("Accept", "application/vnd.ims.lis.v1.score+json")
|
||||
.body(
|
||||
String.format(
|
||||
"{\"id\":\"%s\", \"userId\": \"%s\", \"scoreMaximum\": 1, \"label\":\"LTI page 1\", \"resourceId\": \"%s\"}",
|
||||
lineitems.id(), userId, lineitems.resourceId()
|
||||
)
|
||||
)
|
||||
.body(body)
|
||||
.retrieve();
|
||||
|
||||
log.info("RESULT RESP: {}", result.toEntity(String.class));
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package ru.oa2.lti.service.results.dto;
|
||||
|
||||
public enum GradingType {
|
||||
NotStarted,
|
||||
Pending,
|
||||
PendingManual,
|
||||
Failed,
|
||||
FullyGraded
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package ru.oa2.lti.service.results;
|
||||
package ru.oa2.lti.service.results.dto;
|
||||
|
||||
public record Lineitems(
|
||||
String id,
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package ru.oa2.lti.service.results.dto;
|
||||
|
||||
public enum ProgressType {
|
||||
Initialized,
|
||||
Started,
|
||||
Submitted,
|
||||
Completed
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package ru.oa2.lti.service.results.dto;
|
||||
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class ResultRequest {
|
||||
long scoreGiven;
|
||||
long scoreMaximum;
|
||||
ProgressType activityProgress;
|
||||
GradingType gradingProgress;
|
||||
LocalDateTime timestamp;
|
||||
String userId;
|
||||
}
|
||||
Loading…
Reference in New Issue