Search in sources :

Example 6 with FileIOSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier in project hale by halestudio.

the class SpatiaLiteTestSuite method writeInstances.

/**
 * Writes the provided instances to a SpatiaLite database.
 *
 * @param schema the target schema
 * @param targetFilePath the path to the target database file
 * @param instances the instances to write
 * @throws Exception any exception thrown by
 *             {@link SpatiaLiteInstanceWriter}
 */
public void writeInstances(Schema schema, String targetFilePath, InstanceCollection instances) throws Exception {
    SpatiaLiteInstanceWriter instanceWriter = new SpatiaLiteInstanceWriter();
    instanceWriter.setInstances(instances);
    DefaultSchemaSpace ss = new DefaultSchemaSpace();
    ss.addSchema(schema);
    instanceWriter.setTargetSchema(ss);
    instanceWriter.setTarget(new FileIOSupplier(new File(targetFilePath)));
    // Test instances
    IOReport report = instanceWriter.execute(new LogProgressIndicator());
    assertTrue("Data export was not successfull.", report.isSuccess());
}
Also used : DefaultSchemaSpace(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) LogProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator) File(java.io.File) SpatiaLiteInstanceWriter(eu.esdihumboldt.hale.io.jdbc.spatialite.writer.internal.SpatiaLiteInstanceWriter)

Example 7 with FileIOSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier in project hale by halestudio.

the class SpatiaLiteTestSuite method readSchema.

/**
 * Reads a schema from a SpatiaLite database file.
 *
 * @param sourceFilePath the path to the source database file
 * @return the schema
 * @throws Exception any exception thrown by {@link SpatiaLiteSchemaReader}
 */
public Schema readSchema(String sourceFilePath) throws Exception {
    SpatiaLiteSchemaReader schemaReader = new SpatiaLiteSchemaReader();
    schemaReader.setSource(new FileIOSupplier(new File(sourceFilePath)));
    IOReport report = schemaReader.execute(new LogProgressIndicator());
    assertTrue(report.isSuccess());
    return schemaReader.getSchema();
}
Also used : SpatiaLiteSchemaReader(eu.esdihumboldt.hale.io.jdbc.spatialite.reader.internal.SpatiaLiteSchemaReader) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) LogProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator) File(java.io.File)

Example 8 with FileIOSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier in project hale by halestudio.

the class SpatiaLiteTestSuite method readInstances.

/**
 * Reads instances from from a SpatiaLite database file with the provided
 * schema.
 *
 * @param sourceSchema the schema of the source database
 * @param sourceFilePath the path to the source database file
 * @return the read instances
 * @throws Exception any exception thrown by
 *             {@link SpatiaLiteInstanceReader}
 */
public InstanceCollection readInstances(Schema sourceSchema, String sourceFilePath) throws Exception {
    SpatiaLiteInstanceReader instanceReader = new SpatiaLiteInstanceReader();
    instanceReader.setSource(new FileIOSupplier(new File(sourceFilePath)));
    instanceReader.setSourceSchema(sourceSchema);
    // Test instances
    IOReport report = instanceReader.execute(new LogProgressIndicator());
    assertTrue("Data import was not successfull.", report.isSuccess());
    return instanceReader.getInstances();
}
Also used : SpatiaLiteInstanceReader(eu.esdihumboldt.hale.io.jdbc.spatialite.reader.internal.SpatiaLiteInstanceReader) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) LogProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator) File(java.io.File)

Example 9 with FileIOSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier in project hale by halestudio.

the class ProjectServiceImpl method save.

/**
 * @see ProjectService#save()
 */
