package ca.ualberta.physics.cssdp.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;

import org.hibernate.annotations.Type;
import org.joda.time.DateTime;

import ca.ualberta.physics.cssdp.dao.Persistent;
import ca.ualberta.physics.cssdp.util.JSONDateTimeNoMillisSerializer;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

/**
 * a domain object used to hold service statistics
 * 
 * @author rpotter
 * 
 */
@Entity
@Table(name = "service_stats")
@JsonAutoDetect(getterVisibility = Visibility.PUBLIC_ONLY)
public class ServiceStats extends Persistent implements Serializable {

	public enum ServiceName {
		AUTH, FILE, CATALOGUE, MACRO, VFS, STATS
	}

	private static final long serialVersionUID = 1L;

	@Column(name = "service_name", length = 10, nullable = false)
	@Enumerated(EnumType.STRING)
	private ServiceName serviceName;

	@Column(name = "invocations", nullable = false)
	private int invocations;

	@Column(name = "reset_date", nullable = false)
	@Type(type = "ca.ualberta.physics.cssdp.dao.type.PersistentDateTime")
	private DateTime lastReset;

	// overridden to set jsonignore
	@JsonIgnore
	@Override
	public Long getId() {
		return super.getId();
	}

	// overridden to set jsonignore
	@JsonIgnore
	@Override
	public int getVersion() {
		return super.getVersion();
	}

	@Override
	public String _pk() {
		return serviceName.name();
	}

	@JsonIgnore
	public ServiceName getServiceName() {
		return serviceName;
	}

	public void setServiceName(ServiceName serviceName) {
		this.serviceName = serviceName;
	}

	public int getInvocations() {
		return invocations;
	}

	public void setInvocations(int invocations) {
		this.invocations = invocations;
	}

	@JsonSerialize(using = JSONDateTimeNoMillisSerializer.class)
	public DateTime getLastReset() {
		return lastReset;
	}

	public void setLastReset(DateTime lastReset) {
		this.lastReset = lastReset;
	}

	public void incrementInvocations() {
		setInvocations(getInvocations() + 1);
	}

	public String toHtmlString() {
		return null;
	}

}

@@ -306,16 +306,73 @@
 ateTime;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aimport
@@ -983,19 +983,111 @@
 le %7B%0A%0A%09p
-ubl
+rivate static final Logger logger = LoggerFactory.getLogger(ServiceStats.class);%0A%09%0A%09public stat
 ic enum 
@@ -1779,32 +1779,32 @@
 %0A%09%7D%0A%0A%09@Override%0A
-
 %09public String _
@@ -1806,24 +1806,91 @@
 ing _pk() %7B%0A
+%09%09logger.debug(%22service name in domain object is %22 + serviceName);%0A
 %09%09return ser

add debugging and made enum static in domain object