kpilot/lib
idmapper.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "idmapper.h"
00027 #include "idmapperxml.h"
00028 #include "options.h"
00029
00030 #include <tqsqldatabase.h>
00031 #include <tqfile.h>
00032
00033 #include <kglobal.h>
00034 #include <kstandarddirs.h>
00035
00036 class IDMapperPrivate
00037 {
00038 public:
00039 IDMapperPrivate()
00040 {
00041 fXmlSource = 0L;
00042 }
00043
00044 ~IDMapperPrivate()
00045 {
00046 FUNCTIONSETUP;
00047
00048 KPILOT_DELETE(fXmlSource);
00049 }
00050
00051 IDMapperXml *fXmlSource;
00052 };
00053
00054 IDMapper::IDMapper()
00055 {
00056 FUNCTIONSETUP;
00057
00058 fP = new IDMapperPrivate();
00059
00060 TQString dbPath = KGlobal::dirs()->
00061 saveLocation("data", CSL1("kpilot/") );
00062 TQString dbFile = dbPath + CSL1("mapping.xml");
00063
00064 if( !openDatasource( dbFile ) )
00065 {
00066 DEBUGKPILOT << fname << "Could not open or create xml file." << endl;
00067 }
00068 }
00069
00070 IDMapper::IDMapper( const TQString &file)
00071 {
00072 FUNCTIONSETUP;
00073
00074 fP = new IDMapperPrivate();
00075
00076 if( !openDatasource( file ) )
00077 {
00078 DEBUGKPILOT << fname << "Could not open or create xml file." << endl;
00079 }
00080 }
00081
00082 IDMapper::~IDMapper()
00083 {
00084 KPILOT_DELETE(fP);
00085 }
00086
00087 bool IDMapper::openDatasource( const TQString &file )
00088 {
00089 FUNCTIONSETUP;
00090
00091 fP->fXmlSource = new IDMapperXml( file );
00092 return fP->fXmlSource->open();
00093 }
00094
00095 void IDMapper::registerPCObjectId( const TQString &conduit, const TQString &uid )
00096 {
00097 FUNCTIONSETUP;
00098
00099 IDMapping mapping = IDMapping( conduit );
00100 mapping.setUid( uid );
00101
00102 fP->fXmlSource->addMapping( mapping );
00103 fP->fXmlSource->save();
00104 }
00105
00106 void IDMapper::registerHHObjectId( const TQString &conduit, recordid_t pid )
00107 {
00108 FUNCTIONSETUP;
00109
00110 IDMapping mapping = IDMapping( conduit );
00111 mapping.setPid( pid );
00112
00113 fP->fXmlSource->addMapping( mapping );
00114 fP->fXmlSource->save();
00115 }
00116
00117 TQValueList<TQString> IDMapper::getPCObjectIds( const TQString &conduit )
00118 {
00119 FUNCTIONSETUP;
00120
00121 TQValueList<IDMapping> &mappings = fP->fXmlSource->mappings();
00122 TQValueList<IDMapping>::iterator it;
00123 TQValueList<TQString> uids;
00124
00125 DEBUGKPILOT << fname << ": total " << mappings.count() << endl;
00126
00127 for ( it = mappings.begin(); it != mappings.end(); ++it )
00128 {
00129 IDMapping &mapping = (*it);
00130
00131 DEBUGKPILOT << fname << ": mapping.conduit() = " << mapping.conduit() << endl;
00132 DEBUGKPILOT << fname << ": conduit = " << conduit << endl;
00133
00134 if( (mapping.conduit() == conduit) && !mapping.uid().isNull() )
00135 {
00136 DEBUGKPILOT << fname << ": mapping.conduit() == conduit" << endl;
00137 uids.append( mapping.uid() );
00138 }
00139 }
00140
00141 return uids;
00142 }
00143
00144 TQValueList<recordid_t> IDMapper::getHHObjectIds( const TQString &conduit )
00145 {
00146 FUNCTIONSETUP;
00147
00148 TQValueList<IDMapping> &mappings = fP->fXmlSource->mappings();
00149 TQValueList<IDMapping>::iterator it;
00150 TQValueList<recordid_t> pids;
00151
00152 for ( it = mappings.begin(); it != mappings.end(); ++it )
00153 {
00154 IDMapping &mapping = *it;
00155 DEBUGKPILOT << fname << ": mapping.conduit() = " << mapping.conduit() << endl;
00156 DEBUGKPILOT << fname << ": " << mapping.pid() << endl;
00157 if( mapping.conduit() == conduit && mapping.pid() != 0 )
00158 {
00159 DEBUGKPILOT << fname << ": mapping.conduit() == conduit" << endl;
00160 pids.append( mapping.pid() );
00161 }
00162 }
00163
00164 return pids;
00165 }
00166
00167 bool IDMapper::hasPCId( const TQString &conduit, recordid_t pid )
00168 {
00169 FUNCTIONSETUP;
00170
00171 TQValueList<IDMapping> &mappings = fP->fXmlSource->mappings();
00172 TQValueList<IDMapping>::iterator it;
00173
00174 for ( it = mappings.begin(); it != mappings.end(); ++it )
00175 {
00176 IDMapping &mapping = *it;
00177 if( mapping.conduit() == conduit && mapping.pid() == pid )
00178 {
00179 return !mapping.uid().isNull();
00180 }
00181 }
00182
00183 return false;
00184 }
00185
00186 bool IDMapper::hasHHId( const TQString &conduit, const TQString &uid )
00187 {
00188 FUNCTIONSETUP;
00189
00190 TQValueList<IDMapping> &mappings = fP->fXmlSource->mappings();
00191 TQValueList<IDMapping>::iterator it;
00192
00193 for ( it = mappings.begin(); it != mappings.end(); ++it )
00194 {
00195 IDMapping &mapping = *it;
00196 if( mapping.conduit() == conduit && mapping.uid() == uid )
00197 {
00198 return mapping.pid() != 0;
00199 }
00200 }
00201
00202 return false;
00203 }
00204
00205 void IDMapper::setHHObjectId( const TQString &conduit, const TQString &uid
00206 , recordid_t pid )
00207 {
00208 FUNCTIONSETUP;
00209
00210 bool modified = false;
00211
00212 TQValueList<IDMapping> &mappings = fP->fXmlSource->mappings();
00213 TQValueList<IDMapping>::iterator it;
00214
00215 for ( it = mappings.begin(); it != mappings.end(); ++it )
00216 {
00217 IDMapping &mapping = *it;
00218 if( mapping.conduit() == conduit && mapping.uid() == uid )
00219 {
00220 mapping.setPid( pid );
00221 fP->fXmlSource->save();
00222 modified = true;
00223 }
00224 }
00225 }
00226
00227 void IDMapper::setPCObjectId( const TQString &conduit, recordid_t pid
00228 , const TQString &uid )
00229 {
00230 FUNCTIONSETUP;
00231
00232 bool modified = false;
00233
00234 TQValueList<IDMapping> &mappings = fP->fXmlSource->mappings();
00235 TQValueList<IDMapping>::iterator it;
00236
00237 for ( it = mappings.begin(); it != mappings.end(); ++it )
00238 {
00239 IDMapping &mapping = *it;
00240 if( mapping.conduit() == conduit && mapping.pid() == pid )
00241 {
00242 mapping.setUid( uid );
00243 fP->fXmlSource->save();
00244 modified = true;
00245 }
00246 }
00247 }
|