LCOV - code coverage report
Current view: top level - dbaccess/source/ext/macromigration - migrationlog.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 203 0.0 %
Date: 2014-04-14 Functions: 0 24 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "dbmm_module.hxx"
      21             : #include "dbmm_global.hrc"
      22             : #include "migrationerror.hxx"
      23             : #include "migrationlog.hxx"
      24             : 
      25             : #include <comphelper/anytostring.hxx>
      26             : #include <rtl/ustrbuf.hxx>
      27             : 
      28             : #include <vector>
      29             : #include <map>
      30             : #include <list>
      31             : 
      32             : namespace dbmm
      33             : {
      34             :     // LibraryEntry
      35           0 :     struct LibraryEntry
      36             :     {
      37             :         ScriptType      eType;
      38             :         OUString sOldName;
      39             :         OUString sNewName;
      40             : 
      41             :         LibraryEntry()
      42             :             :eType( eBasic )
      43             :             ,sOldName()
      44             :             ,sNewName()
      45             :         {
      46             :         }
      47             : 
      48           0 :         LibraryEntry( const ScriptType& _eType, const OUString& _rOldName, const OUString& _rNewName )
      49             :             :eType( _eType )
      50             :             ,sOldName( _rOldName )
      51           0 :             ,sNewName( _rNewName )
      52             :         {
      53           0 :         }
      54             :     };
      55             : 
      56             :     // DocumentEntry
      57           0 :     struct DocumentEntry
      58             :     {
      59             :         SubDocumentType                 eType;
      60             :         OUString                 sName;
      61             :         ::std::vector< LibraryEntry >   aMovedLibraries;
      62             : 
      63           0 :         DocumentEntry()
      64             :             :eType( eForm )
      65             :             ,sName()
      66           0 :             ,aMovedLibraries()
      67             :         {
      68           0 :         }
      69             : 
      70           0 :         DocumentEntry( const SubDocumentType _eType, const OUString& _rName )
      71             :             :eType( _eType )
      72           0 :             ,sName( _rName )
      73             :         {
      74           0 :         }
      75             :     };
      76             : 
      77             :     // DocumentLogs
      78             :     typedef ::std::map< DocumentID, DocumentEntry > DocumentLogs;
      79             : 
      80             :     // ErrorLog
      81             :     typedef ::std::list< MigrationError >   ErrorLog;
      82             : 
      83             :     // MigrationLog_Data
      84           0 :     struct MigrationLog_Data
      85             :     {
      86             :         OUString sBackupLocation;
      87             :         DocumentLogs    aDocumentLogs;
      88             :         ErrorLog        aFailures;
      89             :         ErrorLog        aWarnings;
      90             :     };
      91             : 
      92             :     // MigrationLog
      93           0 :     MigrationLog::MigrationLog()
      94           0 :         :m_pData( new MigrationLog_Data )
      95             :     {
      96           0 :     }
      97             : 
      98           0 :     MigrationLog::~MigrationLog()
      99             :     {
     100           0 :     }
     101             : 
     102           0 :     void MigrationLog::logFailure( const MigrationError& _rError )
     103             :     {
     104           0 :         m_pData->aFailures.push_back( _rError );
     105           0 :     }
     106             : 
     107           0 :     void MigrationLog::logRecoverable( const MigrationError& _rError )
     108             :     {
     109           0 :         m_pData->aWarnings.push_back( _rError );
     110           0 :     }
     111             : 
     112           0 :     bool MigrationLog::hadFailure() const
     113             :     {
     114           0 :         return !m_pData->aFailures.empty();
     115             :     }
     116             : 
     117           0 :     void MigrationLog::backedUpDocument( const OUString& _rNewDocumentLocation )
     118             :     {
     119           0 :         m_pData->sBackupLocation = _rNewDocumentLocation;
     120           0 :     }
     121             : 
     122           0 :     DocumentID MigrationLog::startedDocument( const SubDocumentType _eType, const OUString& _rName )
     123             :     {
     124             : #if OSL_DEBUG_LEVEL > 0
     125             :         bool bAlreadyKnown = false;
     126             :         for (   DocumentLogs::const_iterator doc = m_pData->aDocumentLogs.begin();
     127             :                 doc != m_pData->aDocumentLogs.end() && !bAlreadyKnown;
     128             :                 ++doc
     129             :             )
     130             :         {
     131             :             bAlreadyKnown = ( doc->second.eType == _eType ) && ( doc->second.sName == _rName );
     132             :         }
     133             :         OSL_ENSURE( !bAlreadyKnown, "MigrationLog::startedDocument: document is already known!" );
     134             : #endif
     135             : 
     136           0 :         DocumentID nID = (DocumentID)( m_pData->aDocumentLogs.size() + 1 );
     137           0 :         while ( m_pData->aDocumentLogs.find( nID ) != m_pData->aDocumentLogs.end() )
     138           0 :             ++nID;
     139             : 
     140           0 :         m_pData->aDocumentLogs[ nID ] = DocumentEntry( _eType, _rName );
     141             : 
     142           0 :         return nID;
     143             :     }
     144             : 
     145           0 :     void MigrationLog::movedLibrary( const DocumentID _nDocID, const ScriptType _eScriptType,
     146             :             const OUString& _rOriginalLibName, const OUString& _rNewLibName )
     147             :     {
     148             :         OSL_ENSURE( m_pData->aDocumentLogs.find( _nDocID ) != m_pData->aDocumentLogs.end(),
     149             :             "MigrationLog::movedLibrary: document is not known!" );
     150             : 
     151           0 :         DocumentEntry& rDocEntry = m_pData->aDocumentLogs[ _nDocID ];
     152           0 :         rDocEntry.aMovedLibraries.push_back( LibraryEntry( _eScriptType, _rOriginalLibName, _rNewLibName ) );
     153           0 :     }
     154             : 
     155           0 :     void MigrationLog::finishedDocument( const DocumentID _nDocID )
     156             :     {
     157             :         OSL_ENSURE( m_pData->aDocumentLogs.find( _nDocID ) != m_pData->aDocumentLogs.end(),
     158             :             "MigrationLog::finishedDocument: document is not known!" );
     159             : 
     160           0 :         DocumentEntry& rDocEntry = m_pData->aDocumentLogs[ _nDocID ];
     161             :         (void)rDocEntry;
     162             :         // nothing to do here
     163           0 :     }
     164             : 
     165           0 :     const OUString& MigrationLog::getNewLibraryName( DocumentID _nDocID, ScriptType _eScriptType,
     166             :         const OUString& _rOriginalLibName ) const
     167             :     {
     168           0 :         static OUString s_sEmptyString;
     169             : 
     170           0 :         DocumentLogs::const_iterator docPos = m_pData->aDocumentLogs.find( _nDocID );
     171           0 :         if ( docPos == m_pData->aDocumentLogs.end() )
     172             :         {
     173             :             OSL_FAIL( "MigrationLog::getNewLibraryName: document is not known!" );
     174           0 :             return s_sEmptyString;
     175             :         }
     176             : 
     177           0 :         const DocumentEntry& rDocEntry( docPos->second );
     178           0 :         for (   ::std::vector< LibraryEntry >::const_iterator lib = rDocEntry.aMovedLibraries.begin();
     179           0 :                 lib != rDocEntry.aMovedLibraries.end();
     180             :                 ++lib
     181             :             )
     182             :         {
     183           0 :             if  (   ( _eScriptType == lib->eType )
     184           0 :                 &&  ( _rOriginalLibName == lib->sOldName )
     185             :                 )
     186           0 :                 return lib->sNewName;
     187             :         }
     188             : 
     189             :         OSL_FAIL( "MigrationLog::getNewLibraryName: doc is known, but library isn't!" );
     190           0 :         return s_sEmptyString;
     191             :     }
     192             : 
     193             :     namespace
     194             :     {
     195           0 :         static void lcl_appendErrorDescription( OUStringBuffer& _inout_rBuffer, const MigrationError& _rError )
     196             :         {
     197           0 :             const sal_Char* pAsciiErrorDescription( NULL );
     198           0 :             ::std::vector< OUString > aParameterNames;
     199           0 :             switch ( _rError.eType )
     200             :             {
     201             :             case ERR_OPENING_SUB_DOCUMENT_FAILED:
     202           0 :                 pAsciiErrorDescription = "opening '#doc#' failed";
     203           0 :                 aParameterNames.push_back(OUString("#doc#"));
     204           0 :                 break;
     205             : 
     206             :             case ERR_CLOSING_SUB_DOCUMENT_FAILED:
     207           0 :                 pAsciiErrorDescription = "closing '#doc#' failed";
     208           0 :                 aParameterNames.push_back(OUString("#doc#"));
     209           0 :                 break;
     210             : 
     211             :             case ERR_STORAGE_COMMIT_FAILED:
     212           0 :                 pAsciiErrorDescription = "committing the changes for document '#doc#' failed";
     213           0 :                 aParameterNames.push_back(OUString("#doc#"));
     214           0 :                 break;
     215             : 
     216             :             case ERR_STORING_DATABASEDOC_FAILED:
     217           0 :                 pAsciiErrorDescription = "storing the database document failed";
     218           0 :                 break;
     219             : 
     220             :             case ERR_COLLECTING_DOCUMENTS_FAILED:
     221           0 :                 pAsciiErrorDescription = "collecting the forms/reports of the database document failed";
     222           0 :                 break;
     223             : 
     224             :             case ERR_UNEXPECTED_LIBSTORAGE_ELEMENT:
     225           0 :                 pAsciiErrorDescription = "unexpected #lib# storage element in document '#doc#', named '#element#'";
     226           0 :                 aParameterNames.push_back(OUString("#doc#"));
     227           0 :                 aParameterNames.push_back(OUString("#libstore#"));
     228           0 :                 aParameterNames.push_back(OUString("#element#"));
     229           0 :                 break;
     230             : 
     231             :             case ERR_CREATING_DBDOC_SCRIPT_STORAGE_FAILED:
     232           0 :                 pAsciiErrorDescription = "creating the database document's storage for #scripttype# scripts failed";
     233           0 :                 aParameterNames.push_back(OUString("#scripttype#"));
     234           0 :                 break;
     235             : 
     236             :             case ERR_COMMITTING_SCRIPT_STORAGES_FAILED:
     237           0 :                 pAsciiErrorDescription = "saving the #scripttype# scripts for document '#doc#' failed";
     238           0 :                 aParameterNames.push_back(OUString("#scripttype#"));
     239           0 :                 aParameterNames.push_back(OUString("#doc#"));
     240           0 :                 break;
     241             : 
     242             :             case ERR_GENERAL_SCRIPT_MIGRATION_FAILURE:
     243           0 :                 pAsciiErrorDescription = "general error while migrating #scripttype# scripts of document '#doc#'";
     244           0 :                 aParameterNames.push_back(OUString("#scripttype#"));
     245           0 :                 aParameterNames.push_back(OUString("#doc#"));
     246           0 :                 break;
     247             : 
     248             :             case ERR_GENERAL_MACRO_MIGRATION_FAILURE:
     249           0 :                 pAsciiErrorDescription = "general error during macro migration of document '#doc#'";
     250           0 :                 aParameterNames.push_back(OUString("#doc#"));
     251           0 :                 break;
     252             : 
     253             :             case ERR_UNKNOWN_SCRIPT_TYPE:
     254           0 :                 pAsciiErrorDescription = "unknown script type: #type#";
     255           0 :                 aParameterNames.push_back(OUString("#type#"));
     256           0 :                 break;
     257             : 
     258             :             case ERR_UNKNOWN_SCRIPT_LANGUAGE:
     259           0 :                 pAsciiErrorDescription = "unknown script language: #lang#";
     260           0 :                 aParameterNames.push_back(OUString("#lang#"));
     261           0 :                 break;
     262             : 
     263             :             case ERR_UNKNOWN_SCRIPT_NAME_FORMAT:
     264           0 :                 pAsciiErrorDescription = "unknown script name format: #script#";
     265           0 :                 aParameterNames.push_back(OUString("#script#"));
     266           0 :                 break;
     267             : 
     268             :             case ERR_SCRIPT_TRANSLATION_FAILURE:
     269           0 :                 pAsciiErrorDescription = "analyzing/translating the script URL failed; script type: #type#; script: #code#";
     270           0 :                 aParameterNames.push_back(OUString("#type#"));
     271           0 :                 aParameterNames.push_back(OUString("#code#"));
     272           0 :                 break;
     273             : 
     274             :             case ERR_INVALID_SCRIPT_DESCRIPTOR_FORMAT:
     275           0 :                 pAsciiErrorDescription = "invalid script descriptor format";
     276           0 :                 break;
     277             : 
     278             :             case ERR_ADJUSTING_DOCUMENT_EVENTS_FAILED:
     279           0 :                 pAsciiErrorDescription = "adjusting events for document '#doc#' failed";
     280           0 :                 aParameterNames.push_back(OUString("#doc#"));
     281           0 :                 break;
     282             : 
     283             :             case ERR_ADJUSTING_DIALOG_EVENTS_FAILED:
     284           0 :                 pAsciiErrorDescription = "adjusting events for dialog #lib#.#dlg# in document '#doc#' failed";
     285           0 :                 aParameterNames.push_back(OUString("#doc#"));
     286           0 :                 aParameterNames.push_back(OUString("#lib#"));
     287           0 :                 aParameterNames.push_back(OUString("#dlg#"));
     288           0 :                 break;
     289             : 
     290             :             case ERR_ADJUSTING_FORMCOMP_EVENTS_FAILED:
     291           0 :                 pAsciiErrorDescription = "adjusting form component events for '#doc#' failed";
     292           0 :                 aParameterNames.push_back(OUString("#doc#"));
     293           0 :                 break;
     294             : 
     295             :             case ERR_BIND_SCRIPT_STORAGE_FAILED:
     296           0 :                 pAsciiErrorDescription = "binding to the script storage failed for document '#doc#'";
     297           0 :                 aParameterNames.push_back(OUString("#doc#"));
     298           0 :                 break;
     299             : 
     300             :             case ERR_REMOVE_SCRIPTS_STORAGE_FAILED:
     301           0 :                 pAsciiErrorDescription = "removing a scripts storage failed for document '#doc#'";
     302           0 :                 aParameterNames.push_back(OUString("#doc#"));
     303           0 :                 break;
     304             : 
     305             :             case ERR_DOCUMENT_BACKUP_FAILED:
     306           0 :                 pAsciiErrorDescription = "backing up the document to #location# failed";
     307           0 :                 aParameterNames.push_back(OUString("#location#"));
     308           0 :                 break;
     309             : 
     310             :             case ERR_UNKNOWN_SCRIPT_FOLDER:
     311           0 :                 pAsciiErrorDescription = "unknown script folder '#name#' in document '#doc#'";
     312           0 :                 aParameterNames.push_back(OUString("#doc#"));
     313           0 :                 aParameterNames.push_back(OUString("#name#"));
     314           0 :                 break;
     315             : 
     316             :             case ERR_EXAMINING_SCRIPTS_FOLDER_FAILED:
     317           0 :                 pAsciiErrorDescription = "examining the 'Scripts' folder failed for document '#doc#'";
     318           0 :                 aParameterNames.push_back(OUString("#doc#"));
     319           0 :                 break;
     320             : 
     321             :             case ERR_PASSWORD_VERIFICATION_FAILED:
     322           0 :                 pAsciiErrorDescription = "password verification failed for document '#doc#', #libtype# library '#name#'";
     323           0 :                 aParameterNames.push_back(OUString("#doc#"));
     324           0 :                 aParameterNames.push_back(OUString("#libtype#"));
     325           0 :                 aParameterNames.push_back(OUString("#name#"));
     326           0 :                 break;
     327             : 
     328             :             case ERR_NEW_STYLE_REPORT:
     329           0 :                 pAsciiErrorDescription = "#doc# could not be processed, since you don't have the Oracle Report Builder (TM) extension installed.";
     330           0 :                 aParameterNames.push_back(OUString("#doc#"));
     331           0 :                 break;
     332             : 
     333             :                 // do *not* add a default case here: Without a default, some compilers will warn you when
     334             :                 // you miss a newly-introduced enum value here
     335             :             }
     336             :             OSL_ENSURE( pAsciiErrorDescription, "lcl_appendErrorDescription: no error message!" );
     337           0 :             if ( pAsciiErrorDescription )
     338             :             {
     339           0 :                 OUString sSubstituted( OUString::createFromAscii( pAsciiErrorDescription ) );
     340             :                 OSL_ENSURE( aParameterNames.size() == _rError.aErrorDetails.size(),
     341             :                     "lcl_appendErrorDescription: unexpected number of error message parameters!" );
     342             : 
     343           0 :                 for ( size_t i=0; i < ::std::min( aParameterNames.size(), _rError.aErrorDetails.size() ); ++i )
     344             :                 {
     345           0 :                     sSubstituted = sSubstituted.replaceFirst(
     346           0 :                         aParameterNames[i], _rError.aErrorDetails[i]);
     347             :                 }
     348             : 
     349           0 :                 _inout_rBuffer.append( sSubstituted );
     350           0 :             }
     351           0 :         }
     352             : 
     353           0 :         void lcl_describeErrors( OUStringBuffer& _rBuffer, const ErrorLog& _rErrors, const sal_uInt16 _nHeadingResId )
     354             :         {
     355           0 :             _rBuffer.appendAscii( "=== " );
     356           0 :             _rBuffer.append     ( OUString( MacroMigrationResId( _nHeadingResId ) ) );
     357           0 :             _rBuffer.appendAscii( " ===\n" );
     358             : 
     359           0 :             OUString sException( MacroMigrationResId( STR_EXCEPTION ) );
     360             : 
     361           0 :             for (   ErrorLog::const_iterator error = _rErrors.begin();
     362           0 :                     error != _rErrors.end();
     363             :                     ++error
     364             :                 )
     365             :             {
     366           0 :                 _rBuffer.append( '-' );
     367           0 :                 _rBuffer.append( ' ' );
     368           0 :                 lcl_appendErrorDescription( _rBuffer, *error );
     369           0 :                 _rBuffer.append( '\n' );
     370             : 
     371           0 :                 if ( !error->aCaughtException.hasValue() )
     372           0 :                     continue;
     373             : 
     374           0 :                 _rBuffer.append( sException );
     375           0 :                 _rBuffer.append( ::comphelper::anyToString( error->aCaughtException ) );
     376           0 :                 _rBuffer.append( '\n' );
     377           0 :                 _rBuffer.append( '\n' );
     378           0 :             }
     379           0 :         }
     380             :     }
     381             : 
     382           0 :     bool MigrationLog::movedAnyLibrary( const DocumentID _nDocID )
     383             :     {
     384           0 :         DocumentLogs::const_iterator docPos = m_pData->aDocumentLogs.find( _nDocID );
     385           0 :         if ( docPos == m_pData->aDocumentLogs.end() )
     386             :         {
     387             :             OSL_FAIL( "MigrationLog::movedAnyLibrary: document is not known!" );
     388           0 :             return false;
     389             :         }
     390           0 :         return !docPos->second.aMovedLibraries.empty();
     391             :     }
     392             : 
     393           0 :     OUString MigrationLog::getCompleteLog() const
     394             :     {
     395           0 :         OUStringBuffer aBuffer;
     396             : 
     397           0 :         if ( !m_pData->sBackupLocation.isEmpty() )
     398             :         {
     399           0 :             OUString sBackedUp( MacroMigrationResId( STR_SAVED_COPY_TO ) );
     400           0 :             sBackedUp = sBackedUp.replaceAll( "$location$", m_pData->sBackupLocation );
     401             : 
     402           0 :             aBuffer.append( "=== " + OUString( MacroMigrationResId( STR_DATABASE_DOCUMENT ) )
     403           0 :                     + " ===\n" + sBackedUp + "\n\n");
     404             :         }
     405             : 
     406           0 :         if ( !m_pData->aFailures.empty() )
     407             :         {
     408           0 :             lcl_describeErrors( aBuffer, m_pData->aFailures
     409           0 :                 , STR_ERRORS );
     410             :         }
     411             :         else
     412             :         {
     413           0 :             OUString sMovedLibTemplate( MacroMigrationResId( STR_MOVED_LIBRARY ) );
     414             : 
     415           0 :             for (   DocumentLogs::const_iterator doc = m_pData->aDocumentLogs.begin();
     416           0 :                     doc != m_pData->aDocumentLogs.end();
     417             :                     ++doc
     418             :                 )
     419             :             {
     420           0 :                 const DocumentEntry& rDoc( doc->second );
     421             : 
     422           0 :                 if ( rDoc.aMovedLibraries.empty() )
     423           0 :                     continue;
     424             : 
     425           0 :                 OUString sDocTitle( MacroMigrationResId( rDoc.eType == eForm ? STR_FORM : STR_REPORT ) );
     426           0 :                 sDocTitle = sDocTitle.replaceAll( "$name$", rDoc.sName );
     427             : 
     428           0 :                 aBuffer.append( "=== " + sDocTitle + " ===\n" );
     429             : 
     430           0 :                 for (   ::std::vector< LibraryEntry >::const_iterator lib = rDoc.aMovedLibraries.begin();
     431           0 :                         lib != rDoc.aMovedLibraries.end();
     432             :                         ++lib
     433             :                     )
     434             :                 {
     435           0 :                     OUString sMovedLib( sMovedLibTemplate );
     436           0 :                     sMovedLib = sMovedLib.replaceAll( "$type$", getScriptTypeDisplayName( lib->eType ) );
     437           0 :                     sMovedLib = sMovedLib.replaceAll( "$old$", lib->sOldName );
     438           0 :                     sMovedLib = sMovedLib.replaceAll( "$new$", lib->sNewName );
     439             : 
     440           0 :                     aBuffer.append( sMovedLib + "\n" );
     441           0 :                 }
     442             : 
     443           0 :                 aBuffer.append( '\n' );
     444           0 :             }
     445             :         }
     446             : 
     447           0 :         if ( !m_pData->aWarnings.empty() )
     448             :         {
     449           0 :             lcl_describeErrors( aBuffer, m_pData->aWarnings, STR_WARNINGS );
     450             :         }
     451             : 
     452           0 :         return aBuffer.makeStringAndClear();
     453             :     }
     454             : 
     455             : } // namespace dbmm
     456             : 
     457             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10