[mapguide-commits] r9572 - sandbox/jng/wfs_hits/Web/src/HttpHandler

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri Jul 12 07:37:43 PDT 2019


Author: jng
Date: 2019-07-12 07:37:42 -0700 (Fri, 12 Jul 2019)
New Revision: 9572

Modified:
   sandbox/jng/wfs_hits/Web/src/HttpHandler/HttpResourceStrings.cpp
   sandbox/jng/wfs_hits/Web/src/HttpHandler/HttpResourceStrings.h
   sandbox/jng/wfs_hits/Web/src/HttpHandler/HttpWfsGetFeature.cpp
   sandbox/jng/wfs_hits/Web/src/HttpHandler/WfsGetFeatureParams.cpp
   sandbox/jng/wfs_hits/Web/src/HttpHandler/WfsGetFeatureParams.h
Log:
Initial attempt to support reusltType=hits for WFS. The response format is currently not the expected WFS response. We just want to see the placeholder response first with resultType=hits. We fix the response format to the expected WFS response format afterwards.

Modified: sandbox/jng/wfs_hits/Web/src/HttpHandler/HttpResourceStrings.cpp
===================================================================
--- sandbox/jng/wfs_hits/Web/src/HttpHandler/HttpResourceStrings.cpp	2019-07-12 13:47:29 UTC (rev 9571)
+++ sandbox/jng/wfs_hits/Web/src/HttpHandler/HttpResourceStrings.cpp	2019-07-12 14:37:42 UTC (rev 9572)
@@ -326,6 +326,7 @@
 const STRING MgHttpResourceStrings::reqWfsBbox = L"BBOX";
 const STRING MgHttpResourceStrings::reqWfsOutputFormat = L"OUTPUTFORMAT";
 const STRING MgHttpResourceStrings::reqWfsSortBy = L"SORTBY";
+const STRING MgHttpResourceStrings::reqWfsResultType = L"RESULTTYPE";
 
 // Web Application Parameters
 const STRING MgHttpResourceStrings::reqFormat = L"FORMAT";

Modified: sandbox/jng/wfs_hits/Web/src/HttpHandler/HttpResourceStrings.h
===================================================================
--- sandbox/jng/wfs_hits/Web/src/HttpHandler/HttpResourceStrings.h	2019-07-12 13:47:29 UTC (rev 9571)
+++ sandbox/jng/wfs_hits/Web/src/HttpHandler/HttpResourceStrings.h	2019-07-12 14:37:42 UTC (rev 9572)
@@ -237,6 +237,7 @@
     static const STRING reqWfsBbox;
     static const STRING reqWfsOutputFormat;
     static const STRING reqWfsSortBy;
+    static const STRING reqWfsResultType;
 
     // PREDEFINED WEB APPLICATION REQUEST PARAMETERS
     static const STRING reqFormat;

Modified: sandbox/jng/wfs_hits/Web/src/HttpHandler/HttpWfsGetFeature.cpp
===================================================================
--- sandbox/jng/wfs_hits/Web/src/HttpHandler/HttpWfsGetFeature.cpp	2019-07-12 13:47:29 UTC (rev 9571)
+++ sandbox/jng/wfs_hits/Web/src/HttpHandler/HttpWfsGetFeature.cpp	2019-07-12 14:37:42 UTC (rev 9572)
@@ -300,41 +300,71 @@
                                 numFeaturesToRetrieve = limit;
                             }
 
