package edu.duke.cabig.c3pr.domain;

import gov.nih.nci.cabig.ctms.domain.AbstractMutableDomainObject;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

/**
 * 
 * @author Priyatam
 */

@Entity 
@Table (name = "IDENTIFIERS")
@GenericGenerator (name="id-generator", strategy = "native",
		parameters = {
			@Parameter(name="sequence", value="IDENTIFIERS_ID_SEQ")
		}
)
public class Identifier extends AbstractMutableDomainObject
{			
	private String source;
	private String type;
	private String value;
	private Boolean primaryIndicator = false;
				
	/**
     * Null-safe conversion from primaryIndicator property to simple boolean.
     * TODO: switch the db field to not-null, default false so this isn't necessary.
     */
    @Transient
    public boolean isPrimary() {
        return getPrimaryIndicator() == null ? false : getPrimaryIndicator();
    }
    
	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public Boolean getPrimaryIndicator() {
		return primaryIndicator;
	}

	public void setPrimaryIndicator(Boolean primaryIndicator) {
		if (primaryIndicator == null)
		{
			primaryIndicator = false;
		}
		this.primaryIndicator = primaryIndicator;
	}
		
}

@@ -122,22 +122,148 @@
 istence.
-Entity
+DiscriminatorColumn;%0Aimport javax.persistence.Entity;%0Aimport javax.persistence.Inheritance;%0Aimport javax.persistence.InheritanceType
 ;%0Aimport
@@ -454,16 +454,18 @@
 am%0A */%0A%0A
+%0A%0A
 @Entity 
@@ -495,16 +495,70 @@
 FIERS%22)%0A
+@Inheritance(strategy = InheritanceType.SINGLE_TABLE)%0A
 @Generic
@@ -699,16 +699,25 @@
 %0Apublic 
+abstract 
 class Id
@@ -766,16 +766,18 @@
 ct%0A%7B%09%09%09%0A
+//
 %09private
@@ -1200,127 +1200,8 @@
 %0A   
- %0A%09public String getSource() %7B%0A%09%09return source;%0A%09%7D%0A%0A%09public void setSource(String source) %7B%0A%09%09this.source = source;%0A%09%7D%0A
 %0A%09pu
@@ -1663,13 +1663,271 @@
 tor;%0A%09%7D%0A
+/*%0A%09public String getSource() %7B%0A%09%09if(true)throw new UnsupportedOperationException(%22Not supported%22);%0A%09%09return source;%0A%09%7D%0A%0A%09public void setSource(String source) %7B%0A%09%09if(true)throw new UnsupportedOperationException(%22Not supported%22);%0A%09%09this.source = source;%0A%09%7D*/%0A
 %09%09%0A%7D%0A

made it abstract