diff options
author | Kevin Wu Won <kevin.wuwon@nokia.com> | 2010-12-16 14:04:52 +1000 |
---|---|---|
committer | Kevin Wu Won <kevin.wuwon@nokia.com> | 2010-12-17 10:43:34 +1000 |
commit | 02cdd9f4c8180104ca0bc5820f0831876fe2ec8d (patch) | |
tree | 34b244873e2696c0a28f61d9097a51b3a06bde0c | |
parent | cd318cfcbe0bd132288ff252db63143371c04ac6 (diff) |
Finish Partial Save implementation for Organizer
Add client-facing API for partial save in QOrganizerManager
Add autotests for synchronous API (copied from Contacts tests)
Removed sentence from saveContacts and saveItems documentation about clearing
the id on failure
Reviewed-By: Chris Adams
Change-Id: I42982a1c12587513b6884bf0af3706fcafdda6b3
-rw-r--r-- | src/contacts/qcontactmanager.cpp | 6 | ||||
-rw-r--r-- | src/organizer/qorganizermanager.cpp | 42 | ||||
-rw-r--r-- | src/organizer/qorganizermanager.h | 1 | ||||
-rw-r--r-- | src/organizer/qorganizermanagerengine.cpp | 6 | ||||
-rw-r--r-- | tests/auto/qorganizermanager/tst_qorganizermanager.cpp | 112 |
5 files changed, 155 insertions, 12 deletions
diff --git a/src/contacts/qcontactmanager.cpp b/src/contacts/qcontactmanager.cpp index ddaccac80f..6ae48d9f06 100644 --- a/src/contacts/qcontactmanager.cpp +++ b/src/contacts/qcontactmanager.cpp @@ -624,8 +624,7 @@ bool QContactManager::removeContact(const QContactLocalId& contactId) if all contacts were saved successfully. For each newly saved contact that was successful, the id of the contact - in the \a contacts list will be updated with the new value. If a failure occurs - when saving a new contact, the id will be cleared. + in the \a contacts list will be updated with the new value. \sa QContactManager::saveContact() */ @@ -661,8 +660,7 @@ bool QContactManager::saveContacts(QList<QContact>* contacts, QMap<int, QContact if all contacts were saved successfully. For each newly saved contact that was successful, the id of the contact - in the \a contacts list will be updated with the new value. If a failure occurs - when saving a new contact, the id will be cleared. + in the \a contacts list will be updated with the new value. \sa QContactManager::saveContact() */ diff --git a/src/organizer/qorganizermanager.cpp b/src/organizer/qorganizermanager.cpp index 7623ef44cb..3fc10aba59 100644 --- a/src/organizer/qorganizermanager.cpp +++ b/src/organizer/qorganizermanager.cpp @@ -589,8 +589,8 @@ bool QOrganizerManager::removeItem(const QOrganizerItemId& itemId) /*! Adds the list of organizer items given by \a items list to the database. Each item in the list will be saved in the collection whose - id is reported by calling item->collectionId() if the specified collection exists, - or if no collectionId is specified in the item, or the collectionId is the default + id is reported by calling item->collectionId() if the specified collection exists. + If no collectionId is specified in the item, or if the collectionId is the default collection id, it will be saved in the collection in which the item is currently saved (if it is not a new item) or in the default collection (if it is a new item). As such, an item may be moved between collections with this save operation. @@ -601,8 +601,7 @@ bool QOrganizerManager::removeItem(const QOrganizerItemId& itemId) if all organizer items were saved successfully. For each newly saved organizer item that was successful, the id of the organizer item - in the \a items list will be updated with the new value. If a failure occurs - when saving a new item, the id will be cleared. + in the \a items list will be updated with the new value. \sa QOrganizerManager::saveItem() */ @@ -619,6 +618,41 @@ bool QOrganizerManager::saveItems(QList<QOrganizerItem>* items) } /*! + Adds the list of organizer items given by \a items list to the database. + Each item in the list will be saved in the collection whose + id is reported by calling item->collectionId() if the specified collection exists. + If no collectionId is specified in the item, or if the collectionId is the default + collection id, it will be saved in the collection in which the item is currently + saved (if it is not a new item) or in the default collection (if it is a new item). + As such, an item may be moved between collections with this save operation. + Returns true if the organizer items were saved successfully, otherwise false. + + This function accepts a \a definitionMask, which specifies which details of + the items should be updated. Details with definition names not included in + the definitionMask will not be updated or added. + + Calling \l errorMap() will return the per-input errors for the latest batch function. + The \l QOrganizerManager::error() function will only return \c QOrganizerManager::NoError + if all organizer items were saved successfully. + + For each newly saved organizer item that was successful, the id of the organizer item + in the \a items list will be updated with the new value. + + \sa QOrganizerManager::saveItem() + */ +bool QOrganizerManager::saveItems(QList<QOrganizerItem>* items, const QStringList& definitionMask) +{ + d->m_errorMap.clear(); + if (!items) { + d->m_error = QOrganizerManager::BadArgumentError; + return false; + } + + d->m_error = QOrganizerManager::NoError; + return d->m_engine->saveItems(items, definitionMask, &d->m_errorMap, &d->m_error); +} + +/*! Remove every organizer item whose id is contained in the list of organizer item ids \a organizeritemIds. Returns true if all organizer items were removed successfully, otherwise false. diff --git a/src/organizer/qorganizermanager.h b/src/organizer/qorganizermanager.h index 89e24408b5..b483384880 100644 --- a/src/organizer/qorganizermanager.h +++ b/src/organizer/qorganizermanager.h @@ -128,6 +128,7 @@ public: bool saveItem(QOrganizerItem* item); bool saveItems(QList<QOrganizerItem>* items); + bool saveItems(QList<QOrganizerItem>* items, const QStringList& definitionMask); bool removeItem(const QOrganizerItemId& itemId); bool removeItems(const QList<QOrganizerItemId>& itemIds); diff --git a/src/organizer/qorganizermanagerengine.cpp b/src/organizer/qorganizermanagerengine.cpp index 3e0e703d5f..a566aea8b5 100644 --- a/src/organizer/qorganizermanagerengine.cpp +++ b/src/organizer/qorganizermanagerengine.cpp @@ -2024,8 +2024,7 @@ bool QOrganizerManagerEngine::removeItem(const QOrganizerItemId& organizeritemId if all organizer items were saved successfully. For each newly saved item that was successful, the id of the item - in the \a items list will be updated with the new value. If a failure occurs - when saving a new item, the id will be cleared. + in the \a items list will be updated with the new value. Each item in the given list \a items will be added to the collection identified in the item (accessible via item->collectionId()) if it exists, and if @@ -3275,8 +3274,7 @@ bool QOrganizerManagerEngineV2::saveItems(QList<QOrganizerItem>* items, QMap<int items were saved successfully. For each newly saved item that was successful, the id of the item in the \a items list - will be updated with the new value. If a failure occurs when saving a new item, the id will be - cleared. + will be updated with the new value. Any errors encountered during this operation should be stored to \a error. */ diff --git a/tests/auto/qorganizermanager/tst_qorganizermanager.cpp b/tests/auto/qorganizermanager/tst_qorganizermanager.cpp index ecaa7154d5..bc8dc90743 100644 --- a/tests/auto/qorganizermanager/tst_qorganizermanager.cpp +++ b/tests/auto/qorganizermanager/tst_qorganizermanager.cpp @@ -181,6 +181,7 @@ private slots: void recurrence(); void idComparison(); void emptyItemManipulation(); + void partialSave(); /* Tests that take no data */ void itemValidation(); @@ -222,6 +223,7 @@ private slots: void recurrence_data() {addManagers();} void idComparison_data() {addManagers();} void emptyItemManipulation_data() {addManagers();} + void partialSave_data() {addManagers();} }; class BasicItemLocalId : public QOrganizerItemEngineId @@ -3850,6 +3852,116 @@ void tst_QOrganizerManager::emptyItemManipulation() QVERIFY(!cm->removeItem(invalidId)); // id from different manager } +void tst_QOrganizerManager::partialSave() +{ + QFETCH(QString, uri); + QScopedPointer<QOrganizerManager> cm(QOrganizerManager::fromUri(uri)); + + QList<QOrganizerItem> items; + QOrganizerEvent event = QOrganizerEvent(); + event.setDisplayLabel("One"); + event.setStartDateTime(QDateTime(QDate(2010, 12, 25), QTime(1, 0, 0))); + event.setEndDateTime(QDateTime(QDate(2010, 12, 25), QTime(1, 30, 0))); + event.setDescription("One description"); + items.append(event); + + event = QOrganizerEvent(); + event.setDisplayLabel("Two"); + event.setStartDateTime(QDateTime(QDate(2010, 12, 25), QTime(2, 0, 0))); + event.setEndDateTime(QDateTime(QDate(2010, 12, 25), QTime(2, 30, 0))); + event.setDescription("Two description"); + items.append(event); + + event = QOrganizerEvent(); + event.setDisplayLabel("Three"); + event.setStartDateTime(QDateTime(QDate(2010, 12, 25), QTime(3, 0, 0))); + event.setEndDateTime(QDateTime(QDate(2010, 12, 25), QTime(3, 30, 0))); + items.append(event); + + event = QOrganizerEvent(); + event.setDisplayLabel("Four"); + event.setStartDateTime(QDateTime(QDate(2010, 12, 25), QTime(4, 0, 0))); + event.setEndDateTime(QDateTime(QDate(2010, 12, 25), QTime(4, 30, 0))); + items.append(event); + + // First save these items + QVERIFY(cm->saveItems(&items)); + QList<QOrganizerItem> originalItems = items; + + items[0].setDescription("One changed description"); + + // 0) empty mask == full save + QVERIFY(cm->saveItems(&items, QStringList())); + + // That should have updated everything + QOrganizerItem a = cm->item(originalItems[0].id()); + QVERIFY(a.description() == "One changed description"); + + // 1) Change the description for b, mask it out + items[1].setDescription("Two changed description"); + QVERIFY(cm->saveItems(&items, QStringList(QOrganizerEventTime::DefinitionName))); + QVERIFY(cm->errorMap().isEmpty()); + + QOrganizerItem b = cm->item(originalItems[1].id()); + QCOMPARE(b.description(), QString("Two description")); + + // 2) save a modified detail in the mask + items[1].setDescription("Two changed description"); + + QVERIFY(cm->saveItems(&items, QStringList(QOrganizerItemDescription::DefinitionName))); + QVERIFY(cm->errorMap().isEmpty()); + b = cm->item(originalItems[1].id()); + QCOMPARE(b.description(), QString("Two changed description")); + + // 3) Remove a description + QOrganizerItemDescription desc = items[1].detail<QOrganizerItemDescription>(); + QVERIFY(items[1].removeDetail(&desc)); + // Mask it out, so it shouldn't work. + QVERIFY(cm->saveItems(&items, QStringList(QOrganizerEventTime::DefinitionName))); + QVERIFY(cm->errorMap().isEmpty()); + b = cm->item(originalItems[1].id()); + QCOMPARE(b.details<QOrganizerItemDescription>().count(), 1); + // Now include it in the mask + QVERIFY(cm->saveItems(&items, QStringList(QOrganizerItemDescription::DefinitionName))); + QVERIFY(cm->errorMap().isEmpty()); + b = cm->item(originalItems[1].id()); + QCOMPARE(b.details<QOrganizerItemDescription>().count(), 0); + + // 4 - New item, no details in the mask + QOrganizerItem newItem = originalItems[3]; + newItem.setId(QOrganizerItemId()); + + items.append(newItem); // this is items[4] + QVERIFY(cm->saveItems(&items, QStringList(QOrganizerItemTag::DefinitionName))); + QVERIFY(cm->errorMap().isEmpty()); + QVERIFY(!items[4].id().isNull()); // Saved + b = cm->item(items[4].id()); + QCOMPARE(b.details<QOrganizerItemDisplayLabel>().count(), 0); // not saved + QCOMPARE(b.details<QOrganizerEventTime>().count(), 0); // not saved + + // 5 - New item, some details in the mask + newItem = originalItems[2]; + newItem.setId(QOrganizerItemId()); + items.append(newItem); // this is items[5] + QVERIFY(cm->saveItems(&items, QStringList(QOrganizerItemDisplayLabel::DefinitionName))); + QVERIFY(cm->errorMap().isEmpty()); + QVERIFY(!items[5].id().isNull()); // Saved + b = cm->item(items[5].id()); + QCOMPARE(b.details<QOrganizerItemDisplayLabel>().count(), 1); + QCOMPARE(b.details<QOrganizerEventTime>().count(), 0); // not saved + + // 6 Have a non existing item in the middle followed by a save error + cm->removeItem(items[4].id()); + QOrganizerItemDetail badDetail("BadDetail"); + badDetail.setValue("BadField", "BadValue"); + items[5].saveDetail(&badDetail); + QVERIFY(!cm->saveItems(&items, QStringList("BadDetail"))); + QMap<int, QOrganizerManager::Error> errorMap = cm->errorMap(); + QCOMPARE(errorMap.count(), 2); + QCOMPARE(errorMap[4], QOrganizerManager::DoesNotExistError); + QCOMPARE(errorMap[5], QOrganizerManager::InvalidDetailError); +} + void tst_QOrganizerManager::dateRange() { QFETCH(QOrganizerItem, item); |