Search in sources :

Example 1 with SchemaReader

use of eu.esdihumboldt.hale.common.schema.io.SchemaReader in project hale by halestudio.

the class GmlInstanceCollectionTest method loadInstances.

private GmlInstanceCollection loadInstances(URI schemaLocation, URI xmlLocation, boolean restrictToFeatures, boolean ignoreNamespace) 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();
    return new GmlInstanceCollection(new DefaultInputSupplier(xmlLocation), sourceSchema, restrictToFeatures, false, true, ignoreNamespace, null, reader);
}
Also used : SchemaReader(eu.esdihumboldt.hale.common.schema.io.SchemaReader) XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) 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)

Example 2 with SchemaReader

use of eu.esdihumboldt.hale.common.schema.io.SchemaReader in project hale by halestudio.

the class AbstractHandlerTest method loadXMLInstances.

/**
 * Load an instance collection from a GML file.
 *
 * @param schemaLocation the GML application schema location
 * @param xmlLocation the GML file location
 * @param interpolConfig the interpolation configuration
 * @return the instance collection
 * @throws IOException if reading schema or instances failed
 * @throws IOProviderConfigurationException if the I/O providers were not
 *             configured correctly
 */
public static InstanceCollection loadXMLInstances(URI schemaLocation, URI xmlLocation, @Nullable ReaderConfiguration interpolConfig) 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 GmlInstanceReader();
    instanceReader.setSource(new DefaultInputSupplier(xmlLocation));
    instanceReader.setSourceSchema(sourceSchema);
    if (interpolConfig != null) {
        interpolConfig.apply(instanceReader);
    }
    IOReport instanceReport = instanceReader.execute(null);
    assertTrue(instanceReport.isSuccess());
    return instanceReader.getInstances();
}
Also used : InstanceReader(eu.esdihumboldt.hale.common.instance.io.InstanceReader) GmlInstanceReader(eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader) XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) 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) GmlInstanceReader(eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader)

Example 3 with SchemaReader

use of eu.esdihumboldt.hale.common.schema.io.SchemaReader 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 4 with SchemaReader

use of eu.esdihumboldt.hale.common.schema.io.SchemaReader in project hale by halestudio.

the class AppSchemaFileWriterTest method loadTestProject.

@BeforeClass
public static void loadTestProject() {
    try {
        URL archiveLocation = AppSchemaFileWriterTest.class.getResource(PROJECT_LOCATION);
        ArchiveProjectReader projectReader = new ArchiveProjectReader();
        projectReader.setSource(new DefaultInputSupplier(archiveLocation.toURI()));
        IOReport report = projectReader.execute(new LogProgressIndicator());
        if (!report.isSuccess()) {
            throw new RuntimeException("project reader execution failed");
        }
        tempDir = projectReader.getTemporaryFiles().iterator().next();
        project = projectReader.getProject();
        assertNotNull(project);
        sourceSchemaSpace = new DefaultSchemaSpace();
        targetSchemaSpace = new DefaultSchemaSpace();
        // load schemas
        List<IOConfiguration> resources = project.getResources();
        for (IOConfiguration resource : resources) {
            String actionId = resource.getActionId();
            String providerId = resource.getProviderId();
            // get provider
            IOProvider provider = null;
            IOProviderDescriptor descriptor = IOProviderExtension.getInstance().getFactory(providerId);
            if (descriptor == null) {
                throw new RuntimeException("Could not load I/O provider with ID: " + resource.getProviderId());
            }
            provider = descriptor.createExtensionObject();
            provider.loadConfiguration(resource.getProviderConfiguration());
            prepareProvider(provider, project, tempDir.toURI());
            IOReport providerReport = provider.execute(new LogProgressIndicator());
            if (!providerReport.isSuccess()) {
                throw new RuntimeException("I/O provider execution failed");
            }
            // TODO: could (should?) be done by an advisor
            if (provider instanceof SchemaReader) {
                Schema schema = ((SchemaReader) provider).getSchema();
                if (actionId.equals(SchemaIO.ACTION_LOAD_SOURCE_SCHEMA)) {
                    sourceSchemaSpace.addSchema(schema);
                } else if (actionId.equals(SchemaIO.ACTION_LOAD_TARGET_SCHEMA)) {
                    targetSchemaSpace.addSchema(schema);
                }
            }
        }
        // load alignment
        List<ProjectFileInfo> projectFiles = project.getProjectFiles();
        for (ProjectFileInfo projectFile : projectFiles) {
            if (projectFile.getName().equals(AlignmentIO.PROJECT_FILE_ALIGNMENT)) {
                AlignmentReader alignReader = new JaxbAlignmentReader();
                alignReader.setSource(new DefaultInputSupplier(projectFile.getLocation()));
                alignReader.setSourceSchema(sourceSchemaSpace);
                alignReader.setTargetSchema(targetSchemaSpace);
                alignReader.setPathUpdater(new PathUpdate(null, null));
                IOReport alignReport = alignReader.execute(new LogProgressIndicator());
                if (!alignReport.isSuccess()) {
                    throw new RuntimeException("alignment reader execution failed");
                }
                alignment = alignReader.getAlignment();
                assertNotNull(alignment);
                break;
            }
        }
    } catch (Exception e) {
        log.error("Exception occurred", e);
        fail("Test project could not be loaded: " + e.getMessage());
    }
}
Also used : JaxbAlignmentReader(eu.esdihumboldt.hale.common.align.io.impl.JaxbAlignmentReader) AlignmentReader(eu.esdihumboldt.hale.common.align.io.AlignmentReader) JaxbAlignmentReader(eu.esdihumboldt.hale.common.align.io.impl.JaxbAlignmentReader) SchemaReader(eu.esdihumboldt.hale.common.schema.io.SchemaReader) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) DefaultSchemaSpace(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) LogProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator) URL(java.net.URL) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) ZipException(java.util.zip.ZipException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ArchiveProjectReader(eu.esdihumboldt.hale.common.core.io.project.impl.ArchiveProjectReader) ProjectFileInfo(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo) PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) IOProvider(eu.esdihumboldt.hale.common.core.io.IOProvider) BeforeClass(org.junit.BeforeClass)

