package com.libreecm.db.jpa.users;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.annotations.GenericGenerator;

import com.libreecm.db.jpa.CmisExtensionElementImpl;
import com.libreecm.db.jpa.LibreECMObject;

import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;

@Entity
public class PermissionMappingImpl extends LibreECMObject
		implements org.apache.chemistry.opencmis.commons.data.PermissionMapping {


	/** 
	 * 
	 */
	private static final long serialVersionUID = 6066353858545354499L;
 
	@Id
	@GeneratedValue(generator="hilo-gen")
	@GenericGenerator(name="hilo-gen", strategy="hilo")
	private Integer id;
	
	@ElementCollection(targetClass=CmisExtensionElementImpl.class)
    private List<CmisExtensionElementImpl> extensions;

	@ElementCollection(targetClass=String.class)
    private List<String> permissions;

	private String key;

	public PermissionMappingImpl(){
		
	}

	public PermissionMappingImpl(List<CmisExtensionElementImpl> extensions, List<String> permissions, String key) {
		super();
		this.extensions = extensions;
		this.permissions = permissions;
		this.key = key;
	}

	@Override
	public List<CmisExtensionElement> getExtensions() {
		ArrayList<CmisExtensionElement> array= new ArrayList<CmisExtensionElement>();
		array.addAll(this.extensions);
		return array;
	} 

	public void setExtensions(List<CmisExtensionElement> arg0) {
	this.extensions=new ArrayList<CmisExtensionElementImpl>();
	Iterator<CmisExtensionElement> it = arg0.iterator();
		while (it.hasNext()){
			this.extensions.add((CmisExtensionElementImpl) it.next());
		}		
	}
 
	public String getId() {
		if (id==null){
			return null;
		}
		return id.toString();
	}
	
	public void setId(String id) {
		this.id=Integer.parseInt(id);
	}

	public void setPermissions(List<String> permissions) {
		this.permissions = permissions;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getKey() {
		return key;
	}

	public List<String> getPermissions() {
		return permissions;
	}

}
