[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
parent
673535a551
commit
43a0439089
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue