use of eu.esdihumboldt.hale.ui.service.schema.SchemaService in project hale by halestudio.
the class WFSGetFeatureWizard method addPages.
@Override
public void addPages() {
super.addPages();
/**
* Page for specifying the WFS capabilities URL.
*/
AbstractWFSCapabilitiesPage<WFSGetFeatureConfig> capPage = new AbstractWFSCapabilitiesPage<WFSGetFeatureConfig>(this) {
@Override
protected boolean updateConfiguration(WFSGetFeatureConfig configuration, URL capabilitiesUrl, WFSCapabilities capabilities) {
if (capabilities != null && capabilities.getGetFeatureOp() != null) {
WFSOperation op = capabilities.getGetFeatureOp();
configuration.setGetFeatureUri(URI.create(op.getHttpGetUrl()));
configuration.setVersion(capabilities.getVersion());
return true;
}
setErrorMessage("Invalid capabilities or WFS does not support GetFeature KVP");
return false;
}
};
addPage(capPage);
addPage(new AbstractFeatureTypesPage<WFSGetFeatureConfig>(this, capPage, "Please specify the feature types to request") {
private boolean selectAll = false;
@Override
protected void updateState(Set<QName> selected) {
// at least one type must be specified
setPageComplete(!selected.isEmpty());
}
@Override
protected Collection<? extends QName> initialSelection(Set<QName> types) {
// select all by default
if (selectAll) {
return types;
}
return super.initialSelection(types);
}
@Override
protected Set<QName> filterTypes(Set<QName> types) {
// relevant types
if (schemaSpaceID != null) {
SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
if (ss != null) {
Set<QName> relevantElements = new HashSet<>();
SchemaSpace schemas = ss.getSchemas(schemaSpaceID);
for (TypeDefinition type : schemas.getMappingRelevantTypes()) {
XmlElements elms = type.getConstraint(XmlElements.class);
for (XmlElement elm : elms.getElements()) {
relevantElements.add(elm.getName());
}
}
Set<QName> selection = new HashSet<>(types);
selection.retainAll(relevantElements);
// don't filter if we have no match at all
if (!selection.isEmpty()) {
selectAll = true;
return selection;
}
}
}
selectAll = false;
return super.filterTypes(types);
}
@Override
protected boolean updateConfiguration(WFSGetFeatureConfig configuration, Set<QName> selected) {
configuration.getTypeNames().clear();
configuration.getTypeNames().addAll(selected);
return true;
}
});
// bounding box
addPage(new BBOXPage(this, capPage));
// additional params
addPage(new GetFeatureParamsPage(this));
}
use of eu.esdihumboldt.hale.ui.service.schema.SchemaService in project hale by halestudio.
the class SQLSchemaPage method updateState.
private boolean updateState(boolean runQuery) {
boolean typeValid = false;
boolean sqlValid = false;
String error = null;
String message = null;
if (typeName != null) {
// check type name
String type = typeName.getText();
typeValid = type != null && !type.isEmpty();
if (typeValid) {
// check if the name already exists in the source schema
SchemaService schemas = HaleUI.getServiceProvider().getService(SchemaService.class);
if (schemas != null) {
TypeDefinition existing = schemas.getSchemas(SchemaSpaceID.SOURCE).getType(new QName(SQLSchemaReader.NAMESPACE, type));
if (existing != null) {
typeValid = false;
error = "An SQL query with this name already exists";
}
}
// also test for specific characters?
}
}
if (sqlQuery != null) {
// check SQL query
String sql = sqlQuery.getText();
sqlValid = sql != null && !sql.isEmpty();
if (sqlValid) {
String processedQuery;
try {
processedQuery = JDBCUtil.replaceVariables(sql, HaleUI.getServiceProvider());
} catch (Exception e) {
error = e.getLocalizedMessage();
sqlValid = false;
processedQuery = null;
}
// check if processed SQL query can be executed
if (runQuery && processedQuery != null) {
ImportProvider provider = getWizard().getProvider();
if (provider != null && provider instanceof JDBCProvider) {
Connection connection = null;
try {
try {
connection = ((JDBCProvider) provider).getConnection();
} catch (SQLException e) {
sqlValid = false;
error = "Could not establish database connection: " + e.getLocalizedMessage();
}
if (connection != null) {
try {
Statement statement = JDBCUtil.createReadStatement(connection, 1);
try {
ResultSet result = statement.executeQuery(processedQuery);
int columnCount = result.getMetaData().getColumnCount();
if (columnCount <= 0) {
sqlValid = false;
error = "Query result does not have any columns";
} else {
if (columnCount == 1) {
message = "Successfully tested query. It yields a result with a single column.";
} else {
message = MessageFormat.format("Successfully tested query. It yields a result with {0} columns.", columnCount);
}
}
} catch (SQLException e) {
sqlValid = false;
error = "Error querying database: " + e.getMessage();
} finally {
statement.close();
}
} catch (SQLException e) {
sqlValid = false;
error = "Could not create database statement: " + e.getMessage();
}
}
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
// ignore
}
}
}
}
}
}
}
boolean complete = typeValid && sqlValid;
if (complete) {
error = null;
} else if (!typeValid && error == null) {
error = "Please provide a name for the query";
} else if (error == null) {
error = "Please specify the SQL query to use";
}
setMessage(message);
setErrorMessage(error);
setPageComplete(complete);
return complete;
}
use of eu.esdihumboldt.hale.ui.service.schema.SchemaService in project hale by halestudio.
the class AlignmentExportAdvisor method prepareProvider.
/**
* @see AbstractIOAdvisor#prepareProvider(IOProvider)
*/
@Override
public void prepareProvider(AlignmentWriter provider) {
super.prepareProvider(provider);
AlignmentService as = getService(AlignmentService.class);
provider.setAlignment(as.getAlignment());
SchemaService ss = getService(SchemaService.class);
provider.setSourceSchema(ss.getSchemas(SchemaSpaceID.SOURCE));
provider.setTargetSchema(ss.getSchemas(SchemaSpaceID.TARGET));
}
use of eu.esdihumboldt.hale.ui.service.schema.SchemaService in project hale by halestudio.
the class SourceInstanceExportAdvisor method prepareProvider.
/**
* @see IOAdvisor#prepareProvider(IOProvider)
*/
@Override
public void prepareProvider(InstanceWriter provider) {
super.prepareProvider(provider);
// set target schema
SchemaService ss = getService(SchemaService.class);
provider.setTargetSchema(ss.getSchemas(SchemaSpaceID.SOURCE));
// set instances to export
InstanceService is = getService(InstanceService.class);
provider.setInstances(is.getInstances(DataSet.SOURCE));
}
use of eu.esdihumboldt.hale.ui.service.schema.SchemaService in project hale by halestudio.
the class SchemaExportAdvisor method prepareProvider.
@Override
public void prepareProvider(SchemaWriter provider) {
super.prepareProvider(provider);
SchemaService ss = getService(SchemaService.class);
provider.setSchemas(ss.getSchemas(spaceID));
}
Aggregations