Changeset 34264

Show
Ignore:
Timestamp:
12.07.2020 02:51:45 (3 weeks 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.

Location:
main/trunk/gli
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/classes/dictionary.properties

    r34263 r34264  
    534534#***** Export Metadata to CSV ***** 
    535535ExportMeta.ChooseMetaCSVFile: Export metadata from GLI to a new CSV file or add to existing 
     536ExportMeta.MoveMetaXMLToCSV_Warning_Message: Warning, this will remove all metadata from GLI after exporting to CSV. Proceed? 
     537ExportMeta.MoveMetaXMLToCSV_Failed_Message: Failed to export contents of collection metadata.xml files to CSV properly. Will not remove metadata.xml files. 
    536538# 
    537539#***** Inherited Metadata ***** 
     
    784786Menu.File_Exit:Exit 
    785787Menu.File_ExportAs:Export... 
    786 Menu.File_ExportMeta:Export metadata... 
     788Menu.File_ExportMeta:Export metadata to CSV... 
     789Menu.File_MoveMetaToCSV:Move metadata to CSV... 
    787790Menu.File_New:New... 
    788791Menu.File_Open:Open... 
  • main/trunk/gli/src/org/greenstone/gatherer/gui/GUIManager.java

    r34263 r34264  
    199199        eap = null; 
    200200    } 
    201     else if (esrc == menu_bar.file_exportmeta) { 
     201    else if (esrc == menu_bar.file_exportmeta || esrc == menu_bar.file_movemeta) { 
    202202        String currCollName = Gatherer.c_man.getCollection().getName(); 
    203203        String collection_directory_path = CollectionManager.getCollectionDirectoryPath(currCollName); 
    204204         
    205         String importDir = collection_directory_path + File.separator + "import"; 
    206         File selectedFile = MetadataToCSV.chooseMetaCSVFile(importDir, this); 
    207         if(selectedFile != null) { 
    208         MetadataToCSV toCSV = new MetadataToCSV(collection_directory_path, selectedFile); 
    209         //toCSV.printOrderedCollectionMeta();        
    210         toCSV.exportGLIMetaToCSV(new File(importDir, "metadata.csv")); 
    211         } 
     205        String importDir = collection_directory_path + "import"; 
     206        File csvFile = MetadataToCSV.chooseMetaCSVFile(importDir, this); 
     207        if(csvFile != null) { 
     208        MetadataToCSV toCSV = new MetadataToCSV(collection_directory_path, csvFile); 
     209         
     210        boolean success = false; 
     211        if(esrc == menu_bar.file_movemeta) { 
     212            success = toCSV.moveMetaXMLToCSV(csvFile, this); 
     213        } else { 
     214            success = toCSV.exportMetaXMLToCSV(csvFile); 
     215        } 
     216 
     217        // refresh coll view if meta.csv was created somewhere inside this coll's import folder 
     218        // And for remote case, also upload any new file that's inside import dir to server 
     219        if(success && csvFile.exists() && csvFile.getAbsolutePath().startsWith(importDir)) { 
     220            if(Gatherer.isGsdlRemote) { 
     221            Gatherer.remoteGreenstoneServer.uploadFilesIntoCollection(currCollName, new File[] {csvFile}, csvFile.getParentFile()); 
     222            } 
     223            Gatherer.g_man.refreshCollectionTree(DragTree.COLLECTION_CONTENTS_CHANGED); 
     224        } 
     225        } 
     226         
    212227    } 
    213228    else if (esrc == menu_bar.file_exit) { 
  • main/trunk/gli/src/org/greenstone/gatherer/gui/MenuBar.java

    r34263 r34264  
    7070    public JMenuItem file_exportas   = null; 
    7171    public JMenuItem file_exportmeta = null; 
     72    public JMenuItem file_movemeta   = null; 
    7273    public JMenuItem file_new        = null; 
    7374    public JMenuItem file_open       = null; 
     
    126127    file_exportmeta = new JMenuItem(Dictionary.get("Menu.File_ExportMeta")); 
    127128    file_exportmeta.addActionListener(Gatherer.g_man); 
    128     file_exportmeta.setEnabled(!Gatherer.isGsdlRemote); 
    129129    file_exportmeta.setComponentOrientation(Dictionary.getOrientation()); 
    130          
     130 
     131    file_movemeta = new JMenuItem(Dictionary.get("Menu.File_MoveMetaToCSV")); 
     132    file_movemeta.addActionListener(Gatherer.g_man); 
     133    file_movemeta.setComponentOrientation(Dictionary.getOrientation()); 
     134     
    131135    file_new = new JMenuItem(Dictionary.get("Menu.File_New")); 
    132136    file_new.addActionListener(Gatherer.g_man); 
     
    155159    file.add(file_exportas); 
    156160    file.add(file_exportmeta); 
     161    file.add(file_movemeta); 
    157162    // these currently don't work. better to just disable them? 
    158163    if (!Gatherer.GS3) { 
  • 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     */ 
  • main/trunk/gli/src/org/greenstone/gatherer/metadata/MetadataXMLFile.java

    r33749 r34264  
    6464    } 
    6565 
     66    public void clearAllMetadataInFile() { 
     67    // If this metadata.xml file isn't the one currently loaded, load it now 
     68    if (loaded_file != this) { 
     69        // First we must save out the currently loaded file 
     70        saveLoadedFile(); 
     71 
     72        // Parse the metadata.xml file 
     73        Document document = XMLTools.parseXMLFile(this); 
     74        if (document == null) { 
     75        System.err.println("Error: Could not parse metadata.xml file " + getAbsolutePath()); 
     76        return; 
     77        } 
     78 
     79        loaded_file = this; 
     80        loaded_file_document = document; 
     81         
     82        reEncodeFilenamesInMetadataXML(loaded_file_document); 
     83    } 
     84 
     85    Element root = loaded_file_document.getDocumentElement(); 
     86    while(root.hasChildNodes()) { 
     87        root.removeChild(root.getFirstChild()); 
     88    } 
     89    loaded_file_changed = true; 
     90    //saveLoadedFile(); // this final metaxml file being cleared of meta will get saved by MetaXMLFileManager.clearAllMetadataInCollection() 
     91    } 
     92     
    6693 
    6794    public void addMetadata(CollectionTreeNode file_node, ArrayList metadata_values) 
  • main/trunk/gli/src/org/greenstone/gatherer/metadata/MetadataXMLFileManager.java

    r33727 r34264  
    441441    } 
    442442 
    443    
     443    static public void clearAllMetadataInCollection() { 
     444    for (int j = 0; j < metadata_xml_files.size(); j++) { 
     445        MetadataXMLFile metadata_xml_file = (MetadataXMLFile) metadata_xml_files.get(j); 
     446        metadata_xml_file.clearAllMetadataInFile(); 
     447         
     448        // Let any listeners know that the metadata has changed 
     449        //fireMetadataChangedEvent(file_nodes); // sadly don't have file_nodes needed to do this 
     450 
     451        // all are modified      
     452        if (!modified_metadata_xml_files.contains(metadata_xml_file)) {      
     453        modified_metadata_xml_files.add(metadata_xml_file); 
     454        } 
     455        saveMetadataXMLFiles(); // saves final modified metaXML and then takes care of uploading all modified metaXML files to remote gsdl   
     456    } 
     457    } 
     458         
    444459    /** 
    445460      * Comparator to order MetadataXMLFiles in ascending order from 
     
    448463      * it to compare will be linear descendants of one toplevel folder 
    449464      * E.g. /A/metadata.xml, /A/B/metadata.xml, /A/B/C/D/metadata.xml. 
    450       * In other words, that each is a substring of one of the others until we 
     465      * In other words, that each is a substring of one of the others until 
    451466      * the toplevel folder is reached. 
    452467    */