[tr064] Merge duplicate phone book entries (#9739)

* [tr064] Merge duplicate phone book entries

Fixes #9738

Signed-off-by: Stefan Triller <github@stefantriller.de>
pull/9762/head
t2000 2021-01-09 10:39:21 +01:00 committed by GitHub
parent 673535a551
commit 43a0439089
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 1 deletions

View File

@ -72,7 +72,8 @@ public class Tr064PhonebookImpl implements Phonebook {
phonebook = phonebooksType.getPhonebook().getContact().stream().map(contact -> { phonebook = phonebooksType.getPhonebook().getContact().stream().map(contact -> {
String contactName = contact.getPerson().getRealName(); String contactName = contact.getPerson().getRealName();
return contact.getTelephony().getNumber().stream() return contact.getTelephony().getNumber().stream()
.collect(Collectors.toMap(number -> normalizeNumber(number.getValue()), number -> contactName)); .collect(Collectors.toMap(number -> normalizeNumber(number.getValue()), number -> contactName,
this::mergeSameContactNames));
}).collect(HashMap::new, HashMap::putAll, HashMap::putAll); }).collect(HashMap::new, HashMap::putAll, HashMap::putAll);
logger.debug("Downloaded phonebook {}: {}", phonebookName, phonebook); logger.debug("Downloaded phonebook {}: {}", phonebookName, phonebook);
} catch (JAXBException | InterruptedException | ExecutionException | TimeoutException e) { } catch (JAXBException | InterruptedException | ExecutionException | TimeoutException e) {
@ -80,6 +81,16 @@ public class Tr064PhonebookImpl implements Phonebook {
} }
} }
// in case there are multiple phone entries with same number -> name mapping, i.e. in phonebooks exported from
// mobiles containing multiple accounts like: local, cloudprovider1, messenger1, messenger2,...
private String mergeSameContactNames(String nameA, String nameB) {
if (nameA != null && nameA.equals(nameB)) {
return nameA;
}
throw new IllegalStateException(
"Found different names for the same number: '" + nameA + "' and '" + nameB + "'");
}
@Override @Override
public String getName() { public String getName() {
return phonebookName; return phonebookName;