Changeset 34264 for main/trunk
- Timestamp:
- 2020-07-12T02:51:45+12:00 (4 years ago)
- Location:
- main/trunk/gli
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/classes/dictionary.properties
r34263 r34264 534 534 #***** Export Metadata to CSV ***** 535 535 ExportMeta.ChooseMetaCSVFile: Export metadata from GLI to a new CSV file or add to existing 536 ExportMeta.MoveMetaXMLToCSV_Warning_Message: Warning, this will remove all metadata from GLI after exporting to CSV. Proceed? 537 ExportMeta.MoveMetaXMLToCSV_Failed_Message: Failed to export contents of collection metadata.xml files to CSV properly. Will not remove metadata.xml files. 536 538 # 537 539 #***** Inherited Metadata ***** … … 784 786 Menu.File_Exit:Exit 785 787 Menu.File_ExportAs:Export... 786 Menu.File_ExportMeta:Export metadata... 788 Menu.File_ExportMeta:Export metadata to CSV... 789 Menu.File_MoveMetaToCSV:Move metadata to CSV... 787 790 Menu.File_New:New... 788 791 Menu.File_Open:Open... -
main/trunk/gli/src/org/greenstone/gatherer/gui/GUIManager.java
r34263 r34264 199 199 eap = null; 200 200 } 201 else if (esrc == menu_bar.file_exportmeta ) {201 else if (esrc == menu_bar.file_exportmeta || esrc == menu_bar.file_movemeta) { 202 202 String currCollName = Gatherer.c_man.getCollection().getName(); 203 203 String collection_directory_path = CollectionManager.getCollectionDirectoryPath(currCollName); 204 204 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 212 227 } 213 228 else if (esrc == menu_bar.file_exit) { -
main/trunk/gli/src/org/greenstone/gatherer/gui/MenuBar.java
r34263 r34264 70 70 public JMenuItem file_exportas = null; 71 71 public JMenuItem file_exportmeta = null; 72 public JMenuItem file_movemeta = null; 72 73 public JMenuItem file_new = null; 73 74 public JMenuItem file_open = null; … … 126 127 file_exportmeta = new JMenuItem(Dictionary.get("Menu.File_ExportMeta")); 127 128 file_exportmeta.addActionListener(Gatherer.g_man); 128 file_exportmeta.setEnabled(!Gatherer.isGsdlRemote);129 129 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 131 135 file_new = new JMenuItem(Dictionary.get("Menu.File_New")); 132 136 file_new.addActionListener(Gatherer.g_man); … … 155 159 file.add(file_exportas); 156 160 file.add(file_exportmeta); 161 file.add(file_movemeta); 157 162 // these currently don't work. better to just disable them? 158 163 if (!Gatherer.GS3) { -
main/trunk/gli/src/org/greenstone/gatherer/metadata/MetadataToCSV.java
r34263 r34264 39 39 import java.io.*; 40 40 import java.util.*; 41 import javax.swing.filechooser.FileNameExtensionFilter; 41 42 import javax.swing.JFileChooser; 42 import javax.swing.filechooser.FileNameExtensionFilter;43 43 import javax.swing.JFrame; 44 import javax.swing.JOptionPane; 44 45 45 46 import org.apache.commons.csv.*; 46 47 47 48 import org.greenstone.gatherer.util.SafeProcess; 48 //import org.greenstone.gatherer.Configuration;49 49 import org.greenstone.gatherer.DebugStream; 50 50 import 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; 51 import org.greenstone.gatherer.metadata.MetadataElement; 52 import org.greenstone.gatherer.metadata.MetadataValue; 58 53 import org.greenstone.gatherer.metadata.MetadataXMLFileManager; 59 import org.greenstone.gatherer.metadata.MetadataValue;// 54 60 55 61 56 … … 81 76 private File metadataCSVFile; 82 77 83 /** Is this useful?78 /** TODO: Is this useful? 84 79 * Not yet implemented: if this flag is true, then if a file mentioned in metadata.csv does not exist, 85 80 * its entry is dropped and won't appear again when the metadata.csv is written out again. … … 274 269 * then will need to remove all meta from GLI (metadata.xml files). 275 270 * 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 276 273 */ 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(); 281 293 } 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; 284 302 } 285 303 286 304 /** If given a new file to create, creates the specified meta csv file from GLI's meta for the current collection. 287 305 * If the file exists, this will append the GLI metadata without checking if the file already contains the same entries. */ 288 public boolean export GLIMetaToCSV(File csvFile) {306 public boolean exportMetaXMLToCSV(File csvFile) { 289 307 boolean appendSetting = false; 290 308 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);297 309 298 310 if(csvFile.exists()) { … … 510 522 } 511 523 512 /** Filter to only a llowGathered GS documents524 /** Filter to only accept Gathered GS documents 513 525 * to produce the list of files for which we need to export GLI metadata info to CSV. 514 526 */ -
main/trunk/gli/src/org/greenstone/gatherer/metadata/MetadataXMLFile.java
r33749 r34264 64 64 } 65 65 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 66 93 67 94 public void addMetadata(CollectionTreeNode file_node, ArrayList metadata_values) -
main/trunk/gli/src/org/greenstone/gatherer/metadata/MetadataXMLFileManager.java
r33727 r34264 441 441 } 442 442 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 444 459 /** 445 460 * Comparator to order MetadataXMLFiles in ascending order from … … 448 463 * it to compare will be linear descendants of one toplevel folder 449 464 * 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 we465 * In other words, that each is a substring of one of the others until 451 466 * the toplevel folder is reached. 452 467 */
Note:
See TracChangeset
for help on using the changeset viewer.