/**
 * Copyright 2016, RadiantBlue Technologies, Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/
package model.service.taskmanaged;

import java.io.Serializable;

import org.joda.time.DateTime;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * Represents a Job that has been sent to a Task-Managed Piazza Service.
 * <p>
 * This object correlates the Job ID with the time that is was pulled off the Jobs queue and sent to an external Service
 * Worker for processing.
 * </p>
 * 
 * @author Patrick.Doody
 *
 */
public class ServiceJob implements Serializable {
	private static final long serialVersionUID = 1L;
	
	/**
	 * The ID of the Service this Job pertains to.
	 */
	private String serviceId;
	private String jobId;
	private Integer timeouts;
	/**
	 * The time that work began processing on this Job.
	 */
	@JsonIgnore
	public DateTime startedOn;
	/**
	 * The time that the Job was inserted into the Jobs queue.
	 */
	@JsonIgnore
	public DateTime queuedOn;

	public ServiceJob() {
		this.queuedOn = new DateTime();
		this.timeouts = Integer.valueOf(0);
	}

	public ServiceJob(String jobId, String serviceId) {
		this();
		this.jobId = jobId;
		this.serviceId = serviceId;
	}

	public String getJobId() {
		return jobId;
	}

	public void setJobId(String jobId) {
		this.jobId = jobId;
	}

	@JsonIgnore
	public DateTime getStartedOn() {
		return startedOn;
	}

	@JsonIgnore
	public void setStartedOn(DateTime startedOn) {
		this.startedOn = startedOn;
	}

	@JsonProperty("startedOn")
	public Long getStartedOnString() {
		if (startedOn != null) {
			// Defaults to ISO8601
			return startedOn.getMillis();
		} else {
			return null;
		}
	}

	@JsonProperty("startedOn")
	public void setStartedOnString(Long startedOn) {
		this.startedOn = new DateTime(startedOn);
	}

	@JsonIgnore
	public DateTime getQueuedOn() {
		return queuedOn;
	}

	@JsonIgnore
	public void setQueuedOn(DateTime queuedOn) {
		this.queuedOn = queuedOn;
	}

	@JsonProperty("queuedOn")
	public Long getQueuedOnString() {
		if (queuedOn != null) {
			// Defaults to ISO8601
			return queuedOn.getMillis();
		} else {
			return null;
		}
	}

	@JsonProperty("queuedOn")
	public void setQueuedOnString(Long queuedOn) {
		this.queuedOn = new DateTime(queuedOn);
	}

	public Integer getTimeouts() {
		return timeouts;
	}

	public void setTimeouts(Integer timeouts) {
		this.timeouts = timeouts;
	}

	public String getServiceId() {
		return serviceId;
	}

	public void setServiceId(String serviceId) {
		this.serviceId = serviceId;
	}
}

@@ -765,184 +765,8 @@
 re;%0A
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;%0Aimport com.fasterxml.jackson.annotation.JsonInclude;%0Aimport com.fasterxml.jackson.annotation.JsonInclude.Include;%0A
 impo
@@ -1191,17 +1191,16 @@
 D = 1L;%0A
-%09
 %0A%09/**%0A%09 
@@ -2293,32 +2293,60 @@
 ng startedOn) %7B%0A
+%09%09if (startedOn != null) %7B%0A%09
 %09%09this.startedOn
@@ -2369,24 +2369,65 @@
 startedOn);%0A
+%09%09%7D else %7B%0A%09%09%09this.startedOn = null;%0A%09%09%7D%0A
 %09%7D%0A%0A%09@JsonIg

Fix ServiceJob Deserialization