@Test public void testUpdatePropertyDeleteSome() { Person dbPerson = (Person) getEntityManager().createQuery("FROM Person WHERE id = :id") .setParameter("id", PERSON_ID).getSingleResult(); HashMap<String, String> dbProps = new HashMap<String, String>(); dbProps.put("key1", "value1"); dbProps.put("key2", "value2"); dbPerson.setAdditionalProperties(dbProps); getEntityManager().flush(); Person ldapPerson = new Person("fordp", "Ford", "X", "Prefect", "Volgon-Swatter"); HashMap<String, String> ldapProps = new HashMap<String, String>(); ldapProps.put("key1", "value1"); ldapPerson.setAdditionalProperties(ldapProps); UpdatePersonResponse result = sut.execute(ldapPerson); assertTrue(result.wasUserUpdated()); getEntityManager().flush(); getEntityManager().clear(); Person resultPerson = (Person) getEntityManager().createQuery("FROM Person WHERE id = :id") .setParameter("id", PERSON_ID).getSingleResult(); HashMap<String, String> resultProps = resultPerson.getAdditionalProperties(); assertNotNull(resultProps); assertEquals(1, resultProps.size()); assertEquals("value1", resultProps.get("key1")); }
@Override public UpdatePersonResponse execute(final Person ldapPerson) { Person dbPerson = (Person) getEntityManager().createQuery("FROM Person where accountId = :accountId") .setParameter("accountId", ldapPerson.getAccountId()).getSingleResult(); HashMap<String, String> ldapAdditionalProperties = ldapPerson.getAdditionalProperties(); HashMap<String, String> dbAdditionalProperties = dbPerson.getAdditionalProperties(); boolean wasPersonUpdated = false; boolean wasPersonDisplayNameUpdated = false; if (!dbPerson.getLastName().equals(ldapPerson.getLastName())) { dbPerson.setLastName(ldapPerson.getLastName()); wasPersonUpdated = true; wasPersonDisplayNameUpdated = true; } if ((dbPerson.getCompanyName() == null && ldapPerson.getCompanyName() != null) || (dbPerson.getCompanyName() != null && !dbPerson.getCompanyName().equals(ldapPerson.getCompanyName()))) { dbPerson.setCompanyName(ldapPerson.getCompanyName()); wasPersonUpdated = true; } log.debug("Checking if the displayNameSuffix changed"); String newDisplayNameSuffix = ""; if (ldapPerson.getDisplayNameSuffix() != null) { newDisplayNameSuffix = ldapPerson.getDisplayNameSuffix(); } if (!dbPerson.getDisplayNameSuffix().equals(newDisplayNameSuffix)) { log.debug("displayNameSuffix did change - new value: " + newDisplayNameSuffix); dbPerson.setDisplayNameSuffix(newDisplayNameSuffix); wasPersonUpdated = true; wasPersonDisplayNameUpdated = true; } if (ldapAdditionalProperties != null && !ldapAdditionalProperties.isEmpty()) { boolean changed = false; if (dbAdditionalProperties == null) { changed = true; } else { for (String key : ldapAdditionalProperties.keySet()) { String value = ldapAdditionalProperties.get(key); if (!value.equalsIgnoreCase(dbAdditionalProperties.get(key))) { changed = true; break; } } if (!changed) { for (String key : dbAdditionalProperties.keySet()) { if (!ldapAdditionalProperties.containsKey(key)) { changed = true; break; } } } } if (changed) { dbPerson.setAdditionalProperties(ldapAdditionalProperties); wasPersonUpdated = true; } } else if (dbAdditionalProperties != null) { dbPerson.setAdditionalProperties(null); wasPersonUpdated = true; } if (wasPersonUpdated) { getEntityManager().flush(); } return new UpdatePersonResponse(dbPerson.getId(), wasPersonUpdated, wasPersonDisplayNameUpdated); }
UpdatePersonMapper extends BaseArgDomainMapper<Person, UpdatePersonResponse> { @Override public UpdatePersonResponse execute(final Person ldapPerson) { Person dbPerson = (Person) getEntityManager().createQuery("FROM Person where accountId = :accountId") .setParameter("accountId", ldapPerson.getAccountId()).getSingleResult(); HashMap<String, String> ldapAdditionalProperties = ldapPerson.getAdditionalProperties(); HashMap<String, String> dbAdditionalProperties = dbPerson.getAdditionalProperties(); boolean wasPersonUpdated = false; boolean wasPersonDisplayNameUpdated = false; if (!dbPerson.getLastName().equals(ldapPerson.getLastName())) { dbPerson.setLastName(ldapPerson.getLastName()); wasPersonUpdated = true; wasPersonDisplayNameUpdated = true; } if ((dbPerson.getCompanyName() == null && ldapPerson.getCompanyName() != null) || (dbPerson.getCompanyName() != null && !dbPerson.getCompanyName().equals(ldapPerson.getCompanyName()))) { dbPerson.setCompanyName(ldapPerson.getCompanyName()); wasPersonUpdated = true; } log.debug("Checking if the displayNameSuffix changed"); String newDisplayNameSuffix = ""; if (ldapPerson.getDisplayNameSuffix() != null) { newDisplayNameSuffix = ldapPerson.getDisplayNameSuffix(); } if (!dbPerson.getDisplayNameSuffix().equals(newDisplayNameSuffix)) { log.debug("displayNameSuffix did change - new value: " + newDisplayNameSuffix); dbPerson.setDisplayNameSuffix(newDisplayNameSuffix); wasPersonUpdated = true; wasPersonDisplayNameUpdated = true; } if (ldapAdditionalProperties != null && !ldapAdditionalProperties.isEmpty()) { boolean changed = false; if (dbAdditionalProperties == null) { changed = true; } else { for (String key : ldapAdditionalProperties.keySet()) { String value = ldapAdditionalProperties.get(key); if (!value.equalsIgnoreCase(dbAdditionalProperties.get(key))) { changed = true; break; } } if (!changed) { for (String key : dbAdditionalProperties.keySet()) { if (!ldapAdditionalProperties.containsKey(key)) { changed = true; break; } } } } if (changed) { dbPerson.setAdditionalProperties(ldapAdditionalProperties); wasPersonUpdated = true; } } else if (dbAdditionalProperties != null) { dbPerson.setAdditionalProperties(null); wasPersonUpdated = true; } if (wasPersonUpdated) { getEntityManager().flush(); } return new UpdatePersonResponse(dbPerson.getId(), wasPersonUpdated, wasPersonDisplayNameUpdated); } }
UpdatePersonMapper extends BaseArgDomainMapper<Person, UpdatePersonResponse> { @Override public UpdatePersonResponse execute(final Person ldapPerson) { Person dbPerson = (Person) getEntityManager().createQuery("FROM Person where accountId = :accountId") .setParameter("accountId", ldapPerson.getAccountId()).getSingleResult(); HashMap<String, String> ldapAdditionalProperties = ldapPerson.getAdditionalProperties(); HashMap<String, String> dbAdditionalProperties = dbPerson.getAdditionalProperties(); boolean wasPersonUpdated = false; boolean wasPersonDisplayNameUpdated = false; if (!dbPerson.getLastName().equals(ldapPerson.getLastName())) { dbPerson.setLastName(ldapPerson.getLastName()); wasPersonUpdated = true; wasPersonDisplayNameUpdated = true; } if ((dbPerson.getCompanyName() == null && ldapPerson.getCompanyName() != null) || (dbPerson.getCompanyName() != null && !dbPerson.getCompanyName().equals(ldapPerson.getCompanyName()))) { dbPerson.setCompanyName(ldapPerson.getCompanyName()); wasPersonUpdated = true; } log.debug("Checking if the displayNameSuffix changed"); String newDisplayNameSuffix = ""; if (ldapPerson.getDisplayNameSuffix() != null) { newDisplayNameSuffix = ldapPerson.getDisplayNameSuffix(); } if (!dbPerson.getDisplayNameSuffix().equals(newDisplayNameSuffix)) { log.debug("displayNameSuffix did change - new value: " + newDisplayNameSuffix); dbPerson.setDisplayNameSuffix(newDisplayNameSuffix); wasPersonUpdated = true; wasPersonDisplayNameUpdated = true; } if (ldapAdditionalProperties != null && !ldapAdditionalProperties.isEmpty()) { boolean changed = false; if (dbAdditionalProperties == null) { changed = true; } else { for (String key : ldapAdditionalProperties.keySet()) { String value = ldapAdditionalProperties.get(key); if (!value.equalsIgnoreCase(dbAdditionalProperties.get(key))) { changed = true; break; } } if (!changed) { for (String key : dbAdditionalProperties.keySet()) { if (!ldapAdditionalProperties.containsKey(key)) { changed = true; break; } } } } if (changed) { dbPerson.setAdditionalProperties(ldapAdditionalProperties); wasPersonUpdated = true; } } else if (dbAdditionalProperties != null) { dbPerson.setAdditionalProperties(null); wasPersonUpdated = true; } if (wasPersonUpdated) { getEntityManager().flush(); } return new UpdatePersonResponse(dbPerson.getId(), wasPersonUpdated, wasPersonDisplayNameUpdated); }  }
UpdatePersonMapper extends BaseArgDomainMapper<Person, UpdatePersonResponse> { @Override public UpdatePersonResponse execute(final Person ldapPerson) { Person dbPerson = (Person) getEntityManager().createQuery("FROM Person where accountId = :accountId") .setParameter("accountId", ldapPerson.getAccountId()).getSingleResult(); HashMap<String, String> ldapAdditionalProperties = ldapPerson.getAdditionalProperties(); HashMap<String, String> dbAdditionalProperties = dbPerson.getAdditionalProperties(); boolean wasPersonUpdated = false; boolean wasPersonDisplayNameUpdated = false; if (!dbPerson.getLastName().equals(ldapPerson.getLastName())) { dbPerson.setLastName(ldapPerson.getLastName()); wasPersonUpdated = true; wasPersonDisplayNameUpdated = true; } if ((dbPerson.getCompanyName() == null && ldapPerson.getCompanyName() != null) || (dbPerson.getCompanyName() != null && !dbPerson.getCompanyName().equals(ldapPerson.getCompanyName()))) { dbPerson.setCompanyName(ldapPerson.getCompanyName()); wasPersonUpdated = true; } log.debug("Checking if the displayNameSuffix changed"); String newDisplayNameSuffix = ""; if (ldapPerson.getDisplayNameSuffix() != null) { newDisplayNameSuffix = ldapPerson.getDisplayNameSuffix(); } if (!dbPerson.getDisplayNameSuffix().equals(newDisplayNameSuffix)) { log.debug("displayNameSuffix did change - new value: " + newDisplayNameSuffix); dbPerson.setDisplayNameSuffix(newDisplayNameSuffix); wasPersonUpdated = true; wasPersonDisplayNameUpdated = true; } if (ldapAdditionalProperties != null && !ldapAdditionalProperties.isEmpty()) { boolean changed = false; if (dbAdditionalProperties == null) { changed = true; } else { for (String key : ldapAdditionalProperties.keySet()) { String value = ldapAdditionalProperties.get(key); if (!value.equalsIgnoreCase(dbAdditionalProperties.get(key))) { changed = true; break; } } if (!changed) { for (String key : dbAdditionalProperties.keySet()) { if (!ldapAdditionalProperties.containsKey(key)) { changed = true; break; } } } } if (changed) { dbPerson.setAdditionalProperties(ldapAdditionalProperties); wasPersonUpdated = true; } } else if (dbAdditionalProperties != null) { dbPerson.setAdditionalProperties(null); wasPersonUpdated = true; } if (wasPersonUpdated) { getEntityManager().flush(); } return new UpdatePersonResponse(dbPerson.getId(), wasPersonUpdated, wasPersonDisplayNameUpdated); }  @Override UpdatePersonResponse execute(final Person ldapPerson); }
UpdatePersonMapper extends BaseArgDomainMapper<Person, UpdatePersonResponse> { @Override public UpdatePersonResponse execute(final Person ldapPerson) { Person dbPerson = (Person) getEntityManager().createQuery("FROM Person where accountId = :accountId") .setParameter("accountId", ldapPerson.getAccountId()).getSingleResult(); HashMap<String, String> ldapAdditionalProperties = ldapPerson.getAdditionalProperties(); HashMap<String, String> dbAdditionalProperties = dbPerson.getAdditionalProperties(); boolean wasPersonUpdated = false; boolean wasPersonDisplayNameUpdated = false; if (!dbPerson.getLastName().equals(ldapPerson.getLastName())) { dbPerson.setLastName(ldapPerson.getLastName()); wasPersonUpdated = true; wasPersonDisplayNameUpdated = true; } if ((dbPerson.getCompanyName() == null && ldapPerson.getCompanyName() != null) || (dbPerson.getCompanyName() != null && !dbPerson.getCompanyName().equals(ldapPerson.getCompanyName()))) { dbPerson.setCompanyName(ldapPerson.getCompanyName()); wasPersonUpdated = true; } log.debug("Checking if the displayNameSuffix changed"); String newDisplayNameSuffix = ""; if (ldapPerson.getDisplayNameSuffix() != null) { newDisplayNameSuffix = ldapPerson.getDisplayNameSuffix(); } if (!dbPerson.getDisplayNameSuffix().equals(newDisplayNameSuffix)) { log.debug("displayNameSuffix did change - new value: " + newDisplayNameSuffix); dbPerson.setDisplayNameSuffix(newDisplayNameSuffix); wasPersonUpdated = true; wasPersonDisplayNameUpdated = true; } if (ldapAdditionalProperties != null && !ldapAdditionalProperties.isEmpty()) { boolean changed = false; if (dbAdditionalProperties == null) { changed = true; } else { for (String key : ldapAdditionalProperties.keySet()) { String value = ldapAdditionalProperties.get(key); if (!value.equalsIgnoreCase(dbAdditionalProperties.get(key))) { changed = true; break; } } if (!changed) { for (String key : dbAdditionalProperties.keySet()) { if (!ldapAdditionalProperties.containsKey(key)) { changed = true; break; } } } } if (changed) { dbPerson.setAdditionalProperties(ldapAdditionalProperties); wasPersonUpdated = true; } } else if (dbAdditionalProperties != null) { dbPerson.setAdditionalProperties(null); wasPersonUpdated = true; } if (wasPersonUpdated) { getEntityManager().flush(); } return new UpdatePersonResponse(dbPerson.getId(), wasPersonUpdated, wasPersonDisplayNameUpdated); }  @Override UpdatePersonResponse execute(final Person ldapPerson);  }