package cz.esc.iot.cloudservice.persistance.model;

import java.util.Date;

import org.bson.types.ObjectId;
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;
import org.mongodb.morphia.annotations.Index;
import org.mongodb.morphia.annotations.IndexOptions;
import org.mongodb.morphia.annotations.Indexed;
import org.mongodb.morphia.annotations.Indexes;
import org.mongodb.morphia.annotations.Reference;

import com.google.gson.annotations.Expose;

/**
 * Morfia's entity representing one measured value.
 */
@Entity
@Indexes(@Index(options = @IndexOptions(name = "name, -time", unique = true)))
public class Data {
	
    @Id
    private ObjectId id;
	private String name;
	@Expose private String value;
	@Indexed(expireAfterSeconds = 24*3600) // data are stored for one day
	@Expose private Date time;
	@Reference
	private SensorEntity sensor;
	
	public Data() {
		super();
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public String getName() {
		return name;
	}
	
	public SensorEntity getSensor() {
		return sensor;
	}

	public void setSensor(SensorEntity sensor) {
		this.sensor = sensor;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public String getValue() {
		return value;
	}
	
	public void setValue(String value) {
		this.value = value;
	}

	@Override
	public String toString() {
		return "Data [name=" + name + ", value=" + value + ", time=" + time + "]";
	}
}

@@ -386,16 +386,62 @@
 ndexes;%0A
+import org.mongodb.morphia.annotations.Field;%0A
 import o
@@ -482,16 +482,16 @@
 erence;%0A
-
 %0Aimport 
@@ -608,15 +608,21 @@
 xes(
+%7B%0A%09
 @Index(
+%0A%09%09
 opti
@@ -645,45 +645,75 @@
 ons(
-name = %22name, -time%22, unique = true))
+unique = true),%0A%09%09fields = %7B%0A%09%09%09@Field(value = %22name, -time%22)%0A%09%7D)%0A%7D
 )%0Apu

add Field annotation