|
1 /* |
|
2 * Copyright (c) 2005 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: Create attribute list transaction handler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPEngAttributeListTransCreateAttrList.h" |
|
21 |
|
22 #include "CPEngAttributeListItem.h" |
|
23 #include "PEngListLibTools.h" |
|
24 #include "MPEngXMLSerializer.h" |
|
25 #include "MPEngXMLParser.h" |
|
26 #include "CPEngTransactionStatus.h" |
|
27 #include "PEngWVPresenceErrors2.h" |
|
28 #include "PEngAttrLibFactory.h" |
|
29 #include "MPEngPresenceAttrManager.h" |
|
30 #include "MPEngAttributeListTransactionManager.h" |
|
31 #include "MPEngTransactionFactory.h" |
|
32 |
|
33 #include <e32std.h> |
|
34 |
|
35 |
|
36 // ============================ MEMBER FUNCTIONS =============================== |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CPEngAttributeListTransCreateAttrList::CPEngAttributeListTransCreateAttrList() |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CPEngAttributeListTransCreateAttrList::CPEngAttributeListTransCreateAttrList( |
|
43 MPEngAttributeListTransactionManager& aAttrListTransManager, |
|
44 CPEngContactListTransactionManager& aCntListTransManager, |
|
45 MPEngPresenceAttrManager& aPresenceAttributeManager, |
|
46 TPEngWVCspVersion& aCSPVersion, |
|
47 TInt aOperationId, |
|
48 TBool aSync ) |
|
49 : CPEngAttributeListTransBase( aAttrListTransManager, |
|
50 aCntListTransManager, |
|
51 aCSPVersion, |
|
52 aOperationId ), |
|
53 iPresenceAttributeManager( aPresenceAttributeManager ), |
|
54 iSynchronization ( aSync ) |
|
55 { |
|
56 } |
|
57 |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CPEngAttributeListTransCreateAttrList::ConstructL() |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 void CPEngAttributeListTransCreateAttrList::ConstructL( |
|
64 const CPEngAttributeListItem& aAttributeListItem ) |
|
65 { |
|
66 CPEngAttributeListTransBase::ConstructL(); |
|
67 iAttributeListItem = CPEngAttributeListItem::NewL( aAttributeListItem ); |
|
68 } |
|
69 |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CPEngAttributeListTransCreateAttrList::NewLC |
|
73 // Two-phased constructor. |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 CPEngAttributeListTransCreateAttrList* CPEngAttributeListTransCreateAttrList::NewLC( |
|
77 const CPEngAttributeListItem& aAttributeListItem, |
|
78 MPEngAttributeListTransactionManager& aAttrListTransManager, |
|
79 CPEngContactListTransactionManager& aCntListTransManager, |
|
80 MPEngPresenceAttrManager& aPresenceAttributeManager, |
|
81 TPEngWVCspVersion& aCSPVersion, |
|
82 TInt aOperationId, |
|
83 TBool aSync ) |
|
84 { |
|
85 CPEngAttributeListTransCreateAttrList* self = |
|
86 new ( ELeave ) CPEngAttributeListTransCreateAttrList( |
|
87 aAttrListTransManager, |
|
88 aCntListTransManager, |
|
89 aPresenceAttributeManager, |
|
90 aCSPVersion, |
|
91 aOperationId, |
|
92 aSync ); |
|
93 |
|
94 CleanupStack::PushL( self ); |
|
95 self->ConstructL( aAttributeListItem ); |
|
96 |
|
97 return self; |
|
98 } |
|
99 |
|
100 |
|
101 // Destructor |
|
102 CPEngAttributeListTransCreateAttrList::~CPEngAttributeListTransCreateAttrList() |
|
103 { |
|
104 delete iAttributeListItem; |
|
105 } |
|
106 |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CPEngAttributeListTransCreateAttrList::RequestL() |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 void CPEngAttributeListTransCreateAttrList::RequestL( TDes8& aSendBuffer ) |
|
113 { |
|
114 aSendBuffer.Zero(); |
|
115 MPEngXMLSerializer* xmlSerializer = CreateXmlSerializerL( aSendBuffer ); |
|
116 CleanupClosePushL( *xmlSerializer ); |
|
117 |
|
118 // <TransactionContent xmlns="http://www.wireless -village.org/TRC1.1"> |
|
119 NListLibTools::AppendTransactionContentTagXmlL( *xmlSerializer, iCSPVersion ); |
|
120 |
|
121 // <CreateAttributeList-Request> |
|
122 xmlSerializer->StartTagL( KCreateAttributeList ); |
|
123 |
|
124 // <PresenceSubList |
|
125 xmlSerializer->StartTagL( KPresenceSubList ); |
|
126 |
|
127 // check if attribute lists is empty, then we append empty standart atrribute's name space |
|
128 if ( 0 == iAttributeListItem->PresenceAttributes().Count() ) |
|
129 { |
|
130 // attribute name space |
|
131 if ( iCSPVersion == EWVCspV11 ) |
|
132 { |
|
133 // xmlns="http://www.wirelessvillage.org/PA1.1" |
|
134 xmlSerializer->AttributeL( KXmlXmlns, KPresenceSubListAttributesNS ); |
|
135 } |
|
136 else |
|
137 { |
|
138 // xmlns="http://www.openmobilealliance.org/DTD/WV-PA1.2" |
|
139 xmlSerializer->AttributeL( KXmlXmlns, KPresenceSubListAttributesNS_CSP12 ); |
|
140 } |
|
141 } |
|
142 else |
|
143 { |
|
144 // xmlns="Name space" |
|
145 // append attribute's namespace according to attributes on the list |
|
146 // Append Attribute name space |
|
147 TPtrC8 attributeName; |
|
148 TPtrC8 attributeNameSpace; |
|
149 User::LeaveIfError( iPresenceAttributeManager.GetAttributeXmlNameAndNameSpace( |
|
150 iAttributeListItem->PresenceAttributes()[0], |
|
151 attributeName, attributeNameSpace ) ); |
|
152 |
|
153 xmlSerializer->AttributeL( KXmlXmlns, attributeNameSpace ); |
|
154 |
|
155 // Append attributes one by one |
|
156 TInt count ( iAttributeListItem->PresenceAttributes().Count() ); |
|
157 for ( TInt x( 0 ) ; x < count ; x++ ) |
|
158 { |
|
159 User::LeaveIfError( iPresenceAttributeManager.GetAttributeXmlNameAndNameSpace( |
|
160 iAttributeListItem->PresenceAttributes()[x], |
|
161 attributeName, attributeNameSpace ) ); |
|
162 // append attribute name |
|
163 xmlSerializer->StartTagL( attributeName ).EndTagL( attributeName ); |
|
164 } |
|
165 } |
|
166 |
|
167 //</PresenceSubList> |
|
168 xmlSerializer->EndTagL( KPresenceSubList ); |
|
169 |
|
170 // now it depends if this is synchronization handler or not |
|
171 if ( iSynchronization ) |
|
172 { |
|
173 // this us sync handler, |
|
174 // all settings are taken from current and new at the same time |
|
175 XMLAppendContactIdsL( *xmlSerializer, iAttributeListItem->ArrayOfContacts( |
|
176 CPEngAttributeListItem::ECurrentContactIDs ) ); |
|
177 |
|
178 XMLAppendContactIdsL( *xmlSerializer, iAttributeListItem->ArrayOfContacts( |
|
179 CPEngAttributeListItem::ENewContactIDs ) ); |
|
180 |
|
181 XMLAppendContactListsL( *xmlSerializer, iAttributeListItem->ArrayOfContacts( |
|
182 CPEngAttributeListItem::ECurrentContactLists ) ); |
|
183 |
|
184 XMLAppendContactListsL( *xmlSerializer, iAttributeListItem->ArrayOfContacts( |
|
185 CPEngAttributeListItem::ENewContactLists ) ); |
|
186 |
|
187 XMLAppendDefaultFlagL( *xmlSerializer, iAttributeListItem->CurrentlyDefault() ); |
|
188 } |
|
189 else |
|
190 { |
|
191 // this is update handler so settings are taken from new |
|
192 XMLAppendContactIdsL( *xmlSerializer, iAttributeListItem->ArrayOfContacts( |
|
193 CPEngAttributeListItem::ENewContactIDs ) ); |
|
194 |
|
195 XMLAppendContactListsL( *xmlSerializer, iAttributeListItem->ArrayOfContacts( |
|
196 CPEngAttributeListItem::ENewContactLists ) ); |
|
197 |
|
198 XMLAppendDefaultFlagL( *xmlSerializer, iAttributeListItem->NewDefault() ); |
|
199 } |
|
200 |
|
201 // </CreateAttributeList-Request> |
|
202 // </TransactionContent> |
|
203 xmlSerializer->EndTagL( KCreateAttributeList |
|
204 ).EndTagL( KTransactionContent ); |
|
205 CleanupStack::PopAndDestroy( ); // xmlSerializer |
|
206 } |
|
207 |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CPEngAttributeListTransCreateAttrList::ConsumeMessageFromServerL() |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 void CPEngAttributeListTransCreateAttrList::DoConsumeMessageFromServerL( |
|
214 const TDesC8& aResponse ) |
|
215 { |
|
216 MPEngXMLParser* XMLparser = CreateXMLParserLC(); |
|
217 // try if there were some errors |
|
218 TInt err ( XMLparser->ParseResultL( aResponse, iOperationId, *iTransactionStatus ) ); |
|
219 RArray<TUint32> wrongAttributes; |
|
220 CleanupClosePushL( wrongAttributes ); |
|
221 switch ( err ) |
|
222 { |
|
223 case KErrNone: |
|
224 { |
|
225 // successful operation, all went fine, process according to it |
|
226 // if this was synchronization, just mark those attr list as in sync |
|
227 if ( iSynchronization ) |
|
228 { |
|
229 iAttributeListTransManager.AttributeListCreated( iAttributeListItem->PresenceAttributes() ); |
|
230 } |
|
231 else |
|
232 { |
|
233 // since we have copy of the Attribute list item, just commit it |
|
234 iAttributeListTransManager.CommitDefinedContactsL( |
|
235 &iAttributeListItem->ArrayOfContacts( CPEngAttributeListItem::ENewContactLists ), |
|
236 &iAttributeListItem->ArrayOfContacts( CPEngAttributeListItem::ENewContactIDs ) ); |
|
237 |
|
238 if ( iAttributeListItem->NewDefault() ) |
|
239 { |
|
240 iAttributeListTransManager.CommitDefaultL(); |
|
241 } |
|
242 } |
|
243 break; |
|
244 } |
|
245 |
|
246 case KPEngNwErrPartiallySuccessful: |
|
247 { |
|
248 // partial success, figure what went fine and what went OK |
|
249 // we are interested in failed WV IDs, contact list and attributes |
|
250 // anyhow we managed to create attr list |
|
251 if ( iSynchronization ) |
|
252 { |
|
253 iAttributeListTransManager.AttributeListCreated( iAttributeListItem->PresenceAttributes() ); |
|
254 } |
|
255 |
|
256 TInt count ( iTransactionStatus->DetailedResultCount() ); |
|
257 for ( TInt x ( 0 ) ; x < count ; x++ ) |
|
258 { |
|
259 const MPEngDetailedResultEntry2& detailedResult = iTransactionStatus->DetailedResult( x ); |
|
260 |
|
261 switch ( detailedResult.Error() ) |
|
262 { |
|
263 case KPEngNwErrUnknownUser: |
|
264 { |
|
265 // rollback wrong WV ID |
|
266 TPtrC wrongWVWID; |
|
267 detailedResult.GetDetailedDesc( wrongWVWID, EPEngDTPresenceID ); |
|
268 iAttributeListTransManager.RollBackContactIdL( wrongWVWID ); |
|
269 break; |
|
270 } |
|
271 |
|
272 case KPEngNwErrContactListDoesNotExist: |
|
273 { |
|
274 // rollback wrong cnt list |
|
275 TPtrC wrongCntList; |
|
276 detailedResult.GetDetailedDesc( wrongCntList, EPEngDTContactListID ); |
|
277 iAttributeListTransManager.RollBackContactListL( wrongCntList ); |
|
278 break; |
|
279 } |
|
280 |
|
281 case KPEngNwErrInvalidOrUnSupportedPresenceAttribute: |
|
282 { |
|
283 TUint32 wrongAttrib; |
|
284 detailedResult.GetDetailedInt( wrongAttrib, EPEngDIAttributeID ); |
|
285 wrongAttributes.AppendL( wrongAttrib ); |
|
286 break; |
|
287 } |
|
288 |
|
289 default: |
|
290 { |
|
291 } |
|
292 } |
|
293 } |
|
294 break; |
|
295 } |
|
296 |
|
297 case KPEngNwErrUnknownUser: |
|
298 case KPEngNwErrContactListDoesNotExist: |
|
299 { |
|
300 // none of the IDs/cnts list was added, |
|
301 //remove them from the delta list of the attribute list |
|
302 iAttributeListTransManager.RollBackDefinedContactsL( |
|
303 &iAttributeListItem->ArrayOfContacts( CPEngAttributeListItem::ENewContactLists ) , |
|
304 &iAttributeListItem->ArrayOfContacts( CPEngAttributeListItem::ENewContactIDs ) ); |
|
305 |
|
306 // it this was sync, roll back also current |
|
307 if ( iSynchronization ) |
|
308 { |
|
309 iAttributeListTransManager.RollBackDefinedContactsL( |
|
310 &iAttributeListItem->ArrayOfContacts( CPEngAttributeListItem::ECurrentContactLists ) , |
|
311 &iAttributeListItem->ArrayOfContacts( CPEngAttributeListItem::ECurrentContactIDs ) ); |
|
312 |
|
313 } |
|
314 |
|
315 if ( iAttributeListItem->NewDefault() ) |
|
316 { |
|
317 iAttributeListTransManager.RollBackDefaultL(); |
|
318 } |
|
319 } |
|
320 |
|
321 // handle all folllowing errors in the same, default, way |
|
322 case KPEngNwErrInvalidOrUnSupportedPresenceAttribute: |
|
323 default: |
|
324 { |
|
325 if ( iAttributeListItem->NewDefault() ) |
|
326 { |
|
327 iAttributeListTransManager.RollBackDefaultL(); |
|
328 } |
|
329 break; |
|
330 } |
|
331 } |
|
332 |
|
333 // store changes and continue |
|
334 iAttributeListTransManager.StoreChangesToStoreL(); |
|
335 CleanupStack::PopAndDestroy( 2 ); // wrongAttributes, XMLparser |
|
336 |
|
337 if ( iSynchronization ) |
|
338 { |
|
339 iAttributeListTransManager.AttributeEngineSynchronizedL(); |
|
340 } |
|
341 } |
|
342 |
|
343 // End of File |
|
344 |