-                            // Call the C++ API
-                            // NOTE: I updated the maxFeatures value from numFeaturesToRetrieve to numFeaturesToRetrieve-1
-                            // Because the MgServerFdoFeatureReader in MapGuide server uses -1 to mark empty, while MgWfsFeatures
-                            // in MapGuide web tier uses 0
-
-                            //For GeoJSON, use the new GetWfsReader API
-                            if (sOutputFormat == MgMimeType::Json)
+                            // Is this hit mode? If so, just request the raw total
+                            if (m_getFeatureParams->IsHitMode())
                             {
-                                // NOTE: This API doesn't accept WFS version, format and XML namepaces because these are GML-isms baked into the GetWfsFeature API itself, making
-                                // it unsuitable for non-GML output, hence the need for this new GetWfsReader API
-                                Ptr<MgFeatureReader> fr = featureService->GetWfsReader(featureSourceId, ((sSchemaHash.size() == 0) ? sClass : sSchemaHash + _(":") + sClass),
-                                    requiredProperties, m_getFeatureParams->GetSrs(), filter, sSortCriteria);
-                                
-                                //MgByteSource owns this and will clean it up when done
-                                MgReaderByteSourceImpl* bsImpl = new MgReaderByteSourceImpl(fr, MgMimeType::Json, true, false, -1, NULL);
-                                bsImpl->SetMaxFeatures(numFeaturesToRetrieve - 1);
-                                Ptr<MgByteSource> bs = new MgByteSource(bsImpl);
-                                resultReader = bs->GetReader();
+                                INT32 total = featureService->GetWfsFeatureTotal(featureSourceId, ((sSchemaHash.size() == 0) ? sClass : sSchemaHash + _(":") + sClass), sSortCriteria, numFeaturesToRetrieve);
+                                std::string sTotal;
+                                MgUtil::Int32ToString(total, sTotal);
+                                if (sOutputFormat == MgMimeType::Json)
+                                {
+                                    std::string json = "{";
+                                    json += "\"total\": ";
+                                    json += sTotal;
+                                    json += "}"; 
+                                    Ptr<MgByteSource> bs = new MgByteSource((BYTE_ARRAY_IN)json.data(), json.length());
+                                    bs->SetMimeType(MgMimeType::Json);
+                                    resultReader = bs->GetReader();
+                                }
+                                else
+                                {
+                                    std::string xml = "<test>";
+                                    xml += "total is: ";
+                                    xml += sTotal;
+                                    xml += "</test>";
+                                    Ptr<MgByteSource> bs = new MgByteSource((BYTE_ARRAY_IN)xml.data(), xml.length());
+                                    bs->SetMimeType(MgMimeType::Xml);
+                                    resultReader = bs->GetReader();
+                                }
                             }
-                            else 
+                            else
                             {
                                 // Call the C++ API
                                 // NOTE: I updated the maxFeatures value from numFeaturesToRetrieve to numFeaturesToRetrieve-1
                                 // Because the MgServerFdoFeatureReader in MapGuide server uses -1 to mark empty, while MgWfsFeatures
                                 // in MapGuide web tier uses 0
-                                resultReader = featureService->GetWfsFeature(featureSourceId, ((sSchemaHash.size() == 0) ? sClass : sSchemaHash + _(":") + sClass),
-                                    requiredProperties, m_getFeatureParams->GetSrs(), filter, numFeaturesToRetrieve - 1, sVersion, sOutputFormat, sSortCriteria, sPrefix, oFeatureTypes.GetNamespaceUrl());
 
-                                // Store the MgByteReader directly for retrieval
-                                //
-                                // DO NOT PASS THROUGH OGC XML TEMPLATE PROCESSING CODE!
-                                // DO NOT PASS GO!
-                                // DO NOT COLLECT MEMORY SPIKES NEEDLESSLY BUFFERING XML TEMPLATE CONTENT AS A RESULT!
-                                //
-                                // This *is* already the WFS GetFeature response. There is nothing to post-process through the XML templates!
+                                //For GeoJSON, use the new GetWfsReader API
+                                if (sOutputFormat == MgMimeType::Json)
+                                {
+                                    // NOTE: This API doesn't accept WFS version, format and XML namepaces because these are GML-isms baked into the GetWfsFeature API itself, making
+                                    // it unsuitable for non-GML output, hence the need for this new GetWfsReader API
+                                    Ptr<MgFeatureReader> fr = featureService->GetWfsReader(featureSourceId, ((sSchemaHash.size() == 0) ? sClass : sSchemaHash + _(":") + sClass),
+                                        requiredProperties, m_getFeatureParams->GetSrs(), filter, sSortCriteria);
+
+                                    //MgByteSource owns this and will clean it up when done
+                                    MgReaderByteSourceImpl* bsImpl = new MgReaderByteSourceImpl(fr, MgMimeType::Json, true, false, -1, NULL);
+                                    bsImpl->SetMaxFeatures(numFeaturesToRetrieve - 1);
+                                    Ptr<MgByteSource> bs = new MgByteSource(bsImpl);
+                                    resultReader = bs->GetReader();
+                                }
+                                else
+                                {
+                                    // Call the C++ API
+                                    // NOTE: I updated the maxFeatures value from numFeaturesToRetrieve to numFeaturesToRetrieve-1
+                                    // Because the MgServerFdoFeatureReader in MapGuide server uses -1 to mark empty, while MgWfsFeatures
+                                    // in MapGuide web tier uses 0
+                                    resultReader = featureService->GetWfsFeature(featureSourceId, ((sSchemaHash.size() == 0) ? sClass : sSchemaHash + _(":") + sClass),
+                                        requiredProperties, m_getFeatureParams->GetSrs(), filter, numFeaturesToRetrieve - 1, sVersion, sOutputFormat, sSortCriteria, sPrefix, oFeatureTypes.GetNamespaceUrl());
+
+                                    // Store the MgByteReader directly for retrieval
+                                    //
+                                    // DO NOT PASS THROUGH OGC XML TEMPLATE PROCESSING CODE!
+                                    // DO NOT PASS GO!
+                                    // DO NOT COLLECT MEMORY SPIKES NEEDLESSLY BUFFERING XML TEMPLATE CONTENT AS A RESULT!
+                                    //
+                                    // This *is* already the WFS GetFeature response. There is nothing to post-process through the XML templates!
+                                }
                             }
                         }
                         else //Cannot resolve feature source from feature type name

