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

FIWARE / credentials-config-service / #18

07 Mar 2025 01:41PM UTC coverage: 81.223% (-5.6%) from 86.813%
#18

push

web-flow
update the api (#8)

* update the api

* backward compatible api

* extend doc  and testing

* review fixes

* fix naming

27 of 33 new or added lines in 2 files covered. (81.82%)

15 existing lines in 2 files now uncovered.

186 of 229 relevant lines covered (81.22%)

0.81 hits per line

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

80.95
/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
                return credential;
1✔
83
        }
84

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

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

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

121
        default EndpointEntry participantToEntry(TrustedParticipantsListEndpointVO trustedParticipantsListVO) {
122
                return new EndpointEntry()
1✔
123
                                .setEndpoint(trustedParticipantsListVO.getUrl())
1✔
124
                                .setListType(map(trustedParticipantsListVO.getType()))
1✔
125
                                .setType(EndpointType.TRUSTED_PARTICIPANTS);
1✔
126
        }
127

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

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

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

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