Search in sources :

Example 96 with Schema

use of com.reprezen.kaizen.oasparser.model3.Schema in project geo-platform by geosdi.

the class WFSGetFeaturesRequestTest method e_generateXMLFilesTest.

@Ignore(value = "Test to Prepare XML Files")
@Test
public void e_generateXMLFilesTest() throws Exception {
    String wfsURL = "http://150.145.141.92/geoserver/wfs";
    QName layerQName = new QName("sf:restricted");
    GPWFSConnectorStore serverConnector = WFSConnectorBuilder.newConnector().withServerUrl(new URL(wfsURL)).build();
    WFSDescribeFeatureTypeRequest<Schema> request = serverConnector.createDescribeFeatureTypeRequest();
    request.setTypeName(asList(layerQName));
    Schema response = request.getResponse();
    String localPart = layerQName.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);
    GPJAXBContextBuilder.newInstance().marshal(layerSchema, new File("./target/LayerSchemaSFRestricted.xml"));
    WFSGetFeatureRequest getFeatureRequest = serverConnector.createGetFeatureRequest();
    getFeatureRequest.setTypeName(new QName(layerSchema.getTypeName()));
    getFeatureRequest.setSRS("EPSG:4326");
    getFeatureRequest.setResultType(RESULTS.value());
    String responseAsString = getFeatureRequest.formatResponseAsString(2);
    try (BufferedWriter writer = Files.newBufferedWriter(Paths.get("./target/GetFeatureSFRestricted.xml"))) {
        writer.write(responseAsString);
    }
}
Also used : GPWFSConnectorStore(org.geosdi.geoplatform.connector.GPWFSConnectorStore) QName(javax.xml.namespace.QName) Schema(org.geosdi.geoplatform.xml.xsd.v2001.Schema) LayerSchemaDTO(org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO) WFSGetFeatureRequest(org.geosdi.geoplatform.connector.server.request.WFSGetFeatureRequest) URL(java.net.URL) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 97 with Schema

use of com.reprezen.kaizen.oasparser.model3.Schema in project geo-platform by geosdi.

the class WFSGetFeaturesRequestTest method h_toppTasmaniaRoadsTest.

@Test
public void h_toppTasmaniaRoadsTest() throws Exception {
    String wfsURL = "http://150.145.141.92/geoserver/wfs";
    QName TASMANIA_ROADS = new QName("http://www.openplans.org/topp", "tasmania_roads", "topp");
    GPWFSConnectorStore serverConnector = WFSConnectorBuilder.newConnector().withServerUrl(new URL(wfsURL)).build();
    WFSDescribeFeatureTypeRequest<Schema> request = serverConnector.createDescribeFeatureTypeRequest();
    request.setTypeName(asList(TASMANIA_ROADS));
    Schema response = request.getResponse();
    LayerSchemaDTO layerSchema = featureReaderXSD.getFeature(response, TASMANIA_ROADS.getLocalPart());
    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());
    // 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.debug("\n\t@@@@@@@@@@@@@@@@@@@@@@@@@@@FEATURE_COLLECTION_DTO : {}", featureCollection);
}
Also used : WFSGetFeatureStaxReader(org.geosdi.geoplatform.support.wfs.feature.reader.WFSGetFeatureStaxReader) GPWFSConnectorStore(org.geosdi.geoplatform.connector.GPWFSConnectorStore) QName(javax.xml.namespace.QName) Schema(org.geosdi.geoplatform.xml.xsd.v2001.Schema) LayerSchemaDTO(org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO) WFSGetFeatureRequest(org.geosdi.geoplatform.connector.server.request.WFSGetFeatureRequest) URL(java.net.URL) FeatureCollectionDTO(org.geosdi.geoplatform.connector.wfs.response.FeatureCollectionDTO) Test(org.junit.Test)

Example 98 with Schema

use of com.reprezen.kaizen.oasparser.model3.Schema in project geo-platform by geosdi.

the class GPDescribeFeatureService method describeFeatureType.

/**
 * @param serverURL
 * @param typeName
 * @param headerParams
 * @return {@link LayerSchemaDTO}
 * @throws Exception
 */
