private UserGroupRestRep update() {
      UserGroupUpdateParam param = new UserGroupUpdateParam();
      UserGroupRestRep userGroupRestRep = UserGroupUtils.getUserGroup(this.id);

      param.setLabel(userGroupRestRep.getName());
      param.setDomain(this.domain);

      Set<UserAttributeParam> oldAttributes = userGroupRestRep.getAttributes();
      Set<UserAttributeParam> newAttributes = new HashSet<UserAttributeParam>();
      for (AttributeMapping mapping : this.attributes) {
        if (mapping != null) {
          newAttributes.add(mapping.createUserAttributeParam());
        }
      }

      param.getAddAttributes().addAll(newAttributes);
      param.getAddAttributes().removeAll(oldAttributes);

      for (UserAttributeParam oldAttribute : oldAttributes) {
        param.getRemoveAttributes().add(oldAttribute.getKey());
      }

      for (UserAttributeParam newAttribute : newAttributes) {
        param.getRemoveAttributes().remove(newAttribute.getKey());
      }

      return UserGroupUtils.update(this.id, param);
    }
    public void readFrom(UserGroupRestRep userGroupRep) {
      this.id = stringId(userGroupRep);
      this.name = userGroupRep.getName();
      this.domain = userGroupRep.getDomain();

      if (!CollectionUtils.isEmpty(userGroupRep.getAttributes())) {
        for (UserAttributeParam userAttributeMapping : userGroupRep.getAttributes()) {
          if (userAttributeMapping != null) {
            AttributeMapping mapping = new AttributeMapping();
            mapping.key = userAttributeMapping.getKey();
            mapping.values = StringUtils.join(userAttributeMapping.getValues(), "\n");
            this.attributes.add(mapping);
          }
        }
      }
    }