use of eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException in project hale by halestudio.
the class StreamGmlWriter method checkCompatibility.
/**
* @see AbstractInstanceWriter#checkCompatibility()
*/
@Override
public void checkCompatibility() throws IOProviderConfigurationException {
super.checkCompatibility();
XmlIndex xmlIndex = getXMLIndex();
if (xmlIndex == null) {
fail("No XML target schema");
}
if (requiresDefaultContainer()) {
XmlElement element;
try {
element = findDefaultContainter(xmlIndex, null);
} catch (Exception e) {
// ignore
element = null;
}
if (element == null) {
fail("Cannot find container element in schema.");
}
}
}
use of eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException in project hale by halestudio.
the class JDBCInstanceWriter method execute.
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
InstanceCollection instances = getInstances();
Connection connection = null;
try {
// connect to the database
try {
connection = getConnection();
} catch (Exception e) {
reporter.error(new IOMessageImpl(e.getLocalizedMessage(), e));
reporter.setSuccess(false);
reporter.setSummary("Failed to connect to database.");
return reporter;
}
if (isWriteUnordered()) {
// write instances as they come in
writeInstances(connection, instances, progress, reporter);
} else {
// write instances based on type order needed for insert
// (to avoid violating constraints)
Set<TypeDefinition> sortedSet = getSortedSchemas(getTargetSchema().getMappingRelevantTypes());
for (TypeDefinition td : sortedSet) {
writeInstances(connection, instances.select(new TypeFilter(td)), progress, reporter);
}
}
reporter.setSuccess(true);
} catch (Exception e) {
reporter.error(new IOMessageImpl(e.getLocalizedMessage(), e));
reporter.setSuccess(false);
reporter.setSummary("Saving instances to database failed.");
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
// ignore
}
}
progress.end();
}
return reporter;
}
use of eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException in project hale by halestudio.
the class SQLSchemaReader method loadFromSource.
@Override
protected Schema loadFromSource(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
DefaultSchema typeIndex = null;
String query = null;
Text text = getParameter(PARAM_SQL).as(Text.class);
if (text != null) {
query = text.getText();
}
if (query == null) {
query = getParameter(PARAM_SQL).as(String.class);
}
if (query == null) {
reporter.setSuccess(false);
reporter.setSummary("No SQL query specified");
return null;
}
String typename = getParameter(PARAM_TYPE_NAME).as(String.class);
if (typename == null) {
reporter.setSuccess(false);
reporter.setSummary("Name of the type that the SQL query should be represented as must be specified");
return null;
}
progress.begin("Read SQL query schema", ProgressIndicator.UNKNOWN);
Connection connection = null;
try {
// connect to the database
try {
connection = getConnection();
} catch (Exception e) {
reporter.error(new IOMessageImpl(e.getLocalizedMessage(), e));
reporter.setSuccess(false);
reporter.setSummary("Failed to connect to database.");
return null;
}
// connection has been created), report a warning message instead
try {
connection.setReadOnly(true);
} catch (SQLException e) {
// ignore
// reporter.warn(new IOMessageImpl(e.getLocalizedMessage(), e));
}
connection.setAutoCommit(false);
// get advisor
JDBCSchemaReaderAdvisor advisor = SchemaReaderAdvisorExtension.getInstance().getAdvisor(connection);
// determine quotes character
@SuppressWarnings("unused") String quotes = determineQuoteString(connection);
// FIXME not actually used here or in JDBC schema reader
URI jdbcURI = getSource().getLocation();
String dbNamespace = determineNamespace(jdbcURI, advisor);
String namespace = NAMESPACE;
SchemaCrawlerOptions options = new SchemaCrawlerOptions();
SchemaInfoLevel level = new SchemaInfoLevel();
level.setTag("hale");
// these are enabled by default, we don't need them (yet)
level.setRetrieveSchemaCrawlerInfo(false);
level.setRetrieveJdbcDriverInfo(false);
level.setRetrieveDatabaseInfo(false);
level.setRetrieveTables(false);
level.setRetrieveTableColumns(false);
level.setRetrieveForeignKeys(false);
// set what we need
level.setRetrieveColumnDataTypes(true);
level.setRetrieveUserDefinedColumnDataTypes(true);
options.setSchemaInfoLevel(level);
if (advisor != null) {
advisor.configureSchemaCrawler(options);
}
final Catalog database = SchemaCrawlerUtility.getCatalog(connection, options);
// create the type index
typeIndex = new DefaultSchema(dbNamespace, jdbcURI);
Statement st = null;
try {
st = JDBCUtil.createReadStatement(connection, 1);
// support project variables
String processedQuery = JDBCUtil.replaceVariables(query, getServiceProvider());
ResultSet result = st.executeQuery(processedQuery);
// the query represents a type
// get the type definition
TypeDefinition type = addTableType(query, namespace, typeIndex, connection, reporter, typename);
ResultsColumns additionalInfo = SchemaCrawlerUtility.getResultColumns(result);
for (final ResultsColumn column : additionalInfo.getColumns()) {
getOrCreateProperty(type, column, namespace, typeIndex, connection, reporter, database);
}
} finally {
if (st != null) {
st.close();
}
}
reporter.setSuccess(true);
} catch (Exception e) {
throw new IOProviderConfigurationException("Failed to read database schema", e);
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
// ignore
}
}
progress.end();
}
return typeIndex;
}
use of eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException in project hale by halestudio.
the class IOWizard method performFinish.
/**
* @see Wizard#performFinish()
*
* @return <code>true</code> if executing the I/O provider was successful
*/
@Override
public boolean performFinish() {
if (getProvider() == null) {
return false;
}
if (!applyConfiguration()) {
return false;
}
// create default report
IOReporter defReport = provider.createReporter();
// validate and execute provider
try {
// validate configuration
provider.validate();
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
URI projectLoc = ps.getLoadLocation() == null ? null : ps.getLoadLocation();
boolean isProjectResource = false;
if (actionId != null) {
// XXX instead move project resource to action?
ActionUI factory = ActionUIExtension.getInstance().findActionUI(actionId);
isProjectResource = factory.isProjectResource();
}
// prevent loading of duplicate resources
if (isProjectResource && provider instanceof ImportProvider && !getProviderFactory().allowDuplicateResource()) {
String currentResource = ((ImportProvider) provider).getSource().getLocation().toString();
URI currentAbsolute = URI.create(currentResource);
if (projectLoc != null && !currentAbsolute.isAbsolute()) {
currentAbsolute = projectLoc.resolve(currentAbsolute);
}
for (IOConfiguration conf : ((Project) ps.getProjectInfo()).getResources()) {
Value otherResourceValue = conf.getProviderConfiguration().get(ImportProvider.PARAM_SOURCE);
if (otherResourceValue == null) {
continue;
}
String otherResource = otherResourceValue.as(String.class);
URI otherAbsolute = URI.create(otherResource);
if (projectLoc != null && !otherAbsolute.isAbsolute()) {
otherAbsolute = projectLoc.resolve(otherAbsolute);
}
String action = conf.getActionId();
// resource is already loaded into the project
if (currentAbsolute.equals(otherAbsolute) && Objects.equal(actionId, action)) {
// check if the resource is loaded with a provider that
// allows duplicates
boolean allowDuplicate = false;
IOProviderDescriptor providerFactory = IOProviderExtension.getInstance().getFactory(conf.getProviderId());
if (providerFactory != null) {
allowDuplicate = providerFactory.allowDuplicateResource();
}
if (!allowDuplicate) {
log.userError("Resource is already loaded. Loading duplicate resources is aborted!");
return false;
}
}
}
}
// enable provider internal caching
if (isProjectResource && provider instanceof CachingImportProvider) {
((CachingImportProvider) provider).setProvideCache();
}
IOReport report = execute(provider, defReport);
if (report != null) {
// add report to report server
ReportService repService = PlatformUI.getWorkbench().getService(ReportService.class);
repService.addReport(report);
// show message to user
if (report.isSuccess()) {
// let advisor handle results
try {
getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Completing operation...", IProgressMonitor.UNKNOWN);
try {
advisor.handleResults(getProvider());
} finally {
monitor.done();
}
}
});
} catch (InvocationTargetException e) {
log.userError("Error processing results:\n" + e.getCause().getLocalizedMessage(), e.getCause());
return false;
} catch (Exception e) {
log.userError("Error processing results:\n" + e.getLocalizedMessage(), e);
return false;
}
// add to project service if necessary
if (isProjectResource)
ps.rememberIO(actionId, getProviderFactory().getIdentifier(), provider);
return true;
} else {
// error message
log.userError(report.getSummary() + "\nPlease see the report for details.");
return false;
}
} else
return true;
} catch (IOProviderConfigurationException e) {
// user feedback
log.userError("Validation of the provider configuration failed:\n" + e.getLocalizedMessage(), e);
return false;
}
}
use of eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException in project hale by halestudio.
the class CityGMLXsltExport method init.
@Override
protected void init(XmlIndex sourceIndex, XmlIndex targetIndex) throws IOProviderConfigurationException {
super.init(sourceIndex, targetIndex);
// scan target schema for CityModel
targetCityModel = findCityModel(targetIndex);
if (targetCityModel != null) {
QName name = targetCityModel.getName();
setParameter(PARAM_ROOT_ELEMENT_NAMESPACE, new ParameterValue(name.getNamespaceURI()));
setParameter(PARAM_ROOT_ELEMENT_NAME, new ParameterValue(name.getLocalPart()));
} else {
throw new IOProviderConfigurationException(MessageFormat.format("Element {0} not found in the target schema.", CITY_MODEL_ELEMENT));
}
// scan source schema for CityModel
sourceCityModel = findCityModel(sourceIndex);
if (sourceCityModel != null) {
// create a custom source context
sourceContext = new CityGMLSourceContext(sourceCityModel);
// TODO copy envelope?
}
}
Aggregations