use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.
the class CSVInstanceWriter method execute.
/**
* @see eu.esdihumboldt.hale.common.core.io.impl.AbstractIOProvider#execute(eu.esdihumboldt.hale.common.core.io.ProgressIndicator,
* eu.esdihumboldt.hale.common.core.io.report.IOReporter)
*/
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
boolean solveNestedProperties = getParameter(InstanceTableIOConstants.SOLVE_NESTED_PROPERTIES).as(Boolean.class, false);
// XXX what does "solve nested properties" mean?
// get separation, quote and escape sign
sep = CSVUtil.getSep(this);
quote = CSVUtil.getQuote(this);
esc = CSVUtil.getEscape(this);
List<String> headerRow = new ArrayList<String>();
// get the parameter to get the type definition
String exportType = getParameter(InstanceTableIOConstants.EXPORT_TYPE).as(String.class);
QName selectedTypeName = null;
if (exportType != null && !exportType.equals("") && !exportType.equals(" ")) {
selectedTypeName = QName.valueOf(exportType);
}
// get all instances of the selected Type
InstanceCollection instances = getInstanceCollection(selectedTypeName);
Iterator<Instance> instanceIterator = instances.iterator();
Instance instance = null;
try {
instance = instanceIterator.next();
} catch (NoSuchElementException e) {
reporter.error(new IOMessageImpl("There are no instances for the selected type.", e));
return reporter;
}
// get definition of current instance (only this properties with this
// definition type will be written to csv file)
TypeDefinition definition = instance.getDefinition();
// first csv file doesn't have a header row, so it' necessary to write
// it to a temp directory
File tempDir = Files.createTempDir();
File tempFile = new File(tempDir, "tempInstances.csv");
// write instances to csv file (without header)
CSVWriter writer = new CSVWriter(new OutputStreamWriter(new FileOutputStream(tempFile)), sep, quote, esc);
writeLine(solveNestedProperties, headerRow, instance, writer);
while (instanceIterator.hasNext()) {
Instance nextInst = instanceIterator.next();
if (nextInst.getDefinition().equals(definition)) {
writeLine(solveNestedProperties, headerRow, nextInst, writer);
}
}
writer.close();
// header is only finished if all properties have been processed
// insert header to temp file and write it to output
insertHeader(tempFile, getTarget().getOutput(), headerRow);
FileUtils.deleteDirectory(tempDir);
reporter.setSuccess(true);
return reporter;
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.
the class LineStringHandlerTest method testLineStringGml2_Grid.
/**
* Test linestring geometries read from a GML 2 file
*
* @throws Exception if an error occurs
*/
@Test
public void testLineStringGml2_Grid() throws Exception {
InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(getClass().getResource("/data/gml/geom-gml2.xsd").toURI(), getClass().getResource("/data/linestring/sample-linestring-gml2.xml").toURI(), gridConfig);
// three instances expected
ResourceIterator<Instance> it = instances.iterator();
try {
// 1. LineStringProperty with LineString defined through coordinates
assertTrue("First sample feature missing", it.hasNext());
Instance instance = it.next();
checkSingleGeometry(instance, gridChecker);
// 2. LineStringProperty with LineString defined through coord
assertTrue("Second sample feature missing", it.hasNext());
instance = it.next();
checkSingleGeometry(instance, gridChecker);
// 3. LineStringProperty with LineString defined through coord
assertTrue("Third sample feature missing", it.hasNext());
instance = it.next();
checkSingleGeometry(instance, gridChecker);
} finally {
it.close();
}
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.
the class LineStringHandlerTest method testLineStringGml31_Grid.
/**
* Test linestring geometries read from a GML 3.1 file
*
* @throws Exception if an error occurs
*/
@Test
public void testLineStringGml31_Grid() throws Exception {
InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(getClass().getResource("/data/gml/geom-gml31.xsd").toURI(), getClass().getResource("/data/linestring/sample-linestring-gml31.xml").toURI(), gridConfig);
// five instances expected
ResourceIterator<Instance> it = instances.iterator();
try {
// 1. LineStringProperty with LineString defined through coordinates
assertTrue("First sample feature missing", it.hasNext());
Instance instance = it.next();
checkSingleGeometry(instance, gridChecker);
// 2. LineStringProperty with LineString defined through coord
assertTrue("Second sample feature missing", it.hasNext());
instance = it.next();
checkSingleGeometry(instance, gridChecker);
// 3. LineStringProperty with LineString defined through pos
assertTrue("Third sample feature missing", it.hasNext());
instance = it.next();
checkSingleGeometry(instance, gridChecker);
// 4. LineStringProperty with LineString defined through pointRep
assertTrue("Fourth sample feature missing", it.hasNext());
instance = it.next();
checkSingleGeometry(instance, gridChecker);
// 5. LineStringProperty with LineString defined through
// pointProperty
assertTrue("Fifth sample feature missing", it.hasNext());
instance = it.next();
checkSingleGeometry(instance, gridChecker);
// 6. LineStringProperty with LineString defined through posList
assertTrue("Sixth sample feature missing", it.hasNext());
instance = it.next();
checkSingleGeometry(instance, gridChecker);
} finally {
it.close();
}
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.
the class LineStringHandlerTest method testLineStringGml2.
/**
* Test linestring geometries read from a GML 2 file
*
* @throws Exception if an error occurs
*/
@Test
public void testLineStringGml2() throws Exception {
InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(getClass().getResource("/data/gml/geom-gml2.xsd").toURI(), getClass().getResource("/data/linestring/sample-linestring-gml2.xml").toURI());
// three instances expected
ResourceIterator<Instance> it = instances.iterator();
try {
// 1. LineStringProperty with LineString defined through coordinates
assertTrue("First sample feature missing", it.hasNext());
Instance instance = it.next();
checkSingleGeometry(instance, checker);
// 2. LineStringProperty with LineString defined through coord
assertTrue("Second sample feature missing", it.hasNext());
instance = it.next();
checkSingleGeometry(instance, checker);
// 3. LineStringProperty with LineString defined through coord
assertTrue("Third sample feature missing", it.hasNext());
instance = it.next();
checkSingleGeometry(instance, checker);
} finally {
it.close();
}
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.
the class LineStringHandlerTest method testLineStringGml3.
/**
* Test linestring geometries read from a GML 3 file
*
* @throws Exception if an error occurs
*/
@Test
public void testLineStringGml3() throws Exception {
InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(getClass().getResource("/data/gml/geom-gml3.xsd").toURI(), getClass().getResource("/data/linestring/sample-linestring-gml3.xml").toURI());
// five instances expected
ResourceIterator<Instance> it = instances.iterator();
try {
// 1. LineStringProperty with LineString defined through coordinates
assertTrue("First sample feature missing", it.hasNext());
Instance instance = it.next();
checkSingleGeometry(instance, checker);
// 2. LineStringProperty with LineString defined through coord
assertTrue("Second sample feature missing", it.hasNext());
instance = it.next();
checkSingleGeometry(instance, checker);
// 3. GeometryProperty with LineString defined through coord
assertTrue("Third sample feature missing", it.hasNext());
instance = it.next();
checkSingleGeometry(instance, checker);
// 4. LineStringProperty with LineString defined through pos
assertTrue("Fourth sample feature missing", it.hasNext());
instance = it.next();
checkSingleGeometry(instance, checker);
// 5. LineStringProperty with LineString defined through pointRep
assertTrue("Fifth sample feature missing", it.hasNext());
instance = it.next();
checkSingleGeometry(instance, checker);
} finally {
it.close();
}
}
Aggregations