Search in sources :

Example 46 with IOReport

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;
}
Also used : Project(eu.esdihumboldt.hale.common.core.io.project.model.Project) LocationUpdater(eu.esdihumboldt.hale.common.core.io.project.util.LocationUpdater) InputStream(java.io.InputStream) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) File(java.io.File) ProjectReader(eu.esdihumboldt.hale.common.core.io.project.ProjectReader)

Example 47 with IOReport

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;
    }
}
Also used : XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) ShapeSchemaReader(eu.esdihumboldt.hale.io.shp.reader.internal.ShapeSchemaReader) SchemaReader(eu.esdihumboldt.hale.common.schema.io.SchemaReader) XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) StreamGmlReader(eu.esdihumboldt.hale.io.gml.reader.internal.StreamGmlReader) GmlInstanceReader(eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader) Before(org.junit.Before)

Example 48 with IOReport

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();
    }
}
Also used : ShapeInstanceReader(eu.esdihumboldt.hale.io.shp.reader.internal.ShapeInstanceReader) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) MutableInstance(eu.esdihumboldt.hale.common.instance.model.MutableInstance) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) DefaultInstance(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance) Filter(eu.esdihumboldt.hale.common.instance.model.Filter) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) ShapeSchemaReader(eu.esdihumboldt.hale.io.shp.reader.internal.ShapeSchemaReader) Test(org.junit.Test)

Example 49 with IOReport

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();
    }
}
Also used : IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) ATransaction(de.fhg.igd.slf4jplus.ATransaction) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) IOException(java.io.IOException) IOException(java.io.IOException)

Example 50 with IOReport

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;
}
Also used : IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) HaleConnectInputSupplier(eu.esdihumboldt.hale.io.haleconnect.HaleConnectInputSupplier) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport)

Aggregations

IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)102 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)34 Test (org.junit.Test)33 LogProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)25 List (java.util.List)23 QName (javax.xml.namespace.QName)23 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)22 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)22 HashMap (java.util.HashMap)22 File (java.io.File)14 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)11 XmlSchemaReader (eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader)11 SchemaReader (eu.esdihumboldt.hale.common.schema.io.SchemaReader)10 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)8 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)8 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)8 IOException (java.io.IOException)8 Ignore (org.junit.Ignore)8 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)7 IOReporter (eu.esdihumboldt.hale.common.core.io.report.IOReporter)7