|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: update api for contentinfodb |
|
15 * |
|
16 */ |
|
17 #include "contentinfodbupdate.h" |
|
18 #include "contentinfodbparser.h" |
|
19 #include "contentinfodb.h" |
|
20 #include "cpixcontentinfodbdef.h" |
|
21 |
|
22 // --------------------------------------------------------------------------- |
|
23 // ContentInfoDbUpdate::ContentInfoDbUpdate() |
|
24 // --------------------------------------------------------------------------- |
|
25 // |
|
26 ContentInfoDbUpdate::ContentInfoDbUpdate() : |
|
27 iParser(NULL),mdb(NULL) |
|
28 { |
|
29 mdb = ContentInfoDb::instance(); |
|
30 iParser = new ContentInfoDbParser(); |
|
31 if (iParser) |
|
32 { |
|
33 connect(iParser, SIGNAL(categoryDetails(QMap<QString,QString>)), |
|
34 this, SLOT(slotupdateCategoryInfo(QMap<QString,QString>))); |
|
35 connect(iParser, SIGNAL(actionUri(QMap<QString,QString>)), this, |
|
36 SLOT(slotupdateUri(QMap<QString,QString>))); |
|
37 connect(iParser, SIGNAL(filedMapping(QString,QStringList)), this, |
|
38 SLOT(slotupdateFieldmapping(QString,QStringList))); |
|
39 connect(iParser, SIGNAL(firstLineMapping(QStringList)), this, |
|
40 SLOT(slotfirstLineMapping(QStringList))); |
|
41 connect(iParser, SIGNAL(relevancyMapping(QString,QString)), this, |
|
42 SLOT(slotrelevancyMapping(QString,QString))); |
|
43 } |
|
44 counter = 0; |
|
45 } |
|
46 // --------------------------------------------------------------------------- |
|
47 // ContentInfoDbUpdate::~ContentInfoDbUpdate() |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 ContentInfoDbUpdate::~ContentInfoDbUpdate() |
|
51 { |
|
52 ContentInfoDb::deleteinstance(); |
|
53 } |
|
54 // --------------------------------------------------------------------------- |
|
55 // ContentInfoDbUpdate::UpdateDb() |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 bool ContentInfoDbUpdate::UpdateDb(QString xmlpath) |
|
59 { |
|
60 if (mdb) |
|
61 (void)mdb->Open(); |
|
62 if (iParser) |
|
63 { |
|
64 primarykey = QString(); |
|
65 return iParser->parse(xmlpath); |
|
66 } |
|
67 return false; |
|
68 } |
|
69 // --------------------------------------------------------------------------- |
|
70 // ContentInfoDbUpdate::UpdateBlacklisted() |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 bool ContentInfoDbUpdate::UpdateBlacklisted(QString primarykey, int value) |
|
74 { |
|
75 if (mdb) |
|
76 (void)mdb->Open(); |
|
77 QString query = QString(QUERYUPDATEDATA).arg(MAINTABLENAME).arg( |
|
78 BLACKLISTSTATUS).arg(value).arg(TAGPRIMARYKEY).arg(primarykey); |
|
79 if (!mdb->writeData(query)) |
|
80 return false; |
|
81 return true; |
|
82 } |
|
83 // --------------------------------------------------------------------------- |
|
84 // ContentInfoDbUpdate::UpdateIndexStatus() |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 bool ContentInfoDbUpdate::UpdateIndexStatus(QString primarykey, int value) |
|
88 { |
|
89 if (mdb) |
|
90 (void)mdb->Open(); |
|
91 QString query = QString(QUERYUPDATEDATA).arg(MAINTABLENAME).arg( |
|
92 INDEXINGSTATUS).arg(value).arg(TAGPRIMARYKEY).arg(primarykey); |
|
93 if (!mdb->writeData(query)) |
|
94 return false; |
|
95 return true; |
|
96 } |
|
97 // --------------------------------------------------------------------------- |
|
98 // ContentInfoDbUpdate::InsertPrimaryKey() |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 QString ContentInfoDbUpdate::InsertPrimaryKey(QString tableName, |
|
102 QString tagName, QMap<QString, QString> data) |
|
103 { |
|
104 QMapIterator<QString, QString> i(data); |
|
105 QString query; |
|
106 QString p_key; |
|
107 while (i.hasNext()) |
|
108 { |
|
109 i.next(); |
|
110 if (i.key() == tagName) |
|
111 { |
|
112 p_key = i.value(); |
|
113 break; |
|
114 } |
|
115 } |
|
116 query = QString(QUERYINSERTROW).arg(tableName).arg(tagName).arg(p_key); |
|
117 mdb->writeData(query); |
|
118 return p_key; |
|
119 } |
|
120 // --------------------------------------------------------------------------- |
|
121 // ContentInfoDbUpdate::slotupdateCategoryInfo() |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 void ContentInfoDbUpdate::slotupdateCategoryInfo(QMap<QString, QString> map) |
|
125 { |
|
126 QString query; |
|
127 QString p_key = InsertPrimaryKey(MAINTABLENAME, TAGPRIMARYKEY, map); |
|
128 primarykey = p_key; |
|
129 if (p_key.length()) |
|
130 { |
|
131 QMapIterator<QString, QString> i(map); |
|
132 while (i.hasNext()) |
|
133 { |
|
134 i.next(); |
|
135 if (i.key() != TAGPRIMARYKEY) |
|
136 { |
|
137 query = QString(); |
|
138 if ((i.key() == TAGACTIONURI) || (i.key() == TAGFIELDMAP) |
|
139 || (i.key() == TAGRELEVANCY) || (i.key() |
|
140 == TAGRESULTFIRSTLINE)) |
|
141 { |
|
142 counter++; |
|
143 QString tablename = QString(DYNAMICTABLE).arg(counter); |
|
144 query = QString(QUERYUPDATEDATA).arg(MAINTABLENAME).arg( |
|
145 i.key()).arg(tablename).arg(TAGPRIMARYKEY).arg( |
|
146 p_key); |
|
147 } |
|
148 else |
|
149 { |
|
150 query = QString(QUERYUPDATEDATA).arg(MAINTABLENAME).arg( |
|
151 i.key()).arg(i.value()).arg(TAGPRIMARYKEY).arg( |
|
152 p_key); |
|
153 } |
|
154 if (!mdb->writeData(query)) |
|
155 { |
|
156 |
|
157 } |
|
158 } |
|
159 } |
|
160 } |
|
161 } |
|
162 // --------------------------------------------------------------------------- |
|
163 // ContentInfoDbUpdate::slotupdateUri() |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 void ContentInfoDbUpdate::slotupdateUri(QMap<QString, QString> map) |
|
167 { |
|
168 //get actionuri table name |
|
169 QString query = QString(QUERYDATARETRIVAL).arg(TAGACTIONURI).arg( |
|
170 MAINTABLENAME).arg(TAGPRIMARYKEY).arg(primarykey); |
|
171 QString actionuritablename = mdb->readStringData(query); |
|
172 |
|
173 if (actionuritablename.length()) |
|
174 { |
|
175 query = QString(); |
|
176 query = QString(QUERYCREATEACTIONURITABLE).arg(actionuritablename); |
|
177 mdb->createTable(actionuritablename, query); |
|
178 QString p_key = InsertPrimaryKey(actionuritablename, |
|
179 TAGACTIONURISTRING, map); |
|
180 if (p_key.length()) |
|
181 { |
|
182 QMapIterator<QString, QString> i(map); |
|
183 while (i.hasNext()) |
|
184 { |
|
185 i.next(); |
|
186 if (i.key() != TAGACTIONURISTRING) |
|
187 { |
|
188 query = QString(); |
|
189 query |
|
190 = QString(QUERYUPDATEDATA).arg(actionuritablename).arg( |
|
191 i.key()).arg(i.value()).arg( |
|
192 TAGACTIONURISTRING).arg(p_key); |
|
193 if (!mdb->writeData(query)) |
|
194 { |
|
195 |
|
196 } |
|
197 } |
|
198 } |
|
199 } |
|
200 } |
|
201 } |
|
202 // --------------------------------------------------------------------------- |
|
203 // ContentInfoDbUpdate::slotupdateFieldmapping() |
|
204 // --------------------------------------------------------------------------- |
|
205 // |
|
206 void ContentInfoDbUpdate::slotupdateFieldmapping(QString key, |
|
207 QStringList value) |
|
208 { |
|
209 //get fieldmap table name from maintable |
|
210 QString query = QString(QUERYDATARETRIVAL).arg(TAGFIELDMAP).arg( |
|
211 MAINTABLENAME).arg(TAGPRIMARYKEY).arg(primarykey); |
|
212 QString fieldtablename = mdb->readStringData(query); |
|
213 |
|
214 if (fieldtablename.length()) |
|
215 { |
|
216 // create a table for fieldmap |
|
217 query = QString(); |
|
218 query = QString(QUERYCREATEFIELDMAPTABLE).arg(fieldtablename); |
|
219 mdb->createTable(fieldtablename, query); |
|
220 |
|
221 // insert the field in filedmap table |
|
222 query = QString(); |
|
223 query |
|
224 = QString(QUERYINSERTROW).arg(fieldtablename).arg(TAGFIELD).arg( |
|
225 key); |
|
226 mdb->writeData(query); |
|
227 { |
|
228 |
|
229 } |
|
230 |
|
231 counter++; |
|
232 query = QString(); |
|
233 |
|
234 QString tablename = QString(DYNAMICTABLE).arg(counter); |
|
235 |
|
236 // enter the value as table name second column in field map will refer to another table |
|
237 query |
|
238 = QString(QUERYUPDATEDATA).arg(fieldtablename).arg(TAGURILIST).arg( |
|
239 tablename).arg(TAGFIELD).arg(key); |
|
240 if (!mdb->writeData(query)) |
|
241 { |
|
242 |
|
243 } |
|
244 |
|
245 query = QString(); |
|
246 // creating a table for the field map values |
|
247 query = QString(QUERYCREATEFIELDMAPSUBTABLE).arg(tablename); |
|
248 mdb->createTable(tablename, query); |
|
249 |
|
250 for (int i = 0; i < value.count(); i++) |
|
251 { |
|
252 query = QString(); |
|
253 // inserting the uri list mapped for a particular field |
|
254 query = QString(QUERYINSERTROW).arg(tablename).arg(TAGAURI).arg( |
|
255 value[i]); |
|
256 if (!mdb->writeData(query)) |
|
257 { |
|
258 |
|
259 } |
|
260 } |
|
261 } |
|
262 } |
|
263 // --------------------------------------------------------------------------- |
|
264 // ContentInfoDbUpdate::slotfirstLineMapping() |
|
265 // --------------------------------------------------------------------------- |
|
266 // |
|
267 void ContentInfoDbUpdate::slotfirstLineMapping(QStringList list) |
|
268 { |
|
269 //get actionuri table name |
|
270 QString query = QString(QUERYDATARETRIVAL).arg(TAGRESULTFIRSTLINE).arg( |
|
271 MAINTABLENAME).arg(TAGPRIMARYKEY).arg(primarykey); |
|
272 QString firstlinetablename = mdb->readStringData(query); |
|
273 |
|
274 if (firstlinetablename.length()) |
|
275 { |
|
276 query = QString(); |
|
277 query = QString(QUERYCREATEFIRSTLINETABLE).arg(firstlinetablename); |
|
278 mdb->createTable(firstlinetablename, query); |
|
279 |
|
280 for (int i = 0; i < list.count(); i++) |
|
281 { |
|
282 query = QString(); |
|
283 // inserting the uri list mapped for a particular field |
|
284 query = QString(QUERYINSERTROW).arg(firstlinetablename).arg( |
|
285 TAGFIELD).arg(list[i]); |
|
286 if (!mdb->writeData(query)) |
|
287 { |
|
288 |
|
289 } |
|
290 } |
|
291 } |
|
292 } |
|
293 // --------------------------------------------------------------------------- |
|
294 // ContentInfoDbUpdate::slotrelevancyMapping() |
|
295 // --------------------------------------------------------------------------- |
|
296 // |
|
297 void ContentInfoDbUpdate::slotrelevancyMapping(QString field, |
|
298 QString boostvalue) |
|
299 { |
|
300 QString query = QString(QUERYDATARETRIVAL).arg(TAGRELEVANCY).arg( |
|
301 MAINTABLENAME).arg(TAGPRIMARYKEY).arg(primarykey); |
|
302 QString relevancytablename = mdb->readStringData(query); |
|
303 if (relevancytablename.length()) |
|
304 { |
|
305 query = QString(); |
|
306 query = QString(QUERYCREATERELEVANCYTABLE).arg(relevancytablename); |
|
307 mdb->createTable(relevancytablename, query); |
|
308 |
|
309 query = QString(); |
|
310 // inserting field name as a primary key |
|
311 query |
|
312 = QString(QUERYINSERTROW).arg(relevancytablename).arg( |
|
313 TAGFIELD).arg(field); |
|
314 |
|
315 if (!mdb->writeData(query)) |
|
316 { |
|
317 |
|
318 } |
|
319 query = QString(); |
|
320 // updating the row with boostvalue |
|
321 query = QString(QUERYUPDATEDATA).arg(relevancytablename).arg( |
|
322 TAGBOOSTVALUE).arg(boostvalue).arg(TAGFIELD).arg(field); |
|
323 if (!mdb->writeData(query)) |
|
324 { |
|
325 |
|
326 } |
|
327 } |
|
328 } |
|
329 // --------------------------------------------------------------------------- |
|
330 // ContentInfoDbUpdate::slotrelevancyMapping() |
|
331 // --------------------------------------------------------------------------- |
|
332 // |
|
333 void ContentInfoDbUpdate::deleteCategory(QString Key) |
|
334 { |
|
335 if (mdb) |
|
336 (void)mdb->Open(); |
|
337 mdb->writeData(QString(QUERYDELETE).arg(Key)); |
|
338 } |