@Override
public void save() {
    File projectFile;
    IOConfiguration saveConfig;
    synchronized (this) {
        projectFile = this.projectFile;
        saveConfig = main.getSaveConfiguration();
    }
    if (projectFile != null || canSaveTo(projectLocation)) {
        Collection<IOProviderDescriptor> providers = HaleIO.getProviderFactories(ProjectWriter.class);
        // use configuration from previous save if possible
        if (saveConfig != null) {
            // get provider ...
            ProjectWriter writer = null;
            for (IOProviderDescriptor factory : providers) {
                if (factory.getIdentifier().equals(saveConfig.getProviderId())) {
                    /*
						 * Check if the content type the project was loaded with
						 * is supported for saving.
						 * 
						 * Example for a changed content type: A saved project
						 * archive may have been extracted and the internal XML
						 * project file loaded.
						 */
                    if (projectLoadContentType != null) {
                        if (factory.getSupportedTypes() == null || !factory.getSupportedTypes().contains(projectLoadContentType)) {
                            log.warn("Project cannot be saved with the same settings it was originally saved with, as the content type has changed.");
                            break;
                        }
                    }
                    try {
                        writer = (ProjectWriter) factory.createExtensionObject();
                    } catch (Exception e) {
                        log.error("Could not create project writer", e);
                    }
                }
            }
            if (writer != null) {
                // configure provider
                writer.loadConfiguration(saveConfig.getProviderConfiguration());
                // moved externally)
                if (projectFile != null) {
                    writer.setTarget(new FileIOSupplier(projectFile));
                } else {
                    writer.setTarget(new NoStreamOutputSupplier(projectLocation));
                }
                ListenableFuture<IOReport> result = ProjectResourcesUtil.executeProvider(writer, saveProjectAdvisor, true, null);
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            IOReport report = result.get();
                            if (!report.isSuccess()) {
                                log.userError("The project could not be saved. Please check the report for more details.");
                            }
                        } catch (InterruptedException | ExecutionException e) {
                            log.userError("The project could not be saved.", e);
                        }
                    }
                });
            } else {
                log.info("The project cannot be saved because the format the project was saved with is not available or has changed.");
                // use save as instead
                saveAs();
            }
        } else if (projectFile != null) {
            // use I/O provider and content type mechanisms to try saving
            // the project file
            ProjectWriter writer = HaleIO.findIOProvider(ProjectWriter.class, new FileIOSupplier(projectFile), projectFile.getAbsolutePath());
            if (writer != null) {
                ProjectResourcesUtil.executeProvider(writer, saveProjectAdvisor, null);
            } else {
                log.error("The project cannot be saved because the format is not available.");
                // use save as instead
                saveAs();
            }
        } else {
            saveAs();
        }
    } else {
        saveAs();
    }
}
Also used : IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) ProjectWriter(eu.esdihumboldt.hale.common.core.io.project.ProjectWriter) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) NoStreamOutputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.NoStreamOutputSupplier) ProjectFile(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(java.util.concurrent.ExecutionException)

Example 10 with FileIOSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier in project hale by halestudio.

the class XsltTransformationTest method transformData.

@Override
protected List<Instance> transformData(TransformationExample example) throws Exception {
    // export alignment to XSLT
    XsltExport export = new XsltExport();
    export.setAlignment(example.getAlignment());
    export.setSourceSchema(new DefaultSchemaSpace().addSchema(example.getSourceSchema()));
    export.setTargetSchema(new DefaultSchemaSpace().addSchema(example.getTargetSchema()));
    export.setParameter(XsltExport.PARAM_ROOT_ELEMENT_NAMESPACE, Value.of(example.getTargetContainerNamespace()));
    export.setParameter(XsltExport.PARAM_ROOT_ELEMENT_NAME, Value.of(example.getTargetContainerName()));
    File tempXsltFile = File.createTempFile("xsltest", ".xsl");
    export.setTarget(new FileIOSupplier(tempXsltFile));
    IOReport res = export.execute(new LogProgressIndicator());
    assertTrue("XSLT export not successful", res.isSuccess());
    assertTrue("Errors during XSLT export", res.getErrors().isEmpty());
    // invoke XSLT on source file to produce target
    File target = File.createTempFile("xsltest", ".xml");
    executeXslt(example.getSourceDataInput(), tempXsltFile, target);
    // load target and return instances
    InstanceCollection instances = TestUtil.loadInstances(target.toURI(), example.getTargetSchema());
    List<Instance> list = new ArrayList<Instance>();
    ResourceIterator<Instance> it = instances.iterator();
    try {
        while (it.hasNext()) {
            list.add(it.next());
        }
    } finally {
        it.close();
    }
    // clean up
    tempXsltFile.delete();
    target.delete();
    return list;
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) DefaultSchemaSpace(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace) ArrayList(java.util.ArrayList) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) LogProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator) File(java.io.File)

Aggregations

FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)34 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)22 File (java.io.File)22 LogProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)9 IOException (java.io.IOException)9 IContentType (org.eclipse.core.runtime.content.IContentType)8 URI (java.net.URI)6 AlignmentWriter (eu.esdihumboldt.hale.common.align.io.AlignmentWriter)4 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)4 DefaultSchemaSpace (eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace)4 NullProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.NullProgressIndicator)3 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)3 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)3 InstanceWriter (eu.esdihumboldt.hale.common.instance.io.InstanceWriter)3 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)3 OutputStream (java.io.OutputStream)3 TransformationExample (eu.esdihumboldt.cst.test.TransformationExample)2 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)2 ProjectReader (eu.esdihumboldt.hale.common.core.io.project.ProjectReader)2 Project (eu.esdihumboldt.hale.common.core.io.project.model.Project)2