package com.libreecm.db.jpa.users;

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

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
import org.apache.chemistry.opencmis.commons.definitions.PermissionDefinition;
import org.hibernate.annotations.GenericGenerator;

import com.libreecm.db.jpa.CmisExtensionElementImpl;
import com.libreecm.db.jpa.LibreECMObject;
@Entity
public class PermissionDefinitionImpl extends LibreECMObject implements PermissionDefinition {
 
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
    
    @Id
	@GeneratedValue(generator="hilo-gen")
	@GenericGenerator(name="hilo-gen", strategy="hilo")
    private Integer id;

    @OneToMany
    private List<CmisExtensionElementImpl> extensions;

	private String description;


	@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());
		}		
	}
 

	@Override
	public String getDescription() {
		return this.description;
	}

	@Override
	public String getId() {
		if (id==null){
			return null;
		}
		return id.toString();
	}

	public void setId(String id){
		this.id=Integer.parseInt(id);
	}
}
