-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(users): handle external change of user email address by storing p…
…reviously known email addresses and falling back to search by former addresses when necessary closes #242
- Loading branch information
Showing
12 changed files
with
195 additions
and
148 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 |
---|---|---|
|
@@ -11,13 +11,16 @@ | |
package org.eclipse.sw360.datahandler.db; | ||
|
||
import org.eclipse.sw360.components.summary.UserSummary; | ||
import org.eclipse.sw360.datahandler.common.CommonUtils; | ||
import org.eclipse.sw360.datahandler.couchdb.DatabaseConnector; | ||
import org.eclipse.sw360.datahandler.couchdb.SummaryAwareRepository; | ||
import org.eclipse.sw360.datahandler.thrift.users.User; | ||
import org.ektorp.support.View; | ||
import org.ektorp.support.Views; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* CRUD access for the User class | ||
|
@@ -26,7 +29,21 @@ | |
* @author [email protected] | ||
*/ | ||
|
||
@View(name = "all", map = "function(doc) { if (doc.type == 'user') emit(null, doc._id) }") | ||
@Views({ | ||
@View(name = "all", | ||
map = "function(doc) { if (doc.type == 'user') emit(null, doc._id) }"), | ||
@View(name = "byExternalId", | ||
map = "function(doc) { if (doc.type == 'user') emit(doc.externalid, doc._id) }"), | ||
@View(name = "byFormerEmails", | ||
map = "function(doc) {" + | ||
" if (doc.type == 'user' && doc.formerEmailAddresses && Array.isArray(doc.formerEmailAddresses)) {" + | ||
" var arr = doc.formerEmailAddresses;" + | ||
" for (var i = 0; i < arr.length; i++){" + | ||
" emit(arr[i], doc._id);" + | ||
" }" + | ||
" }" + | ||
"}") | ||
}) | ||
public class UserRepository extends SummaryAwareRepository<User> { | ||
public UserRepository(DatabaseConnector databaseConnector) { | ||
super(User.class, databaseConnector, new UserSummary()); | ||
|
@@ -37,4 +54,18 @@ public UserRepository(DatabaseConnector databaseConnector) { | |
public List<User> get(Collection<String> ids) { | ||
return getConnector().get(User.class, ids, true); | ||
} | ||
|
||
public User getByExternalId(String externalId) { | ||
final Set<String> userIds = queryForIdsAsValue("byExternalId", externalId); | ||
if (userIds != null && !userIds.isEmpty()) | ||
return get(CommonUtils.getFirst(userIds)); | ||
return null; | ||
} | ||
|
||
public User getByFormerEmail(String email) { | ||
final Set<String> userIds = queryForIdsAsValue("byFormerEmails", email); | ||
if (userIds != null && !userIds.isEmpty()) | ||
return get(CommonUtils.getFirst(userIds)); | ||
return null; | ||
} | ||
} |
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
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.