package eu.simstadt.nf4j; import java.util.Objects; /** * Import jobs are requests to store, change or delete CityGML models. Every valid import job has an id and a status. * * @author Marcel Bruse */ public class ImportJob extends Job { /** * This constructor forces the job to have a description and a connector instance. Every job which * is created by this constructor will have the status "local", because it is assumed that it has an unsent * description and no job id yet. * * @param connector The job will use this connector to synchronize itself with the nF. * @param descriptor The description of this job. */ public ImportJob(ImportJobDescriptorImpl descriptor, NFConnector connector) { super(descriptor, connector); status = JobStatus.LOCAL; } /** * This constructor forces the job to have a id and a connector instance. Every job which is created by this * constructor will have the status "sent", because it is assumed that the job is already enqueued at the * nF job queue. * * @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 ImportJob(int id, NFConnector connector) { super(id, connector); status = JobStatus.SENT; } /** * 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().requestImportJob(getId()); setStatus(job.getStatus()); } else { throw new 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. * * @param statusCode The nF status code for this job. */ @Override public void setStatusForCode(int statusCode) { switch (statusCode) { case 0: setStatus(JobStatus.READY_TO_RUN); break; case 10: setStatus(JobStatus.RUNNING); break; case 20: setStatus(JobStatus.ERROR); break; case 25: setStatus(JobStatus.WARNING); break; case 30: setStatus(JobStatus.FINISHED); break; case 40: setStatus(JobStatus.APPROVE); break; case 45: setStatus(JobStatus.REJECT); break; case 50: setStatus(JobStatus.APPROVE_RUNNING); break; case 55: setStatus(JobStatus.REJECT_RUNNING); break; case 60: setStatus(JobStatus.APPROVE_REJECT_ERROR); break; case 70: setStatus(JobStatus.APPROVE_REJECT_OK); break; case 80: setStatus(JobStatus.IMPORTED_WARNING); break; default: setStatus(JobStatus.UNKOWN); } } @Override public void send() throws InvalidJobDescriptorException, FailedTransmissionException { connector.sendAndUpdateImportJob(this); } }