Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance/Code Readability #1199

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ target/
.project
.classpath
.settings/
.vscode/
pom.xml.versionsBackup
pom.xml.releaseBackup
pom.xml.tag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,10 @@ public ClientRepository(RealmRepository realmRepository) {
public Optional<ClientRepresentation> searchByClientId(String realmName, String clientId) {
List<ClientRepresentation> foundClients = getResource(realmName).findByClientId(Objects.requireNonNull(clientId));

Optional<ClientRepresentation> client;
if (foundClients.isEmpty()) {
client = Optional.empty();
} else {
client = Optional.of(foundClients.get(0));
}

return client;
return switch (foundClients) {
case List<ClientRepresentation> list when list.isEmpty() -> Optional.empty();
case List<ClientRepresentation> list -> Optional.of(list.get(0));
};
}

public Optional<ClientRepresentation> searchByName(String realmName, String name) {
Expand All @@ -87,21 +83,23 @@ public Optional<ClientRepresentation> searchByName(String realmName, String name
public ClientRepresentation getByClientId(String realmName, String clientId) {
Optional<ClientRepresentation> foundClients = searchByClientId(realmName, clientId);

if (foundClients.isEmpty()) {
throw new KeycloakRepositoryException("Cannot find client by clientId '%s'", clientId);
}

return foundClients.get();
return switch (foundClients) {
case Optional<ClientRepresentation> foundClient when foundClient.isEmpty() ->
throw new KeycloakRepositoryException("Cannot find client by clientId '%s'", clientId);
case Optional<ClientRepresentation> foundClient ->
foundClient.get();
};
}

public ClientRepresentation getByName(String realmName, String name) {
Optional<ClientRepresentation> foundClients = searchByName(realmName, name);

if (foundClients.isEmpty()) {
return switch (foundClients) {
case Optional<ClientRepresentation> foundClient when foundClient.isEmpty() ->
throw new KeycloakRepositoryException("Cannot find client by name '%s'", name);
}

return foundClients.get();
case Optional<ClientRepresentation> foundClient ->
foundClient.get();
};
}

public ResourceServerRepresentation getAuthorizationConfigById(String realmName, String id) {
Expand Down