Ignore:
Timestamp:
2020-07-12T02:51:45+12:00 (4 years ago)
Author:
ak19
Message:
  1. Added moveMetaXMLToCSV 2. Both this and exportMetaAsCSV now also made to work for the remote case. 3. Bugfix to oversight in GUIManager that in the previous commit used to ignore user selected csvfile and always created a metdata.csv in import folder. 4. Tidied up MetaToCSV.java some more.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/metadata/MetadataToCSV.java

    r34263 r34264  
    3939import java.io.*;
    4040import java.util.*;
     41import javax.swing.filechooser.FileNameExtensionFilter;
    4142import javax.swing.JFileChooser;
    42 import javax.swing.filechooser.FileNameExtensionFilter;
    4343import javax.swing.JFrame;
     44import javax.swing.JOptionPane;
    4445
    4546import org.apache.commons.csv.*;
    4647
    4748import org.greenstone.gatherer.util.SafeProcess;
    48 //import org.greenstone.gatherer.Configuration;
    4949import org.greenstone.gatherer.DebugStream;
    5050import org.greenstone.gatherer.Dictionary;
    51 import org.greenstone.gatherer.Gatherer;
    52 //import org.greenstone.gatherer.gui.WarningDialog;
    53 import org.greenstone.gatherer.collection.Collection;
    54 import org.greenstone.gatherer.metadata.MetadataChangedListener;
    55 import org.greenstone.gatherer.metadata.MetadataElement; //
    56 import org.greenstone.gatherer.metadata.MetadataSet;
    57 import org.greenstone.gatherer.metadata.MetadataSetManager;
     51import org.greenstone.gatherer.metadata.MetadataElement;
     52import org.greenstone.gatherer.metadata.MetadataValue;
    5853import org.greenstone.gatherer.metadata.MetadataXMLFileManager;
    59 import org.greenstone.gatherer.metadata.MetadataValue;//
     54
    6055
    6156
     
    8176    private File metadataCSVFile;   
    8277
    83     /** Is this useful?
     78    /** TODO: Is this useful?
    8479     * Not yet implemented: if this flag is true, then if a file mentioned in metadata.csv does not exist,
    8580     * its entry is dropped and won't appear again when the metadata.csv is written out again.
     
    274269     * then will need to remove all meta from GLI (metadata.xml files).
    275270     * Just del or rename those files to .bak?
     271     * This dangerous method goes through all the metadata.xml files that were in use so far
     272     * and removes all the child elements from meta xml files' DirectoryMetadata root elements
    276273     */
    277     public void moveGLIMetaToCSV(File csvFile) {
    278     boolean success = exportGLIMetaToCSV(csvFile);
    279     // TODO
    280     if(success) {
     274    public boolean moveMetaXMLToCSV(File csvFile, JFrame parent) {
     275
     276    // Warn the user about the operation being destructive
     277    int result = JOptionPane.showConfirmDialog(parent,
     278               Dictionary.get("ExportMeta.MoveMetaXMLToCSV_Warning_Message"),
     279               Dictionary.get("General.Warning"),
     280               JOptionPane.OK_CANCEL_OPTION,
     281               JOptionPane.WARNING_MESSAGE);
     282    if(result == JOptionPane.CANCEL_OPTION || result == JOptionPane.CLOSED_OPTION) {
     283        // NO_OPTION shouldn't happen
     284        return false;
     285    }
     286   
     287    boolean success = exportMetaXMLToCSV(csvFile);
     288
     289    if(success) { // now it's backed up to a metadatacsv file, can clear all metadata from metaXML files
     290
     291        System.err.println("About to clear all metadata in collection...");
     292        MetadataXMLFileManager.clearAllMetadataInCollection();
    281293    } else {
    282         System.err.println("Failed to export GLI metadata for this collection to CSV properly. Will not remove metadata.xml files");
    283     }
     294        JOptionPane.showMessageDialog(parent,
     295                      Dictionary.get("ExportMeta.MoveMetaXMLToCSV_Failed_Message"),
     296                      Dictionary.get("General.Error"),
     297                      JOptionPane.ERROR_MESSAGE);
     298        //System.err.println("@@@ Failed to properly export metadata.xml files' contents for this collection to CSV. Will not remove metadata.xml files");
     299    }
     300
     301    return success;
    284302    }
    285303
    286304    /** If given a new file to create, creates the specified meta csv file from GLI's meta for the current collection.
    287305     * If the file exists, this will append the GLI metadata without checking if the file already contains the same entries. */
    288     public boolean exportGLIMetaToCSV(File csvFile) {
     306    public boolean exportMetaXMLToCSV(File csvFile) {
    289307    boolean appendSetting = false;
    290308    boolean success = false;
    291 
    292     // if(csvFile.exists()) {
    293     //     appendSetting = true; // TODO: better to call the other version of this method in this case?
    294     // }
    295     // TreeMap<File, TreeMap<String,TreeSet<String>>> assignedMeta = getAllAssignedMetadataForAllFiles();
    296     // writeMetaToCSV(assignedMeta, csvFile, appendSetting);
    297309   
    298310    if(csvFile.exists()) {
     
    510522    }
    511523
    512     /** Filter to only allow Gathered GS documents
     524    /** Filter to only accept Gathered GS documents
    513525     * to produce the list of files for which we need to export GLI metadata info to CSV.
    514526     */
Note: See TracChangeset for help on using the changeset viewer.