Search in sources :

Example 91 with IOReport

use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.

the class ArchiveProjectWriter method createProjectArchive.

/**
 * Creates the project archive.
 *
 * @param target {@link OutputStream} to write the archive to
 * @param reporter the reporter to use for the execution report
 * @param progress the progress indicator
 * @return the execution report
 * @throws IOException if an I/O operation fails
 * @throws IOProviderConfigurationException if the I/O provider was not
 *             configured properly
 */
public IOReport createProjectArchive(OutputStream target, IOReporter reporter, ProgressIndicator progress) throws IOException, IOProviderConfigurationException {
    ZipOutputStream zip = new ZipOutputStream(target);
    // all files related to the project are copied into a temporary
    // directory first and then packed into a zip file
    // create temporary directory and project file
    File tempDir = Files.createTempDir();
    File baseFile = new File(tempDir, "project.halex");
    // mark the temporary directory for clean-up if the project is closed
    CleanupService clean = HalePlatform.getService(CleanupService.class);
    if (clean != null) {
        clean.addTemporaryFiles(CleanupContext.PROJECT, tempDir);
    }
    LocatableOutputSupplier<OutputStream> out = new FileIOSupplier(baseFile);
    // false is correct if getParameter is null because false is default
    boolean includeWebresources = getParameter(INCLUDE_WEB_RESOURCES).as(Boolean.class, false);
    SubtaskProgressIndicator subtask = new SubtaskProgressIndicator(progress);
    // save old IO configurations
    List<IOConfiguration> oldResources = new ArrayList<IOConfiguration>();
    for (int i = 0; i < getProject().getResources().size(); i++) {
        // clone all IO configurations to work on different objects
        oldResources.add(getProject().getResources().get(i).clone());
    }
    IOConfiguration config = getProject().getSaveConfiguration();
    if (config == null) {
        config = new IOConfiguration();
    }
    IOConfiguration oldSaveConfig = config.clone();
    // copy resources to the temp directory and update xml schemas
    updateResources(tempDir, includeWebresources, subtask, reporter);
    // update target save configuration of the project
    config.getProviderConfiguration().put(PARAM_TARGET, Value.of(baseFile.toURI().toString()));
    // write project file via XMLProjectWriter
    XMLProjectWriter writer = new XMLProjectWriter();
    writer.setTarget(out);
    writer.setProject(getProject());
    writer.setProjectFiles(getProjectFiles());
    IOReport report = writer.execute(progress, reporter);
    // now after the project with its project files is written, look for the
    // alignment file and update it
    ProjectFileInfo newAlignmentInfo = getAlignmentFile(getProject());
    if (newAlignmentInfo != null) {
        URI newAlignment = tempDir.toURI().resolve(newAlignmentInfo.getLocation());
        XMLAlignmentUpdater.update(new File(newAlignment), newAlignment, includeWebresources, reporter);
    }
    // put the complete temp directory into a zip file
    IOUtils.zipDirectory(tempDir, zip);
    zip.close();
    // the files may not be deleted now as they will be needed if the
    // project is saved again w/o loading it first
    // update the relative resource locations
    LocationUpdater updater = new LocationUpdater(getProject(), out.getLocation());
    // resources are made absolute (else they can't be found afterwards),
    // e.g. when saving the project again before loading it
    updater.updateProject(false);
    // reset the save configurations that has been overridden by the XML
    // project writer
    getProject().setSaveConfiguration(oldSaveConfig);
    if (clean == null) {
        // if no clean service is available, assume the directory is not
        // needed anymore
        FileUtils.deleteDirectory(tempDir);
    }
    return report;
}
Also used : LocationUpdater(eu.esdihumboldt.hale.common.core.io.project.util.LocationUpdater) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) SubtaskProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.SubtaskProgressIndicator) URI(java.net.URI) CleanupService(eu.esdihumboldt.hale.common.core.service.cleanup.CleanupService) ZipOutputStream(java.util.zip.ZipOutputStream) ProjectFileInfo(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) File(java.io.File)

