67 */ |
72 */ |
68 QString DataStoreManager::getErrorText() const{ |
73 QString DataStoreManager::getErrorText() const{ |
69 return lastMsg; |
74 return lastMsg; |
70 } |
75 } |
71 |
76 |
72 SmfRelationId DataStoreManager::create(SmfProvider *aProvider, SmfContact *aContact) |
77 SmfError DataStoreManager::create(SmfRelationId &aRelationId,SmfProvider *aProvider, SmfContact *aContact) |
73 { |
78 { |
|
79 SmfError err = SmfNoError; |
|
80 aRelationId.clear(); |
74 if(NULL == aProvider || NULL == aContact) |
81 if(NULL == aProvider || NULL == aContact) |
75 return QString::number(-1);//SmfUnknownError |
82 return SmfUnknownError;//SmfUnknownError |
76 |
83 |
77 QString userId, contactUrl, localId, managerUri, presenceState, presenceText, statusText; |
84 QString userId, contactUrl, localId, managerUri, presenceState, presenceText, statusText; |
78 QDateTime dateTime; |
85 QDateTime dateTime; |
79 Int64 timeStampInSeconds; |
86 Int64 timeStampInSeconds; |
80 |
87 |
115 qDebug()<<"Inside Test DSM Create: snsName"<<snsName; |
122 qDebug()<<"Inside Test DSM Create: snsName"<<snsName; |
116 qDebug()<<"Inside Test DSM Create: snsUrl"<<snsUrl; |
123 qDebug()<<"Inside Test DSM Create: snsUrl"<<snsUrl; |
117 qDebug()<<"Inside Test DSM Create: snsDesc"<<snsDesc; |
124 qDebug()<<"Inside Test DSM Create: snsDesc"<<snsDesc; |
118 |
125 |
119 |
126 |
120 |
127 int contactID; |
121 const int contactID = addContactToTable(userId, contactUrl, localId, managerUri, snsName, snsDesc, snsUrl, presenceState, presenceText , statusText, timeStampInSeconds); |
128 err = addContactToTable(contactID,userId, contactUrl, localId, managerUri, snsName, snsDesc, snsUrl, presenceState, presenceText , statusText, timeStampInSeconds); |
122 if(!(contactIfExist(contactID))) |
129 if(SmfNoError == err) |
123 return QString::number(-1); |
130 { |
124 return QString::number( addRelationToTable( contactID ) ); |
131 QString cntcId(QString::number(addRelationToTable(contactID))); |
|
132 aRelationId.append(cntcId); |
|
133 } |
|
134 return err; |
|
135 |
|
136 //return QString::number( addRelationToTable( contactID ) ); |
125 } |
137 } |
126 |
138 |
127 SmfError DataStoreManager::associate( SmfRelationId aPhoneId, |
139 SmfError DataStoreManager::associate( SmfRelationId aPhoneId, |
128 const SmfContact* aContact, |
140 const SmfContact* aContact, |
129 SmfProvider* aProvider){ |
141 SmfProvider* aProvider){ |
|
142 SmfError err = SmfNoError; |
130 if(NULL == aProvider || NULL == aContact) |
143 if(NULL == aProvider || NULL == aContact) |
131 return SmfError(-1);//SmfUnknownError |
144 return SmfError(-1);//SmfUnknownError |
132 |
145 |
133 if( ! relationIfExist( aPhoneId.toInt()) ) |
146 if( ! relationIfExist( aPhoneId.toInt()) ) |
134 return SmfErrInvalidRelation; |
147 return SmfErrInvalidRelation; |
163 |
176 |
164 qDebug()<<"Inside Test DSM Associate: snsName"<<snsName; |
177 qDebug()<<"Inside Test DSM Associate: snsName"<<snsName; |
165 qDebug()<<"Inside Test DSM Associate: snsUrl"<<snsUrl; |
178 qDebug()<<"Inside Test DSM Associate: snsUrl"<<snsUrl; |
166 qDebug()<<"Inside Test DSM Associate: snsDesc"<<snsDesc; |
179 qDebug()<<"Inside Test DSM Associate: snsDesc"<<snsDesc; |
167 |
180 |
168 const int contactID = addContactToTable(userId, contactUrl, localId, managerUri, snsName, snsDesc, snsUrl, presenceState, presenceText , statusText, timeStampInSeconds); |
181 int contactID; |
|
182 err = addContactToTable(contactID,userId, contactUrl, localId, managerUri, snsName, snsDesc, snsUrl, presenceState, presenceText , statusText, timeStampInSeconds); |
|
183 if(SmfNoError == err) |
|
184 { |
169 TInt Id = addRelationToTable( contactID, aPhoneId.toInt()); |
185 TInt Id = addRelationToTable( contactID, aPhoneId.toInt()); |
170 if(Id == aPhoneId.toInt()) |
186 if(Id == aPhoneId.toInt()) |
171 return SmfNoError ; |
187 err = SmfNoError ; |
172 else |
188 else |
173 return SmfDbOpeningError; |
189 err = SmfDbOpeningError; |
|
190 } |
|
191 return err; |
174 } |
192 } |
175 |
193 |
176 /** remove contact from a relation */ |
194 /** remove contact from a relation */ |
177 SmfError DataStoreManager::remove(SmfRelationId aRelation, const SmfContact* aContact){ |
195 SmfError DataStoreManager::remove(SmfRelationId aRelation, const SmfContact* aContact){ |
178 |
196 |
665 db.close(); |
683 db.close(); |
666 return contactId; |
684 return contactId; |
667 |
685 |
668 } |
686 } |
669 |
687 |
670 int DataStoreManager::addContactToTable(const QString &aUserId, |
688 SmfError DataStoreManager::addContactToTable (int &aContactId, |
|
689 const QString &aUserId, |
671 const QString &aContactUrl, |
690 const QString &aContactUrl, |
672 const QString &aLocalId, |
691 const QString &aLocalId, |
673 const QString &aManagerUri, |
692 const QString &aManagerUri, |
674 const QString &aSnsName, |
693 const QString &aSnsName, |
675 const QString &aSnsDesc, |
694 const QString &aSnsDesc, |
677 const QString &aPresenceState, |
696 const QString &aPresenceState, |
678 const QString &aPresenceText, |
697 const QString &aPresenceText, |
679 const QString &aStatusText, |
698 const QString &aStatusText, |
680 const Int64 aTimeStamp ){ |
699 const Int64 aTimeStamp ){ |
681 |
700 |
682 int contactId; |
701 SmfError err = SmfNoError; |
|
702 |
|
703 if(contactIfExist(aUserId,aSnsName)) |
|
704 return SmfContactExists; |
|
705 |
|
706 if(aUserId.isEmpty() || aUserId.isNull()) |
|
707 return SmfInvalidGuid; |
|
708 |
|
709 if(aContactUrl.isEmpty() || aContactUrl.isNull()) |
|
710 return SmfInvalidContactUrl; |
|
711 |
|
712 if(aLocalId.isEmpty() || aLocalId.isNull()) |
|
713 return SmfInvalidContactUrl; |
683 |
714 |
684 if(SmfDbOpeningError == openDB()) |
715 if(SmfDbOpeningError == openDB()) |
685 return SmfDbOpeningError; |
716 return SmfDbOpeningError; |
686 |
717 |
687 QSqlQuery qry; |
718 QSqlQuery qry; |
713 |
744 |
714 if(SmfDbQueryExecutonError == executeQuery(qry)) |
745 if(SmfDbQueryExecutonError == executeQuery(qry)) |
715 return SmfDbQueryExecutonError; |
746 return SmfDbQueryExecutonError; |
716 |
747 |
717 if(qry.next()){ |
748 if(qry.next()){ |
718 contactId = qry.value(0).toInt(); |
749 aContactId = qry.value(0).toInt(); |
719 } |
750 } |
720 |
751 |
721 qry.finish(); |
752 qry.finish(); |
722 db.close(); |
753 db.close(); |
723 return contactId; |
754 return err; |
724 } |
755 } |
725 |
756 |
726 SmfError DataStoreManager::removeContactFromTable(const int aContactId){ |
757 SmfError DataStoreManager::removeContactFromTable(const int aContactId){ |
727 |
758 |
728 if(SmfDbOpeningError == openDB()) |
759 if(SmfDbOpeningError == openDB()) |
740 |
771 |
741 return SmfNoError; |
772 return SmfNoError; |
742 } |
773 } |
743 |
774 |
744 |
775 |
745 |
776 TBool DataStoreManager::contactIfExist( const QString &userId,const QString &snsName){ |
746 TBool DataStoreManager::contactIfExist( const int aContactId){ |
|
747 |
777 |
748 TBool contactExist = EFalse; |
778 TBool contactExist = EFalse; |
749 if(SmfDbOpeningError == openDB()) |
779 if(SmfDbOpeningError == openDB()) |
750 return EFalse; |
780 return EFalse; |
751 |
781 |
752 QSqlQuery qry; |
782 QSqlQuery qry; |
753 TBool queryPep = qry.prepare("SELECT contactId FROM contact WHERE contactId=:contactId"); |
783 TBool queryPep; |
|
784 queryPep = qry.prepare("SELECT userId FROM contact WHERE userId=:userId"); |
754 if(!queryPep) |
785 if(!queryPep) |
755 return EFalse; |
786 return EFalse; |
756 |
787 |
757 qry.bindValue(":contactId", aContactId); |
788 qry.bindValue(":userId", userId); |
758 |
789 |
759 if(SmfDbQueryExecutonError == executeQuery(qry)) |
790 if(SmfDbQueryExecutonError == executeQuery(qry)) |
760 return EFalse; |
791 return EFalse; |
761 |
792 |
762 if( qry.first() ) |
793 if( qry.first() ) |
763 contactExist = ETrue; |
794 contactExist = ETrue; |
764 |
795 |
|
796 if(contactExist){ |
|
797 queryPep = qry.prepare("SELECT userId FROM contact WHERE snsName=:snsName"); |
|
798 if(!queryPep) |
|
799 return EFalse; |
|
800 |
|
801 qry.bindValue(":snsName", snsName); |
|
802 |
|
803 if(SmfDbQueryExecutonError == executeQuery(qry)) |
|
804 return EFalse; |
|
805 |
|
806 if( qry.first() ) |
|
807 contactExist = ETrue; |
|
808 } |
765 qry.finish(); |
809 qry.finish(); |
766 db.close(); |
810 db.close(); |
767 |
811 |
768 return contactExist; |
812 return contactExist; |
|
813 |
769 } |
814 } |
770 |
815 |
771 TBool DataStoreManager::relationIfExist( const int aRelationId){ |
816 TBool DataStoreManager::relationIfExist( const int aRelationId){ |
772 |
817 |
773 TBool contactExist = EFalse; |
818 TBool contactExist = EFalse; |