Search in sources :

Example 36 with DefaultInputSupplier

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

the class XLSReaderTest method readXLSInstances.

private InstanceCollection readXLSInstances(String sourceLocation, int sheetIndex, String typeName, boolean skipFirst, Schema sourceSchema) throws Exception {
    InstanceReader instanceReader = new XLSInstanceReader();
    instanceReader.setSource(new DefaultInputSupplier(getClass().getResource(sourceLocation).toURI()));
    instanceReader.setParameter(InstanceTableIOConstants.SHEET_INDEX, Value.of(sheetIndex));
    instanceReader.setParameter(CommonSchemaConstants.PARAM_TYPENAME, Value.of(typeName));
    instanceReader.setParameter(CommonSchemaConstants.PARAM_SKIP_FIRST_LINE, Value.of(skipFirst));
    instanceReader.setSourceSchema(sourceSchema);
    // Test instances
    IOReport report = instanceReader.execute(null);
    assertTrue("Data import was not successfull.", report.isSuccess());
    return instanceReader.getInstances();
}
Also used : InstanceReader(eu.esdihumboldt.hale.common.instance.io.InstanceReader) XLSInstanceReader(eu.esdihumboldt.hale.io.xls.reader.XLSInstanceReader) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) XLSInstanceReader(eu.esdihumboldt.hale.io.xls.reader.XLSInstanceReader) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport)

Example 37 with DefaultInputSupplier

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

the class XmlSchemaReaderTest method testRead_definitive_annotated.

/**
 * Test reading a simple XML schema with an annotated element.
 *
 * @throws Exception if reading the schema fails
 */
@Test
public void testRead_definitive_annotated() throws Exception {
    URI location = getClass().getResource("/testdata/definitive/documentation_ex.xsd").toURI();
    LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
    XmlIndex schema = (XmlIndex) readSchema(input);
    // product element
    XmlElement product = schema.getElements().get(new QName("product"));
    assertNotNull(product);
    assertTrue(product.getDescription().contains("This element represents a product."));
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) QName(javax.xml.namespace.QName) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) URI(java.net.URI) Test(org.junit.Test)

Example 38 with DefaultInputSupplier

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

the class XmlSchemaReaderTest method testRead_definitive_substitution.

/**
 * Test reading a simple XML schema containing substitution groups.
 *
 * @throws Exception if reading the schema fails
 */
@Test
public void testRead_definitive_substitution() throws Exception {
    URI location = getClass().getResource("/testdata/definitive/substgroups.xsd").toURI();
    LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
    XmlIndex schema = (XmlIndex) readSchema(input);
    // shirt element
    XmlElement shirt = schema.getElements().get(new QName("shirt"));
    assertNotNull(shirt);
    assertEquals(new QName("product"), shirt.getSubstitutionGroup());
// TODO extend
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) QName(javax.xml.namespace.QName) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) URI(java.net.URI) Test(org.junit.Test)

Example 39 with DefaultInputSupplier

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

the class XmlSchemaReaderTest method testRead_shiporder_types.

/**
 * Test reading a simple XML schema that uses several custom named types
 *
 * @throws Exception if reading the schema fails
 */
@Test
public void testRead_shiporder_types() throws Exception {
    URI location = getClass().getResource("/testdata/shiporder/shiporder-types.xsd").toURI();
    LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
    XmlIndex schema = (XmlIndex) readSchema(input);
    String ns = "http://www.example.com";
    assertEquals(ns, schema.getNamespace());
    // shiporder element
    Collection<XmlElement> elements = getElementsWithNS(ns, schema.getElements().values());
    assertEquals(1, elements.size());
    XmlElement shiporder = elements.iterator().next();
    testShiporderStructure(shiporder, ns);
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) URI(java.net.URI) Test(org.junit.Test)

Example 40 with DefaultInputSupplier

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

the class XmlSchemaReaderTest method testRead_definitive_groups.

/**
 * Test reading a simple XML schema containing groups and group references.
 *
 * @throws Exception if reading the schema fails
 */
@Test
public void testRead_definitive_groups() throws Exception {
    URI location = getClass().getResource("/testdata/definitive/groups.xsd").toURI();
    LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
    XmlIndex schema = (XmlIndex) readSchema(input);
    // ShirtType
    TypeDefinition shirtType = schema.getType(new QName("ShirtType"));
    assertNotNull(shirtType);
    assertEquals(5, shirtType.getChildren().size());
    Iterator<? extends ChildDefinition<?>> it = shirtType.getChildren().iterator();
    // ProductPropertyGroup
    GroupPropertyDefinition prodGroup = it.next().asGroup();
    // cardinality
    Cardinality cc = prodGroup.getConstraint(Cardinality.class);
    assertEquals(0, cc.getMinOccurs());
    assertEquals(1, cc.getMaxOccurs());
    // name
    assertEquals("ProductPropertyGroup", prodGroup.getName().getLocalPart());
    assertEquals(4, prodGroup.getDeclaredChildren().size());
    Iterator<? extends ChildDefinition<?>> itProd = prodGroup.getDeclaredChildren().iterator();
    // not there any more because it is flattened away
    // // DescriptionGroup
    // GroupPropertyDefinition descGroup = itProd.next().asGroup();
    // assertNotNull(descGroup);
    // // cardinality
    // cc = descGroup.getConstraint(Cardinality.class);
    // assertEquals(1, cc.getMinOccurs());
    // assertEquals(1, cc.getMaxOccurs());
    // 
    // assertEquals(2, descGroup.getDeclaredChildren().size());
    // Iterator<? extends ChildDefinition<?>> itDesc = descGroup.getDeclaredChildren().iterator();
    // description
    PropertyDefinition description = itProd.next().asProperty();
    assertNotNull(description);
    assertEquals("description", description.getName().getLocalPart());
    // comment
    PropertyDefinition comment = itProd.next().asProperty();
    assertNotNull(comment);
    assertEquals("comment", comment.getName().getLocalPart());
    // number
    PropertyDefinition number = itProd.next().asProperty();
    assertNotNull(number);
    assertEquals("number", number.getName().getLocalPart());
    // name
    PropertyDefinition name = itProd.next().asProperty();
    assertNotNull(name);
    assertEquals("name", name.getName().getLocalPart());
    // size
    PropertyDefinition size = it.next().asProperty();
    assertNotNull(size);
    assertEquals("size", size.getName().getLocalPart());
}
Also used : GroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) Cardinality(eu.esdihumboldt.hale.common.schema.model.constraint.property.Cardinality) QName(javax.xml.namespace.QName) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) URI(java.net.URI) GroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) 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