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

FIWARE / credentials-config-service / #8

16 Nov 2023 09:02AM UTC coverage: 88.36% (+1.8%) from 86.592%
#8

push

web-flow
Update API for OIDC scopes (#3)

* update api

* CHanging data model. Increasing version of openapi code generator.

* Additional repo classes.

* Adapt API controller and change data model.

* Add query param for oidcScope

* Adapt API tests

* Adapt repo and mapper

* Fix tests with empty default OIDC scope

* Fixed typo

* Fixed test

* Fixed tests

* Updated codegen version

* Add Tests for ServiceMapper

* workaround

* Workaroud for faulty openapi codegen

* bug fixing and api update

* pr remarks

---------

Co-authored-by: Tim Smyth <tim.smyth@fiware.org>
Co-authored-by: Beknazar Esenbek <beknazar.esenbek@fiware.org>

119 of 128 new or added lines in 3 files covered. (92.97%)

2 existing lines in 1 file now uncovered.

167 of 189 relevant lines covered (88.36%)

0.88 hits per line

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

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

3
import org.fiware.iam.ccs.model.*;
4
import org.fiware.iam.repository.Credential;
5
import org.fiware.iam.repository.EndpointEntry;
6
import org.fiware.iam.repository.EndpointType;
7
import org.fiware.iam.repository.Service;
8
import org.mapstruct.Mapper;
9

10
import java.util.*;
11
import java.util.stream.Collectors;
12

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

19
    Service map(ServiceVO serviceVO);
20

21

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

30
    default Map<String,ServiceScopesEntryVO> mapCredentials(Map<String,Collection<Credential>> value){
31
        Map<String,ServiceScopesEntryVO> answer = new HashMap<>();
1✔
32
        Optional.ofNullable(value)
1✔
33
                .orElseGet(Map::of)
1✔
34
                .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✔
NEW
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) {
NEW
58
        if (credentials == null) {
×
NEW
59
            return null;
×
60
        }
NEW
61
        return credentials.stream().map(this::map).toList();
×
62
    }
63

64
    default CredentialVO map(Credential credential) {
65
        if (credential == null) {
1✔
NEW
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✔
NEW
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✔
NEW
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