package com.github.fengtan.solrgui;

import java.util.Collection;

import org.apache.solr.common.SolrDocument;

// TODO extend SolrDocument ? might simplify the code
public class SolrGUIDocument {

	private SolrGUIChange change = SolrGUIChange.NONE;
	private SolrDocument document;
	
	// TODO drop ?
	public SolrGUIDocument(SolrDocument document) {
		this.document = document;
	}
	
	public SolrGUIDocument(String[] fields) {
		document = new SolrDocument();
		for (String field:fields) {
			document.setField(field, null);
		}
	}
	
	public SolrGUIChange getChange() {
		return change;
	}
	
	public void setChange(SolrGUIChange change) {
		this.change = change;
	}
	
	public SolrDocument getDocument() {
		return document;
	}
	
	public void setField(String name, Object value) {
		document.setField(name, value);
	}
	
	public Collection<String> getFieldNames() {
		return document.getFieldNames();
	}
	
	public Object getFieldValue(String name) {
		return document.getFieldValue(name);
	}
	
}

@@ -58,16 +58,41 @@
 lection;
+%0Aimport java.util.Random;
 %0A%0Aimport
@@ -545,16 +545,165 @@
 l);%0A%09%09%7D%0A
+%09%09// TODO can we assume the id field always exists ?%0A%09%09// TODO use something else than random%0A%09%09document.setField(%22id%22, new Random().nextInt(1000));%0A
 %09%7D%0A%09%0A%09pu

Set mandatory field id.