View Javadoc
1   /******************************************************************************
2    * JobLogEntry.java - Describe what happened
3    * 
4    * PicMan - The BuckoSoft Picture Manager in Java
5    * Copyright(c) 2007 - Dick Balaska
6    * 
7    */
8   package com.buckosoft.PicMan.domain;
9   
10  import java.text.SimpleDateFormat;
11  import java.util.Date;
12  
13  import com.buckosoft.PicMan.util.DateUtil;
14  
15  /** describe an event.
16   * @author Dick Balaska
17   * @since 2007/12/07
18   * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/src/com/buckosoft/PicMan/domain/JobLogEntry.java">JobLogEntry.java</a>
19   */
20  public class JobLogEntry {
21  	public static final int	CONTACT	= 0;
22  	public static final int	PICSIZE = 1;
23  	public static final int	MLBFIXER = 2;
24  	public static final int	MD5SUM	= 3;	
25  	public static final int	MOSAIC	= 4;
26  	public static final int	MOSAICV	= 5;
27  	public static final int INFO	= 6;
28  
29  	/** Finished processing a batch run */
30  	public static final int	DONE	= 7;
31  	/** Unknown job log */
32  	public static final int	OTHER	= 8;
33  	
34  	/** For subclasses to continue counting */
35  	protected static final int JLELAST = 9;
36  
37  	public	static final int	COLOR_NORMAL = 0;
38  	public	static final int	COLOR_OK = 1;
39  	public	static final int	COLOR_BAD = 2;
40  	
41  	static private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
42  
43  	protected	int			type = OTHER;
44  
45  	private	String		note = "";
46  	private	String		name = "";
47  	private	Date		startTime = new Date();
48  	private	Date		endTime = null;
49  	private	int			color = COLOR_NORMAL;
50  	private	static int	serialKey = 1;
51  	private	int			serial = serialKey++;
52  
53  	/**
54  	 * @param type the type to set
55  	 */
56  	public void setType(int type) {
57  		this.type = type;
58  	}
59  
60  	/**
61  	 * @return the type
62  	 */
63  	public int getType() {
64  		return type;
65  	}
66  
67  	/** Get the Serial number for this JobLogEntry
68  	 * @return The "unique" key for this entry
69  	 */
70  	public int	getSerial() {
71  		return(serial);
72  	}
73  
74  	/**
75  	 * @return the type as a string
76  	 */
77  	public	String getTypeAsString() {
78  		switch (type) {
79  		case CONTACT:
80  			return("contact");
81  		case PICSIZE:
82  			return("PicSize");
83  		case MLBFIXER:
84  			return("mlbFixer");
85  		case MD5SUM:
86  			return("md5sum");
87  		case MOSAIC:
88  			return("mosaic");
89  		case MOSAICV:
90  			return("mosVec");
91  		case INFO:
92  			return("Info");
93  		case DONE:
94  			return("done");
95  		case OTHER:
96  			return("other");
97  		}
98  		return("unknown");
99  	}
100 
101 	/**
102 	 * @return the endTime
103 	 */
104 	public Date getEndTime() {
105 		return endTime;
106 	}
107 
108 	/**
109 	 * @param endTime the endTime to set
110 	 */
111 	public void setEndTime(Date endTime) {
112 		this.endTime = endTime;
113 	}
114 
115 	/** Set the end time of this JobLogEntry to now.
116 	 */
117 	public void setEndTime() {
118 		this.endTime = new Date();
119 	}
120 
121 	/**
122 	 * @return the name
123 	 */
124 	public String getName() {
125 		return name;
126 	}
127 
128 	/**
129 	 * @param name the name to set
130 	 */
131 	public void setName(String name) {
132 		this.name = name;
133 	}
134 
135 	/** Get any note the job might have about it's status.
136 	 * @return the note
137 	 */
138 	public String getNote() {
139 		return note;
140 	}
141 
142 	/**
143 	 * @param note the note to set
144 	 */
145 	public void setNote(String note) {
146 		this.note = note;
147 	}
148 
149 	/**
150 	 * @return the color
151 	 */
152 	public int getColor() {
153 		return color;
154 	}
155 
156 	/**
157 	 * @param color the color to set
158 	 */
159 	public void setColor(int color) {
160 		this.color = color;
161 	}
162 
163 	/**
164 	 * @return the startTime
165 	 */
166 	public Date getStartTime() {
167 		return startTime;
168 	}
169 
170 	public void setError() {
171 		setColor(COLOR_BAD);
172 	}
173 
174 	public boolean isError() {
175 		return(this.color == COLOR_BAD);
176 	}
177 	/**
178 	 * @param startTime the startTime to set
179 	 */
180 	public void setStartTime(Date startTime) {
181 		this.startTime = startTime;
182 	}
183 
184 	public String getStartTimeAsString() {
185 		return(dateFormat.format(getStartTime()));
186 	}
187 
188 	public String getEndTimeAsString() {
189 		if (getEndTime() != null)
190 			return(dateFormat.format(getEndTime()));
191 		return("0");
192 	}
193 
194 	public String getDurationAsString() {
195 		if (getEndTime() != null) {
196 			return(DateUtil.timeToString(getEndTime().getTime() - getStartTime().getTime()));
197 		}
198 		return(DateUtil.timeToString(new Date().getTime() - getStartTime().getTime()));
199 	}
200 
201 }