Example 5 with SchemaReader

use of eu.esdihumboldt.hale.common.schema.io.SchemaReader in project hale by halestudio.

the class GenerateDefaults method loadSchema.

private void loadSchema() throws IOProviderConfigurationException, IOException {
    System.out.println("Loading schema...");
    LocatableInputSupplier<? extends InputStream> schemaIn = new DefaultInputSupplier(context.getSchema());
    SchemaReader schemaReader = HaleIO.findIOProvider(SchemaReader.class, schemaIn, context.getSchema().getPath());
    schemaReader.setSource(schemaIn);
    IOReport report = schemaReader.execute(new NullProgressIndicator());
    if (!report.isSuccess() || !report.getErrors().isEmpty()) {
        throw new IllegalStateException("Failed to load schema");
    }
    schema = schemaReader.getSchema();
}
Also used : SchemaReader(eu.esdihumboldt.hale.common.schema.io.SchemaReader) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) NullProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.NullProgressIndicator)

Aggregations

IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)10 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)10 SchemaReader (eu.esdihumboldt.hale.common.schema.io.SchemaReader)10 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)8 XmlSchemaReader (eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader)7 GmlInstanceReader (eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader)6 InstanceReader (eu.esdihumboldt.hale.common.instance.io.InstanceReader)4 NullProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.NullProgressIndicator)2 StreamGmlReader (eu.esdihumboldt.hale.io.gml.reader.internal.StreamGmlReader)2 XmlInstanceReader (eu.esdihumboldt.hale.io.gml.reader.internal.XmlInstanceReader)2 ShapeSchemaReader (eu.esdihumboldt.hale.io.shp.reader.internal.ShapeSchemaReader)2 AlignmentReader (eu.esdihumboldt.hale.common.align.io.AlignmentReader)1 JaxbAlignmentReader (eu.esdihumboldt.hale.common.align.io.impl.JaxbAlignmentReader)1 IOProvider (eu.esdihumboldt.hale.common.core.io.IOProvider)1 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)1 PathUpdate (eu.esdihumboldt.hale.common.core.io.PathUpdate)1 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)1 LogProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)1 ArchiveProjectReader (eu.esdihumboldt.hale.common.core.io.project.impl.ArchiveProjectReader)1 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)1