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

FIWARE / credentials-config-service / #34

07 May 2025 05:58AM UTC coverage: 81.385% (+0.2%) from 81.223%
#34

Pull #10

wistefan
temp support for tech-x
Pull Request #10: temp support for tech-x

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

9 existing lines in 2 files now uncovered.

188 of 231 relevant lines covered (81.39%)

0.81 hits per line

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

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

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

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

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

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

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

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

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

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