• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FIWARE / credentials-config-service / #55

04 Nov 2025 06:47AM UTC coverage: 83.552% (-0.9%) from 84.407%
#55

Pull #17

wistefan
fix tests
Pull Request #17: Add dcql support

67 of 71 new or added lines in 3 files covered. (94.37%)

49 existing lines in 2 files now uncovered.

574 of 687 relevant lines covered (83.55%)

0.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.56
/src/main/java/org/fiware/iam/ServiceMapper.java
1
package org.fiware.iam;
2

3
import com.fasterxml.jackson.databind.ObjectMapper;
4
import io.github.wistefan.dcql.model.*;
5
import org.fiware.iam.ccs.model.*;
6
import org.fiware.iam.repository.*;
7
import org.fiware.iam.repository.Credential;
8
import org.mapstruct.Mapper;
9

10
import java.util.*;
11
import java.util.stream.Collectors;
12

13
import static org.fiware.iam.ccs.model.MetaDataQueryVO.*;
14

15
/**
16
 * Responsible for mapping entities from the Service api domain to the internal model.
17
 */
18
@Mapper(componentModel = "jsr330")
19
public interface ServiceMapper {
20

21
        static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
1✔
22

23
        default Service map(ServiceVO serviceVO) {
24
                if (serviceVO == null) {
1✔
25
                        return null;
×
26
                }
27
                Service service = new Service();
1✔
28
                service.setId(serviceVO.getId());
1✔
29
                service.setAuthorizationType(map(serviceVO.getAuthorizationType()));
1✔
30
                service.setDefaultOidcScope(serviceVO.getDefaultOidcScope());
1✔
31
                service.setOidcScopes(
1✔
32
                                serviceVO.getOidcScopes()
1✔
33
                                                .entrySet()
1✔
34
                                                .stream()
1✔
35
                                                .map(e -> {
1✔
36
                                                        ScopeEntry scopeEntry = new ScopeEntry();
1✔
37
                                                        scopeEntry.setScopeKey(e.getKey());
1✔
38
                                                        scopeEntry.setCredentials(Optional.ofNullable(e.getValue().getCredentials()).
1✔
39
                                                                        orElse(List.of()).stream().map(this::map).toList());
1✔
40
                                                        scopeEntry.setPresentationDefinition(this.map(e.getValue().getPresentationDefinition()));
1✔
41
                                                        scopeEntry.setDcqlQuery(this.map(e.getValue().getDcql()));
1✔
42
                                                        return scopeEntry;
1✔
43
                                                })
44
                                                .toList());
1✔
45
                return service;
1✔
46
        }
47

48
        default ServiceVO map(Service service) {
49
                if (service == null) {
1✔
50
                        return null;
×
51
                }
52
                return new ServiceVO().id(service.getId())
1✔
53
                                .authorizationType(map(service.getAuthorizationType()))
1✔
54
                                .defaultOidcScope(service.getDefaultOidcScope())
1✔
55
                                .oidcScopes(this.toOidcScopes(service.getOidcScopes()));
1✔
56
        }
57

58
        default PresentationDefinition map(PresentationDefinitionVO presentationDefinitionVO) {
59
                if (presentationDefinitionVO == null) {
1✔
60
                        return null;
1✔
61
                }
62

63
                PresentationDefinition presentationDefinition = new PresentationDefinition();
1✔
64
                presentationDefinition.setId(presentationDefinitionVO.getId());
1✔
65
                presentationDefinition.setName(presentationDefinitionVO.getName());
1✔
66
                presentationDefinition.setPurpose(presentationDefinitionVO.getPurpose());
1✔
67
                presentationDefinition.setInputDescriptors(this.mapInputDescriptors(presentationDefinitionVO
1✔
68
                                .getInputDescriptors()));
1✔
69
                presentationDefinition.setFormat(this.mapFormatVO(presentationDefinitionVO
1✔
70
                                .getFormat()));
1✔
71

72
                return presentationDefinition;
1✔
73
        }
74

75
        default Collection<InputDescriptor> mapInputDescriptors(Collection<InputDescriptorVO> inputDescriptorVOS) {
76
                if (inputDescriptorVOS == null) {
1✔
77
                        return null;
×
78
                }
79
                return inputDescriptorVOS
1✔
80
                                .stream()
1✔
81
                                .map(this::mapInputDescriptorVO).toList();
1✔
82
        }
83

84
        default Collection<Format> mapFormatVO(Map<String, Object> formatsMap) {
85
                if (formatsMap == null) {
1✔
UNCOV
86
                        return null;
×
87
                }
88

89
                return formatsMap
1✔
90
                                .entrySet()
1✔
91
                                .stream()
1✔
92
                                .map(e -> {
1✔
93
                                        FormatObject formatObject = OBJECT_MAPPER.convertValue(e.getValue(), FormatObject.class);
1✔
94
                                        Format format = new Format();
1✔
95
                                        format.setFormatKey(e.getKey());
1✔
96
                                        format.setAlg(formatObject.getAlg());
1✔
97
                                        format.setProofType(formatObject.getProofType());
1✔
98
                                        return format;
1✔
99
                                }).toList();
1✔
100
        }
101

102
        default Map<String, Object> mapFormats(Collection<Format> formats) {
103
                if (formats == null) {
1✔
104
                        return null;
1✔
105
                }
106

107
                Map<String, Object> formatsMap = new HashMap<>();
1✔
108

109
                formats.stream()
1✔
110
                                .forEach(format -> {
1✔
111
                                        Map<String, Object> formatMap = new HashMap<>();
1✔
112
                                        Optional.ofNullable(format.getAlg()).ifPresent(algs -> formatMap.put("alg", algs));
1✔
113
                                        Optional.ofNullable(format.getProofType()).ifPresent(pt -> formatMap.put("proof_type", pt));
1✔
114
                                        formatsMap.put(format.getFormatKey(), formatMap);
1✔
115
                                });
1✔
116

117
                return formatsMap;
1✔
118
        }
119

120
        AuthorizationType map(ServiceVO.AuthorizationType authorizationType);
121

122
        ServiceVO.AuthorizationType map(AuthorizationType authorizationType);
123

124
        InputDescriptorVO mapInputDescriptor(InputDescriptor inputDescriptor);
125

126
        InputDescriptor mapInputDescriptorVO(InputDescriptorVO inputDescriptor);
127

128
        PresentationDefinitionVO map(PresentationDefinition presentationDefinition);
129

130
        TrustedParticipantsListEndpointVO.Type map(ListType type);
131

132
        ListType map(TrustedParticipantsListEndpointVO.Type type);
133

134
        default Map<String, ServiceScopesEntryVO> toOidcScopes(Collection<ScopeEntry> scopeEntries) {
135
                if (scopeEntries == null) {
1✔
136
                        return null;
×
137
                }
138
                Map<String, ServiceScopesEntryVO> scopes = new LinkedHashMap<>();
1✔
139
                scopeEntries
1✔
140
                                .forEach(entry -> {
1✔
141
                                        ServiceScopesEntryVO scopesEntryVO = new ServiceScopesEntryVO();
1✔
142
                                        scopesEntryVO.setPresentationDefinition(this.map(entry.getPresentationDefinition()));
1✔
143
                                        scopesEntryVO.setCredentials(this.map(entry.getCredentials()));
1✔
144
                                        scopesEntryVO.setDcql(this.map(entry.getDcqlQuery()));
1✔
145
                                        scopes.put(entry.getScopeKey(), scopesEntryVO);
1✔
146
                                });
1✔
147
                return scopes;
1✔
148
        }
149

150
        DCQLVO map(DcqlQuery dcqlQuery);
151

152
        DcqlQuery map(DCQLVO dcqlvo);
153

154
        default CredentialQuery map(CredentialQueryVO credentialQueryVO) {
155
                if (credentialQueryVO == null) {
1✔
NEW
156
                        return null;
×
157
                }
158
                CredentialQuery credentialQuery = new CredentialQuery();
1✔
159
                credentialQuery.setId(credentialQueryVO.getId());
1✔
160
                credentialQuery.setFormat(this.map(credentialQueryVO.getFormat()));
1✔
161
                credentialQuery.setMultiple(credentialQueryVO.getMultiple());
1✔
162
                credentialQuery.setClaims(Optional.ofNullable(credentialQueryVO.getClaims()).orElse(List.of())
1✔
163
                                .stream().map(this::map).toList());
1✔
164
                credentialQuery.setMeta(this.map(credentialQueryVO.getMeta()));
1✔
165
                credentialQuery.setRequireCryptographicHolderBinding(credentialQueryVO.getRequireCryptographicHolderBinding());
1✔
166
                credentialQuery.setClaimSets(credentialQueryVO.getClaimSets());
1✔
167
                credentialQuery.setTrustedAuthorities(Optional.ofNullable(credentialQueryVO.getTrustedAuthorities()).orElse(List.of())
1✔
168
                                .stream().map(this::map).toList());
1✔
169
                return credentialQuery;
1✔
170
        }
171

172
        default CredentialQueryVO map(CredentialQuery credentialQuery) {
173
                if (credentialQuery == null) {
1✔
NEW
174
                        return null;
×
175
                }
176
                CredentialQueryVO credentialQueryVO = new CredentialQueryVO();
1✔
177
                credentialQueryVO.setId(credentialQuery.getId());
1✔
178
                credentialQueryVO.setFormat(this.map(credentialQuery.getFormat()));
1✔
179
                credentialQueryVO.setMultiple(credentialQuery.getMultiple());
1✔
180
                credentialQueryVO.setClaims(Optional.ofNullable(credentialQuery.getClaims()).orElse(List.of())
1✔
181
                                .stream().map(this::map).toList());
1✔
182
                credentialQueryVO.setMeta(map(credentialQuery.getMeta()));
1✔
183
                credentialQueryVO.setRequireCryptographicHolderBinding(credentialQuery.getRequireCryptographicHolderBinding());
1✔
184
                credentialQueryVO.setClaimSets(credentialQuery.getClaimSets());
1✔
185
                credentialQueryVO.setTrustedAuthorities(Optional.ofNullable(credentialQuery.getTrustedAuthorities()).orElse(List.of())
1✔
186
                                .stream().map(this::map).toList());
1✔
187
                return credentialQueryVO;
1✔
188
        }
189

190
        TrustedAuthorityQueryVO map(TrustedAuthorityQuery trustedAuthorityQuery);
191

192
        TrustedAuthorityQuery map(TrustedAuthorityQueryVO trustedAuthorityQueryVO);
193

194
        default TrustedAuthorityType map(String type) {
195
                return TrustedAuthorityType.fromValue(type);
1✔
196
        }
197

198
        default String map(TrustedAuthorityType type) {
199
                return type.getValue();
1✔
200
        }
201

202
        default Map<String, Object> map(MetaDataQueryVO metaDataQueryVO) {
203
                if (metaDataQueryVO == null) {
1✔
NEW
204
                        return null;
×
205
                }
206
                Map<String, Object> metaMap = new HashMap<>();
1✔
207
                if (metaDataQueryVO.getVctValues() != null) {
1✔
208
                        metaMap.put(JSON_PROPERTY_VCT_VALUES, metaDataQueryVO.getVctValues());
1✔
209
                }
210
                if (metaDataQueryVO.getTypeValues() != null) {
1✔
211
                        metaMap.put(JSON_PROPERTY_TYPE_VALUES, metaDataQueryVO.getTypeValues());
1✔
212
                }
213
                if (metaDataQueryVO.getDoctypeValue() != null) {
1✔
214
                        metaMap.put(JSON_PROPERTY_DOCTYPE_VALUE, metaDataQueryVO.getDoctypeValue());
1✔
215
                }
216
                return metaMap;
1✔
217
        }
218

219
        default MetaDataQueryVO map(Map<String, Object> meta) {
220
                if (meta == null) {
1✔
NEW
221
                        return null;
×
222
                }
223
                MetaDataQueryVO metaDataQueryVO = new MetaDataQueryVO();
1✔
224
                if (meta.containsKey(JSON_PROPERTY_VCT_VALUES)) {
1✔
225
                        metaDataQueryVO.setVctValues((List<String>) meta.get(JSON_PROPERTY_VCT_VALUES));
1✔
226
                }
227
                if (meta.containsKey(JSON_PROPERTY_DOCTYPE_VALUE)) {
1✔
228
                        metaDataQueryVO.setDoctypeValue((String) meta.get(JSON_PROPERTY_DOCTYPE_VALUE));
1✔
229
                }
230
                if (meta.containsKey(JSON_PROPERTY_TYPE_VALUES)) {
1✔
231
                        metaDataQueryVO.setTypeValues((List<List<String>>) meta.get(JSON_PROPERTY_TYPE_VALUES));
1✔
232
                }
233
                return metaDataQueryVO;
1✔
234
        }
235

236
        ClaimsQuery map(ClaimsQueryVO claimsQueryVO);
237

238
        ClaimsQueryVO map(ClaimsQuery claimsQuery);
239

240
        CredentialQueryVO.Format map(CredentialFormat credentialFormat);
241

242
        CredentialFormat map(CredentialQueryVO.Format credentialFormat);
243

244
        CredentialSetQueryVO map(CredentialSetQuery credentialSetQuery);
245

246
        CredentialSetQuery map(CredentialSetQueryVO credentialSetQueryVO);
247

248
        default EndpointEntry stringToEndpointEntry(String url) {
249
                EndpointEntry entry = new EndpointEntry();
1✔
250
                entry.setType(EndpointType.TRUSTED_PARTICIPANTS);
1✔
251
                entry.setListType(ListType.EBSI);
1✔
252
                entry.setEndpoint(url);
1✔
253
                return entry;
1✔
254
        }
255

256
        default Credential map(CredentialVO credentialVO) {
257
                if (credentialVO == null) {
1✔
258
                        return null;
×
259
                }
260
                Credential credential = new Credential();
1✔
261
                credential.setCredentialType(credentialVO.getType());
1✔
262
                List<EndpointEntry> trustedList = new ArrayList<>();
1✔
263
                Optional.ofNullable(issuersToEntries(credentialVO.getTrustedIssuersLists())).ifPresent(trustedList::addAll);
1✔
264

265
                credentialVO.getTrustedParticipantsLists()
1✔
266
                                .forEach(tpl -> {
1✔
267
                                        if (tpl instanceof String tplS) {
1✔
268
                                                trustedList.add(stringToEndpointEntry(tplS));
1✔
269
                                        } else {
270
                                                trustedList.add(participantToEntry(OBJECT_MAPPER.convertValue(tpl, TrustedParticipantsListEndpointVO.class)));
1✔
271
                                        }
272
                                });
1✔
273

274
                credential.setTrustedLists(trustedList);
1✔
275

276
                if (credentialVO.getHolderVerification() != null) {
1✔
277
                        credential.setHolderClaim(credentialVO.getHolderVerification().getClaim());
1✔
278
                        credential.setVerifyHolder(credentialVO.getHolderVerification().getEnabled());
1✔
279
                } else {
280
                        credential.setVerifyHolder(false);
×
281
                        credential.setHolderClaim(null);
×
282
                }
283
                credential.setRequireCompliance(credentialVO.getRequireCompliance());
1✔
284
                credential.setJwtInclusion(map(credentialVO.getJwtInclusion()));
1✔
285
                return credential;
1✔
286
        }
287

288
        JwtInclusion map(JwtInclusionVO jwtInclusionVO);
289

290
        JwtInclusionVO map(JwtInclusion jwtInclusion);
291

292
        default List<CredentialVO> map(Collection<Credential> credentials) {
293
                if (credentials == null) {
1✔
294
                        return null;
×
295
                }
296
                return credentials.stream().map(this::map).toList();
1✔
297
        }
298

299
        default CredentialVO map(Credential credential) {
300
                if (credential == null) {
1✔
301
                        return null;
×
302
                }
303
                return new CredentialVO()
1✔
304
                                .type(credential.getCredentialType())
1✔
305
                                .trustedIssuersLists(entriesToIssuers(credential.getTrustedLists()))
1✔
306
                                .trustedParticipantsLists(entriesToParticipants(credential.getTrustedLists()).stream().map(Object.class::cast).toList())
1✔
307
                                .requireCompliance(credential.isRequireCompliance())
1✔
308
                                .jwtInclusion(map(credential.getJwtInclusion()))
1✔
309
                                .holderVerification(new HolderVerificationVO()
1✔
310
                                                .enabled(credential.isVerifyHolder())
1✔
311
                                                .claim(credential.getHolderClaim()));
1✔
312
        }
313

314
        /**
315
         * Map a list of TrustedParticipantsListVO-entries, to a list of {@link EndpointEntry} with
316
         * type {{@link EndpointType#TRUSTED_PARTICIPANTS}
317
         */
318
        default List<EndpointEntry> participantsToEntries(List<TrustedParticipantsListEndpointVO> endpoints) {
319
                if (endpoints == null) {
×
320
                        return null;
×
321
                }
322
                return endpoints.stream()
×
323
                                .map(endpoint -> {
×
324
                                        EndpointEntry entry = new EndpointEntry();
×
325
                                        entry.setEndpoint(endpoint.getUrl());
×
326
                                        entry.setListType(map(endpoint.getType()));
×
327
                                        entry.setType(EndpointType.TRUSTED_PARTICIPANTS);
×
328
                                        return entry;
×
329
                                })
330
                                .toList();
×
331
        }
332

333
        default EndpointEntry participantToEntry(TrustedParticipantsListEndpointVO trustedParticipantsListVO) {
334
                if (trustedParticipantsListVO == null) {
1✔
335
                        return null;
×
336
                }
337
                EndpointEntry entry = new EndpointEntry();
1✔
338
                entry.setEndpoint(trustedParticipantsListVO.getUrl());
1✔
339
                entry.setListType(map(trustedParticipantsListVO.getType()));
1✔
340
                entry.setType(EndpointType.TRUSTED_PARTICIPANTS);
1✔
341
                return entry;
1✔
342
        }
343

344
        /**
345
         * Map a list of string-entries, encoding TrustedIssuers endpoints to a list of {@link EndpointEntry} with
346
         * type {{@link EndpointType#TRUSTED_ISSUERS}
347
         */
348
        default List<EndpointEntry> issuersToEntries(List<String> endpoints) {
349
                if (endpoints == null) {
1✔
350
                        return null;
×
351
                }
352
                return endpoints.stream()
1✔
353
                                .map(endpoint -> {
1✔
354
                                        EndpointEntry entry = new EndpointEntry();
1✔
355
                                        entry.setEndpoint(endpoint);
1✔
356
                                        entry.setType(EndpointType.TRUSTED_ISSUERS);
1✔
357
                                        return entry;
1✔
358
                                })
359
                                .toList();
1✔
360
        }
361

362
        /**
363
         * Return issuer endpoints from the {@link EndpointEntry} list to a list of strings
364
         */
365
        default List<String> entriesToIssuers(List<EndpointEntry> endpoints) {
366
                if (endpoints == null) {
1✔
367
                        return List.of();
1✔
368
                }
369
                return endpoints.stream()
1✔
370
                                .filter(entry -> entry.getType().equals(EndpointType.TRUSTED_ISSUERS))
1✔
371
                                .map(EndpointEntry::getEndpoint)
1✔
372
                                .toList();
1✔
373
        }
374

375
        /**
376
         * Return participant endpoints from the {@link EndpointEntry} list to a list of strings
377
         */
378
        default List<TrustedParticipantsListEndpointVO> entriesToParticipants(List<EndpointEntry> endpoints) {
379
                if (endpoints == null) {
1✔
380
                        return List.of();
1✔
381
                }
382
                return endpoints.stream()
1✔
383
                                .filter(entry -> entry.getType().equals(EndpointType.TRUSTED_PARTICIPANTS))
1✔
384
                                .map(entry -> new TrustedParticipantsListEndpointVO()
1✔
385
                                                .type(map(entry.getListType()))
1✔
386
                                                .url(entry.getEndpoint()))
1✔
387
                                .toList();
1✔
388
        }
389

390
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc