Changeset 4557 for trunk/gli


Ignore:
Timestamp:
2003-06-11T13:43:03+12:00 (21 years ago)
Author:
jmt12
Message:

2030114: Hadn't actually implemented importing from collections other than dls/demo. The last resort step, running a dummy searchForMetadata() process, still doesn't seem to work properly.

File:
1 edited

Legend:

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

    r4513 r4557  
    5353import org.greenstone.gatherer.gui.MetaEditPane;
    5454import org.greenstone.gatherer.gui.NewCollectionMetadataPrompt;
     55import org.greenstone.gatherer.msm.ElementWrapper;
    5556import org.greenstone.gatherer.msm.GDMManager;
     57import org.greenstone.gatherer.msm.GreenstoneArchiveParser;
    5658import org.greenstone.gatherer.msm.MetadataSet;
    5759import org.greenstone.gatherer.msm.MetadataSetManager;
     
    195197    }
    196198
    197     /** Used to set the current collection to the given collection. Note that this call should -always- be proceeded by a ready call, and if the colection is ready and the saved flag is unset then the user should be prompted to save. Also note that this method creates yet another GShell to run buildcol.pl. */
     199    /** Used to set the current collection to the given collection. Note that this call should -always- be proceeded by a ready call, and if the colection is ready and the saved flag is unset then the user should be prompted to save. Also note that this method creates yet another GShell to run buildcol.pl.
     200     * @param description a description of the collection as a String
     201     * @param email the email address of the author/maintainer as a String
     202     * @param name the short name of the collection, which will subsequently be used to refer to this particular collection, as a String
     203     * @param title the longer title of the collection as a String
     204     * @param base_collection_directory if the user has chosen to base their new collection on an existing one, this is the directory where this base collection can be found, as a File, otherwise its null
     205     * @param metadata_sets if the user has decided to select several metadata sets with which to initially populate the GLI then this is an ArrayList of metadata set file names, otherwise its null
     206     */
    198207    public void createCollection(String description, String email, String name, String title, File base_collection_directory, ArrayList metadata_sets) {
     208    boolean cancelled = false;
    199209    special_case = NO_SPECIAL_CASE;
    200210    try {
    201                 // Create a progress monitor.
     211        // Create a progress monitor.
    202212        ProgressMonitor progress = new ProgressMonitor(Gatherer.g_man, get("Creating_New"), "mkcol.pl", 0, 7);
    203                 // Create the new collection.
     213        // Create the new collection.
    204214        makeCollection(description, email, name, title);
    205215        progress.setProgress(1);
    206216
    207                 // ACTIVE_DIR/gimport/
     217        // ACTIVE_DIR/gimport/
    208218        String a_dir = Utility.getCollectionDir(Gatherer.config.gsdl_path) + name + File.separator;
    209219
    210                 // Has to be done before creating greenstone directory metadata manager.
     220        // Has to be done before creating greenstone directory metadata manager.
    211221        File gimport_dir_temp = new File(Utility.getImportDir(a_dir)+"temp.dat");
    212222        File gimport_dir = gimport_dir_temp.getParentFile();
     
    216226        }
    217227
    218                 // ACTIVE_DIR/gcache/
     228        // ACTIVE_DIR/gcache/
    219229        File gcache_dir_temp = new File(Utility.getCacheDir(a_dir)+"temp.dat");
    220230        File gcache_dir = gcache_dir_temp.getParentFile();
     
    224234        }
    225235
    226                 // ACTIVE_DIR/log/
     236        // ACTIVE_DIR/log/
    227237        File log_dir_temp = new File(Utility.getLogDir(a_dir)+"temp.dat");
    228238        File log_dir = log_dir_temp.getParentFile();
     
    234244        progress.setProgress(2);
    235245
    236                 // Now create the collection object around the directory.
     246        // Now create the collection object around the directory.
    237247        collection = new Collection(new File(a_dir, name + ".col"));
    238248        collection.msm = new MetadataSetManager();
    239249        msm = collection.msm; // Legacy
    240250        collection.msm.load();
    241                 // Import default metadata sets if any.
     251        // Import default metadata sets if any.
    242252        for(int i = 0; metadata_sets != null && i < metadata_sets.size(); i++) {
    243253        MetadataSet metadata_set = (MetadataSet) metadata_sets.get(i);
     
    247257        // Before we create the CollectionDesignManager we have to check if we are basing it upon some other collection.
    248258        if(base_collection_directory != null) {
    249         // If so our first step is to correctly generate an import profile for our collection from this base collection.
     259        Gatherer.println("Basing new collection on existing one: " + base_collection_directory);
    250260        // Try to import any existing metadata sets for this collection. Look in base_collection_directory/metadata and import any metadata sets found.
    251         File base_metadata = new File(base_collection_directory, Utility.METADATA_DIR);
     261        File base_metadata = new File(base_collection_directory, Utility.META_DIR);
    252262        if(base_metadata.exists()) {
     263            Gatherer.println("Found the metadata directory.");
    253264            File[] possible_metadata_sets = base_metadata.listFiles();
    254265            for(int i = 0; possible_metadata_sets != null && i < possible_metadata_sets.length; i++) {
    255266            String filename = possible_metadata_sets[i].getName();
    256267            if(filename.endsWith(".mds")) {
    257                 ///ystem.err.println("Found a metadata set. Importing: " + possible_metadata_sets[i].getAbsolutePath());
     268                Gatherer.println("+ Found a metadata set. Importing: " + possible_metadata_sets[i].getAbsolutePath());
    258269                collection.msm.importMDS(possible_metadata_sets[i], false);
    259270            }
    260271            }
    261272        }
     273        else {
     274            Gatherer.println("This base collection has no metadata directory.");
     275        }
    262276        // If no sets were imported, then create a new metadata with this new collections name. Note that if this is one of the 'big five' collections then I already know the importing mappings as well.
    263277        boolean skip_import_phase = false;
    264278        if(collection.msm.getSets().size() == 0) {
     279            Gatherer.println("As there are no metadata sets loaded yet, we'll make special checks for the collections available on the GS2.39CD.");
    265280            CollectionConfiguration col_con = new CollectionConfiguration(new File(base_collection_directory, Utility.CONFIG_DIR));
    266281            // If the source collection is one of the 'big five' then we know what the metadata set is.
     
    268283            // Demo collection - part of the DLS
    269284            if(collection_name.equals(Utility.COLLECTION_DEMO) || collection_name.equals(Utility.COLLECTION_DLS)) {
     285            Gatherer.println("+ This is a DLS.mds collection.");
    270286            special_case = SPECIAL_DLS;
    271287            String demo_directory = (new File(base_collection_directory.getParentFile(), Utility.COLLECTION_DEMO_DIRECTORY)).getAbsolutePath();
    272             System.err.println("Demo directory = " + demo_directory);
    273288            String dls_directory = (new File(base_collection_directory.getParentFile(), Utility.COLLECTION_DLS_DIRECTORY)).getAbsolutePath();
    274             System.err.println("DLS directory = " + dls_directory);
    275289            // Add the dls.mds
    276290            collection.msm.importMDS(new File(Utility.METADATA_DIR + Utility.DLS_MDS), false);
     
    294308            // Prompt the user so that they can choose at least one initial metadata set. We're sneaky here and just create a ncm_prompt
    295309            else {
     310            Gatherer.println("This collection has no metadata sets, nor is it one of our special collections, thus we cannot import any metadata sets automatically. Present the user with the metadata set selection prompt.");
    296311            NewCollectionMetadataPrompt ncm_prompt = new NewCollectionMetadataPrompt();
    297312            // If cancelled then they really do mean to start a collection with no metadata sets.
     
    310325        }
    311326        // Do a dry metadata import run over the entire base collection, recording profile mappings. We do this by finding the archive files, and then iterating over them using the GreenstoneArchiveParser to retrieve metadata from them. We then process the importing of new metadata elements using the selectElement prompt used in a file action metadata import. However the big change is that we don't actually import any metadata, just create importing profiles.
    312         File base_archives = new File(base_collection_directory, Utility.ARCHIVE_DIR);
    313         if(!skip_import_phase && base_archives.exists()) {
    314             ///ystem.err.println("Found archives directory.");
    315         }
    316         // Failing that we do a dummy run over the files in the collection.
    317         else if(!skip_import_phase) {
    318             ///ystem.err.println("No archives directory. Searching files for metadata.xml information.");
    319             // Find the import directory
    320             File base_import = new File(base_collection_directory, Utility.IMPORT_DIR);
    321             if(!base_import.exists()) {
    322             base_import = new File(base_collection_directory, Utility.OLD_IMPORT_DIR);
     327        if(!skip_import_phase) {
     328            File base_archive = new File(base_collection_directory, Utility.ARCHIVE_DIR);
     329            if(base_archive.exists()) {
     330            Gatherer.println("+ Archive directory found. Inspecting archives for metadata information.");
     331            ArrayList metadata_elements = GreenstoneArchiveParser.extractMetadataElements(base_archive);
     332            for(int i = 0; !cancelled && i < metadata_elements.size(); i++) {
     333                String metadata_name = (String) metadata_elements.get(i);
     334                ElementWrapper target = collection.msm.prompt.selectElement(metadata_name);
     335                cancelled = Gatherer.c_man.getCollection().msm.prompt.wasDialogCancelled();
     336                if(!cancelled) {
     337                if(target != null) {
     338                    collection.msm.profiler.addAction(base_collection_directory.getAbsolutePath(), metadata_name, target.getName());
     339                }
     340                else {
     341                    collection.msm.profiler.addAction(base_collection_directory.getAbsolutePath(), metadata_name, null);
     342                }
     343                }
     344            }
     345            // Hopefully mappings should now be in place for metadata extracted from this collection.
    323346            }
    324             if(base_import.exists()) {
    325             searchForMetadata(base_import);
     347            else {
     348            Gatherer.println("+ Searching files for metadata.xml information.");
     349            // Find the import directory
     350            File base_import = new File(base_collection_directory, Utility.IMPORT_DIR);
     351            if(!base_import.exists()) {
     352                base_import = new File(base_collection_directory, Utility.OLD_IMPORT_DIR);
     353            }
     354            if(base_import.exists()) {
     355                searchForMetadata(base_import);
     356            }
    326357            }
    327             // And if that fails then we must have been asked by Satan himself to build the very digital collections of hell, because they don't match any goodly greenstone collection I have ever seen, so you can't blame me if I can't import them.
    328         }
     358        }
     359        // And if that fails then we must have been asked by Satan himself to build the very digital collections of hell, because they don't match any goodly greenstone collection I have ever seen, so you can't blame me if I can't import them.
     360
     361
    329362        // Now we update our collect.cfg
     363        Gatherer.println("Copy and update collect.cfg from base collection.");
    330364        updateCollectionCFG(new File(base_collection_directory, Utility.CONFIG_DIR), new File(a_dir, Utility.CONFIG_DIR), description, email, title);
    331365        }
     
    716750      */
    717751    public boolean loadCollection(String location) {
    718     ///ystem.err.println("Load Collection '" + location + "'");
     752    Gatherer.println("Load Collection '" + location + "'");
    719753    String[] args2 = new String[1];
    720754    args2[0] = location;
     
    11211155    String collection_path = (base_cfg.getParentFile().getParentFile()).getAbsolutePath();
    11221156
    1123     System.err.println("Searching for " + collection_path);
    11241157    HashMap mappings = collection.msm.profiler.getActions(collection_path);
    11251158    if(mappings == null) {
    1126         System.err.println("How is this happening?");
     1159        Gatherer.println("Mappings is null, which is odd. Leaving all configuration commands which use metadata as they are.");
    11271160    }
    11281161
     
    11941227                text.append(token);
    11951228                String temp_metadata = tokenizer.nextToken();
    1196                 String replacement = (String) mappings.get(temp_metadata);
     1229                String replacement = null;
     1230                if(mappings != null) {
     1231                    replacement = (String) mappings.get(temp_metadata);
     1232                }
    11971233                if(replacement != null) {
    11981234                    token = replacement;
     
    12121248                text.append(token);
    12131249                String temp_metadata = tokenizer.nextToken();
    1214                 String replacement = (String) mappings.get(temp_metadata);
     1250                String replacement = null;
     1251                if(mappings != null) {
     1252                    replacement = (String) mappings.get(temp_metadata);
     1253                }
    12151254                if(replacement != null) {
    12161255                    token = replacement;
Note: See TracChangeset for help on using the changeset viewer.