示例#1
0
  @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);
  }
示例#2
0
 @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;
 }
示例#3
0
 @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;
 }
示例#4
0
 @Override
 public String getAttribute(String name) {
   for (UserAttributeEntity attr : user.getAttributes()) {
     if (attr.getName().equals(name)) {
       return attr.getValue();
     }
   }
   return null;
 }
示例#5
0
 @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;
 }
示例#6
0
 @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);
     }
   }
 }
示例#7
0
 @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);
 }