Search in sources :

Example 1 with GPWFSConnectorStore

use of org.geosdi.geoplatform.connector.GPWFSConnectorStore in project geo-platform by geosdi.

the class GPWFSConnectorBuilderPool method internalBuild.

/**
 * @param key
 * @return {@link GPWFSConnectorStore}
 * @throws Exception
 */
@Override
protected GPWFSConnectorStore internalBuild(@Nonnull(when = NEVER) GPPoolConnectorKey key) throws Exception {
    checkArgument(key != null, "The Parameter key must not be null.");
    GPWFSConnectorStore wfsStore = wfsConnectorPool.borrowObject(key);
    wfsConnectorPool.returnObject(key, wfsStore);
    return wfsStore;
}
Also used : GPWFSConnectorStore(org.geosdi.geoplatform.connector.GPWFSConnectorStore)

Example 2 with GPWFSConnectorStore

use of org.geosdi.geoplatform.connector.GPWFSConnectorStore 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 GPWFSConnectorStore

use of org.geosdi.geoplatform.connector.GPWFSConnectorStore in project geo-platform by geosdi.

the class GPTransactionService method transactionDelete.

/**
 * @param serverURL
 * @param typeName
 * @param fid
 * @param headerParams
 * @return {@link Boolean}
 * @throws Exception
 */
@Override
public boolean transactionDelete(String serverURL, String typeName, String fid, Map<String, String> headerParams) throws Exception {
    Preconditions.checkArgument((serverURL != null) && !(serverURL.isEmpty()), "The Parameter serverURL must not be null or an Empty String.");
    Preconditions.checkArgument((typeName != null) && !(typeName.isEmpty()), "The Parameter typeName must not be null or an Empty String.");
    Preconditions.checkArgument((fid != null) && !(fid.isEmpty()), "The Parameter fid must not be null or an Empty String.");
    logger.debug("\n\n*** WFS Transaction DELETE for Feature '{}' ***", fid);
    if (!typeName.contains(":")) {
        throw new IllegalArgumentException("typeName must contain the char \":\"");
    }
    serverURL = serverURL.replace("wms", "wfs");
    if (!wfsConfigurator.matchDefaultDataSource(serverURL)) {
        throw new ResourceNotFoundFault("Edit Mode cannot be applied to the server with url " + wfsConfigurator.getDefaultWFSDataSource());
    }
    try {
        GPWFSConnectorStore serverConnector = ((headerParams != null) && (headerParams.size() > 0)) ? super.createWFSConnector(serverURL, headerParams) : super.createWFSConnector(serverURL);
        WFSTransactionRequest<TransactionResponseType> request = serverConnector.createTransactionRequest();
        request.setOperation(TransactionOperation.DELETE);
        request.setTypeName(new QName(typeName));
        request.setFID(fid);
        TransactionResponseType response = request.getResponse();
        if (response.getTransactionSummary().getTotalDeleted().intValue() == 1) {
            return TRUE;
        }
    } catch (IOException ex) {
        ex.printStackTrace();
        throw new IllegalStateException("Error to execute the WFS Transacion DELETE for the layer " + typeName + " - fid: " + fid);
    }
    return FALSE;
}
Also used : GPWFSConnectorStore(org.geosdi.geoplatform.connector.GPWFSConnectorStore) QName(javax.xml.namespace.QName) ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault) IOException(java.io.IOException) TransactionResponseType(org.geosdi.geoplatform.xml.wfs.v110.TransactionResponseType)

Example 4 with GPWFSConnectorStore

use of org.geosdi.geoplatform.connector.GPWFSConnectorStore 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 GPWFSConnectorStore

use of org.geosdi.geoplatform.connector.GPWFSConnectorStore 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

GPWFSConnectorStore (org.geosdi.geoplatform.connector.GPWFSConnectorStore)18 QName (javax.xml.namespace.QName)16 WFSGetFeatureRequest (org.geosdi.geoplatform.connector.server.request.WFSGetFeatureRequest)13 URL (java.net.URL)10 LayerSchemaDTO (org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO)10 Schema (org.geosdi.geoplatform.xml.xsd.v2001.Schema)10 Test (org.junit.Test)10 FeatureCollectionDTO (org.geosdi.geoplatform.connector.wfs.response.FeatureCollectionDTO)8 WFSGetFeatureStaxReader (org.geosdi.geoplatform.support.wfs.feature.reader.WFSGetFeatureStaxReader)8 IOException (java.io.IOException)4 FeatureCollection (org.geojson.FeatureCollection)4 Ignore (org.junit.Ignore)4 JAXBElement (javax.xml.bind.JAXBElement)3 BBox (org.geosdi.geoplatform.gui.shared.bean.BBox)3 TransactionResponseType (org.geosdi.geoplatform.xml.wfs.v110.TransactionResponseType)3 BasicPreemptiveSecurityConnector (org.geosdi.geoplatform.connector.server.security.BasicPreemptiveSecurityConnector)2 ResourceNotFoundFault (org.geosdi.geoplatform.exception.ResourceNotFoundFault)2 StringTokenizer (java.util.StringTokenizer)1 QueryDTO (org.geosdi.geoplatform.connector.wfs.response.QueryDTO)1