-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAgentProfileRequest.java
More file actions
94 lines (70 loc) · 2.02 KB
/
AgentProfileRequest.java
File metadata and controls
94 lines (70 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright 2016-2025 Berry Cloud Ltd. All rights reserved.
*/
package dev.learning.xapi.client;
import com.fasterxml.jackson.databind.ObjectMapper;
import dev.learning.xapi.model.Agent;
import java.util.Map;
import java.util.function.Consumer;
import lombok.NonNull;
import lombok.SneakyThrows;
import lombok.experimental.SuperBuilder;
import org.springframework.web.util.UriBuilder;
@SuperBuilder
abstract class AgentProfileRequest implements Request {
private static final ObjectMapper objectMapper = new ObjectMapper();
/**
* The Agent associated with this Profile document.
*/
@NonNull
private final Agent agent;
/**
* The profile id associated with this Profile document.
*/
@NonNull
private final String profileId;
@Override
public UriBuilder url(UriBuilder uriBuilder, Map<String, Object> queryParams) {
queryParams.put("agent", agentToJsonString());
queryParams.put("profileId", profileId);
return uriBuilder.path("/agents/profile").queryParam("agent", "{agent}").queryParam("profileId",
"{profileId}");
}
/**
* Builder for AgentProfileRequest.
*/
public abstract static class Builder<C extends AgentProfileRequest, B extends Builder<C, B>> {
/**
* Consumer Builder for agent.
*
* @param agent The Consumer Builder for agent.
*
* @return This builder
*
* @see AgentProfileRequest#agent
*/
public B agent(Consumer<Agent.Builder<?, ?>> agent) {
final Agent.Builder<?, ?> builder = Agent.builder();
agent.accept(builder);
return agent(builder.build());
}
/**
* Sets the agent.
*
* @param agent The Agent of the AgentProfileRequest.
*
* @return This builder
*
* @see AgentProfileRequest#agent
*/
public B agent(Agent agent) {
this.agent = agent;
return self();
}
}
// Exception in write value as string should be impossible.
@SneakyThrows
private String agentToJsonString() {
return objectMapper.writeValueAsString(agent);
}
}