Search in sources :

Example 56 with IOReport

use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.

the class OMLReaderTest method loadAlignment.

private static Alignment loadAlignment(URI sourceSchemaLocation, URI targetSchemaLocation, final URI alignmentLocation) throws IOProviderConfigurationException, IOException {
    // load source schema
    Schema source = readXMLSchema(new DefaultInputSupplier(sourceSchemaLocation));
    // load target schema
    Schema target = readXMLSchema(new DefaultInputSupplier(targetSchemaLocation));
    OmlReader reader = new OmlReader();
    reader.setSourceSchema(source);
    reader.setTargetSchema(target);
    reader.setSource(new DefaultInputSupplier(alignmentLocation));
    reader.validate();
    IOReport report = reader.execute(null);
    assertTrue(report.isSuccess());
    return reader.getAlignment();
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) OmlReader(eu.esdihumboldt.hale.io.oml.OmlReader) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport)

Example 57 with IOReport

use of eu.esdihumboldt.hale.common.core.io.report.IOReport 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 58 with IOReport

use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.

the class XLSInstanceWriterTest method testWriteComplexSchema.

/**
 * Test - write data of complex schema and analyze result
 *
 * @throws Exception , if an error occurs
 */
@Test
public void testWriteComplexSchema() throws Exception {
    TransformationExample example = TransformationExamples.getExample(TransformationExamples.SIMPLE_COMPLEX);
    // alternative the data could be generated by iterating through the
    // exempleproject's sourcedata
    List<String> header = Arrays.asList("id", "name", "details.age", "details.income", "details.address.street", "details.address.city");
    List<String> firstDataRow = Arrays.asList("id0", "name0", "age0", "income0", "street0", "city0");
    // set instances to xls instance writer
    XLSInstanceWriter writer = new XLSInstanceWriter();
    IContentType contentType = HalePlatform.getContentTypeManager().getContentType("eu.esdihumboldt.hale.io.xls.xls");
    writer.setParameter(InstanceTableIOConstants.SOLVE_NESTED_PROPERTIES, Value.of(true));
    File tmpFile = tmpFolder.newFile("excelTestWriteComplexSchema.xls");
    writer.setInstances(example.getSourceInstances());
    // write instances to a temporary XLS file
    writer.setTarget(new FileIOSupplier(tmpFile));
    writer.setContentType(contentType);
    IOReport report = writer.execute(null);
    assertTrue(report.isSuccess());
    Workbook wb = WorkbookFactory.create(tmpFile);
    Sheet sheet = wb.getSheetAt(0);
    checkHeader(sheet, header);
    checkSheetName(sheet, "person");
    checkFirstDataRow(sheet, firstDataRow);
}
Also used : XLSInstanceWriter(eu.esdihumboldt.hale.io.xls.writer.XLSInstanceWriter) TransformationExample(eu.esdihumboldt.cst.test.TransformationExample) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) IContentType(org.eclipse.core.runtime.content.IContentType) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) File(java.io.File) Sheet(org.apache.poi.ss.usermodel.Sheet) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Example 59 with IOReport

use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.

the class XmlInstanceValidator method execute.

/**
 * @see AbstractIOProvider#execute(ProgressIndicator, IOReporter)
 */
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    progress.begin("Validating XML", ProgressIndicator.UNKNOWN);
    List<URI> schemaLocations = new ArrayList<URI>();
    for (Locatable schema : getSchemas()) {
        URI loc = schema.getLocation();
        if (loc != null) {
            schemaLocations.add(loc);
        } else {
            reporter.warn(new IOMessageImpl("No location for schema, may cause validation to fail.", null));
        }
    }
    Validator val = ValidatorFactory.getInstance().createValidator(schemaLocations.toArray(new URI[schemaLocations.size()]));
    InputStream in = getSource().getInput();
    try {
        Report report = val.validate(in);
        // use the report information to populate reporter
        for (SAXParseException warning : report.getWarnings()) {
            reporter.warn(new // 
            IOMessageImpl(// 
            warning.getLocalizedMessage(), // 
            warning, // 
            warning.getLineNumber(), warning.getColumnNumber()));
        }
        for (SAXParseException error : report.getErrors()) {
            reporter.error(new // 
            IOMessageImpl(// 
            error.getLocalizedMessage(), // 
            error, // 
            error.getLineNumber(), error.getColumnNumber()));
        }
        reporter.setSuccess(report.isValid());
        return reporter;
    } finally {
        in.close();
        progress.end();
    }
}
Also used : IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) InputStream(java.io.InputStream) SAXParseException(org.xml.sax.SAXParseException) ArrayList(java.util.ArrayList) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) URI(java.net.URI) AbstractInstanceValidator(eu.esdihumboldt.hale.common.instance.io.impl.AbstractInstanceValidator) Locatable(eu.esdihumboldt.hale.common.core.io.supplier.Locatable)

Example 60 with IOReport

use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.

the class XmlSchemaReaderTest method readSchema.

/**
 * Reads a schema
 *
 * @param input the input supplier
 * @return the schema
 * @throws IOProviderConfigurationException if the configuration of the
 *             reader is invalid
 * @throws IOException if reading the schema fails
 */
public static Schema readSchema(LocatableInputSupplier<? extends InputStream> input) throws IOProviderConfigurationException, IOException {
    XmlSchemaReader reader = new XmlSchemaReader();
    // reader.setContentType(XMLSchemaIO.XSD_CT);
    reader.setSharedTypes(new DefaultTypeIndex());
    reader.setSource(input);
    reader.validate();
    IOReport report = reader.execute(null);
    assertTrue(report.isSuccess());
    assertTrue("Errors are contained in the report", report.getErrors().isEmpty());
    return reader.getSchema();
}
Also used : DefaultTypeIndex(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeIndex) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport)

Aggregations

IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)102 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)34 Test (org.junit.Test)33 LogProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)25 List (java.util.List)23 QName (javax.xml.namespace.QName)23 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)22 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)22 HashMap (java.util.HashMap)22 File (java.io.File)14 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)11 XmlSchemaReader (eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader)11 SchemaReader (eu.esdihumboldt.hale.common.schema.io.SchemaReader)10 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)8 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)8 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)8 IOException (java.io.IOException)8 Ignore (org.junit.Ignore)8 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)7 IOReporter (eu.esdihumboldt.hale.common.core.io.report.IOReporter)7