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

FIWARE / credentials-config-service / #59

03 Mar 2026 11:57AM UTC coverage: 83.429% (+0.05%) from 83.382%
#59

Pull #27

wistefan
set flatclaims
Pull Request #27: set flatclaims

186 of 212 new or added lines in 1 file covered. (87.74%)

579 of 694 relevant lines covered (83.43%)

0.83 hits per line

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

87.74
/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✔
NEW
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.setService(service);
1✔
39
                            scopeEntry.setCredentials(Optional.ofNullable(e.getValue().getCredentials()).
1✔
40
                                    orElse(List.of()).stream().map(this::map).toList());
1✔
41
                            scopeEntry.setPresentationDefinition(this.map(e.getValue().getPresentationDefinition()));
1✔
42
                            scopeEntry.setDcqlQuery(this.map(e.getValue().getDcql()));
1✔
43
                            scopeEntry.setFlatClaims(e.getValue().getFlatClaims());
1✔
44
                            return scopeEntry;
1✔
45
                        })
46
                        .toList());
1✔
47
        return service;
1✔
48
    }
49

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

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

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

74
        return presentationDefinition;
1✔
75
    }
76

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

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

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

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

109
        Map<String, Object> formatsMap = new HashMap<>();
1✔
110

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

119
        return formatsMap;
1✔
120
    }
121

122
    AuthorizationType map(ServiceVO.AuthorizationType authorizationType);
123

124
    ServiceVO.AuthorizationType map(AuthorizationType authorizationType);
125

126
    InputDescriptorVO mapInputDescriptor(InputDescriptor inputDescriptor);
127

128
    InputDescriptor mapInputDescriptorVO(InputDescriptorVO inputDescriptor);
129

130
    PresentationDefinitionVO map(PresentationDefinition presentationDefinition);
131

132
    TrustedParticipantsListEndpointVO.Type map(ListType type);
133

134
    ListType map(TrustedParticipantsListEndpointVO.Type type);
135

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

153
    DCQLVO map(DcqlQuery dcqlQuery);
154

155
    DcqlQuery map(DCQLVO dcqlvo);
156

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

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

193
    TrustedAuthorityQueryVO map(TrustedAuthorityQuery trustedAuthorityQuery);
194

195
    TrustedAuthorityQuery map(TrustedAuthorityQueryVO trustedAuthorityQueryVO);
196

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

201
    default String map(TrustedAuthorityType type) {
202
        return type.getValue();
1✔
203
    }
204

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

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

239
    ClaimsQuery map(ClaimsQueryVO claimsQueryVO);
240

241
    ClaimsQueryVO map(ClaimsQuery claimsQuery);
242

243
    CredentialQueryVO.Format map(CredentialFormat credentialFormat);
244

245
    CredentialFormat map(CredentialQueryVO.Format credentialFormat);
246

247
    CredentialSetQueryVO map(CredentialSetQuery credentialSetQuery);
248

249
    CredentialSetQuery map(CredentialSetQueryVO credentialSetQueryVO);
250

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

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

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

277
        credential.setTrustedLists(trustedList);
1✔
278

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

291
    JwtInclusion map(JwtInclusionVO jwtInclusionVO);
292

293
    JwtInclusionVO map(JwtInclusion jwtInclusion);
294

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

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

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

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

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

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

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

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

© 2026 Coveralls, Inc