/*
 * oxAuth is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

package org.gluu.oxauth.model.common;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import org.gluu.persist.model.base.CustomAttribute;
import org.gluu.persist.annotation.DataEntry;
import org.gluu.persist.annotation.ObjectClass;
import org.gluu.util.StringHelper;

/**
 * @author Yuriy Movchan Date: 06/11/2013
 */
@DataEntry
@ObjectClass(value = "gluuPerson")
public class User extends SimpleUser {

    private static final long serialVersionUID = 6634191420188575733L;

	public void setAttribute(String attributeName, String attributeValue) {
		CustomAttribute attribute = new CustomAttribute(attributeName, attributeValue);
		removeAttribute(attributeName);
		getCustomAttributes().add(attribute);
	}

	public void setAttribute(String attributeName, String[] attributeValues) {
		CustomAttribute attribute = new CustomAttribute(attributeName, Arrays.asList(attributeValues));
		removeAttribute(attributeName);
		getCustomAttributes().add(attribute);
	}

	public void setAttribute(String attributeName, List<String> attributeValues) {
		CustomAttribute attribute = new CustomAttribute(attributeName, attributeValues);
		removeAttribute(attributeName);
		getCustomAttributes().add(attribute);
	}
	
	public void removeAttribute(String attributeName) {
		for (Iterator<CustomAttribute> it = getCustomAttributes().iterator(); it.hasNext();) {
			if (StringHelper.equalsIgnoreCase(attributeName, it.next().getName())) {
				it.remove();
				break;
			}
		}
	}

}
@@ -644,16 +644,32 @@
 5733L;%0A%0A
+    @Deprecated%0A
 %09public 
@@ -729,24 +729,175 @@
 uteValue) %7B%0A
+%09%09setAttribute(attributeName, attributeValue, null);%0A%09%7D%0A%0A%09public void setAttribute(String attributeName, String attributeValue, Boolean multiValued) %7B%0A
 %09%09CustomAttr
@@ -966,16 +966,92 @@
 Value);%0A
+%09%09if (multiValued != null) %7B%0A%09%09%09attribute.setMultiValued(multiValued);%0A%09%09%7D%0A%0A
 %09%09remove
@@ -1112,32 +1112,48 @@
 attribute);%0A%09%7D%0A%0A
+    @Deprecated%0A
 %09public void set
@@ -1204,32 +1204,190 @@
 ributeValues) %7B%0A
+    %09setAttribute(attributeName, attributeValues, null);%0A%09%7D%0A%0A%09public void setAttribute(String attributeName, String%5B%5D attributeValues, Boolean multiValued) %7B%0A
 %09%09CustomAttribut
@@ -1468,16 +1468,92 @@
 lues));%0A
+%09%09if (multiValued != null) %7B%0A%09%09%09attribute.setMultiValued(multiValued);%0A%09%09%7D%0A%0A
 %09%09remove
@@ -1618,24 +1618,40 @@
 ibute);%0A%09%7D%0A%0A
+    @Deprecated%0A
 %09public void
@@ -1714,24 +1714,183 @@
 teValues) %7B%0A
+%09%09setAttribute(attributeName, attributeValues, null);%0A%09%7D%0A%0A%09public void setAttribute(String attributeName, List%3CString%3E attributeValues, Boolean multiValued) %7B%0A
 %09%09CustomAttr
@@ -1960,16 +1960,92 @@
 alues);%0A
+%09%09if (multiValued != null) %7B%0A%09%09%09attribute.setMultiValued(multiValued);%0A%09%09%7D%0A%0A
 %09%09remove

Allow to specify if custome attribute is multivalued