package uk.ac.ebi.biosamples.neo.model;

import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.Index;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Property;

@NodeEntity(label = "Attribute")
public class NeoAttribute {

	@GraphId
	private Long id;

	@Property
	private String type;

	@Property
	private String value;

	@Property
	private String iri;

	@Property
	private String unit;
	
	@Property
	@Index(unique=true, primary=true)
	private String compositeIdentifier;
	
	
	private NeoAttribute() {
		
	}

	public String getType() {
		return type;
	}

	public String getValue() {
		return value;
	}

	public String getIri() {
		return iri;
	}

	public String getUnit() {
		return unit;
	}
	
	public static NeoAttribute build(String type, String value, String iri, String unit) {
		NeoAttribute neoAttribute = new NeoAttribute();
		neoAttribute.type = type;
		neoAttribute.value = value;
		neoAttribute.iri = iri;
		neoAttribute.unit = unit;
		
		//build the composite identifier here so that neo4j can use it as a primary index
		//to unique and merge nodes
		String compositeIdentifier = type+"_"+value;
		if (iri != null)  {
			compositeIdentifier = compositeIdentifier+"_"+iri;
		}
		if (unit != null)  {
			compositeIdentifier = compositeIdentifier+"_"+unit;
		}
		neoAttribute.compositeIdentifier = compositeIdentifier;
		return neoAttribute;
	}
}

@@ -295,32 +295,40 @@
 id;%0A%0A%09@Property%0A
+%09@Index%0A
 %09private String 
@@ -337,32 +337,40 @@
 pe;%0A%0A%09@Property%0A
+%09@Index%0A
 %09private String 
@@ -380,32 +380,40 @@
 ue;%0A%0A%09@Property%0A
+%09@Index%0A
 %09private String 
@@ -429,16 +429,24 @@
 roperty%0A
+%09@Index%0A
 %09private

index attribute keys and values