Ignore:
Timestamp:
2008-02-22T11:25:40+13:00 (16 years ago)
Author:
davidb
Message:

Collections can now be put in to "groups" i.e. can be located inside another collection, which is marked as "collectgroup" true. The top-level collection appears on the home page, and when clicked upon display a new "home page" with only the collections appearing within its folder displayed. To implement this, the main change is in collectset.cpp, which now runs "add_all_collection_groups" after it has added all the top-level collections. comtypes.h has been updated to include the new field, "isCollectGroup". Finally, pageaction.cpp has been updated so these changes are reflected in the home page generated.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/src/colservr/collectset.cpp

    r12246 r15002  
    5151  // get gsdlhome (if we fail the error will be picked up later -- in
    5252  // cgiwrapper)
     53
    5354  if (site_cfg_read (gsdlhome, httpdomain, httpprefix)) {
    5455    if (!gsdlhome.empty() && directory_exists(gsdlhome)) {
     
    6667      }
    6768
    68       // read config file to see if built with mg, mgpp, or lucene
    69       text_t buildtype = "mg"; // mg is default
    70       text_tarray cfgline;
    71       text_t key;
    72       text_t filename = filename_cat(collectdir, *thiscol, "index" , "build.cfg");
    73       ifstream confin(filename.getcstr());
    74 
    75       if (confin) {
    76         while (read_cfg_line(confin, cfgline) >= 0) {
    77           if (cfgline.size() ==2 ) {
    78         key = cfgline[0];
    79         cfgline.erase(cfgline.begin());
    80         if (key =="buildtype") {
    81           buildtype = cfgline[0];
    82           break;
    83         }
    84           }
    85         }
    86       }
    87      
    88       confin.close();
    89 
    90       // this memory is created but never destroyed
    91       // we're also not doing any error checking to make sure we didn't
    92       // run out of memory
    93       collectserver *cserver = new collectserver();
    94       gdbmclass *gdbmhandler = new gdbmclass();
    95    
    96       // add a null filter
    97       filterclass *filter = new filterclass ();
    98       cserver->add_filter (filter);
    99      
    100       // add a browse filter
    101       browsefilterclass *browsefilter = new browsefilterclass();
    102       browsefilter->set_gdbmptr (gdbmhandler);
    103       cserver->add_filter (browsefilter);
    104      
    105       if (buildtype == "mg") {
    106         mgsearch = new mgsearchclass();
    107        
    108         // add a query filter
    109         mgqueryfilterclass *queryfilter = new mgqueryfilterclass();
    110         queryfilter->set_gdbmptr (gdbmhandler);
    111         queryfilter->set_textsearchptr (mgsearch);
    112         cserver->add_filter (queryfilter);
    113        
    114         // add a mg and gdbm source
    115         mggdbmsourceclass *mggdbmsource = new mggdbmsourceclass ();
    116         mggdbmsource->set_gdbmptr (gdbmhandler);
    117         mggdbmsource->set_textsearchptr (mgsearch);
    118         cserver->add_source (mggdbmsource);
    119 
    120       }
    121       else if (buildtype == "mgpp") {
    122        
    123         mgppsearch = new mgppsearchclass();
    124                
    125         // add a query filter
    126         mgppqueryfilterclass *queryfilter = new mgppqueryfilterclass();
    127         queryfilter->set_gdbmptr (gdbmhandler);
    128         queryfilter->set_textsearchptr (mgppsearch);
    129         cserver->add_filter (queryfilter);
    130        
    131         // add a mg and gdbm source
    132         mggdbmsourceclass *mggdbmsource = new mggdbmsourceclass ();
    133         mggdbmsource->set_gdbmptr (gdbmhandler);
    134         mggdbmsource->set_textsearchptr (mgppsearch);
    135         cserver->add_source (mggdbmsource);   
    136       }
    137       else if (buildtype == "lucene") {
    138         lucenesearch = new lucenesearchclass();
    139         lucenesearch->set_gsdlhome(gsdlhome);
    140 
    141         // add a query filter
    142         lucenequeryfilterclass *queryfilter = new lucenequeryfilterclass();
    143         queryfilter->set_gdbmptr (gdbmhandler);
    144         queryfilter->set_textsearchptr (lucenesearch);
    145         cserver->add_filter (queryfilter);
    146        
    147         // add a lucene and gdbm source
    148         lucenegdbmsourceclass *lucenegdbmsource = new lucenegdbmsourceclass ();
    149         lucenegdbmsource->set_gdbmptr (gdbmhandler);
    150         lucenegdbmsource->set_textsearchptr (lucenesearch);
    151         cserver->add_source (lucenegdbmsource);   
    152       }
    153 
    154 
    155       // inform collection server and everything it contains about its
    156       // collection name
    157       cserver->configure ("collection", *thiscol);
    158       // AZIZ: added on 10/10/00
    159       //       the cserver object does not have a reference to gsdlhome
    160       cserver->configure ("gsdlhome", gsdlhome);
    161    
    162       // GRB: removed    proto.add_collectserver (cserver);
    163       // GRB: added to build our own cservers list
    164       cservers.addcollectserver (cserver);
     69      this->add_collection (*thiscol, gsdlhome);
    16570
    16671      ++thiscol;
    16772    }
     73
     74    this->add_all_collection_groups(gsdlhome);
    16875      }
    16976    }
     
    198105      // are available to decode defaultindex, defaultsubcollection, and
    199106      // defaultlanguage
     107
     108      bool failed_build_cfg = false;
    200109      if (!build_cfg_read (*((*here).second.c), configinfo.gsdlhome,
    201110               configinfo.collection)) {
     111    failed_build_cfg = true;
     112
    202113    outconvertclass text_t2ascii;
    203114    logout << text_t2ascii
     
    205116           << configinfo.collection << "\", gsdlhome=\""
    206117           << configinfo.gsdlhome << "\"\n";
    207     ++here;
    208     continue;
    209       }
    210 
     118      }
     119
     120      bool failed_collect_cfg = false;
    211121      if (!collect_cfg_read (*((*here).second.c), configinfo.gsdlhome,
    212122                 configinfo.collection)) {
     123    failed_collect_cfg = true;
    213124    outconvertclass text_t2ascii;
    214125    logout << text_t2ascii
     
    216127           << configinfo.collection << "\", gsdlhome=\""
    217128           << configinfo.gsdlhome << "\"\n";
     129      }
     130
     131     
     132      bool is_colgroup = (*here).second.c->is_collection_group();
     133
     134      if (failed_collect_cfg) {
    218135    ++here;
    219136    continue;
    220137      }
     138
     139      if (failed_build_cfg && (!is_colgroup)) {
     140    ++here;
     141    continue;
     142      }
     143      // let a failed build.cfg through if its 'collect.cfg' marks it as 'collectgroup true'
    221144
    222145      if (!(*here).second.c->init (logout)) return false;
     
    258181      ++thiscol;
    259182    }
     183
     184    this->add_all_collection_groups(gsdlhome);
    260185  }
    261186}
     
    266191                 const text_t &gsdlhome) {
    267192
    268   // if an old collection server exists for this collection we should
    269   // delete it first
    270   collectservermapclass::iterator here = cservers.begin();
    271   collectservermapclass::iterator end = cservers.end();
    272   while (here != end) {
    273     if ((*here).second.c != NULL && (*here).first == collection) {
    274       delete (*here).second.c;
    275       cservers.erase (here);
    276       break;
    277     }
    278     ++here;
    279   }
    280      
     193  this->remove_collection(collection);
     194 
    281195  // read config file to see if built with mg, mgpp, or lucene
    282196  // -- we can rely on the collection (and therefore the build.cfg)
     
    371285  cserver->configure ("gsdlhome", gsdlhome);
    372286
    373   /* Removed from add_collection 24/11/2000; already done elsewhere in collectset. 
    374   // configure receptionist's collectinfo structure
    375   text_tarray colinfo;
    376   colinfo.push_back (collection);
    377   colinfo.push_back (gsdlhome);
    378   colinfo.push_back (gdbmhome);
    379   */
    380287  cservers.addcollectserver (cserver);
    381288}
     
    399306  }
    400307  cservers.clear();
     308}
     309
     310void collectset::add_collection_group(const text_t& collection,
     311                      const text_t& gsdlhome)
     312{
     313  text_tarray group;
     314  text_t collect_group_dir = filename_cat (gsdlhome, "collect", collection);
     315
     316  // need to read collect.cfg for 'collectgroup' as class hasn't been initialised through 'init' yet
     317  text_t is_collect_group;
     318  text_tarray cfgline;
     319  text_t key;
     320  text_t build_cfg = filename_cat(gsdlhome, "collect", collection, "etc", "collect.cfg");
     321  char *collect_cfgc = build_cfg.getcstr();
     322  ifstream confin(collect_cfgc);
     323
     324  if (confin) {
     325    while (read_cfg_line(confin, cfgline) >= 0) {
     326      if (cfgline.size() == 2) {
     327    key = cfgline[0];
     328    cfgline.erase(cfgline.begin());
     329    if (key == "collectgroup") {
     330      is_collect_group = cfgline[0];
     331      break;
     332    }
     333      }
     334    }
     335    confin.close();
     336  }
     337  delete []collect_cfgc;
     338
     339  if (is_collect_group == "true") {
     340
     341    if (read_dir (collect_group_dir, group)) {
     342     
     343      text_tarray::const_iterator thiscol = group.begin();
     344      text_tarray::const_iterator endcol = group.end();
     345     
     346      while (thiscol != endcol) {
     347    // ignore the modelcol
     348    if (*thiscol == "etc") {
     349      ++thiscol;
     350      continue;
     351    }
     352   
     353    this->add_collection (collection + "/" + *thiscol, gsdlhome);
     354   
     355    ++thiscol;
     356      }
     357    }
     358  }
     359}
     360
     361void collectset::add_all_collection_groups (const text_t& gsdlhome)
     362
     363{
     364  collectservermapclass::iterator here = cservers.begin();
     365  collectservermapclass::iterator end = cservers.end();
     366 
     367  while (here != end) {
     368    text_t collection = (*here).second.c->get_collection_name();
     369    this->add_collection_group(collection,gsdlhome);
     370
     371    ++here;
     372  }
     373}
     374
     375
     376// remove_collection deletes the collection server of collection.
     377// This only needs to be called if a collectionserver is to be
     378// removed while the library is running. The destructor function
     379// cleans up all collectservers when the program exits.
     380void collectset::remove_collection (const text_t &collection) {
     381
     382  // do nothing if no collection server exists for this collection
     383  if (cservers.getcollectserver(collection) == NULL) return;
     384
     385  // first unload any cached mg databases - we may need to do something
     386  // similar to this for mgpp and lucene too
     387  if (mgsearch != NULL) {
     388    mgsearch->unload_database();
     389  }
     390
     391  // now delete the collection server object
     392  collectservermapclass::iterator here = cservers.begin();
     393  collectservermapclass::iterator end = cservers.end();
     394
     395  while (here != end) {
     396    if ((*here).second.c != NULL && (*here).first == collection) {
     397      delete (*here).second.c;
     398      cservers.erase (here);
     399      return;
     400    }
     401    ++here;
     402  }
    401403}
    402404
     
    408410void collectset::remove_collection (const text_t &collection, ostream &logout) {
    409411
    410   // do nothing if no collection server exists for this collection
    411   if (cservers.getcollectserver(collection) == NULL) return;
    412 
    413   // first unload any cached mg databases - we may need to do something
    414   // similar to this for mgpp and lucene too
    415   if (mgsearch != NULL) {
    416     mgsearch->unload_database();
    417   }
    418 
    419   // now delete the collection server object
    420   collectservermapclass::iterator here = cservers.begin();
    421   collectservermapclass::iterator end = cservers.end();
    422 
    423   while (here != end) {
    424     if ((*here).second.c != NULL && (*here).first == collection) {
    425       delete (*here).second.c;
    426       cservers.erase (here);
    427       return;
    428     }
    429     ++here;
    430   }
     412  remove_collection(collection);
     413
    431414  outconvertclass text_t2ascii;
    432415  logout << text_t2ascii << "nullproto::remove_collection: failed to remove collectserver for "
Note: See TracChangeset for help on using the changeset viewer.