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();
}
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();
}
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);
}
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();
}
}
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();
}
Aggregations