use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.
the class ArchiveProjectReader method execute.
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
// copy resources to a temporary directory
tempDir = Files.createTempDir();
IOUtils.extract(tempDir, getSource().getInput());
// create the project file via XMLProjectReader
File baseFile = new File(tempDir, "project.halex");
ProjectReader reader;
if (!baseFile.exists()) {
// look for project file
log.debug("Default project file not found, looking for other candidates.");
String candidate = ProjectIO.findProjectFile(tempDir);
if (candidate != null) {
log.info(MessageFormat.format("Loading {0} as project file from archive", candidate));
baseFile = new File(tempDir, candidate);
}
reader = HaleIO.findIOProvider(ProjectReader.class, new FileIOSupplier(baseFile), candidate);
if (reader == null) {
reporter.error(new IOMessageImpl("Could not find reader for project file " + candidate, null));
reporter.setSuccess(false);
return reporter;
}
} else {
// default project file
reader = new XMLProjectReader();
}
LocatableInputSupplier<InputStream> tempSource = new FileIOSupplier(baseFile);
// save old save configuration
LocatableInputSupplier<? extends InputStream> oldSource = getSource();
setSource(tempSource);
reader.setSource(tempSource);
reader.setProjectFiles(getProjectFiles());
IOReport report = reader.execute(progress);
Project readProject = reader.getProject();
if (readProject != null) {
/*
* Because the original source is only available here, update the
* project's resource paths here.
*
* The only drawback is that the UILocationUpdater cannot be used.
*/
LocationUpdater updater = new LocationUpdater(readProject, tempSource.getLocation());
// update resources
// resources are made absolute (else they can't be found afterwards)
updater.updateProject(false);
}
// set the real source
setSource(oldSource);
// set the read project
setProjectChecked(readProject, reporter);
return report;
}
use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.
the class FilterTest method loadXML.
@Before
public void loadXML() throws Exception {
if (init == false) {
SchemaReader reader = new XmlSchemaReader();
reader.setSharedTypes(null);
reader.setSource(new DefaultInputSupplier((getClass().getResource("/testdata/inspire3/HydroPhysicalWaters.xsd").toURI())));
IOReport report = reader.execute(null);
assertTrue(report.isSuccess());
Schema schema = reader.getSchema();
StreamGmlReader instanceReader = new GmlInstanceReader();
instanceReader.setSource(new DefaultInputSupplier(getClass().getResource("/testdata/out/transformWrite_ERM_HPW.gml").toURI()));
instanceReader.setSourceSchema(schema);
instanceReader.validate();
report = instanceReader.execute(null);
assertTrue(report.isSuccess());
FilterTest.complexinstances = instanceReader.getInstances();
assertFalse(FilterTest.complexinstances.isEmpty());
init = true;
}
}
use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.
the class FilterTest method simpleSchemaTestCQL.
@Test
public void simpleSchemaTestCQL() throws Exception {
ShapeSchemaReader schemaReader = new ShapeSchemaReader();
schemaReader.setSource(new DefaultInputSupplier(getClass().getResource("/testdata/GN_Point/GN_Point.shp").toURI()));
schemaReader.validate();
IOReport report = schemaReader.execute(null);
assertTrue(report.isSuccess());
Schema schema = schemaReader.getSchema();
ShapeInstanceReader instanceReader = new ShapeInstanceReader();
instanceReader.setSource(new DefaultInputSupplier(getClass().getResource("/testdata/GN_Point/GN_Point.shp").toURI()));
instanceReader.setSourceSchema(schema);
instanceReader.validate();
report = instanceReader.execute(null);
assertTrue(report.isSuccess());
InstanceCollection instances = instanceReader.getInstances();
assertFalse(instances.isEmpty());
ResourceIterator<Instance> ri = instances.iterator();
try {
boolean foundIt = false;
boolean stayFalse = false;
boolean stayFalseToo = false;
Filter cqlfilter = new FilterGeoCqlImpl("NEV = 'Piritulus'");
Filter foulfilter = new FilterGeoCqlImpl("HERP = 'DERP'");
Filter foulfilter1 = new FilterGeoCqlImpl("NEV = 'HURR'");
while (ri.hasNext()) {
Instance inst = ri.next();
assertNotNull(inst);
if (cqlfilter.match(inst)) {
foundIt = true;
}
if (foulfilter.match(inst)) {
stayFalse = true;
}
if (foulfilter1.match(inst)) {
stayFalseToo = true;
}
}
assertTrue(foundIt);
assertFalse(stayFalse);
assertFalse(stayFalseToo);
} finally {
ri.close();
}
}
use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.
the class HeadlessIO method executeProvider.
/**
* Execute the given I/O provider with the given I/O advisor.
*
* @param provider the I/O provider
* @param advisor the I/O advisor
* @param progress the progress indicator, may be <code>null</code>
* @param reportHandler the report handler, may be <code>null</code>
* @throws IOException if executing the provider fails
*/
@SuppressWarnings("unchecked")
public static void executeProvider(final IOProvider provider, @SuppressWarnings("rawtypes") final IOAdvisor advisor, ProgressIndicator progress, ReportHandler reportHandler) throws IOException {
IOReporter reporter = provider.createReporter();
ATransaction trans = log.begin(reporter.getTaskName());
try {
// use advisor to configure provider
advisor.prepareProvider(provider);
advisor.updateConfiguration(provider);
// execute
IOReport report = provider.execute(progress);
if (reportHandler != null) {
reportHandler.publishReport(report);
}
// handle results
if (report.isSuccess()) {
advisor.handleResults(provider);
} else {
throw new IOException("Executing I/O provider not successful: " + report.getSummary());
}
} catch (Exception e) {
throw new IOException("Error executing an I/O provider.", e);
} finally {
trans.end();
}
}
use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.
the class HaleConnectProjectReader method execute.
/**
* @see eu.esdihumboldt.hale.common.core.io.project.impl.ArchiveProjectReader#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 {
IOReport result = super.execute(progress, reporter);
if (getSource() instanceof HaleConnectInputSupplier) {
HaleConnectInputSupplier source = (HaleConnectInputSupplier) getSource();
getProject().getProperties().put(HALECONNECT_LAST_MODIFIED_PROPERTY, Value.of(source.getLastModified()));
getProject().getProperties().put(HALECONNECT_URN_PROPERTY, Value.of(source.getLocation()));
IOConfiguration saveConfig = getProject().getSaveConfiguration();
saveConfig.setProviderId(HaleConnectProjectWriter.ID);
saveConfig.getProviderConfiguration().put(ExportProvider.PARAM_CONTENT_TYPE, Value.of(HaleConnectProjectWriter.HALECONNECT_CONTENT_TYPE_ID));
/*
* Don't overwrite the target of the save configuration which is, at
* this point, set to the temporary location of the extracted
* project archive. The reason for this is to make sure that
* PathUpdate can correctly resolve all relative resource paths.
* (https://github.com/halestudio/hale/issues/506)
*/
// saveConfig.getProviderConfiguration().put(ExportProvider.PARAM_TARGET,
// Value.of(source.getLocation()));
getProject().setSaveConfiguration(saveConfig);
}
return result;
}
Aggregations