Index: /gsdl/trunk/perllib/cfgread4gs3.pm
===================================================================
--- /gsdl/trunk/perllib/cfgread4gs3.pm	(revision 14183)
+++ /gsdl/trunk/perllib/cfgread4gs3.pm	(revision 14184)
@@ -30,9 +30,8 @@
 no strict 'refs';
 no strict 'subs';
+
 # Wrapper that ensures the right version of XML::Parser is loaded given
 # the version of Perl being used.  Need to distinguish between Perl 5.6 and
 # Perl 5.8
-
-
 sub BEGIN {
     my $perl_dir;
@@ -59,6 +58,6 @@
 }
 
-#use XML::Parser;
-  
+use XML::Parser;
+
 # A mapping hash to resolve name descrepency between gs2 and gs3.
 my $nameMap = {"key" => "value",
@@ -350,7 +349,10 @@
 }
 
+# Create the buildConfig.xml file for a specific collection
 sub write_cfg_file {
-    # information needed from $collectcfg: defaultindex, defaultlevel, classifiers, 
-    # the rest is from $buildcfg
+    # this sub is called make_auxiliary_files() in basebuilder.pm
+    # the received args: $buildoutfile - destination file: buildConfig.xml
+    #                    $buildcfg - all build options, eg, disable_OAI
+    #                    $collectcfg - contents of collectionConfig.xml read in by read_cfg_file sub in cfgread4gs3.pm.
     my ($buildoutfile, $buildcfg, $collectcfg) = @_;
     my $line = [];
@@ -389,4 +391,14 @@
     &write_line('COLCFG', ["<serviceRackList>"]);
 
+    # This serviceRack enables the collection to provide the oai metadata retrieve service, which is served by the OAIPMH.java class
+    # For each collection, we write the following serviceRack in the collection's buildConfig.xml file as follows if the 'disable_OAI' argument is not ticked in GLI (or equivalently, a 'disable_OAI' flag is not specified on the command line). There are also other configurations in the OAIConfig.xml.
+    if ($buildcfg->{'disable_OAI'} == 0) {
+      &write_line('COLCFG', ["<serviceRack name=\"OAIPMH\">"]);
+      if (defined $buildcfg->{'indexstem'}) {
+        my $indexstem = $buildcfg->{'indexstem'};
+        &write_line('COLCFG', ["<indexStem name=\"", $indexstem, "\" />"]);     
+      }
+      &write_line('COLCFG', ["</serviceRack>"]);
+    }    
     # do the search service 
     &write_line('COLCFG', ["<serviceRack name=\"GS2", $service_type, "Search\">"]);
@@ -408,7 +420,11 @@
 	$maptype = "indexmap";
     }
+
+    map {print $_."\n"} keys %$buildcfg;
+
     if (defined $buildcfg->{$maptype}) {
 	my $indexmap_t = $buildcfg->{$maptype};
-	foreach my $i (@$indexmap_t) {
+       foreach my $i (@$indexmap_t) {
+	print "i=".$i;
 	    my ($k, $v) = $i =~ /^(.*)\-\>(.*)$/;
 	    $indexmap->{$k} = $v;
@@ -460,6 +476,7 @@
     my $levelmap = {};
     my @levellist = ();
-    my $default_search_level = "";
-    my $default_retrieve_level = "Doc";#this is defaultGDBMLevel (also for the retrieve service)
+    my $default_search_level = "Doc";
+    my $default_retrieve_level = "Doc";
+    my $default_gdbm_level = "Doc";
     $first = 1;
     if ($buildtype eq "mgpp" || $buildtype eq "lucene") {
@@ -471,17 +488,26 @@
 		push @levellist, $key;
 		if ($first) {
+		    # let default search level follow the first level in the level list
 		    $default_search_level = $val;
+		    # retrieve/GDBM levels may get modified later if text level is defined
+		    $default_retrieve_level = $val;
+		    $default_gdbm_level = $val;
 		    $first = 0;
 		}
 	    }
 	}
-	# now if the user has assigned a default level, we use it 
-	if (defined $collectcfg->{"defaultlevel"}) {
-	  $default_search_level = $levelmap->{$collectcfg->{"defaultlevel"}};
-          $default_retrieve_level = $default_search_level;     
-	}
-	#if (defined $buildcfg->{'textlevel'}) {
-	   # $default_retrieve_level = $buildcfg->{'textlevel'};
+	# even if the user has assigned a default level, we ignore it. Why?
+	# I don't know, but it seems it's the way how the serving works
+	#if (defined $collectcfg->{"defaultlevel"}) {
+	#  $default_search_level = $levelmap->{$collectcfg->{"defaultlevel"}};
+        #  $default_retrieve_level = $default_search_level;
 	#}
+	
+	if (defined $buildcfg->{'textlevel'}) {
+	   # let the retrieve/gdbm levels always follow the textlevel
+           $default_retrieve_level = $buildcfg->{'textlevel'};
+	   $default_gdbm_level = $buildcfg->{'textlevel'};
+		 
+	}
     }
     #for each level in levelList, write them out
@@ -490,5 +516,5 @@
     foreach my $lv (@levellist) {
 	my $level = $levelmap->{$lv};
-	&write_line('COLCFG', ["<level name=\"", $lv, "\" shortname=\"", $level, "\" />"]);
+        &write_line('COLCFG', ["<level name=\"", $lv, "\" shortname=\"", $level, "\" />"]);
     }	
     &write_line('COLCFG', ["</levelList>"]);
@@ -498,5 +524,7 @@
 	&write_line('COLCFG', ["<defaultLevel shortname=\"", $default_search_level, "\" />"]);
     }
-    &write_line('COLCFG', ["<defaultGDBMLevel shortname=\"", $default_retrieve_level, "\" />"]);
+    
+    # make the GDBM level 
+    &write_line('COLCFG', ["<defaultGDBMLevel shortname=\"", $default_gdbm_level, "\" />"]);
 
     # do searchTypeList
