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

FIWARE / credentials-config-service / #41

06 Jun 2025 09:53AM UTC coverage: 84.233% (+0.03%) from 84.199%
#41

Pull #12

wistefan
fix npe
Pull Request #12: Jwt mapping

29 of 46 new or added lines in 4 files covered. (63.04%)

12 existing lines in 2 files now uncovered.

390 of 463 relevant lines covered (84.23%)

0.84 hits per line

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

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

3
import com.fasterxml.jackson.databind.ObjectMapper;
4
import org.fiware.iam.ccs.model.*;
5
import org.fiware.iam.repository.*;
6
import org.mapstruct.Mapper;
7

8
import java.util.*;
9
import java.util.stream.Collectors;
10

11
/**
12
 * Responsible for mapping entities from the Service api domain to the internal model.
13
 */
14
@Mapper(componentModel = "jsr330")
15
public interface ServiceMapper {
16

17
        static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
1✔
18

19
        default Service map(ServiceVO serviceVO) {
20
                if (serviceVO == null) {
1✔
21
                        return null;
×
22
                }
23
                Service service = new Service();
1✔
24
                service.setId(serviceVO.getId());
1✔
25
                service.setDefaultOidcScope(serviceVO.getDefaultOidcScope());
1✔
26
                service.setOidcScopes(
1✔
27
                                serviceVO.getOidcScopes()
1✔
28
                                                .entrySet()
1✔
29
                                                .stream()
1✔
30
                                                .map(e -> {
1✔
31
                                                        ScopeEntry scopeEntry = new ScopeEntry();
1✔
32
                                                        scopeEntry.setScopeKey(e.getKey());
1✔
33
                                                        scopeEntry.setCredentials(e.getValue().getCredentials().stream().map(this::map).toList());
1✔
34
                                                        scopeEntry.setPresentationDefinition(this.map(e.getValue().getPresentationDefinition()));
1✔
35
                                                        return scopeEntry;
1✔
36
                                                })
37
                                                .toList());
1✔
38
                return service;
1✔
39
        }
40

41
        default ServiceVO map(Service service) {
42
                if (service == null) {
1✔
43
                        return null;
×
44
                }
45
                return new ServiceVO().id(service.getId())
1✔
46
                                .defaultOidcScope(service.getDefaultOidcScope())
1✔
47
                                .oidcScopes(this.toOidcScopes(service.getOidcScopes()));
1✔
48
        }
49

50
        default PresentationDefinition map(PresentationDefinitionVO presentationDefinitionVO) {
51
                if (presentationDefinitionVO == null) {
1✔
52
                        return null;
×
53
                }
54

55
                PresentationDefinition presentationDefinition = new PresentationDefinition();
1✔
56
                presentationDefinition.setId(presentationDefinitionVO.getId());
1✔
57
                presentationDefinition.setName(presentationDefinitionVO.getName());
1✔
58
                presentationDefinition.setPurpose(presentationDefinitionVO.getPurpose());
1✔
59
                presentationDefinition.setInputDescriptors(this.mapInputDescriptors(presentationDefinitionVO
1✔
60
                                .getInputDescriptors()));
1✔
61
                presentationDefinition.setFormat(this.mapFormatVO(presentationDefinitionVO
1✔
62
                                .getFormat()));
1✔
63

64
                return presentationDefinition;
1✔
65
        }
66

67
        default Collection<InputDescriptor> mapInputDescriptors(Collection<InputDescriptorVO> inputDescriptorVOS) {
68
                if (inputDescriptorVOS == null) {
1✔
69
                        return null;
×
70
                }
71
                return inputDescriptorVOS
1✔
72
                                .stream()
1✔
73
                                .map(this::mapInputDescriptorVO).toList();
1✔
74
        }
75

76
        default Collection<Format> mapFormatVO(FormatVO formatVO) {
77
                if (formatVO == null || formatVO.getAdditionalProperties() == null) {
1✔
78
                        return null;
1✔
79
                }
80

81
                return formatVO.getAdditionalProperties()
1✔
82
                                .entrySet()
1✔
83
                                .stream()
1✔
84
                                .map(e -> {
1✔
85
                                        FormatObject formatObject = OBJECT_MAPPER.convertValue(e.getValue(), FormatObject.class);
1✔
86
                                        Format format = new Format();
1✔
87
                                        format.setFormatKey(e.getKey());
1✔
88
                                        format.setAlg(formatObject.getAlg());
1✔
89
                                        format.setProofType(formatObject.getProofType());
1✔
90
                                        return format;
1✔
91
                                }).toList();
1✔
92
        }
93

94
        default FormatVO mapFormats(Collection<Format> formats) {
95
                if (formats == null) {
1✔
96
                        return null;
1✔
97
                }
98

99
                FormatVO formatVO = new FormatVO();
1✔
100
                formats
1✔
101
                                .forEach(f -> {
1✔
102
                                        FormatObject formatObject = new FormatObject();
1✔
103
                                        formatObject.setAlg(f.getAlg());
1✔
104
                                        formatObject.setProofType(f.getProofType());
1✔
105
                                        formatVO.setAdditionalProperties(f.getFormatKey(), formatObject);
1✔
106
                                });
1✔
107
                return formatVO;
1✔
108
        }
109

110
        InputDescriptorVO mapInputDescriptor(InputDescriptor inputDescriptor);
111

112
        InputDescriptor mapInputDescriptorVO(InputDescriptorVO inputDescriptor);
113

114
        PresentationDefinitionVO map(PresentationDefinition presentationDefinition);
115

116
        TrustedParticipantsListEndpointVO.Type map(ListType type);
117

118
        ListType map(TrustedParticipantsListEndpointVO.Type type);
119

120
        default Map<String, ServiceScopesEntryVO> toOidcScopes(Collection<ScopeEntry> scopeEntries) {
121
                if (scopeEntries == null) {
1✔
122
                        return null;
×
123
                }
124
                Map<String, ServiceScopesEntryVO> scopes = new LinkedHashMap<>();
1✔
125
                scopeEntries
1✔
126
                                .forEach(entry -> {
1✔
127
                                        ServiceScopesEntryVO scopesEntryVO = new ServiceScopesEntryVO();
1✔
128
                                        scopesEntryVO.setPresentationDefinition(this.map(entry.getPresentationDefinition()));
1✔
129
                                        scopesEntryVO.setCredentials(this.map(entry.getCredentials()));
1✔
130
                                        scopes.put(entry.getScopeKey(), scopesEntryVO);
1✔
131
                                });
1✔
132
                return scopes;
1✔
133
        }
134

135
        default EndpointEntry stringToEndpointEntry(String url) {
136
                EndpointEntry entry = new EndpointEntry();
1✔
137
                entry.setType(EndpointType.TRUSTED_PARTICIPANTS);
1✔
138
                entry.setListType(ListType.EBSI);
1✔
139
                entry.setEndpoint(url);
1✔
140
                return entry;
1✔
141
        }
142

143
        default Credential map(CredentialVO credentialVO) {
144
                if (credentialVO == null) {
1✔
145
                        return null;
×
146
                }
147
                Credential credential = new Credential();
1✔
148
                credential.setCredentialType(credentialVO.getType());
1✔
149
                List<EndpointEntry> trustedList = new ArrayList<>();
1✔
150
                Optional.ofNullable(issuersToEntries(credentialVO.getTrustedIssuersLists())).ifPresent(trustedList::addAll);
1✔
151

152
                credentialVO.getTrustedParticipantsLists()
1✔
153
                                .forEach(tpl -> {
1✔
154
                                        if (tpl instanceof String tplS) {
1✔
155
                                                trustedList.add(stringToEndpointEntry(tplS));
1✔
156
                                        } else {
157
                                                trustedList.add(participantToEntry(OBJECT_MAPPER.convertValue(tpl, TrustedParticipantsListEndpointVO.class)));
1✔
158
                                        }
159
                                });
1✔
160

161
                credential.setTrustedLists(trustedList);
1✔
162

163
                if (credentialVO.getHolderVerification() != null) {
1✔
164
                        credential.setHolderClaim(credentialVO.getHolderVerification().getClaim());
1✔
165
                        credential.setVerifyHolder(credentialVO.getHolderVerification().getEnabled());
1✔
166
                } else {
167
                        credential.setVerifyHolder(false);
×
168
                        credential.setHolderClaim(null);
×
169
                }
170
                credential.setRequireCompliance(credentialVO.getRequireCompliance());
1✔
171
                credential.setJwtInclusion(map(credentialVO.getJwtInclusion()));
1✔
172
                return credential;
1✔
173
        }
174

175
        JwtInclusion map(JwtInclusionVO jwtInclusionVO);
176
        JwtInclusionVO map(JwtInclusion jwtInclusion);
177

178
        default List<CredentialVO> map(Collection<Credential> credentials) {
179
                if (credentials == null) {
1✔
UNCOV
180
                        return null;
×
181
                }
182
                return credentials.stream().map(this::map).toList();
1✔
183
        }
184

185
        default CredentialVO map(Credential credential) {
186
                if (credential == null) {
1✔
UNCOV
187
                        return null;
×
188
                }
189
                return new CredentialVO()
1✔
190
                                .type(credential.getCredentialType())
1✔
191
                                .trustedIssuersLists(entriesToIssuers(credential.getTrustedLists()))
1✔
192
                                .trustedParticipantsLists(entriesToParticipants(credential.getTrustedLists()).stream().map(Object.class::cast).toList())
1✔
193
                                .requireCompliance(credential.isRequireCompliance())
1✔
194
                                .jwtInclusion(map(credential.getJwtInclusion()))
1✔
195
                                .holderVerification(new HolderVerificationVO()
1✔
196
                                                .enabled(credential.isVerifyHolder())
1✔
197
                                                .claim(credential.getHolderClaim()));
1✔
198
        }
199

200
        /**
201
         * Map a list of TrustedParticipantsListVO-entries, to a list of {@link EndpointEntry} with
202
         * type {{@link EndpointType#TRUSTED_PARTICIPANTS}
203
         */
204
        default List<EndpointEntry> participantsToEntries(List<TrustedParticipantsListEndpointVO> endpoints) {
UNCOV
205
                if (endpoints == null) {
×
UNCOV
206
                        return null;
×
207
                }
UNCOV
208
                return endpoints.stream()
×
UNCOV
209
                                .map(endpoint -> {
×
UNCOV
210
                                        EndpointEntry entry = new EndpointEntry();
×
UNCOV
211
                                        entry.setEndpoint(endpoint.getUrl());
×
212
                                        entry.setListType(map(endpoint.getType()));
×
213
                                        entry.setType(EndpointType.TRUSTED_PARTICIPANTS);
×
UNCOV
214
                                        return entry;
×
215
                                })
216
                                .toList();
×
217
        }
218

219
        default EndpointEntry participantToEntry(TrustedParticipantsListEndpointVO trustedParticipantsListVO) {
220
                if (trustedParticipantsListVO == null) {
1✔
221
                        return null;
×
222
                }
223
                EndpointEntry entry = new EndpointEntry();
1✔
224
                entry.setEndpoint(trustedParticipantsListVO.getUrl());
1✔
225
                entry.setListType(map(trustedParticipantsListVO.getType()));
1✔
226
                entry.setType(EndpointType.TRUSTED_PARTICIPANTS);
1✔
227
                return entry;
1✔
228
        }
229

230
        /**
231
         * Map a list of string-entries, encoding TrustedIssuers endpoints to a list of {@link EndpointEntry} with
232
         * type {{@link EndpointType#TRUSTED_ISSUERS}
233
         */
234
        default List<EndpointEntry> issuersToEntries(List<String> endpoints) {
235
                if (endpoints == null) {
1✔
UNCOV
236
                        return null;
×
237
                }
238
                return endpoints.stream()
1✔
239
                                .map(endpoint -> {
1✔
240
                                        EndpointEntry entry = new EndpointEntry();
1✔
241
                                        entry.setEndpoint(endpoint);
1✔
242
                                        entry.setType(EndpointType.TRUSTED_ISSUERS);
1✔
243
                                        return entry;
1✔
244
                                })
245
                                .toList();
1✔
246
        }
247

248
        /**
249
         * Return issuer endpoints from the {@link EndpointEntry} list to a list of strings
250
         */
251
        default List<String> entriesToIssuers(List<EndpointEntry> endpoints) {
252
                if (endpoints == null) {
1✔
253
                        return List.of();
1✔
254
                }
255
                return endpoints.stream()
1✔
256
                                .filter(entry -> entry.getType().equals(EndpointType.TRUSTED_ISSUERS))
1✔
257
                                .map(EndpointEntry::getEndpoint)
1✔
258
                                .toList();
1✔
259
        }
260

261
        /**
262
         * Return participant endpoints from the {@link EndpointEntry} list to a list of strings
263
         */
264
        default List<TrustedParticipantsListEndpointVO> entriesToParticipants(List<EndpointEntry> endpoints) {
265
                if (endpoints == null) {
1✔
266
                        return List.of();
1✔
267
                }
268
                return endpoints.stream()
1✔
269
                                .filter(entry -> entry.getType().equals(EndpointType.TRUSTED_PARTICIPANTS))
1✔
270
                                .map(entry -> new TrustedParticipantsListEndpointVO()
1✔
271
                                                .type(map(entry.getListType()))
1✔
272
                                                .url(entry.getEndpoint()))
1✔
273
                                .toList();
1✔
274
        }
275

276
}
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