Search in sources :

Example 51 with DefaultInputSupplier

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

the class CityGMLPropagate method loadCityGML.

private void loadCityGML() throws IOProviderConfigurationException, IOException {
    System.out.println("Loading schema...");
    LocatableInputSupplier<? extends InputStream> schemaIn = new DefaultInputSupplier(context.getSourceSchema());
    SchemaReader schemaReader = HaleIO.findIOProvider(SchemaReader.class, schemaIn, context.getSourceSchema().getPath());
    schemaReader.setSource(schemaIn);
    IOReport report = schemaReader.execute(new NullProgressIndicator());
    if (!report.isSuccess() || !report.getErrors().isEmpty()) {
        throw new IllegalStateException("Failed to load schema");
    }
    cityGMLSource = 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)

Example 52 with DefaultInputSupplier

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

the class CityGMLPropagate method loadProject.

private boolean loadProject() throws IOException {
    final AtomicBoolean success = new AtomicBoolean(true);
    LocatableInputSupplier<? extends InputStream> projectIn = new DefaultInputSupplier(context.getProject());
    ProjectTransformationEnvironment env = new ProjectTransformationEnvironment("sample", projectIn, new ReportHandler() {

        @Override
        public void publishReport(Report<?> report) {
            if (report.isSuccess() && report.getErrors().isEmpty()) {
                System.out.println(report.getSummary());
            } else {
                System.err.println("Error loading project: " + report.getSummary());
                success.set(false);
            }
        }
    });
    if (success.get()) {
        this.sourceSchema = env.getSourceSchema();
        this.targetSchema = env.getTargetSchema();
        this.examples = env.getAlignment();
        return true;
    }
    return false;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) ReportHandler(eu.esdihumboldt.hale.common.core.report.ReportHandler) ProjectTransformationEnvironment(eu.esdihumboldt.hale.common.headless.impl.ProjectTransformationEnvironment)

Example 53 with DefaultInputSupplier

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

the class SkosCodeListTest method readCodeList_WithLanguage.

private CodeList readCodeList_WithLanguage(URI source, final String language) throws Exception {
    SkosCodeListReader reader = new SkosCodeListReader() {

        /**
         * @see eu.esdihumboldt.hale.io.codelist.skos.reader.SkosCodeListReader#getLangauge()
         */
        @Override
        public String getLangauge() {
            return language;
        }
    };
    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) 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 54 with DefaultInputSupplier

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

the class CSVInstanceReaderTest method readCSVInstances.

private InstanceCollection readCSVInstances(String sourceLocation, String typeName, boolean skipFirst, Schema sourceSchema, String seperator, String quote, String escape, String decimal) throws Exception {
    InstanceReader instanceReader = new CSVInstanceReader();
    instanceReader.setSource(new DefaultInputSupplier(getClass().getResource(sourceLocation).toURI()));
    instanceReader.setParameter(CommonSchemaConstants.PARAM_TYPENAME, Value.of(typeName));
    instanceReader.setParameter(CommonSchemaConstants.PARAM_SKIP_FIRST_LINE, Value.of(skipFirst));
    instanceReader.setParameter(CSVSchemaReader.PARAM_SEPARATOR, Value.of(seperator));
    instanceReader.setParameter(CSVSchemaReader.PARAM_QUOTE, Value.of(quote));
    instanceReader.setParameter(CSVSchemaReader.PARAM_ESCAPE, Value.of(escape));
    instanceReader.setParameter(CSVSchemaReader.PARAM_DECIMAL, Value.of(decimal));
    instanceReader.setSourceSchema(sourceSchema);
    // Test instances
    IOReport report = instanceReader.execute(null);
    assertTrue("Data import was not successfull.", report.isSuccess());
    return instanceReader.getInstances();
}
Also used : CSVInstanceReader(eu.esdihumboldt.hale.io.csv.reader.internal.CSVInstanceReader) InstanceReader(eu.esdihumboldt.hale.common.instance.io.InstanceReader) CSVInstanceReader(eu.esdihumboldt.hale.io.csv.reader.internal.CSVInstanceReader) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport)

Example 55 with DefaultInputSupplier

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

the class CSVSchemaReaderTest method testRead4.

/**
 * Test for given property names and property types with point as a decimal
 * divisor
 *
 * @throws Exception the Exception thrown if the test fails
 */
@Test
public void testRead4() throws Exception {
    String props = "A,B,C,D,E";
    CSVSchemaReader schemaReader = new CSVSchemaReader();
    schemaReader.setSource(new DefaultInputSupplier(getClass().getResource("/data/test4-commadecimal.csv").toURI()));
    schemaReader.setParameter(CommonSchemaConstants.PARAM_TYPENAME, Value.of("TestTyp"));
    schemaReader.setParameter(CSVSchemaReader.PARAM_PROPERTY, Value.of(props));
    schemaReader.setParameter(CSVSchemaReader.PARAM_PROPERTYTYPE, Value.of("java.lang.Integer,java.lang.String,java.lang.Float,java.lang.Float,java.lang.String"));
    schemaReader.setParameter(CSVSchemaReader.PARAM_SEPARATOR, Value.of(";"));
    schemaReader.setParameter(CSVSchemaReader.PARAM_QUOTE, null);
    schemaReader.setParameter(CSVSchemaReader.PARAM_ESCAPE, null);
    schemaReader.setParameter(CSVSchemaReader.PARAM_DECIMAL, Value.of(","));
    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(props.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