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: 2026-07-12 15:23:06 Functions: 0.0 % 9 0

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

Generated by: LCOV version 2.0-1