package eu.simstadt.nf4j; /** * This job class bundles the three attributes of every nF job: Id, status and last job related nF (error) message. * * @author Marcel Bruse */ public abstract class Job { /** The status of the job. There are different states for export and import jobs. */ protected JobStatus status; /** Every job should have a (valid) job descriptor. */ protected D descriptor; /** The id of the job. */ protected int id; /** The connection to the nF. */ protected NFConnector connector; /** * This constructor forces the job to have a description and a connector instance. * * @param connector The job will use this connector to synchronize itself with the nF. * @param descriptor The description of this job. */ public Job(D descriptor, NFConnector connector) { this.descriptor = descriptor; this.connector = connector; } /** * This constructor forces the job to have a id and a connector instance. * * @param id The job id. If you call updateStatus() and the nF "knows" the job id, then the job status * will be updated. If you call updateStatus() and the job id is "unkown" on the server side, then * @param connector The job will use this connector to synchronize itself with the nF. */ public Job(int id, NFConnector connector) { this.id = id; this.connector = connector; } /** * Every job has it's status. Look up the different possible values in the JobStatus enumeration. * * @return Returns the status of this job. */ public JobStatus getStatus() { return status; } /** * Lets you set the status of this job. * * @param status The status of this job. */ protected void setStatus(JobStatus status) { this.status = status; } /** * @return Returns the description of this job. */ public D getDescriptor() { return descriptor; } /** * @return Returns the id of this job. */ public int getId() { return id; } /** * Sets the id of this job. * * @param jobId The job id about to be set. */ public void setId(int jobId) { this.id = jobId; } /** * @return Returns the nF connector of this job. */ public NFConnector getNFConnector() { return connector; } /** * Sets the nF connector of this job. * * @param nFConnector The connector of this job. */ public void setNFConnector(NFConnector nFConnector) { this.connector = nFConnector; } /** * This method reads the job description, builds a job file from it and uses the connector to send the * job file to nF. You may want to implement the file building and file sending parts in the * connector in order to reuse them here. * * This method is a object oriented convenience method for NFConnector.sendXXXJobFile(). It is sensible * to have this convenience method, because it offers the API user centralized controls over the jobs * status chain without switching between job instances and connector instances. In the end, the user is * not interested in the connection to the nF, but in the job itself. */ public abstract void send() throws InvalidJobDescriptorException, FailedTransmissionException; /** * Connects to the nF and refreshes the status of this job. If there is no nF connector set, or the job id * is unkown by the nF, then this operation will throw a FailedTransmissionException. * * @throws FailedTransmissionException If the connection to the nF is broken you will get some of this. */ public abstract void updateStatus() throws FailedTransmissionException; /** * Sets the status of this job depending on the given nF status code. nF status codes will be sent * to you in http responses. Export jobs and import jobs have different states. Consider this fact * in your implementation. * * @param statusCode The nF status code for this job. */ public abstract void setStatusForCode(int statusCode); }