Search in sources :

Example 1 with CSVSchemaReader

use of eu.esdihumboldt.hale.io.csv.reader.internal.CSVSchemaReader 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 2 with CSVSchemaReader

use of eu.esdihumboldt.hale.io.csv.reader.internal.CSVSchemaReader 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)

Example 3 with CSVSchemaReader

use of eu.esdihumboldt.hale.io.csv.reader.internal.CSVSchemaReader in project hale by halestudio.

the class CSVSchemaReaderTest method testRead3.

/**
 * 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 testRead3() throws Exception {
    String props = "A,B,C,D,E";
    CSVSchemaReader schemaReader = new CSVSchemaReader();
    schemaReader.setSource(new DefaultInputSupplier(getClass().getResource("/data/test3-pointdecimal.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)

Example 4 with CSVSchemaReader

use of eu.esdihumboldt.hale.io.csv.reader.internal.CSVSchemaReader in project hale by halestudio.

the class CSVSchemaReaderTest method testRead.

/**
 * Test for given property names and property types
 *
 * @throws Exception the Exception thrown if the test fails
 */
@Test
public void testRead() throws Exception {
    String props = "muh,kuh,bla,blub";
    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, Value.of(props));
    schemaReader.setParameter(CSVSchemaReader.PARAM_PROPERTYTYPE, Value.of("java.lang.String,java.lang.String,java.lang.String,java.lang.String"));
    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(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)

Example 5 with CSVSchemaReader

use of eu.esdihumboldt.hale.io.csv.reader.internal.CSVSchemaReader 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

LogProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)7 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)7 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)7 CSVSchemaReader (eu.esdihumboldt.hale.io.csv.reader.internal.CSVSchemaReader)7 Test (org.junit.Test)5 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)4 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)4