[mapguide-commits] r8055 - in trunk/MgDev/Desktop: DesktopTestData MgDesktop/Services MgDesktop/Services/Feature MgDesktop/Services/Resource UnitTest
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Thu Apr 17 06:38:42 PDT 2014
Author: jng
Date: 2014-04-17 06:38:42 -0700 (Thu, 17 Apr 2014)
New Revision: 8055
Added:
trunk/MgDev/Desktop/DesktopTestData/acea.fs
trunk/MgDev/Desktop/DesktopTestData/config.xml
Modified:
trunk/MgDev/Desktop/MgDesktop/Services/Feature/FdoConnectionUtil.h
trunk/MgDev/Desktop/MgDesktop/Services/Resource/UnmanagedDataManager.cpp
trunk/MgDev/Desktop/MgDesktop/Services/Resource/UnmanagedDataManager.h
trunk/MgDev/Desktop/MgDesktop/Services/ResourceService.cpp
trunk/MgDev/Desktop/MgDesktop/Services/ResourceService.h
trunk/MgDev/Desktop/UnitTest/TestResourceService.cpp
trunk/MgDev/Desktop/UnitTest/TestResourceService.h
Log:
#2305: mg-desktop - Apply substitution for aliases in a configuration document. Unit test included.
Added: trunk/MgDev/Desktop/DesktopTestData/acea.fs
===================================================================
--- trunk/MgDev/Desktop/DesktopTestData/acea.fs (rev 0)
+++ trunk/MgDev/Desktop/DesktopTestData/acea.fs 2014-04-17 13:38:42 UTC (rev 8055)
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<FeatureSource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="FeatureSource-1.0.0.xsd">
+ <Provider>OSGeo.Gdal</Provider>
+ <ConfigurationDocument>config.xml</ConfigurationDocument>
+</FeatureSource>
\ No newline at end of file
Added: trunk/MgDev/Desktop/DesktopTestData/config.xml
===================================================================
--- trunk/MgDev/Desktop/DesktopTestData/config.xml (rev 0)
+++ trunk/MgDev/Desktop/DesktopTestData/config.xml 2014-04-17 13:38:42 UTC (rev 8055)
@@ -0,0 +1 @@
+<fdo:DataStore xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gml="http://www.opengis.net/gml" xmlns:fdo="http://fdo.osgeo.org/schemas" xmlns:fds="http://fdo.osgeo.org/schemas/fds"><gml:DerivedCRS gml:id="Default"><gml:metaDataProperty><gml:GenericMetaData><fdo:XYTolerance>0.001</fdo:XYTolerance><fdo:ZTolerance>0.001</fdo:ZTolerance></gml:GenericMetaData></gml:metaDataProperty><gml:remarks>System generated default FDO Spatial Context</gml:remarks><gml:srsName>Default</gml:srsName><gml:validArea><gml:boundingBox><gml:pos>-15411.6153115346 -15451.2408225685</gml:pos><gml:pos>15488.3846884654 15448.7591774315</gml:pos></gml:boundingBox></gml:validArea><gml:baseCRS><fdo:WKTCRS gml:id="Default"><gml:srsName>Default</gml:srsName><fdo:WKT>LOCAL_CS["*XY-MT*",LOCAL_DATUM["*X-Y*",10000],UNIT["Meter", 1],AXIS["X",EAST],AXIS["Y",NORTH]]</fdo:WKT></fdo:WKTCRS></gml:baseCRS><gml:definedByCo
nversion xlink:href="http://fdo.osgeo.org/coord_conversions#identity" /><gml:derivedCRSType codeSpace="http://fdo.osgeo.org/crs_types">geographic</gml:derivedCRSType><gml:usesCS xlink:href="http://fdo.osgeo.org/cs#default_cartesian" /></gml:DerivedCRS><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://fdo.osgeo.org/schemas/feature/default" xmlns:fdo="http://fdo.osgeo.org/schemas" xmlns:default="http://fdo.osgeo.org/schemas/feature/default" elementFormDefault="qualified" attributeFormDefault="unqualified"><xs:annotation><xs:documentation></xs:documentation></xs:annotation><xs:element name="default" type="default:defaultType" abstract="false" substitutionGroup="gml:_Feature"><xs:key name="defaultKey"><xs:selector xpath=".//default" /><xs:field xpath="FeatId" /></xs:key></xs:element><xs:complexType name="defaultType" abstract="false" fdo:hasGeometry="false"><xs:annotation><xs:documentation></xs:documentation></xs:annotation><xs:complexContent><xs:ext
ension base="gml:AbstractFeatureType"><xs:sequence><xs:element name="FeatId" minOccurs="1"><xs:annotation><xs:documentation></xs:documentation></xs:annotation><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="0" /></xs:restriction></xs:simpleType></xs:element><xs:element name="Raster" type="fdo:RasterPropertyType" fdo:defaultImageXSize="1024" fdo:defaultImageYSize="1024" fdo:srsName="Default"><xs:annotation><xs:documentation></xs:documentation></xs:annotation></xs:element></xs:sequence></xs:extension></xs:complexContent></xs:complexType></xs:schema><SchemaMapping provider="OSGeo.Gdal.3.2" xmlns="http://fdogrfp.osgeo.org/schemas" name="default"><complexType name="defaultType"><complexType name="RasterTypeType"><RasterDefinition name="images"><Location name="%MG_DATA_PATH_ALIAS[MG_TEST]%"><Feature name="acea"><Band name="RGB" number="1"><Image frame="1" name="acea.tif"><Bounds><MinX>-15411.6153115346</MinX><MinY>-15451.2408225685</MinY><MaxX>15488.3846884654
</MaxX><MaxY>15448.7591774315</MaxY></Bounds></Image></Band></Feature></Location></RasterDefinition></complexType></complexType></SchemaMapping></fdo:DataStore>
\ No newline at end of file
Modified: trunk/MgDev/Desktop/MgDesktop/Services/Feature/FdoConnectionUtil.h
===================================================================
--- trunk/MgDev/Desktop/MgDesktop/Services/Feature/FdoConnectionUtil.h 2014-04-17 11:35:17 UTC (rev 8054)
+++ trunk/MgDev/Desktop/MgDesktop/Services/Feature/FdoConnectionUtil.h 2014-04-17 13:38:42 UTC (rev 8055)
@@ -20,9 +20,9 @@
public:
static MdfModel::FeatureSource* GetFeatureSource(MgResourceIdentifier* resource);
static void CloseConnection(FdoIConnection* conn);
+ static void PerformTagSubstitution(MgdResourceService* resSvc, REFSTRING str, MgResourceIdentifier* resource, CREFSTRING username = L"", CREFSTRING password = L"");
private:
- static void PerformTagSubstitution(MgdResourceService* resSvc, REFSTRING str, MgResourceIdentifier* resource, CREFSTRING username = L"", CREFSTRING password = L"");
static STRING ParseNonQualifiedProviderName(CREFSTRING providerName);
//Creates a connection by feature source ID. Any tag and aliases present in the connection parameters
Modified: trunk/MgDev/Desktop/MgDesktop/Services/Resource/UnmanagedDataManager.cpp
===================================================================
--- trunk/MgDev/Desktop/MgDesktop/Services/Resource/UnmanagedDataManager.cpp 2014-04-17 11:35:17 UTC (rev 8054)
+++ trunk/MgDev/Desktop/MgDesktop/Services/Resource/UnmanagedDataManager.cpp 2014-04-17 13:38:42 UTC (rev 8055)
@@ -390,6 +390,23 @@
MgdConfigProperties::UnmanagedDataMappingsSection);
}
+void MgdUnmanagedDataManager::AddAliasMapping(CREFSTRING aliasName, CREFSTRING path)
+{
+ ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, m_MgdMutex));
+
+ if (m_unmanagedDataMappings->Contains(aliasName))
+ {
+ Ptr<MgStringProperty> strProp = dynamic_cast<MgStringProperty*>(m_unmanagedDataMappings->GetItem(aliasName));
+ if (NULL != strProp.p)
+ strProp->SetValue(path);
+ }
+ else
+ {
+ Ptr<MgStringProperty> strProp = new MgStringProperty(aliasName, path);
+ m_unmanagedDataMappings->Add(strProp);
+ }
+}
+
///////////////////////////////////////////////////////////////////////////////
/// \brief
/// Return unmanaged data mappings.
Modified: trunk/MgDev/Desktop/MgDesktop/Services/Resource/UnmanagedDataManager.h
===================================================================
--- trunk/MgDev/Desktop/MgDesktop/Services/Resource/UnmanagedDataManager.h 2014-04-17 11:35:17 UTC (rev 8054)
+++ trunk/MgDev/Desktop/MgDesktop/Services/Resource/UnmanagedDataManager.h 2014-04-17 13:38:42 UTC (rev 8055)
@@ -64,6 +64,7 @@
void Initialize();
+ void AddAliasMapping(CREFSTRING aliasName, CREFSTRING path);
void RefreshUnmanagedDataMappings();
MgPropertyCollection* GetUnmanagedDataMappings();
Modified: trunk/MgDev/Desktop/MgDesktop/Services/ResourceService.cpp
===================================================================
--- trunk/MgDev/Desktop/MgDesktop/Services/ResourceService.cpp 2014-04-17 11:35:17 UTC (rev 8054)
+++ trunk/MgDev/Desktop/MgDesktop/Services/ResourceService.cpp 2014-04-17 13:38:42 UTC (rev 8055)
@@ -1626,6 +1626,23 @@
{
source = new MgByteSource(path);
reader = source->GetReader();
+
+ if (preProcessTags == MgResourcePreProcessingType::Substitution)
+ {
+ STRING resContent;
+ Ptr<MgByteSink> sink = new MgByteSink(reader);
+ sink->ToString(resContent);
+
+ MgdFdoConnectionUtil::PerformTagSubstitution(this, resContent, NULL);
+
+ std::string mbXml = MgUtil::WideCharToMultiByte(resContent);
+
+ Ptr<MgByteSource> source2 = new MgByteSource((BYTE_ARRAY_IN)mbXml.c_str(), mbXml.length());
+ source2->SetMimeType(MgMimeType::Xml);
+
+ reader = NULL; //Un-ref the old one
+ reader = source2->GetReader();
+ }
}
MG_RESOURCE_SERVICE_CATCH_AND_THROW(L"MgdResourceService::GetResourceData")
@@ -1798,4 +1815,10 @@
MG_LOG_OPERATION_MESSAGE_ACCESS_ENTRY();
MG_RESOURCE_SERVICE_THROW()
+}
+
+void MgdResourceService::AddAliasMapping(CREFSTRING aliasName, CREFSTRING path)
+{
+ MgdUnmanagedDataManager* umgr = MgdUnmanagedDataManager::GetInstance();
+ umgr->AddAliasMapping(aliasName, path);
}
\ No newline at end of file
Modified: trunk/MgDev/Desktop/MgDesktop/Services/ResourceService.h
===================================================================
--- trunk/MgDev/Desktop/MgDesktop/Services/ResourceService.h 2014-04-17 11:35:17 UTC (rev 8054)
+++ trunk/MgDev/Desktop/MgDesktop/Services/ResourceService.h 2014-04-17 13:38:42 UTC (rev 8055)
@@ -91,6 +91,7 @@
STRING ResolveDataPath(MgResourceIdentifier* resId);
void DeleteSessionFiles();
+ void AddAliasMapping(CREFSTRING aliasName, CREFSTRING path);
CLASS_ID:
static const INT32 m_cls_id = MapGuide_Desktop_ResourceService_ResourceService;
Modified: trunk/MgDev/Desktop/UnitTest/TestResourceService.cpp
===================================================================
--- trunk/MgDev/Desktop/UnitTest/TestResourceService.cpp 2014-04-17 11:35:17 UTC (rev 8054)
+++ trunk/MgDev/Desktop/UnitTest/TestResourceService.cpp 2014-04-17 13:38:42 UTC (rev 8055)
@@ -76,6 +76,22 @@
void TestResourceService::TestStart()
{
ACE_DEBUG((LM_INFO, ACE_TEXT("\nRunning Resource Service tests.\n")));
+
+ Ptr<MgdServiceFactory> fact = new MgdServiceFactory();
+ Ptr<MgResourceService> pService = dynamic_cast<MgResourceService*>(fact->CreateService(MgServiceType::ResourceService));
+ if (pService == 0)
+ {
+ throw new MgServiceNotAvailableException(L"TestResourceService.TestEnd", __LINE__, __WFILE__, NULL, L"", NULL);
+ }
+
+ Ptr<MgResourceIdentifier> fs1 = new MgResourceIdentifier(L"Library://UnitTests/Data/acea.FeatureSource");
+ Ptr<MgByteSource> fs1Source = new MgByteSource(L"../UnitTestFiles/acea.fs", false);
+ Ptr<MgByteReader> fs1Reader = fs1Source->GetReader();
+ pService->SetResource(fs1, fs1Reader, NULL);
+
+ Ptr<MgByteSource> confSource = new MgByteSource(L"../UnitTestFiles/config.xml", false);
+ Ptr<MgByteReader> confReader = confSource->GetReader();
+ pService->SetResourceData(fs1, L"config.xml", MgResourceDataType::File, confReader);
}
void TestResourceService::TestEnd()
@@ -93,6 +109,9 @@
Ptr<MgResourceIdentifier> mapres1 = new MgResourceIdentifier(L"Library://UnitTests/Data/Shuttle.DrawingSource");
pService->DeleteResource(mapres1);
+ Ptr<MgResourceIdentifier> fs1 = new MgResourceIdentifier(L"Library://UnitTests/Data/acea.FeatureSource");
+ pService->DeleteResource(fs1);
+
// Delete any resources created
if (pService->ResourceExists(&resourceIdentifier))
pService->DeleteResource(&resourceIdentifier);
@@ -1212,4 +1231,36 @@
SAFE_RELEASE(e);
CPPUNIT_FAIL(MG_WCHAR_TO_CHAR(message.c_str()));
}
+}
+
+void TestResourceService::TestCase_AliasedConfigurationDocument()
+{
+ try
+ {
+ Ptr<MgdServiceFactory> fact = new MgdServiceFactory();
+ Ptr<MgdResourceService> pService = dynamic_cast<MgdResourceService*>(fact->CreateService(MgServiceType::ResourceService));
+ if (pService == 0)
+ {
+ throw new MgServiceNotAvailableException(L"TestResourceService.TestCase_PackageNoOpUpdateRepository", __LINE__, __WFILE__, NULL, L"", NULL);
+ }
+
+ pService->AddAliasMapping(L"MG_TEST", L"C:/Temp");
+
+ //Get configuration document
+ Ptr<MgResourceIdentifier> fs1 = new MgResourceIdentifier(L"Library://UnitTests/Data/acea.FeatureSource");
+ Ptr<MgByteReader> configContent = pService->GetResourceData(fs1, L"config.xml", MgResourcePreProcessingType::Substitution);
+ Ptr<MgByteSink> sink = new MgByteSink(configContent);
+ STRING xml;
+ sink->ToString(xml);
+
+ //It should have no alias tags as they have been substituted
+ CPPUNIT_ASSERT(xml.find(L"MG_TEST") == STRING::npos);
+ CPPUNIT_ASSERT(xml.find(L"MG_DATA_PATH_ALIAS") == STRING::npos);
+ }
+ catch(MgException* e)
+ {
+ STRING message = e->GetDetails(TEST_LOCALE);
+ SAFE_RELEASE(e);
+ CPPUNIT_FAIL(MG_WCHAR_TO_CHAR(message.c_str()));
+ }
}
\ No newline at end of file
Modified: trunk/MgDev/Desktop/UnitTest/TestResourceService.h
===================================================================
--- trunk/MgDev/Desktop/UnitTest/TestResourceService.h 2014-04-17 11:35:17 UTC (rev 8054)
+++ trunk/MgDev/Desktop/UnitTest/TestResourceService.h 2014-04-17 13:38:42 UTC (rev 8055)
@@ -59,6 +59,7 @@
CPPUNIT_TEST(TestCase_BenchmarkGetResourceContents);
CPPUNIT_TEST(TestCase_PackageNoOpUpdateRepository);
+ CPPUNIT_TEST(TestCase_AliasedConfigurationDocument);
CPPUNIT_TEST(TestEnd); // This must be the very last unit test
CPPUNIT_TEST_SUITE_END();
@@ -108,6 +109,8 @@
// Benchmarking
void TestCase_BenchmarkGetResourceContents();
+
+ void TestCase_AliasedConfigurationDocument();
};
#endif // TESTRESOURCESERVICE_H_
More information about the mapguide-commits
mailing list