@Override
public LayerSchemaDTO describeFeatureType(String serverURL, String typeName, Map<String, String> headerParams) throws Exception {
    checkArgument((serverURL != null) && !(serverURL.trim().isEmpty()), "The Parameter serverURL must not be null or an empty string.");
    checkArgument((typeName != null) && !(typeName.trim().isEmpty()), "The Parameter typeName must not be null or an empty string.");
    logger.debug("\n*** WFS DescribeFeatureType for layer {} ***", typeName);
    serverURL = serverURL.replace("ows", "wfs").replace("wms", "wfs");
    if (!typeName.contains(":")) {
        throw new IllegalArgumentException("typeName must contain the char \":\"");
    }
    // if (!this.wfsConfigurator.matchDefaultDataSource(serverURL)) {
    // throw new IllegalStateException("Edit Mode cannot be applied to "
    // + "the server with url : " + serverURL);
    // }
    LayerSchemaDTO layerSchema;
    try {
        GPWFSConnectorStore serverConnector = ((headerParams != null) && (headerParams.size() > 0)) ? super.createWFSConnector(serverURL, headerParams) : super.createWFSConnector(serverURL);
        WFSDescribeFeatureTypeRequest<Schema> request = serverConnector.createDescribeFeatureTypeRequest();
        QName qName = new QName(typeName);
        request.setTypeName(Arrays.asList(qName));
        Schema response = request.getResponse();
        String name = typeName.substring(typeName.indexOf(":") + 1);
        layerSchema = GP_FEATURE_SCHEMA_READER.getFeature(response, name);
        if (layerSchema == null) {
            logger.error("\n### The layer \"{}\" isn't a feature ###", typeName);
        } else {
            layerSchema.setScope(serverURL);
        }
    } catch (IOException ex) {
        ex.printStackTrace();
        throw new IllegalStateException("Error to execute the WFS DescribeFeatureType for the layer " + typeName);
    }
    return layerSchema;
}
Also used : GPWFSConnectorStore(org.geosdi.geoplatform.connector.GPWFSConnectorStore) QName(javax.xml.namespace.QName) Schema(org.geosdi.geoplatform.xml.xsd.v2001.Schema) LayerSchemaDTO(org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO) IOException(java.io.IOException)

Example 99 with Schema

use of com.reprezen.kaizen.oasparser.model3.Schema in project java-pubsub by googleapis.

the class SchemaServiceClientTest method createSchemaExceptionTest.

@Test
public void createSchemaExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockSchemaService.addException(exception);
    try {
        ProjectName parent = ProjectName.of("[PROJECT]");
        Schema schema = Schema.newBuilder().build();
        String schemaId = "schemaId-697673060";
        client.createSchema(parent, schema, schemaId);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ProjectName(com.google.pubsub.v1.ProjectName) Schema(com.google.pubsub.v1.Schema) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 100 with Schema

use of com.reprezen.kaizen.oasparser.model3.Schema in project java-pubsub by googleapis.

the class SchemaServiceClientTest method getSchemaTest2.

@Test
public void getSchemaTest2() throws Exception {
    Schema expectedResponse = Schema.newBuilder().setName(SchemaName.of("[PROJECT]", "[SCHEMA]").toString()).setDefinition("definition-1014418093").build();
    mockSchemaService.addResponse(expectedResponse);
    String name = "name3373707";
    Schema actualResponse = client.getSchema(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSchemaService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetSchemaRequest actualRequest = ((GetSchemaRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Schema(com.google.pubsub.v1.Schema) GetSchemaRequest(com.google.pubsub.v1.GetSchemaRequest) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)57 Schema (com.google.pubsub.v1.Schema)38 Schema (org.molgenis.emx2.Schema)38 AbstractMessage (com.google.protobuf.AbstractMessage)16 ByteString (com.google.protobuf.ByteString)16 QName (javax.xml.namespace.QName)16 File (java.io.File)15 URL (java.net.URL)15 Schema (org.geosdi.geoplatform.xml.xsd.v2001.Schema)15 SchemaServiceClient (com.google.cloud.pubsub.v1.SchemaServiceClient)14 ProjectName (com.google.pubsub.v1.ProjectName)14 LayerSchemaDTO (org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO)14 IOException (java.io.IOException)13 StringWriter (java.io.StringWriter)13 Schema (org.oasisopen.odata.csdl.v4.Schema)13 Schema (com.reprezen.kaizen.oasparser.model3.Schema)11 JAXBElement (javax.xml.bind.JAXBElement)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 List (java.util.List)8