Search in sources :

Example 11 with XmlElement

use of eu.esdihumboldt.hale.io.xsd.model.XmlElement 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 12 with XmlElement

use of eu.esdihumboldt.hale.io.xsd.model.XmlElement in project hale by halestudio.

the class WFSFeatureCollectionWriter method createFeatureCollectionElement.

private XmlElement createFeatureCollectionElement(WFSVersion version, XmlIndex targetIndex) {
    String wfsNs = version.wfsNamespace;
    XmlElement memberElement = null;
    switch(version) {
        case V1_1_0:
            memberElement = targetIndex.getElements().get(new QName(GMLConstants.NS_GML, "_Feature"));
            break;
        case V2_0_0:
        case V2_0_2:
            for (XmlElement element : targetIndex.getElements().values()) {
                if (element.getName().getLocalPart().equals("AbstractFeature") && element.getName().getNamespaceURI().startsWith(GMLConstants.GML_NAMESPACE_CORE)) {
                    memberElement = element;
                    break;
                }
            }
            break;
    }
    if (memberElement == null) {
        throw new IllegalStateException("Unable to identify member types for feature collection");
    }
    addValidationSchema(version.wfsNamespace, new LocatableURI(version.schemaLocation), "wfs");
    List<XmlElement> memberElements = SubstitutionGroupProperty.collectSubstitutions(memberElement.getName(), memberElement.getType());
    TypeDefinition fcType = WFSSchemaHelper.createFeatureCollectionType(version, memberElements);
    return new XmlElement(new QName(wfsNs, "FeatureCollection"), fcType, null);
}
Also used : LocatableURI(eu.esdihumboldt.hale.common.core.io.supplier.LocatableURI) QName(javax.xml.namespace.QName) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 13 with XmlElement

use of eu.esdihumboldt.hale.io.xsd.model.XmlElement in project hale by halestudio.

the class GmlInstanceCollectionTest method testWVAInstances.

private void testWVAInstances(InstanceCollection instances) {
    String ns = "http://www.esdi-humboldt.org/waterVA";
    String gmlNs = "http://www.opengis.net/gml";
    ResourceIterator<Instance> it = instances.iterator();
    try {
        assertTrue(it.hasNext());
        Instance instance = it.next();
        assertNotNull(instance);
        // check type and element
        TypeDefinition type = instance.getDefinition();
        assertEquals(new QName(ns, "Watercourses_VA_Type"), type.getName());
        XmlElements elements = type.getConstraint(XmlElements.class);
        Collection<? extends XmlElement> elementCollection = elements.getElements();
        assertEquals(1, elementCollection.size());
        XmlElement element = elementCollection.iterator().next();
        assertEquals(new QName(ns, "Watercourses_VA"), element.getName());
        // check instance
        // check a simple property first (FGW_ID)
        Object[] fgwID = instance.getProperty(new QName(ns, "FGW_ID"));
        assertNotNull(fgwID);
        assertEquals(1, fgwID.length);
        assertEquals("81011403", fgwID[0]);
        // the_geom
        Object[] the_geom = instance.getProperty(new QName(ns, "the_geom"));
        assertNotNull(the_geom);
        assertEquals(1, the_geom.length);
        assertTrue(the_geom[0] instanceof Instance);
        // MultiLineString
        Object[] multiLineString = ((Instance) the_geom[0]).getProperty(new QName(gmlNs, "MultiLineString"));
        assertNotNull(multiLineString);
        assertEquals(1, multiLineString.length);
        assertTrue(multiLineString[0] instanceof Instance);
        // TODO the MultiLineString should have a GeometryProperty value
        // with a MultiLineString as geometry and a CRS definition
        // ...getValue()
        // srsName
        Object[] srsName = ((Instance) multiLineString[0]).getProperty(new QName("srsName"));
        assertNotNull(srsName);
        assertEquals(1, srsName.length);
        assertEquals("EPSG:31251", srsName[0].toString());
        // lineStringMember
        Object[] lineStringMember = ((Instance) multiLineString[0]).getProperty(new QName(gmlNs, "lineStringMember"));
        assertNotNull(lineStringMember);
        assertEquals(1, lineStringMember.length);
        assertTrue(lineStringMember[0] instanceof Instance);
        // LineString
        Object[] lineString = ((Instance) lineStringMember[0]).getProperty(new QName(gmlNs, "LineString"));
        assertNotNull(lineString);
        assertEquals(1, lineString.length);
        assertTrue(lineString[0] instanceof Instance);
        // TODO the LineString should have a GeometryProperty value with a
        // LineString as geometry and a CRS definition
        // ...getValue()
        // choice
        Object[] choice_1 = ((Instance) lineString[0]).getProperty(new QName(gmlNs + "/LineStringType", "choice_1"));
        assertNotNull(choice_1);
        assertEquals(1, choice_1.length);
        assertTrue(choice_1[0] instanceof Group);
        // coordinates
        Object[] coordinates = ((Group) choice_1[0]).getProperty(new QName(gmlNs, "coordinates"));
        assertNotNull(coordinates);
        assertEquals(1, coordinates.length);
        assertTrue(coordinates[0] instanceof Instance);
        assertTrue(((Instance) coordinates[0]).getValue().toString().contains("-39799.68820381"));
        // only one instance should be present
        assertFalse(it.hasNext());
    } finally {
        it.close();
    }
}
Also used : Group(eu.esdihumboldt.hale.common.instance.model.Group) XmlElements(eu.esdihumboldt.hale.io.xsd.constraint.XmlElements) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) QName(javax.xml.namespace.QName) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 14 with XmlElement

