-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing some issue with getting information from the token
- Loading branch information
1 parent
4d5c4ab
commit 7ea4180
Showing
5 changed files
with
112 additions
and
0 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
Empty file.
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
17 changes: 17 additions & 0 deletions
17
...ssenger/src/main/java/tech/ebp/oqm/plugin/alertMessenger/repositories/UserRepository.java
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,17 @@ | ||
package tech.ebp.oqm.plugin.alertMessenger.repositories; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheRepository; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import tech.ebp.oqm.plugin.alertMessenger.model.UserInfo; | ||
|
||
@ApplicationScoped | ||
public class UserRepository implements PanacheRepository<UserInfo> { | ||
|
||
public UserInfo findByUserId(String userId) { | ||
return find("userId", userId).firstResult(); | ||
} | ||
|
||
public UserInfo findByEmail(String email) { | ||
return find("email", email).firstResult(); | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
...ins/alert-messenger/src/main/java/tech/ebp/oqm/plugin/alertMessenger/utils/UserUtils.java
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,88 @@ | ||
package tech.ebp.oqm.plugin.alertMessenger.utils; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import lombok.extern.slf4j.Slf4j; | ||
import tech.ebp.oqm.plugin.alertMessenger.model.UserInfo; | ||
import tech.ebp.oqm.plugin.alertMessenger.repositories.UserRepository; | ||
|
||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
@ApplicationScoped | ||
@Slf4j | ||
public class UserUtils { | ||
|
||
@Inject | ||
UserRepository userRepository; | ||
|
||
/** | ||
* Retrieve a UserInfo object from the database based on the user ID. | ||
* | ||
* @param userId the unique user ID | ||
* @return UserInfo object if found, Optional.empty otherwise | ||
*/ | ||
public Optional<UserInfo> getUserInfo(String userId) { | ||
return Optional.ofNullable(userRepository.findByUserId(userId)); | ||
} | ||
|
||
/** | ||
* Retrieve the user's unique ID. | ||
* | ||
* @param userId the unique user ID | ||
* @return the user ID, or null if the user is not found | ||
*/ | ||
public String getId(String userId) { | ||
return getUserInfo(userId) | ||
.map(UserInfo::getUserId) | ||
.orElse(null); | ||
} | ||
|
||
/** | ||
* Retrieve the user's name. | ||
* | ||
* @param userId the unique user ID | ||
* @return the user's name, or null if the user is not found | ||
*/ | ||
public String getName(String userId) { | ||
return getUserInfo(userId) | ||
.map(UserInfo::getName) | ||
.orElse(null); | ||
} | ||
|
||
/** | ||
* Retrieve the user's email. | ||
* | ||
* @param userId the unique user ID | ||
* @return the user's email, or null if the user is not found | ||
*/ | ||
public String getEmail(String userId) { | ||
return getUserInfo(userId) | ||
.map(UserInfo::getEmail) | ||
.orElse(null); | ||
} | ||
|
||
/** | ||
* Retrieve the user's username. | ||
* | ||
* @param userId the unique user ID | ||
* @return the user's username, or null if the user is not found | ||
*/ | ||
public String getUserName(String userId) { | ||
return getUserInfo(userId) | ||
.map(UserInfo::getUsername) | ||
.orElse(null); | ||
} | ||
|
||
/** | ||
* Retrieve the user's roles. | ||
* | ||
* @param userId the unique user ID | ||
* @return a set of roles, or null if the user is not found | ||
*/ | ||
public Set<String> getRoles(String userId) { | ||
return getUserInfo(userId) | ||
.map(UserInfo::getRoles) | ||
.orElse(null); | ||
} | ||
} |