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

FIWARE / credentials-config-service / #3

29 Sep 2023 09:15AM UTC coverage: 39.614%. First build
#3

Pull #4

pulledtim
single test
Pull Request #4: suggestion

79 of 79 new or added lines in 4 files covered. (100.0%)

82 of 207 relevant lines covered (39.61%)

0.4 hits per line

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

51.47
/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.*;
8
import org.mapstruct.Mapper;
9

10
import java.util.ArrayList;
11
import java.util.Collection;
12
import java.util.List;
13
import java.util.Optional;
14

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

21
    default Service map(ServiceVO serviceVO) {
22
        return new Service()
1✔
23
                .setDefaultOidcScope(serviceVO.getDefaultOidcScope())
1✔
24
                .setId(serviceVO.getId())
1✔
25
                .setOidcScopes(map(serviceVO.getOidcScopes(), serviceVO.getId()));
1✔
26
    }
27

28
    ServiceVO map(Service service);
29

30
    default ServiceScope map(ServiceScopesEntryVO serviceScopesEntryVO, String scopeName, String serviceName) {
31
        return new ServiceScope()
1✔
32
                .setId("%s_%s".formatted(scopeName, serviceName))
1✔
33
                .setScopeName(scopeName)
1✔
34
                .setCredentials(serviceScopesEntryVO.stream().map(this::map).toList());
1✔
35
    }
36

37
    ServiceScopesEntryVO map(ServiceScope serviceScope);
38

39
    default Collection<ServiceScope> map(ServiceScopesVO value, String serviceName) {
40
        if (value.getAdditionalProperties() == null) {
1✔
41
            return List.of();
×
42
        }
43
        return value
1✔
44
                .getAdditionalProperties()
1✔
45
                .entrySet()
1✔
46
                .stream()
1✔
47
                .map(e -> map(e.getValue(), e.getKey(), serviceName))
1✔
48
                .toList();
1✔
49
    }
50

51
    default ServiceScopesVO mapEntries(Collection<ServiceScope> value) {
52
        ServiceScopesVO mappedScopes = new ServiceScopesVO();
×
53
        if (value != null) {
×
54
            value.forEach(e -> {
×
55
                        ServiceScopesEntryVO scopes = new ServiceScopesEntryVO();
×
56
                        scopes.addAll(map(e.getCredentials()));
×
57
                        mappedScopes.setAdditionalProperties(e.getScopeName(), scopes);
×
58
                    }
×
59
            );
60
        }
61
        return mappedScopes;
×
62
    }
63

64
    default Credential map(CredentialVO credentialVO) {
65
        if (credentialVO == null) {
1✔
66
            return null;
×
67
        }
68
        Credential credential = new Credential()
1✔
69
                .setCredentialType(credentialVO.getType());
1✔
70
        List<EndpointEntry> trustedList = new ArrayList<>();
1✔
71
        Optional.ofNullable(issuersToEntries(credentialVO.getTrustedIssuersLists())).ifPresent(trustedList::addAll);
1✔
72
        Optional.ofNullable(participantsToEntries(credentialVO.getTrustedParticipantsLists())).ifPresent(trustedList::addAll);
1✔
73
        credential.setTrustedLists(trustedList);
1✔
74
        return credential;
1✔
75
    }
76

77
    default Collection<CredentialVO> map(Collection<Credential> credentials) {
78
        if (credentials == null) {
×
79
            return null;
×
80
        }
81
        return credentials.stream().map(this::map).toList();
×
82
    }
83

84
    default CredentialVO map(Credential credential) {
85
        if (credential == null) {
×
86
            return null;
×
87
        }
88
        return new CredentialVO()
×
89
                .type(credential.getCredentialType())
×
90
                .trustedIssuersLists(entriesToIssuers(credential.getTrustedLists()))
×
91
                .trustedParticipantsLists(entriesToParticipants(credential.getTrustedLists()));
×
92
    }
93

94
    /**
95
     * Map a list of string-entries, encoding TrustedParticipants endpoints to a list of {@link EndpointEntry} with
96
     * type {{@link EndpointType.TRUSTED_PARTICIPANTS}
97
     */
98
    default List<EndpointEntry> participantsToEntries(List<String> endpoints) {
99
        if (endpoints == null) {
1✔
100
            return null;
1✔
101
        }
102
        return endpoints.stream()
1✔
103
                .map(endpoint -> new EndpointEntry()
1✔
104
                        .setEndpoint(endpoint)
×
105
                        .setType(EndpointType.TRUSTED_PARTICIPANTS))
×
106
                .toList();
1✔
107
    }
108

109
    /**
110
     * Map a list of string-entries, encoding TrustedIssuers endpoints to a list of {@link EndpointEntry} with
111
     * type {{@link EndpointType.TRUSTED_ISSUERS}
112
     */
113
    default List<EndpointEntry> issuersToEntries(List<String> endpoints) {
114
        if (endpoints == null) {
1✔
115
            return null;
1✔
116
        }
117
        return endpoints.stream()
1✔
118
                .map(endpoint -> new EndpointEntry()
1✔
119
                        .setEndpoint(endpoint)
1✔
120
                        .setType(EndpointType.TRUSTED_ISSUERS))
1✔
121
                .toList();
1✔
122
    }
123

124
    /**
125
     * Return issuer endpoints from the {@link EndpointEntry} list to a list of strings
126
     */
127
    default List<String> entriesToIssuers(List<EndpointEntry> endpoints) {
128
        if (endpoints == null) {
×
129
            return null;
×
130
        }
131
        return endpoints.stream()
×
132
                .filter(entry -> entry.getType().equals(EndpointType.TRUSTED_ISSUERS))
×
133
                .map(EndpointEntry::getEndpoint)
×
134
                .toList();
×
135
    }
136

137
    /**
138
     * Return participant endpoints from the {@link EndpointEntry} list to a list of strings
139
     */
140
    default List<String> entriesToParticipants(List<EndpointEntry> endpoints) {
141
        if (endpoints == null) {
×
142
            return null;
×
143
        }
144
        return endpoints.stream()
×
145
                .filter(entry -> entry.getType().equals(EndpointType.TRUSTED_PARTICIPANTS))
×
146
                .map(EndpointEntry::getEndpoint)
×
147
                .toList();
×
148
    }
149

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