contentpublishingsrv/contentpublishingutils/contentpublishingmap/inc/cpliwmap.h
branchRCL_3
changeset 114 a5a39a295112
equal deleted inserted replaced
113:0efa10d348c0 114:a5a39a295112
       
     1 /*
       
     2 * Copyright (c) 2008 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:   CCPLiwMap - class used in Content Publisher
       
    15  *
       
    16 */
       
    17 
       
    18 #ifndef C_CPLIWIDSMAP_H
       
    19 #define C_CPLIWIDSMAP_H
       
    20 
       
    21 #include <liwvariant.h>
       
    22 #include <sqldb.h>
       
    23 #include "cpglobals.h"
       
    24 
       
    25 class RDesReadStream;
       
    26 class CCPSecurityPolicy;
       
    27 class TLiwGenericParam;
       
    28 
       
    29 // CLASS DECLARATION
       
    30 /**
       
    31  *  Base Map class for Publisher Registry and Content
       
    32  *
       
    33  *  @lib cputils.dll
       
    34  *  @since S60 v5.0
       
    35  */
       
    36 class CCPLiwMap : public CLiwMap
       
    37     {
       
    38 
       
    39 protected:
       
    40     
       
    41     /**
       
    42      * Enum defining the properties of filter.
       
    43      */
       
    44     enum TCPProperties
       
    45         {
       
    46         EPublisher = 1,
       
    47         EContentType = 2,
       
    48         EContentId = 4,
       
    49         EFlag = 8,
       
    50         };
       
    51 
       
    52     /**
       
    53      * Enum defining the sort ordering.
       
    54      */    
       
    55 	enum TCPSortOrder
       
    56         {
       
    57         ECPRecent = 1, // 0001
       
    58         ECPPublisher  = 2, // 0010
       
    59         ECPContent = 4, // 0100 
       
    60         ECPContentId = 8 // 1000 
       
    61         };   
       
    62 
       
    63 public:
       
    64 
       
    65     friend class CCpStorageEngine;
       
    66 
       
    67     /**
       
    68      * Two-phased constructor.
       
    69      */    
       
    70     IMPORT_C static CCPLiwMap* NewL( RDesReadStream& aStream );
       
    71 
       
    72     /**
       
    73      * Two-phased constructor.
       
    74      */    
       
    75     IMPORT_C static CCPLiwMap* NewL( const CLiwGenericParamList& aList );
       
    76 
       
    77     /**
       
    78      * Two-phased constructor.
       
    79      */    
       
    80     IMPORT_C static CCPLiwMap* NewL( const CLiwMap& aMap );
       
    81     
       
    82     /**
       
    83      * Used by client to serialize this object 
       
    84      *
       
    85      * @return object serialized to binary
       
    86      */
       
    87     IMPORT_C HBufC8* PackForServerLC() const;
       
    88     
       
    89     /**
       
    90      * Reset map
       
    91      */
       
    92     IMPORT_C void Reset( ) const;
       
    93     
       
    94     /**
       
    95      * Leaves when Add data operation is not possible due
       
    96      * to missing of some parameter
       
    97      */
       
    98     virtual void IsValidForAddL( ) const;
       
    99 
       
   100     /**
       
   101      * Leaves when Execute Action operation is not possible due
       
   102      * to missing of some parameter
       
   103      */
       
   104     IMPORT_C void IsValidForActionL( ) const;
       
   105     
       
   106     /**
       
   107      * Leaves when RequestNotification operation is not possible due
       
   108      * to missing of some parameter
       
   109      */
       
   110     IMPORT_C void IsValidForNotificationL( ) const;
       
   111     
       
   112     /**
       
   113      * Fetches value for property(key) from internal map
       
   114      *
       
   115      * @param aProperty name of the property ( key ) 
       
   116      * @param aResult target descriptor for fetching operation
       
   117      * @return ETrue is property found or EFalse if not
       
   118      */
       
   119     IMPORT_C TBool GetPropertyL( const TDesC8& aProperty,
       
   120              RBuf& aResult ) const;
       
   121     
       
   122     /**
       
   123      * Fetches value for property(key) from internal map
       
   124      *
       
   125      * @param aProperty name of the property ( key ) 
       
   126      * @param aResult target binary for fetching operation
       
   127      * @return ETrue is property found or EFalse if not
       
   128      */
       
   129     IMPORT_C TBool GetPropertyL( const TDesC8& aProperty,
       
   130             RBuf8& aResult ) const;
       
   131     
       
   132     /**
       
   133      * Fetches value for property(key) from internal map
       
   134      *
       
   135      * @param aProperty name of the property ( key ) 
       
   136      * @param aResult target integer for fetching operation
       
   137      * @return ETrue is property found or EFalse if not
       
   138      */
       
   139     IMPORT_C TBool GetProperty( const TDesC8& aProperty,
       
   140     		TInt32& aResult ) const;
       
   141 
       
   142 
       
   143     /**
       
   144      * Return list of action triggers from main map
       
   145      * Note that these are not triggers from action map
       
   146      *
       
   147      * @return list of action triggers, NULL if main map 
       
   148      * doesn't have action trigger
       
   149      */
       
   150     IMPORT_C CLiwDefaultList* GetActionTriggersLC( ) const;
       
   151 
       
   152     /**
       
   153      * Setter for security policy 
       
   154      *
       
   155      * @param aPolicy security policy
       
   156      */
       
   157     IMPORT_C void SetSecurityL( const RMessage2& aMessage );
       
   158     
       
   159     /**
       
   160      * Destructor.
       
   161      */
       
   162     virtual ~CCPLiwMap();
       
   163 
       
   164     /**
       
   165      * Check if IDs are valid for Delete operation
       
   166      */
       
   167     virtual void IsValidForDeleteL() const =0;
       
   168     
       
   169     /**
       
   170      * Check if IDs are valid for GetList operation
       
   171      */
       
   172     virtual void IsValidForGetListL() const =0;    
       
   173 
       
   174 	/**
       
   175      *
       
   176      * @return ETrue if supported, EFalse if not
       
   177      */
       
   178 	virtual TBool ActivateActionSupport( ) const = 0;
       
   179 
       
   180 	/**
       
   181      *
       
   182      * @return ETrue if activate flag is set, EFalse if not
       
   183      */
       
   184 	virtual TBool GetActivateInfo( ) const = 0;
       
   185 
       
   186 	
       
   187 public:
       
   188 
       
   189     // from base class CLiwMap
       
   190     /**
       
   191      * Inserts a key-value pair element to the map collection. If
       
   192      * the specified key already exists, it will be removed from
       
   193      * the collection and the new key-value pair will be added to the
       
   194      * map.
       
   195      *  
       
   196      * @param aKey the key to be stored
       
   197      * @param aValue the value associated with the key to be stored
       
   198      */
       
   199     void InsertL( const TDesC8& aKey, const TLiwVariant& aValue );
       
   200 
       
   201     /**
       
   202      * Finds a value stored in the map collection based on the key.
       
   203      *  
       
   204      * @param aKey the key to be searched
       
   205      * @param aFndValue the value associated with the found key
       
   206      * @return false if there is no key stored; true otherwise
       
   207      */
       
   208     TBool FindL( const TDesC8& aKey, TLiwVariant& aValue ) const;
       
   209 
       
   210     /**
       
   211      * Returns the number of key-value pair stored in the map collection.
       
   212      *  
       
   213      * @return the number of key-value pair stored in the map collection
       
   214      */
       
   215     TInt Count() const;
       
   216 
       
   217     /**
       
   218      * Returns the key stored at a specified index. 
       
   219      *  
       
   220      * @param aIndex the index of the key to be found
       
   221      * @param aFndKey the key found at the passed index
       
   222      *
       
   223      * @return true if a key-value entry is found at the passed index;
       
   224      * false otherwise
       
   225      */
       
   226     TBool AtL( TInt aIndex, TDes8& aFndKey ) const;
       
   227 
       
   228     /**
       
   229      * Removes a key from the map collection.
       
   230      *  
       
   231      * @param aKey the key to be removed from the map
       
   232      */
       
   233     void Remove( const TDesC8& aKey );
       
   234 
       
   235     /**
       
   236      * Returns the size of the collection. The size is 
       
   237      * calculated based on the total numer of key-value elements
       
   238      * and the size of each pair in the collection
       
   239      *  
       
   240      * @return the size of the collection
       
   241      */
       
   242     TInt Size() const;
       
   243 
       
   244     /**
       
   245      * The container managed data values can be serialized to an output
       
   246      * stream. 
       
   247      * 
       
   248      * @param aOutputStream the output stream to which the data will be streamed
       
   249      */
       
   250     void ExternalizeL( RWriteStream& aOutputStream ) const;
       
   251 
       
   252 protected:
       
   253 
       
   254     /**
       
   255      * Adds to database current content
       
   256      *  
       
   257      * @param aSqlDb handle to database
       
   258      * @param aNotificationList list of notifications to fill in when 
       
   259      *        something was actually changed in dataabse
       
   260      *
       
   261      * @return id of added entry
       
   262      */
       
   263     virtual TInt32 AddL( RSqlDatabase aSqlDb,
       
   264         CLiwDefaultList* aNotificationList = 0 ) const= 0;
       
   265 
       
   266     /**
       
   267      * Fetches entries from database
       
   268      *  
       
   269      * @param aSqlDb handle to database
       
   270      * @param aList target list for enntries
       
   271      * @param aItemsToDelete ids of entries for removal - 
       
   272      *        they were found to be expired
       
   273      *
       
   274      * @return number of fetched entries
       
   275      */
       
   276     virtual TUint GetListL( RSqlDatabase aSqlDb, CLiwGenericParamList* aList,
       
   277         RArray<TInt32>& aItemsToDelete ) const = 0;
       
   278 
       
   279     /**
       
   280      * Removes entries from database
       
   281      *  
       
   282      * @param aSqlDb handle to database
       
   283      * @param aNotificationList list of notifications to fill in when 
       
   284      *        something was actually changed in dataabse
       
   285      */
       
   286     virtual void RemoveL( RSqlDatabase aSqlDb,
       
   287         CLiwDefaultList* aNotificationList = 0 ) const = 0;
       
   288 
       
   289     /**
       
   290      * Saves results from query to SQLite Server
       
   291      *  
       
   292      * @param aStmt handle to SQL statement
       
   293      * @param aList target list for enntries
       
   294      * @param aItemsToDelete ids of entries for removal - 
       
   295      *        they were found to be expired
       
   296      */
       
   297     virtual void SaveQueryResultsL( RSqlStatement& aStmt,
       
   298         CLiwGenericParamList& aList, RArray<TInt32>& aItemsToDelete ) const = 0;
       
   299 
       
   300     /**
       
   301      * Updates entry in database
       
   302      *  
       
   303      * @param aSqlDb handle to database
       
   304      * @param aNotificationList list of notifications to fill in when 
       
   305      *        something was actually changed in dataabse
       
   306      */
       
   307     virtual void UpdateL( RSqlDatabase aSqlDb, TInt32 aId,
       
   308         CLiwDefaultList* aNotificationList = 0 ) const = 0;
       
   309 
       
   310     /**
       
   311      * Performs actuall add operation
       
   312      *  
       
   313      * @param aSqlDb handle to database
       
   314      * @param aNotificationList list of notifications to fill in when 
       
   315      *        something was actually changed in dataabse
       
   316      *
       
   317      * @return id of added entry
       
   318      */
       
   319     virtual TInt32 AddToDbL( RSqlDatabase aSqlDb,
       
   320         CLiwDefaultList* aNotificationList = 0 ) const = 0;
       
   321 
       
   322     /**
       
   323      * Checks if operation value is proper
       
   324      *  
       
   325      * @param aValue contains operation value
       
   326      */    
       
   327     void IsProperOperationL( const TLiwVariant& aValue ) const;
       
   328     
       
   329     
       
   330     /**
       
   331      * Appends GetList filter as strings to SQL query according to aFilter
       
   332      *  
       
   333      * @param aQuery SQL query
       
   334      * @param aFilter as enum
       
   335      *
       
   336      */
       
   337     void AppendGetListFilterL( RBuf& aQuery, TUint& aFilter ) const;
       
   338     
       
   339     /**
       
   340      * Appends Remove filter as strings to SQL query according to aFilter
       
   341      *  
       
   342      * @param aQuery SQL query
       
   343      * @param aFilter as enum
       
   344      *
       
   345      */
       
   346     void AppendRemoveFilterL( RBuf& aQuery, TUint& aFilter ) const;
       
   347     
       
   348     
       
   349     /**
       
   350      * Appends filter as strings to SQL query according to aFilter
       
   351      *  
       
   352      * @param aQuery SQL query
       
   353      * @param aFilter as enum
       
   354      *
       
   355      */
       
   356     virtual void AppendFilterL( RBuf& aQuery, TUint& aFilter ) const;
       
   357 
       
   358     /**
       
   359      * Prepares SQL query for Add operation
       
   360      *
       
   361      * @param aSqlDb handle to database  
       
   362      * @param aStmt handle to SQL statement
       
   363      * @param aQuery SQL query
       
   364      *
       
   365      */
       
   366     virtual void PrepareStmtforAddL( RSqlDatabase aSqlDb,
       
   367         RSqlStatement& aStmt, const TDesC& aQuery ) const;
       
   368     /**
       
   369      * Appends sorting criteria as strings to SQL query according to aSort
       
   370      *
       
   371      * @param aQuery SQL query
       
   372      * @param aSort sort filter as TInt
       
   373      *
       
   374      */
       
   375     virtual void AppendSortL( RBuf& aQuery, 
       
   376         const TCPSortOrder& aSort ) const = 0;
       
   377 
       
   378     /**
       
   379       * Fills change info map with proper values
       
   380       *aStmt
       
   381       * @param aStmt handle to SQL statement
       
   382       * @param aChangeInfoMap map that will be filed
       
   383       *
       
   384       */
       
   385     virtual void FillChangeInfoMapL( RSqlStatement& aStmt, 
       
   386 			CLiwDefaultMap* aMap ) const;
       
   387 
       
   388 protected:
       
   389 
       
   390     /**
       
   391      * Sets all parameters according to provided list
       
   392      * @param aItemMap map with parameters
       
   393      */
       
   394     void SetL( const CLiwGenericParamList& aInParamList );
       
   395 
       
   396     /**
       
   397      * Sets all parameters according to provided list
       
   398      * @param aMap map with parameters
       
   399      */
       
   400     void SetL( const CLiwMap& aMap );
       
   401 
       
   402     /**
       
   403      * Extracts a param and appends it to the internal list
       
   404      * @param aParam a param to extract
       
   405      */
       
   406     void ExtractParamL(const TLiwGenericParam& aParam);
       
   407     
       
   408     /**
       
   409      * Check Get properties
       
   410      *
       
   411      * @return logical sum of TCPProperties of the object
       
   412      */
       
   413     TUint GetFilterL() const;
       
   414 
       
   415     /**
       
   416      * Check and return sort order
       
   417      *
       
   418      * @return Sort Criteria
       
   419      */
       
   420     TCPSortOrder GetSortL() const;
       
   421 
       
   422     /**
       
   423      * Check if Publisher name is set
       
   424      *
       
   425      * @return ETrue if Publisher name was set, EFalse if not
       
   426      */
       
   427     TBool IsPublisherNameL() const;
       
   428 
       
   429     /**
       
   430      * Check if ContentType is set
       
   431      *
       
   432      * @return ETrue if ContentType was set, EFalse if not
       
   433      */
       
   434     TBool IsContentTypeL() const;
       
   435 
       
   436     /**
       
   437      * Check if ContentId is set
       
   438      *
       
   439      * @return ETrue if ContentId was set, EFalse if not
       
   440      */
       
   441     TBool IsContentIdL() const;
       
   442 
       
   443     /**
       
   444      * Check if ActionTrigger is set
       
   445      *
       
   446      * @return ETrue if ActionTrigger was set, EFalse if not
       
   447      */
       
   448     TBool IsTriggerL( ) const;
       
   449 
       
   450     /**
       
   451      * Check if Flag is present
       
   452      *
       
   453      * @return ETrue if ContentId was set, EFalse if not
       
   454      */
       
   455     TBool IsFlag( ) const;
       
   456     	
       
   457     /**
       
   458      * Checks if Id property is present in internal map
       
   459      *
       
   460      */
       
   461     TBool IsId() const;
       
   462 
       
   463     /**
       
   464      * Checks if property(key) is present in internal map 
       
   465      *
       
   466      */
       
   467     TBool PropertyExists( const TDesC8& aProperty ) const;
       
   468     
       
   469     /**
       
   470      * Fetches entries from database
       
   471      *  
       
   472      * @param aSqlDb handle to database
       
   473      * @param aQuery aQuery SQL query
       
   474      * @param aList target list for enntries
       
   475      * @param aItemsToDelete ids of entries for removal - 
       
   476      *        they were found to be expired
       
   477      *
       
   478      * @return number of fetched entries
       
   479      */
       
   480     TUint GetListL( RSqlDatabase aSqlDb, const TDesC& aQuery,
       
   481         CLiwGenericParamList* aList, RArray<TInt32>& aItemsToDelete ) const;
       
   482 
       
   483     /**
       
   484      * Removes entries from database
       
   485      *  
       
   486      * @param aSqlDb handle to database
       
   487      * @param aQuery SQL query
       
   488      * 
       
   489      */
       
   490     void RemoveL( RSqlDatabase aSqlDb, const TDesC& aQuery ) const;
       
   491 
       
   492     /**
       
   493      * Fetches Ids (Publisher, ContentType, ContentId) from database
       
   494      * 
       
   495      * @param aId id entry in database
       
   496      * @param aQuery SQL query
       
   497      * @param aMap map to insert Ids
       
   498      * @param aSqlDb handle to database  
       
   499      * 
       
   500      */
       
   501     void FetchIdsL( TInt32 aId, const TDesC& aQuery, CLiwDefaultMap* aMap,
       
   502         RSqlDatabase aSqlDb ) const;
       
   503 
       
   504     /**
       
   505      * Fetches Id from database
       
   506      * 
       
   507      * @param aSqlDb handle to database
       
   508      * @param aQuery SQL query
       
   509      * @param aId id entry from database
       
   510      * 
       
   511      */
       
   512     void FetchIdL( RSqlDatabase aSqlDb,
       
   513         const TDesC& aQuery, TInt32& aId ) const;
       
   514 
       
   515     /**
       
   516      * Gets Ids (Id, Publisher, ContentType, ContentId) 
       
   517      *      of removed entries from database
       
   518      *  
       
   519      * @param aSqlDb handle to database
       
   520      * @param aQuery SQL query
       
   521      * @param aList List with ids
       
   522      * 
       
   523      */
       
   524     void GetIdsOfRemovedEntriesL( RSqlDatabase aSqlDb, const TDesC& aQuery,
       
   525         CLiwDefaultList* aList ) const;
       
   526 
       
   527     /**
       
   528      * Saves Ids (Id, Publisher, ContentType, ContentId) from database
       
   529      * 
       
   530      * @param aSqlDb handle to database
       
   531      * @param aList List with ids
       
   532      * 
       
   533      */
       
   534     void SaveQueryResultsIdsL( RSqlStatement& aStmt,
       
   535         CLiwDefaultList* aList ) const;    
       
   536 
       
   537     /**
       
   538      * Contructs SQL query to select entry
       
   539      * @param aQuery SQL query
       
   540      * 
       
   541      */
       
   542     void ConstructSelectIdL( RBuf& aQuery ) const;
       
   543 
       
   544     /**
       
   545      * Contructs SQL query to select entries for GetList
       
   546      * @param aQuery SQL query
       
   547      * 
       
   548      */
       
   549     void ConstructGetListSelectL( RBuf& aQuery, TBool aGet = ETrue ) const;
       
   550 
       
   551     /**
       
   552      * Contructs SQL query to select entries for Remove
       
   553      * @param aQuery SQL query
       
   554      * 
       
   555      */
       
   556     void ConstructRemoveSelectL( RBuf& aQuery, TBool aGet = ETrue ) const;
       
   557     
       
   558     /**
       
   559      * Binds value to query
       
   560      * @param aQuery SQL query
       
   561      * @param aSqlDb handle to database
       
   562      * 
       
   563      */
       
   564     void BindValueL( const RBuf& aQuery, RSqlStatement& aStmt ) const;
       
   565 
       
   566     /**
       
   567      * Checks if GetList for all items should be done
       
   568      * @param aFilter flag describing which ids are set
       
   569      * @return ETrue if getlist for all items shold be done, EFalse if not
       
   570      */
       
   571     TBool IsGetListAllL( TUint aFilter ) const;
       
   572     
       
   573     /**
       
   574      * Removes attributes with "All" value from map
       
   575      * @param aFilter filter bit will be reset if any attribute == "all"
       
   576      */    
       
   577     void RemoveAllAttributeL( TUint& aFilter ) const;
       
   578     
       
   579     /**
       
   580      * Leaves if publisher, content type od content_id is not descriptor type. 
       
   581      */    
       
   582     void CheckIdentifiersL() const;
       
   583     
       
   584     /**
       
   585      * Leaves if aParameterIndex is negative-error value 
       
   586      * or in case of binding error. 
       
   587      */    
       
   588     void BindTextL(RSqlStatement& aStmt, TInt aParameterIndex,
       
   589         const TDesC& aParameterText) const;
       
   590     
       
   591     /**
       
   592      * Leaves if aParameterIndex is negative-error value 
       
   593      * or in case of binding error. 
       
   594      */ 
       
   595     void BindBinaryL(RSqlStatement& aStmt, TInt aParameterIndex,
       
   596         const TDesC8& aParameterText) const;
       
   597     
       
   598     /**
       
   599      * Leaves if aParameterIndex is negative-error value 
       
   600      * or in case of binding error. 
       
   601      */ 
       
   602     void BindInt64L(RSqlStatement& aStmt, TInt aParameterIndex,
       
   603         TInt64 aParameterValue) const;
       
   604 
       
   605     /**
       
   606      * Leaves if aParameterIndex is negative-error value 
       
   607      * or in case of binding error. 
       
   608      */ 
       
   609     void BindIntL(RSqlStatement& aStmt, TInt aParameterIndex,
       
   610         TInt aParameterValue) const;
       
   611     
       
   612     /**
       
   613      * Leaves if column index return value is negative.
       
   614      * @return result of RSqlStatement::ColumnIndex
       
   615      */ 
       
   616     TInt ColumnIndexL( RSqlStatement& aStmt, const TDesC& aColumnName )	const;
       
   617     
       
   618     /**
       
   619      * Returns ETrue if a property has valid name and type
       
   620      * @param aProperty property name
       
   621      * @return ETrue if property is valid, EFalse if not
       
   622      */ 
       
   623     TBool IsPropertyValidL( const TDesC8& aProperty ) const;
       
   624 
       
   625 protected:
       
   626 
       
   627     /**
       
   628      * C++ default constructor.
       
   629      */     
       
   630     CCPLiwMap();
       
   631 
       
   632     /**
       
   633      * Perform the second phase construction of a CCPLiwMap object.
       
   634      */       
       
   635     void ConstructL();
       
   636     
       
   637     /**
       
   638      * Checks a type a map 
       
   639      * @param aVariant variant containing a map type
       
   640      * @return ETrue if a type is Publisher and EFalse if Content
       
   641      * in other cases method leaves
       
   642      */  
       
   643     static TBool IsTypePublisherL(const TLiwVariant& aVariant);
       
   644 
       
   645 protected:
       
   646     // data
       
   647 
       
   648     /*
       
   649      * The underlying generic parameter list
       
   650      * Own.
       
   651      */
       
   652     CLiwGenericParamList* iMap;
       
   653     
       
   654     /*
       
   655      * Class used for security 
       
   656      *Own.
       
   657      */
       
   658     const CCPSecurityPolicy* iPolicy;
       
   659 
       
   660     };
       
   661 
       
   662 #endif // C_CPLIWIDSMAP_H