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

FIWARE / credentials-config-service / #27

02 May 2025 10:41AM UTC coverage: 86.4% (+5.2%) from 81.223%
#27

Pull #9

wistefan
Extend for presetnation definition
Pull Request #9: add presentation definition

152 of 166 new or added lines in 8 files covered. (91.57%)

14 existing lines in 3 files now uncovered.

324 of 375 relevant lines covered (86.4%)

0.86 hits per line

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

85.33
/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✔
NEW
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✔
NEW
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✔
NEW
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✔
NEW
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✔
NEW
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
                return credential;
1✔
171
        }
172

173
        default List<CredentialVO> map(Collection<Credential> credentials) {
174
                if (credentials == null) {
1✔
175
                        return null;
×
176
                }
177
                return credentials.stream().map(this::map).toList();
1✔
178
        }
179

180
        default CredentialVO map(Credential credential) {
181
                if (credential == null) {
1✔
182
                        return null;
×
183
                }
184
                return new CredentialVO()
1✔
185
                                .type(credential.getCredentialType())
1✔
186
                                .trustedIssuersLists(entriesToIssuers(credential.getTrustedLists()))
1✔
187
                                .trustedParticipantsLists(entriesToParticipants(credential.getTrustedLists()).stream().map(Object.class::cast).toList())
1✔
188
                                .holderVerification(new HolderVerificationVO()
1✔
189
                                                .enabled(credential.isVerifyHolder())
1✔
190
                                                .claim(credential.getHolderClaim()));
1✔
191
        }
192

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

212
        default EndpointEntry participantToEntry(TrustedParticipantsListEndpointVO trustedParticipantsListVO) {
213
                if (trustedParticipantsListVO == null) {
1✔
NEW
214
                        return null;
×
215
                }
216
                EndpointEntry entry = new EndpointEntry();
1✔
217
                entry.setEndpoint(trustedParticipantsListVO.getUrl());
1✔
218
                entry.setListType(map(trustedParticipantsListVO.getType()));
1✔
219
                entry.setType(EndpointType.TRUSTED_PARTICIPANTS);
1✔
220
                return entry;
1✔
221
        }
222

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

241
        /**
242
         * Return issuer endpoints from the {@link EndpointEntry} list to a list of strings
243
         */
244
        default List<String> entriesToIssuers(List<EndpointEntry> endpoints) {
245
                if (endpoints == null) {
1✔
246
                        return List.of();
1✔
247
                }
248
                return endpoints.stream()
1✔
249
                                .filter(entry -> entry.getType().equals(EndpointType.TRUSTED_ISSUERS))
1✔
250
                                .map(EndpointEntry::getEndpoint)
1✔
251
                                .toList();
1✔
252
        }
253

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

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

© 2025 Coveralls, Inc