@Override public void setSingleAttribute(String name, String value) { boolean found = false; List<UserAttributeEntity> toRemove = new ArrayList<>(); for (UserAttributeEntity attr : user.getAttributes()) { if (attr.getName().equals(name)) { if (!found) { attr.setValue(value); found = true; } else { toRemove.add(attr); } } } for (UserAttributeEntity attr : toRemove) { em.remove(attr); user.getAttributes().remove(attr); } if (found) { return; } persistAttributeValue(name, value); }
@Override public Map<String, String> getAttributes() { Map<String, String> result = new HashMap<String, String>(); for (UserAttributeEntity attr : user.getAttributes()) { result.put(attr.getName(), attr.getValue()); } return result; }
@Override public Map<String, List<String>> getAttributes() { MultivaluedHashMap<String, String> result = new MultivaluedHashMap<>(); for (UserAttributeEntity attr : user.getAttributes()) { result.add(attr.getName(), attr.getValue()); } return result; }
@Override public String getAttribute(String name) { for (UserAttributeEntity attr : user.getAttributes()) { if (attr.getName().equals(name)) { return attr.getValue(); } } return null; }
@Override public List<String> getAttribute(String name) { List<String> result = new ArrayList<>(); for (UserAttributeEntity attr : user.getAttributes()) { if (attr.getName().equals(name)) { result.add(attr.getValue()); } } return result; }
@Override public void removeAttribute(String name) { Iterator<UserAttributeEntity> it = user.getAttributes().iterator(); while (it.hasNext()) { UserAttributeEntity attr = it.next(); if (attr.getName().equals(name)) { it.remove(); em.remove(attr); } } }
@Override public void setAttribute(String name, String value) { for (UserAttributeEntity attr : user.getAttributes()) { if (attr.getName().equals(name)) { attr.setValue(value); return; } } UserAttributeEntity attr = new UserAttributeEntity(); attr.setName(name); attr.setValue(value); attr.setUser(user); em.persist(attr); user.getAttributes().add(attr); }