Navigation Menu

Skip to content

Commit

Permalink
Fix - Conflict set to N95:Calendar entry is deleted in N95
Browse files Browse the repository at this point in the history
when modified a calendar entry in N95 and deleted the same in DUT
	modified:   debian/changelog
	modified:   src/CommandHandler.cpp
	modified:   src/StorageHandler.cpp
	modified:   src/StorageHandler.h
	modified:   tests_meego/CommandHandlerTest.cpp
	modified:   tests_meego/CommandHandlerTest.h
	modified:   tests_meego/StorageHandlerTest.cpp
	modified:   tests_meego/StorageHandlerTest.h
  • Loading branch information
Duggirala Karthik committed Dec 2, 2010
1 parent 2baa29b commit c4ce210
Show file tree
Hide file tree
Showing 8 changed files with 495 additions and 119 deletions.
9 changes: 8 additions & 1 deletion debian/changelog
@@ -1,8 +1,15 @@
libmeegosyncml (0.4.9-51) unstable; urgency=low

* Fixes: NB#203771 Conflict set to N95:Calendar entry is deleted in N95
when modified a calendar entry in N95 and deleted the same in DUT

-- Santosh Puranik <santosh.puranik@nokia.com> Thu, 02 Dec 2010 15:14:00 +0530

libmeegosyncml (0.4.9-50) unstable; urgency=low

* Fix tests.xml

-- Santoh Puranik <santosh.puranik@nokia.com> Wed, 01 Dec 2010 15:14:00 +0530
-- Santosh Puranik <santosh.puranik@nokia.com> Wed, 01 Dec 2010 15:14:00 +0530

libmeegosyncml (0.4.9-49) unstable; urgency=low

Expand Down
27 changes: 23 additions & 4 deletions src/CommandHandler.cpp
Expand Up @@ -364,7 +364,7 @@ void CommandHandler::composeBatches( const SyncParams& aSyncParams, SyncTarget&
LOG_WARNING( "No size found for large object:" << id.iCmdId
<<"/" << id.iItemIndex );
}
if( !aStorageHandler.startLargeObjectAdd( *aTarget.getPlugin(), remoteKey,
if( !aStorageHandler.startLargeObjectAdd( *aTarget.getPlugin(), remoteKey,
parentKey, type, format,
version, item.meta.size ) ) {
aResponses.insert( id, COMMAND_FAILED );
Expand Down Expand Up @@ -409,7 +409,7 @@ void CommandHandler::composeBatches( const SyncParams& aSyncParams, SyncTarget&

}
// Normal object
else if( !aStorageHandler.addItem( id, *aTarget.getPlugin(), parentKey,
else if( !aStorageHandler.addItem( id, *aTarget.getPlugin(), QString(), parentKey,
type, format, version, item.data ) ) {
aResponses.insert( id, COMMAND_FAILED );
}
Expand Down Expand Up @@ -591,10 +591,29 @@ void CommandHandler::commitBatches( StorageHandler& aStorageHandler, ConflictRes

const CommitResult& result = results.value( id );

if( result.iStatus == COMMIT_ADDED ) {
if( result.iStatus == COMMIT_ADDED || result.iStatus == COMMIT_INIT_ADD) {

statusCode = ITEM_ADDED;
if( result.iConflict == CONFLICT_LOCAL_WIN ) {

if( iRole == ROLE_CLIENT ) {
statusCode = RESOLVED_CLIENT_WINNING;
}
else {
statusCode = RESOLVED_WITH_SERVER_DATA;
}
}
else if( result.iConflict == CONFLICT_REMOTE_WIN ) {

if( iRole == ROLE_CLIENT ) {
statusCode = RESOLVED_WITH_SERVER_DATA;
}
else {
statusCode = RESOLVED_CLIENT_WINNING;
}
}
else {
statusCode = ITEM_ADDED;
}
UIDMapping map;
map.iRemoteUID = item.source;
map.iLocalUID = result.iItemKey;
Expand Down
226 changes: 113 additions & 113 deletions src/StorageHandler.cpp
Expand Up @@ -63,6 +63,7 @@ StorageHandler::~StorageHandler()

bool StorageHandler::addItem( const ItemId& aItemId,
StoragePlugin& aPlugin,
const SyncItemKey& aLocalKey,
const SyncItemKey& aParentKey,
const QString& aType,
const QString& aFormat,
Expand All @@ -86,7 +87,7 @@ bool StorageHandler::addItem( const ItemId& aItemId,
}

//Setting empty string as we dont have any local key for it.
newItem->setKey(QString());
newItem->setKey( aLocalKey );
newItem->setParentKey( aParentKey );
newItem->setType( aType );
newItem->setFormat( aFormat );
Expand Down Expand Up @@ -132,7 +133,7 @@ bool StorageHandler::replaceItem( const ItemId& aItemId,

if( !item ) {
LOG_DEBUG( "Could not find item, processing as Add" );
return addItem( aItemId, aPlugin, aParentKey, aType, aFormat, aVersion, aData );
return addItem( aItemId, aPlugin, aLocalKey, aParentKey, aType, aFormat, aVersion, aData );
}

item->setParentKey( aParentKey );
Expand Down Expand Up @@ -317,10 +318,12 @@ bool StorageHandler::finishLargeObject( const ItemId& aItemId )

if(iLargeObject->getKey()->isEmpty()) {
LOG_DEBUG( "Queuing large object for addition" );
iLargeObject->setKey(iLargeObjectKey);
iAddList.insert( aItemId, iLargeObject );
}
else {
LOG_DEBUG( "Queuing large object for replace" );
iLargeObject->setKey(iLargeObjectKey);
iReplaceList.insert( aItemId, iLargeObject );
}

Expand All @@ -332,28 +335,114 @@ bool StorageHandler::finishLargeObject( const ItemId& aItemId )

}

QMap<ItemId, CommitResult> StorageHandler::commitAddedItems( StoragePlugin& aPlugin,
ConflictResolver* aConflictResolver )
QMap<ItemId, CommitResult> StorageHandler::resolveConflicts( ConflictResolver* aConflictResolver,
QMap<ItemId, SyncItemKey> &aMap,
CommitStatus aStatus )
{
FUNCTION_CALL_TRACE;
QMutableMapIterator<ItemId, SyncItemKey> i(aMap);


QMutableMapIterator<ItemId, SyncItem*> i( iAddList );

QMap<ItemId, CommitResult> results;
ItemId iId;
while( i.hasNext() ) {
i.next();
// If we fail to find a sync item with local key for replace we add it as
// a new item ; one reason is that the item has been deleted locally if so
// its a conflict
if ( aConflictResolver && aConflictResolver->isConflict(*i.value()->getKey(), false) ) {
LOG_DEBUG ("Move to Replace List :" << *i.value()->getKey());
iReplaceList.insert( i.key(), i.value() );
i.remove();
}

i.next();

CommitResult result;

result.iItemKey = i.value();

result.iStatus = aStatus;

iId.iCmdId = i.key().iCmdId;
iId.iItemIndex = i.key().iItemIndex;

LOG_DEBUG( "Checking item" << iId.iCmdId <<"/" << iId.iItemIndex << "for conflict" );

if( aConflictResolver && aConflictResolver->isConflict( result.iItemKey, false ) ) {

LOG_DEBUG( "Conflict detected" );

if( aConflictResolver->localSideWins() ) {
LOG_DEBUG( "Conflict resolved, local side wins" );
result.iConflict = CONFLICT_LOCAL_WIN;
aConflictResolver->revertLocalChange ( result.iItemKey, CR_MODIFY_TO_ADD );
i.remove();
}
else {
LOG_DEBUG( "Conflict resolved, remote side wins" );
result.iConflict = CONFLICT_REMOTE_WIN;
aConflictResolver->revertLocalChange ( result.iItemKey, CR_REMOVE_LOCAL );
}
}
else {
LOG_DEBUG( "No conflict detected" );
result.iConflict = CONFLICT_NO_CONFLICT;
}

results.insert( iId, result );

}

return results;
}

QMap<ItemId, CommitResult> StorageHandler::resolveConflicts( ConflictResolver* aConflictResolver,
QMap<ItemId, SyncItem*> &aMap,
CommitStatus aStatus )
{
FUNCTION_CALL_TRACE;
QMap<ItemId, CommitResult> results;
ItemId iId;

QMutableMapIterator<ItemId, SyncItem*> i(aMap);
while( i.hasNext() ) {

i.next();

CommitResult result;

result.iItemKey = *i.value()->getKey();

result.iStatus = aStatus;

iId.iCmdId = i.key().iCmdId;
iId.iItemIndex = i.key().iItemIndex;

LOG_DEBUG( "Checking item" << iId.iCmdId <<"/" << iId.iItemIndex << "for conflict" );

if( aConflictResolver && aConflictResolver->isConflict( result.iItemKey, false ) ) {

LOG_DEBUG( "Conflict detected" );

if( aConflictResolver->localSideWins() ) {
LOG_DEBUG( "Conflict resolved, local side wins" );
result.iConflict = CONFLICT_LOCAL_WIN;
delete i.value();
i.remove();
}
else {
LOG_DEBUG( "Conflict resolved, remote side wins" );
result.iConflict = CONFLICT_REMOTE_WIN;
aConflictResolver->revertLocalChange ( result.iItemKey, CR_REMOVE_LOCAL );
}
}
else {
LOG_DEBUG( "No conflict detected" );
result.iConflict = CONFLICT_NO_CONFLICT;
}

results.insert( iId, result );

}
return results;
}

QMap<ItemId, CommitResult> StorageHandler::commitAddedItems( StoragePlugin& aPlugin,
ConflictResolver* aConflictResolver )
{
FUNCTION_CALL_TRACE;

QMap<ItemId, CommitResult> results = resolveConflicts (aConflictResolver, iAddList, COMMIT_INIT_ADD);
QList<ItemId> addIds = iAddList.keys();
QList<SyncItem*> addItems = iAddList.values();

Expand All @@ -363,11 +452,10 @@ QMap<ItemId, CommitResult> StorageHandler::commitAddedItems( StoragePlugin& aPlu

for( int i = 0; i < addStatus.count(); ++i ) {

CommitResult result;
CommitResult& result = results[addIds[i]];
result.iItemKey = *addItems[i]->getKey();
result.iConflict = CONFLICT_NO_CONFLICT;

LOG_DEBUG( "Item" << addIds[i].iCmdId << "/" << addIds[i].iItemIndex << "committed" );

LOG_DEBUG( "Item" << addIds[i].iCmdId << "/" << addIds[i].iItemIndex << "committed" );

switch( addStatus[i] )
{
Expand All @@ -376,8 +464,8 @@ QMap<ItemId, CommitResult> StorageHandler::commitAddedItems( StoragePlugin& aPlu
{
LOG_DEBUG( "Commit result: COMMIT_ADDED" );
result.iStatus = COMMIT_ADDED;

emit itemProcessed( MOD_ITEM_ADDED, MOD_LOCAL_DATABASE,
emit itemProcessed( MOD_ITEM_ADDED, MOD_LOCAL_DATABASE,
aPlugin.getSourceURI() , addItems[i]->getType(), addItems.count() );

break;
Expand Down Expand Up @@ -419,50 +507,7 @@ QMap<ItemId, CommitResult> StorageHandler::commitReplacedItems( StoragePlugin& a
{
FUNCTION_CALL_TRACE;

QMap<ItemId, CommitResult> results;

QMutableMapIterator<ItemId, SyncItem*> i( iReplaceList );

ItemId iId;

while( i.hasNext() ) {

i.next();

CommitResult result;

result.iItemKey = *i.value()->getKey();
result.iStatus = COMMIT_INIT_REPLACE;

iId.iCmdId = i.key().iCmdId;
iId.iItemIndex = i.key().iItemIndex;

LOG_DEBUG( "Checking item" << iId.iCmdId <<"/" << iId.iItemIndex << "for conflict" );

if( aConflictResolver && aConflictResolver->isConflict( *i.value()->getKey(), false ) ) {

LOG_DEBUG( "Conflict detected" );

if( aConflictResolver->localSideWins() ) {
LOG_DEBUG( "Conflict resolved, local side wins" );
result.iConflict = CONFLICT_LOCAL_WIN;
delete i.value();
i.remove();
}
else {
LOG_DEBUG( "Conflict resolved, remote side wins" );
result.iConflict = CONFLICT_REMOTE_WIN;
aConflictResolver->revertLocalChange ( result.iItemKey, CR_REMOVE_LOCAL );
}
}
else {
LOG_DEBUG( "No conflict detected" );
result.iConflict = CONFLICT_NO_CONFLICT;
}

results.insert( iId, result );

}
QMap<ItemId, CommitResult> results = resolveConflicts (aConflictResolver, iReplaceList, COMMIT_INIT_REPLACE);

QList<ItemId> replaceIds = iReplaceList.keys();
QList<SyncItem*> replaceItems = iReplaceList.values();
Expand All @@ -474,7 +519,6 @@ QMap<ItemId, CommitResult> StorageHandler::commitReplacedItems( StoragePlugin& a
for( int i = 0; i < replaceStatus.count(); ++i ) {

CommitResult& result = results[replaceIds[i]];

LOG_DEBUG( "Item" << replaceIds[i].iCmdId << "/" << replaceIds[i].iItemIndex << "committed" );

switch( replaceStatus[i] )
Expand Down Expand Up @@ -526,51 +570,7 @@ QMap<ItemId, CommitResult> StorageHandler::commitDeletedItems( StoragePlugin& aP
{
FUNCTION_CALL_TRACE;

QMap<ItemId, CommitResult> results;

QMutableMapIterator<ItemId, SyncItemKey> i( iDeleteList );

ItemId iId;

while( i.hasNext() ) {

i.next();

CommitResult result;

result.iItemKey = i.value();
result.iStatus = COMMIT_INIT_DELETE;

iId.iCmdId = i.key().iCmdId;
iId.iItemIndex = i.key().iItemIndex;

LOG_DEBUG( "Checking item" << iId.iCmdId <<"/" << iId.iItemIndex << "for conflict" );

if( aConflictResolver && aConflictResolver->isConflict( i.value(), true ) ) {

LOG_DEBUG( "Conflict detected" );

if( aConflictResolver->localSideWins() ) {
LOG_DEBUG( "Conflict resolved, local side wins" );
result.iConflict = CONFLICT_LOCAL_WIN;
aConflictResolver->revertLocalChange ( result.iItemKey, CR_MODIFY_TO_ADD );
i.remove();
}
else {
LOG_DEBUG( "Conflict resolved, remote side wins" );
result.iConflict = CONFLICT_REMOTE_WIN;
aConflictResolver->revertLocalChange ( result.iItemKey, CR_REMOVE_LOCAL );
}
}
else {
LOG_DEBUG( "No conflict detected" );
result.iConflict = CONFLICT_NO_CONFLICT;
}

results.insert( iId, result );

}

QMap<ItemId, CommitResult> results = resolveConflicts (aConflictResolver, iDeleteList, COMMIT_INIT_DELETE);
QList<ItemId> deleteIds = iDeleteList.keys();
QList<SyncItemKey> deleteItems = iDeleteList.values();

Expand Down

0 comments on commit c4ce210

Please sign in to comment.