dcxmletlservices.cpp
3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "dcxmletlservices.h"
#include "log.h"
#include <string>
using namespace osdev::components;
static const char* selectServices = "selectServices";
static const char* selectServiceById = "selectServiceById";
static const char* selectServiceByName = "selectServiceByName";
DcXmlEtlServices::DcXmlEtlServices( const QString &fileName )
{
if( !fileName.isEmpty() )
{
if( !loadConfiguration( fileName ) )
{
LogInfo( "[DcXmlEtlServices::DcXmlEtlServices]", QString( "There was an error reading file : %1" ).arg( fileName ) );
}
}
else
{
LogInfo( "[DcXmlEtlServices::DcXmlEtlServices]", QString( "No filename given. No configuration read." ) );
}
constructXPathHash();
}
bool DcXmlEtlServices::loadConfiguration( const QString &fileName )
{
return DcXmlBase::parseFile( fileName );
}
QStringList DcXmlEtlServices::getServiceNames() const
{
QStringList lstResult;
QList<pugi::xpath_node> serviceList = DcXmlBase::selectNodes( DcXmlBase::getXPath( selectServices ) );
for( const auto& nodeItem : serviceList )
{
lstResult.append( nodeItem.node().attribute( "name" ).value() );
}
return lstResult;
}
QStringList DcXmlEtlServices::getServiceIds() const
{
QStringList lstResult;
QList<pugi::xpath_node> serviceList = DcXmlBase::selectNodes( DcXmlBase::getXPath( selectServices ) );
for( const auto& nodeItem : serviceList )
{
lstResult.append( nodeItem.node().attribute( "id" ).value() );
}
return lstResult;
}
QString DcXmlEtlServices::getServiceConfig( const QString &serviceId ) const
{
QList<QVariant> varList;
varList.append( serviceId );
return QString( DcXmlBase::selectNode( evaluateXPath( selectServiceById, varList ) ).node().attribute( "filename" ).value() );
}
QHash<QString, QString> DcXmlEtlServices::getServiceConfigs() const
{
QHash<QString, QString> qhResult;
QList<pugi::xpath_node> serviceList = DcXmlBase::selectNodes( DcXmlBase::getXPath( selectServices ) );
for( const auto& nodeItem : serviceList )
{
qhResult.insert( nodeItem.node().attribute( "id" ).value(), nodeItem.node().attribute( "filename" ).value() );
}
return qhResult;
}
void DcXmlEtlServices::constructXPathHash()
{
DcXmlBase::addXPath( selectServices, "//modelmapping/services/service" );
DcXmlBase::addXPath( selectServiceById, "//modelmapping/services/service[@id='%1']" );
DcXmlBase::addXPath( selectServiceByName, "//modelmapping/services/service[@name='%1']" );
}
QString DcXmlEtlServices::getServiceConfigByName( const QString &serviceName ) const
{
return this->getValueByAttribute( selectServiceByName, serviceName, "filename" );
}
QString DcXmlEtlServices::getServiceIdByName( const QString &serviceName ) const
{
return this->getValueByAttribute( selectServiceByName, serviceName, "id" );
}
QString DcXmlEtlServices::getServiceConfigById( const QString &serviceId ) const
{
return this->getValueByAttribute( selectServiceById, serviceId, "filename" );
}
QString DcXmlEtlServices::getValueByAttribute( const QString &XPath,
const QString &attrValue,
const QString &returnAttribute ) const
{
QList<QVariant> varList;
varList.append( attrValue );
return QString( DcXmlBase::selectNode( evaluateXPath( XPath.toStdString().c_str(), varList ) ).node().attribute( returnAttribute.toStdString().c_str() ).value() );
}