Modified: sandbox/jng/wfs_hits/Web/src/HttpHandler/WfsGetFeatureParams.cpp
===================================================================
--- sandbox/jng/wfs_hits/Web/src/HttpHandler/WfsGetFeatureParams.cpp	2019-07-12 13:47:29 UTC (rev 9571)
+++ sandbox/jng/wfs_hits/Web/src/HttpHandler/WfsGetFeatureParams.cpp	2019-07-12 14:37:42 UTC (rev 9572)
@@ -37,6 +37,7 @@
 ,   m_filterStrings(new MgStringCollection())
 ,   m_featureTypeList(new MgStringCollection())
 ,   m_pNamespaces(new MgXmlNamespaceManager())
+,   m_hitMode(false)
 {
 
     // Get the required properties
@@ -105,6 +106,12 @@
     // Get the sortby property name
     m_sortCriteria = GetRequestParameter(oServer,MgHttpResourceStrings::reqWfsSortBy);
 
+    // Try to set hit mode flag (only if WFS version != 1.0.0 as it was only introduced from 1.1.0 onwards)
+    if (m_version != L"1.0.0")
+    {
+        STRING resultType = GetRequestParameter(oServer, MgHttpResourceStrings::reqWfsResultType);
+        m_hitMode = (resultType == L"hits");
+    }
 }
 
 WfsGetFeatureParams::~WfsGetFeatureParams()
@@ -609,3 +616,8 @@
     }
     // --------------------------------------------------------
 }
+
+bool WfsGetFeatureParams::IsHitMode()
+{
+    return m_hitMode;
+}
\ No newline at end of file

Modified: sandbox/jng/wfs_hits/Web/src/HttpHandler/WfsGetFeatureParams.h
===================================================================
--- sandbox/jng/wfs_hits/Web/src/HttpHandler/WfsGetFeatureParams.h	2019-07-12 13:47:29 UTC (rev 9571)
+++ sandbox/jng/wfs_hits/Web/src/HttpHandler/WfsGetFeatureParams.h	2019-07-12 14:37:42 UTC (rev 9572)
@@ -68,6 +68,14 @@
     ~WfsGetFeatureParams();
 
     /// <summary>
+    /// Gets whether the query is only asking for hits (ie. A total feature count)
+    /// </summary>
+    /// <returns>
+    /// True if the query is asking for hits. False otherwise
+    /// </returns>
+    bool IsHitMode();
+
+    /// <summary>
     /// Retrieves the filter strings for the request
     /// </summary>
     /// <returns>
@@ -183,6 +191,7 @@
     STRING m_outputFormat;
     STRING m_version;
     STRING m_sortCriteria;
+    bool m_hitMode;
 };
 
 #endif  // _FS_WFS_GET_FEATURE_PARAMS_H



More information about the mapguide-commits mailing list