-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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>
- Loading branch information
1 parent
de84244
commit f54385a
Showing
13 changed files
with
945 additions
and
572 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,130 @@ | ||
package org.fiware.iam; | ||
|
||
import org.fiware.iam.ccs.model.CredentialVO; | ||
import org.fiware.iam.ccs.model.ServiceVO; | ||
import org.fiware.iam.ccs.model.*; | ||
import org.fiware.iam.repository.Credential; | ||
import org.fiware.iam.repository.EndpointEntry; | ||
import org.fiware.iam.repository.EndpointType; | ||
import org.fiware.iam.repository.Service; | ||
import org.mapstruct.Mapper; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Responsible for mapping entities from the Service api domain to the internal model. | ||
*/ | ||
@Mapper(componentModel = "jsr330") | ||
public interface ServiceMapper { | ||
|
||
Service map(ServiceVO serviceVO); | ||
|
||
ServiceVO map(Service service); | ||
|
||
default Credential map(CredentialVO credentialVO) { | ||
if (credentialVO == null) { | ||
return null; | ||
} | ||
Credential credential = new Credential() | ||
.setCredentialType(credentialVO.getType()); | ||
List<EndpointEntry> trustedList = new ArrayList<>(); | ||
trustedList.addAll(issuersToEntries(credentialVO.getTrustedIssuersLists())); | ||
trustedList.addAll(participantsToEntries(credentialVO.getTrustedParticipantsLists())); | ||
credential.setTrustedLists(trustedList); | ||
return credential; | ||
} | ||
|
||
default CredentialVO map(Credential credential) { | ||
if (credential == null) { | ||
return null; | ||
} | ||
return new CredentialVO() | ||
.type(credential.getCredentialType()) | ||
.trustedIssuersLists(entriesToIssuers(credential.getTrustedLists())) | ||
.trustedParticipantsLists(entriesToParticipants(credential.getTrustedLists())); | ||
} | ||
|
||
/** | ||
* Map a list of string-entries, encoding TrustedParticipants endpoints to a list of {@link EndpointEntry} with | ||
* type {{@link EndpointType.TRUSTED_PARTICIPANTS} | ||
*/ | ||
default List<EndpointEntry> participantsToEntries(List<String> endpoints) { | ||
if (endpoints == null) { | ||
return null; | ||
} | ||
return endpoints.stream() | ||
.map(endpoint -> new EndpointEntry() | ||
.setEndpoint(endpoint) | ||
.setType(EndpointType.TRUSTED_PARTICIPANTS)) | ||
.toList(); | ||
} | ||
|
||
/** | ||
* Map a list of string-entries, encoding TrustedIssuers endpoints to a list of {@link EndpointEntry} with | ||
* type {{@link EndpointType.TRUSTED_ISSUERS} | ||
*/ | ||
default List<EndpointEntry> issuersToEntries(List<String> endpoints) { | ||
if (endpoints == null) { | ||
return null; | ||
} | ||
return endpoints.stream() | ||
.map(endpoint -> new EndpointEntry() | ||
.setEndpoint(endpoint) | ||
.setType(EndpointType.TRUSTED_ISSUERS)) | ||
.toList(); | ||
} | ||
|
||
/** | ||
* Return issuer endpoints from the {@link EndpointEntry} list to a list of strings | ||
*/ | ||
default List<String> entriesToIssuers(List<EndpointEntry> endpoints) { | ||
if (endpoints == null) { | ||
return null; | ||
} | ||
return endpoints.stream() | ||
.filter(entry -> entry.getType().equals(EndpointType.TRUSTED_ISSUERS)) | ||
.map(EndpointEntry::getEndpoint) | ||
.toList(); | ||
} | ||
|
||
/** | ||
* Return participant endpoints from the {@link EndpointEntry} list to a list of strings | ||
*/ | ||
default List<String> entriesToParticipants(List<EndpointEntry> endpoints) { | ||
if (endpoints == null) { | ||
return null; | ||
} | ||
return endpoints.stream() | ||
.filter(entry -> entry.getType().equals(EndpointType.TRUSTED_PARTICIPANTS)) | ||
.map(EndpointEntry::getEndpoint) | ||
.toList(); | ||
} | ||
|
||
} | ||
Service map(ServiceVO serviceVO); | ||
|
||
|
||
default Map<String,Collection<Credential>> map(Map<String,ServiceScopesEntryVO> value){ | ||
return Optional.ofNullable(value) | ||
.orElseGet(Map::of) | ||
.entrySet() | ||
.stream() | ||
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().stream().map(this::map).toList())); | ||
} | ||
|
||
default Map<String,ServiceScopesEntryVO> mapCredentials(Map<String,Collection<Credential>> value){ | ||
Map<String,ServiceScopesEntryVO> answer = new HashMap<>(); | ||
Optional.ofNullable(value) | ||
.orElseGet(Map::of) | ||
.entrySet().forEach(entry -> { | ||
ServiceScopesEntryVO credentialVOS = new ServiceScopesEntryVO(); | ||
entry.getValue().stream().map(this::map).forEach(credentialVOS::add); | ||
answer.put(entry.getKey(), credentialVOS); | ||
}); | ||
return answer; | ||
} | ||
|
||
ServiceVO map(Service service); | ||
|
||
default Credential map(CredentialVO credentialVO) { | ||
if (credentialVO == null) { | ||
return null; | ||
} | ||
Credential credential = new Credential() | ||
.setCredentialType(credentialVO.getType()); | ||
List<EndpointEntry> trustedList = new ArrayList<>(); | ||
Optional.ofNullable(issuersToEntries(credentialVO.getTrustedIssuersLists())).ifPresent(trustedList::addAll); | ||
Optional.ofNullable(participantsToEntries(credentialVO.getTrustedParticipantsLists())).ifPresent(trustedList::addAll); | ||
credential.setTrustedLists(trustedList); | ||
return credential; | ||
} | ||
|
||
default Collection<CredentialVO> map(Collection<Credential> credentials) { | ||
if (credentials == null) { | ||
return null; | ||
} | ||
return credentials.stream().map(this::map).toList(); | ||
} | ||
|
||
default CredentialVO map(Credential credential) { | ||
if (credential == null) { | ||
return null; | ||
} | ||
return new CredentialVO() | ||
.type(credential.getCredentialType()) | ||
.trustedIssuersLists(entriesToIssuers(credential.getTrustedLists())) | ||
.trustedParticipantsLists(entriesToParticipants(credential.getTrustedLists())); | ||
} | ||
|
||
/** | ||
* Map a list of string-entries, encoding TrustedParticipants endpoints to a list of {@link EndpointEntry} with | ||
* type {{@link EndpointType#TRUSTED_PARTICIPANTS} | ||
*/ | ||
default List<EndpointEntry> participantsToEntries(List<String> endpoints) { | ||
if (endpoints == null) { | ||
return null; | ||
} | ||
return endpoints.stream() | ||
.map(endpoint -> new EndpointEntry() | ||
.setEndpoint(endpoint) | ||
.setType(EndpointType.TRUSTED_PARTICIPANTS)) | ||
.toList(); | ||
} | ||
|
||
/** | ||
* Map a list of string-entries, encoding TrustedIssuers endpoints to a list of {@link EndpointEntry} with | ||
* type {{@link EndpointType#TRUSTED_ISSUERS} | ||
*/ | ||
default List<EndpointEntry> issuersToEntries(List<String> endpoints) { | ||
if (endpoints == null) { | ||
return null; | ||
} | ||
return endpoints.stream() | ||
.map(endpoint -> new EndpointEntry() | ||
.setEndpoint(endpoint) | ||
.setType(EndpointType.TRUSTED_ISSUERS)) | ||
.toList(); | ||
} | ||
|
||
/** | ||
* Return issuer endpoints from the {@link EndpointEntry} list to a list of strings | ||
*/ | ||
default List<String> entriesToIssuers(List<EndpointEntry> endpoints) { | ||
if (endpoints == null) { | ||
return List.of(); | ||
} | ||
return endpoints.stream() | ||
.filter(entry -> entry.getType().equals(EndpointType.TRUSTED_ISSUERS)) | ||
.map(EndpointEntry::getEndpoint) | ||
.toList(); | ||
} | ||
|
||
/** | ||
* Return participant endpoints from the {@link EndpointEntry} list to a list of strings | ||
*/ | ||
default List<String> entriesToParticipants(List<EndpointEntry> endpoints) { | ||
if (endpoints == null) { | ||
return List.of(); | ||
} | ||
return endpoints.stream() | ||
.filter(entry -> entry.getType().equals(EndpointType.TRUSTED_PARTICIPANTS)) | ||
.map(EndpointEntry::getEndpoint) | ||
.toList(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.