package org.snomed.otf.scheduler.domain;

import java.util.*;

import javax.persistence.*;

@Entity
public class JobRun {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	UUID id;
	String jobName;
	
	@ElementCollection
	@CollectionTable(name = "job_run_parameters")
	@MapKeyColumn(name="param_name", length=25)
	@Column(name="value")
	Map<String, String> parameters;
	
	String terminologyServerUrl;
	Date requestTime;
	String user;
	String authToken;
	JobStatus status;
	String debugInfo;
	Date resultTime;
	Integer issuesReported;
	String resultUrl;
	
	private JobRun () {}
	
	static public JobRun create(String jobName, String user) {
		JobRun j = new JobRun();
		j.id = UUID.randomUUID();
		j.jobName = jobName;
		j.user = user;
		j.requestTime = new Date();
		return j;
	}
	
	static public JobRun create(JobSchedule jobSchedule) {
		JobRun j = new JobRun();
		j.id = UUID.randomUUID();
		j.jobName = jobSchedule.getJobName();
		j.user = jobSchedule.getUser();
		j.setParameters(new HashMap<>(jobSchedule.getParameters()));
		j.requestTime = new Date();
		return j;
	}
	public String getJobName() {
		return jobName;
	}
	public void setJobName(String jobName) {
		this.jobName = jobName;
	}
	public Map<String, String> getParameters() {
		return parameters;
	}
	public void setParameters(Map<String, String> parameters) {
		this.parameters = parameters;
	}
	public String getTerminologyServerUrl() {
		return terminologyServerUrl;
	}
	public void setTerminologyServerUrl(String terminologyServerUrl) {
		this.terminologyServerUrl = terminologyServerUrl;
	}
	public Date getRequestTime() {
		return requestTime;
	}
	public void setRequestTime(Date requestTime) {
		this.requestTime = requestTime;
	}
	public String getUser() {
		return user;
	}
	public String getAuthToken() {
		return authToken;
	}
	public void setAuthToken(String authToken) {
		this.authToken = authToken;
	}
	public JobStatus getStatus() {
		return status;
	}
	public void setStatus(JobStatus status) {
		this.status = status;
	}
	public String getDebugInfo() {
		return debugInfo;
	}
	public void setDebugInfo(String debugInfo) {
		this.debugInfo = debugInfo;
	}
	public Date getResultTime() {
		return resultTime;
	}
	public void setResultTime(Date resultTime) {
		this.resultTime = resultTime;
	}
	public Integer getIssuesReported() {
		return issuesReported;
	}
	public void setIssuesReported(Integer issuesReported) {
		this.issuesReported = issuesReported;
	}
	public String getResultUrl() {
		return resultUrl;
	}
	public void setResultUrl(String resultUrl) {
		this.resultUrl = resultUrl;
	}
	public UUID getId() {
		return id;
	}
	public void setId(UUID id) {
		this.id = id;
	}
	public void setUser(String user) {
		this.user = user;
	}
	public String toString() {
		return jobName + " (" + id + ")"
				+ " for user '" + user + "' in status: "
				+ status 
				+ debugInfo == null? "" : " (" + debugInfo + ")";
	}
}

@@ -364,16 +364,34 @@
 rameters
+ = new HashMap%3C%3E()
 ;%0A%09%0A%09Str
@@ -1293,91 +1293,315 @@
 lic 
-void setParameters(Map%3CString, String%3E parameters) %7B%0A%09%09this.parameters = parameters
+String getParameter(String key) %7B%0A%09%09if (parameters.containsKey(key)) %7B%0A%09%09%09return parameters.get(key);%0A%09%09%7D%0A%09%09return null;%0A%09%7D%0A%09public void setParameters(Map%3CString, String%3E parameters) %7B%0A%09%09this.parameters = parameters;%0A%09%7D%0A%09public void setParameter(String key, String value) %7B%0A%09%09this.parameters.put(key, value)
 ;%0A%09%7D
@@ -3140,10 +3140,11 @@
 %22)%22;%0A%09%7D%0A
+%0A
 %7D%0A

Add get/set to handle specific parameters