-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSCIMPatchOperations.java
More file actions
120 lines (97 loc) · 3.07 KB
/
SCIMPatchOperations.java
File metadata and controls
120 lines (97 loc) · 3.07 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package org.kohsuke.github;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@JsonIgnoreProperties(ignoreUnknown = true)
public class SCIMPatchOperations {
private static final String PATCH_OP = "urn:ietf:params:scim:api:messages:2.0:PatchOp";
@JsonProperty("schemas")
public List<String> schemas = Collections.singletonList(PATCH_OP);
@JsonProperty("Operations")
public List<Operation> operations = new ArrayList<>();
public void replace(String path, String value) {
Operation op = new Operation();
op.op = "replace";
op.path = path;
op.value = value == null ? "" : value;
operations.add(op);
}
public void replace(String path, Boolean value) {
Operation op = new Operation();
op.op = "replace";
op.path = path;
op.value = value;
operations.add(op);
}
public void replace(SCIMEmail value) {
if (value == null) {
operations.add(removeAllOp("emails"));
return;
}
List<SCIMEmail> emails = new ArrayList<>();
emails.add(value);
Operation op = new Operation();
op.op = "replace";
op.path = "emails";
op.value = emails;
operations.add(op);
}
public void replace(SCIMRole value) {
if (value == null) {
operations.add(removeAllOp("roles"));
return;
}
List<SCIMRole> roles = new ArrayList<>();
roles.add(value);
Operation op = new Operation();
op.op = "replace";
op.path = "roles";
op.value = roles;
operations.add(op);
}
private Operation removeAllOp(String path) {
Operation op = new Operation();
op.op = "replace";
op.path = path;
op.value = Collections.emptyList();
return op;
}
public void addMembers(List<String> values) {
List<Member> members = values.stream().map(v -> {
Member member = new Member();
member.value = v;
return member;
}).collect(Collectors.toList());
Operation op = new Operation();
op.op = "add";
op.path = "members";
op.value = members;
operations.add(op);
}
public void removeMembers(List<String> values) {
List<Member> members = values.stream().map(v -> {
Member member = new Member();
member.value = v;
return member;
}).collect(Collectors.toList());
Operation op = new Operation();
op.op = "remove";
op.path = "members";
op.value = members;
operations.add(op);
}
public static class Operation {
public String op;
public String path;
public Object value;
}
public static class Member {
public String value;
}
public boolean hasAttributesChange() {
return !operations.isEmpty();
}
}