1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.bremersee.web.reactive.multipart;
18
19 import java.util.Collections;
20 import java.util.List;
21 import java.util.Map;
22 import javax.validation.constraints.NotNull;
23 import org.bremersee.web.multipart.FileAwareMultipartFile;
24 import org.springframework.http.codec.multipart.Part;
25 import org.springframework.util.MultiValueMap;
26 import org.springframework.validation.annotation.Validated;
27 import org.springframework.web.multipart.MultipartFile;
28 import reactor.core.publisher.Flux;
29 import reactor.core.publisher.Mono;
30
31
32
33
34
35
36 @Validated
37 public interface MultipartFileBuilder {
38
39
40
41
42
43
44
45
46
47 Mono<MultipartFile> build(Part part);
48
49
50
51
52
53
54
55 Mono<MultipartFile> build(@NotNull Flux<? extends Part> parts);
56
57
58
59
60
61
62
63 Mono<List<MultipartFile>> buildList(@NotNull Flux<? extends Part> parts);
64
65
66
67
68
69
70
71
72 Mono<List<MultipartFile>> buildList(
73 @NotNull MultiValueMap<String, Part> multiPartData,
74 String... requestParameters);
75
76
77
78
79
80
81
82
83 Flux<List<MultipartFile>> buildLists(
84 @NotNull MultiValueMap<String, Part> multiPartData,
85 String... requestParameters);
86
87
88
89
90
91
92
93 @SuppressWarnings("unchecked")
94 Mono<Map<String, MultipartFile>> buildMap(@NotNull Flux<? extends Part>... parts);
95
96
97
98
99
100
101
102
103 Mono<Map<String, MultipartFile>> buildMap(
104 @NotNull MultiValueMap<String, Part> multiPartData,
105 String... requestParameters);
106
107
108
109
110
111
112
113 @SuppressWarnings("unchecked")
114 Mono<MultiValueMap<String, MultipartFile>> buildMultiValueMap(
115 @NotNull Flux<? extends Part>... parts);
116
117
118
119
120
121
122
123
124 Mono<MultiValueMap<String, MultipartFile>> buildMultiValueMap(
125 @NotNull MultiValueMap<String, Part> multiPartData,
126 String... requestParameters);
127
128
129
130
131
132
133
134
135
136 @NotNull
137 static MultipartFile getMultipartFile(List<MultipartFile> list, int index) {
138 MultipartFile multipartFile = list != null && index >= 0 && list.size() > index
139 ? list.get(index)
140 : FileAwareMultipartFile.empty();
141 return multipartFile != null ? multipartFile : FileAwareMultipartFile.empty();
142 }
143
144
145
146
147
148
149
150
151
152 @NotNull
153 static MultipartFile getMultipartFile(Map<String, MultipartFile> map, String name) {
154 MultipartFile multipartFile = map != null && name != null
155 ? map.getOrDefault(name, FileAwareMultipartFile.empty())
156 : FileAwareMultipartFile.empty();
157 return multipartFile != null ? multipartFile : FileAwareMultipartFile.empty();
158 }
159
160
161
162
163
164
165
166
167
168 @NotNull
169 static List<MultipartFile> getMultipartFiles(
170 MultiValueMap<String, MultipartFile> map,
171 String name) {
172
173 List<MultipartFile> list = map != null && name != null
174 ? map.getOrDefault(name, Collections.emptyList())
175 : Collections.emptyList();
176 return list != null ? list : Collections.emptyList();
177 }
178
179
180
181
182
183
184
185
186 @NotNull
187 static MultipartFile getFirstMultipartFile(
188 MultiValueMap<String, MultipartFile> map,
189 String name) {
190
191 MultipartFile multipartFile = map != null && name != null
192 ? map.getFirst(name)
193 : FileAwareMultipartFile.empty();
194 return multipartFile != null ? multipartFile : FileAwareMultipartFile.empty();
195 }
196
197 }