Search in sources :

Example 1 with WFSGetFeatureStaxReader

use of org.geosdi.geoplatform.support.wfs.feature.reader.WFSGetFeatureStaxReader in project geo-platform by geosdi.

the class FeatureReaderTest method testFeature.

@Test
public void testFeature() throws Exception {
    FileInputStream ff = null;
    try {
        File dftFile = new File(fileDFT);
        ff = new FileInputStream(dftFile);
        List<LayerSchemaDTO> schemas = featureReaderXSD.read(ff);
        Assert.assertNotNull(schemas);
        Assert.assertEquals(1, schemas.size());
        LayerSchemaDTO layerSchema = schemas.get(0);
        Assert.assertNotNull(layerSchema.getTypeName());
        String name = layerSchema.getTypeName().substring(layerSchema.getTypeName().indexOf(":") + 1);
        Assert.assertNotNull(layerSchema.getTargetNamespace());
        Assert.assertNotNull(layerSchema.getGeometry());
        List<AttributeDTO> attributes = layerSchema.getAttributes();
        Assert.assertNotNull(attributes);
        Assert.assertEquals(numAttributes, attributes.size());
        for (AttributeDTO att : attributes) {
            Assert.assertTrue(att.getMinOccurs() >= 0);
            Assert.assertTrue(att.getMaxOccurs() > att.getMinOccurs());
            Assert.assertNotNull(att.getName());
            Assert.assertNotNull(att.getType());
        }
        logger.debug("@@@@@@@@@@@@@@@@@@@@LAYER_SCHEMA : {}", layerSchema);
        WFSGetFeatureStaxReader featureReader = new WFSGetFeatureStaxReader(layerSchema);
        FeatureCollectionDTO fc = featureReader.read(new File(fileGF));
        Assert.assertNotNull(fc);
        Assert.assertNotNull(fc.getTimeStamp());
        Assert.assertEquals(numFeatures, fc.getNumberOfFeatures());
        List<FeatureDTO> features = fc.getFeatures();
        Assert.assertNotNull(features);
        Assert.assertEquals(numFeatures, features.size());
        for (FeatureDTO feature : features) {
            Assert.assertNotNull(feature.getFID());
            Assert.assertTrue(feature.getFID().contains(name));
            Assert.assertNotNull(feature.getGeometry());
            if (numAttributes == 0) {
                Assert.assertTrue(feature.getAttributes().getAttributesMap().isEmpty());
            } else {
                Assert.assertNotNull(feature.getAttributes());
                Map<String, String> fMap = feature.getAttributes().getAttributesMap();
                Assert.assertNotNull(fMap);
                logger.debug("#################FMAP_SIZE : {}\n", fMap.size());
                Assert.assertEquals(numAttributes, fMap.size());
            }
            logger.debug("@@@@@@@@@@@@@@@@@@@@ {} - {}", feature.getFID(), feature.getAttributes());
            logger.debug("GEOMETRY @@@@@@@@@@@@@@@@ : {}", feature.getGeometry());
        }
    } finally {
        if (ff != null) {
            ff.close();
        }
    }
}
Also used : AttributeDTO(org.geosdi.geoplatform.connector.wfs.response.AttributeDTO) WFSGetFeatureStaxReader(org.geosdi.geoplatform.support.wfs.feature.reader.WFSGetFeatureStaxReader) LayerSchemaDTO(org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO) FeatureDTO(org.geosdi.geoplatform.connector.wfs.response.FeatureDTO) File(java.io.File) FileInputStream(java.io.FileInputStream) FeatureCollectionDTO(org.geosdi.geoplatform.connector.wfs.response.FeatureCollectionDTO) Test(org.junit.Test)

Example 2 with WFSGetFeatureStaxReader

use of org.geosdi.geoplatform.support.wfs.feature.reader.WFSGetFeatureStaxReader in project geo-platform by geosdi.

the class WFSGetFeaturesRequestTest method l_percorsiNavetteTest.

