greenstone.org greenstone wiki greenstone trac planet greenstone

Changeset 16250

Show
Ignore:
Timestamp:
2008-06-30 14:46:16 (2 months ago)
Author:
ak19
Message:

For GSDLRemote case. Moved duplicate scheduling code into scheduling() method which is now only called when greenstone is NOT remote. Otherwise GLI won't allow creation of a new collection over a remote GS server.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gli/trunk/src/org/greenstone/gatherer/collection/CollectionManager.java

    r16132 r16250  
    557557            collection.import_options.setValue("removeold", true, null); 
    558558 
    559             //try to obtain email address of collection owner if it exists...  
    560             String stmp = Configuration.getEmail();  
    561             if(stmp != null) { 
    562                 collection.schedule_options.setValue("toaddr", false, Configuration.getEmail()); 
    563             } 
    564  
    565             //try to obtain email address of Greenstone installation webmaster for - used to indicate "sender".  
    566             File mcfg = new File(LocalGreenstone.getDirectoryPath()+"etc" + File.separator + "main.cfg"); 
    567             BufferedReader maincfg = new BufferedReader(new FileReader(mcfg));       
     559            // for remote case, scheduling causes an Exception on creating a new collection that  
     560            // can't be recovered from.  
     561            if (!Gatherer.isGsdlRemote) { 
     562                scheduling(); 
     563            } 
     564                     
     565            MetadataSetManager.clearMetadataSets(); 
     566            MetadataXMLFileManager.clearMetadataXMLFiles(); 
     567            DocXMLFileManager.clearDocXMLFiles(); 
     568 
     569            // Import default metadata sets, if any 
     570            // for (int i = 0; metadata_sets != null && i < metadata_sets.size(); i++) { 
     571            // importMetadataSet((MetadataSet) metadata_sets.get(i)); 
     572            // } 
     573 
     574            ProfileXMLFileManager.loadProfileXMLFile(new File(collection_directory_path + "metadata")); 
     575 
     576            // Before creating the CollectionDesignManager check if we are basing it upon some other collection 
     577            if (base_collection_directory != null) { 
     578                DebugStream.println("Basing new collection on existing one: " + base_collection_directory); 
     579 
     580                // If we're using a remote Greenstone server, download the collection shell to get the files needed 
     581                if (Gatherer.isGsdlRemote) { 
     582                    String base_collection_name = base_collection_directory.getName(); 
     583                    RemoteGreenstoneServer.downloadCollection(base_collection_name); 
     584                } 
     585 
     586                collection.setBaseCollection(base_collection_directory.getAbsolutePath()); 
     587                // copy over other needed directories 
     588                copyExtraBaseCollStuff(new File(collection_directory_path), base_collection_directory); 
     589 
     590                // Try to import any existing metadata sets for this collection 
     591                // Look in base_collection_directory/metadata and import any metadata sets found. 
     592                File base_metadata_directory = new File(base_collection_directory, "metadata"); 
     593                ArrayList base_metadata_sets = MetadataSetManager.listMetadataSets(base_metadata_directory); 
     594                if (base_metadata_sets != null) { 
     595                    for (int i = 0; i < base_metadata_sets.size(); i++) { 
     596                        importMetadataSet((MetadataSet) base_metadata_sets.get(i)); 
     597                    } 
     598                } 
     599                else { 
     600                    DebugStream.println("This base collection has no metadata directory."); 
     601                } 
     602 
     603                // Now we update our collect.cfg 
     604                DebugStream.println("Copy and update " + file_name + " from base collection."); 
     605 
     606                if (Gatherer.GS3 == true) { 
     607                    updateCollectionConfigXML(new File(base_collection_directory, Utility.CONFIG_GS3_FILE), 
     608                                        new File(collection_directory_path, Utility.CONFIG_GS3_FILE));  
     609                } else { 
     610                    updateCollectionCFG(new File(base_collection_directory, Utility.CONFIG_FILE), 
     611                                        new File(collection_directory_path, Utility.CONFIG_FILE), 
     612                                        description, email, title); 
     613                } 
     614            } 
     615 
     616            // Load the default metadata sets 
     617            addDefaultMetadataSets(); 
     618 
     619            // Make sure we always have the extracted metadata set 
     620            addRequiredMetadataSets(); 
     621 
     622            collection.cdm = new CollectionDesignManager(new File(getLoadedCollectionCfgFilePath())); 
     623 
     624            // We always set title and description here rather than calling mkcol.pl with Unicode arguments 
     625            CollectionMeta collection_name_collectionmeta = collection.cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR); 
     626            collection_name_collectionmeta.setValue(title); 
     627            CollectionMeta collection_extra_collectionmeta = collection.cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_COLLECTIONEXTRA_STR); 
     628            collection_extra_collectionmeta.setValue(description); 
     629 
     630            // Now that we have a CDM, update several settings, such as if we created this collection by basing it on another, set it as public automatically. This update is done to the internal xml structure which may be saved into collect.cfg or collectionConfig.xml accordingly. 
     631            if (base_collection_directory != null) { 
     632                // Update the creator and maintainer 
     633                CollectionMeta creator_collectionmeta = new CollectionMeta(collection.cdm.collect_config.getCreator()); 
     634                creator_collectionmeta.setValue(email); 
     635                creator_collectionmeta = null; 
     636                CollectionMeta maintainer_collectionmeta = new CollectionMeta(collection.cdm.collect_config.getMaintainer()); 
     637                maintainer_collectionmeta.setValue(email); 
     638                maintainer_collectionmeta = null; 
     639 
     640                // All collections based on others are automatically public 
     641                CollectionMeta public_collectionmeta = new CollectionMeta(collection.cdm.collect_config.getPublic()); 
     642                public_collectionmeta.setValue(StaticStrings.TRUE_STR); 
     643                public_collectionmeta = null; 
     644 
     645                // Finally reset the icons 
     646                CollectionMeta icon_collection_collectionmeta = collection.cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTION_STR); 
     647                icon_collection_collectionmeta.setValue(StaticStrings.EMPTY_STR); 
     648                icon_collection_collectionmeta = null; 
     649                CollectionMeta icon_collection_small_collectionmeta = collection.cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR); 
     650                icon_collection_small_collectionmeta.setValue(StaticStrings.EMPTY_STR); 
     651                icon_collection_small_collectionmeta = null; 
     652            } 
     653 
     654            saveCollection(); 
     655 
     656            // Create a lock file 
     657            createLockFile(new File(collection_directory_path, LOCK_FILE)); 
     658 
     659            // We're done. Let everyone know. 
     660            Gatherer.refresh(Gatherer.COLLECTION_OPENED); 
     661        } 
     662        catch (Exception error) { 
     663            DebugStream.printStackTrace(error); 
     664        } 
     665    } 
     666 
     667    private void scheduling()  
     668        throws Exception 
     669    { 
     670        //try to obtain email address of collection owner if it exists...  
     671        String stmp = Configuration.getEmail();  
     672        if(stmp != null) { 
     673            collection.schedule_options.setValue("toaddr", false, Configuration.getEmail()); 
     674        } 
     675         
     676        //The next few items deal with updating the SMTP server, and the to: and from: addresses 
     677        //from main.cfg and the collection configuration. if no changes are made, or the  
     678        //values are result to NULL, any existing values are kept.  
     679 
     680        //try to obtain email address of Greenstone installation webmaster for - used to indicate "sender".  
     681        File mcfg = new File(LocalGreenstone.getDirectoryPath() + File.separator + "etc" + File.separator + "main.cfg"); 
     682        BufferedReader maincfg = new BufferedReader(new FileReader(mcfg));           
    568683            stmp = ""; 
    569684            String fromaddr = "";  
     
    598713            maincfg.close(); 
    599714 
    600             //try if lookup faile
     715            //try if lookup fail
    601716            if(smtptmp.equals("NULL") || smtptmp.equals("null")) { 
    602717                String email2=fromaddr;  
     
    611726            } 
    612727 
    613             MetadataSetManager.clearMetadataSets(); 
    614             MetadataXMLFileManager.clearMetadataXMLFiles(); 
    615             DocXMLFileManager.clearDocXMLFiles(); 
    616  
    617             // Import default metadata sets, if any 
    618             // for (int i = 0; metadata_sets != null && i < metadata_sets.size(); i++) { 
    619             // importMetadataSet((MetadataSet) metadata_sets.get(i)); 
    620             // } 
    621  
    622             ProfileXMLFileManager.loadProfileXMLFile(new File(collection_directory_path + "metadata")); 
    623  
    624             // Before creating the CollectionDesignManager check if we are basing it upon some other collection 
    625             if (base_collection_directory != null) { 
    626                 DebugStream.println("Basing new collection on existing one: " + base_collection_directory); 
    627  
    628                 // If we're using a remote Greenstone server, download the collection shell to get the files needed 
    629                 if (Gatherer.isGsdlRemote) { 
    630                     String base_collection_name = base_collection_directory.getName(); 
    631                     RemoteGreenstoneServer.downloadCollection(base_collection_name); 
    632                 } 
    633  
    634                 collection.setBaseCollection(base_collection_directory.getAbsolutePath()); 
    635                 // copy over other needed directories 
    636                 copyExtraBaseCollStuff(new File(collection_directory_path), base_collection_directory); 
    637  
    638                 // Try to import any existing metadata sets for this collection 
    639                 // Look in base_collection_directory/metadata and import any metadata sets found. 
    640                 File base_metadata_directory = new File(base_collection_directory, "metadata"); 
    641                 ArrayList base_metadata_sets = MetadataSetManager.listMetadataSets(base_metadata_directory); 
    642                 if (base_metadata_sets != null) { 
    643                     for (int i = 0; i < base_metadata_sets.size(); i++) { 
    644                         importMetadataSet((MetadataSet) base_metadata_sets.get(i)); 
    645                     } 
    646                 } 
    647                 else { 
    648                     DebugStream.println("This base collection has no metadata directory."); 
    649                 } 
    650  
    651                 // Now we update our collect.cfg 
    652                 DebugStream.println("Copy and update " + file_name + " from base collection."); 
    653  
    654                 if (Gatherer.GS3 == true) { 
    655                     updateCollectionConfigXML(new File(base_collection_directory, Utility.CONFIG_GS3_FILE), 
    656                                         new File(collection_directory_path, Utility.CONFIG_GS3_FILE));  
    657                 } else { 
    658                     updateCollectionCFG(new File(base_collection_directory, Utility.CONFIG_FILE), 
    659                                         new File(collection_directory_path, Utility.CONFIG_FILE), 
    660                                         description, email, title); 
    661                 } 
    662             } 
    663  
    664             // Load the default metadata sets 
    665             addDefaultMetadataSets(); 
    666  
    667             // Make sure we always have the extracted metadata set 
    668             addRequiredMetadataSets(); 
    669  
    670             collection.cdm = new CollectionDesignManager(new File(getLoadedCollectionCfgFilePath())); 
    671  
    672             // We always set title and description here rather than calling mkcol.pl with Unicode arguments 
    673             CollectionMeta collection_name_collectionmeta = collection.cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR); 
    674             collection_name_collectionmeta.setValue(title); 
    675             CollectionMeta collection_extra_collectionmeta = collection.cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_COLLECTIONEXTRA_STR); 
    676             collection_extra_collectionmeta.setValue(description); 
    677  
    678             // Now that we have a CDM, update several settings, such as if we created this collection by basing it on another, set it as public automatically. This update is done to the internal xml structure which may be saved into collect.cfg or collectionConfig.xml accordingly. 
    679             if (base_collection_directory != null) { 
    680                 // Update the creator and maintainer 
    681                 CollectionMeta creator_collectionmeta = new CollectionMeta(collection.cdm.collect_config.getCreator()); 
    682                 creator_collectionmeta.setValue(email); 
    683                 creator_collectionmeta = null; 
    684                 CollectionMeta maintainer_collectionmeta = new CollectionMeta(collection.cdm.collect_config.getMaintainer()); 
    685                 maintainer_collectionmeta.setValue(email); 
    686                 maintainer_collectionmeta = null; 
    687  
    688                 // All collections based on others are automatically public 
    689                 CollectionMeta public_collectionmeta = new CollectionMeta(collection.cdm.collect_config.getPublic()); 
    690                 public_collectionmeta.setValue(StaticStrings.TRUE_STR); 
    691                 public_collectionmeta = null; 
    692  
    693                 // Finally reset the icons 
    694                 CollectionMeta icon_collection_collectionmeta = collection.cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTION_STR); 
    695                 icon_collection_collectionmeta.setValue(StaticStrings.EMPTY_STR); 
    696                 icon_collection_collectionmeta = null; 
    697                 CollectionMeta icon_collection_small_collectionmeta = collection.cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR); 
    698                 icon_collection_small_collectionmeta.setValue(StaticStrings.EMPTY_STR); 
    699                 icon_collection_small_collectionmeta = null; 
    700             } 
    701  
    702             saveCollection(); 
    703  
    704             // Create a lock file 
    705             createLockFile(new File(collection_directory_path, LOCK_FILE)); 
    706  
    707             // We're done. Let everyone know. 
    708             Gatherer.refresh(Gatherer.COLLECTION_OPENED); 
    709         } 
    710         catch (Exception error) { 
    711             DebugStream.printStackTrace(error); 
    712         } 
    713728    } 
    714729 
     
    11981213                return; 
    11991214            } 
    1200  
    1201             //THIS LOOKS LIKE THE BEST PLACE TO TRY AND UPDATE .col FILES FOR EXISTING COLLECTIONS...Wendy 
     1215             
     1216            if (!Gatherer.isGsdlRemote) { 
     1217                //THIS LOOKS LIKE THE BEST PLACE TO TRY AND UPDATE .col FILES FOR EXISTING COLLECTIONS...Wendy 
    12021218  
    1203             //First, see if "Schedule" exists in the XMl File...  
    1204             BufferedReader bir = new BufferedReader(new FileReader(collection_file));  
    1205             boolean flag = false;  
    1206             try { 
    1207                 String stmp = new String();  
     1219               //First, see if "Schedule" exists in the XMl File...  
     1220               BufferedReader bir = new BufferedReader(new FileReader(collection_file));  
     1221               boolean flag = false;  
     1222               try { 
     1223                    String stmp = new String();  
    12081224                
    1209                 while((stmp = bir.readLine()) != null) { 
    1210                     stmp = stmp.trim();   
    1211                     if(stmp.equals("<Schedule>") || stmp.equals("<Schedule/>")) { 
    1212                        flag = true;  
    1213                        break;  
     1225                    while((stmp = bir.readLine()) != null) { 
     1226                        stmp = stmp.trim();   
     1227                        if(stmp.equals("<Schedule>") || stmp.equals("<Schedule/>")) { 
     1228                            flag = true;  
     1229                            break;  
     1230                        } 
    12141231                    } 
    1215                 } 
    1216                 bir.close();  
    1217  
    1218             } catch (IOException ioe) { 
    1219                 //do something here 
    1220             } 
    1221  
    1222             //modify if old .col (i.e. no Schedule exists in XML file) 
    1223             if(!flag) { 
    1224                 File new_collection_file = new File(collection_directory.getAbsolutePath() + "/tmp.col"); 
    1225  
    1226  
    1227                 BufferedWriter bor = new BufferedWriter(new FileWriter(new_collection_file));  
    1228                 bir = new BufferedReader(new FileReader(collection_file));  
    1229  
    1230                 try {  
    1231                     String stmp = new String();  
    1232                     while((stmp = bir.readLine()) != null) { 
    1233                         String stmp2 = stmp.trim();  
    1234                         if(stmp2.startsWith("<!ELEMENT Argument")) { 
    1235                             bor.write("  <!ELEMENT Schedule          (Arguments*)>\n");                             
    1236                         } 
    1237                         else if(stmp2.equals("</BuildConfig>")) { 
    1238                                bor.write("      <Schedule/>\n");  
    1239                         } 
    1240  
    1241                         bor.write(stmp + "\n");  
    1242  
     1232                    bir.close();  
     1233                     
     1234                } catch (IOException ioe) { 
     1235                    Debug.printStackTrace(ioe); 
     1236                } 
     1237                 
     1238                //modify if old .col (i.e. no Schedule exists in XML file) 
     1239                if(!flag) { 
     1240                    File new_collection_file = new File(collection_directory.getAbsolutePath() + "/tmp.col"); 
     1241                     
     1242                     
     1243                    BufferedWriter bor = new BufferedWriter(new FileWriter(new_collection_file));  
     1244                    bir = new BufferedReader(new FileReader(collection_file));  
     1245                     
     1246                    try {  
     1247                        String stmp = new String();  
     1248                        while((stmp = bir.readLine()) != null) { 
     1249                            String stmp2 = stmp.trim();  
     1250                            if(stmp2.startsWith("<!ELEMENT Argument")) { 
     1251                                bor.write("  <!ELEMENT Schedule          (Arguments*)>\n");                         
     1252                            } 
     1253                            else if(stmp2.equals("</BuildConfig>")) { 
     1254                                bor.write("      <Schedule/>\n");  
     1255                            } 
     1256                             
     1257                            bor.write(stmp + "\n");  
     1258                             
     1259                        } 
     1260                        bir.close();  
     1261                        bor.close(); 
     1262                    } catch (IOException ioe) {   
     1263                        Debug.printStackTrace(ioe); 
     1264                    }   
     1265                     
     1266                    //copy over tmp.col to replace  
     1267                    try {  
     1268                        collection_file.delete(); 
     1269                        new_collection_file.renameTo(collection_file);  
     1270                    } catch (Exception e) {  
     1271                        Debug.printStackTrace(ioe); 
     1272                    }  
     1273                } 
     1274                 
     1275                // Open the collection file 
     1276                this.collection = new Collection(collection_file); 
     1277                if (collection.error) { 
     1278                    collection = null; 
     1279                    // Remove lock file 
     1280                    if (lock_file.exists()) { 
     1281                        lock_file.delete(); 
    12431282                    } 
    1244                     bir.close();  
    1245                     bor.close(); 
    1246                 } catch (IOException ioe) {   
    1247                   //do something here 
    1248                 }   
    1249  
    1250                 //copy over tmp.col to replace  
    1251                 try {  
    1252                 collection_file.delete(); 
    1253                 new_collection_file.renameTo(collection_file);  
    1254                 } catch (Exception e) {  
    1255                     //do something here  
    1256                 }  
    1257             } 
    1258  
    1259             // Open the collection file 
    1260             this.collection = new Collection(collection_file); 
    1261             if (collection.error) { 
    1262                 collection = null; 
    1263                 // Remove lock file 
    1264                 if (lock_file.exists()) { 
    1265                     lock_file.delete(); 
    1266                 } 
    1267                 throw(new Exception(Dictionary.get("CollectionManager.Missing_Config"))); // this error message does not agree with the error 
    1268             } 
    1269  
    1270  
    1271             //try to obtain email address of collection owner if it exists...  
    1272             String stmp = Configuration.getEmail();  
    1273             if(stmp != null) { 
    1274                 collection.schedule_options.setValue("toaddr", false, Configuration.getEmail()); 
    1275             } 
    1276  
    1277  
    1278  
    1279             //The next few items deal with updating the SMTP server, and the to: and from: addresses 
    1280             //from main.cfg and the collection configuration. if no changes are made, or the  
    1281             //values are result to NULL, any existing values are kept.  
    1282  
    1283             //try to obtain email address of Greenstone installation webmaster for - used to indicate "sender".  
    1284             File mcfg = new File(LocalGreenstone.getDirectoryPath()+"etc" + File.separator + "main.cfg"); 
    1285             BufferedReader maincfg = new BufferedReader(new FileReader(mcfg));       
    1286             stmp = ""; 
    1287             String fromaddr = "";  
    1288             while((stmp = maincfg.readLine()) != null) {  
    1289                 if(stmp.startsWith("maintainer")) { 
    1290                        fromaddr = stmp.substring(10); //length of MailServer  
    1291                    fromaddr = fromaddr.trim();   
    1292                    break;  
    1293                 } 
    1294             } 
    1295             maincfg.close();  
    1296             if(!fromaddr.equals("NULL") && !fromaddr.equals("null")) { 
    1297                 collection.schedule_options.setValue("fromaddr", false, fromaddr);           
    1298             } 
    1299  
    1300             //try to obtain an smtp server address from main.cfg. If that fails, 
    1301             //try mail.server if an email address exists. If that fails, 
    1302             //maybe a message to set attribute in main.cfg?  
    1303             //i'm pretty sure there exists functionality to do this, but  
    1304             //i'll finish this faster if I just wrote it 
    1305  
    1306  
    1307             maincfg = new BufferedReader(new FileReader(mcfg));            
    1308             String smtptmp = "NULL"; 
    1309             while((stmp = maincfg.readLine()) != null) {  
    1310                 if(stmp.startsWith("MailServer")) { 
    1311                        smtptmp = stmp.substring(10); //length of MailServer  
    1312                    smtptmp = smtptmp.trim();  
    1313                    break;  
    1314                 } 
    1315             } 
    1316             maincfg.close(); 
    1317  
    1318             //try if lookup failes 
    1319             if(smtptmp.equals("NULL") || smtptmp.equals("null")) { 
    1320                 String email2=fromaddr;  
    1321                 if(!email2.equals("NULL") && !email2.equals("null")) { 
    1322                     int loc = email2.indexOf('@');  
    1323                     email2 = email2.substring(loc+1);  
    1324                     smtptmp = "mail."+email2; 
    1325                 } 
    1326             } 
    1327             if(!smtptmp.equals("NULL") && !smtptmp.equals("null")) {  
    1328                 collection.schedule_options.setValue("smtp", false, smtptmp); 
    1329             } 
    1330  
    1331  
     1283                    throw(new Exception(Dictionary.get("CollectionManager.Missing_Config"))); // this error message does not agree with the error 
     1284                } 
     1285                 
     1286                scheduling(); 
     1287            } 
     1288           
    13321289            MetadataSetManager.clearMetadataSets(); 
    13331290            MetadataSetManager.loadMetadataSets(collection_metadata_directory);