Only import Stockholm University usernames
Improve user search experience since it searches by username, so we don't want a bunch of usernames from other places to interfere.
This commit is contained in:
parent
0e9c5c2b89
commit
deff20cfc7
daisy-integration/src
main/java/se/su/dsv/scipro/daisyExternal/impl
test/java/se/su/dsv/scipro/daisyExternal/impl
@ -26,6 +26,7 @@ public class ImporterTransactionsImpl implements ImporterTransactions {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ImporterTransactionsImpl.class);
|
||||
private static final int ML304C_ID = 41866;
|
||||
private static final String STOCKHOLM_UNIVERSITY = "SU.SE";
|
||||
|
||||
private final UserService userService;
|
||||
private final ResearchAreaService researchAreaService;
|
||||
@ -149,6 +150,11 @@ public class ImporterTransactionsImpl implements ImporterTransactions {
|
||||
private void importUsernames(Person person, User local) {
|
||||
Set<UserName> daisyUsernames = client.getUsernames(person.getId());
|
||||
for (UserName daisyUsername : daisyUsernames) {
|
||||
if (!daisyUsername.getRealm().equalsIgnoreCase(STOCKHOLM_UNIVERSITY)) {
|
||||
// We only care about SU usernames from now on.
|
||||
// Other usernames only obfuscate search results
|
||||
continue;
|
||||
}
|
||||
String completeUsername = daisyUsername.getUsername() + "@" + daisyUsername.getRealm();
|
||||
Username existingUsername = userNameService.findByUsername(completeUsername);
|
||||
if (existingUsername == null) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package se.su.dsv.scipro.io.impl;
|
||||
package se.su.dsv.scipro.daisyExternal.impl;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -7,13 +7,14 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import se.su.dsv.scipro.daisyExternal.http.DaisyAPI;
|
||||
import se.su.dsv.scipro.daisyExternal.impl.ImporterTransactionsImpl;
|
||||
import se.su.dsv.scipro.io.dto.Person;
|
||||
import se.su.dsv.scipro.io.dto.UserName;
|
||||
import se.su.dsv.scipro.match.ProgramService;
|
||||
import se.su.dsv.scipro.project.ProjectService;
|
||||
import se.su.dsv.scipro.system.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.AdditionalAnswers.returnsFirstArg;
|
||||
@ -64,6 +65,41 @@ public class ImporterTransactionsImplTest {
|
||||
assertUserPersonData(captor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void no_longer_imports_kth_usernames() {
|
||||
Person person = createPerson();
|
||||
UserName kth = new UserName();
|
||||
kth.setRealm("kth.se");
|
||||
kth.setUsername("kalle");
|
||||
|
||||
when(daisyAPI.getUsernames(person.getId()))
|
||||
.thenReturn(Set.of(kth));
|
||||
|
||||
importerTransactions.importPerson(person, new HashMap<>());
|
||||
|
||||
verify(userNameService, never()).save(any());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void imports_su_usernames() {
|
||||
Person person = createPerson();
|
||||
UserName su = new UserName();
|
||||
su.setRealm("su.se");
|
||||
su.setUsername("kalle");
|
||||
|
||||
when(daisyAPI.getUsernames(person.getId()))
|
||||
.thenReturn(Set.of(su));
|
||||
|
||||
importerTransactions.importPerson(person, new HashMap<>());
|
||||
|
||||
ArgumentCaptor<Username> captor = ArgumentCaptor.forClass(Username.class);
|
||||
verify(userNameService).save(captor.capture());
|
||||
|
||||
assertEquals(su.getUsername() + "@" + su.getRealm(), captor.getValue().getUsername());
|
||||
}
|
||||
|
||||
|
||||
private static void assertUserPersonData(User user) {
|
||||
assertEquals(SOME_FIRST_NAME, user.getFirstName());
|
||||
assertEquals(SOME_LAST_NAME, user.getLastName());
|
Loading…
x
Reference in New Issue
Block a user