LCOV - code coverage report
Current view: top level - gui/source - gui_search_runner.c (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.62.0_covts Lines: 0 143 0.0 %
Date: 2024-12-21 18:34:41 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_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_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_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_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_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_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           0 :                     d_err = data_database_reader_get_diagram_by_id ( (*this_).db_reader, search_row_id, &((*this_).temp_diagram) );
     191           0 :                     if ( d_err == U8_ERROR_NONE )
     192             :                     {
     193             :                         data_search_result_t half_initialized;
     194           0 :                         data_search_result_init_diagram( &half_initialized,
     195             :                                                          search_row_id,
     196           0 :                                                          data_diagram_get_diagram_type( &((*this_).temp_diagram) ),
     197           0 :                                                          data_diagram_get_name_const( &((*this_).temp_diagram) )
     198             :                                                        );
     199           0 :                         const u8_error_t err = data_search_result_list_add( &((*this_).temp_result_list), &half_initialized );
     200           0 :                         if ( err != U8_ERROR_NONE )
     201             :                         {
     202             :                             /*d_err = U8_ERROR_ARRAY_BUFFER_EXCEEDED;*/
     203           0 :                             U8_LOG_WARNING( "U8_ERROR_ARRAY_BUFFER_EXCEEDED at inserting search result to list" );
     204             :                         }
     205             : 
     206           0 :                         data_diagram_destroy( &((*this_).temp_diagram) );
     207           0 :                         data_search_result_destroy( &half_initialized );
     208             :                     }
     209             :                     else
     210             :                     {
     211           0 :                         U8_TRACE_INFO( "diagram does not exist or database not open." );
     212             :                     }
     213             :                 }
     214           0 :                 break;
     215             : 
     216           0 :                 default:
     217             :                 {
     218           0 :                     assert(false);  /* data_id_is_valid should have been false already */
     219             :                 }
     220             :                 break;
     221             :             }
     222             :         }
     223             :         else
     224             :         {
     225           0 :             U8_LOG_EVENT_STR( "User search input is not an id", search_string );
     226             :         }
     227             : 
     228             :         /* free text search */
     229           0 :         d_err = data_database_text_search_get_objects_by_textfragment ( &((*this_).db_searcher),
     230             :                                                                         search_string,
     231             :                                                                         &((*this_).temp_result_list)
     232             :                                                                       );
     233           0 :         if ( U8_ERROR_NONE != d_err )
     234             :         {
     235           0 :             U8_LOG_ERROR_HEX( "data_database_text_search_t could not search.", d_err );
     236             :         }
     237             : 
     238           0 :         gui_sketch_area_show_result_list ( (*this_).result_consumer, &((*this_).temp_result_list) );
     239           0 :         data_search_result_list_clear( &((*this_).temp_result_list) );
     240             :     }
     241             :     else
     242             :     {
     243           0 :         assert(false);
     244             :     }
     245             : 
     246           0 :     U8_TRACE_END();
     247           0 : }
     248             : 
     249           0 : void gui_search_runner_private_add_diagrams_of_classifier ( gui_search_runner_t *this_,
     250             :                                                             data_search_result_t *classifier_template,
     251             :                                                             data_search_result_list_t *io_list
     252             :                                                           )
     253             : {
     254           0 :     U8_TRACE_BEGIN();
     255           0 :     assert( classifier_template != NULL );
     256           0 :     assert( io_list != NULL );
     257           0 :     u8_error_t d_err = U8_ERROR_NONE;
     258             : 
     259             :     data_row_t classifier_row_id;
     260           0 :     if ( DATA_TABLE_CLASSIFIER == data_id_get_table( data_search_result_get_match_id_const( classifier_template )))
     261             :     {
     262           0 :         classifier_row_id = data_id_get_row_id( data_search_result_get_match_id_const( classifier_template ));
     263             :     }
     264             :     else
     265             :     {
     266           0 :         classifier_row_id = data_id_get_row_id( data_search_result_get_src_classifier_id_const( classifier_template ));
     267             :     }
     268             : 
     269             :     data_diagram_iterator_t diagram_iterator;
     270           0 :     d_err |= data_diagram_iterator_init_empty( &diagram_iterator );
     271           0 :     d_err |= data_database_reader_get_diagrams_by_classifier_id( (*this_).db_reader,
     272             :                                                                 classifier_row_id,
     273             :                                                                 &diagram_iterator
     274             :                                                               );
     275             : 
     276           0 :     if ( d_err == U8_ERROR_NONE )
     277             :     {
     278           0 :         while ( data_diagram_iterator_has_next( &diagram_iterator ) )
     279             :         {
     280           0 :             d_err |= data_diagram_iterator_next( &diagram_iterator, &((*this_).temp_diagram) );
     281           0 :             const data_row_t diagram_row_id = data_diagram_get_row_id( &((*this_).temp_diagram) );
     282           0 :             data_id_reinit( data_search_result_get_diagram_id_ptr( classifier_template ), DATA_TABLE_DIAGRAM, diagram_row_id );
     283             : 
     284           0 :             bool filter = false;
     285           0 :             switch ( data_id_get_table( data_search_result_get_match_id_const( classifier_template ) ) )
     286             :             {
     287           0 :                 case DATA_TABLE_FEATURE:
     288             :                 {
     289             :                     /* if a user searches explicitly for a feature-id, which feature/classifiers should be filtered? */
     290             :                     /* and how? till here, the classifier type is not yet loaded. */
     291             :                 }
     292           0 :                 break;
     293             : 
     294           0 :                 case DATA_TABLE_RELATIONSHIP:
     295             :                 {
     296             :                     /* if a user searches explicitly for a relationship-id, which ones should be filtered? */
     297             :                     /* and how? till here, the classifier type is not yet loaded. */
     298             :                 }
     299           0 :                 break;
     300             : 
     301           0 :                 default:
     302             :                 {
     303             :                     /* do not filter classifiers (or other things?) */
     304             :                 }
     305           0 :                 break;
     306             :             }
     307             : 
     308           0 :             if ( ! filter )
     309             :             {
     310           0 :                 const u8_error_t err = data_search_result_list_add( io_list, classifier_template );
     311           0 :                 if ( err != U8_ERROR_NONE )
     312             :                 {
     313             :                     /*d_err |= U8_ERROR_ARRAY_BUFFER_EXCEEDED;*/
     314           0 :                     U8_LOG_WARNING( "U8_ERROR_ARRAY_BUFFER_EXCEEDED at inserting search result to list" );
     315             :                 }
     316             :             }
     317             : 
     318           0 :             data_diagram_destroy( &((*this_).temp_diagram) );
     319             :         }
     320             :     }
     321             :     else
     322             :     {
     323           0 :         U8_TRACE_INFO( "diagram does not exist or database not open." );
     324             :     }
     325           0 :     d_err |= data_diagram_iterator_destroy( &diagram_iterator );
     326             : 
     327           0 :     U8_TRACE_END();
     328           0 : }
     329             : 
     330             : 
     331             : /*
     332             : Copyright 2020-2024 Andreas Warnke
     333             : 
     334             : Licensed under the Apache License, Version 2.0 (the "License");
     335             : you may not use this file except in compliance with the License.
     336             : You may obtain a copy of the License at
     337             : 
     338             :     http://www.apache.org/licenses/LICENSE-2.0
     339             : 
     340             : Unless required by applicable law or agreed to in writing, software
     341             : distributed under the License is distributed on an "AS IS" BASIS,
     342             : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     343             : See the License for the specific language governing permissions and
     344             : limitations under the License.
     345             : */

Generated by: LCOV version 1.16