1
2
3
4
5
6
7 package org.astrogrid.dataservice.queriers.status;
8
9 import org.astrogrid.query.QueryState;
10 import org.astrogrid.status.DefaultTaskStatus;
11
12 /***
13 * Records the status and past activity of a querier
14 */
15
16 public abstract class QuerierStatus extends DefaultTaskStatus
17 {
18
19
20 /*** A constructor makes a status from a previous status. This means
21 * we can carry previous information along with it
22 *
23 public QuerierStatus(Querier querier) {
24 if ( (querier!= null) && (querier.getStatus() != null)) {
25 //copy in old details to new ones
26 String[] oldDetails = querier.getStatus().getDetails();
27 for (int i=0;i<oldDetails.length;i++) { addDetail(oldDetails[i]); }
28 id = querier.getId();
29 }
30 }
31
32 /** Initial constructor - should only be called by subclasses that form
33 * the beginning of the task status chain (see 'previous')*/
34 protected QuerierStatus() {
35 }
36
37 /*** Constructor from a previous status */
38 protected QuerierStatus(QuerierStatus oldStatus, String newStage) {
39 super(oldStatus, newStage);
40 }
41
42 /*** Returns true if this status should come before the given status */
43 public boolean isBefore(QuerierStatus status)
44 {
45 return this.getState().getOrder() < status.getState().getOrder();
46 }
47
48 /*** Subclasses should return the appropriate enumerated state */
49 public abstract QueryState getState();
50
51 public String toString() {
52 return getState().toString();
53 }
54
55 /*** Returns a full human-readable message string */
56 public String asFullMessage() {
57 StringBuffer s = new StringBuffer(getState().toString()+": "+getMessage()+" ("+getProgressMsg()+")");
58 String[] details = getDetails();
59 for (int i = 0; i < details.length; i++) {
60 s.append("\n"+details[i]);
61 }
62 return s.toString();
63 }
64
65 /*** Start a new progress with the given descriptive note and max value for pos
66 * (leave max -1 if unknown) */
67 public void newProgress(String note, long max) {
68 setProgressText(note);
69 setProgressMax(max);
70 setProgress(-1);
71 }
72
73 /*** Resets the progress message to nothing - ie clears it */
74 public void clearProgress() {
75 newProgress("", -1);
76 }
77
78
79 }
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141