@Ignore
@Test
public void l_percorsiNavetteTest() throws Exception {
    String wfsURL = "http://mappe-dpc.protezionecivile.it/gssitdpc/wfs";
    GPWFSConnectorStore serverConnector = WFSConnectorBuilder.newConnector().withServerUrl(new URL(wfsURL)).build();
    QName percorsiNavette = new QName("PianoCampiFlegrei:CF_PercorsiNavette");
    String localPart = percorsiNavette.getLocalPart();
    String name = localPart.substring(localPart.indexOf(":") + 1);
    WFSDescribeFeatureTypeRequest<Schema> request = serverConnector.createDescribeFeatureTypeRequest();
    request.setTypeName(asList(percorsiNavette));
    Schema response = request.getResponse();
    logger.info("#################SCHEMA : {}\n", response);
    LayerSchemaDTO layerSchema = featureReaderXSD.getFeature(response, name);
    if (layerSchema == null) {
        throw new IllegalStateException("The Layer Schema is null.");
    }
    layerSchema.setScope(wfsURL);
    logger.debug("\n\t##################################LAYER_SCHEMA : {}", layerSchema);
    WFSGetFeatureRequest getFeatureRequest = serverConnector.createGetFeatureRequest();
    getFeatureRequest.setTypeName(new QName(layerSchema.getTypeName()));
    getFeatureRequest.setSRS("EPSG:4326");
    getFeatureRequest.setResultType(RESULTS.value());
    getFeatureRequest.setMaxFeatures(valueOf(50));
    logger.debug("@@@@@@@@@@@@@@@@@@REQUEST_AS_STRING : \n{}\n", getFeatureRequest.showRequestAsString());
    InputStream is = getFeatureRequest.getResponseAsStream();
    WFSGetFeatureStaxReader featureReaderStAX = new WFSGetFeatureStaxReader(layerSchema);
    FeatureCollectionDTO featureCollection = featureReaderStAX.read(is);
    if (!featureCollection.isFeaturesLoaded()) {
        featureCollection.setErrorMessage(getFeatureRequest.getResponseAsString());
    }
    JAXBElement<FeatureCollectionDTO> root = new JAXBElement<>(percorsiNavette, FeatureCollectionDTO.class, featureCollection);
    gpJAXBContextBuilder.marshal(root, new File(of(new File(".").getCanonicalPath(), "target", "PercorsiNavette").collect(joining(separator, "", ".xml"))));
    getFeatureRequest.setOutputFormat("json");
    InputStream isJson = getFeatureRequest.getResponseAsStream();
    FeatureCollection featureCollectionJson = JACKSON_SUPPORT.getDefaultMapper().readValue(isJson, FeatureCollection.class);
    JACKSON_SUPPORT.getDefaultMapper().writeValue(new File(of(new File(".").getCanonicalPath(), "target", "PercorsiNavette").collect(joining(separator, "", ".json"))), featureCollectionJson);
}
Also used : GPWFSConnectorStore(org.geosdi.geoplatform.connector.GPWFSConnectorStore) QName(javax.xml.namespace.QName) Schema(org.geosdi.geoplatform.xml.xsd.v2001.Schema) JAXBElement(javax.xml.bind.JAXBElement) WFSGetFeatureRequest(org.geosdi.geoplatform.connector.server.request.WFSGetFeatureRequest) URL(java.net.URL) FeatureCollectionDTO(org.geosdi.geoplatform.connector.wfs.response.FeatureCollectionDTO) WFSGetFeatureStaxReader(org.geosdi.geoplatform.support.wfs.feature.reader.WFSGetFeatureStaxReader) FeatureCollection(org.geojson.FeatureCollection) LayerSchemaDTO(org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with WFSGetFeatureStaxReader

use of org.geosdi.geoplatform.support.wfs.feature.reader.WFSGetFeatureStaxReader in project geo-platform by geosdi.

the class WFSGetFeatureCreateLayerStaxReaderTest method createLayerStaxReaderTest.

@Test
public void createLayerStaxReaderTest() throws Exception {
    WFSGetFeatureStaxReader featureReaderStAX = new WFSGetFeatureStaxReader(createLayerSchema);
    FeatureCollectionDTO featureCollectionDTO = featureReaderStAX.read(getFeatureCreateLayer);
    assertTrue(!(featureCollectionDTO == null));
}
Also used : WFSGetFeatureStaxReader(org.geosdi.geoplatform.support.wfs.feature.reader.WFSGetFeatureStaxReader) FeatureCollectionDTO(org.geosdi.geoplatform.connector.wfs.response.FeatureCollectionDTO) Test(org.junit.Test)

Example 4 with WFSGetFeatureStaxReader

use of org.geosdi.geoplatform.support.wfs.feature.reader.WFSGetFeatureStaxReader in project geo-platform by geosdi.

the class WFSGetFeaturesRequestTest method d_siteTrTest.

@Ignore(value = "Geoserver is Down")
@Test
public void d_siteTrTest() throws Exception {
    String wfsURL = "http://150.145.141.241/geoserver/wfs";
    QName siteTRCom = new QName("cite:tr_com");
    GPWFSConnectorStore serverConnector = WFSConnectorBuilder.newConnector().withServerUrl(new URL(wfsURL)).build();
    WFSDescribeFeatureTypeRequest<Schema> request = serverConnector.createDescribeFeatureTypeRequest();
    request.setTypeName(asList(siteTRCom));
    Schema response = request.getResponse();
    String localPart = siteTRCom.getLocalPart();
    String name = localPart.substring(localPart.indexOf(":") + 1);
    LayerSchemaDTO layerSchema = featureReaderXSD.getFeature(response, name);
    if (layerSchema == null) {
        throw new IllegalStateException("The Layer Schema is null.");
    }
    layerSchema.setScope(wfsURL);
    WFSGetFeatureRequest getFeatureRequest = serverConnector.createGetFeatureRequest();
    getFeatureRequest.setTypeName(new QName(layerSchema.getTypeName()));
    getFeatureRequest.setSRS("EPSG:4326");
    getFeatureRequest.setResultType(RESULTS.value());
    getFeatureRequest.setMaxFeatures(valueOf(50));
    logger.debug("@@@@@@@@@@@@@@@@@@REQUEST_AS_STRING : \n{}\n", getFeatureRequest.showRequestAsString());
    logger.debug("######################RESPONSE_AS_STRING : \n{}\n", getFeatureRequest.formatResponseAsString(2));
    InputStream is = getFeatureRequest.getResponseAsStream();
    WFSGetFeatureStaxReader featureReaderStAX = new WFSGetFeatureStaxReader(layerSchema);
    FeatureCollectionDTO featureCollection = featureReaderStAX.read(is);
    if (!featureCollection.isFeaturesLoaded()) {
        featureCollection.setErrorMessage(getFeatureRequest.getResponseAsString());
    }
    logger.info("###################################FEATURE_COLLECTION : {}\n", featureCollection);
    getFeatureRequest.setGeometryName(layerSchema.getGeometry().getName());
    getFeatureRequest.setBBox(new BBox(10.329274141729897, 44.64877730606194, 10.35673996203874, 44.66831396911103));
    logger.debug("@@@@@@@@@@@@@@@@@@REQUEST_FILTERED_BY_BBOX_AS_STRING : \n{}\n", getFeatureRequest.showRequestAsString());
    logger.debug("######################RESPONSE_FILTERED_BY_BBOX_AS_STRING : \n{}\n", getFeatureRequest.formatResponseAsString(2));
    InputStream si = getFeatureRequest.getResponseAsStream();
    FeatureCollectionDTO featureCollectionByBBOX = featureReaderStAX.read(si);
    if (!featureCollectionByBBOX.isFeaturesLoaded()) {
        featureCollectionByBBOX.setErrorMessage(getFeatureRequest.getResponseAsString());
    }
    logger.info("###################################FEATURE_COLLECTION_BY_BBOX : {}\n", featureCollectionByBBOX);
}
Also used : GPWFSConnectorStore(org.geosdi.geoplatform.connector.GPWFSConnectorStore) QName(javax.xml.namespace.QName) Schema(org.geosdi.geoplatform.xml.xsd.v2001.Schema) WFSGetFeatureRequest(org.geosdi.geoplatform.connector.server.request.WFSGetFeatureRequest) URL(java.net.URL) FeatureCollectionDTO(org.geosdi.geoplatform.connector.wfs.response.FeatureCollectionDTO) WFSGetFeatureStaxReader(org.geosdi.geoplatform.support.wfs.feature.reader.WFSGetFeatureStaxReader) BBox(org.geosdi.geoplatform.gui.shared.bean.BBox) LayerSchemaDTO(org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with WFSGetFeatureStaxReader

use of org.geosdi.geoplatform.support.wfs.feature.reader.WFSGetFeatureStaxReader in project geo-platform by geosdi.

the class WFSGetFeaturesRequestTest method b_statesTest.

// @Ignore(value = "FIX PROBLEM TO RETRIEVE ATTRIBUTES WITHOUT GEOMETRY")
@Test
public void b_statesTest() throws Exception {
    String wfsURL = "http://150.145.141.92/geoserver/wfs";
    GPWFSConnectorStore serverConnector = WFSConnectorBuilder.newConnector().withServerUrl(new URL(wfsURL)).build();
    WFSDescribeFeatureTypeRequest<Schema> request = serverConnector.createDescribeFeatureTypeRequest();
    request.setTypeName(asList(states));
    Schema response = request.getResponse();
    LayerSchemaDTO layerSchema = featureReaderXSD.getFeature(response, statesName);
    if (layerSchema == null) {
        throw new IllegalStateException("The Layer Schema is null.");
    }
    layerSchema.setScope(wfsURL);
    logger.debug("\n\t##################################LAYER_SCHEMA : {}", layerSchema);
    WFSGetFeatureRequest getFeatureRequest = serverConnector.createGetFeatureRequest();
    getFeatureRequest.setTypeName(new QName(layerSchema.getTypeName()));
    getFeatureRequest.setPropertyNames(asList(new String[] { "STATE_NAME", "PERSONS" }));
    getFeatureRequest.setBBox(new BBox(-75.102613, 40.212597, -72.361859, 41.512517));
    getFeatureRequest.setSRS("EPSG:4326");
    getFeatureRequest.setResultType(RESULTS.value());
    getFeatureRequest.setMaxFeatures(valueOf(50));
    logger.debug("\n\t@@@@@@@@@@@@@@@@@@RESPONSE_AS_STRING : {}", getFeatureRequest.getResponseAsString());
    InputStream is = getFeatureRequest.getResponseAsStream();
    WFSGetFeatureStaxReader featureReaderStAX = new WFSGetFeatureStaxReader(layerSchema);
    FeatureCollectionDTO featureCollection = featureReaderStAX.read(is);
    if (!featureCollection.isFeaturesLoaded()) {
        featureCollection.setErrorMessage(getFeatureRequest.getResponseAsString());
    }
    logger.debug("\n\t@@@@@@@@@@@@@@@@@@@@@@@@@@@FEATURE_COLLECTION_DTO : {}", featureCollection.getNumberOfFeatures());
}
Also used : GPWFSConnectorStore(org.geosdi.geoplatform.connector.GPWFSConnectorStore) QName(javax.xml.namespace.QName) Schema(org.geosdi.geoplatform.xml.xsd.v2001.Schema) WFSGetFeatureRequest(org.geosdi.geoplatform.connector.server.request.WFSGetFeatureRequest) URL(java.net.URL) FeatureCollectionDTO(org.geosdi.geoplatform.connector.wfs.response.FeatureCollectionDTO) WFSGetFeatureStaxReader(org.geosdi.geoplatform.support.wfs.feature.reader.WFSGetFeatureStaxReader) BBox(org.geosdi.geoplatform.gui.shared.bean.BBox) LayerSchemaDTO(org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO) Test(org.junit.Test)

Aggregations

WFSGetFeatureStaxReader (org.geosdi.geoplatform.support.wfs.feature.reader.WFSGetFeatureStaxReader)18 FeatureCollectionDTO (org.geosdi.geoplatform.connector.wfs.response.FeatureCollectionDTO)17 Test (org.junit.Test)14 LayerSchemaDTO (org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO)10 URL (java.net.URL)9 QName (javax.xml.namespace.QName)9 WFSGetFeatureRequest (org.geosdi.geoplatform.connector.server.request.WFSGetFeatureRequest)9 GPWFSConnectorStore (org.geosdi.geoplatform.connector.GPWFSConnectorStore)8 Schema (org.geosdi.geoplatform.xml.xsd.v2001.Schema)8 FeatureDTO (org.geosdi.geoplatform.connector.wfs.response.FeatureDTO)6 Ignore (org.junit.Ignore)4 JAXBElement (javax.xml.bind.JAXBElement)3 FeatureCollection (org.geojson.FeatureCollection)3 BBox (org.geosdi.geoplatform.gui.shared.bean.BBox)3 InputStream (java.io.InputStream)2 BasicPreemptiveSecurityConnector (org.geosdi.geoplatform.connector.server.security.BasicPreemptiveSecurityConnector)2 AttributeDTO (org.geosdi.geoplatform.connector.wfs.response.AttributeDTO)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1