Example 92 with IOReport

use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.

the class FilterTest method simpleSchemaTestECQL.

@Test
public void simpleSchemaTestECQL() 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 FilterGeoECqlImpl("NEV = 'Piritulus'");
        Filter foulfilter = new FilterGeoECqlImpl("HERP = 'DERP'");
        Filter foulfilter1 = new FilterGeoECqlImpl("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 93 with IOReport

use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.

the class FilterTest method loadXMLInstances.

private InstanceCollection loadXMLInstances(URI schemaLocation, URI xmlLocation) throws IOException, IOProviderConfigurationException {
    SchemaReader reader = new XmlSchemaReader();
    reader.setSharedTypes(null);
    reader.setSource(new DefaultInputSupplier(schemaLocation));
    IOReport schemaReport = reader.execute(null);
    assertTrue(schemaReport.isSuccess());
    Schema sourceSchema = reader.getSchema();
    // 
    InstanceReader instanceReader = new XmlInstanceReader();
    instanceReader.setSource(new DefaultInputSupplier(xmlLocation));
    instanceReader.setSourceSchema(sourceSchema);
    IOReport instanceReport = instanceReader.execute(null);
    assertTrue(instanceReport.isSuccess());
    return instanceReader.getInstances();
}
Also used : ShapeInstanceReader(eu.esdihumboldt.hale.io.shp.reader.internal.ShapeInstanceReader) InstanceReader(eu.esdihumboldt.hale.common.instance.io.InstanceReader) GmlInstanceReader(eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader) XmlInstanceReader(eu.esdihumboldt.hale.io.gml.reader.internal.XmlInstanceReader) 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) XmlInstanceReader(eu.esdihumboldt.hale.io.gml.reader.internal.XmlInstanceReader) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport)

Example 94 with IOReport

use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.

the class TestUtil method loadInstances.

/**
 * Loads an instance collection from the specified XML file with the given
 * source types.
 *
 * @param location the URI specifying the location of the xml instance file
 * @param types the type index
 * @return the loaded instance collection
 * @throws IOException if loading the instance failed
 * @throws IOProviderConfigurationException if configuring the instance
 *             reader failed
 */
public static InstanceCollection loadInstances(URI location, Schema types) throws IOProviderConfigurationException, IOException {
    DefaultInputSupplier input = new DefaultInputSupplier(location);
    XmlInstanceReader instanceReader = new XmlInstanceReader();
    instanceReader.setSource(input);
    instanceReader.setSourceSchema(types);
    IOReport report = instanceReader.execute(null);
    assertTrue(report.isSuccess());
    assertTrue("Errors are contained in the report", report.getErrors().isEmpty());
    return instanceReader.getInstances();
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) XmlInstanceReader(eu.esdihumboldt.hale.io.gml.reader.internal.XmlInstanceReader) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport)

Example 95 with IOReport

use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.

the class TestUtil method loadSchema.

/**
 * Loads the specified XML Schema.
 *
 * @param location the URI specifying the location of the schema
 * @return the loaded schema
 * @throws IOProviderConfigurationException if the schema reader
 *             configuration failed
 * @throws IOException if the schema could not be loaded
 */
public static Schema loadSchema(URI location) throws IOProviderConfigurationException, IOException {
    DefaultInputSupplier input = new DefaultInputSupplier(location);
    XmlSchemaReader reader = new XmlSchemaReader();
    reader.setSharedTypes(new DefaultTypeIndex());
    reader.setSource(input);
    reader.validate();
    IOReport report = reader.execute(null);
    assertTrue(report.isSuccess());
    assertTrue("Errors are contained in the report", report.getErrors().isEmpty());
    return reader.getSchema();
}
Also used : DefaultTypeIndex(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeIndex) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) 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