Skip to content
Snippets Groups Projects
Commit 96edc27f authored by OZGCloud's avatar OZGCloud
Browse files

OZG-2653 Readme um properties erweitert. Fehler in findByEMail gefixed

parent b9469a7b
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,18 @@ This project uses Quarkus, the Supersonic Subatomic Java Framework. ...@@ -4,6 +4,18 @@ This project uses Quarkus, the Supersonic Subatomic Java Framework.
If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ . If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ .
## Configuring the application
This properties mist be configured to run the application
quarkus.mongodb.connection-string=<The connection string for the mongo db database>
quarkus.mongodb.database=<name of the mongo db database>
usermanager.keycloak.sync.cron=<default is "0 15 2 * * ?" >
usermanager.keycloak.api.user=< the name of the keycloak admin api user, default: goofyApiUser>
usermanager.keycloak.api.password=< the password of the keycloak admin api user>
usermanager.keycloak.api.realm=<The name of the realm>
usermanager.keycloak.api.organisations-einheit-id-key=< The key where the organisationsEinheitId of the group is saved, default is 'organisationseinheitId'>
## Running the application in dev mode ## Running the application in dev mode
You can run your application in dev mode that enables live coding using: You can run your application in dev mode that enables live coding using:
......
...@@ -4,21 +4,22 @@ import java.util.Optional; ...@@ -4,21 +4,22 @@ import java.util.Optional;
import javax.enterprise.context.ApplicationScoped; import javax.enterprise.context.ApplicationScoped;
import org.apache.commons.lang3.StringUtils;
import io.quarkus.mongodb.panache.PanacheMongoRepository; import io.quarkus.mongodb.panache.PanacheMongoRepository;
@ApplicationScoped @ApplicationScoped
public class UserRepository implements PanacheMongoRepository<User> { public class UserRepository implements PanacheMongoRepository<User> {
public Optional<User> findByExternalIdOrEmail(User user) {
return find("externalId = ?1 or email = ?2", user.getExternalId(), user.getEmail()).firstResultOptional();
}
public Optional<User> findByExternalId(String externalId) { public Optional<User> findByExternalId(String externalId) {
return find("externalId", externalId).firstResultOptional(); return find("externalId", externalId).firstResultOptional();
} }
public Optional<User> findByEmail(String email) { public Optional<User> findByEmail(String email) {
if (StringUtils.isNotEmpty(email)) {
return find("email", email).firstResultOptional(); return find("email", email).firstResultOptional();
} else {
return Optional.empty();
}
} }
public long updateUnsyncedUsers(long lastSyncTimestamp) { public long updateUnsyncedUsers(long lastSyncTimestamp) {
......
...@@ -11,5 +11,5 @@ usermanager: ...@@ -11,5 +11,5 @@ usermanager:
cron: "0 */10 * * * ?" cron: "0 */10 * * * ?"
api: api:
user: alice user: alice
password: alice password: S9UEMuLG9y9ev99
realm: dev realm: dev
...@@ -28,14 +28,6 @@ class UserRepositoryTest { ...@@ -28,14 +28,6 @@ class UserRepositoryTest {
user2.setExternalId(null); user2.setExternalId(null);
} }
@Test
void shouldFindByExternalIdOrEmail() {
var res = repository.findByExternalIdOrEmail(user1);
assertThat(res).isPresent().get();
assertThat(res.get().getExternalId()).isEqualTo(user1.getExternalId());
}
@Test @Test
void shouldFindByExternalId() { void shouldFindByExternalId() {
var res = repository.findByExternalId(user1.getExternalId()); var res = repository.findByExternalId(user1.getExternalId());
...@@ -53,10 +45,12 @@ class UserRepositoryTest { ...@@ -53,10 +45,12 @@ class UserRepositoryTest {
} }
@Test @Test
void shouldFindByEMail() { void shouldNotFindByEmptyEmail() {
var res = repository.findByExternalIdOrEmail(user2); var user = UserTestFactory.createBuilder().externalId("unknown").email(null).build();
repository.persist(user);
user.setExternalId(null);
var res = repository.findByEmail(user.getEmail());
assertThat(res).isPresent(); assertThat(res).isEmpty();
assertThat(res.get().getEmail()).isEqualTo(user2.getEmail());
} }
} }
...@@ -21,7 +21,7 @@ class KeycloakApiServiceTest { ...@@ -21,7 +21,7 @@ class KeycloakApiServiceTest {
KeycloakApiService service; KeycloakApiService service;
@Test @Test
@Disabled("Keycloak configuration need to be fixed") @Disabled("Keycloak configuration needs to be fixed")
void shouldFindUserByExternalId() { void shouldFindUserByExternalId() {
User user = service.findUserByExternalId("adfda431-2ee8-4b94-bab2-24225f658719"); User user = service.findUserByExternalId("adfda431-2ee8-4b94-bab2-24225f658719");
...@@ -29,7 +29,7 @@ class KeycloakApiServiceTest { ...@@ -29,7 +29,7 @@ class KeycloakApiServiceTest {
} }
@Test @Test
@Disabled("Keycloak configuration need to be fixed") @Disabled("Keycloak configuration needs to be fixed")
void shouldFindUserByEmail() { void shouldFindUserByEmail() {
Optional<User> user = service.findUserByEmail(UserTestFactory.EMAIL); Optional<User> user = service.findUserByEmail(UserTestFactory.EMAIL);
...@@ -37,7 +37,7 @@ class KeycloakApiServiceTest { ...@@ -37,7 +37,7 @@ class KeycloakApiServiceTest {
} }
@Test @Test
@Disabled("Keycloak configuration need to be fixed") @Disabled("Keycloak configuration needs to be fixed")
void shouldGetAllUsers() { void shouldGetAllUsers() {
var usersStream = service.getAllUsers(); var usersStream = service.getAllUsers();
......
...@@ -78,7 +78,7 @@ class SyncServiceTest { ...@@ -78,7 +78,7 @@ class SyncServiceTest {
service.sync(); service.sync();
verify(repository, never()).findByExternalIdOrEmail(any()); verify(repository, never()).findByExternalId(any());
} }
@Test @Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment