ExportJob.java 2.39 KB
Newer Older
1
package eu.simstadt.nf4j;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

import java.util.Objects;

/**
 * Export jobs are requests for CityGML models. Every valid export job has an id and a status.
 * 
 * @author Marcel Bruse
 */
public class ExportJob extends Job {

	/**
	 * Initializes a new export job instance with unknown state. This is a convenient method.
	 * 
	 * @return Returns a new export job instance with unknown state.
	 */
17
	public static ExportJob getNewInstance() {
18
19
20
		return new ExportJob(JobStatus.UNKOWN);
	}
	
21
22
23
24
25
26
27
28
29
30
31
32
33
	/**
	 * Initializes a new export job instance with unknown state and connector instance. This is a 
	 * convenient method.
	 * 
	 * @param The nF connector which answers status requests for this job.
	 * @return Returns a new export job instance with unknown state.
	 */
	public static ExportJob getNewInstance(NFConnector<?, ?> nFConnector) {
		ExportJob result = getNewInstance();
		result.setNFConnector(nFConnector);
		return result;
	}
	
34
35
36
37
38
39
40
41
	/**
	 * This constructor forces the job to have a defined state.
	 * 
	 * @param status
	 */
	public ExportJob(JobStatus status) {
		super(status);
	}
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
	
	/**
	 * Connects to the nF and refreshes the status of this job. If there is no nF connector set,
	 * this operation will throw a FailedTransmissionException.
	 * 
	 * @throws FailedTransmissionException If the connection to the nF is broken you will get some of this. 
	 */
	public void updateStatus() throws FailedTransmissionException {
		if (Objects.nonNull(getNFConnector())) {
			Job job = getNFConnector().requestExportJob(getJobId());
			setStatus(job.getStatus());
		} else {
			throw new FailedTransmissionException();
		}
	}
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

	/**
	 * Sets the status of this job depending on the given nF status code. nF status codes will be sent
	 * to you in http responses.
	 *  
	 * @param statusCode The nF status code for this job.
	 */
	@Override
	public void setStatusForCode(int statusCode) {
		switch (statusCode) {
		case 0:
			setStatus(JobStatus.PENDING); break;
		case 10:
			setStatus(JobStatus.RUNNING); break;
		case 20:
			setStatus(JobStatus.FAILED); break;
		case 30:
			setStatus(JobStatus.FINISHED); break;
		default:
			setStatus(JobStatus.UNKOWN);
		}
	}
	
	/**
	 * @return Returns true, if the job is definitely done. False, otherwise.
	 */
	public boolean isFinished() {
		return Objects.nonNull(getStatus()) && getStatus().equals(JobStatus.FINISHED);
	}
	
}