Search in sources :

Example 1 with SchemaService

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));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) QName(javax.xml.namespace.QName) SchemaSpace(eu.esdihumboldt.hale.common.schema.model.SchemaSpace) WFSOperation(eu.esdihumboldt.hale.io.wfs.capabilities.WFSOperation) AbstractWFSCapabilitiesPage(eu.esdihumboldt.hale.io.wfs.ui.capabilities.AbstractWFSCapabilitiesPage) WFSCapabilities(eu.esdihumboldt.hale.io.wfs.capabilities.WFSCapabilities) URL(java.net.URL) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) XmlElements(eu.esdihumboldt.hale.io.xsd.constraint.XmlElements) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) Collection(java.util.Collection) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement)

Example 2 with SchemaService

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;
}
Also used : JDBCProvider(eu.esdihumboldt.hale.io.jdbc.JDBCProvider) SQLException(java.sql.SQLException) QName(javax.xml.namespace.QName) Statement(java.sql.Statement) Connection(java.sql.Connection) ImportProvider(eu.esdihumboldt.hale.common.core.io.ImportProvider) SQLException(java.sql.SQLException) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) ResultSet(java.sql.ResultSet)

Example 3 with SchemaService

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));
}
Also used : SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService)

Example 4 with SchemaService

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));
}
Also used : SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) InstanceService(eu.esdihumboldt.hale.ui.service.instance.InstanceService)

Example 5 with SchemaService

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));
}
Also used : SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService)

Aggregations

SchemaService (eu.esdihumboldt.hale.ui.service.schema.SchemaService)29 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)8 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)4 SchemaSpace (eu.esdihumboldt.hale.common.schema.model.SchemaSpace)3 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)2 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)2 StyledDefinitionLabelProvider (eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider)2 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)2 EntityDefinitionService (eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService)2 EntityTypeIndexContentProvider (eu.esdihumboldt.hale.ui.service.entity.util.EntityTypeIndexContentProvider)2 EntityTypeIndexHierarchy (eu.esdihumboldt.hale.ui.service.entity.util.EntityTypeIndexHierarchy)2 TreePathProviderAdapter (eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathProviderAdapter)2 QName (javax.xml.namespace.QName)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 GridData (org.eclipse.swt.layout.GridData)2 Label (org.eclipse.swt.widgets.Label)2 EntityAccessor (eu.esdihumboldt.hale.common.align.groovy.accessor.EntityAccessor)1 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)1