From 43a043908925e3d489b5b11b7afd72134395ef3c Mon Sep 17 00:00:00 2001 From: t2000 Date: Sat, 9 Jan 2021 10:39:21 +0100 Subject: [PATCH] [tr064] Merge duplicate phone book entries (#9739) * [tr064] Merge duplicate phone book entries Fixes #9738 Signed-off-by: Stefan Triller --- .../internal/phonebook/Tr064PhonebookImpl.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/Tr064PhonebookImpl.java b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/Tr064PhonebookImpl.java index b9e1dc650c9a6..8e7782b763685 100644 --- a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/Tr064PhonebookImpl.java +++ b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/Tr064PhonebookImpl.java @@ -72,7 +72,8 @@ private void getPhonebook() { phonebook = phonebooksType.getPhonebook().getContact().stream().map(contact -> { String contactName = contact.getPerson().getRealName(); 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); logger.debug("Downloaded phonebook {}: {}", phonebookName, phonebook); } catch (JAXBException | InterruptedException | ExecutionException | TimeoutException e) { @@ -80,6 +81,16 @@ private void getPhonebook() { } } + // 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 public String getName() { return phonebookName;