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

FIWARE / credentials-config-service / #35

07 May 2025 10:37AM UTC coverage: 81.545% (+0.3%) from 81.223%
#35

Pull #10

wistefan
make jwt inclusion optional
Pull Request #10: temp support for tech-x

2 of 2 new or added lines in 1 file covered. (100.0%)

10 existing lines in 2 files now uncovered.

190 of 233 relevant lines covered (81.55%)

0.82 hits per line

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

81.82
/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
        Service map(ServiceVO serviceVO);
20

21
        TrustedParticipantsListEndpointVO.Type map(ListType type);
22

23
        ListType map(TrustedParticipantsListEndpointVO.Type type);
24

25
        default Map<String, Collection<Credential>> map(Map<String, ServiceScopesEntryVO> value) {
26
                return Optional.ofNullable(value)
1✔
27
                                .orElseGet(Map::of)
1✔
28
                                .entrySet()
1✔
29
                                .stream()
1✔
30
                                .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().stream().map(this::map).toList()));
1✔
31
        }
32

33
        default Map<String, ServiceScopesEntryVO> mapCredentials(Map<String, Collection<Credential>> value) {
34
                Map<String, ServiceScopesEntryVO> answer = new HashMap<>();
1✔
35
                Optional.ofNullable(value)
1✔
36
                                .orElseGet(Map::of)
1✔
37
                                .entrySet().forEach(entry -> {
1✔
38
                                        ServiceScopesEntryVO credentialVOS = new ServiceScopesEntryVO();
1✔
39
                                        entry.getValue().stream().map(this::map).forEach(credentialVOS::add);
1✔
40
                                        answer.put(entry.getKey(), credentialVOS);
1✔
41
                                });
1✔
42
                return answer;
1✔
43
        }
44

45
        ServiceVO map(Service service);
46

47
        default EndpointEntry stringToEndpointEntry(String url) {
48
                EndpointEntry entry = new EndpointEntry();
1✔
49
                entry.setType(EndpointType.TRUSTED_PARTICIPANTS);
1✔
50
                entry.setListType(ListType.EBSI);
1✔
51
                entry.setEndpoint(url);
1✔
52
                return entry;
1✔
53
        }
54

55
        default Credential map(CredentialVO credentialVO) {
56
                if (credentialVO == null) {
1✔
57
                        return null;
×
58
                }
59
                Credential credential = new Credential()
1✔
60
                                .setCredentialType(credentialVO.getType());
1✔
61
                List<EndpointEntry> trustedList = new ArrayList<>();
1✔
62
                Optional.ofNullable(issuersToEntries(credentialVO.getTrustedIssuersLists())).ifPresent(trustedList::addAll);
1✔
63

64
                credentialVO.getTrustedParticipantsLists()
1✔
65
                                .forEach(tpl -> {
1✔
66
                                        if (tpl instanceof String tplS) {
1✔
67
                                                trustedList.add(stringToEndpointEntry(tplS));
1✔
68
                                        } else {
69
                                                trustedList.add(participantToEntry(OBJECT_MAPPER.convertValue(tpl, TrustedParticipantsListEndpointVO.class)));
1✔
70
                                        }
71
                                });
1✔
72

73
                credential.setTrustedLists(trustedList);
1✔
74

75
                if (credentialVO.getHolderVerification() != null) {
1✔
76
                        credential.setHolderClaim(credentialVO.getHolderVerification().getClaim());
1✔
77
                        credential.setVerifyHolder(credentialVO.getHolderVerification().getEnabled());
1✔
78
                } else {
79
                        credential.setVerifyHolder(false);
×
80
                        credential.setHolderClaim(null);
×
81
                }
82
                credential.setRequireCompliance(credentialVO.getRequireCompliance());
1✔
83
                credential.setIncludeInJwt(credentialVO.getIncludeInJWT());
1✔
84
                return credential;
1✔
85
        }
86

87
        default Collection<CredentialVO> map(Collection<Credential> credentials) {
UNCOV
88
                if (credentials == null) {
×
89
                        return null;
×
90
                }
UNCOV
91
                return credentials.stream().map(this::map).toList();
×
92
        }
93

94
        default CredentialVO map(Credential credential) {
95
                if (credential == null) {
1✔
UNCOV
96
                        return null;
×
97
                }
98
                return new CredentialVO()
1✔
99
                                .type(credential.getCredentialType())
1✔
100
                                .trustedIssuersLists(entriesToIssuers(credential.getTrustedLists()))
1✔
101
                                .trustedParticipantsLists(entriesToParticipants(credential.getTrustedLists()).stream().map(Object.class::cast).toList())
1✔
102
                                .requireCompliance(credential.isRequireCompliance())
1✔
103
                                .includeInJWT(credential.isIncludeInJwt())
1✔
104
                                .holderVerification(new HolderVerificationVO()
1✔
105
                                                .enabled(credential.isVerifyHolder())
1✔
106
                                                .claim(credential.getHolderClaim()));
1✔
107
        }
108

109
        /**
110
         * Map a list of TrustedParticipantsListVO-entries, to a list of {@link EndpointEntry} with
111
         * type {{@link EndpointType#TRUSTED_PARTICIPANTS}
112
         */
113
        default List<EndpointEntry> participantsToEntries(List<TrustedParticipantsListEndpointVO> endpoints) {
114
                if (endpoints == null) {
×
115
                        return null;
×
116
                }
117
                return endpoints.stream()
×
118
                                .map(endpoint -> new EndpointEntry()
×
UNCOV
119
                                                .setEndpoint(endpoint.getUrl())
×
UNCOV
120
                                                .setListType(map(endpoint.getType()))
×
UNCOV
121
                                                .setType(EndpointType.TRUSTED_PARTICIPANTS))
×
UNCOV
122
                                .toList();
×
123
        }
124

125
        default EndpointEntry participantToEntry(TrustedParticipantsListEndpointVO trustedParticipantsListVO) {
126
                return new EndpointEntry()
1✔
127
                                .setEndpoint(trustedParticipantsListVO.getUrl())
1✔
128
                                .setListType(map(trustedParticipantsListVO.getType()))
1✔
129
                                .setType(EndpointType.TRUSTED_PARTICIPANTS);
1✔
130
        }
131

132
        /**
133
         * Map a list of string-entries, encoding TrustedIssuers endpoints to a list of {@link EndpointEntry} with
134
         * type {{@link EndpointType#TRUSTED_ISSUERS}
135
         */
136
        default List<EndpointEntry> issuersToEntries(List<String> endpoints) {
137
                if (endpoints == null) {
1✔
UNCOV
138
                        return null;
×
139
                }
140
                return endpoints.stream()
1✔
141
                                .map(endpoint -> new EndpointEntry()
1✔
142
                                                .setEndpoint(endpoint)
1✔
143
                                                .setType(EndpointType.TRUSTED_ISSUERS))
1✔
144
                                .toList();
1✔
145
        }
146

147
        /**
148
         * Return issuer endpoints from the {@link EndpointEntry} list to a list of strings
149
         */
150
        default List<String> entriesToIssuers(List<EndpointEntry> endpoints) {
151
                if (endpoints == null) {
1✔
152
                        return List.of();
1✔
153
                }
154
                return endpoints.stream()
1✔
155
                                .filter(entry -> entry.getType().equals(EndpointType.TRUSTED_ISSUERS))
1✔
156
                                .map(EndpointEntry::getEndpoint)
1✔
157
                                .toList();
1✔
158
        }
159

160
        /**
161
         * Return participant endpoints from the {@link EndpointEntry} list to a list of strings
162
         */
163
        default List<TrustedParticipantsListEndpointVO> entriesToParticipants(List<EndpointEntry> endpoints) {
164
                if (endpoints == null) {
1✔
165
                        return List.of();
1✔
166
                }
167
                return endpoints.stream()
1✔
168
                                .filter(entry -> entry.getType().equals(EndpointType.TRUSTED_PARTICIPANTS))
1✔
169
                                .map(entry -> new TrustedParticipantsListEndpointVO()
1✔
170
                                                .type(map(entry.getListType()))
1✔
171
                                                .url(entry.getEndpoint()))
1✔
172
                                .toList();
1✔
173
        }
174

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