LCOV - code coverage report
Current view: top level - dbe/src/internal - config_api_commands.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 156 0
Test Date: 2025-12-21 13:07:08 Functions: 0.0 % 9 0

            Line data    Source code
       1              : /*
       2              :  * config_api_commands.cpp
       3              :  *
       4              :  *  Created on: Apr 19, 2016
       5              :  *      Author: Leonidas Georgopoulos
       6              :  */
       7              : 
       8              : #include "dbe/confaccessor.hpp"
       9              : #include "dbe/config_reference.hpp"
      10              : #include "dbe/confobject_desc.hpp"
      11              : #include "dbe/Command.hpp"
      12              : #include "dbe/dbcontroller.hpp"
      13              : #include "dbe/Exceptions.hpp"
      14              : #include "dbe/messenger.hpp"
      15              : #include "dbe/config_api.hpp"
      16              : #include "dbe/change_class.hpp"
      17              : #include "dbe/change_date.hpp"
      18              : #include "dbe/change_enum.hpp"
      19              : #include "dbe/change_time.hpp"
      20              : #include "dbe/change_attribute.hpp"
      21              : 
      22              : 
      23              : #include "conffwk/Schema.hpp"
      24              : #include "ers/Issue.hpp"
      25              : 
      26              : #include <QString>
      27              : #include <QUuid>
      28              : 
      29              : #include <stack>
      30              : #include <string>
      31              : #include <vector>
      32              : 
      33              : 
      34              : 
      35              : //------------------------------------------------------------------------------------------
      36              : // NAMESPACE DBE::CONFIG::API::COMMANDS
      37              : //------------------------------------------------------------------------------------------
      38              : /*
      39              :  * Purpose of this namespace is to group all commands that generate undo/redo objects
      40              :  * that acts on config related structures and objects .
      41              :  *
      42              :  * DBE user interface should access the database by appropriately calling methods in this
      43              :  * namespace. Direct access by accessing that database and retrieving ConfigObject directly
      44              :  * is strongly discouraged.
      45              :  */
      46              : namespace dbe
      47              : {
      48              : namespace config
      49              : {
      50              : namespace api
      51              : {
      52              : namespace commands
      53              : {
      54              : 
      55              : //------------------------------------------------------------------------------------------
      56            0 : void newobj ( std::string const & fn, std::string const & cn, std::string const & name,
      57              :               dbe::t_config_object_preimage::type_attrmap const & attributes,
      58              :               dbe::t_config_object_preimage::type_relmap const & relations, QUuid const & src )
      59              : {
      60            0 :   std::string description
      61            0 :   { "Object created : " + name + "@" + cn };
      62              : 
      63            0 :   config_internal_change request
      64            0 :     { config_internal_change::CREATED, description, name, cn, "" };
      65              : 
      66            0 :   confaccessor::get_commands()->push (
      67            0 :     new dbe::actions::object::create ( { attributes, relations, { name, cn}, fn }, src ) );
      68              : 
      69            0 :   confaccessor::get_internal_change_stack()->push ( request );
      70            0 : }
      71              : //------------------------------------------------------------------------------------------
      72              : 
      73              : //------------------------------------------------------------------------------------------
      74            0 : bool delobj ( tref obj, QUuid const & src )
      75              : {
      76            0 :   try
      77              :   {
      78            0 :     std::string const description
      79            0 :     { "Object deleted : " + obj.UID() + "@" + obj.class_name()
      80            0 :     };
      81            0 :     config_internal_change request
      82            0 :       { config_internal_change::DELETED, description, obj.UID(), obj.class_name(), "" };
      83            0 :     confaccessor::get_commands()->push ( new dbe::actions::object::remove ( obj, src ) );
      84            0 :     confaccessor::get_internal_change_stack()->push ( request );
      85            0 :   }
      86            0 :   catch ( daq::dbe::ObjectChangeWasNotSuccessful const & dbe_err )
      87              :   {
      88            0 :     INFO ( "Delete Object: The object could not be deleted!\n\n", dbe::config::errors::parse ( dbe_err ).c_str() );
      89            0 :     return false;
      90            0 :   }
      91              : 
      92            0 :   return true;
      93              : }
      94              : //------------------------------------------------------------------------------------------
      95              : 
      96              : //------------------------------------------------------------------------------------------
      97            0 : bool renobj ( tref obj, std::string const & newuuid, QUuid const & src )
      98              : {
      99            0 :   try
     100              :   {
     101            0 :     std::string const description =
     102              :     {
     103            0 :       "Object renamed : " + obj.UID() + "@" + obj.class_name() + " to " + newuuid + "@"
     104            0 :       + obj.class_name()
     105            0 :     };
     106              : 
     107            0 :     config_internal_change request
     108            0 :       { config_internal_change::RENAMED, description, obj.UID(), obj.class_name(), "" };
     109              : 
     110            0 :     confaccessor::get_commands()->push (
     111            0 :       new dbe::actions::object::rename ( obj, newuuid, src ) );
     112              : 
     113            0 :     confaccessor::get_internal_change_stack()->push ( request );
     114              : 
     115            0 :     return true;
     116            0 :   }
     117            0 :   catch ( daq::dbe::ObjectChangeWasNotSuccessful const & dbe_err )
     118              :   {
     119            0 :     INFO ( "It was not possible to rename object ", dbe::config::errors::parse ( dbe_err ).c_str(), "\n\nObject UID:",
     120            0 :            obj.UID().c_str() );
     121            0 :     return false;
     122            0 :   }
     123              : }
     124              : //------------------------------------------------------------------------------------------
     125              : 
     126              : //------------------------------------------------------------------------------------------
     127            0 : bool movobj ( tref obj, std::string const & destination, QUuid const & src )
     128              : {
     129            0 :   try
     130              :   {
     131            0 :     std::string const description
     132            0 :     { "Object " + obj.UID() + "@" + obj.class_name() + " contained in " + obj.contained_in()
     133            0 :       + " moved to " + destination
     134            0 :     };
     135              : 
     136            0 :     config_internal_change request
     137            0 :       { config_internal_change::MOVED, description, obj.UID(), obj.class_name(), "" };
     138              : 
     139            0 :     confaccessor::get_commands()->push (
     140            0 :       new dbe::actions::object::move ( obj, destination, src ) );
     141            0 :     confaccessor::get_internal_change_stack()->push ( request );
     142              : 
     143            0 :     return true;
     144            0 :   }
     145            0 :   catch ( daq::dbe::ObjectChangeWasNotSuccessful const & dbe_err )
     146              :   {
     147            0 :     INFO ( "It was not possible to move object ", dbe::config::errors::parse ( dbe_err ).c_str(), "\n\nObject UID:",
     148            0 :            obj.UID().c_str() );
     149            0 :     return false;
     150            0 :   }
     151              : }
     152              : //------------------------------------------------------------------------------------------
     153              : 
     154              : //------------------------------------------------------------------------------------------
     155            0 : void modobj ( tref object, const dunedaq::conffwk::relationship_t & linkinfo,
     156              :               std::vector<std::string> const & others_names )
     157              : {
     158            0 :   try
     159              :   {
     160            0 :     confaccessor::get_commands()->push (
     161            0 :       new dbe::actions::object::changerefs ( object, linkinfo, others_names ) );
     162            0 :     std::string
     163              :     const description (
     164            0 :       others_names.size() != 1 ? "Multi Relationship : " + linkinfo.p_name :
     165            0 :       "Single Relationship : " + linkinfo.p_name );
     166              : 
     167            0 :     config_internal_change const change
     168              :     {
     169            0 :       config_internal_change::MODIFIED, description, object.UID(), object.class_name(), ""
     170            0 :     };
     171              : 
     172            0 :     confaccessor::get_internal_change_stack()->push ( change );
     173            0 :   }
     174            0 :   catch ( daq::dbe::ObjectChangeWasNotSuccessful const & dbe_err )
     175              :   {
     176            0 :     WARN ( "The object reference could not be changed", dbe::config::errors::parse ( dbe_err ).c_str() );
     177            0 :   }
     178            0 : }
     179              : //------------------------------------------------------------------------------------------
     180              : 
     181              : //------------------------------------------------------------------------------------------
     182              : template<>
     183            0 : void modobj<std::string> ( tref Object, const dunedaq::conffwk::attribute_t & AttributeData,
     184              :                            std::string Value )
     185              : {
     186            0 :   try
     187              :   {
     188            0 :     config_internal_change Change;
     189            0 :     Change.uid = Object.UID();
     190            0 :     Change.classname = Object.class_name();
     191            0 :     Change.request = config_internal_change::MODIFIED;
     192            0 :     Change.description = QString ( "Attribute " ).append ( AttributeData.p_name.c_str() )
     193            0 :                          .toStdString();
     194              : 
     195            0 :     if ( AttributeData.p_type == dunedaq::conffwk::string_type )
     196              :     {
     197            0 :       confaccessor::get_commands()->push (
     198            0 :         new dbe::actions::ChangeAttribute<std::string> ( Object, AttributeData, Value ) );
     199              :     }
     200              :     else if ( AttributeData.p_type == dunedaq::conffwk::enum_type )
     201              :     {
     202            0 :       confaccessor::get_commands()->push (
     203            0 :         new dbe::actions::ChangeEnum<std::string> ( Object, AttributeData, Value ) );
     204              :     }
     205              :     else if ( AttributeData.p_type == dunedaq::conffwk::class_type )
     206              :     {
     207            0 :       confaccessor::get_commands()->push (
     208            0 :         new dbe::actions::ChangeClass<std::string> ( Object, AttributeData, Value ) );
     209              :     }
     210              :     else if ( AttributeData.p_type == dunedaq::conffwk::date_type )
     211              :     {
     212              : 
     213            0 :       confaccessor::get_commands()->push (
     214            0 :         new dbe::actions::ChangeDate<std::string> ( Object, AttributeData, Value ) );
     215              :     }
     216              :     else if ( AttributeData.p_type == dunedaq::conffwk::time_type )
     217              :     {
     218            0 :       confaccessor::get_commands()->push (
     219            0 :         new dbe::actions::ChangeTime<std::string> ( Object, AttributeData, Value ) );
     220              :     }
     221              : 
     222            0 :     confaccessor::get_internal_change_stack()->push ( Change );
     223            0 :   }
     224            0 :   catch ( daq::dbe::ObjectChangeWasNotSuccessful const & dbe_err )
     225              :   {
     226            0 :     WARN ( "The object attribute could not be changed", dbe::config::errors::parse ( dbe_err ).c_str() );
     227            0 :   }
     228            0 : }
     229              : //------------------------------------------------------------------------------------------
     230              : 
     231              : //------------------------------------------------------------------------------------------
     232              : template<>
     233            0 : void modobj<std::vector<std::string>> (
     234              :                                      tref Object, const dunedaq::conffwk::attribute_t & AttributeData,
     235              :                                      std::vector<std::string> Value )
     236              : {
     237            0 :   try
     238              :   {
     239            0 :     config_internal_change Change;
     240            0 :     Change.uid = Object.UID();
     241            0 :     Change.classname = Object.class_name();
     242            0 :     Change.request = config_internal_change::MODIFIED;
     243            0 :     Change.description = QString ( "Attribute " ).append ( AttributeData.p_name.c_str() )
     244            0 :                          .toStdString();
     245              : 
     246            0 :     if ( AttributeData.p_type == dunedaq::conffwk::string_type )
     247              :     {
     248            0 :       confaccessor::get_commands()->push (
     249              :         new dbe::actions::ChangeAttribute<std::vector<std::string>> ( Object, AttributeData,
     250            0 :                                                                       Value ) );
     251              :     }
     252              :     else if ( AttributeData.p_type == dunedaq::conffwk::enum_type )
     253              :     {
     254            0 :       confaccessor::get_commands()->push (
     255              :         new dbe::actions::ChangeEnum<std::vector<std::string>> ( Object, AttributeData,
     256            0 :                                                                  Value ) );
     257              :     }
     258              :     else if ( AttributeData.p_type == dunedaq::conffwk::class_type )
     259              :     {
     260            0 :       confaccessor::get_commands()->push (
     261              :         new dbe::actions::ChangeClass<std::vector<std::string>> ( Object, AttributeData,
     262            0 :                                                                   Value ) );
     263              :     }
     264              :     else if ( AttributeData.p_type == dunedaq::conffwk::date_type )
     265              :     {
     266            0 :       confaccessor::get_commands()->push (
     267              :         new dbe::actions::ChangeDate<std::vector<std::string>> ( Object, AttributeData,
     268            0 :                                                                  Value ) );
     269              :     }
     270              :     else if ( AttributeData.p_type == dunedaq::conffwk::time_type )
     271              :     {
     272            0 :       confaccessor::get_commands()->push (
     273              :         new dbe::actions::ChangeTime<std::vector<std::string>> ( Object, AttributeData,
     274            0 :                                                                  Value ) );
     275              :     }
     276              : 
     277            0 :     confaccessor::get_internal_change_stack()->push ( Change );
     278            0 :   }
     279            0 :   catch ( daq::dbe::ObjectChangeWasNotSuccessful const & dbe_err )
     280              :   {
     281            0 :     WARN ( "The object attribute could not be changed", dbe::config::errors::parse ( dbe_err ).c_str()  );
     282            0 :   }
     283            0 : }
     284              : //------------------------------------------------------------------------------------------
     285              : 
     286              : 
     287              : //------------------------------------------------------------------------------------------
     288              : 
     289              : 
     290              : 
     291              : 
     292              : 
     293              : //------------------------------------------------------------------------------------------
     294              : namespace file
     295              : {
     296            0 : void remove ( QString const & db, QString const & fn )
     297              : {
     298            0 :   std::string dbname = db.toStdString();
     299            0 :   std::string sinclude = fn.toStdString();
     300              : 
     301            0 :   try
     302              :   {
     303            0 :     config_internal_change Change;
     304            0 :     Change.filename = fn.toStdString();
     305            0 :     Change.request = config_internal_change::FILE_DELETED;
     306            0 :     Change.description = QString ( "File(deleted) : " ).append ( fn ).toStdString();
     307              : 
     308            0 :     confaccessor::get_commands()->push ( new dbe::actions::file::remove ( dbname, sinclude ) );
     309            0 :     confaccessor::get_internal_change_stack()->push ( Change );
     310            0 :   }
     311            0 :   catch ( daq::dbe::DatabaseChangeNotSuccessful const & dbe_err )
     312              :   {
     313            0 :     WARN ( "File removal failure", dbe::config::errors::parse ( dbe_err ).c_str() );
     314            0 :   }
     315            0 : }
     316              : 
     317              : 
     318            0 : void add ( const QString & Database, const QString & IncludedFile )
     319              : {
     320            0 :   std::string dbname = Database.toStdString();
     321            0 :   std::string sinclude = IncludedFile.toStdString();
     322              : 
     323            0 :   try
     324              :   {
     325            0 :     config_internal_change Change;
     326            0 :     Change.filename = IncludedFile.toStdString();
     327            0 :     Change.request = config_internal_change::FILE_INCLUDED;
     328            0 :     Change.description = QString ( "File(included) : " ).append ( IncludedFile ).toStdString();
     329              : 
     330            0 :     confaccessor::get_commands()->push ( new dbe::actions::file::add ( dbname, sinclude ) );
     331            0 :     confaccessor::get_internal_change_stack()->push ( Change );
     332            0 :   }
     333            0 :   catch ( daq::dbe::DatabaseChangeNotSuccessful const & dbe_err )
     334              :   {
     335            0 :     WARN ( "File inclusion did not succeed", dbe::config::errors::parse ( dbe_err ).c_str() );
     336            0 :   }
     337            0 : }
     338              : 
     339              : }
     340              : 
     341              : }
     342              : }
     343              : }
     344              : }
     345              : //------------------------------------------------------------------------------------------
     346              : 
     347              : 
     348              : 
        

Generated by: LCOV version 2.0-1