use of eu.esdihumboldt.hale.io.xsd.model.XmlElement in project hale by halestudio.

the class RootElementPage method updateConfiguration.

/**
 * @see IOWizardPage#updateConfiguration(IOProvider)
 */
@Override
public boolean updateConfiguration(XmlWriterBase provider) {
    ISelection sel = list.getSelection();
    if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
        Object selected = ((IStructuredSelection) sel).getFirstElement();
        if (selected instanceof XmlElement) {
            QName name = ((XmlElement) selected).getName();
            provider.setParameter(StreamGmlWriter.PARAM_ROOT_ELEMENT_NAMESPACE, Value.of(name.getNamespaceURI()));
            provider.setParameter(StreamGmlWriter.PARAM_ROOT_ELEMENT_NAME, Value.of(name.getLocalPart()));
            return true;
        }
    }
    provider.setParameter(StreamGmlWriter.PARAM_ROOT_ELEMENT_NAMESPACE, null);
    provider.setParameter(StreamGmlWriter.PARAM_ROOT_ELEMENT_NAME, null);
    return false;
}
Also used : QName(javax.xml.namespace.QName) ISelection(org.eclipse.jface.viewers.ISelection) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 15 with XmlElement

use of eu.esdihumboldt.hale.io.xsd.model.XmlElement 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.");
        }
    }
}
Also used : XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) XMLStreamException(javax.xml.stream.XMLStreamException) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException) IOException(java.io.IOException) FactoryException(org.opengis.referencing.FactoryException) URISyntaxException(java.net.URISyntaxException) TransformException(org.opengis.referencing.operation.TransformException)

Aggregations

XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)37 QName (javax.xml.namespace.QName)23 XmlIndex (eu.esdihumboldt.hale.io.xsd.model.XmlIndex)16 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)14 XmlElements (eu.esdihumboldt.hale.io.xsd.constraint.XmlElements)12 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)11 URI (java.net.URI)11 Test (org.junit.Test)9 HashSet (java.util.HashSet)7 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)6 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)4 SchemaSpace (eu.esdihumboldt.hale.common.schema.model.SchemaSpace)4 IOException (java.io.IOException)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)3 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)3 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)3 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)3 File (java.io.File)3 ValueList (eu.esdihumboldt.hale.common.core.io.ValueList)2