LCOV - code coverage report
Current view: top level - gui/source - gui_search_runner.c (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.61.0_covts Lines: 0 144 0.0 %
Date: 2024-10-26 21:44:38 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /* File: gui_search_runner.c; Copyright and License: see below */
       2             : 
       3             : #include "gui_search_runner.h"
       4             : #include "set/data_search_result_list.h"
       5             : #include "u8/u8_trace.h"
       6             : #include "u8/u8_log.h"
       7             : #include <assert.h>
       8             : 
       9           0 : void gui_search_runner_init ( gui_search_runner_t *this_,
      10             :                               gui_simple_message_to_user_t *message_to_user,
      11             :                               data_database_reader_t *db_reader,
      12             :                               data_database_t *database,
      13             :                               gui_sketch_area_t *result_consumer )
      14             : {
      15           0 :     U8_TRACE_BEGIN();
      16           0 :     assert ( message_to_user != NULL );
      17           0 :     assert ( db_reader != NULL );
      18           0 :     assert ( database != NULL );
      19           0 :     assert ( result_consumer != NULL );
      20             : 
      21           0 :     (*this_).message_to_user = message_to_user;
      22           0 :     (*this_).db_reader = db_reader;
      23           0 :     const u8_error_t d_err = data_database_text_search_init ( &((*this_).db_searcher), database );
      24           0 :     if ( U8_ERROR_NONE != d_err )
      25             :     {
      26           0 :         U8_LOG_WARNING_HEX( "data_database_text_search_t could not be constructed.", d_err );
      27             :     }
      28           0 :     (*this_).result_consumer = result_consumer;
      29           0 :     DATA_SEARCH_RESULT_LIST_INIT( &((*this_).temp_result_list), (*this_).temp_result_list_buf );
      30             : 
      31           0 :     U8_TRACE_END();
      32           0 : }
      33             : 
      34           0 : void gui_search_runner_destroy ( gui_search_runner_t *this_ )
      35             : {
      36           0 :     U8_TRACE_BEGIN();
      37             : 
      38           0 :     (*this_).message_to_user = NULL;
      39           0 :     (*this_).db_reader = NULL;
      40           0 :     const u8_error_t d_err = data_database_text_search_destroy ( &((*this_).db_searcher) );
      41           0 :     if ( U8_ERROR_NONE != d_err )
      42             :     {
      43           0 :         U8_LOG_WARNING_HEX( "data_database_text_search_t could not be destructed.", d_err );
      44             :     }
      45           0 :     (*this_).result_consumer = NULL;
      46             : 
      47           0 :     U8_TRACE_END();
      48           0 : }
      49             : 
      50           0 : void gui_search_runner_run ( gui_search_runner_t *this_, const char* search_string )
      51             : {
      52           0 :     U8_TRACE_BEGIN();
      53             : 
      54           0 :     if ( search_string != NULL )
      55             :     {
      56             :         data_id_t search_id;
      57           0 :         data_id_init_by_string ( &search_id, search_string );
      58           0 :         data_id_trace ( &search_id );
      59             : 
      60           0 :         gui_simple_message_to_user_hide( (*this_).message_to_user );
      61             : 
      62           0 :         data_search_result_list_clear( &((*this_).temp_result_list) );
      63           0 :         const data_row_id_t search_row_id = data_id_get_row_id(&search_id);
      64           0 :         u8_error_t d_err = U8_ERROR_NONE;
      65             : 
      66           0 :         if ( data_id_is_valid( &search_id ))
      67             :         {
      68           0 :             switch ( data_id_get_table(&search_id) )
      69             :             {
      70           0 :                 case DATA_TABLE_CLASSIFIER:
      71             :                 {
      72           0 :                     d_err = data_database_reader_get_classifier_by_id ( (*this_).db_reader,
      73             :                                                                         search_row_id,
      74             :                                                                         &((*this_).temp_classifier)
      75             :                                                                       );
      76           0 :                     if ( d_err == U8_ERROR_NONE )
      77             :                     {
      78             :                         data_search_result_t half_initialized;
      79           0 :                         data_search_result_init_classifier( &half_initialized,
      80             :                                                             search_row_id,
      81           0 :                                                             data_classifier_get_main_type( &((*this_).temp_classifier) ),
      82           0 :                                                             data_classifier_get_name_const( &((*this_).temp_classifier) ),
      83             :                                                             DATA_ROW_ID_VOID /* diagram_id */
      84             :                                                         );
      85           0 :                         gui_search_runner_private_add_diagrams_of_classifier( this_, &half_initialized, &((*this_).temp_result_list) );
      86             : 
      87           0 :                         data_classifier_destroy( &((*this_).temp_classifier) );
      88           0 :                         data_search_result_destroy( &half_initialized );
      89             :                     }
      90             :                     else
      91             :                     {
      92           0 :                         U8_TRACE_INFO( "classifier does not exist or database not open." );
      93             :                     }
      94             :                 }
      95           0 :                 break;
      96             : 
      97           0 :                 case DATA_TABLE_FEATURE:
      98             :                 {
      99           0 :                     d_err = data_database_reader_get_feature_by_id ( (*this_).db_reader,
     100             :                                                                      search_row_id,
     101             :                                                                      &((*this_).temp_feature)
     102             :                                                                    );
     103           0 :                     if ( d_err == U8_ERROR_NONE )
     104             :                     {
     105           0 :                         data_row_id_t classifier_id = data_feature_get_classifier_row_id( &((*this_).temp_feature) );
     106             :                         data_search_result_t half_initialized;
     107           0 :                         data_search_result_init_feature( &half_initialized,
     108           0 :                                                          data_feature_get_row_id( &((*this_).temp_feature) ),
     109           0 :                                                          data_feature_get_main_type( &((*this_).temp_feature) ),
     110           0 :                                                          data_feature_get_key_const( &((*this_).temp_feature) ),
     111             :                                                          classifier_id,
     112             :                                                          DATA_ROW_ID_VOID /* diagram_id */
     113             :                                                        );
     114           0 :                         gui_search_runner_private_add_diagrams_of_classifier( this_, &half_initialized, &((*this_).temp_result_list) );
     115             : 
     116           0 :                         data_feature_destroy( &((*this_).temp_feature) );
     117           0 :                         data_search_result_destroy( &half_initialized );
     118             :                     }
     119             :                     else
     120             :                     {
     121           0 :                         U8_TRACE_INFO( "feature does not exist or database not open." );
     122             :                     }
     123             :                 }
     124           0 :                 break;
     125             : 
     126           0 :                 case DATA_TABLE_RELATIONSHIP:
     127             :                 {
     128           0 :                     d_err = data_database_reader_get_relationship_by_id ( (*this_).db_reader,
     129             :                                                                           search_row_id,
     130             :                                                                           &((*this_).temp_relationship)
     131             :                                                                         );
     132           0 :                     if ( d_err == U8_ERROR_NONE )
     133             :                     {
     134           0 :                         data_row_id_t classifier_id = data_relationship_get_from_classifier_row_id( &((*this_).temp_relationship) );
     135             :                         data_search_result_t half_initialized;
     136           0 :                         data_search_result_init_relationship( &half_initialized,
     137           0 :                                                               data_relationship_get_row_id( &((*this_).temp_relationship) ),
     138           0 :                                                               data_relationship_get_main_type( &((*this_).temp_relationship) ),
     139           0 :                                                               data_relationship_get_name_const( &((*this_).temp_relationship) ),
     140             :                                                               classifier_id,
     141           0 :                                                               data_relationship_get_to_classifier_row_id( &((*this_).temp_relationship) ),
     142             :                                                               DATA_ROW_ID_VOID /* diagram_id */
     143             :                                                             );
     144           0 :                         gui_search_runner_private_add_diagrams_of_classifier( this_, &half_initialized, &((*this_).temp_result_list) );
     145             : 
     146           0 :                         data_relationship_destroy( &((*this_).temp_relationship) );
     147           0 :                         data_search_result_destroy( &half_initialized );
     148             :                     }
     149             :                     else
     150             :                     {
     151           0 :                         U8_TRACE_INFO( "relationship does not exist or database not open." );
     152             :                     }
     153             :                 }
     154           0 :                 break;
     155             : 
     156           0 :                 case DATA_TABLE_DIAGRAMELEMENT:
     157             :                 {
     158           0 :                     d_err = data_database_reader_get_diagramelement_by_id ( (*this_).db_reader,
     159             :                                                                             search_row_id,
     160             :                                                                             &((*this_).temp_diagramelement)
     161             :                                                                           );
     162           0 :                     if ( d_err == U8_ERROR_NONE )
     163             :                     {
     164             :                         data_search_result_t half_initialized;
     165           0 :                         data_search_result_init_classifier( &half_initialized,
     166           0 :                                                             data_diagramelement_get_classifier_row_id(&((*this_).temp_diagramelement)),
     167             :                                                             0 /* match_type is unknown */,
     168             :                                                             "" /* match_name */,
     169           0 :                                                             data_diagramelement_get_diagram_row_id(&((*this_).temp_diagramelement))
     170             :                                                           );
     171           0 :                         const u8_error_t err = data_search_result_list_add( &((*this_).temp_result_list), &half_initialized );
     172           0 :                         if ( err != U8_ERROR_NONE )
     173             :                         {
     174             :                             /*d_err = U8_ERROR_ARRAY_BUFFER_EXCEEDED;*/
     175           0 :                             U8_LOG_WARNING( "U8_ERROR_ARRAY_BUFFER_EXCEEDED at inserting search result to list" );
     176             :                         }
     177             : 
     178           0 :                         data_diagramelement_destroy( &((*this_).temp_diagramelement) );
     179           0 :                         data_search_result_destroy( &half_initialized );
     180             :                     }
     181             :                     else
     182             :                     {
     183           0 :                         U8_TRACE_INFO( "diagramelement does not exist or database not open." );
     184             :                     }
     185             :                 }
     186           0 :                 break;
     187             : 
     188           0 :                 case DATA_TABLE_DIAGRAM:
     189             :                 {
     190             :                     assert( GUI_SEARCH_RUNNER_MAX_DIAGRAMS > 0 );
     191           0 :                     d_err = data_database_reader_get_diagram_by_id ( (*this_).db_reader, search_row_id, &((*this_).temp_diagrams[0]) );
     192           0 :                     if ( d_err == U8_ERROR_NONE )
     193             :                     {
     194             :                         data_search_result_t half_initialized;
     195           0 :                         data_search_result_init_diagram( &half_initialized,
     196             :                                                          search_row_id,
     197           0 :                                                          data_diagram_get_diagram_type( &((*this_).temp_diagrams[0]) ),
     198           0 :                                                          data_diagram_get_name_const( &((*this_).temp_diagrams[0]) )
     199             :                                                        );
     200           0 :                         const u8_error_t err = data_search_result_list_add( &((*this_).temp_result_list), &half_initialized );
     201           0 :                         if ( err != U8_ERROR_NONE )
     202             :                         {
     203             :                             /*d_err = U8_ERROR_ARRAY_BUFFER_EXCEEDED;*/
     204           0 :                             U8_LOG_WARNING( "U8_ERROR_ARRAY_BUFFER_EXCEEDED at inserting search result to list" );
     205             :                         }
     206             : 
     207           0 :                         data_diagram_destroy( &((*this_).temp_diagrams[0]) );
     208           0 :                         data_search_result_destroy( &half_initialized );
     209             :                     }
     210             :                     else
     211             :                     {
     212           0 :                         U8_TRACE_INFO( "diagram does not exist or database not open." );
     213             :                     }
     214             :                 }
     215           0 :                 break;
     216             : 
     217           0 :                 default:
     218             :                 {
     219           0 :                     assert(false);  /* data_id_is_valid should have been false already */
     220             :                 }
     221             :                 break;
     222             :             }
     223             :         }
     224             :         else
     225             :         {
     226           0 :             U8_LOG_EVENT_STR( "User search input is not an id", search_string );
     227             :         }
     228             : 
     229             :         /* free text search */
     230           0 :         d_err = data_database_text_search_get_objects_by_textfragment ( &((*this_).db_searcher),
     231             :                                                                         search_string,
     232             :                                                                         &((*this_).temp_result_list)
     233             :                                                                       );
     234           0 :         if ( U8_ERROR_NONE != d_err )
     235             :         {
     236           0 :             U8_LOG_ERROR_HEX( "data_database_text_search_t could not search.", d_err );
     237             :         }
     238             : 
     239           0 :         gui_sketch_area_show_result_list ( (*this_).result_consumer, &((*this_).temp_result_list) );
     240           0 :         data_search_result_list_clear( &((*this_).temp_result_list) );
     241             :     }
     242             :     else
     243             :     {
     244           0 :         assert(false);
     245             :     }
     246             : 
     247           0 :     U8_TRACE_END();
     248           0 : }
     249             : 
     250           0 : void gui_search_runner_private_add_diagrams_of_classifier ( gui_search_runner_t *this_,
     251             :                                                             data_search_result_t *classifier_template,
     252             :                                                             data_search_result_list_t *io_list
     253             :                                                           )
     254             : {
     255           0 :     U8_TRACE_BEGIN();
     256           0 :     assert( classifier_template != NULL );
     257           0 :     assert( io_list != NULL );
     258           0 :     u8_error_t d_err = U8_ERROR_NONE;
     259             : 
     260             :     data_row_id_t classifier_row_id;
     261           0 :     if ( DATA_TABLE_CLASSIFIER == data_id_get_table( data_search_result_get_match_id_const( classifier_template )))
     262             :     {
     263           0 :         classifier_row_id = data_id_get_row_id( data_search_result_get_match_id_const( classifier_template ));
     264             :     }
     265             :     else
     266             :     {
     267           0 :         classifier_row_id = data_id_get_row_id( data_search_result_get_src_classifier_id_const( classifier_template ));
     268             :     }
     269             :     uint32_t diagram_count;
     270           0 :     d_err = data_database_reader_get_diagrams_by_classifier_id ( (*this_).db_reader,
     271             :                                                                  classifier_row_id,
     272             :                                                                  GUI_SEARCH_RUNNER_MAX_DIAGRAMS,
     273           0 :                                                                  &((*this_).temp_diagrams),
     274             :                                                                  &diagram_count
     275             :                                                                );
     276           0 :     if ( d_err == U8_ERROR_ARRAY_BUFFER_EXCEEDED )
     277             :     {
     278           0 :         U8_LOG_WARNING( "U8_ERROR_ARRAY_BUFFER_EXCEEDED at searching diagrams" );
     279             :     }
     280             : 
     281           0 :     if (( d_err == U8_ERROR_NONE )||( d_err == U8_ERROR_ARRAY_BUFFER_EXCEEDED ))
     282             :     {
     283           0 :         assert ( diagram_count <= GUI_SEARCH_RUNNER_MAX_DIAGRAMS );
     284           0 :         for ( uint32_t idx = 0; idx < diagram_count; idx ++ )
     285             :         {
     286           0 :             const data_row_id_t diagram_row_id = data_diagram_get_row_id ( &((*this_).temp_diagrams[idx]) );
     287           0 :             data_id_reinit( data_search_result_get_diagram_id_ptr( classifier_template ), DATA_TABLE_DIAGRAM, diagram_row_id );
     288             : 
     289           0 :             bool filter = false;
     290           0 :             switch ( data_id_get_table( data_search_result_get_match_id_const( classifier_template ) ) )
     291             :             {
     292           0 :                 case DATA_TABLE_FEATURE:
     293             :                 {
     294             :                     /* if a user searches explicitly for a feature-id, which feature/classifiers should be filtered? */
     295             :                     /* and how? till here, the classifier type is not yet loaded. */
     296             :                 }
     297           0 :                 break;
     298             : 
     299           0 :                 case DATA_TABLE_RELATIONSHIP:
     300             :                 {
     301             :                     /* if a user searches explicitly for a relationship-id, which ones should be filtered? */
     302             :                     /* and how? till here, the classifier type is not yet loaded. */
     303             :                 }
     304           0 :                 break;
     305             : 
     306           0 :                 default:
     307             :                 {
     308             :                     /* do not filter classifiers (or other things?) */
     309             :                 }
     310           0 :                 break;
     311             :             }
     312             : 
     313           0 :             if ( ! filter )
     314             :             {
     315           0 :                 const u8_error_t err = data_search_result_list_add( io_list, classifier_template );
     316           0 :                 if ( err != U8_ERROR_NONE )
     317             :                 {
     318             :                     /*d_err |= U8_ERROR_ARRAY_BUFFER_EXCEEDED;*/
     319           0 :                     U8_LOG_WARNING( "U8_ERROR_ARRAY_BUFFER_EXCEEDED at inserting search result to list" );
     320             :                 }
     321             :             }
     322             : 
     323           0 :             data_diagram_destroy( &((*this_).temp_diagrams[idx]) );
     324             :         }
     325             :     }
     326             :     else
     327             :     {
     328           0 :         U8_TRACE_INFO( "diagram does not exist or database not open." );
     329             :     }
     330             : 
     331           0 :     U8_TRACE_END();
     332           0 : }
     333             : 
     334             : 
     335             : /*
     336             : Copyright 2020-2024 Andreas Warnke
     337             : 
     338             : Licensed under the Apache License, Version 2.0 (the "License");
     339             : you may not use this file except in compliance with the License.
     340             : You may obtain a copy of the License at
     341             : 
     342             :     http://www.apache.org/licenses/LICENSE-2.0
     343             : 
     344             : Unless required by applicable law or agreed to in writing, software
     345             : distributed under the License is distributed on an "AS IS" BASIS,
     346             : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     347             : See the License for the specific language governing permissions and
     348             : limitations under the License.
     349             : */

Generated by: LCOV version 1.16