Commit 48a81112 authored by bruse's avatar bruse
Browse files

The prototype for the data connection between SimStadt and novaFACTORY has been completed!

parent b5948448
......@@ -4,12 +4,12 @@
import java.util.List;
/**
* Every instance of this class describes an export or import job for the novaFACTORY. Instances of JobBuilder
* take JobDescriptions and build XML export and import job files out of it.
* Every instance of this class describes an export job for the novaFACTORY. Instances of JobBuilder
* take JobDescriptions and build XML export job files out of it.
*
* @author Marcel Bruse
*/
public class JobDescriptorImpl implements JobDescriptor {
public class ExportJobDescriptor implements JobDescriptor {
private static final String DEFAULT_ACCOUNT = "Habib";
......@@ -332,15 +332,9 @@ public void setXmetadata(String xmetadata) {
}
@Override
public String supportsExportJobVersion() {
public String supportsJobVersion() {
return EXPORT_JOB_VERSION;
}
@Override
public String supportsImportJobVersion() {
// TODO Auto-generated method stub
return null;
}
/**
* Adds a new coordinate to the region polygon. A region polygon is only used for export jobs.
......@@ -396,8 +390,8 @@ public boolean isValid() {
}
}
public static JobDescriptorImpl getDefaultDescriptor() {
JobDescriptorImpl descriptor = new JobDescriptorImpl();
public static ExportJobDescriptor getDefaultDescriptor() {
ExportJobDescriptor descriptor = new ExportJobDescriptor();
descriptor.setInitiator(DEFAULT_INITIATOR);
descriptor.setJobnumber(DEFAULT_JOBNUMBER);
descriptor.setAccount(DEFAULT_ACCOUNT);
......
package eu.simstadt.nf;
import java.io.File;
/**
* Every instance of this class describes an import job for the novaFACTORY. Instances of JobBuilder
* take JobDescriptions and build XML import job files out of it.
*
* @author Marcel Bruse
*/
public class ImportJobDescriptor implements JobDescriptor {
/** The version of the novaFACTORY XML export job format. */
public static final String IMPORT_JOB_VERSION = "1.0.0";
/** The default level on which your CityGML will be stored within the nF. */
public static final String DEFAULT_LEVEL = "GML";
/** The CityGML file which should be imported through a import job. */
private File cityGMLFile;
/** The nF product (Produkt) which will keep our CityGML. */
private String product;
/** The nF leaf (Blatt) of the nF product. */
private String leaf;
/** The nF level (Ebene) of the nF product. */
private String level;
/** The operation to be performed for the feature objects of the CityGML file. */
private String operation;
/**
* @return Returns the nF product which will keep our CityGML.
*/
public String getProduct() {
return product;
}
/**
* Sets the nF product for this import job.
*
* @param product The product of our import job.
*/
public void setProduct(String product) {
this.product = product;
}
/**
* @return Returns the nF leaf of the nF product.
*/
public String getLeaf() {
return leaf;
}
/**
* Sets the nF leaf for the nF product.
*
* @param leaf The leaf for the nF product.
*/
public void setLeaf(String leaf) {
this.leaf = leaf;
}
/**
* @return Returns the level of the product.
*/
public String getLevel() {
return level;
}
/**
* Sets the nF level for the nF product.
*
* @param level The level for the nF product.
*/
public void setLevel(String level) {
this.level = level;
}
/**
* @return Returns the CityGML file which should be imported through a import job.
*/
public File getCityGMLFile() {
return cityGMLFile;
}
/**
* Sets the CityGML file which should be imported through a import job.
*
* @param cityGMLFile The CityGML file which should be imported through a import job.
*/
public void setCityGMLFile(File cityGMLFile) {
this.cityGMLFile = cityGMLFile;
}
/**
* @return Returns the operation which should be conducted for the features of the CityGML file.
*/
public String getOperation() {
return operation;
}
/**
* Sets the operation which should be conducted for the feature objects of the CityGML file.
*
* @param operation The operation which should be conducted for the feature object of the CityGML file.
*/
public void setOperation(String operation) {
this.operation = operation;
}
/**
* @return Returns the supported nF job version. This enables your job builder instance to check if
* the job version is compatible with itself.
*/
@Override
public String supportsJobVersion() {
return IMPORT_JOB_VERSION;
}
/**
* This is just a prototype for presentation purposes.
*/
public static ImportJobDescriptor getDefaultDescriptor() {
ImportJobDescriptor descriptor = new ImportJobDescriptor();
descriptor.setLevel(DEFAULT_LEVEL);
return descriptor;
}
/**
* @return Returns true, if product, leaf, level and CityGML file are present.
*/
public boolean isValid() {
boolean result = true;
if (product.isEmpty()
&& leaf.isEmpty()
&& level.isEmpty()
&& !cityGMLFile.canRead()) {
result = false;
}
return result;
}
}
\ No newline at end of file
package eu.simstadt.nf;
import java.io.File;
/**
* Implementations of JobBuilder build nF import and export jobs using nF's XML job format. There should be
* one implementation for each version of novaFACTORY. The supported version should be returned by
* supportsNFVersion().
*
* @param <T> JobBuilder takes implementations of JobDescriptor in order to populate the XML job.
* @param <I> A import JobDescriptor.
* @param <E> JobBuilder takes implementations of JobDescriptor in order to populate the XML export job.
*
* @author Marcel Bruse
*/
public interface JobBuilder<T extends JobDescriptor> {
public interface JobBuilder<I extends JobDescriptor, E extends JobDescriptor> {
/**
* @return Tells the caller the supported version of novaFACTORY.
......@@ -26,23 +30,21 @@
public String supportsImportJobVersion();
/**
* Builds a XML export job document as a string. This string representation of an export job can be written
* into a file or directly sent to a novaFACTORY server instance by the caller.
* Builds a XML export job document. This file can be sent to a nF server instance by the caller afterwards.
*
* @param jobDescriptor A job descriptor which describes the export job with all its attributes according to
* a valid nF export job DTD.
* @return Returns a XML export job document in a string.
* @return Returns a XML export job document.
*/
public String buildExportJob(T jobDescriptor);
public File buildExportJobFile(E jobDescriptor);
/**
* Builds a XML import job document as a string. This string representation of an import job can be written
* into a file or directly sent to a nF server instance by the caller.
* Builds a zipped import job file. This file can be sent to a nF server instance by the caller afterwards.
*
* @param jobDescriptor A job descriptor which describes the import job with all its attributes according to
* a valid nF import job DTD.
* @return Returns a XML import job document in a string.
* the nF manual.
* @return Returns a zipped import job file.
*/
public String buildImportJob(T jobDescriptor);
public File buildImportJobFile(I jobDescriptor);
}
package eu.simstadt.nf;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
......@@ -30,11 +38,10 @@
/**
* Builds nF import and export jobs using nF's XML job format. Please read the nF manual if you want more
* details about the numerous job attributes listed below.
*
* @param <T> JobBuilder takes implementations of JobDescriptor in order to populate the XML job.
*
* @author Marcel Bruse
*/
public class JobBuilderImpl implements JobBuilder<JobDescriptorImpl> {
public class JobBuilderImpl implements JobBuilder<ImportJobDescriptor, ExportJobDescriptor> {
/** Supported version of the novaFACTORY. */
public static final String NOVA_FACTORY_VERSION = "6.3.1.1";
......@@ -65,8 +72,8 @@ public String supportsImportJobVersion() {
* @return Returns a string representation of the nF export job.
*/
@Override
public String buildExportJob(JobDescriptorImpl jobDescriptor) {
String result = null;
public File buildExportJobFile(ExportJobDescriptor jobDescriptor) {
File result = null;
if (Objects.nonNull(jobDescriptor) && jobDescriptor.isValid()) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
......@@ -205,7 +212,12 @@ public String buildExportJob(JobDescriptorImpl jobDescriptor) {
StreamResult streamResult = new StreamResult(writer);
transformer.transform(new DOMSource(doc), streamResult);
result = writer.toString();
File tempfile = File.createTempFile(jobDescriptor.getProduct() + "_", ".xml");
PrintWriter printWriter = new PrintWriter(tempfile);
printWriter.print(writer.toString());
printWriter.close();
return tempfile;
} catch (ParserConfigurationException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
......@@ -215,6 +227,12 @@ public String buildExportJob(JobDescriptorImpl jobDescriptor) {
} catch (TransformerException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
} catch (FileNotFoundException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
} catch (IOException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
}
return result;
......@@ -296,10 +314,61 @@ private static Element appendRegionPolygon(Document doc, List<Coord> regionPolyg
return polygon;
}
/**
* Builds a zipped import job file. This file can be sent to a nF server instance by the caller afterwards.
*
* @param jobDescriptor A job descriptor which describes the import job with all its attributes according to
* a valid nF import job DTD.
* @return Returns a XML import job document.
*/
@Override
public String buildImportJob(JobDescriptorImpl jobDescriptor) {
// TODO Auto-generated method stub
public File buildImportJobFile(ImportJobDescriptor jobDescriptor) {
try {
// Write the nF start file which triggers and controls the processing of the CityGML file.
String startFilename = jobDescriptor.getProduct() + "_" + jobDescriptor.getLeaf() + ".start";
File startfile = new File(System.getProperty("java.io.tmpdir"), startFilename);
PrintWriter writer = new PrintWriter(startfile);
writer.print(jobDescriptor.getLevel());
writer.close();
// Zip start file and CityGML file
File zippedCityGMLFile = File.createTempFile("nF_Import_", ".zip");
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zippedCityGMLFile));
File cityGMLFile = jobDescriptor.getCityGMLFile();
writeBytesToZipFile(new FileInputStream(cityGMLFile), zos, jobDescriptor.getProduct() + "_"
+ jobDescriptor.getLeaf() + "_"
+ jobDescriptor.getLevel() + ".gml");
writeBytesToZipFile(new FileInputStream(startfile), zos, startFilename);
zos.close();
return zippedCityGMLFile;
} catch (FileNotFoundException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
} catch (IOException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
return null;
}
/**
* Writes a file to the given ZipOutputStream which compresses the file.
*
* @param fis The file input stream to be compressed.
* @param zos The zip output stream.
* @param zipEntry The new zip entry for the file to be compressed.
* @throws IOException You will get some of this, if your streams point to nirvana.
*/
private void writeBytesToZipFile(FileInputStream fis, ZipOutputStream zos, String zipEntry)
throws IOException {
zos.putNextEntry(new ZipEntry(zipEntry));
byte[] b = new byte[1024];
int chunkSize;
while ((chunkSize = fis.read(b)) > 0) {
zos.write(b, 0, chunkSize);
}
fis.close();
}
}
......@@ -9,13 +9,8 @@
public interface JobDescriptor {
/**
* @return The supported version of the XML export job format.
* @return The supported version of the XML import or export job format.
*/
public String supportsExportJobVersion();
/**
* @return The supported version of the XML import job format.
*/
public String supportsImportJobVersion();
public String supportsJobVersion();
}
package eu.simstadt.nf;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;
public class Main {
public static void main(String[] args) {
NFConnector connector = new NFConnectorImpl("193.196.136.164");
ImportJob job = connector.requestImportJob(261);
JobStatus status = job.getStatus();
System.out.println(job.getJobId() + ": " + status + " - " + status.getMessage());
Job job = connector.requestExportJob(566);
System.out.println(job.getJobId() + ": " + job.getStatus() + " - " + job.getStatus().getMessage());
}
}
\ No newline at end of file
......@@ -25,7 +25,7 @@
import eu.simstadt.nf.Coord;
import eu.simstadt.nf.JobBuilderImpl;
import eu.simstadt.nf.JobDescriptor;
import eu.simstadt.nf.JobDescriptorImpl;
import eu.simstadt.nf.ExportJobDescriptor;
import eu.simstadt.nf.Layer;
......@@ -116,11 +116,11 @@ protected String call() throws Exception {
layer.setName("GML");
layer.setProduct("LBTEST");
layer.setStyle("#000000");
JobDescriptorImpl jobDescriptor = JobDescriptorImpl.getDefaultDescriptor();
ExportJobDescriptor jobDescriptor = ExportJobDescriptor.getDefaultDescriptor();
jobDescriptor.addLayer(layer);
jobDescriptor.setRegionPolygon(regionPolygon);
JobBuilderImpl jobBuilder = new JobBuilderImpl();
return jobBuilder.buildExportJob(jobDescriptor);
return jobBuilder.buildExportJobFile(jobDescriptor).getAbsolutePath();
}
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment