private void continueButton_Button_Pressed(object sender, EventArgs e) { if (textBox1.Text.Trim().Length > 0) { oaiUrl = textBox1.Text.Trim(); repositoryInfo = OAI_Repository_Stream_Reader.Identify(oaiUrl); if (repositoryInfo.Is_Valid) { OAI_Repository_Stream_Reader.List_Metadata_Formats(repositoryInfo); if (!repositoryInfo.Metadata_Formats.Contains("oai_dc")) { MessageBox.Show(repositoryInfo.Name + " does not support 'oai_dc' metadata format. ", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MetaTemplate_UserSettings.Last_OAI_URL = oaiUrl; MetaTemplate_UserSettings.Save(); DialogResult = DialogResult.OK; Close(); } } else { MessageBox.Show("Unable to connect to the OAI-PMH repository listed.\n\nTry checking the URL or your network connections. ", "Error Encountered", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Enter the OAI-PMH Repository URL to continue. ", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void testButton_Button_Pressed(object sender, EventArgs e) { OAI_Repository_Information repositoryInfo = OAI_Repository_Stream_Reader.Identify(textBox1.Text.Trim()); if (repositoryInfo.Is_Valid) { OAI_Repository_Stream_Reader.List_Metadata_Formats(repositoryInfo); if (repositoryInfo.Metadata_Formats.Contains("oai_dc")) { MessageBox.Show("Connection to '" + repositoryInfo.Name + "' successful! ", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(repositoryInfo.Name + " does not support 'oai_dc' metadata format. ", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Unable to connect to the OAI-PMH repository listed.\n\nTry checking the URL or your network connections. ", "Error Encountered", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public OAI_PMH_Record_Import_Form(OAI_Repository_Information Repository) { CheckForIllegalCrossThreadCalls = false; InitializeComponent(); // Try to create a directory under the application first try { mappings_directory = Application.StartupPath + "\\OAI"; if (!Directory.Exists(mappings_directory)) { Directory.CreateDirectory(mappings_directory); } StreamWriter testWriter = new StreamWriter(mappings_directory + "\\test.txt"); testWriter.WriteLine("PERMISSIONS TEST"); testWriter.Flush(); testWriter.Close(); File.Delete(mappings_directory + "\\test.txt"); } catch (Exception ee) { try { mappings_directory = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\METS Editor\\OAI"; if (!Directory.Exists(mappings_directory)) { Directory.CreateDirectory(mappings_directory); } StreamWriter testWriter = new StreamWriter(mappings_directory + "\\test.txt"); testWriter.WriteLine("PERMISSIONS TEST"); testWriter.Flush(); testWriter.Close(); File.Delete(mappings_directory + "\\test.txt"); } catch (Exception e) { mappings_directory = String.Empty; } } repository = Repository; // Get the list of sets bool setPullSuccess = OAI_Repository_Stream_Reader.List_Sets(Repository); foreach (KeyValuePair <string, string> set in Repository.Sets) { setComboBox.Items.Add(set.Key + " ( " + set.Value + " )"); } step1Label.ForeColor = ControlPaint.Dark(SystemColors.ActiveCaption); step2Label.ForeColor = ControlPaint.LightLight(SystemColors.ActiveCaption); constant_map_inputs = new List <Constant_Assignment_Control>(); // Create the constants mapping custom control // Add eight constant user controls to panel for (int i = 1; i < 9; i++) { Constant_Assignment_Control thisConstantCtrl = new Constant_Assignment_Control(); thisConstantCtrl.Location = new Point(10, 10 + ((i - 1) * 30)); pnlConstants.Controls.Add(thisConstantCtrl); constant_map_inputs.Add(thisConstantCtrl); } // set some of the constant columns to required tracking fields constant_map_inputs[0].Mapped_Name = "First BibID"; constant_map_inputs[1].Mapped_Name = "Aggregation Code"; }
/// <summary> Perform the requested work </summary> public void Do_Work() { // Get the current user name string username = WindowsIdentity.GetCurrent().Name; int recordsProcessed = 0; // Look for a mappings file for this repository Dictionary <string, string> oai_objectid_mapping = new Dictionary <string, string>(); string mappings_file = mapping_directory + "\\" + repository.Repository_Identifier + ".xml"; try { if (String.IsNullOrEmpty(repository.Repository_Identifier)) { mappings_file = mapping_directory + "\\" + repository.Name + ".xml"; } if ((mapping_directory.Length > 0) && (Directory.Exists(mapping_directory)) && (File.Exists(mappings_file))) { DataSet mappingSet = new DataSet(); mappingSet.ReadXml(mappings_file); foreach (DataRow thisRow in mappingSet.Tables[0].Rows) { oai_objectid_mapping[thisRow[0].ToString()] = thisRow[1].ToString(); } } } catch (Exception ee) { Debug.WriteLine(ee.Message); OnComplete(0, OAI_PMH_Importer_Error_Enum.Unable_to_read_existing_mappings_file); } // Get the first set of records OAI_Repository_Records_List records = OAI_Repository_Stream_Reader.List_Records(repository.Harvested_URL, set_to_import, "oai_dc"); if ((records == null) || (records.Count == 0)) { OnComplete(0, OAI_PMH_Importer_Error_Enum.Unable_to_pull_feed_data); return; } // Flag used to keep the user request if a previous mapping is found that matches a record Nullable <bool> use_previous_mappings = null; try { // Continue through each pull using the resumption token while ((records != null) && (records.Count > 0)) { // Step through these records int total_count = records.Count; for (int i = 0; i < total_count; i++) { // Get this record out OAI_Repository_DublinCore_Record record = records[i]; // Create the bib package SobekCM_Item bibPackage = new SobekCM_Item(record); // Add some more information about the repository here bibPackage.Bib_Info.Add_Identifier(record.OAI_Identifier, "oai"); bibPackage.Bib_Info.Record.Main_Record_Identifier.Type = "oai"; bibPackage.Bib_Info.Record.Main_Record_Identifier.Identifier = record.OAI_Identifier; bibPackage.Bib_Info.Location.Other_URL_Note = repository.Name; bibPackage.Bib_Info.Location.Other_URL_Display_Label = "External Link"; bibPackage.Bib_Info.Source.Statement = repository.Name; // Add constant data from each mapped column into the bib package constantCollection.Add_To_Package(bibPackage); // Make sure there is a title if (bibPackage.Bib_Info.Main_Title.ToString().Trim().Length == 0) { bibPackage.Bib_Info.Main_Title.Title = "Missing Title"; } // Set some defaults bibPackage.Source_Directory = destination_folder; if (MetaTemplate_UserSettings.Individual_Creator.Length > 0) { bibPackage.METS_Header.Creator_Individual = MetaTemplate_UserSettings.Individual_Creator; } else { bibPackage.METS_Header.Creator_Individual = username; } bibPackage.METS_Header.Add_Creator_Individual_Notes("Imported via OAI from " + repository.Name); bibPackage.VID = "00001"; bibPackage.METS_Header.Creator_Software = "SobekCM METS Editor"; // See if this already exists in the mapping if ((!use_previous_mappings.HasValue) && (oai_objectid_mapping.ContainsKey(record.OAI_Identifier))) { DialogResult result = MessageBox.Show("Record from OAI set appears in previous mapping file. \n\nShould the previous mappings be used? \n\nIf you select 'YES' the ObjectID will be the same as the previous harvest.\n\nIf you select 'NO' a new ObjectID will be assigned from your range. ", "Previous Mapping Found", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { use_previous_mappings = true; } if (result == DialogResult.No) { use_previous_mappings = false; } } // Assign a BibId if ((use_previous_mappings.HasValue) && (use_previous_mappings.Value) && (oai_objectid_mapping.ContainsKey(record.OAI_Identifier))) { // Use the existing BibId from the previous mapping bibPackage.BibID = oai_objectid_mapping[record.OAI_Identifier]; } else { // Determine the next BibID to be assigned string next_bibid = next_bibid_counter.ToString(); next_bibid_counter++; bibPackage.BibID = (bibid_start + next_bibid.PadLeft(10 - bibid_start.Length, '0')).ToUpper(); // Save this mapping to the dictionary oai_objectid_mapping[record.OAI_Identifier] = bibPackage.BibID; } // Set some values bibPackage.METS_Header.Creator_Organization = bibPackage.Bib_Info.Source.Code + "," + bibPackage.Bib_Info.Source.Statement; if (MetaTemplate_UserSettings.AddOns_Enabled.Contains("FCLA")) { PALMM_Info palmmInfo = bibPackage.Get_Metadata_Module(GlobalVar.PALMM_METADATA_MODULE_KEY) as PALMM_Info; if (palmmInfo == null) { palmmInfo = new PALMM_Info(); bibPackage.Add_Metadata_Module(GlobalVar.PALMM_METADATA_MODULE_KEY, palmmInfo); } if ((palmmInfo.toPALMM) && (palmmInfo.PALMM_Project.Length > 0)) { string creator_org_to_remove = String.Empty; foreach (string thisString in bibPackage.METS_Header.Creator_Org_Notes) { if (thisString.IndexOf("projects=") >= 0) { creator_org_to_remove = thisString; break; } } if (creator_org_to_remove.Length > 0) { bibPackage.METS_Header.Replace_Creator_Org_Notes(creator_org_to_remove, "projects=" + palmmInfo.PALMM_Project); } else { bibPackage.METS_Header.Add_Creator_Org_Notes("projects=" + palmmInfo.PALMM_Project); } } } // Determine the filename string mets_file = destination_folder + "\\" + bibPackage.BibID + "_" + bibPackage.VID + MetaTemplate_UserSettings.METS_File_Extension; // Save the actual file METS_File_ReaderWriter metsWriter = new METS_File_ReaderWriter(); string writing_error = String.Empty; metsWriter.Write_Metadata(mets_file, bibPackage, null, out writing_error); // Increment progress recordsProcessed++; OnNewProgress(recordsProcessed, total_count); } // If there was a resumption token, pull the next set of records from the repository if (String.IsNullOrEmpty(records.Resumption_Token)) { records = null; } else { records = OAI_Repository_Stream_Reader.List_Records(repository.Harvested_URL, records.Resumption_Token); } } } catch (Exception ee) { Debug.WriteLine(ee.Message); OnComplete(recordsProcessed, OAI_PMH_Importer_Error_Enum.Unknown_error_while_processing_feed); } // Now, save this mapping if (mapping_directory.Length > 0) { try { // Ensure the directory exists if (!Directory.Exists(mapping_directory)) { Directory.CreateDirectory(mapping_directory); } // Create the dataset/table with the new mappings (includes old if one was found) DataSet mappingSet2 = new DataSet("SobekCM_METS_Editor_OAI_Mapping"); DataTable mappingTable = new DataTable("OAI_ObjectID_Map"); mappingSet2.Tables.Add(mappingTable); mappingTable.Columns.Add("OAI_Identifier"); mappingTable.Columns.Add("SobekCM_ObjectID"); // Copy over the data into the new datatable foreach (string thisKey in oai_objectid_mapping.Keys) { DataRow newRow = mappingTable.NewRow(); newRow[0] = thisKey; newRow[1] = oai_objectid_mapping[thisKey]; mappingTable.Rows.Add(newRow); } // Write the mappings as the dataset in XML format mappingSet2.WriteXml(mappings_file, XmlWriteMode.WriteSchema); } catch (Exception ee) { Debug.WriteLine(ee.Message); OnComplete(recordsProcessed, OAI_PMH_Importer_Error_Enum.Unable_to_save_mappings_file); } } // Process complete! OnComplete(recordsProcessed, OAI_PMH_Importer_Error_Enum.NO_ERROR); }