Search in sources :

Example 21 with DefaultInputSupplier

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

the class PredefinedSchemaImpl method getLocation.

/**
 * @see eu.esdihumboldt.hale.common.schema.presets.extension.SchemaPreset#getLocation()
 */
@Override
public LocatableInputSupplier<? extends InputStream> getLocation() {
    IConfigurationElement[] children = element.getChildren("uri");
    if (children != null && children.length > 0) {
        IConfigurationElement uri = children[0];
        URI location = URI.create(uri.getAttribute("value"));
        return new DefaultInputSupplier(location);
    }
    return null;
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) URI(java.net.URI)

Example 22 with DefaultInputSupplier

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

the class TestUtil method loadAlignment.

/**
 * Loads the specified alignment. Assumes that its base alignments don't
 * need a location update.
 *
 * @param location the URI specifying the location of the alignment
 * @param sourceTypes the source type index
 * @param targetTypes the target type index
 * @return the loaded alignment
 * @throws Exception if the alignment or other resources could not be loaded
 */
public static Alignment loadAlignment(final URI location, Schema sourceTypes, Schema targetTypes) throws Exception {
    DefaultInputSupplier input = new DefaultInputSupplier(location);
    IOReporter report = new DefaultIOReporter(new Locatable() {

        @Override
        public URI getLocation() {
            return location;
        }
    }, "Load alignment", AlignmentIO.ACTION_LOAD_ALIGNMENT, true);
    Alignment alignment;
    try {
        alignment = CastorAlignmentIO.load(input.getInput(), report, sourceTypes, targetTypes, new PathUpdate(null, null));
    } catch (Exception e) {
        alignment = JaxbAlignmentIO.load(input.getInput(), report, sourceTypes, targetTypes, new PathUpdate(null, null), null, null);
    }
    assertTrue("Errors are contained in the report", report.getErrors().isEmpty());
    return alignment;
}
Also used : DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) URI(java.net.URI) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) Locatable(eu.esdihumboldt.hale.common.core.io.supplier.Locatable)

Example 23 with DefaultInputSupplier

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

the class SkosCodeListTest method readCodeList.

private CodeList readCodeList(URI source) throws Exception {
    CodeListReader reader = new SkosCodeListReader();
    reader.setSource(new DefaultInputSupplier(source));
    IOReport report = reader.execute(new LogProgressIndicator());
    assertTrue(report.isSuccess());
    return reader.getCodeList();
}
Also used : SkosCodeListReader(eu.esdihumboldt.hale.io.codelist.skos.reader.SkosCodeListReader) CodeListReader(eu.esdihumboldt.hale.common.codelist.io.CodeListReader) SkosCodeListReader(eu.esdihumboldt.hale.io.codelist.skos.reader.SkosCodeListReader) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) LogProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)

Example 24 with DefaultInputSupplier

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

the class CSVInstanceReaderTest method readCSVSchema.

private Schema readCSVSchema(String sourceLocation, String typeName, String paramPropertyType, String propertyNames, String seperator, String quote, String escape, String decimal) throws Exception {
    CSVSchemaReader schemaReader = new CSVSchemaReader();
    schemaReader.setSource(new DefaultInputSupplier(getClass().getResource(sourceLocation).toURI()));
    schemaReader.setParameter(CommonSchemaConstants.PARAM_TYPENAME, Value.of(typeName));
    schemaReader.setParameter(CSVSchemaReader.PARAM_PROPERTY, Value.of(propertyNames));
    schemaReader.setParameter(CSVSchemaReader.PARAM_PROPERTYTYPE, Value.of(paramPropertyType));
    schemaReader.setParameter(CSVSchemaReader.PARAM_SEPARATOR, Value.of(seperator));
    schemaReader.setParameter(CSVSchemaReader.PARAM_QUOTE, Value.of(quote));
    schemaReader.setParameter(CSVSchemaReader.PARAM_ESCAPE, Value.of(escape));
    schemaReader.setParameter(CSVSchemaReader.PARAM_DECIMAL, Value.of(decimal));
    IOReport report = schemaReader.execute(new LogProgressIndicator());
    assertTrue(report.isSuccess());
    return schemaReader.getSchema();
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) CSVSchemaReader(eu.esdihumboldt.hale.io.csv.reader.internal.CSVSchemaReader) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) LogProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)

Example 25 with DefaultInputSupplier

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

the class CSVSchemaReaderTest method testRead2.

/**
 * Test for no given property names and property types (using default
 * settings)
 *
 * @throws Exception the Exception thrown if the test fails
 */
@Test
public void testRead2() throws Exception {
    String prop = "Name,Xcoord,Ycoord,id";
    CSVSchemaReader schemaReader = new CSVSchemaReader();
    schemaReader.setSource(new DefaultInputSupplier(getClass().getResource("/data/test1.csv").toURI()));
    schemaReader.setParameter(CommonSchemaConstants.PARAM_TYPENAME, Value.of("TestTyp"));
    schemaReader.setParameter(CSVSchemaReader.PARAM_PROPERTY, null);
    schemaReader.setParameter(CSVSchemaReader.PARAM_PROPERTYTYPE, null);
    schemaReader.setParameter(CSVSchemaReader.PARAM_SEPARATOR, null);
    schemaReader.setParameter(CSVSchemaReader.PARAM_QUOTE, null);
    schemaReader.setParameter(CSVSchemaReader.PARAM_ESCAPE, null);
    IOReport report = schemaReader.execute(new LogProgressIndicator());
    assertTrue(report.isSuccess());
    Schema schema = schemaReader.getSchema();
    assertEquals(1, schema.getMappingRelevantTypes().size());
    TypeDefinition type = schema.getMappingRelevantTypes().iterator().next();
    assertTrue(type.getName().getLocalPart().equals("TestTyp"));
    Iterator<? extends ChildDefinition<?>> it = type.getChildren().iterator();
    while (it.hasNext()) {
        assertTrue(prop.contains(it.next().getName().getLocalPart()));
    }
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) CSVSchemaReader(eu.esdihumboldt.hale.io.csv.reader.internal.CSVSchemaReader) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) LogProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) Test(org.junit.Test)

Aggregations

DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)73 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)34 URI (java.net.URI)30 Test (org.junit.Test)21 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)15 XmlIndex (eu.esdihumboldt.hale.io.xsd.model.XmlIndex)15 IOException (java.io.IOException)13 LogProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)11 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)11 SchemaReader (eu.esdihumboldt.hale.common.schema.io.SchemaReader)10 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)10 XmlSchemaReader (eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader)10 QName (javax.xml.namespace.QName)10 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)9 InstanceReader (eu.esdihumboldt.hale.common.instance.io.InstanceReader)7 CSVSchemaReader (eu.esdihumboldt.hale.io.csv.reader.internal.CSVSchemaReader)7 GmlInstanceReader (eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader)7 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)6 GroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition)6 File (java.io.File)6