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

FIWARE / credentials-config-service / #5

26 Oct 2023 08:26AM UTC coverage: 88.235% (+1.6%) from 86.592%
#5

Pull #3

pulledtim
Workaroud for faulty openapi codegen
Pull Request #3: Update API for OIDC scopes

126 of 126 new or added lines in 3 files covered. (100.0%)

165 of 187 relevant lines covered (88.24%)

0.88 hits per line

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

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

3
import org.fiware.iam.ccs.model.CredentialVO;
4
import org.fiware.iam.ccs.model.ServiceScopesEntryVO;
5
import org.fiware.iam.ccs.model.ServiceScopesVO;
6
import org.fiware.iam.ccs.model.ServiceVO;
7
import org.fiware.iam.repository.Credential;
8
import org.fiware.iam.repository.EndpointEntry;
9
import org.fiware.iam.repository.EndpointType;
10
import org.fiware.iam.repository.Service;
11
import org.mapstruct.Mapper;
12

13
import java.util.*;
14
import java.util.stream.Collectors;
15

16
/**
17
 * Responsible for mapping entities from the Service api domain to the internal model.
18
 */
19
@Mapper(componentModel = "jsr330")
20
public interface ServiceMapper {
21

22
    Service map(ServiceVO serviceVO);
23

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

32
    default ServiceScopesVO mapCredentials(Map<String, Collection<Credential>> scopes) {
33
        ServiceScopesVO answer = new ServiceScopesVO();
1✔
34
        scopes.entrySet().forEach(entry -> {
1✔
35
            ServiceScopesEntryVO credentialVOS = new ServiceScopesEntryVO();
1✔
36
            entry.getValue().stream().map(this::map).forEach(credentialVOS::add);
1✔
37
            answer.put(entry.getKey(), credentialVOS);
1✔
38
        });
1✔
39
        return answer;
1✔
40
    }
41

42
    ServiceVO map(Service service);
43

44
    default Credential map(CredentialVO credentialVO) {
45
        if (credentialVO == null) {
1✔
46
            return null;
×
47
        }
48
        Credential credential = new Credential()
1✔
49
                .setCredentialType(credentialVO.getType());
1✔
50
        List<EndpointEntry> trustedList = new ArrayList<>();
1✔
51
        Optional.ofNullable(issuersToEntries(credentialVO.getTrustedIssuersLists())).ifPresent(trustedList::addAll);
1✔
52
        Optional.ofNullable(participantsToEntries(credentialVO.getTrustedParticipantsLists())).ifPresent(trustedList::addAll);
1✔
53
        credential.setTrustedLists(trustedList);
1✔
54
        return credential;
1✔
55
    }
56

57
    default Collection<CredentialVO> map(Collection<Credential> credentials) {
58
        if (credentials == null) {
×
59
            return null;
×
60
        }
61
        return credentials.stream().map(this::map).toList();
×
62
    }
63

64
    default CredentialVO map(Credential credential) {
65
        if (credential == null) {
1✔
66
            return null;
×
67
        }
68
        return new CredentialVO()
1✔
69
                .type(credential.getCredentialType())
1✔
70
                .trustedIssuersLists(entriesToIssuers(credential.getTrustedLists()))
1✔
71
                .trustedParticipantsLists(entriesToParticipants(credential.getTrustedLists()));
1✔
72
    }
73

74
    /**
75
     * Map a list of string-entries, encoding TrustedParticipants endpoints to a list of {@link EndpointEntry} with
76
     * type {{@link EndpointType.TRUSTED_PARTICIPANTS}
77
     */
78
    default List<EndpointEntry> participantsToEntries(List<String> endpoints) {
79
        if (endpoints == null) {
1✔
80
            return null;
×
81
        }
82
        return endpoints.stream()
1✔
83
                .map(endpoint -> new EndpointEntry()
1✔
84
                        .setEndpoint(endpoint)
1✔
85
                        .setType(EndpointType.TRUSTED_PARTICIPANTS))
1✔
86
                .toList();
1✔
87
    }
88

89
    /**
90
     * Map a list of string-entries, encoding TrustedIssuers endpoints to a list of {@link EndpointEntry} with
91
     * type {{@link EndpointType.TRUSTED_ISSUERS}
92
     */
93
    default List<EndpointEntry> issuersToEntries(List<String> endpoints) {
94
        if (endpoints == null) {
1✔
95
            return null;
×
96
        }
97
        return endpoints.stream()
1✔
98
                .map(endpoint -> new EndpointEntry()
1✔
99
                        .setEndpoint(endpoint)
1✔
100
                        .setType(EndpointType.TRUSTED_ISSUERS))
1✔
101
                .toList();
1✔
102
    }
103

104
    /**
105
     * Return issuer endpoints from the {@link EndpointEntry} list to a list of strings
106
     */
107
    default List<String> entriesToIssuers(List<EndpointEntry> endpoints) {
108
        if (endpoints == null) {
1✔
109
            return List.of();
1✔
110
        }
111
        return endpoints.stream()
1✔
112
                .filter(entry -> entry.getType().equals(EndpointType.TRUSTED_ISSUERS))
1✔
113
                .map(EndpointEntry::getEndpoint)
1✔
114
                .toList();
1✔
115
    }
116

117
    /**
118
     * Return participant endpoints from the {@link EndpointEntry} list to a list of strings
119
     */
120
    default List<String> entriesToParticipants(List<EndpointEntry> endpoints) {
121
        if (endpoints == null) {
1✔
122
            return List.of();
1✔
123
        }
124
        return endpoints.stream()
1✔
125
                .filter(entry -> entry.getType().equals(EndpointType.TRUSTED_PARTICIPANTS))
1✔
126
                .map(EndpointEntry::getEndpoint)
1✔
127
                .toList();
1✔
128
    }
129

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