use of eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException in project hale by halestudio.
the class AbstractAppSchemaConfigurator method generateMapping.
/**
* Uses a fresh {@link AppSchemaMappingGenerator} instance to generates the
* mapping configuration based on the current provider's configuration
* parameters.
*
* @param reporter the status reporter
* @throws IOProviderConfigurationException if something is wrong with the
* provider configuration
* @throws IOException if an error occurs loading the mapping template file
*/
public void generateMapping(IOReporter reporter) throws IOProviderConfigurationException, IOException {
if (getAlignment() == null) {
throw new IOProviderConfigurationException("No alignment was provided.");
}
if (getTargetSchema() == null) {
throw new IOProviderConfigurationException("No target schema was provided.");
}
if (getTarget() == null) {
throw new IOProviderConfigurationException("No target was provided.");
}
DataStore dataStoreParam = getDataStoreParameter();
FeatureChaining featureChainingParam = getFeatureChainingParameter();
// resolve property entity definitions here, could't do it on project
// loading
resolvePropertyTypes(featureChainingParam, getTargetSchema(), SchemaSpaceID.TARGET);
WorkspaceConfiguration workspaceConfParam = getWorkspaceConfigurationParameter();
generator = new AppSchemaMappingGenerator(getAlignment(), getTargetSchema(), dataStoreParam, featureChainingParam, workspaceConfParam);
generator.generateMapping(reporter);
}
use of eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException in project hale by halestudio.
the class AbstractCachedSchemaReaderBase method execute.
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
if (validCache(cache) && useCache(cache)) {
reporter.info(new IOMessageImpl("Loading schema from cached result...", null));
schema = loadFromCache(cache, progress, reporter);
} else {
try {
schema = loadFromSource(progress, reporter);
} catch (Exception e) {
reporter.error("Error loading schema from source", e);
if (reporter.isSuccess()) {
reporter.setSuccess(false);
}
}
if (provideCache && schema != null && reporter.isSuccess()) {
try {
cache = storeInCache(schema);
reporter.info(new IOMessageImpl("Created cached schema representation", null));
} catch (Exception e) {
reporter.error(new IOMessageImpl("Failed to create a representation of the schema for caching", e));
// invalidate cache
cache = null;
}
cacheUpdate = true;
}
if (!reporter.isSuccess() && validCache(cache) && useCacheAsFallback()) {
schema = loadFromCache(cache, progress, reporter);
}
}
return reporter;
}
use of eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException in project hale by halestudio.
the class HaleSchemaWriter method execute.
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
progress.begin("Save schema", ProgressIndicator.UNKNOWN);
try (OutputStream out = getTarget().getOutput()) {
// create DOM
NSDOMBuilder builder = SchemaToXml.createBuilder();
Element root = new SchemaToXml().schemasToXml(builder, getSchemas().getSchemas());
// configure transformer for serialization
Transformer transformer = TransformerFactory.newInstance().newTransformer();
// $NON-NLS-1$
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
// $NON-NLS-1$
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
// TODO configurable?!
// $NON-NLS-1$
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
// serialize DOM
DOMSource source = new DOMSource(root);
StreamResult result = new StreamResult(out);
transformer.transform(source, result);
reporter.setSuccess(true);
} catch (Exception e) {
reporter.error(new IOMessageImpl(e.getMessage(), e));
reporter.setSuccess(false);
} finally {
progress.end();
}
return reporter;
}
use of eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException in project hale by halestudio.
the class HaleSchemaReaderJson method execute.
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
progress.begin("Load schema", ProgressIndicator.UNKNOWN);
try (InputStream in = getSource().getInput();
Reader reader = new InputStreamReader(in, getCharset())) {
Iterable<Schema> schemas = new JsonToSchema(null, new OsgiClassResolver(), reporter).parseSchemas(reader);
List<Schema> schemaList = StreamSupport.stream(schemas.spliterator(), false).collect(Collectors.toList());
if (!schemaList.isEmpty()) {
schema = HaleSchemaUtil.combineSchema(schemaList, reporter);
reporter.setSuccess(true);
} else {
reporter.setSuccess(false);
reporter.setSummary("No schema definition found");
}
} catch (Exception e) {
reporter.error(new IOMessageImpl(e.getMessage(), e));
reporter.setSuccess(false);
} finally {
progress.end();
}
return reporter;
}
use of eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException in project hale by halestudio.
the class HaleSchemaWriterJson method execute.
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
progress.begin("Save schema", ProgressIndicator.UNKNOWN);
try (OutputStream out = getTarget().getOutput();
Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8)) {
// create DOM
JsonStreamBuilder builder = new JsonStreamBuilder(writer, true);
new SchemaToJson().schemasToJson(builder, getSchemas().getSchemas(), null);
reporter.setSuccess(true);
} catch (Exception e) {
reporter.error(new IOMessageImpl(e.getMessage(), e));
reporter.setSuccess(false);
} finally {
progress.end();
}
return reporter;
}
Aggregations